HDWallet prod -> mainnet
This commit is contained in:
parent
eaf84c4283
commit
02b3a2b564
4 changed files with 9 additions and 11 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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('%%@');
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue