From 322ade58e4479274081c04e4db77136e61adb15b Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 9 Sep 2015 12:25:50 +1000 Subject: [PATCH] revert 4b825bf --- src/hdnode.js | 13 +++++++------ test/hdnode.js | 2 +- test/integration/crypto.js | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/hdnode.js b/src/hdnode.js index 22ccecf..fbf0577 100644 --- a/src/hdnode.js +++ b/src/hdnode.js @@ -11,9 +11,6 @@ var ECPair = require('./ecpair') var ecurve = require('ecurve') var curve = ecurve.getCurveByName('secp256k1') -var MASTER_SECRET = new Buffer('Bitcoin seed') -var HIGHEST_BIT = 0x80000000 - function HDNode (keyPair, chainCode) { typeforce(types.tuple('ECPair', types.Buffer256bit), arguments) @@ -26,13 +23,17 @@ function HDNode (keyPair, chainCode) { this.parentFingerprint = 0x00000000 } +HDNode.HIGHEST_BIT = 0x80000000 +HDNode.LENGTH = 78 +HDNode.MASTER_SECRET = new Buffer('Bitcoin seed') + HDNode.fromSeedBuffer = function (seed, network) { typeforce(types.tuple(types.Buffer, types.maybe(types.Network)), arguments) if (seed.length < 16) throw new TypeError('Seed should be at least 128 bits') if (seed.length > 64) throw new TypeError('Seed should be at most 512 bits') - var I = createHmac('sha512', MASTER_SECRET).update(seed).digest() + var I = createHmac('sha512', HDNode.MASTER_SECRET).update(seed).digest() var IL = I.slice(0, 32) var IR = I.slice(32) @@ -189,7 +190,7 @@ HDNode.prototype.toBase58 = function (__isPrivate) { // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions HDNode.prototype.derive = function (index) { - var isHardened = index >= HIGHEST_BIT + var isHardened = index >= HDNode.HIGHEST_BIT var data = new Buffer(37) // Hardened child @@ -261,7 +262,7 @@ HDNode.prototype.derive = function (index) { HDNode.prototype.deriveHardened = function (index) { // Only derives hardened private keys by default - return this.derive(index + HIGHEST_BIT) + return this.derive(index + HDNode.HIGHEST_BIT) } HDNode.prototype.toString = HDNode.prototype.toBase58 diff --git a/test/hdnode.js b/test/hdnode.js index a14d89f..3bfed8d 100644 --- a/test/hdnode.js +++ b/test/hdnode.js @@ -193,7 +193,7 @@ describe('HDNode', function () { assert.strictEqual(hd.depth, depth || 0) if (v.hardened) { - assert.strictEqual(hd.index, v.m + 0x80000000) + assert.strictEqual(hd.index, v.m + HDNode.HIGHEST_BIT) } else { assert.strictEqual(hd.index, v.m) } diff --git a/test/integration/crypto.js b/test/integration/crypto.js index f34bd34..a494675 100644 --- a/test/integration/crypto.js +++ b/test/integration/crypto.js @@ -67,7 +67,7 @@ describe('bitcoinjs-lib (crypto)', function () { serQP.copy(data, 0) // search index space until we find it - for (var i = 0; i < 0x80000000; ++i) { + for (var i = 0; i < bitcoin.HDNode.HIGHEST_BIT; ++i) { data.writeUInt32BE(i, 33) // calculate I