diff --git a/lib/protocol/networks.js b/lib/protocol/networks.js index 2d8cd5dc1..c11abe0e0 100644 --- a/lib/protocol/networks.js +++ b/lib/protocol/networks.js @@ -429,8 +429,8 @@ main.keyPrefix = { // P2WSH zpubkey: 0x04b24746, zprivkey: 0x04b2430c, - zpubkey58: 'ypub', - zprivkey58: 'yprv', + zpubkey58: 'zpub', + zprivkey58: 'zprv', coinType: 0 }; diff --git a/lib/wallet/account.js b/lib/wallet/account.js index fcfbc3924..a7687bc04 100644 --- a/lib/wallet/account.js +++ b/lib/wallet/account.js @@ -105,8 +105,6 @@ class Account { if (options.purpose != null) { assert(common.purposes[options.purpose] !== undefined, 'Bad purpose'); this.purpose = options.purpose; - } else { - this.purpose = 'x'; } if (this.purpose === 'y' || this.purpose === 'z') diff --git a/test/hd-test.js b/test/hd-test.js index 89fdab703..7d13cd2c5 100644 --- a/test/hd-test.js +++ b/test/hd-test.js @@ -156,4 +156,51 @@ describe('HD', function() { base58Equal(zprv.toBase58('main'), vectors.xyz.z.zprv); base58Equal(zpub.toBase58('main'), vectors.xyz.z.zpub); }); + + it('should test for base58 network matches', () => { + assert(HD.fromBase58( + 'xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhawA7d4' + + 'R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj', + 'main' + )); + + assert(HD.fromBase58( + 'ypub6Ww3ibxVfGzLrAH1PNcjyAWenMTbbAosGNB6VvmSEgytSER9az' + + 'LDWCxoJwW7Ke7icmizBMXrzBx9979FfaHxHcrArf3zbeJJJUZPf663zsP', + 'main' + )); + + assert(HD.fromBase58( + 'zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhX' + + 'NfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs', + 'main' + )); + + assert(HD.fromBase58( + 'zprvAWgYBBk7JR8Gjrh4UJQ2uJdG1r3WNRRfURiABBE3RvMXYSrRJL' + + '62XuezvGdPvG6GFBZduosCc1YP5wixPox7zhZLfiUm8aunE96BBa4Kei5', + 'main' + )); + + // oops wrong network + let err = null; + try { + assert(HD.fromBase58( + 'tprv8gRrNu65W2Msef2BdBSUgFdRTGzC8EwVXnV7UGS3faeXtuMVtG' + + 'fEdidVeGbThs4ELEoayCAzZQ4uUji9DUiAs7erdVskqju7hrBcDvDsdbY', + 'main' + )); + } catch (e) { + err = e; + } + assert(err); + assert.strictEqual(err.message, 'Network mismatch for xprivkey.'); + + // there we go + assert(HD.fromBase58( + 'tprv8gRrNu65W2Msef2BdBSUgFdRTGzC8EwVXnV7UGS3faeXtuMVtG' + + 'fEdidVeGbThs4ELEoayCAzZQ4uUji9DUiAs7erdVskqju7hrBcDvDsdbY', + 'testnet' + )); + }); });