| 270 | } |
| 271 | |
| 272 | static void print_secret(const char *hsm_secret_path, const char *id, bool must_be_oldstyle) |
| 273 | { |
| 274 | struct secret hsm_secret; |
| 275 | char *bip93; |
| 276 | const char *err; |
| 277 | struct hsm_secret *hsms = load_hsm_secret(tmpctx, hsm_secret_path); |
| 278 | |
| 279 | switch (hsms->type) { |
| 280 | case HSM_SECRET_ENCRYPTED: |
| 281 | errx(ERROR_USAGE, "Encrypted hsm_secret"); |
| 282 | case HSM_SECRET_MNEMONIC_NO_PASS: |
| 283 | if (must_be_oldstyle) |
| 284 | errx(ERROR_USAGE, "Cannot use getcodexsecret with modern nodes: use getsecret"); |
| 285 | printf("%s\n", hsms->mnemonic); |
| 286 | return; |
| 287 | case HSM_SECRET_MNEMONIC_WITH_PASS: |
| 288 | errx(ERROR_USAGE, "hsm_secret with passphrase"); |
| 289 | case HSM_SECRET_PLAIN: |
| 290 | if (id == NULL) |
| 291 | errx(ERROR_USAGE, "Must set 'id' for a codex32 secret"); |
| 292 | /* Extract first 32 bytes for legacy compatibility */ |
| 293 | memcpy(hsm_secret.data, hsms->secret_data, 32); |
| 294 | |
| 295 | err = codex32_secret_encode(tmpctx, "cl", id, 0, hsm_secret.data, 32, &bip93); |
| 296 | if (err) |
| 297 | errx(ERROR_USAGE, "%s", err); |
| 298 | |
| 299 | printf("%s\n", bip93); |
| 300 | return; |
| 301 | case HSM_SECRET_INVALID: |
| 302 | break; |
| 303 | } |
| 304 | /* Never happens. */ |
| 305 | abort(); |
| 306 | } |
| 307 | |
| 308 | static void print_emergencyrecover(const char *emer_rec_path) |
| 309 | { |
no test coverage detected