Refactoring helper to get printable eth address from hex

This commit is contained in:
TamtamHero
2021-08-25 13:43:27 +02:00
parent dda1e20fb3
commit 3e25f04d05
8 changed files with 80 additions and 62 deletions

View File

@@ -219,6 +219,24 @@ void getEthAddressStringFromBinary(uint8_t *address,
out[40] = '\0';
}
// Fills the `out` buffer with the lowercase string representation of the pubkey passed in as binary
// format by `in`. (eg: uint8_t*:0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB ->
// char*:"0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB\0" ) `sha3` context doesn't have have to be
// initialized prior to call. `chain_config` must be initialized.
void getEthDisplayableAddress(uint8_t *in,
char *out,
size_t out_len,
cx_sha3_t *sha3,
chain_config_t *chain_config) {
if (out_len < 43) {
strlcpy(out, "ERROR", out_len);
return;
}
out[0] = '0';
out[1] = 'x';
getEthAddressStringFromBinary(in, out + 2, sha3, chain_config);
}
bool adjustDecimals(char *src,
uint32_t srcLength,
char *target,

View File

@@ -51,6 +51,12 @@ void getEthAddressStringFromBinary(uint8_t *address,
cx_sha3_t *sha3Context,
chain_config_t *chain_config);
void getEthDisplayableAddress(uint8_t *in,
char *out,
size_t out_len,
cx_sha3_t *sha3,
chain_config_t *chain_config);
bool adjustDecimals(char *src,
uint32_t srcLength,
char *target,