Browse Source

HDNode: enforces sane seed lengths

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
ddcde038d0
  1. 4
      src/hdnode.js
  2. 12
      test/hdnode.js

4
src/hdnode.js

@ -51,6 +51,10 @@ HDNode.HIGHEST_BIT = 0x80000000
HDNode.LENGTH = 78
HDNode.fromSeedBuffer = function(seed, network) {
assert(Buffer.isBuffer(seed), 'Expected Buffer, got' + seed)
assert(seed.length >= 16, 'Seed should be atleast 128 bits')
assert(seed.length <= 64, 'Seed should be atmost 512 bits')
var I = crypto.HmacSHA512(seed, HDNode.MASTER_SECRET)
var IL = I.slice(0, 32)
var IR = I.slice(32)

12
test/hdnode.js

@ -65,6 +65,18 @@ describe('HDNode', function() {
assert.equal(hd.chainCode.toString('hex'), f.master.chainCode)
})
})
it('throws on low entropy seed', function() {
assert.throws(function() {
HDNode.fromSeedHex('ffffffffff')
}, /Seed should be atleast 128 bits/)
})
it('throws on too high entropy seed', function() {
assert.throws(function() {
HDNode.fromSeedHex('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
}, /Seed should be atmost 512 bits/)
})
})
describe('toBase58', function() {

Loading…
Cancel
Save