HDWallet: add fromBase58 exception checks
This commit is contained in:
parent
cde285ccfc
commit
80da2ed2d5
3 changed files with 28 additions and 3 deletions
|
@ -49,8 +49,8 @@ HDWallet.fromBase58 = function(string) {
|
|||
var checksum = buffer.slice(-4)
|
||||
var newChecksum = crypto.hash256(payload).slice(0, 4)
|
||||
|
||||
assert.deepEqual(newChecksum, checksum)
|
||||
assert.equal(payload.length, HDWallet.LENGTH)
|
||||
assert.deepEqual(newChecksum, checksum, 'Invalid checksum')
|
||||
assert.equal(payload.length, HDWallet.LENGTH, 'Invalid BIP32 string')
|
||||
|
||||
return HDWallet.fromBuffer(payload)
|
||||
}
|
||||
|
|
17
test/fixtures/hdwallet.json
vendored
17
test/fixtures/hdwallet.json
vendored
|
@ -176,5 +176,20 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"invalid": []
|
||||
"invalid": {
|
||||
"fromBase58": [
|
||||
{
|
||||
"exception": "Invalid checksum",
|
||||
"string": "xprvQQQQQQQQQQQQQQQQCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334"
|
||||
},
|
||||
{
|
||||
"exception": "Invalid BIP32 string",
|
||||
"string": "SQ8nQ2jWarXqLo9oHGKKP6iQDsQbPRftq7rjtYY3hqJRPQRgrmeunFnDKbH7B15yGPLZBrhhkKXx3pwD6LcBooJRGq6x7matAXpMsgn"
|
||||
},
|
||||
{
|
||||
"exception": "Invalid BIP32 string",
|
||||
"string": "37hdAfw3aMiWcBGPP2ywmY5jizTeSSP5GXayKY3RxkEZ7f3SBnRE1pN6eY3VzGkgx6vbdNtuKfrHgEaYvW9KkFZCycaPvWiA9TtfmeVB592Sf9RfSzQzXo72"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,16 @@ describe('HDWallet', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('fromBase58', function() {
|
||||
fixtures.invalid.fromBase58.forEach(function(f) {
|
||||
it('throws on ' + f.string, function() {
|
||||
assert.throws(function() {
|
||||
HDWallet.fromBase58(f.string)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('constructor & seed deserialization', function() {
|
||||
var expectedPrivateKey = '0fd71c652e847ba7ea7956e3cf3fc0a0985871846b1b2c23b9c6a29a38cee860'
|
||||
var seed = new Buffer([
|
||||
|
|
Loading…
Add table
Reference in a new issue