From 6a4387e768864b699a46db2a44bc028e67fcbb50 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Tue, 22 Apr 2014 17:42:50 -0300 Subject: [PATCH] allow creating blank BIP32 by passing in null --- lib/BIP32.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/BIP32.js b/lib/BIP32.js index 06c77708f..875eb87ad 100644 --- a/lib/BIP32.js +++ b/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();