36#include "status_words.h"
48#if defined(HAVE_ADDRESS_BOOK) && defined(HAVE_ADDRESS_BOOK_LEDGER_ACCOUNT)
51#define STRUCT_VERSION 0x01
63#define LEDGER_ACCOUNT_TAGS(X) \
64 X(0x01, TAG_STRUCTURE_TYPE, handle_struct_type, ENFORCE_UNIQUE_TAG) \
65 X(0x02, TAG_STRUCTURE_VERSION, handle_struct_version, ENFORCE_UNIQUE_TAG) \
66 X(0xf0, TAG_CONTACT_NAME, handle_contact_name, ENFORCE_UNIQUE_TAG) \
67 X(0x69, TAG_DERIVATION_PATH, handle_derivation_path, ENFORCE_UNIQUE_TAG) \
68 X(0x23, TAG_CHAIN_ID, handle_chain_id, ENFORCE_UNIQUE_TAG) \
69 X(0x51, TAG_BLOCKCHAIN_FAMILY, handle_blockchain_family, ENFORCE_UNIQUE_TAG)
88 PRINTF(
"[Register Ledger Account] Invalid STRUCTURE_TYPE value\n");
107 PRINTF(
"[Register Ledger Account] Invalid STRUCTURE_VERSION value\n");
127 PRINTF(
"CONTACT_NAME: failed to parse\n");
187 TAG_STRUCTURE_VERSION,
190 TAG_BLOCKCHAIN_FAMILY);
192 PRINTF(
"Missing mandatory fields in Ledger Account descriptor!\n");
198 PRINTF(
"Missing CHAIN_ID for Ethereum family in Ledger Account descriptor!\n");
216 PRINTF(
"****************************************************************************\n");
217 PRINTF(
"[Ledger Account] - Retrieved Descriptor:\n");
218 PRINTF(
"[Ledger Account] - Account name: %s\n",
221 PRINTF(
"[Ledger Account] - Derivation path[%d]: %s\n",
226 PRINTF(
"[Ledger Account] - Derivation path length[%d] (failed to format)\n",
229 PRINTF(
"[Ledger Account] - Blockchain family: %s\n",
232 PRINTF(
"[Ledger Account] - Chain ID: %llu\n",
247 uint8_t hmac_proof[CX_SHA256_SIZE] = {0};
250 (
const char *)
g_ab_payload.ledger_account.account_name,
255 PRINTF(
"[Ledger Account] Error: Failed to compute HMAC proof\n");
260 explicit_bzero(hmac_proof,
sizeof(hmac_proof));
274 PRINTF(
"[Ledger Account] Error: Failed to build and send response\n");
295 const buffer_t payload = {.ptr = buffer_in, .size = buffer_in_length};
303 if (!ledger_account_tlv_parser(&payload, &ctx, &ctx.
received_tags)) {
304 PRINTF(
"[Ledger Account] Failed to parse TLV payload\n");
305 return SWO_INCORRECT_DATA;
308 return SWO_INCORRECT_DATA;
314 PRINTF(
"[Ledger Account] Error: Account rejected by coin application\n");
315 return SWO_WRONG_PARAMETER_VALUE;
320 return SWO_NO_RESPONSE;
void address_book_finalize_review(bool success, const char *successMsg, const char *errorMsg, nbgl_callback_t finalize)
Common handling of a confirmed Address Book review's outcome.
void address_book_handle_review_rejected(nbgl_callback_t finalize)
Common handling of a rejected Address Book review.
bool address_book_handle_blockchain_family(const tlv_data_t *data, blockchain_family_e *family)
Generic handler for blockchain family.
bool address_book_handle_derivation_path(const tlv_data_t *data, path_bip32_t *bip32_path)
Generic handler for BIP32 derivation path.
ab_payload_u g_ab_payload
bool address_book_handle_printable_string(const tlv_data_t *data, char *output_buffer, size_t buffer_size)
Generic handler for printable string extraction.
bool address_book_handle_chain_id(const tlv_data_t *data, uint64_t *chain_id)
Generic handler for chain ID.
bool address_book_send_hmac_proof(uint8_t type, const uint8_t hmac_proof[CX_SHA256_SIZE])
Send an HMAC proof response for Edit operations.
bool address_book_compute_hmac_proof_ledger_account(const char *name, const path_bip32_t *bip32_path, blockchain_family_e family, uint64_t chain_id, uint8_t hmac_out[CX_SHA256_SIZE])
Compute an HMAC-SHA256 Proof of Registration for a Ledger Account.
bool handle_check_register_ledger_account(ledger_account_t *params)
Handle called to validate the received Ledger Account.
void display_register_ledger_account_review(nbgl_choiceCallback_t choice_callback)
Handle called to display the Ledger Account registration review screen.
void finalize_ui_ledger_account(void)
Handle called to finalize the UI flow for a Ledger Account operation.
bool bip32_path_format_simple(path_bip32_t *bip32, char *out, size_t out_len)
Format a BIP32 path as a string.
#define TYPE_REGISTER_LEDGER_ACCOUNT
static bool handle_contact_name(const tlv_data_t *data, void *context_ptr)
Handler for tag CONTACT_NAME.
static bool handle_blockchain_family(const tlv_data_t *data, void *context_ptr)
Handler for tag BLOCKCHAIN_FAMILY.
static bool handle_derivation_path(const tlv_data_t *data, void *context_ptr)
Handler for tag DERIVATION_PATH.
static bool verify_fields(const s_ledger_account_ctx *context)
Check that all mandatory TLV tags were received.
static void review_choice(bool confirm)
NBGL callback invoked after the user confirms or rejects the registration.
static bool handle_struct_type(const tlv_data_t *data, void *context_ptr)
Handler for tag STRUCTURE_TYPE.
bolos_err_t register_ledger_account(uint8_t *buffer_in, size_t buffer_in_length)
Register a new Ledger Account.
static bool handle_chain_id(const tlv_data_t *data, void *context_ptr)
Handler for tag CHAIN_ID.
static bool build_and_send_response(void)
Build and send response.
static bool handle_struct_version(const tlv_data_t *data, void *context_ptr)
Handler for tag STRUCTURE_VERSION.
static void print_payload(const s_ledger_account_ctx *context)
Print the received descriptor.
#define LEDGER_ACCOUNT_TAGS(X)
API of the Advanced BOLOS Graphical Library, for typical application use-cases.
Data extracted from a Register Ledger Account TLV payload.
char account_name[ACCOUNT_NAME_LENGTH]
blockchain_family_e blockchain_family
TLV_reception_t received_tags
ledger_account_t * ledger_account
bool tlv_enforce_u8_value(const tlv_data_t *data, uint8_t expected_value)
Enforce that a TLV data contains the expected uint8 value.
TLV_reception_internal_t TLV_reception_t
#define DEFINE_TLV_PARSER(TAG_LIST, COMMON_HANDLER, PARSE_FUNCTION_NAME)
Creates a parser function for a given TLV use case.
struct tlv_data_s tlv_data_t
#define TLV_CHECK_RECEIVED_TAGS(received,...)