Anderson-Juhasc/bip84

Add testnet examples to test.js

Closed this issue · 6 comments

Hi, I had tried to create some testnet addresses. Due to different derivation paths in wasabi and electrum I had some trouble getting it right.
May you could add some testnet examples to test.js

Hi @pbengert you derived from your seed, zprv or zpub?

From zpub.
I think electrum uses m/84‘/1‘/ paths and wasabi uses m/84‘/0‘ paths.
Your tool is the only one I found that can generate addresses from zpub/vpubs alone (without seed or zprv.
At first I wasn‘t sure which path you use when a vpub is provided

@pbengert here have the test with vpub: https://github.com/Anderson-Juhasc/bip84/blob/master/test/test.js#L37

I had problem with Electrum too, I think they don't follow correctly the specification of BIP84 using the seed, but with zpub/vpub works.

On next version I will improve the code to be less confuse.

Following the BIP84 the path for testnet is m/84'/1'/ and mainnet is m/84'/0'/, you can see these references:
https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki
https://github.com/satoshilabs/slips/blob/master/slip-0044.md

Thanks for looking into it. Maybe some of my confusion came from not being sure about the derivation path.
If I take the mnemonic: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
it will create a testnet zpub of (from https://iancoleman.io/bip39/):
vpub5Y6cjg78GGuNLsaPhmYsiw4gYX3HoQiRBiSwDaBXKUafCt9bNwWQiitDk5VZ5BVxYnQdwoTyXSs2JHRPAgjAvtbBrf8ZhDYe2jWAqvZVnsc

This generates (https://iancoleman.io/bip39/)
m/84'/1'/0'/0/0 | tb1q6rz28mcfaxtmd6v789l9rrlrusdprr9pqcpvkl
m/84'/1'/0'/0/1 | tb1qd7spv5q28348xl4myc8zmh983w5jx32cjhkn97
m/84'/1'/0'/1/0 | tb1q9u62588spffmq4dzjxsr5l297znf3z6j5p2688
m/84'/1'/0'/1/1 | tb1qkwgskuzmmwwvqajnyr7yp9hgvh5y45kg8wvdmd

The same zpub added in test.js will lead to:
Account 1, root = m/84'/0'/0'
Account 1 xpub: vpub5Y6cjg78GGuNLsaPhmYsiw4gYX3HoQiRBiSwDaBXKUafCt9bNwWQiitDk5VZ5BVxYnQdwoTyXSs2JHRPAgjAvtbBrf8ZhDYe2jWAqvZVnsc
Account 1, first receiving address = m/84'/0'/0'/0/0
Pubkey: 02e7ab2537b5d49e970309aae06e9e49f36ce1c9febbd44ec8e0d1cca0b4f9c319
Address: tb1q6rz28mcfaxtmd6v789l9rrlrusdprr9pqcpvkl
Account 1, second receiving address = m/84'/0'/0'/0/1
Pubkey: 03eeed205a69022fed4a62a02457f3699b19c06bf74bf801acc6d9ae84bc16a9e1
Address: tb1qd7spv5q28348xl4myc8zmh983w5jx32cjhkn97
Account 1, first change address = m/84'/0'/0'/1/0
Pubkey: 035d49eccd54d0099e43676277c7a6d4625d611da88a5df49bf9517a7791a777a5
Address: tb1q9u62588spffmq4dzjxsr5l297znf3z6j5p2688
Account 1, second change address = m/84'/0'/0'/1/1
Pubkey: 03f37f9607be4661510885f4f960954dadfc0af91ea722fe2935ca39c1e54c2948
Address: tb1qkwgskuzmmwwvqajnyr7yp9hgvh5y45kg8wvdmd

So I think you could change the console.log of the testnet derivation path, because you get the keys for m/84'/1'/0'/0/0 but test.js prints it as m/84'/0'/0'/0/0
This makes clear that the testnet derivation used by your program is m/84'/1'/
Maybe something like this

var account1 = new BIP84.fromZPub(zpub)

console.log("Account 1 Testnet, root = m/84'/1'/0'");
console.log('Account 1 Testnet xpub:', account1.getAccountPublic());
console.log('\n');

console.log("Account 1 Testnet, first receiving address = m/84'/1'/0'/0/0");
console.log('Pubkey:', account1.getPublicKey(0))
console.log('Address:', account1.getAddress(0))
console.log('\n');

console.log("Account 1 Testnet, second receiving address = m/84'/1'/0'/0/1");
console.log('Pubkey:', account1.getPublicKey(1))
console.log('Address:', account1.getAddress(1))
console.log('\n');

console.log("Account 1 Testnet, first change address = m/84'/1'/0'/1/0");
console.log('Pubkey:', account1.getPublicKey(0, true))
console.log('Address:', account1.getAddress(0, true))
console.log('\n');

console.log("Account 1 Testnet, second change address = m/84'/1'/0'/1/1");
console.log('Pubkey:', account1.getPublicKey(1, true))
console.log('Address:', account1.getAddress(1, true))
console.log('\n');

You right, I will consider in the next version.