how to link the 1XXX address to the 3XXX address without me having to retrieve the Ledger from its stored location.
Things you can not do:
- Get the 1xxx address from 3xxx address
Things you can do:
- Get the 3xxx address from the 1xxx address
1- Get either 1xxx or 3xxx or basically anything else if you have published a signature with a message that you signed (this includes transactions that were spent from that key)!
2Here are the steps for (1)
1. Having the address starting with 1, perform a Base58check_decode on it to get the byte array remove the first byte as it is the version byte. The next 20 bytes are the hash160 (you can also open the address in blockchain.com explorer and it shows you the hash160 result!)
2. Write the "witness script" for the current version of SegWit which is
0x00 0x14
3. Perform HASH160 hash on the result of step 2
RIPEMD160(SHA256())
4. Append the P2SH version byte (=0x05) to the beginning of the result of step 3 and perform a Base58Check_encode on the result
Base58.EncodeWithCheckSum(0x05 || )
=> now you have your P2SH-P2WPKH address that starts with 3.
Here are the steps for (2):
1. Decode your signature (base-64) and throw away the first byte. Then your first 32 bytes are your
r value in little-endian order and the second one is
s.
2. Append the default message to your message (Bitcoin Signed Message:\n) with its length. Compute double SHA256 of it. This is the "message".
3. Recover your public key by knowing (r,s) and message. (I haven't released my library yet to add that as a reference but you should be able to find this option in any library such as OpenSSL that has ECDSA capabilities)
4. Perform HASH160 on the compressed public key as bytes.
5. Feed it to step 2 of above.
This is the reference but in my opinion it is very vague:
https://bitcoincore.org/en/segwit_wallet_dev/