From be37f5e37f789ea0807db4b4e539d765c89c2c4d Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Sat, 9 Aug 2014 23:16:15 -0700 Subject: [PATCH] improve bip32 interface slightly --- lib/bip32.js | 5 ++++- test/test.bip32.js | 15 ++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/bip32.js b/lib/bip32.js index 7ccc560..4891417 100644 --- a/lib/bip32.js +++ b/lib/bip32.js @@ -17,7 +17,10 @@ var BIP32 = function(str) { this.fromString(str); } -BIP32.prototype.fromRandom = function() { +BIP32.prototype.fromRandom = function(network) { + if (!network) + network = 'mainnet'; + this.version = constants[network].bip32privkey; this.depth = 0x00; this.parentFingerprint = new Buffer([0, 0, 0, 0]); this.childIndex = new Buffer([0, 0, 0, 0]); diff --git a/test/test.bip32.js b/test/test.bip32.js index e101870..a0d32fb 100644 --- a/test/test.bip32.js +++ b/test/test.bip32.js @@ -36,13 +36,8 @@ describe('BIP32', function() { should.exist(BIP32); }); - it('should create a mainnet bip32', function() { - var bip32 = new BIP32('mainnet'); - should.exist(bip32); - }); - - it('should create a testnet bip32', function() { - var bip32 = new BIP32('testnet'); + it('should create a bip32', function() { + var bip32 = new BIP32(); should.exist(bip32); }); @@ -291,13 +286,15 @@ describe('BIP32', function() { describe('testnet', function() { it('should initialize a new BIP32 correctly from a random BIP32', function() { - var b1 = new BIP32('testnet'); + var b1 = new BIP32(); + b1.fromRandom('testnet'); var b2 = new BIP32(b1.extendedPublicKeyString()); b2.extendedPublicKeyString().should.equal(b1.extendedPublicKeyString()); }); it('should generate valid ext pub key for testnet', function() { - var b = new BIP32('testnet'); + var b = new BIP32(); + b.fromRandom('testnet'); b.extendedPublicKeyString().substring(0,4).should.equal('tpub'); }); });