Bitcoin Forum
May 10, 2024, 11:30:44 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Creation of <20-byte hash of redeem Script> in a P2SH Transaction  (Read 934 times)
topflankerkiller (OP)
Newbie
*
Offline Offline

Activity: 11
Merit: 0


View Profile
January 04, 2016, 05:33:42 PM
 #1

Hello.

According to this example:

Redeem Script: 2 PubKey1 PubKey2 PubKey3 PubKey4 PubKey5 5 OP_CHECKMULTISIG

Locking Script: OP_HASH160 <20-byte hash of redeem script> OP_EQUAL

Unlocking Script: Sig1 Sig2 redeem script

I want to calculate the <20-byte hash of redeem script> with BitcoinJ but i don't know how to do it.

This <20-byte hash of redeem script> is the result of :

RIPEMD160(SHA256(PubKey1.getPublicKeyAsHex() || PubKey2.getPublicKeyAsHex() || PubKey3.getPublicKeyAsHex() || PubKey4.getPublicKeyAsHex() || PubKey5.getPublicKeyAsHex())) or RIPEMD160(SHA256(input))Huh

The input (which is String type) from above is the concatenation of each public key of all participants in the redeem script.

And if <20-byte hash of redeem script> it is not the result that i mentioned above...how can i estimate this hash with BitcoinJ?

Thanks in advance.
1715340644
Hero Member
*
Offline Offline

Posts: 1715340644

View Profile Personal Message (Offline)

Ignore
1715340644
Reply with quote  #2

1715340644
Report to moderator
1715340644
Hero Member
*
Offline Offline

Posts: 1715340644

View Profile Personal Message (Offline)

Ignore
1715340644
Reply with quote  #2

1715340644
Report to moderator
1715340644
Hero Member
*
Offline Offline

Posts: 1715340644

View Profile Personal Message (Offline)

Ignore
1715340644
Reply with quote  #2

1715340644
Report to moderator
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715340644
Hero Member
*
Offline Offline

Posts: 1715340644

View Profile Personal Message (Offline)

Ignore
1715340644
Reply with quote  #2

1715340644
Report to moderator
1715340644
Hero Member
*
Offline Offline

Posts: 1715340644

View Profile Personal Message (Offline)

Ignore
1715340644
Reply with quote  #2

1715340644
Report to moderator
1715340644
Hero Member
*
Offline Offline

Posts: 1715340644

View Profile Personal Message (Offline)

Ignore
1715340644
Reply with quote  #2

1715340644
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
January 04, 2016, 09:56:47 PM
 #2

The hash is the hash of the redeem script encoded as hex bytes. You can build a script using the ScriptBuilder class and then get the bytes of the script and perform the sha256 and ripemd160 hashes on those bytes to get the hash.

topflankerkiller (OP)
Newbie
*
Offline Offline

Activity: 11
Merit: 0


View Profile
January 05, 2016, 12:26:46 PM
 #3

Thanks for the help!

I created the redeem Script as follows:
Script redeemScript=scriptbuilder.createRedeemScript(2, pubkeys);

Then in order to get the bytes of the script i used the :
byte[] bytesFromScript=myScript.getProgram();

and finally in got the hash of the Script using the  RIPEMD160(SHA256(bytesFromScript)) procedure.

The Script class doesn't have any other function to get the bytes so i used the getProgram() function.
Am i wrong to this?


 
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
January 05, 2016, 12:35:11 PM
 #4

Thanks for the help!

I created the redeem Script as follows:
Script redeemScript=scriptbuilder.createRedeemScript(2, pubkeys);

Then in order to get the bytes of the script i used the :
byte[] bytesFromScript=myScript.getProgram();

and finally in got the hash of the Script using the  RIPEMD160(SHA256(bytesFromScript)) procedure.

The Script class doesn't have any other function to get the bytes so i used the getProgram() function.
Am i wrong to this?


 
That should be right.

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!