2

lets say i have sha256 Private Key Hexadecimal Format

0000000000000000000000000000000000000000000000000000000000000001

how can i get P2SH address and its corresponding WIF private KEY ?

by P2SH i mean P2SH-P2WPKH address starting with 3. are these called 1-of-1 multisig address ?

2

It's the same b58check(HASH160), but you're hashing a script.

The script for 1-to-1 multisig P2SH addresses is OP_0 hash160(pubkey).

So your address would be b58check(hash160('\x00\x14' + hash160(pubkey))).

Long story short:

1) WIF to pubkey:

secret = b58check_decode(WIF)
pubkey = ECKey(secret).pubkey

2) pubkey to P2PKH (legacy address):

addrtype = 0
addr = b58check(addrtype, hash160(pubkey))

3) pubkey to P2SH (1-to-1 multisig address):

addrtype = 5
addr = b58check(addrtype, hash160('\x00\x14' + hash160(pubkey)))    

where hash160(x) = ripemd160(sha256(x))

That's, basically, it. Also see https://github.com/joric/pywallet/issues/1

Regarding 32-byte secret to WIF conversion - bitcoin core doesn't tell apart different WIF's it's just b58check(secret) type 0x80. Importprivkey command generates 3 different addresses - P2PKH, P2SH and BECH32 from the same secret, and you can reexport-reimport the secret anytime.

1

Private keys give public keys, which can give bitcoin addresses starting with a 1. But a P2SH address (starting with a 3) is simply the hash of a script, and that script could be almost anything, it isn't usually associated with a single public/private key. Perhaps you mean P2SH-P2WPKH? In that case you could read something like this: https://bitcoincore.org/en/segwit_wallet_dev/ (specifically the section called 'Creation of P2SH-P2WPKH Address'). Otherwise maybe something like a 1-of-1 multisig address or simple P2SH encoding a normal P2PK/P2PKH redeem script? I'll update this answer if you clarify exactly what you mean :)

  • 1-of-1 multisig address. – AMB Oct 15 '17 at 11:36
  • Please update your answer on how to compute the P2SH address (starting with a 3) from scriptPubKey. – Jus12 Dec 16 '17 at 16:04
  • @Jus12 that is not what the question asked. If you have a new question, please ask it separately :) – MeshCollider Dec 16 '17 at 19:31
0

next to bitcoin.org, adresses are structured this way: https://en.bitcoin.it/wiki/Protocol_specification#Addresses

and a detailed step-by-step explanation: https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses

This allowed me to understand more detailed: http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html

I usually use this site to verify results: http://gobittest.appspot.com/Address

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.