This module provides native bindings to ecdsa secp256k1 functions. This library is experimental, so use at your own risk. Works on node version 0.10 or greater.
If you have gmp installed secp256k1 will use it. Otherwise it should fallback to openssl.
- arch
pacman -S gmp
- ubuntu
sudo apt-get install libgmp-dev
npm install secp256k1
git clone [email protected]:wanderer/secp256k1-node.git
cd secp256k1-node
npm install
var crypto = require('crypto')
var secp256k1 = require('secp256k1')
// or require('secp256k1/js')
// if you want to use pure js implementation in node (uses elliptic now)
// or require('secp256k1/elliptic')
// if implementation that uses elliptic package
// generate message to sign
var msg = crypto.randomBytes(32)
// generate privKey
var privKey
do {
privKey = crypto.randomBytes(32)
} while (!secp256k1.secretKeyVerify(privKey))
// get the public key in a compressed format
var pubKey = secp256k1.publicKeyCreate(privKey)
// sign the message
var sigObj = secp256k1.signSync(msg, privKey)
// verify the signature
console.log(secp256k1.verifySync(msg, sigObj.signature, pubKey))
This library is free and open-source software released under the MIT license.