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

Function hsmd_init

hsmd/libhsmd.c:2423–2595  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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)
2425{
2426 u8 bip32_seed[BIP32_ENTROPY_LEN_256];
2427 struct pubkey key, bolt12;
2428 u32 salt = 0;
2429 struct ext_key master_extkey, child_extkey;
2430 struct node_id node_id;
2431 static const u32 capabilities[] = {
2432 WIRE_HSMD_CHECK_PUBKEY,
2433 WIRE_HSMD_CHECK_BIP86_PUBKEY,
2434 WIRE_HSMD_SIGN_ANY_DELAYED_PAYMENT_TO_US,
2435 WIRE_HSMD_SIGN_ANCHORSPEND,
2436 WIRE_HSMD_SIGN_HTLC_TX_MINGLE,
2437 WIRE_HSMD_SIGN_SPLICE_TX,
2438 WIRE_HSMD_CHECK_OUTPOINT,
2439 WIRE_HSMD_FORGET_CHANNEL,
2440 WIRE_HSMD_REVOKE_COMMITMENT_TX,
2441 WIRE_HSMD_SIGN_BOLT12_2,
2442 WIRE_HSMD_BIP137_SIGN_MESSAGE,
2443 };
2444 u32 *caps;
2445
2446 /*~ Store the BIP32 key version for network compatibility */
2447 network_bip32_key_version = bip32_key_version;
2448
2449 /*~ Store the secret (32 or 64 bytes) - use NULL context for persistence */
2450 secretstuff.bip32_seed = notleak(tal_dup_arr(NULL, u8, secret_data, secret_len, 0));
2451 mlock_tal_memory(secretstuff.bip32_seed);
2452
2453 assert(bip32_key_version.bip32_pubkey_version == BIP32_VER_MAIN_PUBLIC
2454 || bip32_key_version.bip32_pubkey_version == BIP32_VER_TEST_PUBLIC);
2455
2456 assert(bip32_key_version.bip32_privkey_version == BIP32_VER_MAIN_PRIVATE
2457 || bip32_key_version.bip32_privkey_version == BIP32_VER_TEST_PRIVATE);
2458
2459 /* Fill in the BIP32 tree for bitcoin addresses. */
2460 /* In libwally-core, the version BIP32_VER_TEST_PRIVATE is for testnet/regtest,
2461 * and BIP32_VER_MAIN_PRIVATE is for mainnet. */
2462 do {
2463 hkdf_sha256(bip32_seed, sizeof(bip32_seed),
2464 &salt, sizeof(salt),
2465 secretstuff.bip32_seed,
2466 tal_bytelen(secretstuff.bip32_seed),
2467 "bip32 seed", strlen("bip32 seed"));
2468 salt++;
2469 } while (bip32_key_from_seed(bip32_seed, sizeof(bip32_seed),
2470 bip32_key_version.bip32_privkey_version,
2471 0, &master_extkey) != WALLY_OK);
2472
2473 /* In --developer mode, we can override with --dev-force-bip32-seed */
2474 if (dev_force_bip32_seed) {
2475 if (bip32_key_from_seed(dev_force_bip32_seed->data,
2476 sizeof(dev_force_bip32_seed->data),
2477 bip32_key_version.bip32_privkey_version,
2478 0, &master_extkey) != WALLY_OK)
2479 hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR,
2480 "Can't derive bip32 master key");

Callers 1

init_hsmFunction · 0.85

Calls 8

mlock_tal_memoryFunction · 0.85
hkdf_sha256Function · 0.85
tal_bytelenFunction · 0.85
node_id_from_pubkeyFunction · 0.85
use_bip86_derivationFunction · 0.85
derive_bip86_base_keyFunction · 0.85
hsmd_status_failedFunction · 0.70
node_keyFunction · 0.70

Tested by

no test coverage detected