Skip to content

Commit bf4aa28

Browse files
committed
feat: Add stellar txn and helper files
1 parent 044e31b commit bf4aa28

File tree

10 files changed

+1434
-133
lines changed

10 files changed

+1434
-133
lines changed

apps/stellar_app/stellar_api.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@
101101
* GLOBAL FUNCTIONS
102102
*****************************************************************************/
103103
bool decode_stellar_query(const uint8_t *data,
104-
uint16_t data_size,
105-
stellar_query_t *query_out) {
104+
uint16_t data_size,
105+
stellar_query_t *query_out) {
106106
if (NULL == data || NULL == query_out || 0 == data_size) {
107107
stellar_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
108-
ERROR_DATA_FLOW_DECODING_FAILED);
108+
ERROR_DATA_FLOW_DECODING_FAILED);
109109
return false;
110110
}
111111

@@ -121,16 +121,16 @@ bool decode_stellar_query(const uint8_t *data,
121121
/* Send error to host if status is false*/
122122
if (false == status) {
123123
stellar_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
124-
ERROR_DATA_FLOW_DECODING_FAILED);
124+
ERROR_DATA_FLOW_DECODING_FAILED);
125125
}
126126

127127
return status;
128128
}
129129

130130
bool encode_stellar_result(const stellar_result_t *result,
131-
uint8_t *buffer,
132-
uint16_t max_buffer_len,
133-
size_t *bytes_written_out) {
131+
uint8_t *buffer,
132+
uint16_t max_buffer_len,
133+
size_t *bytes_written_out) {
134134
if (NULL == result || NULL == buffer || NULL == bytes_written_out)
135135
return false;
136136

@@ -147,10 +147,11 @@ bool encode_stellar_result(const stellar_result_t *result,
147147
return status;
148148
}
149149

150-
bool check_stellar_query(const stellar_query_t *query, pb_size_t exp_query_tag) {
150+
bool check_stellar_query(const stellar_query_t *query,
151+
pb_size_t exp_query_tag) {
151152
if ((NULL == query) || (exp_query_tag != query->which_request)) {
152153
stellar_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
153-
ERROR_DATA_FLOW_INVALID_QUERY);
154+
ERROR_DATA_FLOW_INVALID_QUERY);
154155
return false;
155156
}
156157
return true;
@@ -163,7 +164,8 @@ stellar_result_t init_stellar_result(pb_size_t result_tag) {
163164
}
164165

165166
void stellar_send_error(pb_size_t which_error, uint32_t error_code) {
166-
stellar_result_t result = init_stellar_result(STELLAR_RESULT_COMMON_ERROR_TAG);
167+
stellar_result_t result =
168+
init_stellar_result(STELLAR_RESULT_COMMON_ERROR_TAG);
167169
result.common_error = init_common_error(which_error, error_code);
168170
stellar_send_result(&result);
169171
}

apps/stellar_app/stellar_api.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
* @return bool True if decoding was successful, else false
4242
*/
4343
bool decode_stellar_query(const uint8_t *data,
44-
uint16_t data_size,
45-
stellar_query_t *query_out);
44+
uint16_t data_size,
45+
stellar_query_t *query_out);
4646

4747
/**
4848
* @brief Encodes the STELLAR result with `STELLAR_RESULT_FIELDS` to byte-stream
@@ -55,9 +55,9 @@ bool decode_stellar_query(const uint8_t *data,
5555
* @return bool True if decoding was successful, else false
5656
*/
5757
bool encode_stellar_result(const stellar_result_t *result,
58-
uint8_t *buffer,
59-
uint16_t max_buffer_len,
60-
size_t *bytes_written_out);
58+
uint8_t *buffer,
59+
uint16_t max_buffer_len,
60+
size_t *bytes_written_out);
6161

