Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vain</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f8f8f8;
            padding: 20px;
        }
        h1, h2, p {
            color: #333;
        }
        button {
            background-color: #4CAF50; /* Green */
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            transition-duration: 0.4s;
            cursor: pointer;
        }
        button:hover {
            background-color: white;
            color: black;
            border: 1px solid #4CAF50;
        }
        input {
            width: 100%;
            padding: 12px 20px;
            margin: 8px 0;
            display: inline-block;
            border: 1px solid #ccc;
            box-sizing: border-box;
        }
        .key {
            background-color: #f1f1f1;
            padding: 10px;
            border-radius: 5px;
            word-break: break-all;
        }
        a {
            color: #4CAF50;
        }
        a:hover {
            color: #45a049;
        }
    </style>
</head>
<body>

<div>
    <p>This demo uses <a href="https://github.com/indutny/elliptic">Elliptic</a>, which implements <a href="https://en.bitcoin.it/wiki/Secp256k1"><tt>secp256k1</tt></a>:</p>
    <button id="genbtn">Generate address</button>
    <br>    
<br>
    <p>Private key:</p>
    <p class="key" id="priv"></p>
    <p>Public key:</p>
    <p class="key" id="pub"></p>
    <p>Ethereum address:</p>
    <p class="key" id="eth"></p>
    
    <h1>Public Key</h1><p >Recover Public Key from message signature (safe)</p>
  <button id="signMessage">Sign Message</button>
    <p id="publicKey">Recovered Public Key will appear here</p>
OR<br>
    <label for="pKA">Your Private Key:</label>
    <input type="text" id="pKA" name="pKA" required>
    <br>
    <button id="getbt">Get Public Key</button>
    <h2>Results:</h2>
   <p id="rs"></p>
    <h1>Private Key Adder</h1>
    <label for="privateKeyA">Your Private Key:</label>
    <input type="text" id="privateKeyA" name="privateKeyA" required>
    <br>
    <label for="privateKeyB">Vain Private Key:</label>
    <input type="text" id="privateKeyB" name="privateKeyB" required>
    <br>
    <button id="getbtn">Add Private Keys</button>
    <h2>Results:</h2>
    <p id="result"></p>
   <p id="res"></p>
</div>

<script src="//rawgit.com/weepy/brequire/master/require.js"></script>


</body>
</html>

              
            
!

CSS

              
                 body {
            font-family: Arial, sans-serif;
            background-color: #f8f8f8;
            padding: 20px;
        }
        h1, h2, p {
            color: #333;
        }
        button {
            background-color: #4CAF50; /* Green */
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            transition-duration: 0.4s;
            cursor: pointer;
        }
        button:hover {
            background-color: white;
            color: black;
            border: 1px solid #4CAF50;
        }
        input {
            width: 100%;
            padding: 12px 20px;
            margin: 8px 0;
            display: inline-block;
            border: 1px solid #ccc;
            box-sizing: border-box;
        }
        .key {
            background-color: #f1f1f1;
            padding: 10px;
            border-radius: 5px;
            word-break: break-all;
        }
        a {
            color: #4CAF50;
        }
        a:hover {
            color: #45a049;
        }
              
            
!

JS

              
                import * as ethers from "https://cdn.skypack.dev/ethers@5.5.1";

const btn = document.getElementById('genbtn');const b = document.getElementById('getbt');
//const bt = document.getElemztbtn');
const bt = document.getElementById('getbtn');

let elliptic;

function generateKeyAndAddress() {
  btn.className = 'loading';
  
  // load library
  elliptic = elliptic || require('https://rawgit.com/indutny/elliptic/v6.4.1/dist/elliptic.min.js');
  const ec = new elliptic.ec('secp256k1');
  
  // generate keypair
  const keyPair = ec.genKeyPair();
  
  // extract + display private key
  const privKey = keyPair.getPrivate();
  console.log(privKey);
  document.getElementById('priv').innerText = privKey.toString('hex');
  
  // extract + display public key
  const pubKey = keyPair.getPublic();
  const pubKeyAsHex = "0x" + pubKey.encode('hex');
  document.getElementById('pub').innerText = "0x" + pubKeyAsHex.substring(4);
  
  // hash + slice
  var hash = ethers.utils.keccak256(pubKeyAsHex);
  var slicedHash = "0x" + hash.slice(-40);
  document.getElementById('eth').innerHTML = "<a href='https://etherscan.io/address/" + slicedHash + "'>" + slicedHash + "</a>";
  
  btn.className = '';
}
 function addPrivateKeys(privateKeyA, privateKeyB) {
        const secp256k1N = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141');
        const result = (BigInt(`0x${privateKeyA}`) + BigInt(`0x${privateKeyB}`)) % secp256k1N;
        return result.toString(16).padStart(64, '0').toUpperCase();
    }

    function addKeysAndDisplay() {
        const privateKeyA = document.getElementById('privateKeyA').value;
        const privateKeyB = document.getElementById('privateKeyB').value;
        const newPrivateKey = addPrivateKeys(privateKeyA, privateKeyB);
  var ha = ('0x'+newPrivateKey);
      var hash =  ethers.utils.computeAddress(ha);
 const from = hash;
const nonce = 0;
var h =  ethers.utils.getContractAddress({ from, nonce });

 document.getElementById('result').innerText = `Added Private Key: ${newPrivateKey}`;
  document.getElementById('res').innerText = `Address: ${hash}`+`\n`+`Contract Address: ${h}`;
    }function pubKey() {
        const privateKey = document.getElementById('pKA').value;
      var hash =  ethers.utils.computePublicKey('0x'+privateKey);

 document.getElementById('rs').innerText = `PublicKey: ${"0x" + hash.substring(4)}`;
  
    }
document.getElementById('signMessage').addEventListener('click', async () => {
    if (typeof window.ethereum !== 'undefined') {
        try {
            const provider = new ethers.providers.Web3Provider(window.ethereum);
            await provider.send("eth_requestAccounts", []);
            const signer = provider.getSigner();

            // Change the message as per your requirement
            const message = "Hello, world!";
            const signature = await signer.signMessage(message);

            // Extracting the public key
            const messageBytes = ethers.utils.toUtf8Bytes(message);
            const messageDigest = ethers.utils.keccak256(messageBytes);
            const recoveredPubKey = ethers.utils.recoverPublicKey(messageDigest, signature);
           document.getElementById('publicKey').textContent = `Recovered Public Key: ${"0x" + recoveredPubKey.substring(4)}`;
            console.log("Signature:", signature);
            console.log("Recovered Public Key:",     ethers.utils.keccak256("0x" + recoveredPubKey.substring(4)));
        } catch (err) {
            console.error(err);
        }
    } else {
        console.log('Please install MetaMask!');
    }
});
btn.addEventListener('click', generateKeyAndAddress);b.addEventListener('click', pubKey);
bt.addEventListener('click', addKeysAndDisplay);
              
            
!
999px

Console