use base58check in fromString
This commit is contained in:
parent
334c443d8b
commit
70659ad9d4
15
lib/bip32.js
15
lib/bip32.js
|
@ -1,4 +1,5 @@
|
||||||
var base58 = require('./base58');
|
var base58 = require('./base58');
|
||||||
|
var Base58Check = require('./base58check');
|
||||||
var Hash = require('./hash');
|
var Hash = require('./hash');
|
||||||
var Keypair = require('./keypair');
|
var Keypair = require('./keypair');
|
||||||
var Pubkey = require('./pubkey');
|
var Pubkey = require('./pubkey');
|
||||||
|
@ -29,20 +30,8 @@ BIP32.prototype.fromRandom = function(networkstr) {
|
||||||
};
|
};
|
||||||
|
|
||||||
BIP32.prototype.fromString = function(str) {
|
BIP32.prototype.fromString = function(str) {
|
||||||
var decoded = base58.decode(str);
|
var bytes = Base58Check.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);
|
this.initFromBytes(bytes);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue