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

Function print_node_id

tools/lightning-hsmtool.c:640–666  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

638}
639
640static void print_node_id(const char *hsm_secret_path)
641{
642 u32 salt = 0;
643 struct secret hsm_secret;
644 struct privkey node_privkey;
645 struct pubkey node_id;
646 struct hsm_secret *hsms = load_hsm_secret(tmpctx, hsm_secret_path);
647 /* Extract first 32 bytes for legacy compatibility */
648 memcpy(hsm_secret.data, hsms->secret_data, 32);
649
650 /*~ So, there is apparently a 1 in 2^127 chance that a random value is
651 * not a valid private key, so this never actually loops. */
652 do {
653 /*~ ccan/crypto/hkdf_sha256 implements RFC5869 "Hardened Key
654 * Derivation Functions". That means that if a derived key
655 * leaks somehow, the other keys are not compromised. */
656 hkdf_sha256(&node_privkey, sizeof(node_privkey),
657 &salt, sizeof(salt),
658 &hsm_secret,
659 sizeof(hsm_secret),
660 "nodeid", 6);
661 salt++;
662 } while (!secp256k1_ec_pubkey_create(secp256k1_ctx, &node_id.pubkey,
663 node_privkey.secret.data));
664
665 printf("%s\n", fmt_pubkey(tmpctx, &node_id));
666}
667
668int main(int argc, char *argv[])
669{

Callers 1

mainFunction · 0.70

Calls 3

load_hsm_secretFunction · 0.85
hkdf_sha256Function · 0.85
fmt_pubkeyFunction · 0.85

Tested by

no test coverage detected