Merge pull request #242 from dcousens/hdstrict
HDNode: enforces sane seed lengths and Transaction input
This commit is contained in:
commit
490b34852d
3 changed files with 19 additions and 1 deletions
|
@ -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 at least 128 bits')
|
||||
assert(seed.length <= 64, 'Seed should be at most 512 bits')
|
||||
|
||||
var I = crypto.HmacSHA512(seed, HDNode.MASTER_SECRET)
|
||||
var IL = I.slice(0, 32)
|
||||
var IR = I.slice(32)
|
||||
|
|
|
@ -84,9 +84,11 @@ Transaction.prototype.addOutput = function(scriptPubKey, value) {
|
|||
scriptPubKey = address.toOutputScript()
|
||||
}
|
||||
|
||||
assert(scriptPubKey instanceof Script, 'Expected Address or Script, got ' + scriptPubKey)
|
||||
|
||||
return (this.outs.push({
|
||||
script: scriptPubKey,
|
||||
value: value,
|
||||
value: value
|
||||
}) - 1)
|
||||
}
|
||||
|
||||
|
|
|
@ -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 at least 128 bits/)
|
||||
})
|
||||
|
||||
it('throws on too high entropy seed', function() {
|
||||
assert.throws(function() {
|
||||
HDNode.fromSeedHex('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
|
||||
}, /Seed should be at most 512 bits/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('toBase58', function() {
|
||||
|
|
Loading…
Add table
Reference in a new issue