Bitcoin Forum
July 03, 2024, 01:21:12 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to generate fingerprint in xpub  (Read 60 times)
DanielAThompson27@gmail.c (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
July 02, 2024, 03:54:45 AM
 #1

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?
nc50lc
Legendary
*
Offline Offline

Activity: 2464
Merit: 5759


Self-proclaimed Genius


View Profile
July 02, 2024, 05:38:15 AM
Merited by pooya87 (4)
 #2

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/*)
Descriptor with Master Private Key (private version of the above):
Code:
"wpkh(tprv8ZgxMBicQKsPfMMj4bdRMrXr3RMDCc24Pqqa3TAGHBrqgtSQ6mYnxzHLNPzSJD1m8hv3pEjiu3fYdGTcVzc8WNvfChULWAQAqojcimN4D4h/84'/1'/0'/1/*)

Now to compute the Master Fingerprint:
  • Decode the base58 tprv above and get the private key (teal colored):
    04358394
    00
    00000000
    00000000
    f8f8553de856d4e29504423da00dad4067296c782213919c64bb98f41752c66f
    00
    56a85c89f1df3bd53d00723768357bcb02930b366c13e97170133c12c4344b1f
    f9f0b48e
  • Compute its Compressed Public key pair:
    02cd9776ca76833f399a5c0fa7af51edca0b1edaa24a09accc3f7568964fdbb0fc

  • Compute the HASH160 of the above; RIPEMD160[SHA256(PubKey)]:
    de651e9fb4c50f68fe4be1ca9d6bb563a78307ce

  • Get the first four Bytes of the above (check if it's the same as the Master Fingerprint):
    de651e9f

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
DanielAThompson27@gmail.c (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
July 02, 2024, 11:54:19 AM
Last edit: July 02, 2024, 02:56:35 PM by DanielAThompson27@gmail.c
 #3

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/*)
Descriptor with Master Private Key (private version of the above):
Code:
"wpkh(tprv8ZgxMBicQKsPfMMj4bdRMrXr3RMDCc24Pqqa3TAGHBrqgtSQ6mYnxzHLNPzSJD1m8hv3pEjiu3fYdGTcVzc8WNvfChULWAQAqojcimN4D4h/84'/1'/0'/1/*)

Now to compute the Master Fingerprint:
  • Decode the base58 tprv above and get the private key (teal colored):
    04358394
    00
    00000000
    00000000
    f8f8553de856d4e29504423da00dad4067296c782213919c64bb98f41752c66f
    00
    56a85c89f1df3bd53d00723768357bcb02930b366c13e97170133c12c4344b1f
    f9f0b48e
  • Compute its Compressed Public key pair:
    02cd9776ca76833f399a5c0fa7af51edca0b1edaa24a09accc3f7568964fdbb0fc

  • Compute the HASH160 of the above; RIPEMD160[SHA256(PubKey)]:
    de651e9fb4c50f68fe4be1ca9d6bb563a78307ce

  • Get the first four Bytes of the above (check if it's the same as the Master Fingerprint):
    de651e9f
const bitcoin = require('bitcoinjs-lib');
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, Cool;
}

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
nc50lc
Legendary
*
Offline Offline

Activity: 2464
Merit: 5759


Self-proclaimed Genius


View Profile
July 02, 2024, 01:19:02 PM
 #4

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: 072439bb6c3508a0b583c781a1fb787d173ea7619866d86a1d32d10be0310fa4
pubKey: 0330104bf9b299b41c775842dc22f26b420ce36e0787104bbc6ce2472f3447f88b
SHA256: 459c1f0d9f68e849dc245a8910763a0752358f2eb9fc3b797032ddc3917e1502
RIPEMD160: de4044283b4e32a35e1adfe6001a24eaf3fa8f76
Fingerprint: de404428
It has to be the "Master Private Key" which is the "m" in the derivation path.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
DanielAThompson27@gmail.c (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
July 02, 2024, 01:32:12 PM
 #5

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: 072439bb6c3508a0b583c781a1fb787d173ea7619866d86a1d32d10be0310fa4
pubKey: 0330104bf9b299b41c775842dc22f26b420ce36e0787104bbc6ce2472f3447f88b
SHA256: 459c1f0d9f68e849dc245a8910763a0752358f2eb9fc3b797032ddc3917e1502
RIPEMD160: de4044283b4e32a35e1adfe6001a24eaf3fa8f76
Fingerprint: de404428
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
DanielAThompson27@gmail.c (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
July 02, 2024, 01:41:12 PM
 #6

Are there other different private keys?
DanielAThompson27@gmail.c (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
July 02, 2024, 01:51:59 PM
 #7

Thank you for your help. After testing, I successfully tested 133a3b3
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!