From 0760f2c5d6800c2a9ed21d616bd67a24e8c81499 Mon Sep 17 00:00:00 2001 From: gministeri Date: Mon, 18 Sep 2023 15:37:29 +0200 Subject: [PATCH] list of changes - renaming hdkey formatting functions: better more expressive names - refactor return values of such functions to copy snprintf behaviour - BIP32_SERIALIZED_LEN rather than magic number 78 --- include/urc/crypto_hdkey.h | 13 +++-- src/hdkey.c | 30 +++++----- tests/parser.c | 112 ++++++++++++++++++------------------- 3 files changed, 78 insertions(+), 77 deletions(-) diff --git a/include/urc/crypto_hdkey.h b/include/urc/crypto_hdkey.h index f19f42d..94c4ad4 100644 --- a/include/urc/crypto_hdkey.h +++ b/include/urc/crypto_hdkey.h @@ -105,8 +105,11 @@ typedef struct { } crypto_hdkey; urc_error parse_hdkey(size_t size, const uint8_t *buffer, crypto_hdkey *out); -bool hdkey2bip32(const crypto_hdkey *hdkey, uint8_t out[78]); -// -1 --> out of memory -// -2 --> internal error / invalid hdkey -int hdkey2keypathstr(const crypto_hdkey *hdkey, size_t size, char *out); -int hdkeytrail(const crypto_hdkey *hdkey, size_t size, char *out); +#define BIP32_SERIALIZED_LEN 78 +bool bip32_serialize(const crypto_hdkey *hdkey, uint8_t out[BIP32_SERIALIZED_LEN]); +// return values of following functions follow the snprintf convention: +// any value >= of size means that the output has been truncated +// any value >= 0 indicates the number of characters written to ``out`` buffer (excluding the null-terminator) +// otherwise, any value <0 means an error occurred +int format_keyorigin(const crypto_hdkey *hdkey, size_t size, char *out); +int format_keyderivationpath(const crypto_hdkey *hdkey, size_t size, char *out); diff --git a/src/hdkey.c b/src/hdkey.c index fac0dd9..bf54554 100644 --- a/src/hdkey.c +++ b/src/hdkey.c @@ -498,7 +498,7 @@ urc_error internal_parse_pair_component(CborValue *iter, child_pair_component *o return result; } -bool hdkey2bip32(const crypto_hdkey *hdkey, uint8_t out[78]) { +bool bip32_serialize(const crypto_hdkey *hdkey, uint8_t out[BIP32_SERIALIZED_LEN]) { size_t cursor = 0; uint32_t *version = (uint32_t *)&out[cursor]; // 0 - 3 @@ -629,12 +629,12 @@ bool hdkey2bip32(const crypto_hdkey *hdkey, uint8_t out[78]) { return true; } -int hdkey2keypathstr(const crypto_hdkey *hdkey, size_t size, char *out) { +int format_keyorigin(const crypto_hdkey *hdkey, size_t size, char *out) { switch (hdkey->type) { case hdkey_type_master: return 0; case hdkey_type_na: - return -2; + return -1; default: break; } @@ -645,8 +645,9 @@ int hdkey2keypathstr(const crypto_hdkey *hdkey, size_t size, char *out) { fpr = hdkey->key.derived.parent_fingerprint; } len += snprintf(out, size, "[%x", fpr); + // either an error or an out-of-space if (len < 0 || (size_t)len >= size) { - return -1; + return len; } for (size_t idx = 0; idx < hdkey->key.derived.origin.components_count; idx++) { const path_component *comp = &hdkey->key.derived.origin.components[idx]; @@ -659,25 +660,24 @@ int hdkey2keypathstr(const crypto_hdkey *hdkey, size_t size, char *out) { } break; default: - return -2; + return -1; } + // either an error or an out-of-space if (len < 0 || (size_t)len >= size) { - return -1; + return len; } } len += snprintf(&out[len], size - len, "]"); - if (len < 0 || (size_t)len >= size) { - return -1; - } + // it includes error or out-of-space cases return len; } -int hdkeytrail(const crypto_hdkey *hdkey, size_t size, char *out) { +int format_keyderivationpath(const crypto_hdkey *hdkey, size_t size, char *out) { switch (hdkey->type) { case hdkey_type_master: return 0; case hdkey_type_na: - return -2; + return -1; default: break; } @@ -697,15 +697,13 @@ int hdkeytrail(const crypto_hdkey *hdkey, size_t size, char *out) { len += snprintf(&out[len], size - len, "/*"); break; default: - return -2; + return -1; } + // either an error or an out-of-space if (len < 0 || (size_t)len >= size) { - return -1; + return len; } } - if (len < 0 || (size_t)len >= size) { - return -1; - } return len; } diff --git a/tests/parser.c b/tests/parser.c index 2c7a24d..ccb1ab8 100644 --- a/tests/parser.c +++ b/tests/parser.c @@ -82,23 +82,23 @@ void test_crypto_hdkey_parse_1() { TEST_ASSERT_EQUAL_HEX(0x87, hdkey.key.master.chaincode[0]); TEST_ASSERT_EQUAL_HEX(0x08, hdkey.key.master.chaincode[CRYPTO_HDKEY_CHAINCODE_SIZE - 1]); - uint8_t bip32[78]; - bool ok = hdkey2bip32(&hdkey, bip32); + uint8_t bip32[BIP32_SERIALIZED_LEN]; + bool ok = bip32_serialize(&hdkey, bip32); TEST_ASSERT_TRUE(ok); - uint8_t expected[78] = {0x04, 0x88, 0xad, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x3d, 0xff, + uint8_t expected[] = {0x04, 0x88, 0xad, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x3d, 0xff, 0x81, 0xc0, 0x2f, 0x52, 0x56, 0x23, 0xfd, 0x1f, 0xe5, 0x16, 0x7e, 0xac, 0x3a, 0x55, 0xa0, 0x49, 0xde, 0x3d, 0x31, 0x4b, 0xb4, 0x2e, 0xe2, 0x27, 0xff, 0xed, 0x37, 0xd5, 0x08, 0x00, 0xe8, 0xf3, 0x2e, 0x72, 0x3d, 0xec, 0xf4, 0x05, 0x1a, 0xef, 0xac, 0x8e, 0x2c, 0x93, 0xc9, 0xc5, 0xb2, 0x14, 0x31, 0x38, 0x17, 0xcd, 0xb0, 0x1a, 0x14, 0x94, 0xb9, 0x17, 0xc8, 0x43, 0x6b, 0x35}; - TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, 78); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, BIP32_SERIALIZED_LEN); { char keypath[BUFSIZE]; - int len = hdkey2keypathstr(&hdkey, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(&hdkey, BUFSIZE, (char *)&keypath); TEST_ASSERT_EQUAL(0, len); } { char trailing[BUFSIZE]; - int len = hdkeytrail(&hdkey, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(&hdkey, BUFSIZE, (char *)&trailing); TEST_ASSERT_EQUAL(0, len); } } @@ -157,26 +157,26 @@ void test_crypto_hdkey_parse_2() { TEST_ASSERT_EQUAL(3910671603, hdkey.key.derived.parent_fingerprint); - uint8_t bip32[78]; - bool ok = hdkey2bip32(&hdkey, bip32); + uint8_t bip32[BIP32_SERIALIZED_LEN]; + bool ok = bip32_serialize(&hdkey, bip32); TEST_ASSERT_TRUE(ok); - uint8_t expected[78] = {0x04, 0x35, 0x87, 0xcf, 0x05, 0xe9, 0x18, 0x1c, 0xf3, 0x00, 0x00, 0x00, 0x01, 0xce, 0xd1, 0x55, + uint8_t expected[] = {0x04, 0x35, 0x87, 0xcf, 0x05, 0xe9, 0x18, 0x1c, 0xf3, 0x00, 0x00, 0x00, 0x01, 0xce, 0xd1, 0x55, 0xc7, 0x24, 0x56, 0x25, 0x58, 0x81, 0x79, 0x35, 0x14, 0xed, 0xc5, 0xbd, 0x94, 0x47, 0xe7, 0xf7, 0x4a, 0xbb, 0x88, 0xc6, 0xd6, 0xb6, 0x48, 0x0f, 0xd0, 0x16, 0xee, 0x8c, 0x85, 0x02, 0x6f, 0xe2, 0x35, 0x57, 0x45, 0xbb, 0x2d, 0xb3, 0x63, 0x0b, 0xbc, 0x80, 0xef, 0x5d, 0x58, 0x95, 0x1c, 0x96, 0x3c, 0x84, 0x1f, 0x54, 0x17, 0x0b, 0xa6, 0xe5, 0xc1, 0x2b, 0xe7, 0xfc, 0x12, 0xa6}; - TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, 78); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, BIP32_SERIALIZED_LEN); { char keypath[BUFSIZE]; const char *expected = "[e9181cf3/44'/1'/1'/0/1]"; - int len = hdkey2keypathstr(&hdkey, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(&hdkey, BUFSIZE, (char *)&keypath); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, keypath); } { char trailing[BUFSIZE]; const char *expected = "[e9181cf3/44'/1'/1'/0/1]"; - int len = hdkeytrail(&hdkey, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(&hdkey, BUFSIZE, (char *)&trailing); TEST_ASSERT_EQUAL(0, len); TEST_ASSERT_EQUAL_STRING(expected, trailing); } @@ -279,27 +279,27 @@ void test_crypto_output_parse_4() { TEST_ASSERT_EQUAL(2017537594, key->key.derived.parent_fingerprint); - uint8_t bip32[78]; - bool ok = hdkey2bip32(key, bip32); + uint8_t bip32[BIP32_SERIALIZED_LEN]; + bool ok = bip32_serialize(key, bip32); TEST_ASSERT_TRUE(ok); - uint8_t expected[78] = {0x04, 0x88, 0xb2, 0x1e, 0x04, 0x78, 0x41, 0x2e, 0x3a, 0xff, 0xff, 0xff, 0xfe, 0x63, 0x78, 0x07, + uint8_t expected[] = {0x04, 0x88, 0xb2, 0x1e, 0x04, 0x78, 0x41, 0x2e, 0x3a, 0xff, 0xff, 0xff, 0xfe, 0x63, 0x78, 0x07, 0x03, 0x0d, 0x55, 0xd0, 0x1f, 0x9a, 0x0c, 0xb3, 0xa7, 0x83, 0x95, 0x15, 0xd7, 0x96, 0xbd, 0x07, 0x70, 0x63, 0x86, 0xa6, 0xed, 0xdf, 0x06, 0xcc, 0x29, 0xa6, 0x5a, 0x0e, 0x29, 0x02, 0xd2, 0xb3, 0x69, 0x00, 0x39, 0x6c, 0x92, 0x82, 0xfa, 0x14, 0x62, 0x85, 0x66, 0x58, 0x2f, 0x20, 0x6a, 0x5d, 0xd0, 0xbc, 0xc8, 0xd5, 0xe8, 0x92, 0x61, 0x18, 0x06, 0xca, 0xfb, 0x03, 0x01, 0xf0}; - TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, 78); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, BIP32_SERIALIZED_LEN); { char keypath[BUFSIZE]; const char *expected = "[d34db33f/44'/0'/0']"; - int len = hdkey2keypathstr(key, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(key, BUFSIZE, (char *)&keypath); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, keypath); } { char trailing[BUFSIZE]; const char *expected = "/1/*"; - int len = hdkeytrail(key, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(key, BUFSIZE, (char *)&trailing); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, trailing); } @@ -373,25 +373,25 @@ void test_crypto_account_parse() { TEST_ASSERT_EQUAL(0, key->key.derived.children.components_count); TEST_ASSERT_EQUAL(2583285239, key->key.derived.parent_fingerprint); - uint8_t bip32[78]; - bool ok = hdkey2bip32(key, bip32); + uint8_t bip32[BIP32_SERIALIZED_LEN]; + bool ok = bip32_serialize(key, bip32); TEST_ASSERT_TRUE(ok); - uint8_t expected[78] = {0x04, 0x88, 0xb2, 0x1e, 0x03, 0x99, 0xf9, 0xcd, 0xf7, 0x80, 0x00, 0x00, 0x00, 0x64, 0x56, 0xa5, + uint8_t expected[] = {0x04, 0x88, 0xb2, 0x1e, 0x03, 0x99, 0xf9, 0xcd, 0xf7, 0x80, 0x00, 0x00, 0x00, 0x64, 0x56, 0xa5, 0xdf, 0x2d, 0xb0, 0xf6, 0xd9, 0xaf, 0x72, 0xb2, 0xa1, 0xaf, 0x4b, 0x25, 0xf4, 0x52, 0x00, 0xed, 0x6f, 0xcc, 0x29, 0xc3, 0x44, 0x0b, 0x31, 0x1d, 0x47, 0x96, 0xb7, 0x0b, 0x5b, 0x03, 0xeb, 0x3e, 0x28, 0x63, 0x91, 0x18, 0x26, 0x37, 0x4d, 0xe8, 0x6c, 0x23, 0x1a, 0x4b, 0x76, 0xf0, 0xb8, 0x9d, 0xfa, 0x17, 0x4a, 0xfb, 0x78, 0xd7, 0xf4, 0x78, 0x19, 0x98, 0x84, 0xd9, 0xdd, 0x32}; - TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, 78); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, BIP32_SERIALIZED_LEN); { char keypath[BUFSIZE]; const char *expected = "[37b5eed4/44'/0'/0']"; - int len = hdkey2keypathstr(key, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(key, BUFSIZE, (char *)&keypath); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, keypath); } { char trailing[BUFSIZE]; - int len = hdkeytrail(key, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(key, BUFSIZE, (char *)&trailing); TEST_ASSERT_EQUAL(0, len); } } @@ -421,25 +421,25 @@ void test_crypto_account_parse() { TEST_ASSERT_EQUAL(0, key->key.derived.children.components_count); TEST_ASSERT_EQUAL(2819587291, key->key.derived.parent_fingerprint); - uint8_t bip32[78]; - bool ok = hdkey2bip32(key, bip32); + uint8_t bip32[BIP32_SERIALIZED_LEN]; + bool ok = bip32_serialize(key, bip32); TEST_ASSERT_TRUE(ok); - uint8_t expected[78] = {0x04, 0x88, 0xb2, 0x1e, 0x03, 0xa8, 0x0f, 0x7c, 0xdb, 0x80, 0x00, 0x00, 0x00, 0x9d, 0x2f, 0x86, + uint8_t expected[] = {0x04, 0x88, 0xb2, 0x1e, 0x03, 0xa8, 0x0f, 0x7c, 0xdb, 0x80, 0x00, 0x00, 0x00, 0x9d, 0x2f, 0x86, 0x04, 0x32, 0x76, 0xf9, 0x25, 0x1a, 0x4a, 0x4f, 0x57, 0x71, 0x66, 0xa5, 0xab, 0xeb, 0x16, 0xb6, 0xec, 0x61, 0xe2, 0x26, 0xb5, 0xb8, 0xfa, 0x11, 0x03, 0x8b, 0xfd, 0xa4, 0x2d, 0x02, 0xc7, 0xe4, 0x82, 0x37, 0x30, 0xf6, 0xee, 0x2c, 0xf8, 0x64, 0xe2, 0xc3, 0x52, 0x06, 0x0a, 0x88, 0xe6, 0x0b, 0x51, 0xa8, 0x4e, 0x89, 0xe4, 0xc8, 0xc7, 0x5e, 0xc2, 0x25, 0x90, 0xad, 0x6b, 0x69}; - TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, 78); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, BIP32_SERIALIZED_LEN); { char keypath[BUFSIZE]; const char *expected = "[37b5eed4/49'/0'/0']"; - int len = hdkey2keypathstr(key, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(key, BUFSIZE, (char *)&keypath); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, keypath); } { char trailing[BUFSIZE]; - int len = hdkeytrail(key, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(key, BUFSIZE, (char *)&trailing); TEST_ASSERT_EQUAL(0, len); } } @@ -469,25 +469,25 @@ void test_crypto_account_parse() { TEST_ASSERT_EQUAL(0, key->key.derived.children.components_count); TEST_ASSERT_EQUAL(224256471, key->key.derived.parent_fingerprint); - uint8_t bip32[78]; - bool ok = hdkey2bip32(key, bip32); + uint8_t bip32[BIP32_SERIALIZED_LEN]; + bool ok = bip32_serialize(key, bip32); TEST_ASSERT_TRUE(ok); - uint8_t expected[78] = {0x04, 0x88, 0xb2, 0x1e, 0x03, 0x0d, 0x5d, 0xe1, 0xd7, 0x80, 0x00, 0x00, 0x00, 0x72, 0xed, 0xe7, + uint8_t expected[] = {0x04, 0x88, 0xb2, 0x1e, 0x03, 0x0d, 0x5d, 0xe1, 0xd7, 0x80, 0x00, 0x00, 0x00, 0x72, 0xed, 0xe7, 0x33, 0x4d, 0x5a, 0xcf, 0x91, 0xc6, 0xfd, 0xa6, 0x22, 0xc2, 0x05, 0x19, 0x9c, 0x59, 0x5a, 0x31, 0xf9, 0x21, 0x8e, 0xd3, 0x07, 0x92, 0xd3, 0x01, 0xd5, 0xee, 0x9e, 0x3a, 0x88, 0x03, 0xfd, 0x43, 0x34, 0x50, 0xb6, 0x92, 0x4b, 0x4f, 0x7e, 0xfd, 0xd5, 0xd1, 0xed, 0x01, 0x7d, 0x36, 0x4b, 0xe9, 0x5a, 0xb2, 0xb5, 0x92, 0xdc, 0x8b, 0xdd, 0xb3, 0xb0, 0x0c, 0x1c, 0x24, 0xf6, 0x3f}; - TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, 78); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, BIP32_SERIALIZED_LEN); { char keypath[BUFSIZE]; const char *expected = "[37b5eed4/84'/0'/0']"; - int len = hdkey2keypathstr(key, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(key, BUFSIZE, (char *)&keypath); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, keypath); } { char trailing[BUFSIZE]; - int len = hdkeytrail(key, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(key, BUFSIZE, (char *)&trailing); TEST_ASSERT_EQUAL(0, len); } } @@ -511,26 +511,26 @@ void test_crypto_account_parse() { TEST_ASSERT_EQUAL(0, key->key.derived.children.components_count); TEST_ASSERT_EQUAL(934670036, key->key.derived.parent_fingerprint); - uint8_t bip32[78]; - bool ok = hdkey2bip32(key, bip32); + uint8_t bip32[BIP32_SERIALIZED_LEN]; + bool ok = bip32_serialize(key, bip32); TEST_ASSERT_TRUE(ok); - uint8_t expected[78] = {0x04, 0x88, 0xb2, 0x1e, 0x01, 0x37, 0xb5, 0xee, 0xd4, 0x80, 0x00, 0x00, 0x2d, 0x88, 0xd3, 0x29, + uint8_t expected[] = {0x04, 0x88, 0xb2, 0x1e, 0x01, 0x37, 0xb5, 0xee, 0xd4, 0x80, 0x00, 0x00, 0x2d, 0x88, 0xd3, 0x29, 0x9b, 0x44, 0x8f, 0x87, 0x21, 0x5d, 0x96, 0xb0, 0xc2, 0x26, 0x23, 0x5a, 0xfc, 0x02, 0x7f, 0x9e, 0x7d, 0xc7, 0x00, 0x28, 0x4f, 0x3e, 0x91, 0x2a, 0x34, 0xda, 0xeb, 0x1a, 0x23, 0x03, 0x5c, 0xcd, 0x58, 0xb6, 0x3a, 0x2c, 0xdc, 0x23, 0xd0, 0x81, 0x27, 0x10, 0x60, 0x35, 0x92, 0xe7, 0x45, 0x75, 0x73, 0x21, 0x18, 0x80, 0xcb, 0x59, 0xb1, 0xef, 0x01, 0x2e, 0x16, 0x8e, 0x05, 0x9a}; - TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, 78); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, BIP32_SERIALIZED_LEN); { char keypath[BUFSIZE]; const char *expected = "[37b5eed4/45']"; - int len = hdkey2keypathstr(key, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(key, BUFSIZE, (char *)&keypath); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, keypath); } { char trailing[BUFSIZE]; - int len = hdkeytrail(key, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(key, BUFSIZE, (char *)&trailing); TEST_ASSERT_EQUAL(0, len); } } @@ -563,26 +563,26 @@ void test_crypto_account_parse() { TEST_ASSERT_EQUAL(0, key->key.derived.children.components_count); TEST_ASSERT_EQUAL(1505139498, key->key.derived.parent_fingerprint); - uint8_t bip32[78]; - bool ok = hdkey2bip32(key, bip32); + uint8_t bip32[BIP32_SERIALIZED_LEN]; + bool ok = bip32_serialize(key, bip32); TEST_ASSERT_TRUE(ok); - uint8_t expected[78] = {0x04, 0x88, 0xb2, 0x1e, 0x04, 0x59, 0xb6, 0x9b, 0x2a, 0x80, 0x00, 0x00, 0x01, 0x79, 0x53, 0xef, + uint8_t expected[] = {0x04, 0x88, 0xb2, 0x1e, 0x04, 0x59, 0xb6, 0x9b, 0x2a, 0x80, 0x00, 0x00, 0x01, 0x79, 0x53, 0xef, 0xe1, 0x6a, 0x73, 0xe5, 0xd3, 0xf9, 0xf2, 0xd4, 0xc6, 0xe4, 0x9b, 0xd8, 0x8e, 0x22, 0x09, 0x3b, 0xbd, 0x85, 0xbe, 0x5a, 0x7e, 0x86, 0x2a, 0x4b, 0x98, 0xa1, 0x6e, 0x0a, 0xb6, 0x03, 0x2c, 0x78, 0xeb, 0xfc, 0xab, 0xda, 0xc6, 0xd7, 0x35, 0xa0, 0x82, 0x0e, 0xf8, 0x73, 0x2f, 0x28, 0x21, 0xb4, 0xfb, 0x84, 0xcd, 0x5d, 0x6b, 0x26, 0x52, 0x69, 0x38, 0xf9, 0x0c, 0x05, 0x07, 0x11}; - TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, 78); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, BIP32_SERIALIZED_LEN); { char keypath[BUFSIZE]; const char *expected = "[37b5eed4/48'/0'/0'/1']"; - int len = hdkey2keypathstr(key, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(key, BUFSIZE, (char *)&keypath); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, keypath); } { char trailing[BUFSIZE]; - int len = hdkeytrail(key, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(key, BUFSIZE, (char *)&trailing); TEST_ASSERT_EQUAL(0, len); } } @@ -615,25 +615,25 @@ void test_crypto_account_parse() { TEST_ASSERT_EQUAL(0, key->key.derived.children.components_count); TEST_ASSERT_EQUAL(1505139498, key->key.derived.parent_fingerprint); - uint8_t bip32[78]; - bool ok = hdkey2bip32(key, bip32); + uint8_t bip32[BIP32_SERIALIZED_LEN]; + bool ok = bip32_serialize(key, bip32); TEST_ASSERT_TRUE(ok); - uint8_t expected[78] = {0x04, 0x88, 0xb2, 0x1e, 0x04, 0x59, 0xb6, 0x9b, 0x2a, 0x80, 0x00, 0x00, 0x02, 0x2f, 0xa0, 0xe4, + uint8_t expected[] = {0x04, 0x88, 0xb2, 0x1e, 0x04, 0x59, 0xb6, 0x9b, 0x2a, 0x80, 0x00, 0x00, 0x02, 0x2f, 0xa0, 0xe4, 0x1c, 0x9d, 0xc4, 0x3d, 0xc4, 0x51, 0x86, 0x59, 0xbf, 0xce, 0xf9, 0x35, 0xba, 0x81, 0x01, 0xb5, 0x7d, 0xbc, 0x08, 0x12, 0x80, 0x5d, 0xd9, 0x83, 0xbc, 0x1d, 0x34, 0xb8, 0x13, 0x02, 0x60, 0x56, 0x3e, 0xe8, 0x0c, 0x26, 0x84, 0x46, 0x21, 0xb0, 0x6b, 0x74, 0x07, 0x0b, 0xaf, 0x0e, 0x23, 0xfb, 0x76, 0xce, 0x43, 0x9d, 0x02, 0x37, 0xe8, 0x75, 0x02, 0xeb, 0xbd, 0x3c, 0xa3, 0x46}; - TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, 78); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, bip32, BIP32_SERIALIZED_LEN); { char keypath[BUFSIZE]; const char *expected = "[37b5eed4/48'/0'/0'/2']"; - int len = hdkey2keypathstr(key, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(key, BUFSIZE, (char *)&keypath); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, keypath); } { char trailing[BUFSIZE]; - int len = hdkeytrail(key, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(key, BUFSIZE, (char *)&trailing); TEST_ASSERT_EQUAL(0, len); } } @@ -681,13 +681,13 @@ void test_crypto_jadeaccount_parse() { { char keypath[BUFSIZE]; const char *expected = "[b6215d6b/84'/0'/0']"; - int len = hdkey2keypathstr(key, BUFSIZE, (char *)&keypath); + int len = format_keyorigin(key, BUFSIZE, (char *)&keypath); TEST_ASSERT_GREATER_THAN_INT(0, len); TEST_ASSERT_EQUAL_STRING(expected, keypath); } { char trailing[BUFSIZE]; - int len = hdkeytrail(key, BUFSIZE, (char *)&trailing); + int len = format_keyderivationpath(key, BUFSIZE, (char *)&trailing); TEST_ASSERT_EQUAL(0, len); } }