ecdsa

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

Usage

Installation

npm install --save ecdsa

Example

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: https://github.com/cryptocoinjs/ecurve/blob/master/lib/names.js
var ecdsa = require('ecdsa')('secp160r1')

API

calcPubKeyRecoveryParam

(TODO)

deterministicGenerateK(hash, privateKey)

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

parseSig(buffer)

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

parseSigCompact(buffer)

(TODO)

recoverPubKey(e, signature, i)

(TODO)

serializeSig(signature)

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

serializeSigCompact(signature, i ,compressed)

(TODO)

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)

(TODO)