Skip to content

Commit

Permalink
fix z base58 prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Feb 8, 2019
1 parent 4532805 commit 81cb2c2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/protocol/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ main.keyPrefix = {
// P2WSH
zpubkey: 0x04b24746,
zprivkey: 0x04b2430c,
zpubkey58: 'ypub',
zprivkey58: 'yprv',
zpubkey58: 'zpub',
zprivkey58: 'zprv',

coinType: 0
};
Expand Down
2 changes: 0 additions & 2 deletions lib/wallet/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
47 changes: 47 additions & 0 deletions test/hd-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
));
});
});

0 comments on commit 81cb2c2

Please sign in to comment.