Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
address_book_common.c
Go to the documentation of this file.
1/*****************************************************************************
2 * (c) 2026 Ledger SAS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
29#include <string.h>
30#include "address_book_common.h"
31#include "os_utils.h"
32#include "os_print.h"
33#include "buffer.h"
34#include "tlv_library.h"
35#include "bip32.h"
36#include "address_book.h"
37#include "io.h"
38#include "status_words.h"
39#include "nbgl_use_case.h"
40
41#ifdef HAVE_ADDRESS_BOOK
42
43ab_payload_u g_ab_payload = {0};
44ab_ui_t g_ab_ui = {0};
45
53bool address_book_handle_derivation_path(const tlv_data_t *data, path_bip32_t *bip32_path)
54{
55 buffer_t path_buffer = {0};
56
57 if (!get_buffer_from_tlv_data(data, &path_buffer, 1, MAX_BIP32_PATH * 4 + 1)) {
58 PRINTF("DERIVATION_PATH: failed to extract\n");
59 return false;
60 }
61
62 // Parse BIP32 path using the standard parser
63 if (buffer_get_path_bip32(&path_buffer, bip32_path) == false) {
64 PRINTF("DERIVATION_PATH: failed to parse BIP32 path\n");
65 return false;
66 }
67
68 return true;
69}
70
78bool address_book_handle_chain_id(const tlv_data_t *data, uint64_t *chain_id)
79{
80 if (!get_uint64_t_from_tlv_data(data, chain_id)) {
81 PRINTF("CHAIN_ID: failed to extract\n");
82 return false;
83 }
84 return true;
85}
86
94bool address_book_handle_blockchain_family(const tlv_data_t *data, blockchain_family_e *family)
95{
96 uint8_t value = 0;
97 if (!get_uint8_t_from_tlv_data(data, &value)) {
98 PRINTF("UINT8: failed to extract\n");
99 return false;
100 }
101 if (value >= FAMILY_COUNT) {
102 PRINTF("BLOCKCHAIN_FAMILY: Value out of range (%d, max %d)!\n", value, FAMILY_COUNT - 1);
103 return false;
104 }
105 *family = (blockchain_family_e) value;
106 return true;
107}
108
119bool address_book_handle_printable_string(const tlv_data_t *data,
120 char *output_buffer,
121 size_t buffer_size)
122{
123 // Extract the string (with null terminator added by get_string_from_tlv_data)
124 if (!get_string_from_tlv_data(data, output_buffer, 1, buffer_size)) {
125 PRINTF("String extraction failed\n");
126 return false;
127 }
128 if (!is_printable_string(output_buffer, strlen(output_buffer))) {
129 PRINTF("String contains non-printable characters\n");
130 return false;
131 }
132 return true;
133}
134
147void address_book_display_review(const nbgl_icon_details_t *icon,
148 const char *reviewTitle,
149 const char *confirmText,
150 nbgl_choiceCallback_t choiceCallback)
151{
152 g_ab_ui.list.wrapping = true;
153 // NB: no subtitle for address book reviews, as the content is already quite long
154 // Indicate the flag ADDRESS_BOOK_OPERATION to force wording in review screens
156 &g_ab_ui.list,
157 icon,
158 reviewTitle,
159 NULL,
160 confirmText,
161 choiceCallback);
162}
163
172void address_book_handle_review_rejected(nbgl_callback_t finalize)
173{
174 io_send_sw(SWO_INCORRECT_DATA);
175 nbgl_useCaseStatus("Canceled", false, finalize);
176}
177
191void address_book_finalize_review(bool success,
192 const char *successMsg,
193 const char *errorMsg,
194 nbgl_callback_t finalize)
195{
196 if (success) {
197 nbgl_useCaseStatus(successMsg, true, finalize);
198 }
199 else {
200 io_send_sw(SWO_INCORRECT_DATA);
201 nbgl_useCaseStatus(errorMsg, false, finalize);
202 }
203}
204
205#endif // HAVE_ADDRESS_BOOK
blockchain_family_e
@ FAMILY_COUNT
#define MAX_BIP32_PATH
Definition bip32.h:15
bool buffer_get_path_bip32(buffer_t *buffer, path_bip32_t *bip32)
Definition buffer.c:155
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
API of the Advanced BOLOS Graphical Library, for typical application use-cases.
void(* nbgl_callback_t)(void)
prototype of generic callback function
void(* nbgl_choiceCallback_t)(bool confirm)
prototype of choice callback function
void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
void nbgl_useCaseReviewLight(nbgl_operationType_t operationType, const nbgl_contentTagValueList_t *tagValueList, const nbgl_icon_details_t *icon, const char *reviewTitle, const char *reviewSubTitle, const char *finishTitle, nbgl_choiceCallback_t choiceCallback)
#define ADDRESS_BOOK_OPERATION
This is to use in nbgl_operationType_t when the operation is related to "Address Book" to adapt wordi...
@ TYPE_OPERATION
For other types of operation (generic type)