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