Socket
Socket
Sign inDemoInstall

secp256k1

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

secp256k1 - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

test.js

77

index.js

@@ -0,1 +1,3 @@

var crypto = require('crypto');
/**

@@ -9,2 +11,47 @@ * This module provides native bindings to ecdsa [secp256k1](https://github.com/bitcoin/secp256k1) functions

/**
* deteministic Generation of k
* @method detereministicGenerateK
* @param {Buffer} h1 the hash of the message
* @param {Buffer} x the private key
*/
var deterministicGenerateK = exports.deterministicGenerateK = function(h1, x){
//https://tools.ietf.org/html/rfc6979#section-3.2
//step b
var v = new Buffer(32);
v.fill(1);
//step c
var k = new Buffer(32);
k.fill(0);
//step d
var hash = crypto.createHmac('sha256', k);
hash.update(Buffer.concat([v, new Buffer([0]), x, h1]));
k = hash.digest();
//step e
hash = crypto.createHmac('sha256', k);
hash.update(v);
v = hash.digest();
//step f
hash = crypto.createHmac('sha256', k);
hash.update(Buffer.concat([v, new Buffer([1]), x, h1]));
k = hash.digest();
//step g
hash = crypto.createHmac('sha256', k);
hash.update(v);
v = hash.digest();
//step h
hash = crypto.createHmac('sha256', k);
hash.update(v);
v = hash.digest();
return v;
};
/**
* Verify an ECDSA secret key.

@@ -29,3 +76,3 @@ * @method verifySecetKey

/**
/**
* Create an ECDSA signature.

@@ -35,3 +82,3 @@ * @method sign

* @param {Buffer} msg he message being signed
* @param {Function} cb the callback given. The callback is given the signature
* @param {Function} cb the callback given. The callback is given the signature
* @returns {Buffer} if no callback is given a 72-byte signature is returned

@@ -41,5 +88,5 @@ */

if(cb){
secpNode.signAsync(secretKey, msg, cb);
secpNode.signAsync(secretKey, msg, deterministicGenerateK(msg, secretKey), cb);
}else{
return secpNode.sign(secretKey, msg);
return secpNode.sign(secretKey, msg, deterministicGenerateK(msg, secretKey));
}

@@ -51,9 +98,9 @@ };

* if given a callback
* @method signCompact
* @method signCompact
* @param {Buffer} sercetKey a 32-byte secret key (assumed to be valid)
* @param {Buffer} msg the message being signed
* @param {Function} [cb] the callback which is give `err`, `sig` the
* @param {Function} [cb] the callback which is give `err`, `sig` the
* - param {Buffer} sig a 64-byte buffer repersenting the signature
* - param {Number} recid an int which is the recovery id.
* @return {Object} result only if no callback is given will the result be returned
* @return {Object} result only if no callback is given will the result be returned
* - result.sigature

@@ -66,8 +113,6 @@ * - result.r

assert(secretKey.length === 32, 'the secret key needs tobe 32 bytes');
if(cb){
secpNode.signCompactAsync(secretKey, msg, cb);
secpNode.signCompactAsync(secretKey, msg, deterministicGenerateK(msg, secretKey), cb);
}else{
var array = secpNode.signCompact(secretKey, msg);
var array = secpNode.signCompact(secretKey, msg, deterministicGenerateK(msg, secretKey));
return {

@@ -109,4 +154,4 @@ recoveryId: array[1],

* @param {Buffer} sig the signature as 64 byte buffer
* @param {Integer} recid the recovery id (as returned by ecdsa_sign_compact)
* @param {Boolean} compressed whether to recover a compressed or uncompressed pubkey
* @param {Integer} recid the recovery id (as returned by ecdsa_sign_compact)
* @param {Function} [cb]

@@ -120,3 +165,3 @@ * @return {Buffer} the pubkey, a 33 or 65 byte buffer

if(!cb){
return secpNode.recoverCompact(msg, sig, compressed, recid);
return secpNode.recoverCompact(msg, sig, compressed, recid);
}else{

@@ -127,3 +172,3 @@ secpNode.recoverCompactAsync(msg, sig, compressed, recid, cb);

/**
/**
* Compute the public key for a secret key.

@@ -151,3 +196,3 @@ * @method createPubKey

* @param {Buffer} privateKey
* @return {Buffer} secertKey
* @return {Buffer} secertKey
*/

@@ -160,3 +205,3 @@ exports.importPrivateKey = secpNode.privKeyImport;

* @return {Buffer}
*/
*/
exports.decompressPublicKey = secpNode.pubKeyDecompress;
{
"name": "secp256k1",
"version": "0.0.4",
"version": "0.0.5",
"description": "This module provides native bindings to ecdsa secp256k1 functions",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -91,3 +91,3 @@ secp256k1 [![Build Status](https://travis-ci.org/wanderer/secp256k1-node.svg?branch=master)](https://travis-ci.org/wanderer/secp256k1-node)

**Returns**: result only returned if no callback is given
- result.sigature
- result.signature
- result.r

@@ -115,3 +115,3 @@ - result.s

secp256k1.recoverCompact(msg, sig, compressed, recid, cb)
secp256k1.recoverCompact(msg, sig, recid, compressed, cb)
-----------------------------

@@ -126,6 +126,6 @@ Recover an ECDSA public key from a compact signature in the process also verifing it. Runs asynchronously if given a callback

**recid**: Integer, the recovery id (as returned by ecdsa_sign_compact)
**compressed**: Boolean, whether to recover a compressed or uncompressed pubkey
**recid**: Integer, the recovery id (as returned by ecdsa_sign_compact)
**cb**: function, Recover an ECDSA public key from a compact signature. In the process also verifing it.

@@ -182,8 +182,1 @@

This will not work on node version 11 yet. Arrays need to have `isolates` for this.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc