Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib_tlv/use_cases/tlv_use_case_trusted_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ static bool handle_trusted_name_source(const tlv_data_t *data, tlv_extracted_t *
return get_uint8_t_from_tlv_data(data, &tlv_extracted->output->trusted_name_source);
}

static bool handle_blockchain_family(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
{
return get_uint8_t_from_tlv_data(data, &tlv_extracted->output->blockchain_family);
}

static bool handle_trusted_name(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
{
return get_buffer_from_tlv_data(
Expand Down Expand Up @@ -226,6 +231,7 @@ static bool handle_common(const tlv_data_t *data, tlv_extracted_t *tlv_extracted
X(0x02, TAG_VERSION, handle_version, ENFORCE_UNIQUE_TAG) \
X(0x70, TAG_TRUSTED_NAME_TYPE, handle_trusted_name_type, ENFORCE_UNIQUE_TAG) \
X(0x71, TAG_TRUSTED_NAME_SOURCE, handle_trusted_name_source, ENFORCE_UNIQUE_TAG) \
X(0x51, TAG_BLOCKCHAIN_FAMILY, handle_blockchain_family, ENFORCE_UNIQUE_TAG) \
X(0x20, TAG_TRUSTED_NAME, handle_trusted_name, ENFORCE_UNIQUE_TAG) \
X(0x23, TAG_CHAIN_ID, handle_chain_id, ENFORCE_UNIQUE_TAG) \
X(0x22, TAG_ADDRESS, handle_address, ENFORCE_UNIQUE_TAG) \
Expand Down Expand Up @@ -291,6 +297,8 @@ static tlv_trusted_name_status_t verify_struct(const tlv_extracted_t *tlv_extrac
= TLV_CHECK_RECEIVED_TAGS(tlv_extracted->received_tags, TAG_CHALLENGE);
tlv_extracted->output->not_valid_after_received
= TLV_CHECK_RECEIVED_TAGS(tlv_extracted->received_tags, TAG_NOT_VALID_AFTER);
tlv_extracted->output->blockchain_family_received
= TLV_CHECK_RECEIVED_TAGS(tlv_extracted->received_tags, TAG_BLOCKCHAIN_FAMILY);

if (tlv_extracted->output->version == 0
|| tlv_extracted->output->version > CURRENT_TRUSTED_NAME_SPEC_VERSION) {
Expand Down
13 changes: 13 additions & 0 deletions lib_tlv/use_cases/tlv_use_case_trusted_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ typedef enum tlv_trusted_name_source_e {
TLV_TRUSTED_NAME_SOURCE_DYNAMIC_RESOLVER = 0x06,
} tlv_trusted_name_source_t;

typedef enum tlv_trusted_name_blockchain_family_e {
TLV_TRUSTED_NAME_BLOCKCHAIN_FAMILY_BITCOIN = 0x00,
TLV_TRUSTED_NAME_BLOCKCHAIN_FAMILY_ETHEREUM = 0x01,
TLV_TRUSTED_NAME_BLOCKCHAIN_FAMILY_SOLANA = 0x02,
TLV_TRUSTED_NAME_BLOCKCHAIN_FAMILY_POLKADOT = 0x03,
TLV_TRUSTED_NAME_BLOCKCHAIN_FAMILY_COSMOS = 0x04,
TLV_TRUSTED_NAME_BLOCKCHAIN_FAMILY_CARDANO = 0x05,
TLV_TRUSTED_NAME_BLOCKCHAIN_FAMILY_TRON = 0x06,
} tlv_trusted_name_blockchain_family_t;

typedef enum tlv_trusted_name_signer_key_id_e {
TLV_TRUSTED_NAME_SIGNER_KEY_ID_TEST = 0x00,
TLV_TRUSTED_NAME_SIGNER_KEY_ID_PROD = 0x07,
Expand Down Expand Up @@ -111,12 +121,15 @@ typedef struct tlv_trusted_name_out_s {
uint32_t challenge;
// A version date to revoke the trusted name validity.
semver_t not_valid_after;
// The blockchain family of the network tlv_trusted_name_blockchain_family_t
uint8_t blockchain_family;

// Flag optional tags reception
bool nft_id_received;
bool source_contract_received;
bool challenge_received;
bool not_valid_after_received;
bool blockchain_family_received;
} tlv_trusted_name_out_t;

typedef enum tlv_trusted_name_status_e {
Expand Down
5 changes: 5 additions & 0 deletions unit-tests/lib_tlv/test_tlv_use_case_trusted_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ static void test_valid_trusted_name_v1(void **state)
assert_false(out.source_contract_received);
assert_false(out.challenge_received);
assert_false(out.not_valid_after_received);
assert_false(out.blockchain_family_received);
}

/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -184,6 +185,8 @@ static void test_valid_trusted_name_v2_with_optionals(void **state)
// Optional: Not valid after (semver: major.minor.patch)
uint8_t semver[4] = {0x01, 0x02, 0x03, 0x04}; // 1.2.772
append_tlv(payload, &offset, 0x10, semver, sizeof(semver));
// Optional: Blockchain family
append_tlv_uint8(payload, &offset, 0x51, TLV_TRUSTED_NAME_BLOCKCHAIN_FAMILY_ETHEREUM);
append_tlv_uint16(payload, &offset, 0x13, TLV_TRUSTED_NAME_SIGNER_KEY_ID_PROD);
append_tlv_uint8(payload, &offset, 0x14, TLV_TRUSTED_NAME_SIGNER_ALGORITHM_ECDSA_SHA256);
uint8_t signature[64] = {0};
Expand All @@ -206,6 +209,8 @@ static void test_valid_trusted_name_v2_with_optionals(void **state)
assert_int_equal(out.not_valid_after.major, 1);
assert_int_equal(out.not_valid_after.minor, 2);
assert_int_equal(out.not_valid_after.patch, 0x0304);
assert_true(out.blockchain_family_received);
assert_int_equal(out.blockchain_family, TLV_TRUSTED_NAME_BLOCKCHAIN_FAMILY_ETHEREUM);
}

/* -------------------------------------------------------------------------- */
Expand Down