Title: How to generate fingerprint in xpub Post by: DanielAThompson27@gmail.c on July 02, 2024, 03:54:45 AM XPUB : [5183a8d8/86'/1'/0']tpubDDtdVYn7LWnWNUXADgoLGu48aLH4dZ17hYfRfV9rjB7QQK3BrphnrSV6pGAeyfyiAM7DmXPJgRz GoBdwWvRoFdJoMVpWfmM9FCk8ojVhbMS/*
I want to know what the 5183a8d8 in the xpub above is generated based on, is this the fingerprint? Title: Re: How to generate fingerprint in xpub Post by: nc50lc on July 02, 2024, 05:38:15 AM I want to know what the 5183a8d8 in the xpub above is generated based on, is this the fingerprint? Just get the HASH160 of the compressed public key pair of ECDSA Private key part (without the 'Chain Code') of the "Master Private Key".Given that your example has an "Extended Public Key" instead, you wont be able to compute the master fingerprint from it. I'll provide you a valid example: Descriptor (Master Fingerprint: de651e9f): Code: "wpkh([de651e9f/84h/1h/0h]tpubDDDduCzj2qe9kXmasbrKu8CxNG6LoueVcQbeb3mJ9nKC9m2UnwKxGupu83TKhq9EV4RCCXdsf5mVboMh5FBf5AC74PPHXh2fBrP47q7oqHx/1/*) Code: "wpkh(tprv8ZgxMBicQKsPfMMj4bdRMrXr3RMDCc24Pqqa3TAGHBrqgtSQ6mYnxzHLNPzSJD1m8hv3pEjiu3fYdGTcVzc8WNvfChULWAQAqojcimN4D4h/84'/1'/0'/1/*) Now to compute the Master Fingerprint:
Title: Re: How to generate fingerprint in xpub Post by: DanielAThompson27@gmail.c on July 02, 2024, 11:54:19 AM I want to know what the 5183a8d8 in the xpub above is generated based on, is this the fingerprint? Just get the HASH160 of the compressed public key pair of ECDSA Private key part (without the 'Chain Code') of the "Master Private Key".Given that your example has an "Extended Public Key" instead, you wont be able to compute the master fingerprint from it. I'll provide you a valid example: Descriptor (Master Fingerprint: de651e9f): Code: "wpkh([de651e9f/84h/1h/0h]tpubDDDduCzj2qe9kXmasbrKu8CxNG6LoueVcQbeb3mJ9nKC9m2UnwKxGupu83TKhq9EV4RCCXdsf5mVboMh5FBf5AC74PPHXh2fBrP47q7oqHx/1/*) Code: "wpkh(tprv8ZgxMBicQKsPfMMj4bdRMrXr3RMDCc24Pqqa3TAGHBrqgtSQ6mYnxzHLNPzSJD1m8hv3pEjiu3fYdGTcVzc8WNvfChULWAQAqojcimN4D4h/84'/1'/0'/1/*) Now to compute the Master Fingerprint:
const bip39 = require('bip39'); const bitcoinMessage = require('bitcoinjs-message'); const ecc = require('tiny-secp256k1') const { BIP32Factory } = require('bip32') const bip32 = BIP32Factory(ecc) function computeFingerprintFromXPriv() { const mnemonic = "top ritual venue glad soon alcohol annual base tornado invest speak lpke"; const seed = bip39.mnemonicToSeedSync(mnemonic); const network = bitcoin.networks.testnet; const root = bip32.fromSeed(seed, network); const path = "m/86'/1'/0'"; const account = root.derivePath(path); const xpriv = account.toBase58() const extendedPublicKey = account.neutered().toBase58(); console.log(extendedPublicKey) const node = bip32.fromBase58(xpriv,network); const compressedPublicKey = node.publicKey; const hash160 = bitcoin.crypto.hash160(compressedPublicKey); console.log(`Master fingerprint: ${hash160.toString('hex')}`); return hash160.toString('hex').substring(0, 8); } I successfully reproduced it using bitcoinjs of node, but the final result of hash160 does not correspond to the correct result. I don't know why [133a3b35/86h/1h/0h]tpubDCynnv7orn7ymby6QpWMgw9DwJahdDzzgxARwSd4ipdJ9rv5na4ppub8Pv6346pWtigrNMFrnau uCgcsx1SrtaWqNuELKFGTeZYvAVhX3ES/<0;1;9;10> The correct result is 133a3b35, but the final output is de404428. I have confirmed that the extended public key is consistent with the extended public key result above, but the fingerprint is different. I don't know why Title: Re: How to generate fingerprint in xpub Post by: nc50lc on July 02, 2024, 01:19:02 PM I don't know why The problem is: your code is using the "Extended Private Key" at m/86'/1'/0' derivation path.Which has the fingerprint de404428. prvKey: 072439bb6c3508a0b583c781a1fb787d173ea7619866d86a1d32d10be0310fa4It has to be the "Master Private Key" which is the "m" in the derivation path. Title: Re: How to generate fingerprint in xpub Post by: DanielAThompson27@gmail.c on July 02, 2024, 01:32:12 PM I don't know why The problem is: your code is using the "Extended Private Key" at m/86'/1'/0' derivation path.Which has the fingerprint de404428. prvKey: 072439bb6c3508a0b583c781a1fb787d173ea7619866d86a1d32d10be0310fa4It has to be the "Master Private Key" which is the "m" in the derivation path. The extended public key is correct, but the fingerprint is incorrect Title: Re: How to generate fingerprint in xpub Post by: DanielAThompson27@gmail.c on July 02, 2024, 01:41:12 PM Are there other different private keys?
Title: Re: How to generate fingerprint in xpub Post by: DanielAThompson27@gmail.c on July 02, 2024, 01:51:59 PM Thank you for your help. After testing, I successfully tested 133a3b3
Title: Re: How to generate fingerprint in xpub Post by: nc50lc on July 03, 2024, 03:12:02 AM Are there other different private keys? In case this still isn't clear: The other private keys at the lower hierarchy of the derivation path other than "m" (Master Private Key) are its children private keys,And if that children private key is used to derive its own children, it's called "Extended Private Key". e.g.: If we put those terms on the xprv key in your derivation path, it's: m/86'/1'/0' = master_prvKey/extended_prvKey/extended_prvKey/extended_prvKey It has to be the "Master Private Key" which is the "m" in the derivation path. But the final value submitted is [133a3b35/86h/1h/0h]tpubDCynnv7orn7ymby6QpWMgw9DwJahdDzzgxARwSd4ipdJ9rv5na4ppub8Pv6346pWtigrNMFrnau uCgcsx1SrtaWqNuELKFGTeZYvAVhX3ES/The extended public key is correct, but the fingerprint is incorrect The Master Fingerprint represents the Master Private Key and not the private pair (Extended Private Key) of the displayed Extended Public key. (notice that it's positioned where the "m" should be in the derivation path) Thank you for your help. After testing, I successfully tested 133a3b3 Glad that you figured it out. |