Title: Electrumx protocol Post by: ilib on October 26, 2019, 12:55:27 PM The description (https://electrumx.readthedocs.io/en/latest/protocol-basics.html#script-hashes) states:
Code: A script hash is the hash of the binary bytes of the locking script (ScriptPubKey), expressed as a hexadecimal string. The hash function to use is given by the ?hash_function? member of server.features() (currently sha256() only). Like for block and transaction hashes, when converting the big-endian binary hash to a hexadecimal string the least-significant byte appears first, and the most-significant byte last. 6191c3b590bfcfa0475e877c302da1e323497acf3b42c08d8fa28e364edf018b 8b01df4e368ea28f8dc0423bcf7a4923e3a12d307c875e47a0cfbf90b5c39161 and how to get them? Title: Re: Electrumx protocol Post by: BrewMaster on October 26, 2019, 02:41:06 PM you have an address that you want to check, each address (based on its type) corresponds to a certain type of script in this example the address starting with 1 is a P2PKH address so the script of it is DUP HASH160 <hash> EQUALVERIFY CHECKSIG
so you start from the address: 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa base58decodecheck to get the hash (after removing the version byte) 62e907b15cbf27d5425399ebf6f0fb50ebb88f18 build the script from the hash 76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac now you hash it using the hash you specified for the server (it is apparently SHA256 by default) Code: SHA256('76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac') = Code: 8b01df4e368ea28f8dc0423bcf7a4923e3a12d307c875e47a0cfbf90b5c39161 Title: Re: Electrumx protocol Post by: ilib on October 26, 2019, 06:25:01 PM Quote now you hash it using the hash you specified for the server (it is apparently SHA256 by default) Code: Code: SHA256('76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac') = But I failed to get it using sha256. For example in PHP: Code: hash('sha256', '76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac') 5f3f330fccb56d6b43f19b7e235f5b146ac92add3a3ab99380a39e7f7406959b Title: Re: Electrumx protocol Post by: BrewMaster on October 26, 2019, 07:09:36 PM Quote now you hash it using the hash you specified for the server (it is apparently SHA256 by default) Code: Code: SHA256('76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac') = But I failed to get it using sha256. For example in PHP: Code: hash('sha256', '76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac') 5f3f330fccb56d6b43f19b7e235f5b146ac92add3a3ab99380a39e7f7406959b it is because you are reading "76a9..." as an ASCII (or UTF8) string not a hexadecimal string. you should convert it to its byte array representation (0x76=118, 0xa9=169,...) and then hash that. also you shouldn't be working with hex in first place. your code must convert the address (1A1zP1....) to bytes then add the extra bytes that come from the script to it and the pass that to SHA256 and then reverse the result (bytes) and send that. that is both faster and has less chance of having any errors like this. after all that you can convert the final result to hex if you wanted. Title: Re: Electrumx protocol Post by: ilib on October 27, 2019, 09:59:21 AM Thanks a lot!
I finally managed to hash it like this: Code: $p2pkh = sprintf("76a914%s88ac", $hash160); |