Skip to content

Instantly share code, notes, and snippets.

@Dan-Nolan
Created October 8, 2021 18:30
Show Gist options
  • Save Dan-Nolan/629054de172fe3ea5141740697379ffd to your computer and use it in GitHub Desktop.
Save Dan-Nolan/629054de172fe3ea5141740697379ffd to your computer and use it in GitHub Desktop.
Elliptic Key Utils
const EC = require('elliptic').ec;
const ec = new EC('secp256k1');
// private/public key pair generation
const key = ec.genKeyPair();
// to public key hex string (04...)
const hexPublicKey = key.getPublic().encode('hex');
// from hex string back to the elliptic key object (this key can verify)
const verifyKey = ec.keyFromPublic(hexPublicKey, 'hex');
// to private key hex string
const hexPrivateKey = key.getPrivate().toString(16);
// from hex string back to elliptic key object (this key can sign)
const signingKey = ec.keyFromPrivate(hexPrivateKey);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment