When Tezos needs to sign a baking or endorsement operation payload, byte 0 will be a 0x01 for a baking operation or 0x02 for an endorsement operation. Bytes 1-5 in the operation payload contain the chain ID (otherwise known as Network), which can be encoded in base58 using this specification:
let chain_id = "\087\082\000" (* Net(15) *)
The resulting chain ID will be a string like
NetXdQprcVkpaWU (the currently active mainnet chain ID as of Feb. 16th, 2019).
How do I convert the 4-byte field in bytes 1-5 into the base58 encoded Net(15) format using Vitalik's pybitcointools module?
I've tried using the script in
scripts/b58_prefix.py to determine the appropriate magicbyte to pass to the
bitcoin.bin_to_b58check function, but I'm not getting the appropriate result:
$ ./b58_prefix.py Net 4 15 5722583 [87L, 81L, 215L]
Here is my code:
def get_chain_id(self): chainid = bytes.fromhex(self.payload[2:10]) return bitcoin.bin_to_b58check(chainid, magicbyte=5722583)
On zeronet, an endorsement payload looks like this:
3bb717ee is the chain id, but that converts to
Net1BPz7FKbUqsY and it should be
NetXSzLHKwSumh7 on zeronet.