rfe-types 0.1.0

Shared types for the Rust Fintech Ecosystem (RFE): newtype IDs, hashing, Decimal utilities
Documentation
//! NORM Protocol v1 Canonical Test Vectors.
//! Used to verify cross-platform determinism across Xtensa (TrustBox) and x86_64 (Risk-Lens).

pub struct TestVector {
    pub name: &'static str,
    pub nonce: [u8; 32],
    pub csv_payload: &'static [u8],
    pub expected_request_hash: [u8; 32],
    pub expected_result_hash: [u8; 32],
    pub chain_head_pre: [u8; 32],
    pub expected_seal: [u8; 32],
}

/// Vector 1: Simple Approved Transaction.
pub const VECTOR_1: TestVector = TestVector {
    name: "Simple Approved",
    nonce: [0u8; 32],
    csv_payload: b"TX001,1000,5000,1\n",
    expected_request_hash: [
        0xbc, 0x54, 0x5c, 0x2f, 0xa5, 0xe2, 0xa4, 0xf9, 0x4f, 0xd6, 0x29, 0x9d, 0x84, 0x82, 0x1a,
        0x14, 0x71, 0x25, 0x55, 0x8c, 0x27, 0x60, 0x8a, 0x40, 0x97, 0x84, 0xcd, 0xfb, 0xbe, 0x63,
        0x87, 0xe0,
    ],
    expected_result_hash: [
        0xce, 0xf7, 0x6b, 0xe1, 0x6f, 0x03, 0xc9, 0xd2, 0x4e, 0x94, 0x91, 0x74, 0xef, 0x29, 0x66,
        0xd5, 0xbd, 0xdc, 0x7a, 0x1b, 0xd7, 0xf7, 0xfb, 0xb0, 0xd1, 0xf9, 0xa8, 0xcd, 0x4d, 0x05,
        0xbc, 0x1b,
    ],
    chain_head_pre: [0u8; 32],
    expected_seal: [
        0xc9, 0xe6, 0x7c, 0xfe, 0x3e, 0x7d, 0x4b, 0x26, 0x63, 0xb3, 0xf8, 0x6b, 0x16, 0xc3, 0x61,
        0xb5, 0xa9, 0x72, 0xd8, 0x4b, 0x84, 0x8f, 0x92, 0x98, 0x6c, 0xb1, 0xa2, 0x34, 0x49, 0x1a,
        0x35, 0x90,
    ],
};

/// Vector 2: Single Flagged PDN.
pub const VECTOR_2: TestVector = TestVector {
    name: "Flagged PDN",
    nonce: [0u8; 32],
    csv_payload: b"TX002,3000,5000,1\n",
    expected_request_hash: [
        0x6a, 0x1f, 0xd5, 0x42, 0xcc, 0x54, 0x0f, 0xd4, 0x33, 0x16, 0xa5, 0x64, 0x7f, 0x5c, 0x87,
        0xef, 0x81, 0xbb, 0x72, 0x56, 0x15, 0x52, 0x77, 0x7c, 0x3e, 0xcb, 0x75, 0xc1, 0xe8, 0xc0,
        0x65, 0xa5,
    ],
    expected_result_hash: [
        0xbe, 0x17, 0x3d, 0x4f, 0xb5, 0x1a, 0x75, 0xa9, 0x21, 0xef, 0xb0, 0xac, 0x5b, 0x0e, 0x4d,
        0xd9, 0x05, 0xd2, 0xf7, 0x81, 0xe5, 0xc2, 0xc6, 0x79, 0x2b, 0xca, 0x97, 0xa7, 0xc2, 0x31,
        0x03, 0x21,
    ],
    chain_head_pre: [0u8; 32],
    expected_seal: [
        0xe6, 0x45, 0x52, 0x44, 0x3f, 0x48, 0x2b, 0xda, 0x7c, 0x91, 0x0e, 0xe9, 0x0a, 0xa3, 0x62,
        0x64, 0x8e, 0xd8, 0x72, 0x9f, 0x0b, 0x34, 0x26, 0x19, 0xe8, 0x71, 0x86, 0x7f, 0xd3, 0x5b,
        0xc8, 0x5b,
    ],
};

#[cfg(test)]
mod tests {
    use super::{TestVector, VECTOR_1, VECTOR_2};
    use crate::hashing::hash_raw_request;
    use crate::SealInput;

    fn verify_vector(v: &TestVector) {
        let request_hash = hash_raw_request(v.csv_payload);
        assert_eq!(
            request_hash, v.expected_request_hash,
            "{}: request hash mismatch",
            v.name
        );

        let seal = SealInput::new_v1(
            v.nonce,
            v.expected_request_hash,
            v.expected_result_hash,
            v.chain_head_pre,
        )
        .compute_seal();
        assert_eq!(seal, v.expected_seal, "{}: seal mismatch", v.name);
    }

    #[test]
    fn vector_1_simple_approved() {
        verify_vector(&VECTOR_1);
    }

    #[test]
    fn vector_2_flagged_pdn() {
        verify_vector(&VECTOR_2);
    }
}