Skip to content

Commit b343e09

Browse files
Merge pull request #666 from Cypherock/fix/stellar/reviews
fix: Resolve stellar review comments and fixes
2 parents 3578a93 + 932f0f6 commit b343e09

File tree

9 files changed

+255
-203
lines changed

9 files changed

+255
-203
lines changed

apps/stellar_app/stellar_context.h

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,84 @@ typedef enum {
6868
STELLAR_OPERATION_PAYMENT = 1
6969
} stellar_operation_type_t;
7070

71+
// Custom generic structure for Stellar operation data
72+
// So far we only support create account and payment operations with native
73+
// asset only
74+
typedef struct {
75+
stellar_operation_type_t type;
76+
uint8_t destination[STELLAR_PUBKEY_RAW_SIZE];
77+
uint64_t amount;
78+
} stellar_operation_data_t;
79+
80+
// Stellar preconditions types
81+
// See
82+
// https://developers.stellar.org/docs/learn/fundamentals/transactions/operations-and-transactions#preconditions
83+
// See
84+
// https://github.com/stellar/js-stellar-base/blob/master/xdr/curr/Stellar-transaction.x#L804
85+
typedef enum {
86+
STELLAR_PRECOND_NONE = 0,
87+
STELLAR_PRECOND_TIME = 1,
88+
STELLAR_PRECOND_V2 = 2
89+
} stellar_preconditions_type_t;
90+
91+
// Stellar time bounds structure
92+
// See
93+
// https://developers.stellar.org/docs/learn/fundamentals/transactions/operations-and-transactions#time-bounds
94+
// See
95+
// https://github.com/stellar/js-stellar-base/blob/master/xdr/curr/Stellar-transaction.x#L759
96+
typedef struct {
97+
uint64_t min_time;
98+
uint64_t max_time;
99+
} stellar_time_bounds_t;
100+
101+
// Stellar preconditions structure
102+
// See
103+
// https://developers.stellar.org/docs/learn/fundamentals/transactions/operations
104+
typedef struct {
105+
stellar_preconditions_type_t type;
106+
union {
107+
stellar_time_bounds_t
108+
time_bounds; // For PRECOND_TIME, only PRECOND_TIME is supported
109+
// For PRECOND_V2, we can add more fields in future if needed
110+
} preconditions;
111+
} stellar_preconditions_t;
112+
113+
// Stellar transaction extension types
114+
// See
115+
// https://github.com/stellar/js-stellar-base/blob/master/xdr/curr/Stellar-transaction.x#L929
116+
typedef enum {
117+
STELLAR_EXT_TYPE_EMPTY = 0, // Empty extension, only supported type
118+
// Other extension types can be added in future if needed
119+
} stellar_ext_type_t;
120+
121+
// Stellar transaction extension structure
122+
// See
123+
// https://github.com/stellar/js-stellar-base/blob/master/xdr/curr/Stellar-transaction.x#L929
124+
typedef struct {
125+
stellar_ext_type_t
126+
type; // Currently only STELLAR_EXT_TYPE_EMPTY is supported
127+
// Other fields can be added in future if needed
128+
} stellar_transaction_extension_t;
129+
71130
// Stellar transaction structures
72-
// See https://developers.stellar.org/docs/learn/encyclopedia/data-format/xdr
131+
// See
132+
// https://github.com/stellar/stellar-xdr/blob/curr/Stellar-transaction.x#L911
73133
typedef struct {
74-
uint8_t source_account[32];
134+
uint8_t source_account[STELLAR_PUBKEY_RAW_SIZE];
75135
uint64_t sequence_number;
76136
uint32_t fee;
77-
uint32_t operation_count;
78-
stellar_operation_type_t operation_type;
79137
stellar_memo_type_t memo_type;
80138
union {
81139
char text[29]; // STELLAR_MEMO_TEXT (max 28 bytes + 1 byte delimiter)
82140
uint64_t id; // STELLAR_MEMO_ID
83141
uint8_t hash[32]; // STELLAR_MEMO_HASH or STELLAR_MEMO_RETURN(32 bytes)
84142
} memo;
143+
uint32_t operation_count;
144+
stellar_operation_data_t operations[1]; // Only one operation supported
145+
stellar_preconditions_t preconditions;
146+
stellar_transaction_extension_t ext;
85147
} stellar_transaction_t;
86148

87-
typedef struct {
88-
uint8_t destination[32];
89-
uint64_t amount;
90-
} stellar_payment_t;
91-
92149
typedef enum {
93150
STELLAR_NETWORK_MAINNET = 0,
94151
STELLAR_NETWORK_TESTNET = 1

apps/stellar_app/stellar_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ bool stellar_generate_address(const uint8_t *public_key, char *address) {
142142
// Stellar address encoding (StrKey format)
143143
// See
144144
// https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md
145-
uint8_t payload[35];
145+
uint8_t payload[35] = {0};
146146
payload[0] = 0x30; // Account ID version byte (6 << 3 | 0 = STRKEY_PUBKEY
147147
// OR STRKEY_ALG_ED25519)
148148
memcpy(payload + 1, public_key, STELLAR_PUBKEY_RAW_SIZE);

apps/stellar_app/stellar_priv.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ typedef struct {
3333

3434
// decoded transaction structures
3535
stellar_transaction_t *txn;
36-
stellar_payment_t *payment;
37-
size_t signature_data_len;
36+
37+
// holds the length of the xdr txn used for signing
38+
uint32_t tagged_txn_len;
3839
} stellar_txn_context_t;
3940

4041
/*****************************************************************************

0 commit comments

Comments
 (0)