Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
tlv_use_case_transaction_check.c File Reference
#include <stdint.h>
#include <string.h>
#include "os_math.h"
#include "os_utils.h"
#include "ox_ec.h"
#include "cx.h"
#include "os_pki.h"
#include "ledger_pki.h"
#include "tlv_use_case_transaction_check.h"
Include dependency graph for tlv_use_case_transaction_check.c:

Go to the source code of this file.

Classes

struct  tlv_extracted_s

Macros

#define TYPE_TRANSACTION_CHECK   0x09
#define TRANSACTION_CHECK_VERSION   0x01
#define TRANSACTION_CHECK_TLV_TAGS(X)

Typedefs

typedef struct tlv_extracted_s tlv_extracted_t

Functions

static bool handle_structure_type (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_structure_version (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_tx_hash (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_domain_hash (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_address (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_chain_id (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_risk (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_category (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_type (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_provider_msg (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_tiny_url (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_signature (const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_common (const tlv_data_t *data, void *tlv_extracted_ptr)
 Common handler called for all tags to progressively hash them (except signature).
static tlv_transaction_check_status_t verify_struct (const tlv_extracted_t *tlv_extracted)
static tlv_transaction_check_status_t verify_signature (tlv_extracted_t *tlv_extracted)
tlv_transaction_check_status_t tlv_use_case_transaction_check (const buffer_t *payload, tlv_transaction_check_out_t *out)
 Parse a Transaction Check TLV payload.

Macro Definition Documentation

◆ TRANSACTION_CHECK_TLV_TAGS

#define TRANSACTION_CHECK_TLV_TAGS ( X)
Value:
X(0x01, TAG_STRUCTURE_TYPE, handle_structure_type, ENFORCE_UNIQUE_TAG) \
X(0x02, TAG_STRUCTURE_VERSION, handle_structure_version, ENFORCE_UNIQUE_TAG) \
X(0x22, TAG_ADDRESS, handle_address, ENFORCE_UNIQUE_TAG) \
X(0x23, TAG_CHAIN_ID, handle_chain_id, ENFORCE_UNIQUE_TAG) \
X(0x27, TAG_TX_HASH, handle_tx_hash, ENFORCE_UNIQUE_TAG) \
X(0x28, TAG_DOMAIN_HASH, handle_domain_hash, ENFORCE_UNIQUE_TAG) \
X(0x80, TAG_NORMALIZED_RISK, handle_risk, ENFORCE_UNIQUE_TAG) \
X(0x81, TAG_NORMALIZED_CATEGORY, handle_category, ENFORCE_UNIQUE_TAG) \
X(0x82, TAG_PROVIDER_MSG, handle_provider_msg, ENFORCE_UNIQUE_TAG) \
X(0x83, TAG_TINY_URL, handle_tiny_url, ENFORCE_UNIQUE_TAG) \
X(0x84, TAG_SIMULATION_TYPE, handle_type, ENFORCE_UNIQUE_TAG) \
X(0x85, TAG_ADDITIONAL_DATA, NULL, ENFORCE_UNIQUE_TAG) \
X(0x15, TAG_DER_SIGNATURE, handle_signature, ENFORCE_UNIQUE_TAG)
static bool handle_chain_id(const tlv_data_t *data, void *context_ptr)
Handler for tag CHAIN_ID.
@ ENFORCE_UNIQUE_TAG
static bool handle_structure_type(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_signature(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_domain_hash(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_structure_version(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_provider_msg(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_category(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_tiny_url(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_type(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_tx_hash(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_risk(const tlv_data_t *data, void *tlv_extracted_ptr)
static bool handle_address(const tlv_data_t *data, void *tlv_extracted_ptr)

Definition at line 208 of file tlv_use_case_transaction_check.c.

◆ TRANSACTION_CHECK_VERSION

#define TRANSACTION_CHECK_VERSION   0x01

Definition at line 29 of file tlv_use_case_transaction_check.c.

◆ TYPE_TRANSACTION_CHECK

#define TYPE_TRANSACTION_CHECK   0x09

Definition at line 28 of file tlv_use_case_transaction_check.c.

Typedef Documentation

◆ tlv_extracted_t

Function Documentation

◆ handle_address()

bool handle_address ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 87 of file tlv_use_case_transaction_check.c.

◆ handle_category()

bool handle_category ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 121 of file tlv_use_case_transaction_check.c.

◆ handle_chain_id()

bool handle_chain_id ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 97 of file tlv_use_case_transaction_check.c.

◆ handle_common()

bool handle_common ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Common handler called for all tags to progressively hash them (except signature).

Definition at line 229 of file tlv_use_case_transaction_check.c.

◆ handle_domain_hash()

bool handle_domain_hash ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 77 of file tlv_use_case_transaction_check.c.

◆ handle_provider_msg()

bool handle_provider_msg ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 155 of file tlv_use_case_transaction_check.c.

◆ handle_risk()

bool handle_risk ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 104 of file tlv_use_case_transaction_check.c.

◆ handle_signature()

bool handle_signature ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 191 of file tlv_use_case_transaction_check.c.

◆ handle_structure_type()

bool handle_structure_type ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 53 of file tlv_use_case_transaction_check.c.

◆ handle_structure_version()

bool handle_structure_version ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 60 of file tlv_use_case_transaction_check.c.

◆ handle_tiny_url()

bool handle_tiny_url ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 174 of file tlv_use_case_transaction_check.c.

◆ handle_tx_hash()

bool handle_tx_hash ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 67 of file tlv_use_case_transaction_check.c.

◆ handle_type()

bool handle_type ( const tlv_data_t * data,
void * tlv_extracted_ptr )
static

Definition at line 138 of file tlv_use_case_transaction_check.c.

◆ tlv_use_case_transaction_check()

tlv_transaction_check_status_t tlv_use_case_transaction_check ( const buffer_t * payload,
tlv_transaction_check_out_t * out )

Parse a Transaction Check TLV payload.

Parses the provided TLV payload, verifies the PKI signature, and extracts the simulation result into the output structure.

Warning
A successful return only means the descriptor is authentic and well-formed. This parser is chain-agnostic: it does not enforce the presence of chain_id nor domain_hash, as their meaning depends on the blockchain (e.g. EVM vs Solana). Before displaying the risk verdict, the caller MUST check that the descriptor is bound to the operation being reviewed:
  • type matches the kind of operation being reviewed,
  • tx_hash and address match the transaction / message hash and the signer address,
  • when relevant for the blockchain, chain_id is received (chain_id_received) and matches the transaction chain ID,
  • for EIP-712 typed data, domain_hash is received (domain_hash_received) and matches the domain separator hash of the message. Otherwise a valid verdict could be replayed on another chain, domain or operation.
Parameters
[in]payloadPointer to the buffer containing the TLV payload data.
[out]outPointer to the structure where the parsed Transaction Check result will be stored.
Returns
Status code indicating the result of the operation. See tlv_transaction_check_status_t for possible values.

Definition at line 317 of file tlv_use_case_transaction_check.c.

◆ verify_signature()

tlv_transaction_check_status_t verify_signature ( tlv_extracted_t * tlv_extracted)
static

Definition at line 291 of file tlv_use_case_transaction_check.c.

◆ verify_struct()

tlv_transaction_check_status_t verify_struct ( const tlv_extracted_t * tlv_extracted)
static

Definition at line 244 of file tlv_use_case_transaction_check.c.