allow creating blank BIP32 by passing in null
This commit is contained in:
parent
d52e8ac8ed
commit
6a4387e768
13
lib/BIP32.js
13
lib/BIP32.js
|
@ -10,6 +10,11 @@ var networks = require('../networks');
|
|||
var secp256k1_n = new bignum("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16);
|
||||
var secp256k1_Gx = new bignum("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16);
|
||||
|
||||
/*
|
||||
random new BIP32: new BIP32();
|
||||
from extended public or private key: new BIP32(str);
|
||||
new blank BIP32: new BIP32(null);
|
||||
*/
|
||||
var BIP32 = function(bytes) {
|
||||
if (typeof bytes == 'undefined' || bytes == 'mainnet' || bytes == 'livenet') {
|
||||
bytes = 'livenet';
|
||||
|
@ -46,7 +51,7 @@ var BIP32 = function(bytes) {
|
|||
}
|
||||
}
|
||||
|
||||
if (bytes !== undefined)
|
||||
if (bytes !== undefined && bytes !== null)
|
||||
this.initFromBytes(bytes);
|
||||
}
|
||||
|
||||
|
@ -60,7 +65,7 @@ BIP32.seed = function(bytes, network) {
|
|||
return false; //need more entropy
|
||||
var hash = coinUtil.sha512hmac(bytes, new Buffer("Bitcoin seed"));
|
||||
|
||||
var bip32 = new BIP32();
|
||||
var bip32 = new BIP32(null);
|
||||
bip32.depth = 0x00;
|
||||
bip32.parentFingerprint = new Buffer([0, 0, 0, 0]);
|
||||
bip32.childIndex = new Buffer([0, 0, 0, 0]);
|
||||
|
@ -265,7 +270,7 @@ BIP32.prototype.deriveChild = function(i) {
|
|||
var priv = bignum.fromBuffer(this.eckey.private, {size: 32});
|
||||
var k = il.add(priv).mod(secp256k1_n);
|
||||
|
||||
ret = new BIP32();
|
||||
ret = new BIP32(null);
|
||||
ret.chainCode = ir;
|
||||
|
||||
ret.eckey = new Key();
|
||||
|
@ -289,7 +294,7 @@ BIP32.prototype.deriveChild = function(i) {
|
|||
var Kpar = Point.fromKey(oldkey);
|
||||
var newpub = Point.add(ilG, Kpar).toKey().public;
|
||||
|
||||
ret = new BIP32();
|
||||
ret = new BIP32(null);
|
||||
ret.chainCode = new Buffer(ir);
|
||||
|
||||
var eckey = new Key();
|
||||
|
|
Loading…
Reference in New Issue