After some hours lost I have realized that the library gives the public keys in different formats.
const root = bip32.fromSeed(seed, network);
const publicKey = root.derivePath("m/49'/0'/0'/0/0").publicKey
This publicKey is a Buffer containing a Unit8Array, while
let hDMaster = bip32.fromSeed( seed, network)
let xpub = hDMaster.derivePath(t"m/49'/0'/0'/0").neutered().toBase58()
...
let node = bip32.fromBase58(xpub, network)
let publicKey = node.derivePath("0").publicKey
This publicKey key is just a Unit8Array
When using this 2nd publicKey to compose a script it failed when compiling the script.
Doing a console.log(publicKey) showed the exact same thing for both pubkeys, but console.log(JSON.stringfy(publicKey)) showed the subtle difference.
To make the 2nd pubkey work in a script I had to: publicKey = new Buffer(publicKey) which worked ok when compiling.
Cannot reproduce
Hi.
You don't get different results when displaying: console.log(JSON.stringify(publicKey) for both pubKeys?
I clearly do.
Thanks.
const bip32 = require('./')
const seed = Buffer.alloc(32, 1)
const a = bip32.fromSeed(seed)
.derivePath("m/49'/0'/0'/0/0")
const b = bip32.fromSeed(seed)
.derivePath("m/49'/0'/0'/0").neutered()
const xpub = b.toBase58()
const p = bip32.fromBase58(xpub)
.derivePath('0')
console.log(a.publicKey)
console.log(b.publicKey)
console.log(p.publicKey)
console.log(JSON.stringify(a.publicKey))
console.log(JSON.stringify(b.publicKey))
console.log(JSON.stringify(p.publicKey))
Node
<Buffer 02 b6 bc 15 b3 35 02 f0 0d e8 65 70 83 e4 ac b9 85 02 8a a7 15 dc 64 81 cd 3b 7b eb bb 0e 4e f6 5d>
<Buffer 02 2c 0a ca 80 2a 22 8c 7d 29 36 de 18 6d ec fb ff e8 f6 e5 c1 c0 49 a5 22 28 23 6f 44 74 20 01 0f>
<Buffer 02 b6 bc 15 b3 35 02 f0 0d e8 65 70 83 e4 ac b9 85 02 8a a7 15 dc 64 81 cd 3b 7b eb bb 0e 4e f6 5d>
{"type":"Buffer","data":[2,182,188,21,179,53,2,240,13,232,101,112,131,228,172,185,133,2,138,167,21,220,100,129,205,59,123,235,187,14,78,246,93]}
{"type":"Buffer","data":[2,44,10,202,128,42,34,140,125,41,54,222,24,109,236,251,255,232,246,229,193,192,73,165,34,40,35,111,68,116,32,1,15]}
{"type":"Buffer","data":[2,182,188,21,179,53,2,240,13,232,101,112,131,228,172,185,133,2,138,167,21,220,100,129,205,59,123,235,187,14,78,246,93]}
Firefox (via browserify)
Uint8Array(33) [ 2, 182, 188, 21, 179, 53, 2, 240, 13, 232, … ]
Uint8Array(33) [ 2, 44, 10, 202, 128, 42, 34, 140, 125, 41, … ]
Uint8Array(33) [ 2, 182, 188, 21, 179, 53, 2, 240, 13, 232, … ]
{"type":"Buffer","data":[2,182,188,21,179,53,2,240,13,232,101,112,131,228,172,185,133,2,138,167,21,220,100,129,205,59,123,235,187,14,78,246,93]} bundle.js:17597:1
{"type":"Buffer","data":[2,44,10,202,128,42,34,140,125,41,54,222,24,109,236,251,255,232,246,229,193,192,73,165,34,40,35,111,68,116,32,1,15]} bundle.js:17598:1
{"type":"Buffer","data":[2,182,188,21,179,53,2,240,13,232,101,112,131,228,172,185,133,2,138,167,21,220,100,129,205,59,123,235,187,14,78,246,93]}
What is your environment?
Hi.
After running your code on the browser I think I know now what's going on.
I am using meteor -vue and the pubkey is created on the server and sent to the client (all transparently by meteor). In the serialization process the buffer part is lost and it's deserialized as an unit8array.
So the library is doing its job properly but Meteor did some messed up with the data.
Thanks for your help.
This issue, and issues like this issue, are making me hate javascript a little bit every day... lol...
Let's all switch to Go. That sounds like a good language.