Skip to content

Latest commit

 

History

History
73 lines (52 loc) · 2.97 KB

TRANSACTION.md

File metadata and controls

73 lines (52 loc) · 2.97 KB

Hathor Transaction

Overview

The hathor transaction serialized

Structure

Transaction

Field Size (bytes) Description
version_byte 1 Version byte for the transaction apdu protocol
change_info var Bytes representing the existence of a change output and the bip32 path of the change address
tx_version 2 TX Version, indicates this is a transaction, block, etc.
num_tokens 1 Number of token UIDs present on the data below
num_inputs 1 Number of inputs present on the data below
num_outputs 1 Number of outputs present on the data below
tokens 32*num_tokens list of Token UIDs
inputs 35*num_inputs list of Inputs
outputs var List of Outputs

Obs: The version_byte indicates how the transaction is serialized, especially the change information.

Change info

Field Size Description
num_change_outputs 1 byte The number of change outputs on this tx.
change_output_info var list of change outputs info.

Change Output info

Field Size Description
change_output_index 1 byte the index of the change output
change_bip32_path_length 1 byte The length of the bip32 path
change bip32 path var (4*bip32_path_length) an array of 32bit unsigned integers of the path indexes

Obs: bip32 paths have a hard depth limitation of 5, so the max value of the change output info is 22 bytes.

We don't have to indicate which token this is a change for since the output has that data. We don't validate if there is a max of 1 change per token.

TX Output

Field Size (bytes) Description
value 4 or 8 value of the output, first bit indicates if it's 4 or 8 bytes.
If 0: unsigned 32bit integer
If 1: value is the negative of the signed 64 bit integer
token_data 1 token data
script_length 2 length of the script
script var (script_length) script of the output

Obs: currently only P2PKH is supported for the script

TX Input

Field Size (bytes) Description
TX id 32 id of the TX the input belongs to
input index 1 output index of the input on the TX being spent
data length 2 length of the data that should follow, but since we are using these bytes as sighash_all, we do not send this data, and this MUST be 0.

Signature

Deterministic ECDSA (RFC 6979) is used to sign transaction on the SECP-256k1 curve. The SDK call used should be cx_ecdsa_sign of the message. The message is everything after the change_info (i.e. the sighash_all).

Address format

Hathor addresses are generated by b58 encoding the hash160 of the compressed pubkey. For validation, verifying the pubkey hash is enough, but for user confirmation the address must be b58 encoded.