MCPcopy Create free account
hub / github.com/ElementsProject/lightning / bip86_key

Function bip86_key

hsmd/libhsmd.c:2390–2421  ·  view source on GitHub ↗

~ Get the BIP86 keys for this given index: if privkey is NULL, we * don't fill it in. This derives the full path: m/86'/0'/0'/0/index */

Source from the content-addressed store, hash-verified

2388/*~ Get the BIP86 keys for this given index: if privkey is NULL, we
2389 * don't fill it in. This derives the full path: m/86'/0'/0'/0/index */
2390void bip86_key(struct privkey *privkey, struct pubkey *pubkey, u32 index)
2391{
2392 struct privkey unused_priv;
2393
2394 if (privkey == NULL)
2395 privkey = &unused_priv;
2396
2397 if (index >= BIP32_INITIAL_HARDENED_CHILD)
2398 hsmd_status_failed(STATUS_FAIL_MASTER_IO, "Index %u too great", index);
2399
2400 /* Derive the BIP86 base key using the helper function */
2401 struct ext_key bip86_base;
2402 derive_bip86_base_key(&bip86_base);
2403
2404 /* Now derive the specific index: m/86'/0'/0'/0/index */
2405 u32 final_path[2];
2406 final_path[0] = 0; /* change (0 for receive) */
2407 final_path[1] = index; /* address_index */
2408
2409 struct ext_key final_key;
2410 if (bip32_key_from_parent_path(&bip86_base, final_path, 2, BIP32_FLAG_KEY_PRIVATE, &final_key) != WALLY_OK) {
2411 hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR,
2412 "BIP86 derivation of index %u failed", index);
2413 }
2414
2415 /* Convert to our format */
2416 memcpy(privkey->secret.data, final_key.priv_key+1, 32);
2417 if (!secp256k1_ec_pubkey_create(secp256k1_ctx, &pubkey->pubkey,
2418 privkey->secret.data))
2419 hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR,
2420 "BIP86 pubkey %u create failed", index);
2421}
2422
2423u8 *hsmd_init(const u8 *secret_data, size_t secret_len, const u64 hsmd_version,
2424 struct bip32_key_version bip32_key_version, u8 hsm_secret_type)

Callers 3

hsm_key_for_utxoFunction · 0.85

Calls 2

derive_bip86_base_keyFunction · 0.85
hsmd_status_failedFunction · 0.70

Tested by

no test coverage detected