Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 1.87 KB

README.md

File metadata and controls

63 lines (44 loc) · 1.87 KB

secp256k1-node

NPM Package Build Status Coverage Status

js-standard-style

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.

Installation

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
from npm

npm install secp256k1

from git
git clone [email protected]:wanderer/secp256k1-node.git
cd secp256k1-node
npm install

Usage

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))

LICENSE

This library is free and open-source software released under the MIT license.