From d4f92080701ac9771e5b7a63a27b529eb9d0b1c8 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 15 Jul 2024 11:41:39 +0200 Subject: [PATCH] add btc msg sign structures --- app/core/core.c | 4 ++ app/core/core.h | 1 + app/core/core_btc.c | 6 +++ app/qrcode/qrscan.c | 5 +- app/ur/ur.c | 27 +++++----- app/ur/ur.h | 24 +++++---- app/ur/ur_decode.c | 113 +++++++++++++++++++++++++++++++++++++++++ app/ur/ur_decode.h | 12 +++++ app/ur/ur_encode.c | 112 ++++++++++++++++++++++++++++++++++++++++ app/ur/ur_encode.h | 12 +++++ app/ur/ur_types.h | 26 ++++++++++ cddl/ur.cddl | 28 ++++++++++ tools/bytewords-lut.py | 2 +- tools/zcbor-gen.sh | 2 +- 14 files changed, 347 insertions(+), 27 deletions(-) diff --git a/app/core/core.c b/app/core/core.c index 95c4eee..3021e0d 100644 --- a/app/core/core.c +++ b/app/core/core.c @@ -46,6 +46,7 @@ core_ctx_t g_core; union qr_tx_data { struct eth_sign_request eth_sign_request; struct zcbor_string crypto_psbt; + struct btc_sign_request btc_sign_request; }; app_err_t core_export_key(keycard_t* kc, uint8_t* path, uint16_t len, uint8_t* out_pub, uint8_t* out_chain) { @@ -244,6 +245,9 @@ void core_qr_run() { case CRYPTO_PSBT: core_btc_psbt_qr_run(&qr_request.crypto_psbt); break; + case BTC_SIGN_REQUEST: + core_btc_sign_msg_qr_run(&qr_request.btc_sign_request); + break; default: break; } diff --git a/app/core/core.h b/app/core/core.h index 22b7144..5623d6b 100644 --- a/app/core/core.h +++ b/app/core/core.h @@ -84,6 +84,7 @@ app_err_t core_eth_usb_sign_eip712(keycard_t* kc, apdu_t* cmd); void core_eth_eip4527_run(struct eth_sign_request* qr_request); void core_btc_psbt_qr_run(struct zcbor_string* qr_request); +void core_btc_sign_msg_qr_run(struct btc_sign_request* qr_request); void core_qr_run(); void core_display_public_eip4527(); diff --git a/app/core/core_btc.c b/app/core/core_btc.c index d7d20fc..894e377 100644 --- a/app/core/core_btc.c +++ b/app/core/core_btc.c @@ -12,6 +12,7 @@ #define BTC_TXID_LEN 32 #define BTC_PUBKEY_HASH_LEN 20 #define BTC_WITNESS_LEN 32 +#define BTC_MSG_SIG_LEN 65 #define SIGHASH_MASK 0x1f #define SIGHASH_ANYONECANPAY 0x80 @@ -19,6 +20,8 @@ static const uint8_t P2PKH_SCRIPT_PRE[4] = { 0x19, 0x76, 0xa9, 0x14 }; static const uint8_t P2PKH_SCRIPT_POST[2] = { 0x88, 0xac }; +const uint8_t *const BTC_MSG_MAGIC = (uint8_t *) "\030Bitcoin Signed Message:\n"; + enum btc_input_type { BTC_INPUT_TYPE_LEGACY, BTC_INPUT_TYPE_LEGACY_WITH_REDEEM, @@ -618,3 +621,6 @@ void core_btc_psbt_qr_run(struct zcbor_string* qr_request) { cbor_encode_psbt(g_mem_heap, MEM_HEAP_SIZE, &qr_out, &out_len); ui_display_ur_qr(LSTR(QR_SIGNATURE_TITLE), g_mem_heap, out_len, CRYPTO_PSBT); } + +void core_btc_sign_msg_qr_run(struct btc_sign_request* qr_request) { +} diff --git a/app/qrcode/qrscan.c b/app/qrcode/qrscan.c index 33ec2d9..742433c 100644 --- a/app/qrcode/qrscan.c +++ b/app/qrcode/qrscan.c @@ -37,7 +37,7 @@ app_err_t qrscan_decode(struct quirc *qrctx, ur_t* ur) { app_err_t qrscan_deserialize(ur_t* ur) { if (g_ui_cmd.params.qrscan.type == UR_ANY_TX) { - if (ur->type == ETH_SIGN_REQUEST || ur->type == CRYPTO_PSBT) { + if (ur->type == ETH_SIGN_REQUEST || ur->type == CRYPTO_PSBT || ur->type == BTC_SIGN_REQUEST) { g_ui_cmd.params.qrscan.type = ur->type; } else { return ERR_DATA; @@ -60,6 +60,9 @@ app_err_t qrscan_deserialize(ur_t* ur) { case CRYPTO_PSBT: err = cbor_decode_psbt(ur->data, ur->data_len, g_ui_cmd.params.qrscan.out, NULL) == ZCBOR_SUCCESS ? ERR_OK : ERR_DATA; break; + case BTC_SIGN_REQUEST: + err = cbor_decode_btc_sign_request(ur->data, ur->data_len, g_ui_cmd.params.qrscan.out, NULL) == ZCBOR_SUCCESS ? ERR_OK : ERR_DATA; + break; case FS_DATA: data = g_ui_cmd.params.qrscan.out; data->data = ur->data; diff --git a/app/ur/ur.c b/app/ur/ur.c index e2b24f3..55610fb 100644 --- a/app/ur/ur.c +++ b/app/ur/ur.c @@ -7,25 +7,26 @@ #define MIN_ENCODED_LEN 22 #define MAX_CBOR_HEADER_LEN 32 -#define UR_TYPE(t) (ur_type_t)(((t * 4597373) >> 28) & 0xf) +#define UR_LOOKUP_MULT 88116301 +#define UR_TYPE(t) (ur_type_t)(((t * UR_LOOKUP_MULT) >> 28) & 0xf) const char *const ur_type_string[] = { - "ETH-SIGNATURE", - "CRYPTO-OUTPUT", - "CRYPTO-ACCOUNT", - NULL, + "BYTES", "ETH-SIGN-REQUEST", NULL, - "BYTES", - NULL, - "FS-DATA", - "DEV-AUTH", - "CRYPTO-MULTI-ACCOUNTS", - "FW-UPDATE", - NULL, - NULL, "CRYPTO-PSBT", + "CRYPTO-MULTI-ACCOUNTS", + NULL, + "FW-UPDATE", "CRYPTO-HDKEY", + "BTC-SIGNATURE", + "CRYPTO-ACCOUNT", + NULL, + "ETH-SIGNATURE", + "DEV-AUTH", + "FS-DATA", + "BTC-SIGN-REQUEST", + "CRYPTO-OUTPUT", }; 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 36e9ac9..b1ca3c0 100644 --- a/app/ur/ur.h +++ b/app/ur/ur.h @@ -8,17 +8,19 @@ #define UR_PART_DESC_COUNT (UR_MAX_PART_COUNT + 16) typedef enum { - ETH_SIGNATURE = 0, - CRYPTO_OUTPUT = 1, - CRYPTO_ACCOUNT = 2, - ETH_SIGN_REQUEST = 4, - BYTES = 6, - FS_DATA = 8, - DEV_AUTH = 9, - CRYPTO_MULTI_ACCOUNTS = 10, - FW_UPDATE = 11, - CRYPTO_PSBT = 14, - CRYPTO_HDKEY = 15, + BYTES = 0, + ETH_SIGN_REQUEST = 1, + CRYPTO_PSBT = 3, + CRYPTO_MULTI_ACCOUNTS = 4, + FW_UPDATE = 6, + CRYPTO_HDKEY = 7, + BTC_SIGNATURE = 8, + CRYPTO_ACCOUNT = 9, + ETH_SIGNATURE = 11, + DEV_AUTH = 12, + FS_DATA = 13, + BTC_SIGN_REQUEST = 14, + CRYPTO_OUTPUT = 15, UR_ANY_TX = 255 } ur_type_t; diff --git a/app/ur/ur_decode.c b/app/ur/ur_decode.c index d648e7a..dbf0470 100644 --- a/app/ur/ur_decode.c +++ b/app/ur/ur_decode.c @@ -38,6 +38,8 @@ 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_repeated_btc_sign_request_btc_addresses(zcbor_state_t *state, struct btc_sign_request_btc_addresses_r *result); +static bool decode_repeated_btc_sign_request_btc_origin(zcbor_state_t *state, struct btc_sign_request_btc_origin *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); @@ -48,6 +50,8 @@ 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_btc_signature(zcbor_state_t *state, struct btc_signature *result); +static bool decode_btc_sign_request(zcbor_state_t *state, struct btc_sign_request *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); @@ -475,6 +479,42 @@ static bool decode_repeated_hd_key_source( return tmp_result; } +static bool decode_repeated_btc_sign_request_btc_addresses( + zcbor_state_t *state, struct btc_sign_request_btc_addresses_r *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_expect(state, (5)))) + && (zcbor_list_start_decode(state) && ((((*result).btc_sign_request_btc_addresses_btc_address_m_present = ((zcbor_tstr_decode(state, (&(*result).btc_sign_request_btc_addresses_btc_address_m)))), 1)) || (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_repeated_btc_sign_request_btc_origin( + zcbor_state_t *state, struct btc_sign_request_btc_origin *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_expect(state, (6)))) + && (zcbor_tstr_decode(state, (&(*result).btc_sign_request_btc_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 decode_tagged_hd_key( zcbor_state_t *state, struct hd_key *result) { @@ -658,6 +698,55 @@ static bool decode_crypto_output( return tmp_result; } +static bool decode_btc_signature( + zcbor_state_t *state, struct btc_signature *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_decode(state) && (((((zcbor_uint32_expect(state, (1)))) + && (decode_uuid(state, (&(*result).btc_signature_request_id)))) + && (((zcbor_uint32_expect(state, (2)))) + && (zcbor_bstr_decode(state, (&(*result).btc_signature_signature)))) + && (((zcbor_uint32_expect(state, (3)))) + && (zcbor_bstr_decode(state, (&(*result).btc_signature_public_key))))) || (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_btc_sign_request( + zcbor_state_t *state, struct btc_sign_request *result) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_decode(state) && (((((zcbor_uint32_expect(state, (1)))) + && (decode_uuid(state, (&(*result).btc_sign_request_request_id)))) + && (((zcbor_uint32_expect(state, (2)))) + && (zcbor_bstr_decode(state, (&(*result).btc_sign_request_sign_data)))) + && (((zcbor_uint32_expect(state, (3)))) + && (zcbor_uint32_expect(state, (1)))) + && (((zcbor_uint32_expect(state, (4)))) + && (zcbor_list_start_decode(state) && ((((*result).btc_sign_request_btc_derivation_paths_crypto_keypath_m_present = (zcbor_tag_expect(state, 304) + && (decode_crypto_keypath(state, (&(*result).btc_sign_request_btc_derivation_paths_crypto_keypath_m)))), 1)) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))) + && zcbor_present_decode(&((*result).btc_sign_request_btc_addresses_present), (zcbor_decoder_t *)decode_repeated_btc_sign_request_btc_addresses, state, (&(*result).btc_sign_request_btc_addresses)) + && zcbor_present_decode(&((*result).btc_sign_request_btc_origin_present), (zcbor_decoder_t *)decode_repeated_btc_sign_request_btc_origin, state, (&(*result).btc_sign_request_btc_origin))) || (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_psbt( zcbor_state_t *state, struct zcbor_string *result) { @@ -945,4 +1034,28 @@ int cbor_decode_psbt( 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); +} + + +int cbor_decode_btc_sign_request( + const uint8_t *payload, size_t payload_len, + struct btc_sign_request *result, + size_t *payload_len_out) +{ + zcbor_state_t states[6]; + + return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, + (zcbor_decoder_t *)decode_btc_sign_request, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_decode_btc_signature( + const uint8_t *payload, size_t payload_len, + struct btc_signature *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_btc_signature, sizeof(states) / sizeof(zcbor_state_t), 1); } diff --git a/app/ur/ur_decode.h b/app/ur/ur_decode.h index 760ce6d..ae25f99 100644 --- a/app/ur/ur_decode.h +++ b/app/ur/ur_decode.h @@ -67,6 +67,18 @@ int cbor_decode_dev_auth( int cbor_decode_psbt( const uint8_t *payload, size_t payload_len, struct zcbor_string *result, + size_t *payload_len_out); + + +int cbor_decode_btc_sign_request( + const uint8_t *payload, size_t payload_len, + struct btc_sign_request *result, + size_t *payload_len_out); + + +int cbor_decode_btc_signature( + const uint8_t *payload, size_t payload_len, + struct btc_signature *result, size_t *payload_len_out); diff --git a/app/ur/ur_encode.c b/app/ur/ur_encode.c index 9c9cc2f..0967afb 100644 --- a/app/ur/ur_encode.c +++ b/app/ur/ur_encode.c @@ -38,6 +38,8 @@ static bool encode_repeated_eth_sign_request_request_origin(zcbor_state_t *state 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_btc_sign_request_btc_addresses(zcbor_state_t *state, const struct btc_sign_request_btc_addresses_r *input); +static bool encode_repeated_btc_sign_request_btc_origin(zcbor_state_t *state, const struct btc_sign_request_btc_origin *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); @@ -48,6 +50,8 @@ 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_btc_signature(zcbor_state_t *state, const struct btc_signature *input); +static bool encode_btc_sign_request(zcbor_state_t *state, const struct btc_sign_request *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); @@ -477,6 +481,42 @@ static bool encode_repeated_hd_key_source( return tmp_result; } +static bool encode_repeated_btc_sign_request_btc_addresses( + zcbor_state_t *state, const struct btc_sign_request_btc_addresses_r *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (5)))) + && (zcbor_list_start_encode(state, 1) && (((!(*input).btc_sign_request_btc_addresses_btc_address_m_present || zcbor_tstr_encode(state, (&(*input).btc_sign_request_btc_addresses_btc_address_m)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 1)))); + + 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_btc_sign_request_btc_origin( + zcbor_state_t *state, const struct btc_sign_request_btc_origin *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = ((((zcbor_uint32_put(state, (6)))) + && (zcbor_tstr_encode(state, (&(*input).btc_sign_request_btc_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_tagged_hd_key( zcbor_state_t *state, const struct hd_key *input) { @@ -660,6 +700,54 @@ static bool encode_crypto_output( return tmp_result; } +static bool encode_btc_signature( + zcbor_state_t *state, const struct btc_signature *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 3) && (((((zcbor_uint32_put(state, (1)))) + && (encode_uuid(state, (&(*input).btc_signature_request_id)))) + && (((zcbor_uint32_put(state, (2)))) + && (zcbor_bstr_encode(state, (&(*input).btc_signature_signature)))) + && (((zcbor_uint32_put(state, (3)))) + && (zcbor_bstr_encode(state, (&(*input).btc_signature_public_key))))) || (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_btc_sign_request( + zcbor_state_t *state, const struct btc_sign_request *input) +{ + zcbor_log("%s\r\n", __func__); + + bool tmp_result = (((zcbor_map_start_encode(state, 6) && (((((zcbor_uint32_put(state, (1)))) + && (encode_uuid(state, (&(*input).btc_sign_request_request_id)))) + && (((zcbor_uint32_put(state, (2)))) + && (zcbor_bstr_encode(state, (&(*input).btc_sign_request_sign_data)))) + && (((zcbor_uint32_put(state, (3)))) + && (zcbor_uint32_put(state, (1)))) + && (((zcbor_uint32_put(state, (4)))) + && (zcbor_list_start_encode(state, 1) && (((!(*input).btc_sign_request_btc_derivation_paths_crypto_keypath_m_present || encode_crypto_keypath(state, (&(*input).btc_sign_request_btc_derivation_paths_crypto_keypath_m)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 1))) + && (!(*input).btc_sign_request_btc_addresses_present || encode_repeated_btc_sign_request_btc_addresses(state, (&(*input).btc_sign_request_btc_addresses))) + && (!(*input).btc_sign_request_btc_origin_present || encode_repeated_btc_sign_request_btc_origin(state, (&(*input).btc_sign_request_btc_origin)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 6)))); + + 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) { @@ -947,4 +1035,28 @@ int cbor_encode_psbt( 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); +} + + +int cbor_encode_btc_sign_request( + uint8_t *payload, size_t payload_len, + const struct btc_sign_request *input, + size_t *payload_len_out) +{ + zcbor_state_t states[6]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_btc_sign_request, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + +int cbor_encode_btc_signature( + uint8_t *payload, size_t payload_len, + const struct btc_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_btc_signature, sizeof(states) / sizeof(zcbor_state_t), 1); } diff --git a/app/ur/ur_encode.h b/app/ur/ur_encode.h index cc78d5e..821b366 100644 --- a/app/ur/ur_encode.h +++ b/app/ur/ur_encode.h @@ -67,6 +67,18 @@ int cbor_encode_dev_auth( int cbor_encode_psbt( uint8_t *payload, size_t payload_len, const struct zcbor_string *input, + size_t *payload_len_out); + + +int cbor_encode_btc_sign_request( + uint8_t *payload, size_t payload_len, + const struct btc_sign_request *input, + size_t *payload_len_out); + + +int cbor_encode_btc_signature( + uint8_t *payload, size_t payload_len, + const struct btc_signature *input, size_t *payload_len_out); diff --git a/app/ur/ur_types.h b/app/ur/ur_types.h index 86ee759..d88c8c2 100644 --- a/app/ur/ur_types.h +++ b/app/ur/ur_types.h @@ -49,6 +49,12 @@ struct ur_part { struct zcbor_string ur_part_data; }; +struct btc_signature { + struct zcbor_string btc_signature_request_id; + struct zcbor_string btc_signature_signature; + struct zcbor_string btc_signature_public_key; +}; + struct dev_auth_step_type_r { enum { dev_auth_step_type_dev_auth_init_m_c = 1, @@ -184,6 +190,26 @@ struct hd_key { bool hd_key_source_present; }; +struct btc_sign_request_btc_addresses_r { + struct zcbor_string btc_sign_request_btc_addresses_btc_address_m; + bool btc_sign_request_btc_addresses_btc_address_m_present; +}; + +struct btc_sign_request_btc_origin { + struct zcbor_string btc_sign_request_btc_origin; +}; + +struct btc_sign_request { + struct zcbor_string btc_sign_request_request_id; + struct zcbor_string btc_sign_request_sign_data; + struct crypto_keypath btc_sign_request_btc_derivation_paths_crypto_keypath_m; + bool btc_sign_request_btc_derivation_paths_crypto_keypath_m_present; + struct btc_sign_request_btc_addresses_r btc_sign_request_btc_addresses; + bool btc_sign_request_btc_addresses_present; + struct btc_sign_request_btc_origin btc_sign_request_btc_origin; + bool btc_sign_request_btc_origin_present; +}; + struct crypto_multi_accounts_device { struct zcbor_string crypto_multi_accounts_device; }; diff --git a/cddl/ur.cddl b/cddl/ur.cddl index ba29aca..37fd78e 100644 --- a/cddl/ur.cddl +++ b/cddl/ur.cddl @@ -152,6 +152,34 @@ output-descriptors = 2 ; PSBT psbt = bstr +; BTC Message Sign +btc-message = 1 +btc-data-type = btc-message + +btc-address = text + +btc-sign-request = { + request-id: uuid, + sign-data: sign-data-bytes, + data-type: btc-data-type, + btc-derivation-paths: [0*1 #6.304(crypto-keypath)], + ? btc-addresses: [0*1 btc-address], + ? btc-origin: text +} + +btc-message-data-type = 3 +btc-derivation-paths = 4 +btc-addresses = 5 +btc-origin = 6 + +btc-signature = { + request-id: uuid, + signature: bstr, + public-key: bstr +} + +public-key = 3 + ; Dev auth dev-auth-init = 1 diff --git a/tools/bytewords-lut.py b/tools/bytewords-lut.py index 97891b2..f3cbcd5 100644 --- a/tools/bytewords-lut.py +++ b/tools/bytewords-lut.py @@ -1,4 +1,4 @@ -words = ['BYTES', 'CRYPTO-ACCOUNT', 'CRYPTO-HDKEY', 'CRYPTO-MULTI-ACCOUNTS', 'CRYPTO-OUTPUT', 'CRYPTO-PSBT', 'DEV-AUTH', 'ETH-SIGN-REQUEST', 'ETH-SIGNATURE', 'FS-DATA', 'FW-UPDATE'] +words = ['BTC-SIGN-REQUEST', 'BTC-SIGNATURE', '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 diff --git a/tools/zcbor-gen.sh b/tools/zcbor-gen.sh index 9fd059d..3b8c3b6 100644 --- a/tools/zcbor-gen.sh +++ b/tools/zcbor-gen.sh @@ -1 +1 @@ -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 +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 btc-sign-request btc-signature --output-c app/ur/ur.c --output-h app/ur/ur.h \ No newline at end of file