Minter Docsv3.3.0
Developers / Test vectors and porting
Developers

Test vectors and porting

Structure of test-vectors.json, canonical Minter v3.3.0 RLP rules, and self-contained signing implementations in Python and Rust.

test-vectors.json contains Minter v3.3.0 serialization and signing regression fixtures: 37 signed active transaction vectors (activeVectors), 1 RLP data vector for inactive opcode 0x13 PRICE_VOTE (inactiveRlpVectors), a weighted multisig vector (multisigVectors), two-key check vectors (checkVectors), and non-canonical RLP test cases (negativeRlpVectors). @minter-network/tx-core generates these fixtures (when cross-checked with minter-go-node, entries carry goNodeVerified; otherwise treat the suite as regression fixtures rather than an independent external oracle).

Structure of /test-vectors.json and verification stages

Each activeVectors entry provides typed input fields, envelope metadata, and hex outputs for four sequential encoding stages:

json
{
  "id": "tx-0x01-send",
  "txTypeCode": 1,
  "txTypeHex": "0x01",
  "txTypeName": "SEND",
  "envelope": {
    "nonce": "1",
    "chainId": 1,
    "gasPrice": 1,
    "gasCoin": 0,
    "payloadUtf8": "invoice:2026-11",
    "signatureType": 1
  },
  "input": {
    "coinId": 0,
    "to": "Mx6fac4d18c912343bf86fa7049364dd4e424ab9c0",
    "valuePip": "12500000000000000000"
  },
  "privateKeyHex": "1ab42cc412b618bdea3a599e3c9bae199ebf030895b039e9db1e30dafb12b727",
  "signerAddress": "Mx9858effd232b4033e47d90003d41ec34ecaeda94",
  "dataBytesHex": "0xdf80946fac4d18c912343bf86fa7049364dd4e424ab9c088ad78ebc5ac620000",
  "signingHash": "0x4fdf01449f56ca56b2310e91e17d5cf07d930578ccf620d2354b0bf8edb47617",
  "signedRawTxHex": "0xf87f0101018001a0df80946fac4d18c912343bf86fa7049364dd4e424ab9c088ad78ebc5ac6200008f696e766f6963653a323032362d31318001b845f8431ba04acb879e7e90f8475c553a23e4c2f11c7ba71ff8a36cc4ae15dc1a74f2fdc511a04da0b3d26cde48103cde55dd74e9d867e539cbbb8516f74cb3dd085b4dc951de",
  "txHash": "Mte53eeda7a4268983a7ea5481cf150ae9d6ef76c1e497f7489d99805a812b7011"
}

Test each top-level array according to its scope:

  1. activeVectors (37 entries): assert dataBytesHex, signingHash, signedRawTxHex, and txHash in sequence.
  2. inactiveRlpVectors (0x13 PRICE_VOTE): assert dataBytesHex encoding and decoding only (0x13 has no registered handler in v3.3.0 and no signedRawTxHex).
  3. multisigVectors and checkVectors: assert SignatureMulti (0x02) assembly and leading-zero stripping on the check Lock field.
  4. negativeRlpVectors: assert rejection at the target decoder layer (for example, raw byte 0x00 is a valid single-byte RLP string and fails specifically when decoded as an unsigned integer).

Canonical 10-field RLP envelope and byte rules

Every signed Minter v3.3.0 transaction encodes as an outer RLP list of 10 items (up to 16_144 bytes total):

text
SignedTxRLP = RLP([
  0: nonce,          // uint64  (big-endian with no leading zero bytes; 1 -> 0x01)
  1: chainId,        // uint8   (1 = Mainnet, 2 = Testnet)
  2: gasPrice,       // uint32  (minimum 1 -> 0x01)
  3: gasCoin,        // uint32  (0 = BIP -> empty slice -> 0x80)
  4: type,           // uint8   (TX_TYPE opcode 0x01..0x26)
  5: data,           // bytes   (RLP-encoded inner struct wrapped as byte string)
  6: payload,        // bytes   (up to 10,000 bytes; empty -> 0x80)
  7: serviceData,    // bytes   (up to 128 bytes; empty -> 0x80)
  8: signatureType,  // uint8   (0x01 = Single, 0x02 = Multisig)
  9: signatureData   // bytes   (RLP-encoded [v, r, s] or [multisig20B, sigs[]] as byte string)
])

