Browse Source

HDWallet: add fromBase58 exception checks

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
80da2ed2d5
  1. 4
      src/hdwallet.js
  2. 17
      test/fixtures/hdwallet.json
  3. 10
      test/hdwallet.js

4
src/hdwallet.js

@ -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

@ -176,5 +176,20 @@
]
}
],
"invalid": []
"invalid": {
"fromBase58": [
{
"exception": "Invalid checksum",
"string": "xprvQQQQQQQQQQQQQQQQCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334"
},
{
"exception": "Invalid BIP32 string",
"string": "SQ8nQ2jWarXqLo9oHGKKP6iQDsQbPRftq7rjtYY3hqJRPQRgrmeunFnDKbH7B15yGPLZBrhhkKXx3pwD6LcBooJRGq6x7matAXpMsgn"
},
{
"exception": "Invalid BIP32 string",
"string": "37hdAfw3aMiWcBGPP2ywmY5jizTeSSP5GXayKY3RxkEZ7f3SBnRE1pN6eY3VzGkgx6vbdNtuKfrHgEaYvW9KkFZCycaPvWiA9TtfmeVB592Sf9RfSzQzXo72"
}
]
}
}

10
test/hdwallet.js

@ -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…
Cancel
Save