Socket
Socket
Sign inDemoInstall

hdkey

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hdkey - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

15

CHANGELOG.md

@@ -0,1 +1,5 @@

0.7.0 / 2016-03-22
------------------
- upgrade from `ecurve` to `secp256k1`. [#5][#5]
0.6.0 / 2015-07-02

@@ -49,1 +53,12 @@ ------------------

- initial release
<!--- hdkey: use the secp256k1 package for crypto -->
[#5]: https://github.com/cryptocoinjs/hdkey/pull/5
<!--- Is this library still maintained? -->
[#4]: https://github.com/cryptocoinjs/hdkey/issues/4
<!--- Update hdkey.js -->
[#3]: https://github.com/cryptocoinjs/hdkey/pull/3
<!--- Update hdkey.js -->
[#2]: https://github.com/cryptocoinjs/hdkey/pull/2
<!--- rare condition needed for bip consistency -->
[#1]: https://github.com/cryptocoinjs/hdkey/issues/1

46

lib/hdkey.js
var assert = require('assert')
var crypto = require('crypto')
var BigInteger = require('bigi')
var cs = require('coinstring')
var ecurve = require('ecurve')
var curve = ecurve.getCurveByName('secp256k1')
var Point = ecurve.Point
var secp256k1 = require('secp256k1')

@@ -28,4 +25,4 @@ var MASTER_SECRET = new Buffer('Bitcoin seed')

Object.defineProperty(HDKey.prototype, 'fingerprint', { get: function () { return this._fingerprint } })
Object.defineProperty(HDKey.prototype, 'identifier', {get: function () { return this._identifier } })
Object.defineProperty(HDKey.prototype, 'pubKeyHash', {get: function () { return this.identifier }})
Object.defineProperty(HDKey.prototype, 'identifier', { get: function () { return this._identifier } })
Object.defineProperty(HDKey.prototype, 'pubKeyHash', { get: function () { return this.identifier } })

@@ -38,5 +35,6 @@ Object.defineProperty(HDKey.prototype, 'privateKey', {

assert.equal(value.length, 32, 'Private key must be 32 bytes.')
assert(secp256k1.privateKeyVerify(value) === true, 'Invalid private key')
this._privateKey = value
this._publicPoint = curve.G.multiply(BigInteger.fromBuffer(this._privateKey))
this._publicKey = this._publicPoint.getEncoded(true) // force compressed point
this._publicKey = secp256k1.publicKeyCreate(value, true)
this._identifier = hash160(this.publicKey)

@@ -53,4 +51,5 @@ this._fingerprint = this._identifier.slice(0, 4).readUInt32BE(0)

assert(value.length === 33 || value.length === 65, 'Public key must be 33 or 65 bytes.')
this._publicPoint = Point.decodeFrom(curve, value)
this._publicKey = this._publicPoint.getEncoded(true) // force compressed point
assert(secp256k1.publicKeyVerify(value) === true, 'Invalid public key')
this._publicKey = secp256k1.publicKeyConvert(value, true) // force compressed point
this._identifier = hash160(this.publicKey)

@@ -125,3 +124,2 @@ this._fingerprint = this._identifier.slice(0, 4).readUInt32BE(0)

var hd = new HDKey(this.versions)
var pIL = BigInteger.fromBuffer(IL)

@@ -131,12 +129,9 @@ // Private parent key -> private child key

// ki = parse256(IL) + kpar (mod n)
var ki = pIL.add(BigInteger.fromBuffer(this.privateKey)).mod(curve.n)
// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
if (pIL.compareTo(curve.n) >= 0 || ki.signum() === 0) {
try {
hd.privateKey = secp256k1.privateKeyTweakAdd(this.privateKey, IL)
// throw if IL >= n || (privateKey + IL) === 0
} catch (err) {
// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
return this.derive(index + 1)
}
// if less than 32 bytes, pad with 0's
hd.privateKey = ki.toBuffer(32)
// Public parent key -> public child key

@@ -146,10 +141,9 @@ } else {

// = G*IL + Kpar
var Ki = curve.G.multiply(pIL).add(this._publicPoint)
// In case parse256(IL) >= n or Ki is the point at infinity, one should proceed with the next value for i
if (pIL.compareTo(curve.n) >= 0 || curve.isInfinity(Ki)) {
return this.derive(index + 1)
try {
hd.publicKey = secp256k1.publicKeyTweakAdd(this.publicKey, IL, true)
// throw if IL >= n || (g**IL + publicKey) is infinity
} catch (err) {
// In case parse256(IL) >= n or Ki is the point at infinity, one should proceed with the next value for i
return this.derive(index + 1, isHardened)
}
hd.publicKey = Ki.getEncoded(true)
}

@@ -156,0 +150,0 @@

{
"name": "hdkey",
"version": "0.6.0",
"version": "0.7.0",
"description": "Bitcoin BIP32 hierarchical deterministic keys",

@@ -10,2 +10,3 @@ "main": "lib/hdkey.js",

},
"license": "MIT",
"keywords": [

@@ -25,3 +26,5 @@ "bitcoin",

"devDependencies": {
"bigi": "^1.1.0",
"coveralls": "^2.10.0",
"ecurve": "^1.0.0",
"istanbul": "^0.3.17",

@@ -32,12 +35,13 @@ "mocha": "^2.2.5",

"secure-random": "^1.0.0",
"standard": "4.x"
"standard": "6.x"
},
"dependencies": {
"bigi": "^1.1.0",
"ecurve": "^1.0.0",
"coinstring": "^2.0.0"
"coinstring": "^2.0.0",
"secp256k1": "^3.0.1"
},
"scripts": {
"lint": "standard",
"browser-test": "mochify --wd -R spec",
"test": "standard && mocha",
"unit": "mocha",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",

@@ -44,0 +48,0 @@ "coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info"

hdkey
=====
[![build status](https://secure.travis-ci.org/cryptocoinjs/hdkey.png)](http://travis-ci.org/cryptocoinjs/hdkey)
[![Coverage Status](https://img.shields.io/coveralls/cryptocoinjs/hdkey.svg)](https://coveralls.io/r/cryptocoinjs/hdkey)
[![NPM Package](https://img.shields.io/npm/v/hdkey.svg?style=flat-square)](https://www.npmjs.org/package/hdkey)
[![build status](https://secure.travis-ci.org/cryptocoinjs/hdkey.svg)](http://travis-ci.org/cryptocoinjs/hdkey)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
A JavaScript component for [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki)(hierarchical deterministic keys).
Thanks to the active BitcoinJS team and their hard work - some code borrowed from it.

@@ -33,3 +33,2 @@ Installation

References

@@ -42,1 +41,7 @@ ----------

- http://bitcoinmagazine.com/8396/deterministic-wallets-advantages-flaw/
License
-------
MIT

@@ -122,3 +122,2 @@ var assert = require('assert')

assert.equal(derivedHDKey.publicExtendedKey, expected)
})

@@ -125,0 +124,0 @@ })

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