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

Function hsm_init

lightningd/hsm_control.c:82–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82struct ext_key *hsm_init(struct lightningd *ld)
83{
84 u8 *msg;
85 int fds[2];
86 struct ext_key *bip32_base;
87 u32 hsm_version;
88 struct pubkey unused;
89
90 /* We actually send requests synchronously: only status is async. */
91 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0)
92 err(EXITCODE_HSM_GENERIC_ERROR, "Could not create hsm socketpair");
93
94 ld->hsm = new_global_subd(ld, "lightning_hsmd",
95 hsmd_wire_name,
96 hsm_msg,
97 take(&fds[1]), NULL);
98 if (!ld->hsm)
99 err(EXITCODE_HSM_GENERIC_ERROR, "Could not subd hsm");
100
101 ld->hsm_fd = fds[0];
102
103 if (ld->developer) {
104 struct tlv_hsmd_dev_preinit_tlvs *tlv;
105
106 tlv = tlv_hsmd_dev_preinit_tlvs_new(tmpctx);
107 tlv->fail_preapprove = tal_dup(tlv, bool,
108 &ld->dev_hsmd_fail_preapprove);
109 tlv->no_preapprove_check = tal_dup(tlv, bool,
110 &ld->dev_hsmd_no_preapprove_check);
111 tlv->warn_on_overgrind = tal_dup(tlv, bool,
112 &ld->dev_hsmd_warn_on_overgrind);
113
114 msg = towire_hsmd_dev_preinit(tmpctx, tlv);
115 if (!wire_sync_write(ld->hsm_fd, msg))
116 err(EXITCODE_HSM_GENERIC_ERROR, "Writing preinit msg to hsm");
117 }
118
119 /* Create TLV for passphrase if needed */
120 struct tlv_hsmd_init_tlvs *tlv = NULL;
121 if (ld->hsm_passphrase) {
122 tlv = tlv_hsmd_init_tlvs_new(tmpctx);
123 tlv->hsm_passphrase = tal_strdup(tlv, ld->hsm_passphrase);
124 }
125
126 if (!wire_sync_write(ld->hsm_fd, towire_hsmd_init(tmpctx,
127 &chainparams->bip32_key_version,
128 chainparams,
129 NULL,
130 ld->dev_force_privkey,
131 ld->dev_force_bip32_seed,
132 ld->dev_force_channel_secrets,
133 ld->dev_force_channel_secrets_shaseed,
134 HSM_MIN_VERSION,
135 HSM_MAX_VERSION,
136 tlv)))
137 err(EXITCODE_HSM_GENERIC_ERROR, "Writing init msg to hsm");
138
139 bip32_base = tal(ld, struct ext_key);

Callers 1

mainFunction · 0.70

Calls 15

errFunction · 0.85
towire_hsmd_dev_preinitFunction · 0.85
tlv_hsmd_init_tlvs_newFunction · 0.85
towire_hsmd_initFunction · 0.85
errxFunction · 0.85
fmt_node_idFunction · 0.85
hsmd_wire_nameFunction · 0.85
log_infoClass · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected