build status Coverage Status Version

browser support

JavaScript component for Elliptical Curve Cryptography signing and verification. This package is important to sign transactions. Works with both Node.js and the browser.

Package Info



npm install --save ecdsa


var crypto = require('crypto') //Node.js or Browserify (browser)

var ecdsa = require('ecdsa')
var sr = require('secure-random') //npm install --save secure-random@1.x
var CoinKey = require('coinkey') //npm install --save coinkey@0.1.0

var privateKey = sr.randomBuffer(32)
var ck = new CoinKey(privateKey, true) // true => compressed public key / addresses

var msg = new Buffer("hello world!", 'utf8')
var shaMsg = crypto.createHash('sha256').update(msg).digest()
var signature = ecdsa.sign(shaMsg, ck.privateKey)
var isValid = ecdsa.verify(shaMsg, signature, ck.publicKey)
console.log(isValid) //true

you could also use another curve, you'd probably never need to do this though:

//curves defined here:
var ecdsa = require('ecdsa')('secp160r1')




deterministicGenerateK(hash, privateKey)

Used by sign() to securely and deterministically generate the K value. From RFC 6979.


Parses the signature and returns an object with r and s values.



recoverPubKey(e, signature, i)



Serializes a signature object that contains r and s fields into a DER encoded signature with type Buffer.

serializeSigCompact(signature, i ,compressed)


sign(hash, privateKey)

Signs a hash. Typically used to sign crypto currency transactions.

verify(hash, signature, publicKey)

Verifies that the hash is signed with the signature.

(TODO: add params)

verifyRaw(e, signature, Q)