From df5fd43c6be1e51677d1a849c836837a2904bda3 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Tue, 2 Jul 2024 15:20:23 +0200 Subject: [PATCH] unify ur types --- app/core/auth.c | 25 +- app/core/core.c | 6 +- app/core/core.h | 2 +- app/core/core_eth.c | 2 +- app/qrcode/qrscan.c | 4 +- app/ui/ui.h | 2 +- app/ui/ui_internal.h | 2 +- app/ur/auth_decode.c | 219 --- app/ur/auth_decode.h | 35 - app/ur/auth_encode.c | 220 ---- app/ur/auth_encode.h | 35 - app/ur/auth_types.h | 80 -- app/ur/btc_decode.c | 50 - app/ur/btc_decode.h | 35 - app/ur/btc_encode.c | 50 - app/ur/btc_encode.h | 35 - app/ur/btc_types.h | 34 - app/ur/ur.c | 36 +- app/ur/ur.h | 4 +- app/ur/{eip4527_decode.c => ur_decode.c} | 418 +++++- app/ur/{eip4527_decode.h => ur_decode.h} | 32 +- app/ur/{eip4527_encode.c => ur_encode.c} | 1536 +++++++++++++--------- app/ur/{eip4527_encode.h => ur_encode.h} | 32 +- app/ur/ur_part_decode.c | 56 - app/ur/ur_part_decode.h | 35 - app/ur/ur_part_encode.c | 56 - app/ur/ur_part_encode.h | 35 - app/ur/ur_part_types.h | 40 - app/ur/{eip4527_types.h => ur_types.h} | 87 +- cddl/auth.cddl | 27 - cddl/btc.cddl | 1 - cddl/eip4527.cddl | 114 -- cddl/ur.cddl | 174 ++- tools/bytewords-lut.py | 21 +- tools/zcbor-gen.sh | 5 +- 35 files changed, 1736 insertions(+), 1809 deletions(-) delete mode 100644 app/ur/auth_decode.c delete mode 100644 app/ur/auth_decode.h delete mode 100644 app/ur/auth_encode.c delete mode 100644 app/ur/auth_encode.h delete mode 100644 app/ur/auth_types.h delete mode 100644 app/ur/btc_decode.c delete mode 100644 app/ur/btc_decode.h delete mode 100644 app/ur/btc_encode.c delete mode 100644 app/ur/btc_encode.h delete mode 100644 app/ur/btc_types.h rename app/ur/{eip4527_decode.c => ur_decode.c} (56%) rename app/ur/{eip4527_decode.h => ur_decode.h} (58%) rename app/ur/{eip4527_encode.c => ur_encode.c} (54%) rename app/ur/{eip4527_encode.h => ur_encode.h} (58%) delete mode 100644 app/ur/ur_part_decode.c delete mode 100644 app/ur/ur_part_decode.h delete mode 100644 app/ur/ur_part_encode.c delete mode 100644 app/ur/ur_part_encode.h delete mode 100644 app/ur/ur_part_types.h rename app/ur/{eip4527_types.h => ur_types.h} (63%) delete mode 100644 cddl/auth.cddl delete mode 100644 cddl/btc.cddl delete mode 100644 cddl/eip4527.cddl diff --git a/app/core/auth.c b/app/core/auth.c index b987928..1e1043d 100644 --- a/app/core/auth.c +++ b/app/core/auth.c @@ -8,8 +8,7 @@ #include "storage/keys.h" #include "ui/ui.h" #include "ur/ur.h" -#include "ur/auth_types.h" -#include "ur/auth_encode.h" +#include "ur/ur_encode.h" #define AUTH_CHALLENGE_LEN 32 #define AUTH_SIG_LEN 64 @@ -24,11 +23,11 @@ void device_auth_run() { if ((auth.dev_auth_step.dev_auth_step_type_choice != dev_auth_step_type_dev_auth_init_m_c) || !auth.dev_auth_challenge_present || - auth.dev_auth_device_id_present || + auth.dev_auth_dev_id_present || auth.dev_auth_first_auth_present || auth.dev_auth_auth_time_present || auth.dev_auth_auth_count_present || - auth.dev_auth_signature_present) { + auth.dev_auth_auth_sig_present) { ui_info(LSTR(DEV_AUTH_INVALID_CHALLENGE), 1); return; } @@ -53,14 +52,14 @@ void device_auth_run() { // Response random_buffer((uint8_t*) auth.dev_auth_challenge.dev_auth_challenge.value, AUTH_CHALLENGE_LEN); - auth.dev_auth_device_id_present = 1; - auth.dev_auth_device_id.dev_auth_device_id.value = uid; - auth.dev_auth_device_id.dev_auth_device_id.len = HAL_DEVICE_UID_LEN; + auth.dev_auth_dev_id_present = 1; + auth.dev_auth_dev_id.dev_auth_dev_id.value = uid; + auth.dev_auth_dev_id.dev_auth_dev_id.len = HAL_DEVICE_UID_LEN; auth.dev_auth_step.dev_auth_step_type_choice = dev_auth_step_type_dev_auth_device_m_c; - auth.dev_auth_signature_present = 1; - auth.dev_auth_signature.dev_auth_signature.value = g_core.data.sig.plain_sig; - auth.dev_auth_signature.dev_auth_signature.len = AUTH_SIG_LEN; + auth.dev_auth_auth_sig_present = 1; + auth.dev_auth_auth_sig.dev_auth_auth_sig.value = g_core.data.sig.plain_sig; + auth.dev_auth_auth_sig.dev_auth_auth_sig.len = AUTH_SIG_LEN; cbor_encode_dev_auth(g_core.data.sig.cbor_sig, CBOR_SIG_MAX_LEN, &auth, &g_core.data.sig.cbor_len); @@ -77,11 +76,11 @@ void device_auth_run() { if ((auth.dev_auth_step.dev_auth_step_type_choice != dev_auth_step_type_dev_auth_server_m_c) || auth.dev_auth_challenge_present || - auth.dev_auth_device_id_present || + auth.dev_auth_dev_id_present || !auth.dev_auth_first_auth_present || !auth.dev_auth_auth_time_present || !auth.dev_auth_auth_count_present || - !auth.dev_auth_signature_present + !auth.dev_auth_auth_sig_present ) { ui_info(LSTR(DEV_AUTH_INVALID_CHALLENGE), 1); return; @@ -94,7 +93,7 @@ void device_auth_run() { const uint8_t* key; key_read_public(DEV_AUTH_SERVER_KEY, &key); - if (!ecdsa_verify(&secp256k1, key, auth.dev_auth_signature.dev_auth_signature.value, digest)) { + if (!ecdsa_verify(&secp256k1, key, auth.dev_auth_auth_sig.dev_auth_auth_sig.value, digest)) { ui_device_auth(auth.dev_auth_first_auth.dev_auth_first_auth, auth.dev_auth_auth_time.dev_auth_auth_time, auth.dev_auth_auth_count.dev_auth_auth_count); } else { ui_info(LSTR(DEV_AUTH_INVALID_AUTH), 1); diff --git a/app/core/core.c b/app/core/core.c index e775608..0e1abf2 100644 --- a/app/core/core.c +++ b/app/core/core.c @@ -12,7 +12,7 @@ #include "storage/keys.h" #include "ui/ui_internal.h" #include "util/tlv.h" -#include "ur/eip4527_encode.h" +#include "ur/ur_encode.h" #define BTC_SEGWIT_VER 0 @@ -325,7 +325,7 @@ void core_display_public_eip4527() { // this macro can only be used in core_display_public_multicoin() #define CORE_MULTICOIN_EXPORT(__NUM__, __PATH__, __PATH_LEN__, __SOURCE___) \ - if (encode_hd_key(&accounts.crypto_multi_accounts_keys_hd_key_m[__NUM__], &g_mem_heap[keys_off], &g_mem_heap[keys_off + PUBKEY_LEN], __PATH__, __PATH_LEN__, __SOURCE___) != ERR_OK) { \ + if (encode_hd_key(&accounts.crypto_multi_accounts_keys_tagged_hd_key_m[__NUM__], &g_mem_heap[keys_off], &g_mem_heap[keys_off + PUBKEY_LEN], __PATH__, __PATH_LEN__, __SOURCE___) != ERR_OK) { \ ui_card_transport_error(); \ return; \ } \ @@ -357,7 +357,7 @@ void core_display_public_multicoin() { CORE_MULTICOIN_EXPORT(2, BTC_NATIVE_SEGWIT_PATH, BTC_NATIVE_SEGWIT_PATH_LEN, false); CORE_MULTICOIN_EXPORT(3, ETH_DEFAULT_BIP44, ETH_DEFAULT_BIP44_LEN, true); - accounts.crypto_multi_accounts_keys_hd_key_m_count = 4; + accounts.crypto_multi_accounts_keys_tagged_hd_key_m_count = 4; accounts.crypto_multi_accounts_master_fingerprint = g_core.master_fingerprint; cbor_encode_crypto_multi_accounts(&g_mem_heap[keys_off], MEM_HEAP_SIZE, &accounts, &g_core.data.key.cbor_len); diff --git a/app/core/core.h b/app/core/core.h index 2c379f9..9cf1416 100644 --- a/app/core/core.h +++ b/app/core/core.h @@ -12,7 +12,7 @@ #include "keycard/keycard.h" #include "iso7816/smartcard.h" #include "ui/ui.h" -#include "ur/eip4527_types.h" +#include "ur/ur_types.h" #define BIP44_MAX_PATH_LEN 40 diff --git a/app/core/core_eth.c b/app/core/core_eth.c index f098068..c5260a3 100644 --- a/app/core/core_eth.c +++ b/app/core/core_eth.c @@ -4,7 +4,7 @@ #include "crypto/util.h" #include "keycard/keycard_cmdset.h" #include "mem.h" -#include "ur/eip4527_encode.h" +#include "ur/ur_encode.h" #define ETH_MSG_MAGIC_LEN 26 #define ETH_EIP712_MAGIC_LEN 2 diff --git a/app/qrcode/qrscan.c b/app/qrcode/qrscan.c index 2f07115..33ec2d9 100644 --- a/app/qrcode/qrscan.c +++ b/app/qrcode/qrscan.c @@ -8,9 +8,7 @@ #include "ui/theme.h" #include "ui/ui_internal.h" #include "ur/ur.h" -#include "ur/eip4527_decode.h" -#include "ur/auth_decode.h" -#include "ur/btc_decode.h" +#include "ur/ur_decode.h" #define QR_INDICATOR_WIDTH ((SCREEN_WIDTH - CAM_OUT_WIDTH) / 2) #define QR_INDICATOR_HEIGHT 40 diff --git a/app/ui/ui.h b/app/ui/ui.h index 13c4634..d3ffcb5 100644 --- a/app/ui/ui.h +++ b/app/ui/ui.h @@ -5,7 +5,7 @@ #include "ethereum/ethUstream.h" #include "ethereum/eip712.h" #include "menu.h" -#include "ur/eip4527_types.h" +#include "ur/ur_types.h" #include "ur/ur.h" #define PIN_NEW_CODE -1 diff --git a/app/ui/ui_internal.h b/app/ui/ui_internal.h index 7aba526..adb0ed8 100644 --- a/app/ui/ui_internal.h +++ b/app/ui/ui_internal.h @@ -9,7 +9,7 @@ #include "core/core.h" #include "ethereum/ethUstream.h" #include "qrcode/qrcode.h" -#include "ur/eip4527_types.h" +#include "ur/ur_types.h" #include "ur/ur.h" #define UI_NOTIFICATION_IDX 2 diff --git a/app/ur/auth_decode.c b/app/ur/auth_decode.c deleted file mode 100644 index 2b96d14..0000000 --- a/app/ur/auth_decode.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#include -#include -#include -#include -#include "zcbor_decode.h" -#include "auth_decode.h" -#include "zcbor_print.h" - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - -static bool decode_dev_auth_step_type(zcbor_state_t *state, struct dev_auth_step_type_r *result); -static bool decode_uuid(zcbor_state_t *state, struct zcbor_string *result); -static bool decode_repeated_dev_auth_device_id(zcbor_state_t *state, struct dev_auth_device_id *result); -static bool decode_repeated_dev_auth_first_auth(zcbor_state_t *state, struct dev_auth_first_auth *result); -static bool decode_repeated_dev_auth_auth_time(zcbor_state_t *state, struct dev_auth_auth_time *result); -static bool decode_repeated_dev_auth_auth_count(zcbor_state_t *state, struct dev_auth_auth_count *result); -static bool decode_repeated_dev_auth_challenge(zcbor_state_t *state, struct dev_auth_challenge *result); -static bool decode_repeated_dev_auth_signature(zcbor_state_t *state, struct dev_auth_signature *result); -static bool decode_dev_auth(zcbor_state_t *state, struct dev_auth *result); - - -static bool decode_dev_auth_step_type( - zcbor_state_t *state, struct dev_auth_step_type_r *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((((zcbor_uint_decode(state, &(*result).dev_auth_step_type_choice, sizeof((*result).dev_auth_step_type_choice)))) && ((((((*result).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_init_m_c) && ((1))) - || (((*result).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_device_m_c) && ((1))) - || (((*result).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_server_m_c) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool decode_uuid( - zcbor_state_t *state, struct zcbor_string *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((zcbor_tag_expect(state, 37) - && (zcbor_bstr_decode(state, (&(*result)))) - && ((((*result).len >= 16) - && ((*result).len <= 16)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool decode_repeated_dev_auth_device_id( - zcbor_state_t *state, struct dev_auth_device_id *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_expect(state, (2)))) - && (decode_uuid(state, (&(*result).dev_auth_device_id))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool decode_repeated_dev_auth_first_auth( - zcbor_state_t *state, struct dev_auth_first_auth *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_expect(state, (3)))) - && (zcbor_uint32_decode(state, (&(*result).dev_auth_first_auth))) - && ((((((*result).dev_auth_first_auth <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool decode_repeated_dev_auth_auth_time( - zcbor_state_t *state, struct dev_auth_auth_time *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_expect(state, (4)))) - && (zcbor_uint32_decode(state, (&(*result).dev_auth_auth_time))) - && ((((((*result).dev_auth_auth_time <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool decode_repeated_dev_auth_auth_count( - zcbor_state_t *state, struct dev_auth_auth_count *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_expect(state, (5)))) - && (zcbor_uint32_decode(state, (&(*result).dev_auth_auth_count))) - && ((((((*result).dev_auth_auth_count <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool decode_repeated_dev_auth_challenge( - zcbor_state_t *state, struct dev_auth_challenge *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_expect(state, (6)))) - && (zcbor_bstr_decode(state, (&(*result).dev_auth_challenge))) - && ((((*result).dev_auth_challenge.len >= 32) - && ((*result).dev_auth_challenge.len <= 32)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool decode_repeated_dev_auth_signature( - zcbor_state_t *state, struct dev_auth_signature *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_expect(state, (7)))) - && (zcbor_bstr_decode(state, (&(*result).dev_auth_signature))) - && ((((*result).dev_auth_signature.len >= 64) - && ((*result).dev_auth_signature.len <= 64)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool decode_dev_auth( - zcbor_state_t *state, struct dev_auth *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_map_start_decode(state) && (((((zcbor_uint32_expect(state, (1)))) - && (decode_dev_auth_step_type(state, (&(*result).dev_auth_step)))) - && zcbor_present_decode(&((*result).dev_auth_device_id_present), (zcbor_decoder_t *)decode_repeated_dev_auth_device_id, state, (&(*result).dev_auth_device_id)) - && zcbor_present_decode(&((*result).dev_auth_first_auth_present), (zcbor_decoder_t *)decode_repeated_dev_auth_first_auth, state, (&(*result).dev_auth_first_auth)) - && zcbor_present_decode(&((*result).dev_auth_auth_time_present), (zcbor_decoder_t *)decode_repeated_dev_auth_auth_time, state, (&(*result).dev_auth_auth_time)) - && zcbor_present_decode(&((*result).dev_auth_auth_count_present), (zcbor_decoder_t *)decode_repeated_dev_auth_auth_count, state, (&(*result).dev_auth_auth_count)) - && zcbor_present_decode(&((*result).dev_auth_challenge_present), (zcbor_decoder_t *)decode_repeated_dev_auth_challenge, state, (&(*result).dev_auth_challenge)) - && zcbor_present_decode(&((*result).dev_auth_signature_present), (zcbor_decoder_t *)decode_repeated_dev_auth_signature, state, (&(*result).dev_auth_signature))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - - -int cbor_decode_dev_auth( - const uint8_t *payload, size_t payload_len, - struct dev_auth *result, - size_t *payload_len_out) -{ - zcbor_state_t states[4]; - - return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, - (zcbor_decoder_t *)decode_dev_auth, sizeof(states) / sizeof(zcbor_state_t), 1); -} diff --git a/app/ur/auth_decode.h b/app/ur/auth_decode.h deleted file mode 100644 index dc3ac6c..0000000 --- a/app/ur/auth_decode.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#ifndef AUTH_DECODE_H__ -#define AUTH_DECODE_H__ - -#include -#include -#include -#include -#include "auth_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - -int cbor_decode_dev_auth( - const uint8_t *payload, size_t payload_len, - struct dev_auth *result, - size_t *payload_len_out); - - -#ifdef __cplusplus -} -#endif - -#endif /* AUTH_DECODE_H__ */ diff --git a/app/ur/auth_encode.c b/app/ur/auth_encode.c deleted file mode 100644 index dd97f6d..0000000 --- a/app/ur/auth_encode.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#include -#include -#include -#include -#include "zcbor_encode.h" -#include "auth_encode.h" -#include "zcbor_print.h" - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - -static bool encode_dev_auth_step_type(zcbor_state_t *state, const struct dev_auth_step_type_r *input); -static bool encode_uuid(zcbor_state_t *state, const struct zcbor_string *input); -static bool encode_repeated_dev_auth_device_id(zcbor_state_t *state, const struct dev_auth_device_id *input); -static bool encode_repeated_dev_auth_first_auth(zcbor_state_t *state, const struct dev_auth_first_auth *input); -static bool encode_repeated_dev_auth_auth_time(zcbor_state_t *state, const struct dev_auth_auth_time *input); -static bool encode_repeated_dev_auth_auth_count(zcbor_state_t *state, const struct dev_auth_auth_count *input); -static bool encode_repeated_dev_auth_challenge(zcbor_state_t *state, const struct dev_auth_challenge *input); -static bool encode_repeated_dev_auth_signature(zcbor_state_t *state, const struct dev_auth_signature *input); -static bool encode_dev_auth(zcbor_state_t *state, const struct dev_auth *input); - - -static bool encode_dev_auth_step_type( - zcbor_state_t *state, const struct dev_auth_step_type_r *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((((*input).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_init_m_c) ? ((zcbor_uint32_put(state, (1)))) - : (((*input).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_device_m_c) ? ((zcbor_uint32_put(state, (2)))) - : (((*input).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_server_m_c) ? ((zcbor_uint32_put(state, (3)))) - : false))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool encode_uuid( - zcbor_state_t *state, const struct zcbor_string *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((zcbor_tag_put(state, 37) - && ((((*input).len >= 16) - && ((*input).len <= 16)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_bstr_encode(state, (&(*input)))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool encode_repeated_dev_auth_device_id( - zcbor_state_t *state, const struct dev_auth_device_id *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (2)))) - && (encode_uuid(state, (&(*input).dev_auth_device_id))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool encode_repeated_dev_auth_first_auth( - zcbor_state_t *state, const struct dev_auth_first_auth *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (3)))) - && ((((((*input).dev_auth_first_auth <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).dev_auth_first_auth))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool encode_repeated_dev_auth_auth_time( - zcbor_state_t *state, const struct dev_auth_auth_time *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (4)))) - && ((((((*input).dev_auth_auth_time <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).dev_auth_auth_time))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool encode_repeated_dev_auth_auth_count( - zcbor_state_t *state, const struct dev_auth_auth_count *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (5)))) - && ((((((*input).dev_auth_auth_count <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).dev_auth_auth_count))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool encode_repeated_dev_auth_challenge( - zcbor_state_t *state, const struct dev_auth_challenge *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (6)))) - && ((((*input).dev_auth_challenge.len >= 32) - && ((*input).dev_auth_challenge.len <= 32)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_bstr_encode(state, (&(*input).dev_auth_challenge))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool encode_repeated_dev_auth_signature( - zcbor_state_t *state, const struct dev_auth_signature *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (7)))) - && ((((*input).dev_auth_signature.len >= 64) - && ((*input).dev_auth_signature.len <= 64)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_bstr_encode(state, (&(*input).dev_auth_signature))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool encode_dev_auth( - zcbor_state_t *state, const struct dev_auth *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_map_start_encode(state, 7) && (((((zcbor_uint32_put(state, (1)))) - && (encode_dev_auth_step_type(state, (&(*input).dev_auth_step)))) - && (!(*input).dev_auth_device_id_present || encode_repeated_dev_auth_device_id(state, (&(*input).dev_auth_device_id))) - && (!(*input).dev_auth_first_auth_present || encode_repeated_dev_auth_first_auth(state, (&(*input).dev_auth_first_auth))) - && (!(*input).dev_auth_auth_time_present || encode_repeated_dev_auth_auth_time(state, (&(*input).dev_auth_auth_time))) - && (!(*input).dev_auth_auth_count_present || encode_repeated_dev_auth_auth_count(state, (&(*input).dev_auth_auth_count))) - && (!(*input).dev_auth_challenge_present || encode_repeated_dev_auth_challenge(state, (&(*input).dev_auth_challenge))) - && (!(*input).dev_auth_signature_present || encode_repeated_dev_auth_signature(state, (&(*input).dev_auth_signature)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 7)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - - -int cbor_encode_dev_auth( - uint8_t *payload, size_t payload_len, - const struct dev_auth *input, - size_t *payload_len_out) -{ - zcbor_state_t states[4]; - - return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, - (zcbor_decoder_t *)encode_dev_auth, sizeof(states) / sizeof(zcbor_state_t), 1); -} diff --git a/app/ur/auth_encode.h b/app/ur/auth_encode.h deleted file mode 100644 index dd11ee7..0000000 --- a/app/ur/auth_encode.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#ifndef AUTH_ENCODE_H__ -#define AUTH_ENCODE_H__ - -#include -#include -#include -#include -#include "auth_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - -int cbor_encode_dev_auth( - uint8_t *payload, size_t payload_len, - const struct dev_auth *input, - size_t *payload_len_out); - - -#ifdef __cplusplus -} -#endif - -#endif /* AUTH_ENCODE_H__ */ diff --git a/app/ur/auth_types.h b/app/ur/auth_types.h deleted file mode 100644 index 6ef2e02..0000000 --- a/app/ur/auth_types.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#ifndef AUTH_TYPES_H__ -#define AUTH_TYPES_H__ - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** Which value for --default-max-qty this file was created with. - * - * The define is used in the other generated file to do a build-time - * compatibility check. - * - * See `zcbor --help` for more information about --default-max-qty - */ -#define DEFAULT_MAX_QTY 3 - -struct dev_auth_step_type_r { - enum { - dev_auth_step_type_dev_auth_init_m_c = 1, - dev_auth_step_type_dev_auth_device_m_c = 2, - dev_auth_step_type_dev_auth_server_m_c = 3, - } dev_auth_step_type_choice; -}; - -struct dev_auth_device_id { - struct zcbor_string dev_auth_device_id; -}; - -struct dev_auth_first_auth { - uint32_t dev_auth_first_auth; -}; - -struct dev_auth_auth_time { - uint32_t dev_auth_auth_time; -}; - -struct dev_auth_auth_count { - uint32_t dev_auth_auth_count; -}; - -struct dev_auth_challenge { - struct zcbor_string dev_auth_challenge; -}; - -struct dev_auth_signature { - struct zcbor_string dev_auth_signature; -}; - -struct dev_auth { - struct dev_auth_step_type_r dev_auth_step; - struct dev_auth_device_id dev_auth_device_id; - bool dev_auth_device_id_present; - struct dev_auth_first_auth dev_auth_first_auth; - bool dev_auth_first_auth_present; - struct dev_auth_auth_time dev_auth_auth_time; - bool dev_auth_auth_time_present; - struct dev_auth_auth_count dev_auth_auth_count; - bool dev_auth_auth_count_present; - struct dev_auth_challenge dev_auth_challenge; - bool dev_auth_challenge_present; - struct dev_auth_signature dev_auth_signature; - bool dev_auth_signature_present; -}; - -#ifdef __cplusplus -} -#endif - -#endif /* AUTH_TYPES_H__ */ diff --git a/app/ur/btc_decode.c b/app/ur/btc_decode.c deleted file mode 100644 index 024b96f..0000000 --- a/app/ur/btc_decode.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#include -#include -#include -#include -#include "zcbor_decode.h" -#include "btc_decode.h" -#include "zcbor_print.h" - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - -static bool decode_psbt(zcbor_state_t *state, struct zcbor_string *result); - - -static bool decode_psbt( - zcbor_state_t *state, struct zcbor_string *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_bstr_decode(state, (&(*result)))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - - -int cbor_decode_psbt( - const uint8_t *payload, size_t payload_len, - struct zcbor_string *result, - size_t *payload_len_out) -{ - zcbor_state_t states[2]; - - return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, - (zcbor_decoder_t *)decode_psbt, sizeof(states) / sizeof(zcbor_state_t), 1); -} diff --git a/app/ur/btc_decode.h b/app/ur/btc_decode.h deleted file mode 100644 index be655fb..0000000 --- a/app/ur/btc_decode.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#ifndef BTC_DECODE_H__ -#define BTC_DECODE_H__ - -#include -#include -#include -#include -#include "btc_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - -int cbor_decode_psbt( - const uint8_t *payload, size_t payload_len, - struct zcbor_string *result, - size_t *payload_len_out); - - -#ifdef __cplusplus -} -#endif - -#endif /* BTC_DECODE_H__ */ diff --git a/app/ur/btc_encode.c b/app/ur/btc_encode.c deleted file mode 100644 index c2d3c47..0000000 --- a/app/ur/btc_encode.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#include -#include -#include -#include -#include "zcbor_encode.h" -#include "btc_encode.h" -#include "zcbor_print.h" - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - -static bool encode_psbt(zcbor_state_t *state, const struct zcbor_string *input); - - -static bool encode_psbt( - zcbor_state_t *state, const struct zcbor_string *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_bstr_encode(state, (&(*input)))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - - -int cbor_encode_psbt( - uint8_t *payload, size_t payload_len, - const struct zcbor_string *input, - size_t *payload_len_out) -{ - zcbor_state_t states[2]; - - return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, - (zcbor_decoder_t *)encode_psbt, sizeof(states) / sizeof(zcbor_state_t), 1); -} diff --git a/app/ur/btc_encode.h b/app/ur/btc_encode.h deleted file mode 100644 index 362fecb..0000000 --- a/app/ur/btc_encode.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#ifndef BTC_ENCODE_H__ -#define BTC_ENCODE_H__ - -#include -#include -#include -#include -#include "btc_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - -int cbor_encode_psbt( - uint8_t *payload, size_t payload_len, - const struct zcbor_string *input, - size_t *payload_len_out); - - -#ifdef __cplusplus -} -#endif - -#endif /* BTC_ENCODE_H__ */ diff --git a/app/ur/btc_types.h b/app/ur/btc_types.h deleted file mode 100644 index f251b70..0000000 --- a/app/ur/btc_types.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#ifndef BTC_TYPES_H__ -#define BTC_TYPES_H__ - -#include -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif - -/** Which value for --default-max-qty this file was created with. - * - * The define is used in the other generated file to do a build-time - * compatibility check. - * - * See `zcbor --help` for more information about --default-max-qty - */ -#define DEFAULT_MAX_QTY 3 - - - -#ifdef __cplusplus -} -#endif - -#endif /* BTC_TYPES_H__ */ diff --git a/app/ur/ur.c b/app/ur/ur.c index 0caff4d..e2b24f3 100644 --- a/app/ur/ur.c +++ b/app/ur/ur.c @@ -2,30 +2,30 @@ #include "ur.h" #include "bytewords.h" #include "sampler.h" -#include "ur_part_decode.h" +#include "ur_decode.h" #define MIN_ENCODED_LEN 22 #define MAX_CBOR_HEADER_LEN 32 -#define UR_TYPE(t) (ur_type_t)(((t * 4558338) >> 28) & 0xf) +#define UR_TYPE(t) (ur_type_t)(((t * 4597373) >> 28) & 0xf) const char *const ur_type_string[] = { - "ETH-SIGNATURE", - "CRYPTO-OUTPUT", - "CRYPTO-KEYPATH", - "ETH-SIGN-REQUEST", - NULL, - NULL, - "BYTES", - NULL, - "FS-DATA", - "DEV-AUTH", - "CRYPTO-MULTI-ACCOUNTS", - "FW-UPDATE", - NULL, - NULL, - "CRYPTO-PSBT", - "CRYPTO-HDKEY", + "ETH-SIGNATURE", + "CRYPTO-OUTPUT", + "CRYPTO-ACCOUNT", + NULL, + "ETH-SIGN-REQUEST", + NULL, + "BYTES", + NULL, + "FS-DATA", + "DEV-AUTH", + "CRYPTO-MULTI-ACCOUNTS", + "FW-UPDATE", + NULL, + NULL, + "CRYPTO-PSBT", + "CRYPTO-HDKEY", }; static app_err_t ur_process_simple(ur_t* ur, uint8_t* parts, uint8_t* part_data, size_t part_len, uint32_t desc_idx, struct ur_part* part) { diff --git a/app/ur/ur.h b/app/ur/ur.h index 279f080..36e9ac9 100644 --- a/app/ur/ur.h +++ b/app/ur/ur.h @@ -10,8 +10,8 @@ typedef enum { ETH_SIGNATURE = 0, CRYPTO_OUTPUT = 1, - CRYPTO_KEYPATH = 2, - ETH_SIGN_REQUEST = 3, + CRYPTO_ACCOUNT = 2, + ETH_SIGN_REQUEST = 4, BYTES = 6, FS_DATA = 8, DEV_AUTH = 9, diff --git a/app/ur/eip4527_decode.c b/app/ur/ur_decode.c similarity index 56% rename from app/ur/eip4527_decode.c rename to app/ur/ur_decode.c index d3c851b..d648e7a 100644 --- a/app/ur/eip4527_decode.c +++ b/app/ur/ur_decode.c @@ -9,7 +9,7 @@ #include #include #include "zcbor_decode.h" -#include "eip4527_decode.h" +#include "ur_decode.h" #include "zcbor_print.h" #if DEFAULT_MAX_QTY != 3 @@ -19,6 +19,13 @@ static bool decode_uuid(zcbor_state_t *state, struct zcbor_string *result); static bool decode_repeated_eth_signature_request_id(zcbor_state_t *state, struct eth_signature_request_id *result); static bool decode_repeated_eth_signature_signature_origin(zcbor_state_t *state, struct eth_signature_signature_origin *result); +static bool decode_dev_auth_step_type(zcbor_state_t *state, struct dev_auth_step_type_r *result); +static bool decode_repeated_dev_auth_dev_id(zcbor_state_t *state, struct dev_auth_dev_id *result); +static bool decode_repeated_dev_auth_first_auth(zcbor_state_t *state, struct dev_auth_first_auth *result); +static bool decode_repeated_dev_auth_auth_time(zcbor_state_t *state, struct dev_auth_auth_time *result); +static bool decode_repeated_dev_auth_auth_count(zcbor_state_t *state, struct dev_auth_auth_count *result); +static bool decode_repeated_dev_auth_challenge(zcbor_state_t *state, struct dev_auth_challenge *result); +static bool decode_repeated_dev_auth_auth_sig(zcbor_state_t *state, struct dev_auth_auth_sig *result); static bool decode_repeated_eth_sign_request_request_id(zcbor_state_t *state, struct eth_sign_request_request_id *result); static bool decode_sign_data_type(zcbor_state_t *state, struct sign_data_type_r *result); static bool decode_repeated_eth_sign_request_chain_id(zcbor_state_t *state, struct eth_sign_request_chain_id *result); @@ -31,9 +38,20 @@ static bool decode_repeated_eth_sign_request_request_origin(zcbor_state_t *state static bool decode_coininfo(zcbor_state_t *state, struct coininfo *result); static bool decode_repeated_hd_key_use_info(zcbor_state_t *state, struct hd_key_use_info *result); static bool decode_repeated_hd_key_source(zcbor_state_t *state, struct hd_key_source *result); +static bool decode_tagged_hd_key(zcbor_state_t *state, struct hd_key *result); static bool decode_repeated_crypto_multi_accounts_device(zcbor_state_t *state, struct crypto_multi_accounts_device *result); static bool decode_repeated_crypto_multi_accounts_device_id(zcbor_state_t *state, struct crypto_multi_accounts_device_id *result); static bool decode_repeated_crypto_multi_accounts_version(zcbor_state_t *state, struct crypto_multi_accounts_version *result); +static bool decode_key_exp(zcbor_state_t *state, struct hd_key *result); +static bool decode_witness_public_key_hash(zcbor_state_t *state, struct hd_key *result); +static bool decode_script_hash(zcbor_state_t *state, struct hd_key *result); +static bool decode_public_key_hash(zcbor_state_t *state, struct hd_key *result); +static bool decode_taproot(zcbor_state_t *state, struct hd_key *result); +static bool decode_crypto_output(zcbor_state_t *state, struct crypto_output_r *result); +static bool decode_psbt(zcbor_state_t *state, struct zcbor_string *result); +static bool decode_dev_auth(zcbor_state_t *state, struct dev_auth *result); +static bool decode_ur_part(zcbor_state_t *state, struct ur_part *result); +static bool decode_crypto_account(zcbor_state_t *state, struct crypto_account *result); static bool decode_crypto_multi_accounts(zcbor_state_t *state, struct crypto_multi_accounts *result); static bool decode_hd_key(zcbor_state_t *state, struct hd_key *result); static bool decode_eth_signature(zcbor_state_t *state, struct eth_signature *result); @@ -94,6 +112,140 @@ static bool decode_repeated_eth_signature_signature_origin( return tmp_result; } +static bool decode_dev_auth_step_type( + zcbor_state_t *state, struct dev_auth_step_type_r *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((((zcbor_uint_decode(state, &(*result).dev_auth_step_type_choice, sizeof((*result).dev_auth_step_type_choice)))) && ((((((*result).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_init_m_c) && ((1))) + || (((*result).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_device_m_c) && ((1))) + || (((*result).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_server_m_c) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_repeated_dev_auth_dev_id( + zcbor_state_t *state, struct dev_auth_dev_id *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_expect(state, (2)))) + && (decode_uuid(state, (&(*result).dev_auth_dev_id))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_repeated_dev_auth_first_auth( + zcbor_state_t *state, struct dev_auth_first_auth *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_expect(state, (3)))) + && (zcbor_uint32_decode(state, (&(*result).dev_auth_first_auth))) + && ((((((*result).dev_auth_first_auth <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_repeated_dev_auth_auth_time( + zcbor_state_t *state, struct dev_auth_auth_time *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_expect(state, (4)))) + && (zcbor_uint32_decode(state, (&(*result).dev_auth_auth_time))) + && ((((((*result).dev_auth_auth_time <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_repeated_dev_auth_auth_count( + zcbor_state_t *state, struct dev_auth_auth_count *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_expect(state, (5)))) + && (zcbor_uint32_decode(state, (&(*result).dev_auth_auth_count))) + && ((((((*result).dev_auth_auth_count <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_repeated_dev_auth_challenge( + zcbor_state_t *state, struct dev_auth_challenge *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_expect(state, (6)))) + && (zcbor_bstr_decode(state, (&(*result).dev_auth_challenge))) + && ((((*result).dev_auth_challenge.len >= 32) + && ((*result).dev_auth_challenge.len <= 32)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_repeated_dev_auth_auth_sig( + zcbor_state_t *state, struct dev_auth_auth_sig *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_expect(state, (7)))) + && (zcbor_bstr_decode(state, (&(*result).dev_auth_auth_sig))) + && ((((*result).dev_auth_auth_sig.len >= 64) + && ((*result).dev_auth_auth_sig.len <= 64)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + static bool decode_repeated_eth_sign_request_request_id( zcbor_state_t *state, struct eth_sign_request_request_id *result) { @@ -323,6 +475,24 @@ static bool decode_repeated_hd_key_source( return tmp_result; } +static bool decode_tagged_hd_key( + zcbor_state_t *state, struct hd_key *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_expect(state, 303) + && (decode_hd_key(state, (&(*result)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + static bool decode_repeated_crypto_multi_accounts_device( zcbor_state_t *state, struct crypto_multi_accounts_device *result) { @@ -377,6 +547,202 @@ static bool decode_repeated_crypto_multi_accounts_version( return tmp_result; } +static bool decode_key_exp( + zcbor_state_t *state, struct hd_key *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_expect(state, 303) + && (decode_hd_key(state, (&(*result)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_witness_public_key_hash( + zcbor_state_t *state, struct hd_key *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_expect(state, 404) + && (decode_key_exp(state, (&(*result)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_script_hash( + zcbor_state_t *state, struct hd_key *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_expect(state, 400) + && (decode_witness_public_key_hash(state, (&(*result)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_public_key_hash( + zcbor_state_t *state, struct hd_key *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_expect(state, 403) + && (decode_key_exp(state, (&(*result)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_taproot( + zcbor_state_t *state, struct hd_key *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_expect(state, 409) + && (decode_key_exp(state, (&(*result)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_crypto_output( + zcbor_state_t *state, struct crypto_output_r *result) +{ + zcbor_log("%s\r\n", __func__); + bool int_res; + + bool tmp_result = (((zcbor_union_start_code(state) && (int_res = ((((decode_script_hash(state, (&(*result).crypto_output_script_hash_m)))) && (((*result).crypto_output_choice = crypto_output_script_hash_m_c), true)) + || (zcbor_union_elem_code(state) && (((decode_public_key_hash(state, (&(*result).crypto_output_public_key_hash_m)))) && (((*result).crypto_output_choice = crypto_output_public_key_hash_m_c), true))) + || (zcbor_union_elem_code(state) && (((decode_witness_public_key_hash(state, (&(*result).crypto_output_witness_public_key_hash_m)))) && (((*result).crypto_output_choice = crypto_output_witness_public_key_hash_m_c), true))) + || (zcbor_union_elem_code(state) && (((decode_taproot(state, (&(*result).crypto_output_taproot_m)))) && (((*result).crypto_output_choice = crypto_output_taproot_m_c), true)))), zcbor_union_end_code(state), int_res)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_psbt( + zcbor_state_t *state, struct zcbor_string *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_bstr_decode(state, (&(*result)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_dev_auth( + zcbor_state_t *state, struct dev_auth *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_decode(state) && (((((zcbor_uint32_expect(state, (1)))) + && (decode_dev_auth_step_type(state, (&(*result).dev_auth_step)))) + && zcbor_present_decode(&((*result).dev_auth_dev_id_present), (zcbor_decoder_t *)decode_repeated_dev_auth_dev_id, state, (&(*result).dev_auth_dev_id)) + && zcbor_present_decode(&((*result).dev_auth_first_auth_present), (zcbor_decoder_t *)decode_repeated_dev_auth_first_auth, state, (&(*result).dev_auth_first_auth)) + && zcbor_present_decode(&((*result).dev_auth_auth_time_present), (zcbor_decoder_t *)decode_repeated_dev_auth_auth_time, state, (&(*result).dev_auth_auth_time)) + && zcbor_present_decode(&((*result).dev_auth_auth_count_present), (zcbor_decoder_t *)decode_repeated_dev_auth_auth_count, state, (&(*result).dev_auth_auth_count)) + && zcbor_present_decode(&((*result).dev_auth_challenge_present), (zcbor_decoder_t *)decode_repeated_dev_auth_challenge, state, (&(*result).dev_auth_challenge)) + && zcbor_present_decode(&((*result).dev_auth_auth_sig_present), (zcbor_decoder_t *)decode_repeated_dev_auth_auth_sig, state, (&(*result).dev_auth_auth_sig))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_ur_part( + zcbor_state_t *state, struct ur_part *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_list_start_decode(state) && ((((zcbor_uint32_decode(state, (&(*result).ur_part_seqNum))) + && ((((((*result).ur_part_seqNum <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) + && ((zcbor_uint32_decode(state, (&(*result).ur_part_seqLen)))) + && ((zcbor_uint32_decode(state, (&(*result).ur_part_messageLen)))) + && ((zcbor_uint32_decode(state, (&(*result).ur_part_checksum))) + && ((((((*result).ur_part_checksum <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) + && ((zcbor_bstr_decode(state, (&(*result).ur_part_data))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool decode_crypto_account( + zcbor_state_t *state, struct crypto_account *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_decode(state) && (((((zcbor_uint32_expect(state, (1)))) + && (zcbor_uint32_decode(state, (&(*result).crypto_account_master_fingerprint))) + && ((((((*result).crypto_account_master_fingerprint <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) + && (((zcbor_uint32_expect(state, (2)))) + && (zcbor_list_start_decode(state) && ((zcbor_multi_decode(0, 10, &(*result).crypto_account_output_descriptors_crypto_output_m_count, (zcbor_decoder_t *)decode_crypto_output, state, (&(*result).crypto_account_output_descriptors_crypto_output_m), sizeof(struct crypto_output_r))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + static bool decode_crypto_multi_accounts( zcbor_state_t *state, struct crypto_multi_accounts *result) { @@ -386,7 +752,7 @@ static bool decode_crypto_multi_accounts( && (zcbor_uint32_decode(state, (&(*result).crypto_multi_accounts_master_fingerprint))) && ((((((*result).crypto_multi_accounts_master_fingerprint <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && (((zcbor_uint32_expect(state, (2)))) - && (zcbor_list_start_decode(state) && ((zcbor_multi_decode(0, 10, &(*result).crypto_multi_accounts_keys_hd_key_m_count, (zcbor_decoder_t *)decode_hd_key, state, (&(*result).crypto_multi_accounts_keys_hd_key_m), sizeof(struct hd_key))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))) + && (zcbor_list_start_decode(state) && ((zcbor_multi_decode(0, 10, &(*result).crypto_multi_accounts_keys_tagged_hd_key_m_count, (zcbor_decoder_t *)decode_tagged_hd_key, state, (&(*result).crypto_multi_accounts_keys_tagged_hd_key_m), sizeof(struct hd_key))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))) && zcbor_present_decode(&((*result).crypto_multi_accounts_device_present), (zcbor_decoder_t *)decode_repeated_crypto_multi_accounts_device, state, (&(*result).crypto_multi_accounts_device)) && zcbor_present_decode(&((*result).crypto_multi_accounts_device_id_present), (zcbor_decoder_t *)decode_repeated_crypto_multi_accounts_device_id, state, (&(*result).crypto_multi_accounts_device_id)) && zcbor_present_decode(&((*result).crypto_multi_accounts_version_present), (zcbor_decoder_t *)decode_repeated_crypto_multi_accounts_version, state, (&(*result).crypto_multi_accounts_version))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); @@ -531,4 +897,52 @@ int cbor_decode_crypto_multi_accounts( return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, (zcbor_decoder_t *)decode_crypto_multi_accounts, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_decode_crypto_account( + const uint8_t *payload, size_t payload_len, + struct crypto_account *result, + size_t *payload_len_out) +{ + zcbor_state_t states[8]; + + return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, + (zcbor_decoder_t *)decode_crypto_account, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_decode_ur_part( + const uint8_t *payload, size_t payload_len, + struct ur_part *result, + size_t *payload_len_out) +{ + zcbor_state_t states[3]; + + return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, + (zcbor_decoder_t *)decode_ur_part, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_decode_dev_auth( + const uint8_t *payload, size_t payload_len, + struct dev_auth *result, + size_t *payload_len_out) +{ + zcbor_state_t states[4]; + + return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, + (zcbor_decoder_t *)decode_dev_auth, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_decode_psbt( + const uint8_t *payload, size_t payload_len, + struct zcbor_string *result, + size_t *payload_len_out) +{ + zcbor_state_t states[2]; + + return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, + (zcbor_decoder_t *)decode_psbt, sizeof(states) / sizeof(zcbor_state_t), 1); } diff --git a/app/ur/eip4527_decode.h b/app/ur/ur_decode.h similarity index 58% rename from app/ur/eip4527_decode.h rename to app/ur/ur_decode.h index ddfbc2c..760ce6d 100644 --- a/app/ur/eip4527_decode.h +++ b/app/ur/ur_decode.h @@ -4,14 +4,14 @@ * Generated with a --default-max-qty of 3 */ -#ifndef EIP4527_DECODE_H__ -#define EIP4527_DECODE_H__ +#ifndef UR_DECODE_H__ +#define UR_DECODE_H__ #include #include #include #include -#include "eip4527_types.h" +#include "ur_types.h" #ifdef __cplusplus extern "C" { @@ -43,6 +43,30 @@ int cbor_decode_hd_key( int cbor_decode_crypto_multi_accounts( const uint8_t *payload, size_t payload_len, struct crypto_multi_accounts *result, + size_t *payload_len_out); + + +int cbor_decode_crypto_account( + const uint8_t *payload, size_t payload_len, + struct crypto_account *result, + size_t *payload_len_out); + + +int cbor_decode_ur_part( + const uint8_t *payload, size_t payload_len, + struct ur_part *result, + size_t *payload_len_out); + + +int cbor_decode_dev_auth( + const uint8_t *payload, size_t payload_len, + struct dev_auth *result, + size_t *payload_len_out); + + +int cbor_decode_psbt( + const uint8_t *payload, size_t payload_len, + struct zcbor_string *result, size_t *payload_len_out); @@ -50,4 +74,4 @@ int cbor_decode_crypto_multi_accounts( } #endif -#endif /* EIP4527_DECODE_H__ */ +#endif /* UR_DECODE_H__ */ diff --git a/app/ur/eip4527_encode.c b/app/ur/ur_encode.c similarity index 54% rename from app/ur/eip4527_encode.c rename to app/ur/ur_encode.c index de1859f..9c9cc2f 100644 --- a/app/ur/eip4527_encode.c +++ b/app/ur/ur_encode.c @@ -1,586 +1,950 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#include -#include -#include -#include -#include "zcbor_encode.h" -#include "eip4527_encode.h" -#include "zcbor_print.h" - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - -static bool encode_uuid(zcbor_state_t *state, const struct zcbor_string *input); - -static bool encode_repeated_eth_signature_request_id(zcbor_state_t *state, const struct eth_signature_request_id *input); - -static bool encode_repeated_eth_signature_signature_origin(zcbor_state_t *state, const struct eth_signature_signature_origin *input); - -static bool encode_repeated_eth_sign_request_request_id(zcbor_state_t *state, const struct eth_sign_request_request_id *input); - -static bool encode_sign_data_type(zcbor_state_t *state, const struct sign_data_type_r *input); - -static bool encode_repeated_eth_sign_request_chain_id(zcbor_state_t *state, const struct eth_sign_request_chain_id *input); - -static bool encode_path_component(zcbor_state_t *state, const struct path_component *input); - -static bool encode_repeated_crypto_keypath_source_fingerprint(zcbor_state_t *state, const struct crypto_keypath_source_fingerprint *input); - -static bool encode_repeated_crypto_keypath_depth(zcbor_state_t *state, const struct crypto_keypath_depth *input); - -static bool encode_crypto_keypath(zcbor_state_t *state, const struct crypto_keypath *input); - -static bool encode_repeated_eth_sign_request_address(zcbor_state_t *state, const struct eth_sign_request_address *input); - -static bool encode_repeated_eth_sign_request_request_origin(zcbor_state_t *state, const struct eth_sign_request_request_origin *input); - -static bool encode_coininfo(zcbor_state_t *state, const struct coininfo *input); - -static bool encode_repeated_hd_key_use_info(zcbor_state_t *state, const struct hd_key_use_info *input); - -static bool encode_repeated_hd_key_source(zcbor_state_t *state, const struct hd_key_source *input); - -static bool encode_repeated_crypto_multi_accounts_device(zcbor_state_t *state, const struct crypto_multi_accounts_device *input); - -static bool encode_repeated_crypto_multi_accounts_device_id(zcbor_state_t *state, const struct crypto_multi_accounts_device_id *input); - -static bool encode_repeated_crypto_multi_accounts_version(zcbor_state_t *state, const struct crypto_multi_accounts_version *input); - -static bool encode_crypto_multi_accounts(zcbor_state_t *state, const struct crypto_multi_accounts *input); - -static bool encode_hd_key(zcbor_state_t *state, const struct hd_key *input); - -static bool encode_eth_signature(zcbor_state_t *state, const struct eth_signature *input); - -static bool encode_eth_sign_request(zcbor_state_t *state, const struct eth_sign_request *input); - - -static bool encode_uuid( - zcbor_state_t *state, const struct zcbor_string *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((zcbor_tag_put(state, 37) - && (zcbor_bstr_encode(state, (&(*input)))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_eth_signature_request_id( - zcbor_state_t *state, const struct eth_signature_request_id *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (1)))) - && (encode_uuid(state, (&(*input).eth_signature_request_id))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_eth_signature_signature_origin( - zcbor_state_t *state, const struct eth_signature_signature_origin *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (3)))) - && (zcbor_tstr_encode(state, (&(*input).eth_signature_signature_origin))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_eth_sign_request_request_id( - zcbor_state_t *state, const struct eth_sign_request_request_id *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (1)))) - && (encode_uuid(state, (&(*input).eth_sign_request_request_id))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_sign_data_type( - zcbor_state_t *state, const struct sign_data_type_r *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((((*input).sign_data_type_choice == sign_data_type_eth_transaction_data_m_c) ? ((zcbor_uint32_put(state, (1)))) - : (((*input).sign_data_type_choice == sign_data_type_eth_typed_data_m_c) ? ((zcbor_uint32_put(state, (2)))) - : (((*input).sign_data_type_choice == sign_data_type_eth_raw_bytes_m_c) ? ((zcbor_uint32_put(state, (3)))) - : (((*input).sign_data_type_choice == sign_data_type_eth_typed_transaction_m_c) ? ((zcbor_uint32_put(state, (4)))) - : false)))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_eth_sign_request_chain_id( - zcbor_state_t *state, const struct eth_sign_request_chain_id *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (4)))) - && (zcbor_int32_encode(state, (&(*input).eth_sign_request_chain_id))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_path_component( - zcbor_state_t *state, const struct path_component *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((((((((((((*input).path_component_child_index_m <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).path_component_child_index_m)))) - && ((zcbor_bool_encode(state, (&(*input).path_component_is_hardened_m))))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_crypto_keypath_source_fingerprint( - zcbor_state_t *state, const struct crypto_keypath_source_fingerprint *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (2)))) - && ((((((*input).crypto_keypath_source_fingerprint <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).crypto_keypath_source_fingerprint))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_crypto_keypath_depth( - zcbor_state_t *state, const struct crypto_keypath_depth *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (3)))) - && ((((((*input).crypto_keypath_depth <= UINT8_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).crypto_keypath_depth))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_crypto_keypath( - zcbor_state_t *state, const struct crypto_keypath *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_map_start_encode(state, 3) && (((((zcbor_uint32_put(state, (1)))) - && (zcbor_list_start_encode(state, 20) && ((zcbor_multi_encode_minmax(0, 10, &(*input).crypto_keypath_components_path_component_m_count, (zcbor_encoder_t *)encode_path_component, state, (&(*input).crypto_keypath_components_path_component_m), sizeof(struct path_component))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 20))) - && (!(*input).crypto_keypath_source_fingerprint_present || encode_repeated_crypto_keypath_source_fingerprint(state, (&(*input).crypto_keypath_source_fingerprint))) - && (!(*input).crypto_keypath_depth_present || encode_repeated_crypto_keypath_depth(state, (&(*input).crypto_keypath_depth)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 3)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_eth_sign_request_address( - zcbor_state_t *state, const struct eth_sign_request_address *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (6)))) - && ((((((*input).eth_sign_request_address.len >= 20) - && ((*input).eth_sign_request_address.len <= 20)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_bstr_encode(state, (&(*input).eth_sign_request_address))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_eth_sign_request_request_origin( - zcbor_state_t *state, const struct eth_sign_request_request_origin *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (7)))) - && (zcbor_tstr_encode(state, (&(*input).eth_sign_request_request_origin))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_coininfo( - zcbor_state_t *state, const struct coininfo *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_map_start_encode(state, 2) && (((((zcbor_uint32_put(state, (1)))) - && ((((((((*input).coininfo_coin_type <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).coininfo_coin_type)))) - && (((zcbor_uint32_put(state, (2)))) - && (zcbor_int32_encode(state, (&(*input).coininfo_network))))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 2)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_hd_key_use_info( - zcbor_state_t *state, const struct hd_key_use_info *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (5)))) - && zcbor_tag_put(state, 305) - && (encode_coininfo(state, (&(*input).hd_key_use_info))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_hd_key_source( - zcbor_state_t *state, const struct hd_key_source *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (10)))) - && (zcbor_tstr_encode(state, (&(*input).hd_key_source))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_crypto_multi_accounts_device( - zcbor_state_t *state, const struct crypto_multi_accounts_device *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (3)))) - && (zcbor_tstr_encode(state, (&(*input).crypto_multi_accounts_device))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_crypto_multi_accounts_device_id( - zcbor_state_t *state, const struct crypto_multi_accounts_device_id *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (4)))) - && (zcbor_tstr_encode(state, (&(*input).crypto_multi_accounts_device_id))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_repeated_crypto_multi_accounts_version( - zcbor_state_t *state, const struct crypto_multi_accounts_version *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (5)))) - && (zcbor_tstr_encode(state, (&(*input).crypto_multi_accounts_version))))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - -static bool encode_crypto_multi_accounts_key( - zcbor_state_t *state, const struct hd_key *input) -{ - zcbor_tag_put(state, 303); - return encode_hd_key(state, input); -} - -static bool encode_crypto_multi_accounts( - zcbor_state_t *state, const struct crypto_multi_accounts *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_map_start_encode(state, 5) && (((((zcbor_uint32_put(state, (1)))) - && ((((((*input).crypto_multi_accounts_master_fingerprint <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).crypto_multi_accounts_master_fingerprint)))) - && (((zcbor_uint32_put(state, (2)))) - && (zcbor_list_start_encode(state, 10) && ((zcbor_multi_encode_minmax(0, 10, &(*input).crypto_multi_accounts_keys_hd_key_m_count, (zcbor_encoder_t *)encode_crypto_multi_accounts_key, state, (&(*input).crypto_multi_accounts_keys_hd_key_m), sizeof(struct hd_key))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 10))) - && (!(*input).crypto_multi_accounts_device_present || encode_repeated_crypto_multi_accounts_device(state, (&(*input).crypto_multi_accounts_device))) - && (!(*input).crypto_multi_accounts_device_id_present || encode_repeated_crypto_multi_accounts_device_id(state, (&(*input).crypto_multi_accounts_device_id))) - && (!(*input).crypto_multi_accounts_version_present || encode_repeated_crypto_multi_accounts_version(state, (&(*input).crypto_multi_accounts_version)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 5)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_hd_key( - zcbor_state_t *state, const struct hd_key *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_map_start_encode(state, 8) && (((((zcbor_uint32_put(state, (2)))) - && (zcbor_bool_encode(state, (&(*input).hd_key_is_private)))) - && (((zcbor_uint32_put(state, (3)))) - && ((((((*input).hd_key_key_data.len >= 33) - && ((*input).hd_key_key_data.len <= 33)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_bstr_encode(state, (&(*input).hd_key_key_data)))) - && (((zcbor_uint32_put(state, (4)))) - && ((((((*input).hd_key_chain_code.len >= 32) - && ((*input).hd_key_chain_code.len <= 32)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_bstr_encode(state, (&(*input).hd_key_chain_code)))) - && (!(*input).hd_key_use_info_present || encode_repeated_hd_key_use_info(state, (&(*input).hd_key_use_info))) - && (((zcbor_uint32_put(state, (6)))) - && zcbor_tag_put(state, 304) - && (encode_crypto_keypath(state, (&(*input).hd_key_origin)))) - && (((zcbor_uint32_put(state, (8)))) - && ((((((*input).hd_key_parent_fingerprint <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).hd_key_parent_fingerprint)))) - && (((zcbor_uint32_put(state, (9)))) - && (zcbor_tstr_encode(state, (&(*input).hd_key_name)))) - && (!(*input).hd_key_source_present || encode_repeated_hd_key_source(state, (&(*input).hd_key_source)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 8)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_eth_signature( - zcbor_state_t *state, const struct eth_signature *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_map_start_encode(state, 3) && (((!(*input).eth_signature_request_id_present || encode_repeated_eth_signature_request_id(state, (&(*input).eth_signature_request_id))) - && (((zcbor_uint32_put(state, (2)))) - && (zcbor_bstr_encode(state, (&(*input).eth_signature_signature)))) - && (!(*input).eth_signature_signature_origin_present || encode_repeated_eth_signature_signature_origin(state, (&(*input).eth_signature_signature_origin)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 3)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - -static bool encode_eth_sign_request( - zcbor_state_t *state, const struct eth_sign_request *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_map_start_encode(state, 7) && (((!(*input).eth_sign_request_request_id_present || encode_repeated_eth_sign_request_request_id(state, (&(*input).eth_sign_request_request_id))) - && (((zcbor_uint32_put(state, (2)))) - && (zcbor_bstr_encode(state, (&(*input).eth_sign_request_sign_data)))) - && (((zcbor_uint32_put(state, (3)))) - && (encode_sign_data_type(state, (&(*input).eth_sign_request_data_type)))) - && (!(*input).eth_sign_request_chain_id_present || encode_repeated_eth_sign_request_chain_id(state, (&(*input).eth_sign_request_chain_id))) - && (((zcbor_uint32_put(state, (5)))) - && zcbor_tag_put(state, 304) - && (encode_crypto_keypath(state, (&(*input).eth_sign_request_derivation_path)))) - && (!(*input).eth_sign_request_address_present || encode_repeated_eth_sign_request_address(state, (&(*input).eth_sign_request_address))) - && (!(*input).eth_sign_request_request_origin_present || encode_repeated_eth_sign_request_request_origin(state, (&(*input).eth_sign_request_request_origin)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 7)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - - -int cbor_encode_eth_sign_request( - uint8_t *payload, size_t payload_len, - const struct eth_sign_request *input, - size_t *payload_len_out) -{ - zcbor_state_t states[5]; - - return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, - (zcbor_decoder_t *)encode_eth_sign_request, sizeof(states) / sizeof(zcbor_state_t), 1); -} - - - -int cbor_encode_eth_signature( - uint8_t *payload, size_t payload_len, - const struct eth_signature *input, - size_t *payload_len_out) -{ - zcbor_state_t states[3]; - - return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, - (zcbor_decoder_t *)encode_eth_signature, sizeof(states) / sizeof(zcbor_state_t), 1); -} - - - -int cbor_encode_hd_key( - uint8_t *payload, size_t payload_len, - const struct hd_key *input, - size_t *payload_len_out) -{ - zcbor_state_t states[5]; - - return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, - (zcbor_decoder_t *)encode_hd_key, sizeof(states) / sizeof(zcbor_state_t), 1); -} - - - -int cbor_encode_crypto_multi_accounts( - uint8_t *payload, size_t payload_len, - const struct crypto_multi_accounts *input, - size_t *payload_len_out) -{ - zcbor_state_t states[7]; - - return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, - (zcbor_decoder_t *)encode_crypto_multi_accounts, sizeof(states) / sizeof(zcbor_state_t), 1); -} +/* + * Generated using zcbor version 0.8.1 + * https://github.com/NordicSemiconductor/zcbor + * Generated with a --default-max-qty of 3 + */ + +#include +#include +#include +#include +#include "zcbor_encode.h" +#include "ur_encode.h" +#include "zcbor_print.h" + +#if DEFAULT_MAX_QTY != 3 +#error "The type file was generated with a different default_max_qty than this file" +#endif + +static bool encode_uuid(zcbor_state_t *state, const struct zcbor_string *input); +static bool encode_repeated_eth_signature_request_id(zcbor_state_t *state, const struct eth_signature_request_id *input); +static bool encode_repeated_eth_signature_signature_origin(zcbor_state_t *state, const struct eth_signature_signature_origin *input); +static bool encode_dev_auth_step_type(zcbor_state_t *state, const struct dev_auth_step_type_r *input); +static bool encode_repeated_dev_auth_dev_id(zcbor_state_t *state, const struct dev_auth_dev_id *input); +static bool encode_repeated_dev_auth_first_auth(zcbor_state_t *state, const struct dev_auth_first_auth *input); +static bool encode_repeated_dev_auth_auth_time(zcbor_state_t *state, const struct dev_auth_auth_time *input); +static bool encode_repeated_dev_auth_auth_count(zcbor_state_t *state, const struct dev_auth_auth_count *input); +static bool encode_repeated_dev_auth_challenge(zcbor_state_t *state, const struct dev_auth_challenge *input); +static bool encode_repeated_dev_auth_auth_sig(zcbor_state_t *state, const struct dev_auth_auth_sig *input); +static bool encode_repeated_eth_sign_request_request_id(zcbor_state_t *state, const struct eth_sign_request_request_id *input); +static bool encode_sign_data_type(zcbor_state_t *state, const struct sign_data_type_r *input); +static bool encode_repeated_eth_sign_request_chain_id(zcbor_state_t *state, const struct eth_sign_request_chain_id *input); +static bool encode_path_component(zcbor_state_t *state, const struct path_component *input); +static bool encode_repeated_crypto_keypath_source_fingerprint(zcbor_state_t *state, const struct crypto_keypath_source_fingerprint *input); +static bool encode_repeated_crypto_keypath_depth(zcbor_state_t *state, const struct crypto_keypath_depth *input); +static bool encode_crypto_keypath(zcbor_state_t *state, const struct crypto_keypath *input); +static bool encode_repeated_eth_sign_request_address(zcbor_state_t *state, const struct eth_sign_request_address *input); +static bool encode_repeated_eth_sign_request_request_origin(zcbor_state_t *state, const struct eth_sign_request_request_origin *input); +static bool encode_coininfo(zcbor_state_t *state, const struct coininfo *input); +static bool encode_repeated_hd_key_use_info(zcbor_state_t *state, const struct hd_key_use_info *input); +static bool encode_repeated_hd_key_source(zcbor_state_t *state, const struct hd_key_source *input); +static bool encode_tagged_hd_key(zcbor_state_t *state, const struct hd_key *input); +static bool encode_repeated_crypto_multi_accounts_device(zcbor_state_t *state, const struct crypto_multi_accounts_device *input); +static bool encode_repeated_crypto_multi_accounts_device_id(zcbor_state_t *state, const struct crypto_multi_accounts_device_id *input); +static bool encode_repeated_crypto_multi_accounts_version(zcbor_state_t *state, const struct crypto_multi_accounts_version *input); +static bool encode_key_exp(zcbor_state_t *state, const struct hd_key *input); +static bool encode_witness_public_key_hash(zcbor_state_t *state, const struct hd_key *input); +static bool encode_script_hash(zcbor_state_t *state, const struct hd_key *input); +static bool encode_public_key_hash(zcbor_state_t *state, const struct hd_key *input); +static bool encode_taproot(zcbor_state_t *state, const struct hd_key *input); +static bool encode_crypto_output(zcbor_state_t *state, const struct crypto_output_r *input); +static bool encode_psbt(zcbor_state_t *state, const struct zcbor_string *input); +static bool encode_dev_auth(zcbor_state_t *state, const struct dev_auth *input); +static bool encode_ur_part(zcbor_state_t *state, const struct ur_part *input); +static bool encode_crypto_account(zcbor_state_t *state, const struct crypto_account *input); +static bool encode_crypto_multi_accounts(zcbor_state_t *state, const struct crypto_multi_accounts *input); +static bool encode_hd_key(zcbor_state_t *state, const struct hd_key *input); +static bool encode_eth_signature(zcbor_state_t *state, const struct eth_signature *input); +static bool encode_eth_sign_request(zcbor_state_t *state, const struct eth_sign_request *input); + + +static bool encode_uuid( + zcbor_state_t *state, const struct zcbor_string *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_put(state, 37) + && (zcbor_bstr_encode(state, (&(*input)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_eth_signature_request_id( + zcbor_state_t *state, const struct eth_signature_request_id *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (1)))) + && (encode_uuid(state, (&(*input).eth_signature_request_id))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_eth_signature_signature_origin( + zcbor_state_t *state, const struct eth_signature_signature_origin *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (3)))) + && (zcbor_tstr_encode(state, (&(*input).eth_signature_signature_origin))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_dev_auth_step_type( + zcbor_state_t *state, const struct dev_auth_step_type_r *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((((*input).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_init_m_c) ? ((zcbor_uint32_put(state, (1)))) + : (((*input).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_device_m_c) ? ((zcbor_uint32_put(state, (2)))) + : (((*input).dev_auth_step_type_choice == dev_auth_step_type_dev_auth_server_m_c) ? ((zcbor_uint32_put(state, (3)))) + : false))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_dev_auth_dev_id( + zcbor_state_t *state, const struct dev_auth_dev_id *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (2)))) + && (encode_uuid(state, (&(*input).dev_auth_dev_id))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_dev_auth_first_auth( + zcbor_state_t *state, const struct dev_auth_first_auth *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (3)))) + && ((((((*input).dev_auth_first_auth <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).dev_auth_first_auth))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_dev_auth_auth_time( + zcbor_state_t *state, const struct dev_auth_auth_time *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (4)))) + && ((((((*input).dev_auth_auth_time <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).dev_auth_auth_time))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_dev_auth_auth_count( + zcbor_state_t *state, const struct dev_auth_auth_count *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (5)))) + && ((((((*input).dev_auth_auth_count <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).dev_auth_auth_count))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_dev_auth_challenge( + zcbor_state_t *state, const struct dev_auth_challenge *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (6)))) + && ((((*input).dev_auth_challenge.len >= 32) + && ((*input).dev_auth_challenge.len <= 32)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_bstr_encode(state, (&(*input).dev_auth_challenge))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_dev_auth_auth_sig( + zcbor_state_t *state, const struct dev_auth_auth_sig *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (7)))) + && ((((*input).dev_auth_auth_sig.len >= 64) + && ((*input).dev_auth_auth_sig.len <= 64)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_bstr_encode(state, (&(*input).dev_auth_auth_sig))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_eth_sign_request_request_id( + zcbor_state_t *state, const struct eth_sign_request_request_id *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (1)))) + && (encode_uuid(state, (&(*input).eth_sign_request_request_id))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_sign_data_type( + zcbor_state_t *state, const struct sign_data_type_r *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((((*input).sign_data_type_choice == sign_data_type_eth_transaction_data_m_c) ? ((zcbor_uint32_put(state, (1)))) + : (((*input).sign_data_type_choice == sign_data_type_eth_typed_data_m_c) ? ((zcbor_uint32_put(state, (2)))) + : (((*input).sign_data_type_choice == sign_data_type_eth_raw_bytes_m_c) ? ((zcbor_uint32_put(state, (3)))) + : (((*input).sign_data_type_choice == sign_data_type_eth_typed_transaction_m_c) ? ((zcbor_uint32_put(state, (4)))) + : false)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_eth_sign_request_chain_id( + zcbor_state_t *state, const struct eth_sign_request_chain_id *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (4)))) + && (zcbor_int32_encode(state, (&(*input).eth_sign_request_chain_id))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_path_component( + zcbor_state_t *state, const struct path_component *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((((((((((((*input).path_component_child_index_m <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).path_component_child_index_m)))) + && ((zcbor_bool_encode(state, (&(*input).path_component_is_hardened_m))))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_crypto_keypath_source_fingerprint( + zcbor_state_t *state, const struct crypto_keypath_source_fingerprint *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (2)))) + && ((((((*input).crypto_keypath_source_fingerprint <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).crypto_keypath_source_fingerprint))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_crypto_keypath_depth( + zcbor_state_t *state, const struct crypto_keypath_depth *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (3)))) + && ((((((*input).crypto_keypath_depth <= UINT8_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).crypto_keypath_depth))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_crypto_keypath( + zcbor_state_t *state, const struct crypto_keypath *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 3) && (((((zcbor_uint32_put(state, (1)))) + && (zcbor_list_start_encode(state, 20) && ((zcbor_multi_encode_minmax(0, 10, &(*input).crypto_keypath_components_path_component_m_count, (zcbor_encoder_t *)encode_path_component, state, (&(*input).crypto_keypath_components_path_component_m), sizeof(struct path_component))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 20))) + && (!(*input).crypto_keypath_source_fingerprint_present || encode_repeated_crypto_keypath_source_fingerprint(state, (&(*input).crypto_keypath_source_fingerprint))) + && (!(*input).crypto_keypath_depth_present || encode_repeated_crypto_keypath_depth(state, (&(*input).crypto_keypath_depth)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 3)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_eth_sign_request_address( + zcbor_state_t *state, const struct eth_sign_request_address *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (6)))) + && ((((((*input).eth_sign_request_address.len >= 20) + && ((*input).eth_sign_request_address.len <= 20)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_bstr_encode(state, (&(*input).eth_sign_request_address))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_eth_sign_request_request_origin( + zcbor_state_t *state, const struct eth_sign_request_request_origin *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (7)))) + && (zcbor_tstr_encode(state, (&(*input).eth_sign_request_request_origin))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_coininfo( + zcbor_state_t *state, const struct coininfo *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 2) && (((((zcbor_uint32_put(state, (1)))) + && ((((((((*input).coininfo_coin_type <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).coininfo_coin_type)))) + && (((zcbor_uint32_put(state, (2)))) + && (zcbor_int32_encode(state, (&(*input).coininfo_network))))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 2)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_hd_key_use_info( + zcbor_state_t *state, const struct hd_key_use_info *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (5)))) + && zcbor_tag_put(state, 305) + && (encode_coininfo(state, (&(*input).hd_key_use_info))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_hd_key_source( + zcbor_state_t *state, const struct hd_key_source *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (10)))) + && (zcbor_tstr_encode(state, (&(*input).hd_key_source))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_tagged_hd_key( + zcbor_state_t *state, const struct hd_key *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_put(state, 303) + && (encode_hd_key(state, (&(*input)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_crypto_multi_accounts_device( + zcbor_state_t *state, const struct crypto_multi_accounts_device *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (3)))) + && (zcbor_tstr_encode(state, (&(*input).crypto_multi_accounts_device))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_crypto_multi_accounts_device_id( + zcbor_state_t *state, const struct crypto_multi_accounts_device_id *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (4)))) + && (zcbor_tstr_encode(state, (&(*input).crypto_multi_accounts_device_id))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_repeated_crypto_multi_accounts_version( + zcbor_state_t *state, const struct crypto_multi_accounts_version *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (5)))) + && (zcbor_tstr_encode(state, (&(*input).crypto_multi_accounts_version))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_key_exp( + zcbor_state_t *state, const struct hd_key *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_put(state, 303) + && (encode_hd_key(state, (&(*input)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_witness_public_key_hash( + zcbor_state_t *state, const struct hd_key *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_put(state, 404) + && (encode_key_exp(state, (&(*input)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_script_hash( + zcbor_state_t *state, const struct hd_key *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_put(state, 400) + && (encode_witness_public_key_hash(state, (&(*input)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_public_key_hash( + zcbor_state_t *state, const struct hd_key *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_put(state, 403) + && (encode_key_exp(state, (&(*input)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_taproot( + zcbor_state_t *state, const struct hd_key *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((zcbor_tag_put(state, 409) + && (encode_key_exp(state, (&(*input)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_crypto_output( + zcbor_state_t *state, const struct crypto_output_r *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((((*input).crypto_output_choice == crypto_output_script_hash_m_c) ? ((encode_script_hash(state, (&(*input).crypto_output_script_hash_m)))) + : (((*input).crypto_output_choice == crypto_output_public_key_hash_m_c) ? ((encode_public_key_hash(state, (&(*input).crypto_output_public_key_hash_m)))) + : (((*input).crypto_output_choice == crypto_output_witness_public_key_hash_m_c) ? ((encode_witness_public_key_hash(state, (&(*input).crypto_output_witness_public_key_hash_m)))) + : (((*input).crypto_output_choice == crypto_output_taproot_m_c) ? ((encode_taproot(state, (&(*input).crypto_output_taproot_m)))) + : false)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_psbt( + zcbor_state_t *state, const struct zcbor_string *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_bstr_encode(state, (&(*input)))))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_dev_auth( + zcbor_state_t *state, const struct dev_auth *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 7) && (((((zcbor_uint32_put(state, (1)))) + && (encode_dev_auth_step_type(state, (&(*input).dev_auth_step)))) + && (!(*input).dev_auth_dev_id_present || encode_repeated_dev_auth_dev_id(state, (&(*input).dev_auth_dev_id))) + && (!(*input).dev_auth_first_auth_present || encode_repeated_dev_auth_first_auth(state, (&(*input).dev_auth_first_auth))) + && (!(*input).dev_auth_auth_time_present || encode_repeated_dev_auth_auth_time(state, (&(*input).dev_auth_auth_time))) + && (!(*input).dev_auth_auth_count_present || encode_repeated_dev_auth_auth_count(state, (&(*input).dev_auth_auth_count))) + && (!(*input).dev_auth_challenge_present || encode_repeated_dev_auth_challenge(state, (&(*input).dev_auth_challenge))) + && (!(*input).dev_auth_auth_sig_present || encode_repeated_dev_auth_auth_sig(state, (&(*input).dev_auth_auth_sig)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 7)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_ur_part( + zcbor_state_t *state, const struct ur_part *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_list_start_encode(state, 5) && (((((((((*input).ur_part_seqNum <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).ur_part_seqNum)))) + && ((zcbor_uint32_encode(state, (&(*input).ur_part_seqLen)))) + && ((zcbor_uint32_encode(state, (&(*input).ur_part_messageLen)))) + && (((((((*input).ur_part_checksum <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).ur_part_checksum)))) + && ((zcbor_bstr_encode(state, (&(*input).ur_part_data))))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 5)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_crypto_account( + zcbor_state_t *state, const struct crypto_account *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 2) && (((((zcbor_uint32_put(state, (1)))) + && ((((((*input).crypto_account_master_fingerprint <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).crypto_account_master_fingerprint)))) + && (((zcbor_uint32_put(state, (2)))) + && (zcbor_list_start_encode(state, 10) && ((zcbor_multi_encode_minmax(0, 10, &(*input).crypto_account_output_descriptors_crypto_output_m_count, (zcbor_encoder_t *)encode_crypto_output, state, (&(*input).crypto_account_output_descriptors_crypto_output_m), sizeof(struct crypto_output_r))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 10)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 2)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_crypto_multi_accounts( + zcbor_state_t *state, const struct crypto_multi_accounts *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 5) && (((((zcbor_uint32_put(state, (1)))) + && ((((((*input).crypto_multi_accounts_master_fingerprint <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).crypto_multi_accounts_master_fingerprint)))) + && (((zcbor_uint32_put(state, (2)))) + && (zcbor_list_start_encode(state, 10) && ((zcbor_multi_encode_minmax(0, 10, &(*input).crypto_multi_accounts_keys_tagged_hd_key_m_count, (zcbor_encoder_t *)encode_tagged_hd_key, state, (&(*input).crypto_multi_accounts_keys_tagged_hd_key_m), sizeof(struct hd_key))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 10))) + && (!(*input).crypto_multi_accounts_device_present || encode_repeated_crypto_multi_accounts_device(state, (&(*input).crypto_multi_accounts_device))) + && (!(*input).crypto_multi_accounts_device_id_present || encode_repeated_crypto_multi_accounts_device_id(state, (&(*input).crypto_multi_accounts_device_id))) + && (!(*input).crypto_multi_accounts_version_present || encode_repeated_crypto_multi_accounts_version(state, (&(*input).crypto_multi_accounts_version)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 5)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_hd_key( + zcbor_state_t *state, const struct hd_key *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 8) && (((((zcbor_uint32_put(state, (2)))) + && (zcbor_bool_encode(state, (&(*input).hd_key_is_private)))) + && (((zcbor_uint32_put(state, (3)))) + && ((((((*input).hd_key_key_data.len >= 33) + && ((*input).hd_key_key_data.len <= 33)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_bstr_encode(state, (&(*input).hd_key_key_data)))) + && (((zcbor_uint32_put(state, (4)))) + && ((((((*input).hd_key_chain_code.len >= 32) + && ((*input).hd_key_chain_code.len <= 32)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_bstr_encode(state, (&(*input).hd_key_chain_code)))) + && (!(*input).hd_key_use_info_present || encode_repeated_hd_key_use_info(state, (&(*input).hd_key_use_info))) + && (((zcbor_uint32_put(state, (6)))) + && zcbor_tag_put(state, 304) + && (encode_crypto_keypath(state, (&(*input).hd_key_origin)))) + && (((zcbor_uint32_put(state, (8)))) + && ((((((*input).hd_key_parent_fingerprint <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) + && (zcbor_uint32_encode(state, (&(*input).hd_key_parent_fingerprint)))) + && (((zcbor_uint32_put(state, (9)))) + && (zcbor_tstr_encode(state, (&(*input).hd_key_name)))) + && (!(*input).hd_key_source_present || encode_repeated_hd_key_source(state, (&(*input).hd_key_source)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 8)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_eth_signature( + zcbor_state_t *state, const struct eth_signature *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 3) && (((!(*input).eth_signature_request_id_present || encode_repeated_eth_signature_request_id(state, (&(*input).eth_signature_request_id))) + && (((zcbor_uint32_put(state, (2)))) + && (zcbor_bstr_encode(state, (&(*input).eth_signature_signature)))) + && (!(*input).eth_signature_signature_origin_present || encode_repeated_eth_signature_signature_origin(state, (&(*input).eth_signature_signature_origin)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 3)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + +static bool encode_eth_sign_request( + zcbor_state_t *state, const struct eth_sign_request *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 7) && (((!(*input).eth_sign_request_request_id_present || encode_repeated_eth_sign_request_request_id(state, (&(*input).eth_sign_request_request_id))) + && (((zcbor_uint32_put(state, (2)))) + && (zcbor_bstr_encode(state, (&(*input).eth_sign_request_sign_data)))) + && (((zcbor_uint32_put(state, (3)))) + && (encode_sign_data_type(state, (&(*input).eth_sign_request_data_type)))) + && (!(*input).eth_sign_request_chain_id_present || encode_repeated_eth_sign_request_chain_id(state, (&(*input).eth_sign_request_chain_id))) + && (((zcbor_uint32_put(state, (5)))) + && zcbor_tag_put(state, 304) + && (encode_crypto_keypath(state, (&(*input).eth_sign_request_derivation_path)))) + && (!(*input).eth_sign_request_address_present || encode_repeated_eth_sign_request_address(state, (&(*input).eth_sign_request_address))) + && (!(*input).eth_sign_request_request_origin_present || encode_repeated_eth_sign_request_request_origin(state, (&(*input).eth_sign_request_request_origin)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 7)))); + + if (!tmp_result) { + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); + } + + return tmp_result; +} + + + +int cbor_encode_eth_sign_request( + uint8_t *payload, size_t payload_len, + const struct eth_sign_request *input, + size_t *payload_len_out) +{ + zcbor_state_t states[5]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_eth_sign_request, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_encode_eth_signature( + uint8_t *payload, size_t payload_len, + const struct eth_signature *input, + size_t *payload_len_out) +{ + zcbor_state_t states[3]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_eth_signature, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_encode_hd_key( + uint8_t *payload, size_t payload_len, + const struct hd_key *input, + size_t *payload_len_out) +{ + zcbor_state_t states[5]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_hd_key, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_encode_crypto_multi_accounts( + uint8_t *payload, size_t payload_len, + const struct crypto_multi_accounts *input, + size_t *payload_len_out) +{ + zcbor_state_t states[7]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_crypto_multi_accounts, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_encode_crypto_account( + uint8_t *payload, size_t payload_len, + const struct crypto_account *input, + size_t *payload_len_out) +{ + zcbor_state_t states[8]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_crypto_account, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_encode_ur_part( + uint8_t *payload, size_t payload_len, + const struct ur_part *input, + size_t *payload_len_out) +{ + zcbor_state_t states[3]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_ur_part, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_encode_dev_auth( + uint8_t *payload, size_t payload_len, + const struct dev_auth *input, + size_t *payload_len_out) +{ + zcbor_state_t states[4]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_dev_auth, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_encode_psbt( + uint8_t *payload, size_t payload_len, + const struct zcbor_string *input, + size_t *payload_len_out) +{ + zcbor_state_t states[2]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_psbt, sizeof(states) / sizeof(zcbor_state_t), 1); +} diff --git a/app/ur/eip4527_encode.h b/app/ur/ur_encode.h similarity index 58% rename from app/ur/eip4527_encode.h rename to app/ur/ur_encode.h index f8fc189..cc78d5e 100644 --- a/app/ur/eip4527_encode.h +++ b/app/ur/ur_encode.h @@ -4,14 +4,14 @@ * Generated with a --default-max-qty of 3 */ -#ifndef EIP4527_ENCODE_H__ -#define EIP4527_ENCODE_H__ +#ifndef UR_ENCODE_H__ +#define UR_ENCODE_H__ #include #include #include #include -#include "eip4527_types.h" +#include "ur_types.h" #ifdef __cplusplus extern "C" { @@ -43,6 +43,30 @@ int cbor_encode_hd_key( int cbor_encode_crypto_multi_accounts( uint8_t *payload, size_t payload_len, const struct crypto_multi_accounts *input, + size_t *payload_len_out); + + +int cbor_encode_crypto_account( + uint8_t *payload, size_t payload_len, + const struct crypto_account *input, + size_t *payload_len_out); + + +int cbor_encode_ur_part( + uint8_t *payload, size_t payload_len, + const struct ur_part *input, + size_t *payload_len_out); + + +int cbor_encode_dev_auth( + uint8_t *payload, size_t payload_len, + const struct dev_auth *input, + size_t *payload_len_out); + + +int cbor_encode_psbt( + uint8_t *payload, size_t payload_len, + const struct zcbor_string *input, size_t *payload_len_out); @@ -50,4 +74,4 @@ int cbor_encode_crypto_multi_accounts( } #endif -#endif /* EIP4527_ENCODE_H__ */ +#endif /* UR_ENCODE_H__ */ diff --git a/app/ur/ur_part_decode.c b/app/ur/ur_part_decode.c deleted file mode 100644 index b2efced..0000000 --- a/app/ur/ur_part_decode.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#include -#include -#include -#include -#include "zcbor_decode.h" -#include "ur_part_decode.h" -#include "zcbor_print.h" - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - -static bool decode_ur_part(zcbor_state_t *state, struct ur_part *result); - - -static bool decode_ur_part( - zcbor_state_t *state, struct ur_part *result) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_list_start_decode(state) && ((((zcbor_uint32_decode(state, (&(*result).ur_part_seqNum))) - && ((((((*result).ur_part_seqNum <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) - && ((zcbor_uint32_decode(state, (&(*result).ur_part_seqLen)))) - && ((zcbor_uint32_decode(state, (&(*result).ur_part_messageLen)))) - && ((zcbor_uint32_decode(state, (&(*result).ur_part_checksum))) - && ((((((*result).ur_part_checksum <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) - && ((zcbor_bstr_decode(state, (&(*result).ur_part_data))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - - -int cbor_decode_ur_part( - const uint8_t *payload, size_t payload_len, - struct ur_part *result, - size_t *payload_len_out) -{ - zcbor_state_t states[3]; - - return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, - (zcbor_decoder_t *)decode_ur_part, sizeof(states) / sizeof(zcbor_state_t), 1); -} diff --git a/app/ur/ur_part_decode.h b/app/ur/ur_part_decode.h deleted file mode 100644 index e8383de..0000000 --- a/app/ur/ur_part_decode.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#ifndef UR_PART_DECODE_H__ -#define UR_PART_DECODE_H__ - -#include -#include -#include -#include -#include "ur_part_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - -int cbor_decode_ur_part( - const uint8_t *payload, size_t payload_len, - struct ur_part *result, - size_t *payload_len_out); - - -#ifdef __cplusplus -} -#endif - -#endif /* UR_PART_DECODE_H__ */ diff --git a/app/ur/ur_part_encode.c b/app/ur/ur_part_encode.c deleted file mode 100644 index 4ddd8b8..0000000 --- a/app/ur/ur_part_encode.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#include -#include -#include -#include -#include "zcbor_encode.h" -#include "ur_part_encode.h" -#include "zcbor_print.h" - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - -static bool encode_ur_part(zcbor_state_t *state, const struct ur_part *input); - - -static bool encode_ur_part( - zcbor_state_t *state, const struct ur_part *input) -{ - zcbor_log("%s\r\n", __func__); - - bool tmp_result = (((zcbor_list_start_encode(state, 5) && (((((((((*input).ur_part_seqNum <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).ur_part_seqNum)))) - && ((zcbor_uint32_encode(state, (&(*input).ur_part_seqLen)))) - && ((zcbor_uint32_encode(state, (&(*input).ur_part_messageLen)))) - && (((((((*input).ur_part_checksum <= UINT32_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_uint32_encode(state, (&(*input).ur_part_checksum)))) - && ((zcbor_bstr_encode(state, (&(*input).ur_part_data))))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 5)))); - - if (!tmp_result) { - zcbor_trace_file(state); - zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); - } else { - zcbor_log("%s success\r\n", __func__); - } - - return tmp_result; -} - - - -int cbor_encode_ur_part( - uint8_t *payload, size_t payload_len, - const struct ur_part *input, - size_t *payload_len_out) -{ - zcbor_state_t states[3]; - - return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, - (zcbor_decoder_t *)encode_ur_part, sizeof(states) / sizeof(zcbor_state_t), 1); -} diff --git a/app/ur/ur_part_encode.h b/app/ur/ur_part_encode.h deleted file mode 100644 index 2218502..0000000 --- a/app/ur/ur_part_encode.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#ifndef UR_PART_ENCODE_H__ -#define UR_PART_ENCODE_H__ - -#include -#include -#include -#include -#include "ur_part_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if DEFAULT_MAX_QTY != 3 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - -int cbor_encode_ur_part( - uint8_t *payload, size_t payload_len, - const struct ur_part *input, - size_t *payload_len_out); - - -#ifdef __cplusplus -} -#endif - -#endif /* UR_PART_ENCODE_H__ */ diff --git a/app/ur/ur_part_types.h b/app/ur/ur_part_types.h deleted file mode 100644 index 57b7933..0000000 --- a/app/ur/ur_part_types.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor - * Generated with a --default-max-qty of 3 - */ - -#ifndef UR_PART_TYPES_H__ -#define UR_PART_TYPES_H__ - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** Which value for --default-max-qty this file was created with. - * - * The define is used in the other generated file to do a build-time - * compatibility check. - * - * See `zcbor --help` for more information about --default-max-qty - */ -#define DEFAULT_MAX_QTY 3 - -struct ur_part { - uint32_t ur_part_seqNum; - uint32_t ur_part_seqLen; - uint32_t ur_part_messageLen; - uint32_t ur_part_checksum; - struct zcbor_string ur_part_data; -}; - -#ifdef __cplusplus -} -#endif - -#endif /* UR_PART_TYPES_H__ */ diff --git a/app/ur/eip4527_types.h b/app/ur/ur_types.h similarity index 63% rename from app/ur/eip4527_types.h rename to app/ur/ur_types.h index 98a8eda..86ee759 100644 --- a/app/ur/eip4527_types.h +++ b/app/ur/ur_types.h @@ -4,8 +4,8 @@ * Generated with a --default-max-qty of 3 */ -#ifndef EIP4527_TYPES_H__ -#define EIP4527_TYPES_H__ +#ifndef UR_TYPES_H__ +#define UR_TYPES_H__ #include #include @@ -41,6 +41,62 @@ struct eth_signature { bool eth_signature_signature_origin_present; }; +struct ur_part { + uint32_t ur_part_seqNum; + uint32_t ur_part_seqLen; + uint32_t ur_part_messageLen; + uint32_t ur_part_checksum; + struct zcbor_string ur_part_data; +}; + +struct dev_auth_step_type_r { + enum { + dev_auth_step_type_dev_auth_init_m_c = 1, + dev_auth_step_type_dev_auth_device_m_c = 2, + dev_auth_step_type_dev_auth_server_m_c = 3, + } dev_auth_step_type_choice; +}; + +struct dev_auth_dev_id { + struct zcbor_string dev_auth_dev_id; +}; + +struct dev_auth_first_auth { + uint32_t dev_auth_first_auth; +}; + +struct dev_auth_auth_time { + uint32_t dev_auth_auth_time; +}; + +struct dev_auth_auth_count { + uint32_t dev_auth_auth_count; +}; + +struct dev_auth_challenge { + struct zcbor_string dev_auth_challenge; +}; + +struct dev_auth_auth_sig { + struct zcbor_string dev_auth_auth_sig; +}; + +struct dev_auth { + struct dev_auth_step_type_r dev_auth_step; + struct dev_auth_dev_id dev_auth_dev_id; + bool dev_auth_dev_id_present; + struct dev_auth_first_auth dev_auth_first_auth; + bool dev_auth_first_auth_present; + struct dev_auth_auth_time dev_auth_auth_time; + bool dev_auth_auth_time_present; + struct dev_auth_auth_count dev_auth_auth_count; + bool dev_auth_auth_count_present; + struct dev_auth_challenge dev_auth_challenge; + bool dev_auth_challenge_present; + struct dev_auth_auth_sig dev_auth_auth_sig; + bool dev_auth_auth_sig_present; +}; + struct eth_sign_request_request_id { struct zcbor_string eth_sign_request_request_id; }; @@ -142,18 +198,39 @@ struct crypto_multi_accounts_version { struct crypto_multi_accounts { uint32_t crypto_multi_accounts_master_fingerprint; - struct hd_key crypto_multi_accounts_keys_hd_key_m[10]; - size_t crypto_multi_accounts_keys_hd_key_m_count; + struct hd_key crypto_multi_accounts_keys_tagged_hd_key_m[10]; + size_t crypto_multi_accounts_keys_tagged_hd_key_m_count; struct crypto_multi_accounts_device crypto_multi_accounts_device; bool crypto_multi_accounts_device_present; struct crypto_multi_accounts_device_id crypto_multi_accounts_device_id; bool crypto_multi_accounts_device_id_present; struct crypto_multi_accounts_version crypto_multi_accounts_version; bool crypto_multi_accounts_version_present; +}; + +struct crypto_output_r { + union { + struct hd_key crypto_output_script_hash_m; + struct hd_key crypto_output_public_key_hash_m; + struct hd_key crypto_output_witness_public_key_hash_m; + struct hd_key crypto_output_taproot_m; + }; + enum { + crypto_output_script_hash_m_c, + crypto_output_public_key_hash_m_c, + crypto_output_witness_public_key_hash_m_c, + crypto_output_taproot_m_c, + } crypto_output_choice; +}; + +struct crypto_account { + uint32_t crypto_account_master_fingerprint; + struct crypto_output_r crypto_account_output_descriptors_crypto_output_m[10]; + size_t crypto_account_output_descriptors_crypto_output_m_count; }; #ifdef __cplusplus } #endif -#endif /* EIP4527_TYPES_H__ */ +#endif /* UR_TYPES_H__ */ diff --git a/cddl/auth.cddl b/cddl/auth.cddl deleted file mode 100644 index 2e3cce8..0000000 --- a/cddl/auth.cddl +++ /dev/null @@ -1,27 +0,0 @@ -dev-auth-init = 1 -dev-auth-device = 2 -dev-auth-server = 3 - -dev-auth-step-type = dev-auth-init / dev-auth-device / dev-auth-server - -dev-auth = { - dev-auth-step: dev-auth-step-type, - ? device-id: uuid, - ? first-auth: timestamp, - ? auth-time: timestamp, - ? auth-count: uint32, - ? challenge: bstr .size 32, - ? signature: bstr .size 64, -} - -dev-auth-step = 1 -device-id = 2 -first-auth = 3 -auth-time = 4 -auth-count = 5 -challenge = 6 -signature = 7 - -uuid = #6.37(bstr .size 16) -timestamp = uint .size 4 -uint32 = uint .size 4 diff --git a/cddl/btc.cddl b/cddl/btc.cddl deleted file mode 100644 index c9f074a..0000000 --- a/cddl/btc.cddl +++ /dev/null @@ -1 +0,0 @@ -psbt = bstr \ No newline at end of file diff --git a/cddl/eip4527.cddl b/cddl/eip4527.cddl deleted file mode 100644 index cabee44..0000000 --- a/cddl/eip4527.cddl +++ /dev/null @@ -1,114 +0,0 @@ -; Crypto Keypath -crypto-keypath = { - components: [0*10 path-component], - ? source-fingerprint: uint32 .gt 0, - ? depth: uint8 -} - -path-component = ( - child-index, - is-hardened -) - -uint8 = uint .size 1 -uint32 = uint .size 4 -uint31 = uint32 .lt 2147483648 -child-index = uint31 -is-hardened = bool -components = 1 -source-fingerprint = 2 -depth = 3 - -; Coin info -coininfo = { - coin-type: uint31, - network: int -} - -coin-type = 1 -network = 2 - -; Crypto HDKey -hd-key = { - ;? is-master: bool, - is-private: bool, - key-data: key-data-bytes, - chain-code: chain-code-bytes, - ? use-info: #6.305(coininfo), - origin: #6.304(crypto-keypath), - ;? children: #6.304(crypto-keypath), - parent-fingerprint: uint32 .gt 0, - name: text, - ? source: text -} - -is-master = 1 -is-private = 2 -key-data = 3 -chain-code = 4 -use-info = 5 -origin = 6 -children = 7 -parent-fingerprint = 8 -name = 9 -source = 10 - -key-data-bytes = bstr .size 33 -chain-code-bytes = bstr .size 32 - -; Crypto Multi Accounts -crypto-multi-accounts = { - master-fingerprint: uint32, - keys: [0*10 #6.303(hd-key)], - ? device: text, - ? device-id: text, - ? version: text -} - -master-fingerprint = 1 -keys = 2 -device = 3 -device-id = 4 -version = 5 - -; Sign data type -sign-data-type = eth-transaction-data / eth-typed-data / eth-raw-bytes / eth-typed-transaction - -eth-transaction-data = 1 -eth-typed-data = 2 -eth-raw-bytes = 3 -eth-typed-transaction = 4 - -; Eth Sign request -eth-sign-request = { - ? request-id: uuid, - sign-data: sign-data-bytes, - data-type: sign-data-type, - ? chain-id: int, - derivation-path: #6.304(crypto-keypath), - ? address: eth-address-bytes, - ? request-origin: text -} - -request-id = 1 -sign-data = 2 -data-type = 3 -chain-id = 4 -derivation-path = 5 -address = 6 -request-origin = 7 -eth-address-bytes = bstr .size 20 -sign-data-bytes = bstr -uuid = #6.37(bstr) - -; Eth Signature -eth-signature = { - ? request-id: uuid, - signature: eth-signature-bytes, - ? signature-origin: text, -} - -signature = 2 -signature-origin = 3 - -eth-signature-bytes = bstr diff --git a/cddl/ur.cddl b/cddl/ur.cddl index 040b0d9..ba29aca 100644 --- a/cddl/ur.cddl +++ b/cddl/ur.cddl @@ -1,3 +1,4 @@ +; UR Part ur-part = [ seqNum: uint32, seqLen: uint, @@ -6,4 +7,175 @@ ur-part = [ data: bstr ] -uint32 = uint .size 4 \ No newline at end of file +; Crypto Keypath +crypto-keypath = { + components: [0*10 path-component], + ? source-fingerprint: uint32 .gt 0, + ? depth: uint8 +} + +path-component = ( + child-index, + is-hardened +) + +uint8 = uint .size 1 +uint32 = uint .size 4 +uint31 = uint32 .lt 2147483648 +child-index = uint31 +is-hardened = bool +components = 1 +source-fingerprint = 2 +depth = 3 + +; Coin info +coininfo = { + coin-type: uint31, + network: int +} + +coin-type = 1 +network = 2 + +; Crypto HDKey +hd-key = { + ;? is-master: bool, + is-private: bool, + key-data: key-data-bytes, + chain-code: chain-code-bytes, + ? use-info: #6.305(coininfo), + origin: #6.304(crypto-keypath), + ;? children: #6.304(crypto-keypath), + parent-fingerprint: uint32 .gt 0, + name: text, + ? source: text +} + +is-master = 1 +is-private = 2 +key-data = 3 +chain-code = 4 +use-info = 5 +origin = 6 +children = 7 +parent-fingerprint = 8 +name = 9 +source = 10 + +key-data-bytes = bstr .size 33 +chain-code-bytes = bstr .size 32 + +; Crypto Multi Accounts +tagged-hd-key = #6.303(hd-key) +crypto-multi-accounts = { + master-fingerprint: uint32, + keys: [0*10 tagged-hd-key], + ? device: text, + ? device-id: text, + ? version: text +} + +master-fingerprint = 1 +keys = 2 +device = 3 +device-id = 4 +version = 5 + +; Sign data type +sign-data-type = eth-transaction-data / eth-typed-data / eth-raw-bytes / eth-typed-transaction + +eth-transaction-data = 1 +eth-typed-data = 2 +eth-raw-bytes = 3 +eth-typed-transaction = 4 + +; Eth Sign request +eth-sign-request = { + ? request-id: uuid, + sign-data: sign-data-bytes, + data-type: sign-data-type, + ? chain-id: int, + derivation-path: #6.304(crypto-keypath), + ? address: eth-address-bytes, + ? request-origin: text +} + +request-id = 1 +sign-data = 2 +data-type = 3 +chain-id = 4 +derivation-path = 5 +address = 6 +request-origin = 7 +eth-address-bytes = bstr .size 20 +sign-data-bytes = bstr +uuid = #6.37(bstr) + +; Eth Signature +eth-signature = { + ? request-id: uuid, + signature: eth-signature-bytes, + ? signature-origin: text, +} + +signature = 2 +signature-origin = 3 + +eth-signature-bytes = bstr + +; Crypto Output +key-exp = #6.303(hd-key) + +crypto-output = ( + script-hash / ; sh + public-key-hash / ; pkh + witness-public-key-hash / ; wpkh + taproot ; tr +) + +script-hash = #6.400(witness-public-key-hash) +public-key-hash = #6.403(key-exp) +witness-public-key-hash = #6.404(key-exp) +taproot = #6.409(key-exp) + +threshold = 1 + +script-bytes = bytes + +crypto-account = { + master-fingerprint: uint32, + output-descriptors: [0*10 #6.308(crypto-output)] +} + +output-descriptors = 2 + +; PSBT +psbt = bstr + +; Dev auth + +dev-auth-init = 1 +dev-auth-device = 2 +dev-auth-server = 3 + +dev-auth-step-type = dev-auth-init / dev-auth-device / dev-auth-server + +dev-auth = { + dev-auth-step: dev-auth-step-type, + ? dev-id: uuid, + ? first-auth: timestamp, + ? auth-time: timestamp, + ? auth-count: uint32, + ? challenge: bstr .size 32, + ? auth-sig: bstr .size 64, +} + +dev-auth-step = 1 +dev-id = 2 +first-auth = 3 +auth-time = 4 +auth-count = 5 +challenge = 6 +auth-sig = 7 + +timestamp = uint .size 4 diff --git a/tools/bytewords-lut.py b/tools/bytewords-lut.py index 9ab5359..97891b2 100644 --- a/tools/bytewords-lut.py +++ b/tools/bytewords-lut.py @@ -1,4 +1,4 @@ -words = ['BYTES', 'CRYPTO-HDKEY', 'CRYPTO-KEYPATH', 'CRYPTO-MULTI-ACCOUNTS', 'CRYPTO-OUTPUT', 'CRYPTO-PSBT', 'DEV-AUTH', 'ETH-SIGN-REQUEST', 'ETH-SIGNATURE', 'FS-DATA', 'FW-UPDATE'] +words = ['BYTES', 'CRYPTO-ACCOUNT', 'CRYPTO-HDKEY', 'CRYPTO-MULTI-ACCOUNTS', 'CRYPTO-OUTPUT', 'CRYPTO-PSBT', 'DEV-AUTH', 'ETH-SIGN-REQUEST', 'ETH-SIGNATURE', 'FS-DATA', 'FW-UPDATE'] def hf(w, m): sum = 0 @@ -22,5 +22,20 @@ while repeat: else: lut[h] = w -print(lut) -print(mult) + +print("const char *const ur_type_string[] = {") +for i in range(16): + if i in lut: + print(f" \"{lut[i]}\",") + else: + print(" NULL,") +print("};\n") + +print("typedef enum {") +for i in range(16): + if i in lut: + print(f" {lut[i].replace("-", "_")} = {i},") +print(f" UR_ANY_TX = 255") +print("} ur_type_t;\n") + +print(f"Multiplier: {mult}") diff --git a/tools/zcbor-gen.sh b/tools/zcbor-gen.sh index 5a15a75..9fd059d 100644 --- a/tools/zcbor-gen.sh +++ b/tools/zcbor-gen.sh @@ -1,4 +1 @@ -zcbor code -c cddl/eip4527.cddl -d -e -t eth-sign-request eth-signature hd-key crypto-multi-accounts --output-c app/ur/eip4527.c --output-h app/ur/eip4527.h -zcbor code -c cddl/ur.cddl -d -e -t ur-part --output-c app/ur/ur_part.c --output-h app/ur/ur_part.h -zcbor code -c cddl/auth.cddl -d -e -t dev-auth --output-c app/ur/auth.c --output-h app/ur/auth.h -zcbor code -c cddl/btc.cddl -d -e -t psbt --output-c app/ur/btc.c --output-h app/ur/btc.h \ No newline at end of file +zcbor code -c cddl/ur.cddl -d -e -t eth-sign-request eth-signature hd-key crypto-multi-accounts crypto-account ur-part dev-auth psbt --output-c app/ur/ur.c --output-h app/ur/ur.h \ No newline at end of file