From 02b3a2b5640f3765031361c8d1290acfa2a5f6f5 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Fri, 28 Feb 2014 16:57:44 +0800 Subject: [PATCH] HDWallet prod -> mainnet --- src/hdwallet.js | 8 +++----- src/wallet.js | 2 +- test/address.js | 6 +++--- test/wallet.js | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/hdwallet.js b/src/hdwallet.js index a65c2bd..acc7764 100644 --- a/src/hdwallet.js +++ b/src/hdwallet.js @@ -8,15 +8,13 @@ var ECKey = require('./eckey.js').ECKey var ECPubKey = require('./eckey.js').ECPubKey var Address = require('./address.js') var Network = require('./network') -var mainnet = Network.mainnet.addressVersion -var testnet = Network.testnet.addressVersion var HDWallet = module.exports = function(seed, network) { if (seed === undefined) return var I = Crypto.HMAC(Crypto.SHA512, seed, 'Bitcoin seed', { asBytes: true }) this.chaincode = I.slice(32) - this.network = network || 'prod' + this.network = network || 'mainnet' this.priv = new ECKey(I.slice(0, 32).concat([1]), true, this.getKeyVersion()) this.pub = this.priv.getPub() this.index = 0 @@ -27,7 +25,7 @@ HDWallet.HIGHEST_BIT = 0x80000000 HDWallet.LENGTH = 78 HDWallet.VERSIONS = { - prod: [0x0488B21E, 0x0488ADE4], + mainnet: [0x0488B21E, 0x0488ADE4], testnet: [0x043587CF, 0x04358394] } @@ -236,7 +234,7 @@ HDWallet.prototype.derivePrivate = function(index) { } HDWallet.prototype.getKeyVersion = function() { - return this.network == 'prod' ? mainnet : testnet + return Network[this.network].addressVersion } HDWallet.prototype.toString = HDWallet.prototype.toBase58 diff --git a/src/wallet.js b/src/wallet.js index ead9af6..bf6efe2 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -18,7 +18,7 @@ var Wallet = function (seed, options) { if (!(this instanceof Wallet)) { return new Wallet(seed, options); } var options = options || {} - var network = options.network || 'prod' + var network = options.network || 'mainnet' // HD first-level child derivation method (i.e. public or private child key derivation) // NB: if not specified, defaults to private child derivation diff --git a/test/address.js b/test/address.js index 2a9fb2c..40de751 100644 --- a/test/address.js +++ b/test/address.js @@ -17,7 +17,7 @@ describe('Address', function() { } validate('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'); - // validate('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', 'prod'); + // validate('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', 'mainnet'); validate('mzBc4XEFSdzCDcTxAgf6EZXgsZWpztRhef'); // validate('mzBc4XEFSdzCDcTxAgf6EZXgsZWpztRhef', 'testnet'); @@ -29,7 +29,7 @@ describe('Address', function() { // p2sh addresses validate('3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt'); - // validate('3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt', 'prod'); + // validate('3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt', 'mainnet'); validate('2MxKEf2su6FGAUfCEAHreGFQvEYrfYNHvL7'); // validate('2MxKEf2su6FGAUfCEAHreGFQvEYrfYNHvL7', 'testnet'); }) @@ -43,7 +43,7 @@ describe('Address', function() { invalid('mzBc4XEFSdzCDcTxAgf6EZXgsZWpztRhe'); // invalid('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', 'testnet'); - // invalid('mzBc4XEFSdzCDcTxAgf6EZXgsZWpztRhef', 'prod'); + // invalid('mzBc4XEFSdzCDcTxAgf6EZXgsZWpztRhef', 'mainnet'); // invalid base58 string invalid('%%@'); diff --git a/test/wallet.js b/test/wallet.js index 5617c41..44474ac 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -14,7 +14,7 @@ describe('Wallet', function() { }) it('defaults to Bitcoin mainnet', function() { - assert.equal(wallet.getMasterKey().network, 'prod') + assert.equal(wallet.getMasterKey().network, 'mainnet') }) it('defaults to private derivationMethod', function() { @@ -39,7 +39,7 @@ describe('Wallet', function() { describe('networkType', function() { it('ensures that a mainnet Wallet has mainnet child keys (pub and priv)', function() { - var w = Wallet("foobar", {network: "prod"}) + var w = Wallet("foobar", {network: "mainnet"}) assert(w.getMasterKey().priv.version == mainnet) w.generateAddress() assert(w.getPrivateKey(0).priv.version == mainnet)