|
8 | 8 | #include "storage.h" |
9 | 9 | #include "utils/malloc_ext.h" |
10 | 10 | #include "utils/network.h" |
| 11 | +#include "wallet.h" |
11 | 12 |
|
12 | 13 | #include <sodium/crypto_verify_32.h> |
13 | 14 | #include <string.h> |
|
20 | 21 | // Encrypted length plus hmac (input length given) |
21 | 22 | #define ENCRYPTED_DATA_LEN(len) (AES_ENCRYPTED_LEN(len) + HMAC_SHA256_LEN) |
22 | 23 |
|
23 | | -// GA derived key index, and fixed GA key message |
24 | | -static const uint32_t GA_PATH_ROOT = BIP32_INITIAL_HARDENED_CHILD + 0x4741; |
25 | | -static const uint8_t GA_KEY_MSG[] = "GreenAddress.it HD wallet path"; |
26 | | - |
27 | 24 | // Internal variables - the single/global keychain data |
28 | 25 | static keychain_t* keychain_data = NULL; |
29 | 26 | static network_type_t network_type_restriction = NETWORK_TYPE_NONE; |
@@ -245,31 +242,6 @@ bool keychain_is_network_type_consistent(const char* network) |
245 | 242 | return network_type_restriction == NETWORK_TYPE_NONE || network_type == network_type_restriction; |
246 | 243 | } |
247 | 244 |
|
248 | | -// Helper to create the service/gait path. |
249 | | -// (The below is correct for newly created wallets, verified in regtest). |
250 | | -static void populate_service_path(keychain_t* keydata) |
251 | | -{ |
252 | | - JADE_ASSERT(keydata); |
253 | | - |
254 | | - // 1. Derive a child of our private key using the fixed GA index |
255 | | - struct ext_key derived; |
256 | | - SENSITIVE_PUSH(&derived, sizeof(derived)); |
257 | | - JADE_WALLY_VERIFY(bip32_key_from_parent_path( |
258 | | - &keydata->xpriv, &GA_PATH_ROOT, 1, BIP32_FLAG_KEY_PRIVATE | BIP32_FLAG_SKIP_HASH, &derived)); |
259 | | - |
260 | | - // 2. Get it as an 'extended public key' byte-array |
261 | | - uint8_t extkeydata[sizeof(derived.chain_code) + sizeof(derived.pub_key)]; |
262 | | - SENSITIVE_PUSH(extkeydata, sizeof(extkeydata)); |
263 | | - memcpy(extkeydata, derived.chain_code, sizeof(derived.chain_code)); |
264 | | - memcpy(extkeydata + sizeof(derived.chain_code), derived.pub_key, sizeof(derived.pub_key)); |
265 | | - |
266 | | - // 3. HMAC the fixed GA key message with 2. to yield the 512-bit 'service path' for this mnemonic/private key |
267 | | - JADE_WALLY_VERIFY(wally_hmac_sha512(GA_KEY_MSG, sizeof(GA_KEY_MSG), extkeydata, sizeof(extkeydata), |
268 | | - keydata->service_path, sizeof(keydata->service_path))); |
269 | | - SENSITIVE_POP(extkeydata); |
270 | | - SENSITIVE_POP(&derived); |
271 | | -} |
272 | | - |
273 | 245 | void keychain_get_new_mnemonic(char** mnemonic, const size_t nwords) |
274 | 246 | { |
275 | 247 | JADE_INIT_OUT_PPTR(mnemonic); |
@@ -311,7 +283,7 @@ void keychain_derive_from_seed(const uint8_t* seed, const size_t seed_len, keych |
311 | 283 | wally_asset_blinding_key_from_seed(seed, seed_len, keydata->master_unblinding_key, HMAC_SHA512_LEN)); |
312 | 284 |
|
313 | 285 | // Compute and cache the path the GA server will use to sign |
314 | | - populate_service_path(keydata); |
| 286 | + wallet_calculate_gaservice_path(&keydata->xpriv, keydata->service_path, sizeof(keydata->service_path)); |
315 | 287 | } |
316 | 288 |
|
317 | 289 | // Derive master key from mnemonic if passed a valid mnemonic |
|
0 commit comments