Skip to content

Instantly share code, notes, and snippets.

@changwu-tw
Created April 15, 2023 14:52
Show Gist options
  • Save changwu-tw/f59ccd6d561a6e061c31fb9a41f2e2f9 to your computer and use it in GitHub Desktop.
Save changwu-tw/f59ccd6d561a6e061c31fb9a41f2e2f9 to your computer and use it in GitHub Desktop.
let elliptic = require('elliptic');
let sha3 = require('js-sha3');
let ec = new elliptic.ec('secp256k1');
// let keyPair = ec.genKeyPair();
// privkey: 0xbe2d433d23c65543f3841dd402d4af1ef97674cc656c7c3cf35b06e17bd22da9
// pubKey: 0x0331632fb5e68cd4c81b9656babb420d630da2a629f97aaf3fa07f30df22866bac
// 0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d
// 0x04e68acfc0253a10620dff706b0a1b1f1f5833ea3beb3bde2250d5f271f3563606672ebc45e0b7ea2e816ecb70ca03137b1c9476eec63d4632e990020b7b6fba39
// 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
let keyPair = ec.keyFromPrivate("4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d");
let privKey = keyPair.getPrivate("hex");
let pubKey = keyPair.getPublic();
console.log(`Private key: 0x${privKey}`);
console.log("Public key:", "0x"+pubKey.encodeCompressed("hex"));
console.log("Public key :", pubKey.encode("hex").substr(2));
console.log("Address :", address);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment