Skip to content

Commit 0769cff

Browse files
committed
feat: address stellar review feedback
1 parent 2af5061 commit 0769cff

File tree

7 files changed

+48
-33
lines changed

7 files changed

+48
-33
lines changed

apps/stellar_app/stellar_context.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ typedef struct {
5050
} stellar_config_t;
5151

5252
// Stellar Memo types
53-
// See https://developers.stellar.org/docs/learn/encyclopedia/transactions-specialized/memos
53+
// See
54+
// https://developers.stellar.org/docs/learn/encyclopedia/transactions-specialized/memos
5455
typedef enum {
5556
STELLAR_MEMO_NONE = 0,
5657
STELLAR_MEMO_TEXT = 1,
@@ -59,8 +60,9 @@ typedef enum {
5960
STELLAR_MEMO_RETURN = 4
6061
} stellar_memo_type_t;
6162

62-
// Stellar operation types
63-
// See https://developers.stellar.org/docs/learn/fundamentals/transactions/list-of-operations
63+
// Stellar operation types
64+
// See
65+
// https://developers.stellar.org/docs/learn/fundamentals/transactions/list-of-operations
6466
typedef enum {
6567
STELLAR_OPERATION_CREATE_ACCOUNT = 0,
6668
STELLAR_OPERATION_PAYMENT = 1

apps/stellar_app/stellar_helpers.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,22 @@ bool stellar_generate_address(const uint8_t *public_key, char *address) {
140140
}
141141

142142
// Stellar address encoding (StrKey format)
143-
// See https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md
143+
// See
144+
// https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md
144145
uint8_t payload[35];
145-
payload[0] = 0x30; // Account ID version byte (6 << 3 | 0 = STRKEY_PUBKEY OR STRKEY_ALG_ED25519)
146+
payload[0] = 0x30; // Account ID version byte (6 << 3 | 0 = STRKEY_PUBKEY
147+
// OR STRKEY_ALG_ED25519)
146148
memcpy(payload + 1, public_key, STELLAR_PUBKEY_RAW_SIZE);
147149

148150
// CRC16-XModem checksum calculation
149-
// See https://stellar.stackexchange.com/questions/255/which-cryptographic-algorithm-is-used-to-generate-the-secret-and-public-keys
151+
// See
152+
// https://stellar.stackexchange.com/questions/255/which-cryptographic-algorithm-is-used-to-generate-the-secret-and-public-keys
150153
uint16_t checksum = crc16(payload, 33);
151154
payload[33] = checksum & 0xFF;
152155
payload[34] = checksum >> 8;
153156

154157
// RFC4648 base32 encoding without padding
155-
base32_encode(payload, 35, address, STELLAR_ADDRESS_LENGTH, BASE32_ALPHABET_RFC4648);
158+
base32_encode(
159+
payload, 35, address, STELLAR_ADDRESS_LENGTH, BASE32_ALPHABET_RFC4648);
156160
return true;
157161
}

apps/stellar_app/stellar_helpers.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ bool stellar_derivation_path_guard(const uint32_t *path, uint8_t levels);
6464
* @brief Generates a Stellar address from a public key
6565
* @details Follows the Stellar address generation algorithm:
6666
* 1. Creates a payload with account ID type (0x30) and the public key
67-
* 2. Calculates CRC16 checksum
67+
* 2. Calculates CRC16 checksum
6868
* 3. Encodes the result using base32
69-
* See https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md
69+
* See
70+
* https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md
7071
*
7172
* @param public_key The 32-byte ED25519 public key
7273
* @param address Buffer to store the resulting address (must be at least

apps/stellar_app/stellar_txn.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ static bool get_user_verification(void) {
459459
snprintf(operation_display,
460460
sizeof(operation_display),
461461
ui_text_stellar_operation,
462-
decoded_txn->operation_type == STELLAR_OPERATION_CREATE_ACCOUNT ? "CREATE_ACCOUNT" : "PAYMENT");
462+
decoded_txn->operation_type == STELLAR_OPERATION_CREATE_ACCOUNT
463+
? "CREATE_ACCOUNT"
464+
: "PAYMENT");
463465
if (!core_confirmation(operation_display, stellar_send_error)) {
464466
return false;
465467
}
@@ -578,7 +580,8 @@ static int create_signature_base(const char *network_passphrase,
578580
} else if (tx->memo_type == STELLAR_MEMO_ID) {
579581
write_uint64_be(signature_base + offset, tx->memo.id);
580582
offset += 8;
581-
} else if (tx->memo_type == STELLAR_MEMO_HASH || tx->memo_type == STELLAR_MEMO_RETURN) {
583+
} else if (tx->memo_type == STELLAR_MEMO_HASH ||
584+
tx->memo_type == STELLAR_MEMO_RETURN) {
582585
memcpy(signature_base + offset, tx->memo.hash, 32);
583586
offset += 32;
584587
}
@@ -599,15 +602,16 @@ static int create_signature_base(const char *network_passphrase,
599602
// Destination (type + pubkey)
600603
write_uint32_be(signature_base + offset, STELLAR_KEY_TYPE_ED25519);
601604
offset += 4;
602-
memcpy(signature_base + offset, payment->destination, STELLAR_PUBKEY_RAW_SIZE);
605+
memcpy(
606+
signature_base + offset, payment->destination, STELLAR_PUBKEY_RAW_SIZE);
603607
offset += STELLAR_PUBKEY_RAW_SIZE;
604-
608+
605609
// Asset (native) - only for PAYMENT operations
606610
if (tx->operation_type == STELLAR_OPERATION_PAYMENT) {
607611
write_uint32_be(signature_base + offset, STELLAR_ASSET_TYPE_NATIVE);
608612
offset += 4;
609613
}
610-
614+
611615
// Amount
612616
write_uint64_be(signature_base + offset, payment->amount);
613617
offset += 8;
@@ -665,13 +669,15 @@ static bool sign_txn(der_sig_t *der_signature) {
665669

666670
set_app_flow_status(STELLAR_SIGN_TXN_STATUS_SEED_GENERATED);
667671

668-
// Create HDNode from seed and derive private key using derive_hdnode_from_path
672+
// Create HDNode from seed and derive private key using
673+
// derive_hdnode_from_path
669674
HDNode node = {0};
670-
if (!derive_hdnode_from_path(stellar_txn_context->init_info.derivation_path,
671-
stellar_txn_context->init_info.derivation_path_count,
672-
ED25519_NAME,
673-
seed,
674-
&node)) {
675+
if (!derive_hdnode_from_path(
676+
stellar_txn_context->init_info.derivation_path,
677+
stellar_txn_context->init_info.derivation_path_count,
678+
ED25519_NAME,
679+
seed,
680+
&node)) {
675681
stellar_send_error(ERROR_COMMON_ERROR_UNKNOWN_ERROR_TAG, 1);
676682
memzero(seed, sizeof(seed));
677683
memzero(&node, sizeof(HDNode));

apps/stellar_app/stellar_txn_helpers.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,18 @@ static uint64_t read_uint64_be_offset(const uint8_t *data, int *offset) {
109109
return (high << 32) | low;
110110
}
111111

112-
static void read_account_offset(const uint8_t *data, int *offset, uint8_t *account) {
112+
static void read_account_offset(const uint8_t *data,
113+
int *offset,
114+
uint8_t *account) {
113115
memcpy(account, data + *offset, STELLAR_PUBKEY_RAW_SIZE);
114116
*offset += STELLAR_PUBKEY_RAW_SIZE;
115117
}
116118

117119
static int read_string_offset(const uint8_t *data,
118-
int *offset,
119-
char *str,
120-
int max_len,
121-
int data_len) {
120+
int *offset,
121+
char *str,
122+
int max_len,
123+
int data_len) {
122124
if (*offset + 4 > data_len)
123125
return -1;
124126

@@ -154,8 +156,8 @@ static int parse_memo_data(const uint8_t *xdr,
154156

155157
case STELLAR_MEMO_TEXT: {
156158
char temp_memo[64];
157-
int memo_len =
158-
read_string_offset(xdr, offset, temp_memo, sizeof(temp_memo), xdr_len);
159+
int memo_len = read_string_offset(
160+
xdr, offset, temp_memo, sizeof(temp_memo), xdr_len);
159161
if (memo_len < 0) {
160162
return -1;
161163
}
@@ -199,15 +201,15 @@ static int parse_operation_data(const uint8_t *xdr,
199201
uint32_t has_source_account = read_uint32_be_offset(xdr, offset);
200202

201203
if (has_source_account == 1) {
202-
*offset += 36; // Skip source account (4 bytes type + 32 bytes key)
204+
*offset += 36; // Skip source account (4 bytes type + 32 bytes key)
203205
} else if (has_source_account != 0) {
204206
return -1;
205207
}
206208

207209
// Parse operation type
208210
uint32_t operation_type = read_uint32_be_offset(xdr, offset);
209211

210-
if (operation_type != STELLAR_OPERATION_PAYMENT &&
212+
if (operation_type != STELLAR_OPERATION_PAYMENT &&
211213
operation_type != STELLAR_OPERATION_CREATE_ACCOUNT) {
212214
return -1;
213215
}
@@ -230,7 +232,7 @@ static int parse_operation_data(const uint8_t *xdr,
230232

231233
// Parse amount (common for both operations)
232234
payment->amount = read_uint64_be_offset(xdr, offset);
233-
235+
234236
return 0;
235237
}
236238

@@ -271,7 +273,7 @@ int stellar_parse_transaction(const uint8_t *xdr,
271273
uint32_t preconditions_type = read_uint32_be_offset(xdr, &offset);
272274

273275
if (preconditions_type == 1) {
274-
offset += 16; // Skip time bounds (8 + 8 bytes)
276+
offset += 16; // Skip time bounds (8 + 8 bytes)
275277
} else if (preconditions_type != 0) {
276278
return -1;
277279
}

common/libraries/util/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ uint8_t string_to_escaped_string(const char *input,
489489
void write_uint32_be(uint8_t *buffer, uint32_t value);
490490

491491
/**
492-
* @brief Write 64-bit value in big-endian format
492+
* @brief Write 64-bit value in big-endian format
493493
* @param buffer Output buffer
494494
* @param value 64-bit value to write
495495
*/

src/constant_texts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ extern const char *ui_text_send_logs_prompt;
421421

422422
// Stellar memo display texts
423423
#define UI_TEXT_STELLAR_MEMO_TEXT "Memo: \"%s\""
424-
#define UI_TEXT_STELLAR_MEMO_ID "Memo ID: %llu"
424+
#define UI_TEXT_STELLAR_MEMO_ID "Memo ID: %llu"
425425
#define UI_TEXT_STELLAR_MEMO_HASH "Memo Hash: %s"
426426
#define UI_TEXT_STELLAR_OPERATION "Operation: %s"
427427
#define UI_TEXT_STELLAR_MEMO_UNKNOWN "Memo: (unknown type %u)"

0 commit comments

Comments
 (0)