6262
/**
6363
* @brief This API checks if the `which_request` field of the query of type

apps/stellar_app/stellar_context.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,39 +45,38 @@ typedef struct {
4545

4646
// Stellar Memo types
4747
typedef enum {
48-
MEMO_NONE = 0,
49-
MEMO_TEXT = 1,
50-
MEMO_ID = 2,
51-
MEMO_HASH = 3,
52-
MEMO_RETURN = 4
48+
MEMO_NONE = 0,
49+
MEMO_TEXT = 1,
50+
MEMO_ID = 2,
51+
MEMO_HASH = 3,
52+
MEMO_RETURN = 4
5353
} stellar_memo_type_t;
5454

5555
// Stellar transaction structures
5656
typedef struct {
57-
uint8_t source_account[32];
58-
uint64_t sequence_number;
59-
uint32_t fee;
60-
uint32_t operation_count;
61-
uint32_t operation_type; // CREATE_ACCOUNT = 0, PAYMENT = 1
62-
stellar_memo_type_t memo_type;
63-
union {
64-
char text[29]; // MEMO_TEXT (max 28 bytes + 1 byte delimiter)
65-
uint64_t id; // MEMO_ID
66-
uint8_t hash[32]; // MEMO_HASH or MEMO_RETURN(32 bytes)
67-
} memo;
57+
uint8_t source_account[32];
58+
uint64_t sequence_number;
59+
uint32_t fee;
60+
uint32_t operation_count;
61+
uint32_t operation_type; // CREATE_ACCOUNT = 0, PAYMENT = 1
62+
stellar_memo_type_t memo_type;
63+
union {
64+
char text[29]; // MEMO_TEXT (max 28 bytes + 1 byte delimiter)
65+
uint64_t id; // MEMO_ID
66+
uint8_t hash[32]; // MEMO_HASH or MEMO_RETURN(32 bytes)
67+
} memo;
6868
} stellar_transaction_t;
6969

7070
typedef struct {
71-
uint8_t destination[32];
72-
uint64_t amount;
71+
uint8_t destination[32];
72+
uint64_t amount;
7373
} stellar_payment_t;
7474

7575
typedef enum {
76-
STELLAR_NETWORK_MAINNET = 0,
77-
STELLAR_NETWORK_TESTNET = 1
76+
STELLAR_NETWORK_MAINNET = 0,
77+
STELLAR_NETWORK_TESTNET = 1
7878
} stellar_network_t;
7979

80-
8180
/*****************************************************************************
8281
* EXPORTED VARIABLES
8382
*****************************************************************************/
@@ -91,9 +90,10 @@ typedef enum {
9190
* 1. Creates a payload with account ID type (0x30) and the public key
9291
* 2. Calculates CRC16 checksum
9392
* 3. Encodes the result using base32
94-
*
93+
*
9594
* @param public_key The 32-byte ED25519 public key
96-
* @param address Buffer to store the resulting address (must be at least STELLAR_ADDRESS_LENGTH bytes)
95+
* @param address Buffer to store the resulting address (must be at least
96+
* STELLAR_ADDRESS_LENGTH bytes)
9797
* @return true if the address was generated successfully, false otherwise
9898
*/
9999
bool stellar_generate_address(const uint8_t *public_key, char *address);

apps/stellar_app/stellar_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ bool stellar_derivation_path_guard(const uint32_t *path, uint8_t levels) {
101101
}
102102

103103
uint32_t purpose = path[0], coin = path[1], account = path[2];
104-
104+
105105
// m/44'/148'/n' - support any hardened account index
106106
status = (STELLAR_PURPOSE_INDEX == purpose && STELLAR_COIN_INDEX == coin &&
107107
is_hardened(account));

apps/stellar_app/stellar_main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ void stellar_main(usb_event_t usb_evt, const void *stellar_app_config);
9999
*****************************************************************************/
100100

101101
static const cy_app_desc_t stellar_app_desc = {.id = 25,
102-
.version =
103-
{
104-
.major = 1,
105-
.minor = 0,
106-
.patch = 0,
107-
},
108-
.app = stellar_main,
109-
.app_config = NULL};
102+
.version =
103+
{
104+
.major = 1,
105+
.minor = 0,
106+
.patch = 0,
107+
},
108+
.app = stellar_main,
109+
.app_config = NULL};
110110

111111
/*****************************************************************************
112112
* STATIC FUNCTIONS
@@ -135,7 +135,7 @@ void stellar_main(usb_event_t usb_evt, const void *stellar_app_config) {
135135
default: {
136136
/* In case we ever encounter invalid query, convey to the host app */
137137
stellar_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
138-
ERROR_DATA_FLOW_INVALID_QUERY);
138+
ERROR_DATA_FLOW_INVALID_QUERY);
139139
break;
140140
}
141141
}

apps/stellar_app/stellar_priv.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ typedef struct {
3434
// decoded transaction structures
3535
stellar_transaction_t *txn;
3636
stellar_payment_t *payment;
37-
3837
} stellar_txn_context_t;
3938

4039
/*****************************************************************************
@@ -47,17 +46,17 @@ typedef struct {
4746

4847
/**
4948
* @brief Handler for Stellar public key derivation.
50-
* @details This flow expects STELLAR_GET_PUBLIC_KEY_REQUEST_INITIATE_TAG as initial
51-
* query, otherwise the flow is aborted
49+
* @details This flow expects STELLAR_GET_PUBLIC_KEY_REQUEST_INITIATE_TAG as
50+
* initial query, otherwise the flow is aborted
5251
*
5352
* @param query object for address public key query
5453
*/
5554
void stellar_get_pub_keys(stellar_query_t *query);
5655

5756
/**
5857
* @brief Handler for signing a transaction on stellar.
59-
* @details The expected request type is STELLAR_SIGN_TXN_REQUEST_INITIATE_TAG. The
60-
* function controls the complete data exchange with host, user prompts and
58+
* @details The expected request type is STELLAR_SIGN_TXN_REQUEST_INITIATE_TAG.
59+
* The function controls the complete data exchange with host, user prompts and
6160
* confirmations for signing an STELLAR based transaction.
6261
*
6362
* @param query Reference to the decoded query struct from the host app

0 commit comments

Comments
 (0)