Bitcoin Forum
August 15, 2024, 04:27:41 PM *
News: Latest Bitcoin Core release: 27.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Get pubKey for an address using bitcoin-cli  (Read 45 times)
minerdole (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
July 09, 2024, 11:10:18 AM
 #1

Howdy tech folks,

I would greatly value your expertise in retrieving my wallet's public key for a given address.

What I currently understand:
  • The scriptPubKey no longer contains the public key for Taproot addresses.
  • The bitcoin-cli commands `validateaddress` and `getaddressinfo` no longer return the pubKey.
  • The addresses in question have been receive addresses so far and have not submitted any transactions from which I could retrieve the pubKey.

The only way I can currently identify is to dump the private key from bitcoin-cli, import it into bitcoin-js, and then get the pubKey. But I really, really want to avoid this.

I appreciate any advice or hints.

Thanks a lot! BTC

nc50lc
Legendary
*
Offline Offline

Activity: 2506
Merit: 5933


Self-proclaimed Genius


View Profile
July 09, 2024, 01:04:20 PM
 #2

The only way I can currently identify is to dump the private key from bitcoin-cli -snip-
Since you're talking about a wallet with TapRoot, it must be a descriptor wallet.
So, how are you able to export its private key? I'm curious.

Anyways, you may use getaddressinfo, then take note of the extended public key in its "parent_desc" and the derivation path's internal/external chain index.
(the number after the "/" on its right, '0' for receiving addresses, '1' for change addresses)
And also the "address_index" in its descriptor - "desc:". (the last digit on its derivation path)
Then use bitcoin-js or other tool to derive the public key from the xpub.

e.g. (RegTest):
getaddressinfo bcrt1pg9aez39kk2w5qucfy5da340amz3ajzug7zs4xetpkhzcr5maxwgqfw43k0
...
"desc": "tr([de651e9f/86h/1h/0h/0/3]6dd8531afdb9ce153cd8a053cc94e125ed7efc2be0e2c451b57104330274a595)#hskruc03",
"parent_desc": "tr([de651e9f/86h/1h/0h]tpubDCjhgDSSsWLW5xD6nFUQswRHkdJrdAmfJqu8jewwoWYgXvvdA5jr2qqEZc38UVynn1zPMJv7vw8 hPXuhfd7yZhuLh5Fbq2mPb4CVrcE5To4/0/*)#l6qxnyxd",
...

From the example; (external) chain index = 0 & address_index = 3.
So derive the public key at tpub/0/3 which should be the public key of the address.
Public key: 036dd8531afdb9ce153cd8a053cc94e125ed7efc2be0e2c451b57104330274a595 (I used IanColeman's BIP39 tool for this example, I don't use bitcoin-js)

█▀▀▀











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











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
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!