From 70659ad9d42393edc1a65cd0eda54a12729ffdd0 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Wed, 17 Sep 2014 14:40:29 -0700 Subject: [PATCH] use base58check in fromString --- lib/bip32.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/lib/bip32.js b/lib/bip32.js index 29f4bcb..b5c34d1 100644 --- a/lib/bip32.js +++ b/lib/bip32.js @@ -1,4 +1,5 @@ var base58 = require('./base58'); +var Base58Check = require('./base58check'); var Hash = require('./hash'); var Keypair = require('./keypair'); var Pubkey = require('./pubkey'); @@ -29,20 +30,8 @@ BIP32.prototype.fromRandom = function(networkstr) { }; BIP32.prototype.fromString = function(str) { - var decoded = base58.decode(str); - if (decoded.length != 82) - throw new Error('Not enough data, expected 82 and received ' + decoded.length); - var checksum = decoded.slice(78, 82); - var bytes = decoded.slice(0, 78); - - var hash = Hash.sha256sha256(bytes); - - if (hash[0] != checksum[0] || hash[1] != checksum[1] || hash[2] != checksum[2] || hash[3] != checksum[3]) - throw new Error('Invalid checksum'); - - if (bytes !== undefined && bytes !== null) - this.initFromBytes(bytes); - + var bytes = Base58Check.decode(str); + this.initFromBytes(bytes); return this; };