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

Function bitcoin_key

hsmd/libhsmd.c:417–444  ·  view source on GitHub ↗

~ Get the keys for this given BIP32 index: if privkey is NULL, we * don't fill it in. */

Source from the content-addressed store, hash-verified

415/*~ Get the keys for this given BIP32 index: if privkey is NULL, we
416 * don't fill it in. */
417static void bitcoin_key(struct privkey *privkey, struct pubkey *pubkey,
418 u32 index)
419{
420 struct ext_key ext;
421 struct privkey unused_priv;
422
423 if (privkey == NULL)
424 privkey = &unused_priv;
425
426 if (index >= BIP32_INITIAL_HARDENED_CHILD)
427 hsmd_status_failed(STATUS_FAIL_MASTER_IO, "Index %u too great",
428 index);
429
430 /*~ This uses libwally, which doesn't dovetail directly with
431 * libsecp256k1 even though it, too, uses it internally. */
432 if (bip32_key_from_parent(&secretstuff.bip32, index,
433 BIP32_FLAG_KEY_PRIVATE, &ext) != WALLY_OK)
434 hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR,
435 "BIP32 of %u failed", index);
436
437 /* libwally says: The private key with prefix byte 0; remove it
438 * for libsecp256k1. */
439 memcpy(privkey->secret.data, ext.priv_key+1, 32);
440 if (!secp256k1_ec_pubkey_create(secp256k1_ctx, &pubkey->pubkey,
441 privkey->secret.data))
442 hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR,
443 "BIP32 pubkey %u create failed", index);
444}
445
446/* This gets the bitcoin private key needed to spend from our wallet */
447static void hsm_key_for_utxo(struct privkey *privkey, struct pubkey *pubkey,

Callers 1

hsm_key_for_utxoFunction · 0.85

Calls 1

hsmd_status_failedFunction · 0.70

Tested by

no test coverage detected