| 350 | } |
| 351 | |
| 352 | static void guess_to_remote(const char *address, struct node_id *node_id, |
| 353 | u64 tries, char *hsm_secret_path) |
| 354 | { |
| 355 | struct secret hsm_secret, channel_seed, basepoint_secret; |
| 356 | struct pubkey basepoint; |
| 357 | struct ripemd160 pubkeyhash; |
| 358 | u8 goal_pubkeyhash[20]; |
| 359 | char hrp[strlen(address) - 6]; |
| 360 | int witver; |
| 361 | size_t witlen; |
| 362 | |
| 363 | /* Get the hrp to accept addresses from any network. */ |
| 364 | if (bech32_decode(hrp, goal_pubkeyhash, &witlen, address, 90) != BECH32_ENCODING_BECH32) |
| 365 | errx(ERROR_USAGE, "Could not get address' network"); |
| 366 | if (segwit_addr_decode(&witver, goal_pubkeyhash, &witlen, hrp, address) != 1) |
| 367 | errx(ERROR_USAGE, "Wrong bech32 address"); |
| 368 | |
| 369 | struct hsm_secret *hsms = load_hsm_secret(tmpctx, hsm_secret_path); |
| 370 | memcpy(hsm_secret.data, hsms->secret_data, 32); |
| 371 | |
| 372 | for (u64 dbid = 1; dbid < tries ; dbid++) { |
| 373 | get_channel_seed(&channel_seed, node_id, dbid, &hsm_secret); |
| 374 | if (!derive_payment_basepoint(&channel_seed, |
| 375 | &basepoint, &basepoint_secret)) |
| 376 | errx(ERROR_KEYDERIV, "Could not derive basepoints for dbid %"PRIu64 |
| 377 | " and channel seed %s.", dbid, |
| 378 | fmt_secret(tmpctx, &channel_seed)); |
| 379 | |
| 380 | pubkey_to_hash160(&basepoint, &pubkeyhash); |
| 381 | if (memcmp(pubkeyhash.u.u8, goal_pubkeyhash, 20) == 0) { |
| 382 | printf("bech32 : %s\n", address); |
| 383 | printf("pubkey hash : %s\n", |
| 384 | tal_hexstr(tmpctx, pubkeyhash.u.u8, 20)); |
| 385 | printf("pubkey : %s \n", |
| 386 | fmt_pubkey(tmpctx, &basepoint)); |
| 387 | printf("privkey : %s \n", |
| 388 | fmt_secret(tmpctx, &basepoint_secret)); |
| 389 | return; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | errx(ERROR_USAGE, "Could not find any basepoint matching the provided witness programm.\n" |
| 394 | "Are you sure that the channel used `option_static_remotekey` ?"); |
| 395 | } |
| 396 | |
| 397 | static void generate_hsm(const char *hsm_secret_path) |
| 398 | { |
no test coverage detected