mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-23 22:01:01 +00:00
refactor(legacy): update to new Stellar protobuf usage
[no changelog]
This commit is contained in:
parent
98f0496b2c
commit
4b8f52cd2f
@ -1,5 +1,5 @@
|
|||||||
StellarAssetType.code max_size:13
|
StellarAsset.code max_size:13
|
||||||
StellarAssetType.issuer max_size:57
|
StellarAsset.issuer max_size:57
|
||||||
StellarGetAddress.address_n max_count:10
|
StellarGetAddress.address_n max_count:10
|
||||||
|
|
||||||
StellarAddress.address max_size:57
|
StellarAddress.address max_size:57
|
||||||
|
@ -121,20 +121,20 @@ bool stellar_signingInit(const StellarSignTx *msg) {
|
|||||||
stellar_hashupdate_uint32(msg->memo_type);
|
stellar_hashupdate_uint32(msg->memo_type);
|
||||||
switch (msg->memo_type) {
|
switch (msg->memo_type) {
|
||||||
// None, nothing else to do
|
// None, nothing else to do
|
||||||
case 0:
|
case StellarMemoType_NONE:
|
||||||
break;
|
break;
|
||||||
// Text: 4 bytes (size) + up to 28 bytes
|
// Text: 4 bytes (size) + up to 28 bytes
|
||||||
case 1:
|
case StellarMemoType_TEXT:
|
||||||
stellar_hashupdate_string((unsigned char *)&(msg->memo_text),
|
stellar_hashupdate_string((unsigned char *)&(msg->memo_text),
|
||||||
strnlen(msg->memo_text, 28));
|
strnlen(msg->memo_text, 28));
|
||||||
break;
|
break;
|
||||||
// ID (8 bytes, uint64)
|
// ID (8 bytes, uint64)
|
||||||
case 2:
|
case StellarMemoType_ID:
|
||||||
stellar_hashupdate_uint64(msg->memo_id);
|
stellar_hashupdate_uint64(msg->memo_id);
|
||||||
break;
|
break;
|
||||||
// Hash and return are the same data structure (32 byte tx hash)
|
// Hash and return are the same data structure (32 byte tx hash)
|
||||||
case 3:
|
case StellarMemoType_HASH:
|
||||||
case 4:
|
case StellarMemoType_RETURN:
|
||||||
stellar_hashupdate_bytes(msg->memo_hash.bytes, 32);
|
stellar_hashupdate_bytes(msg->memo_hash.bytes, 32);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -791,7 +791,7 @@ bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg) {
|
|||||||
char *str_signer_type = NULL;
|
char *str_signer_type = NULL;
|
||||||
bool needs_hash_confirm = false;
|
bool needs_hash_confirm = false;
|
||||||
switch (msg->signer_type) {
|
switch (msg->signer_type) {
|
||||||
case 0:
|
case StellarSignerType_ACCOUNT:
|
||||||
strlcat(str_title, _("account"), sizeof(str_title));
|
strlcat(str_title, _("account"), sizeof(str_title));
|
||||||
|
|
||||||
const char **str_addr_rows =
|
const char **str_addr_rows =
|
||||||
@ -805,8 +805,8 @@ bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case StellarSignerType_PRE_AUTH:
|
||||||
case 2:
|
case StellarSignerType_HASH:
|
||||||
str_signer_type =
|
str_signer_type =
|
||||||
(msg->signer_type == 1) ? _("pre-auth hash") : _("hash(x)");
|
(msg->signer_type == 1) ? _("pre-auth hash") : _("hash(x)");
|
||||||
needs_hash_confirm = true;
|
needs_hash_confirm = true;
|
||||||
@ -971,13 +971,13 @@ bool stellar_confirmAllowTrustOp(const StellarAllowTrustOp *msg) {
|
|||||||
// asset code
|
// asset code
|
||||||
char padded_code[12 + 1] = {0};
|
char padded_code[12 + 1] = {0};
|
||||||
switch (msg->asset_type) {
|
switch (msg->asset_type) {
|
||||||
case 0: // native asset (XLM)
|
case StellarAssetType_NATIVE: // native asset (XLM)
|
||||||
break;
|
break;
|
||||||
case 1: // alphanum 4
|
case StellarAssetType_ALPHANUM4:
|
||||||
strlcpy(padded_code, msg->asset_code, 4 + 1);
|
strlcpy(padded_code, msg->asset_code, 4 + 1);
|
||||||
stellar_hashupdate_bytes((uint8_t *)padded_code, 4);
|
stellar_hashupdate_bytes((uint8_t *)padded_code, 4);
|
||||||
break;
|
break;
|
||||||
case 2: // alphanum 12
|
case StellarAssetType_ALPHANUM12:
|
||||||
strlcpy(padded_code, msg->asset_code, 12 + 1);
|
strlcpy(padded_code, msg->asset_code, 12 + 1);
|
||||||
stellar_hashupdate_bytes((uint8_t *)padded_code, 12);
|
stellar_hashupdate_bytes((uint8_t *)padded_code, 12);
|
||||||
break;
|
break;
|
||||||
@ -1286,7 +1286,7 @@ const char **stellar_lineBreakAddress(const uint8_t *addrbytes) {
|
|||||||
* MOBI (G123456789000)
|
* MOBI (G123456789000)
|
||||||
* ALPHA12EXAMP (G0987)
|
* ALPHA12EXAMP (G0987)
|
||||||
*/
|
*/
|
||||||
void stellar_format_asset(const StellarAssetType *asset, char *str_formatted,
|
void stellar_format_asset(const StellarAsset *asset, char *str_formatted,
|
||||||
size_t len) {
|
size_t len) {
|
||||||
char str_asset_code[12 + 1] = {0};
|
char str_asset_code[12 + 1] = {0};
|
||||||
// truncated asset issuer, final length depends on length of asset code
|
// truncated asset issuer, final length depends on length of asset code
|
||||||
@ -1297,17 +1297,17 @@ void stellar_format_asset(const StellarAssetType *asset, char *str_formatted,
|
|||||||
memzero(str_asset_issuer_trunc, sizeof(str_asset_issuer_trunc));
|
memzero(str_asset_issuer_trunc, sizeof(str_asset_issuer_trunc));
|
||||||
|
|
||||||
// Validate issuer account for non-native assets
|
// Validate issuer account for non-native assets
|
||||||
if (asset->type != 0 && !stellar_validateAddress(asset->issuer)) {
|
if (asset->type != StellarAssetType_NATIVE && !stellar_validateAddress(asset->issuer)) {
|
||||||
stellar_signingAbort(_("Invalid asset issuer"));
|
stellar_signingAbort(_("Invalid asset issuer"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Native asset
|
// Native asset
|
||||||
if (asset->type == 0) {
|
if (asset->type == StellarAssetType_NATIVE) {
|
||||||
strlcpy(str_formatted, _("XLM (native asset)"), len);
|
strlcpy(str_formatted, _("XLM (native asset)"), len);
|
||||||
}
|
}
|
||||||
// 4-character custom
|
// 4-character custom
|
||||||
if (asset->type == 1) {
|
if (asset->type == StellarAssetType_ALPHANUM4) {
|
||||||
memcpy(str_asset_code, asset->code, 4);
|
memcpy(str_asset_code, asset->code, 4);
|
||||||
strlcpy(str_formatted, str_asset_code, len);
|
strlcpy(str_formatted, str_asset_code, len);
|
||||||
|
|
||||||
@ -1315,7 +1315,7 @@ void stellar_format_asset(const StellarAssetType *asset, char *str_formatted,
|
|||||||
memcpy(str_asset_issuer_trunc, asset->issuer, 13);
|
memcpy(str_asset_issuer_trunc, asset->issuer, 13);
|
||||||
}
|
}
|
||||||
// 12-character custom
|
// 12-character custom
|
||||||
if (asset->type == 2) {
|
if (asset->type == StellarAssetType_ALPHANUM12) {
|
||||||
memcpy(str_asset_code, asset->code, 12);
|
memcpy(str_asset_code, asset->code, 12);
|
||||||
strlcpy(str_formatted, str_asset_code, len);
|
strlcpy(str_formatted, str_asset_code, len);
|
||||||
|
|
||||||
@ -1323,7 +1323,7 @@ void stellar_format_asset(const StellarAssetType *asset, char *str_formatted,
|
|||||||
memcpy(str_asset_issuer_trunc, asset->issuer, 5);
|
memcpy(str_asset_issuer_trunc, asset->issuer, 5);
|
||||||
}
|
}
|
||||||
// Issuer is read the same way for both types of custom assets
|
// Issuer is read the same way for both types of custom assets
|
||||||
if (asset->type == 1 || asset->type == 2) {
|
if (asset->type == StellarAssetType_ALPHANUM4 || asset->type == StellarAssetType_ALPHANUM12) {
|
||||||
strlcat(str_formatted, _(" ("), len);
|
strlcat(str_formatted, _(" ("), len);
|
||||||
strlcat(str_formatted, str_asset_issuer_trunc, len);
|
strlcat(str_formatted, str_asset_issuer_trunc, len);
|
||||||
strlcat(str_formatted, _(")"), len);
|
strlcat(str_formatted, _(")"), len);
|
||||||
@ -1544,19 +1544,19 @@ void stellar_hashupdate_address(const uint8_t *address_bytes) {
|
|||||||
* a typical string, so if "TEST" is the asset code then the hashed value needs
|
* a typical string, so if "TEST" is the asset code then the hashed value needs
|
||||||
* to be 4 bytes and not include the null at the end of the string
|
* to be 4 bytes and not include the null at the end of the string
|
||||||
*/
|
*/
|
||||||
void stellar_hashupdate_asset(const StellarAssetType *asset) {
|
void stellar_hashupdate_asset(const StellarAsset *asset) {
|
||||||
stellar_hashupdate_uint32(asset->type);
|
stellar_hashupdate_uint32(asset->type);
|
||||||
|
|
||||||
// For non-native assets, validate issuer account and convert to bytes
|
// For non-native assets, validate issuer account and convert to bytes
|
||||||
uint8_t issuer_bytes[STELLAR_KEY_SIZE] = {0};
|
uint8_t issuer_bytes[STELLAR_KEY_SIZE] = {0};
|
||||||
if (asset->type != 0 &&
|
if (asset->type != StellarAssetType_NATIVE &&
|
||||||
!stellar_getAddressBytes(asset->issuer, issuer_bytes)) {
|
!stellar_getAddressBytes(asset->issuer, issuer_bytes)) {
|
||||||
stellar_signingAbort(_("Invalid asset issuer"));
|
stellar_signingAbort(_("Invalid asset issuer"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4-character asset code
|
// 4-character asset code
|
||||||
if (asset->type == 1) {
|
if (asset->type == StellarAssetType_ALPHANUM4) {
|
||||||
char code4[4 + 1] = {0};
|
char code4[4 + 1] = {0};
|
||||||
memzero(code4, sizeof(code4));
|
memzero(code4, sizeof(code4));
|
||||||
strlcpy(code4, asset->code, sizeof(code4));
|
strlcpy(code4, asset->code, sizeof(code4));
|
||||||
@ -1566,7 +1566,7 @@ void stellar_hashupdate_asset(const StellarAssetType *asset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 12-character asset code
|
// 12-character asset code
|
||||||
if (asset->type == 2) {
|
if (asset->type == StellarAssetType_ALPHANUM12) {
|
||||||
char code12[12 + 1] = {0};
|
char code12[12 + 1] = {0};
|
||||||
memzero(code12, sizeof(code12));
|
memzero(code12, sizeof(code12));
|
||||||
strlcpy(code12, asset->code, sizeof(code12));
|
strlcpy(code12, asset->code, sizeof(code12));
|
||||||
@ -1627,13 +1627,13 @@ void stellar_layoutTransactionSummary(const StellarSignTx *msg) {
|
|||||||
memzero(str_lines, sizeof(str_lines));
|
memzero(str_lines, sizeof(str_lines));
|
||||||
|
|
||||||
switch (msg->memo_type) {
|
switch (msg->memo_type) {
|
||||||
case 0: // Memo: none
|
case StellarMemoType_NONE:
|
||||||
strlcpy(str_lines[0], _("[No Memo Set]"), sizeof(str_lines[0]));
|
strlcpy(str_lines[0], _("[No Memo Set]"), sizeof(str_lines[0]));
|
||||||
strlcpy(str_lines[1], _("Important:"), sizeof(str_lines[0]));
|
strlcpy(str_lines[1], _("Important:"), sizeof(str_lines[0]));
|
||||||
strlcpy(str_lines[2], _("Many exchanges require"), sizeof(str_lines[0]));
|
strlcpy(str_lines[2], _("Many exchanges require"), sizeof(str_lines[0]));
|
||||||
strlcpy(str_lines[3], _("a memo when depositing."), sizeof(str_lines[0]));
|
strlcpy(str_lines[3], _("a memo when depositing."), sizeof(str_lines[0]));
|
||||||
break;
|
break;
|
||||||
case 1: // Memo: text
|
case StellarMemoType_TEXT:
|
||||||
strlcpy(str_lines[0], _("Memo (TEXT)"), sizeof(str_lines[0]));
|
strlcpy(str_lines[0], _("Memo (TEXT)"), sizeof(str_lines[0]));
|
||||||
|
|
||||||
// Split 28-character string into two lines of 19 / 9
|
// Split 28-character string into two lines of 19 / 9
|
||||||
@ -1641,15 +1641,15 @@ void stellar_layoutTransactionSummary(const StellarSignTx *msg) {
|
|||||||
strlcpy(str_lines[1], (const char *)msg->memo_text, 19 + 1);
|
strlcpy(str_lines[1], (const char *)msg->memo_text, 19 + 1);
|
||||||
strlcpy(str_lines[2], (const char *)(msg->memo_text + 19), 9 + 1);
|
strlcpy(str_lines[2], (const char *)(msg->memo_text + 19), 9 + 1);
|
||||||
break;
|
break;
|
||||||
case 2: // Memo: ID
|
case StellarMemoType_ID:
|
||||||
strlcpy(str_lines[0], _("Memo (ID)"), sizeof(str_lines[0]));
|
strlcpy(str_lines[0], _("Memo (ID)"), sizeof(str_lines[0]));
|
||||||
stellar_format_uint64(msg->memo_id, str_lines[1], sizeof(str_lines[1]));
|
stellar_format_uint64(msg->memo_id, str_lines[1], sizeof(str_lines[1]));
|
||||||
break;
|
break;
|
||||||
case 3: // Memo: hash
|
case StellarMemoType_HASH:
|
||||||
needs_memo_hash_confirm = 1;
|
needs_memo_hash_confirm = 1;
|
||||||
strlcpy(str_lines[0], _("Memo (HASH)"), sizeof(str_lines[0]));
|
strlcpy(str_lines[0], _("Memo (HASH)"), sizeof(str_lines[0]));
|
||||||
break;
|
break;
|
||||||
case 4: // Memo: return
|
case StellarMemoType_RETURN:
|
||||||
needs_memo_hash_confirm = 1;
|
needs_memo_hash_confirm = 1;
|
||||||
strlcpy(str_lines[0], _("Memo (RETURN)"), sizeof(str_lines[0]));
|
strlcpy(str_lines[0], _("Memo (RETURN)"), sizeof(str_lines[0]));
|
||||||
break;
|
break;
|
||||||
|
@ -94,7 +94,7 @@ void stellar_hashupdate_uint64(uint64_t value);
|
|||||||
void stellar_hashupdate_bool(bool value);
|
void stellar_hashupdate_bool(bool value);
|
||||||
void stellar_hashupdate_string(const uint8_t *data, size_t len);
|
void stellar_hashupdate_string(const uint8_t *data, size_t len);
|
||||||
void stellar_hashupdate_address(const uint8_t *address_bytes);
|
void stellar_hashupdate_address(const uint8_t *address_bytes);
|
||||||
void stellar_hashupdate_asset(const StellarAssetType *asset);
|
void stellar_hashupdate_asset(const StellarAsset *asset);
|
||||||
void stellar_hashupdate_bytes(const uint8_t *data, size_t len);
|
void stellar_hashupdate_bytes(const uint8_t *data, size_t len);
|
||||||
|
|
||||||
void stellar_fillSignedTx(StellarSignedTx *resp);
|
void stellar_fillSignedTx(StellarSignedTx *resp);
|
||||||
@ -104,7 +104,7 @@ void stellar_getSignatureForActiveTx(uint8_t *out_signature);
|
|||||||
void stellar_format_uint32(uint32_t number, char *out, size_t outlen);
|
void stellar_format_uint32(uint32_t number, char *out, size_t outlen);
|
||||||
void stellar_format_uint64(uint64_t number, char *out, size_t outlen);
|
void stellar_format_uint64(uint64_t number, char *out, size_t outlen);
|
||||||
void stellar_format_stroops(uint64_t number, char *out, size_t outlen);
|
void stellar_format_stroops(uint64_t number, char *out, size_t outlen);
|
||||||
void stellar_format_asset(const StellarAssetType *asset, char *str_formatted,
|
void stellar_format_asset(const StellarAsset *asset, char *str_formatted,
|
||||||
size_t len);
|
size_t len);
|
||||||
void stellar_format_price(uint32_t numerator, uint32_t denominator, char *out,
|
void stellar_format_price(uint32_t numerator, uint32_t denominator, char *out,
|
||||||
size_t outlen);
|
size_t outlen);
|
||||||
|
Loading…
Reference in New Issue
Block a user