diff --git a/BIP32.js b/BIP32.js index 64d602179..3e0d5e54f 100644 --- a/BIP32.js +++ b/BIP32.js @@ -21,6 +21,24 @@ var secp256k1_n = new bignum("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBF var secp256k1_G = new bignum("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16); //x coordinate var BIP32 = function(bytes) { + if (bytes == 'mainnet' || bytes == 'livenet') + this.version = BITCOIN_MAINNET_PRIVATE; + else if (bytes == 'testnet') + this.version = BITCOIN_TESTNET_PRIVATE; + + if (bytes == 'mainnet' || bytes == 'livenet' || bytes == 'testnet') { + this.depth = 0x00; + this.parent_fingerprint = new Buffer([0, 0, 0, 0]); + this.child_index = new Buffer([0, 0, 0, 0]); + this.chain_code = Key.generateSync().private; + this.eckey = Key.generateSync(); + this.has_private_key = true; + this.pubKeyHash = coinUtil.sha256ripe160(this.eckey.public); + this.build_extended_public_key(); + this.build_extended_private_key(); + return; + } + // decode base58 if (typeof bytes === "string") { var decoded = base58.decode(bytes); diff --git a/test/test.BIP32.js b/test/test.BIP32.js index 132cd5347..95d7ae081 100644 --- a/test/test.BIP32.js +++ b/test/test.BIP32.js @@ -40,6 +40,16 @@ 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'); + should.exist(bip32); + }); + it('should initialize test vector 1 from the extended public key', function() { var bip32 = new BIP32(vector1_m_public); should.exist(bip32);