Five byte-level rules govern custom implementations:

  1. Unsigned integer 0 serializes as an empty byte slice (RLP byte 0x80). Encoding 0 as 0x00 in integer fields (gasCoin, value, minimumValueToBuy) fails with non-canonical integer.
  2. Fields data (#5) and signatureData (#9) use double RLP wrapping: encode the inner list into bytes first, then pass that buffer into the outer 10-field list as a byte string rather than a nested list.
  3. Coin and token tickers in 0x05, 0x10, 0x11, 0x1E, and 0x1F occupy 10 ASCII bytes right-padded with 0x00 ([10]byte).
  4. Signature scalars v, r, s encode as unsigned integers with no leading zero bytes (v = recovery + 27, s normalized to lower-half secp256k1 order). In Mc... checks, the 65-byte Lock signature also encodes as *big.Int with leading 0x00 bytes stripped.
  5. Signing and network indexing use distinct hash functions: signingHash = Keccak256(RLP(fields 0..8)) (original Keccak 0x01 padding, not NIST SHA3-256 0x06 padding), whereas txHash = "Mt" + hexLower(SHA256(SignedTxRLP)) hashes all 10 fields.
Languagesecp256k1 (RFC 6979 + recovery)Keccak-256 (0x01 pad)SHA-256 (Mt...)Integer pip type
TypeScript@noble/curves/secp256k1.js@noble/hashes/sha3.js@noble/hashes/sha2.jsbigint
Python 3.11+coincurve (PrivateKey.sign_recoverable)pycryptodome (Crypto.Hash.keccak)hashlib.sha256int
Rustk256 (SigningKey::sign_prehash_recoverable)sha3::Keccak256sha2::Sha256u128 / alloy_primitives::U256
Go 1.22+decred/dcrd/dcrec/secp256k1/v4golang.org/x/crypto/sha3 (NewLegacyKeccak256)crypto/sha256*math/big.Int
Swiftsecp256k1.swift (GigaBitcoin)CryptoSwift (.keccak256)CryptoKit.SHA256BigUInt
Kotlin / JVMorg.bouncycastle (manual low-S and recId)Keccak.Digest256MessageDigest("SHA-256")java.math.BigInteger

Self-contained Python 3.11+ implementation

Install the dependencies in your Python environment:

bash
pip install pycryptodome coincurve

The module below implements canonical RLP encoding, [10]byte tickers, Send (0x01) signing, and verifies exact byte parity against tx-0x01-send:

python
import hashlib
from Crypto.Hash import keccak
from coincurve import PrivateKey


def _encode_length(length: int, offset: int) -> bytes:
    if length < 56:
        return bytes([offset + length])
    len_bytes = length.to_bytes((length.bit_length() + 7) // 8, "big")
    return bytes([offset + 55 + len(len_bytes)]) + len_bytes


def rlp_encode(item: bytes | list) -> bytes:
    if isinstance(item, bytes):
        if len(item) == 1 and item[0] < 0x80:
            return item
        return _encode_length(len(item), 0x80) + item
    if isinstance(item, list):
        payload = b"".join(rlp_encode(elem) for elem in item)
        return _encode_length(len(payload), 0xC0) + payload
    raise TypeError(f"Unsupported RLP type: {type(item)}")


def encode_uint(value: int) -> bytes:
    if value < 0:
        raise ValueError("Unsigned integer cannot be negative")
    if value == 0:
        return b""
    return value.to_bytes((value.bit_length() + 7) // 8, "big")


def encode_ticker10(symbol: str) -> bytes:
    raw = symbol.encode("ascii")
    if len(raw) < 3 or len(raw) > 10:
        raise ValueError("Ticker length must be in 3..10 ASCII bytes")
    return raw.ljust(10, b"\x00")


def keccak256(data: bytes) -> bytes:
    h = keccak.new(digest_bits=256)
    h.update(data)
    return h.digest()


def sign_send_tx(
    priv_hex: str,
    nonce: int,
    chain_id: int,
    gas_price: int,
    gas_coin: int,
    coin_id: int,
    to_mx: str,
    value_pip: int,
    payload: bytes = b"",
    service_data: bytes = b"",
) -> dict[str, str]:
    to_bytes = bytes.fromhex(to_mx[2:])
    if len(to_bytes) != 20:
        raise ValueError("Recipient Mx address must be 20 bytes")

    data_bytes = rlp_encode([
        encode_uint(coin_id),
        to_bytes,
        encode_uint(value_pip),
    ])

    unsigned_rlp = rlp_encode([
        encode_uint(nonce),
        encode_uint(chain_id),
        encode_uint(gas_price),
        encode_uint(gas_coin),
        encode_uint(0x01),
        data_bytes,
        payload,
        service_data,
        encode_uint(0x01),
    ])
    signing_hash = keccak256(unsigned_rlp)

    # coincurve wraps libsecp256k1 with RFC 6979 and low-S normalization: [r(32) || s(32) || recid(1)]
    sig65 = PrivateKey(bytes.fromhex(priv_hex)).sign_recoverable(signing_hash, hasher=None)
    r_trimmed = sig65[:32].lstrip(b"\x00")
    s_trimmed = sig65[32:64].lstrip(b"\x00")
    v_uint = sig65[64] + 27
    signature_data = rlp_encode([encode_uint(v_uint), r_trimmed, s_trimmed])

    signed_rlp = rlp_encode([
        encode_uint(nonce),
        encode_uint(chain_id),
        encode_uint(gas_price),
        encode_uint(gas_coin),
        encode_uint(0x01),
        data_bytes,
        payload,
        service_data,
        encode_uint(0x01),
        signature_data,
    ])
    tx_hash = "Mt" + hashlib.sha256(signed_rlp).hexdigest()
    return {
        "dataBytesHex": "0x" + data_bytes.hex(),
        "signingHash": "0x" + signing_hash.hex(),
        "signedRawTxHex": "0x" + signed_rlp.hex(),
        "txHash": tx_hash,
    }


if __name__ == "__main__":
    res = sign_send_tx(
        priv_hex="1ab42cc412b618bdea3a599e3c9bae199ebf030895b039e9db1e30dafb12b727",
        nonce=1,
        chain_id=1,
        gas_price=1,
        gas_coin=0,
        coin_id=0,
        to_mx="Mx6fac4d18c912343bf86fa7049364dd4e424ab9c0",
        value_pip=12_500_000_000_000_000_000,
        payload=b"invoice:2026-11",
    )
    assert res["dataBytesHex"] == "0xdf80946fac4d18c912343bf86fa7049364dd4e424ab9c088ad78ebc5ac620000"
    assert res["signingHash"] == "0x4fdf01449f56ca56b2310e91e17d5cf07d930578ccf620d2354b0bf8edb47617"
    assert res["txHash"] == "Mte53eeda7a4268983a7ea5481cf150ae9d6ef76c1e497f7489d99805a812b7011"

Self-contained Rust implementation

Cargo.toml dependencies: alloy-rlp = "0.3", k256 = { version = "0.13", features = ["ecdsa"] }, sha3 = "0.10", sha2 = "0.10", hex = "0.4".

rust
use alloy_rlp::{BufMut, Encodable, Header};
use k256::ecdsa::SigningKey;
use sha2::{Digest as _, Sha256};
use sha3::Keccak256;

pub struct SignedMinterTx {
    pub data_bytes_hex: String,
    pub signing_hash_hex: String,
    pub signed_raw_tx_hex: String,
    pub tx_hash: String,
}

pub fn encode_ticker10(symbol: &str) -> [u8; 10] {
    let raw = symbol.as_bytes();
    let mut out = [0u8; 10];
    let copy_len = raw.len().min(10);
    out[..copy_len].copy_from_slice(&raw[..copy_len]);
    out
}

fn trim_leading_zeros(bytes: &[u8]) -> &[u8] {
    let first_nonzero = bytes.iter().position(|&b| b != 0).unwrap_or(bytes.len());
    &bytes[first_nonzero..]
}

fn encode_rlp_bytes_item(slice: &[u8], out: &mut Vec<u8>) {
    slice.encode(out);
}

pub fn sign_send_tx(
    priv_key_bytes: &[u8; 32],
    nonce: u64,
    chain_id: u8,
    gas_price: u32,
    gas_coin: u32,
    coin_id: u32,
    recipient_20: &[u8; 20],
    value_pip: u128,
    payload: &[u8],
    service_data: &[u8],
) -> Result<SignedMinterTx, k256::ecdsa::Error> {
    // 1. Inner SendData struct: RLP([coin_id, to, value_pip])
    let mut inner_payload = Vec::new();
    coin_id.encode(&mut inner_payload);
    encode_rlp_bytes_item(recipient_20, &mut inner_payload);
    value_pip.encode(&mut inner_payload);

    let mut data_bytes = Vec::new();
    Header {
        list: true,
        payload_length: inner_payload.len(),
    }
    .encode(&mut data_bytes);
    data_bytes.put_slice(&inner_payload);

    // 2. 9-field signing list for Keccak-256 signingHash
    let sig_type: u8 = 0x01;
    let mut unsigned_items = Vec::new();
    nonce.encode(&mut unsigned_items);
    chain_id.encode(&mut unsigned_items);
    gas_price.encode(&mut unsigned_items);
    gas_coin.encode(&mut unsigned_items);
    0x01u8.encode(&mut unsigned_items);
    encode_rlp_bytes_item(&data_bytes, &mut unsigned_items);
    encode_rlp_bytes_item(payload, &mut unsigned_items);
    encode_rlp_bytes_item(service_data, &mut unsigned_items);
    sig_type.encode(&mut unsigned_items);

    let mut unsigned_rlp = Vec::new();
    Header {
        list: true,
        payload_length: unsigned_items.len(),
    }
    .encode(&mut unsigned_rlp);
    unsigned_rlp.put_slice(&unsigned_items);

    let signing_hash = Keccak256::digest(&unsigned_rlp);

    // 3. RFC 6979 recoverable signature (k256 normalizes low-S by default)
    let signing_key = SigningKey::from_bytes(priv_key_bytes.into())?;
    let (sig, recid) = signing_key.sign_prehash_recoverable(&signing_hash)?;
    let sig_bytes = sig.to_bytes();
    let r_trimmed = trim_leading_zeros(&sig_bytes[..32]);
    let s_trimmed = trim_leading_zeros(&sig_bytes[32..64]);
    let v_byte: u8 = recid.to_byte() + 27;

    let mut sig_tuple = Vec::new();
    v_byte.encode(&mut sig_tuple);
    encode_rlp_bytes_item(r_trimmed, &mut sig_tuple);
    encode_rlp_bytes_item(s_trimmed, &mut sig_tuple);

    let mut signature_data = Vec::new();
    Header {
        list: true,
        payload_length: sig_tuple.len(),
    }
    .encode(&mut signature_data);
    signature_data.put_slice(&sig_tuple);

    // 4. Outer 10-field signed RLP and Mt + SHA-256 network hash
    let mut signed_items = unsigned_items;
    encode_rlp_bytes_item(&signature_data, &mut signed_items);

    let mut signed_rlp = Vec::new();
    Header {
        list: true,
        payload_length: signed_items.len(),
    }
    .encode(&mut signed_rlp);
    signed_rlp.put_slice(&signed_items);

    let sha_digest = Sha256::digest(&signed_rlp);
    Ok(SignedMinterTx {
        data_bytes_hex: String::from("0x") + &hex::encode(&data_bytes),
        signing_hash_hex: String::from("0x") + &hex::encode(signing_hash),
        signed_raw_tx_hex: String::from("0x") + &hex::encode(&signed_rlp),
        tx_hash: String::from("Mt") + &hex::encode(sha_digest),
    })
}
Cross-language Minter v3.3.0 signer verified against test-vectors.json
Read the portal’s test-vectors.json. Implement canonical RLP serialization and secp256k1 signing for Minter v3.3.0 in the target language (Python with pycryptodome + coincurve or Rust with alloy-rlp + k256): unsigned 0 encodes as 0x80, tickers are right-padded with 0x00 to [10]byte, data and signatureData use double RLP wrapping, check Lock encodes as an unsigned integer with no leading zero bytes, signingHash uses Keccak-256 over 9 fields, and txHash equals 'Mt' + SHA-256 over 10 fields. Add unit tests covering activeVectors (37), multisigVectors, checkVectors, the data-only 0x13 entry in inactiveRlpVectors, and negativeRlpVectors.