Revert "Merge pull request #27 from xnova/master"

due to broken tests, moved the changes to branch hd-testnet-support

This reverts commit a4ba59e9ba, reversing
changes made to 36d3d6ebaa.
This commit is contained in:
Wei Lu 2014-02-28 11:52:19 +08:00
parent a4ba59e9ba
commit 09ee406106
2 changed files with 4 additions and 23 deletions

View file

@ -13,8 +13,7 @@ var HDWallet = module.exports = function(seed, network) {
var I = Crypto.HMAC(Crypto.SHA512, seed, 'Bitcoin seed', { asBytes: true }) var I = Crypto.HMAC(Crypto.SHA512, seed, 'Bitcoin seed', { asBytes: true })
this.chaincode = I.slice(32) this.chaincode = I.slice(32)
this.keyVersion = network == 'Bitcoin' ? Address.address_types.prod : Address.address_types.testnet this.priv = new ECKey(I.slice(0, 32).concat([1]), true)
this.priv = new ECKey(I.slice(0, 32).concat([1]), true, this.keyVersion)
this.pub = this.priv.getPub() this.pub = this.priv.getPub()
this.network = network || 'Bitcoin' this.network = network || 'Bitcoin'
this.index = 0 this.index = 0
@ -107,10 +106,10 @@ HDWallet.fromBytes = function(input) {
// 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for // 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for
// public keys, 0x00 + k for private keys) // public keys, 0x00 + k for private keys)
if (type == 'private') { if (type == 'private') {
hd.priv = new ECKey(input.slice(46, 78).concat([1]), true, this.keyVersion) hd.priv = new ECKey(input.slice(46, 78).concat([1]), true)
hd.pub = hd.priv.getPub() hd.pub = hd.priv.getPub()
} else { } else {
hd.pub = new ECPubKey(input.slice(45, 78), true, this.keyVersion) hd.pub = new ECPubKey(input.slice(45, 78), true)
} }
return hd return hd
@ -214,11 +213,10 @@ HDWallet.prototype.derive = function(i) {
// ki = IL + kpar (mod n). // ki = IL + kpar (mod n).
hd.priv = this.priv.add(new ECKey(IL.concat([1]))) hd.priv = this.priv.add(new ECKey(IL.concat([1])))
hd.priv.compressed = true hd.priv.compressed = true
hd.priv.version = this.keyVersion
hd.pub = hd.priv.getPub() hd.pub = hd.priv.getPub()
} else { } else {
// Ki = (IL + kpar)*G = IL*G + Kpar // Ki = (IL + kpar)*G = IL*G + Kpar
hd.pub = this.pub.add(new ECKey(IL.concat([1]), true, this.keyVersion).getPub()) hd.pub = this.pub.add(new ECKey(IL.concat([1])).getPub())
} }
// ci = IR. // ci = IR.

View file

@ -1,5 +1,4 @@
var Wallet = require('../src/wallet.js') var Wallet = require('../src/wallet.js')
var Address = require('../src/address.js')
var assert = require('assert') var assert = require('assert')
describe('Wallet', function() { describe('Wallet', function() {
@ -34,20 +33,4 @@ describe('Wallet', function() {
assert.equal(wallet.derivationMethod, 'public') assert.equal(wallet.derivationMethod, 'public')
}) })
}) })
describe('networkType', function() {
it('ensures that a mainnet Wallet has mainnet child keys (pub and priv)', function() {
var w = Wallet("foobar", {network: "Bitcoin"})
assert(w.getMasterKey().priv.version == Address.address_types['prod'])
w.generateAddress()
assert(w.getPrivateKey(0).priv.version == Address.address_types['prod'])
})
it('ensures that a testnet Wallet has testnet child keys (pub and priv)', function() {
var w = Wallet("foobar", {network: "BitcoinTest"})
assert(w.getMasterKey().priv.version == Address.address_types['testnet'])
w.generateAddress()
assert(w.getPrivateKey(0).priv.version == Address.address_types['testnet'])
})
})
}) })