Title: i need Help in learning how p2sh addresses and tx works. Post by: btctousd81 on November 09, 2017, 07:20:30 PM i have had discussion here , https://bitcointalk.org/index.php?topic=2294855
ill resume it here in this thread. i was under impression that address starting with 3 needs more than 1 private keys to send funds. but looks like that is not the case from : https://bitcointalk.org/index.php?topic=2294855.msg23374174 post id 11 : https://bitcointalk.org/index.php?topic=2294855.msg23374174#msg23374174 from 1 sha256 private key i can create WIF private key and public kay pair which is 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm how would i get p2sh address for something like that ? or am i missing again something ., does the p2sh address's private key also falls in int range 1 - 115792089237316195423570985008687907852837564279074904382605163141518161494336 if so then how can i generate a pair ? lets say , so far i have these input : 1 network : Bitcoin mainnet netcode : BTC secret exponent : 1 hex : 1 wif : KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn uncompressed : 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf public pair x : 55066263022277343669578718895168534326250603453777594175500187360389116729240 public pair y : 32670510020758816978083085130507043184471273380659243275938904335757337482424 x as hex : 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 y as hex : 483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 y parity : even key pair as sec : 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 uncompressed : 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\ 483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 hash160 : 751e76e8199196d454941c45d1b3a323f1433bd6 uncompressed : 91b24bf9f5288532960ac687abb035127b1d28a5 Bitcoin address : 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH Bitcoin address uncompressed : 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm Bitcoin segwit address : p2y59b9U5YTUAYEDBr5zwSHFoM8pn3ozAhRD post id 12 : https://bitcointalk.org/index.php?topic=2294855.msg23375280#msg23375280 from 1 sha256 private key i can create WIF private key and public kay pair which is 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm That is NOT a public key. That is a bitcoin address. Specifically, that is an uncompressed key P2PKH bitcoin address. From that SAME WIF private key, you could also generate a compressed key P2PKH bitcoin address: 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH Furthermore, you could create 2160 different P2SH bitcoin addresses. Here are a few of them: 38fEX6RbBBMmpu3nbbuULku1xyrrzqqqnE 3Q2iKGxFppUJEZUTUMmahjwUoLNRqDY9o3 3CZj1DTSHD4vhr3zALL3pgs6acyw1deYDt how would i get p2sh address for something like that ? Build a bitcoin output script. Hash it. Concatenate a byte value of 0x05 in front of the hash value. Encode the result with base64check encoding. or am i missing again something . Probably. does the p2sh address's private key also falls in int range 1 - 115792089237316195423570985008687907852837564279074904382605163141518161494336 if so then how can i generate a pair ? P2SH means "pay to script hash". It doesn't necessarily need a key, but is it is safer to build a script that requires a signature (in which case a signature would be required). so how can i spend this output https://blockchain.info/unspent?active=3LmzcN7f4M8dnvTnoHV3BF8n8i1mLE1udr&format=html Code: { Code: tx_hash_big_endian : 5302959774e4161e2d67c78ff265ac63d763a53ee70643d1e772a2d59a863534 Code: { if i decode tx i get this Code: { what next ? is this correct so far ? Thanks for your time. Title: Re: i need Help in learning how p2sh addresses and tx works. Post by: HCP on November 09, 2017, 11:04:06 PM You have totally missed the point regarding "P2SH" aka "Pay to Script Hash" addresses and how they work.
These addresses are effectively built from hashes of a "redeem script". They are NOT hashes of a public key (generated from the private key). To spend UTXOs controlled by a P2SH, you need to be able to provide the full redeem script, and any signatures, such that when the script is executed, it does not return false. You might want to read here: https://bitcoin.org/en/developer-guide#p2sh-scripts especially this part: When Bob wants to spend the output, he provides his signature along with the full (serialized) redeem script in the signature script. The peer-to-peer network ensures the full redeem script hashes to the same value as the script hash Alice put in her output; it then processes the redeem script exactly as it would if it were the primary pubkey script, letting Bob spend the output if the redeem script does not return false. Also, you should probably note this warning in the developer examples: Warning: You must not lose the redeem script, especially if you don’t have a record of which public keys you used to create the P2SH multisig address. You need the redeem script to spend any bitcoins sent to the P2SH address. If you lose the redeem script, you can recreate it by running the same command above, with the public keys listed in the same order. However, if you lose both the redeem script and even one of the public keys, you will never be able to spend satoshis sent to that P2SH address. Effectively, if you lose the redeem script, you will have NO WAY to spend any coins sent to a P2SH address unless you have some method to recreate it (in the case of a MultiSig Address, if you have all the public keys, you could recreate the redeem script)... you would of course still need any private keys associated with the P2SH address to be able to sign the transaction (if required). Title: Re: i need Help in learning how p2sh addresses and tx works. Post by: pebwindkraft on November 10, 2017, 07:50:02 AM Andreas has a very good explanation on Bitcoin Transactions in his book "Mastering Bitcoin", which is also online readable: file:///Data/Crypto_CCY/Mastering_Bitcoin_2nd.pdf
There is page 141ff for the tx part, and beginning with 151ff he explains the use case for P2SH in detail for multisig purposes. |