Electrumx protocol

1

The description states:

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.

For example, the legacy Bitcoin address from the genesis block:

1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa has P2PKH script:

76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac with SHA256 hash:

6191c3b590bfcfa0475e877c302da1e323497acf3b42c08d8fa28e364edf018b which is sent to the server reversed as:

8b01df4e368ea28f8dc0423bcf7a4923e3a12d307c875e47a0cfbf90b5c39161 By subscribing to this hash you can find P2PKH payments to that address.

Can anybody explain what are these numbers:

6191c3b590bfcfa0475e877c302da1e323497acf3b42c08d8fa28e364edf018b

8b01df4e368ea28f8dc0423bcf7a4923e3a12d307c875e47a0cfbf90b5c39161

and how to get them?

melaxon

Posted 2019-10-25T14:14:35.903

Reputation: 9

Answers

0

Using the bx command line tool, the Satoshi address:

1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

looks like this decoded (using bx)

$ bx base58-decode 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

outputs:

0062e907b15cbf27d5425399ebf6f0fb50ebb88f18c29b7d93

The first 2 digits (00) is the version number, the last 8 digits (c29b7d93) is the checksum. Leaving 62e907b15cbf27d5425399ebf6f0fb50ebb88f18 as your payload (pubkey in this instance).

Now if I were to make a basic P2PKH locking script with the above pubkey it would look like this:

dup hash160 [62e907b15cbf27d5425399ebf6f0fb50ebb88f18] equalverify checksig

and now encode it in base16:

bx script-encode "dup hash160 [62e907b15cbf27d5425399ebf6f0fb50ebb88f18] equalverify checksig"

result:

76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac

sha256 this:

bx sha256 76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac

result is your number:

6191c3b590bfcfa0475e877c302da1e323497acf3b42c08d8fa28e364edf018b

The second number,

8b01df4e368ea28f8dc0423bcf7a4923e3a12d307c875e47a0cfbf90b5c39161

is serialized in the little-endian (least-significant-byte-first) order. As stated in the link:

When transactions are transmitted over the network or exchanged between applications, they are serialized. Serialization is the process of converting the internal representation of a data structure into a format that can be transmitted one byte at a time, also known as a byte stream. Serialization is most commonly used for encoding data structures for transmission over a network or for storage in a file.

so they're the same number, except byte by byte backwards (I exploded the last 3 bytes of the first to make it apparent).

6191c3b590bfcfa0475e877c302da1e323497acf3b42c08d8fa28e364e df 01 8b
8b 01 df ...

tgunnoe

Posted 2019-10-25T14:14:35.903

Reputation: 191

1Thanks a lot!!! One more question: we derived this number :

from P2PKH:
```62e907b15cbf27d5425399ebf6f0fb50ebb88f18

by adding a prefix 76a914 and suffix 88ac. What are these prefix and suffix? Do they depend on currency or something else? – melaxon 2019-10-30T20:52:45.757

It's not derived from 62e9.. but its making a locking script using that pubkey, then encoding it. So you're seeing the base16 encoding of the script language. For example, bx script-encode "[62e907b15cbf27d5425399ebf6f0fb50ebb88f18]" yields the hash 1462e907b15cbf27d5425399ebf6f0fb50ebb88f18 (14...) and bx script-encode "dup hash160 equalverify checksig" yields 76a988ac. The pubkey is already base16, of course. So there are your numbers.tgunnoe 2019-10-31T12:40:29.673