Extracts signature but does not check it. */
| 746 | |
| 747 | /* Extracts signature but does not check it. */ |
| 748 | struct bolt11 *bolt11_decode_nosig(const tal_t *ctx, const char *str, |
| 749 | const struct feature_set *our_features, |
| 750 | const char *description, |
| 751 | const struct chainparams *must_be_chain, |
| 752 | struct sha256 *hash, |
| 753 | const u5 **sig, |
| 754 | bool *have_n, |
| 755 | const char **fail) |
| 756 | { |
| 757 | const char *hrp, *prefix; |
| 758 | char *amountstr; |
| 759 | const u5 *data; |
| 760 | size_t data_len; |
| 761 | struct bolt11 *b11 = new_bolt11(ctx, NULL); |
| 762 | struct hash_u5 hu5; |
| 763 | const char *err; |
| 764 | /* We don't need all of these, but in theory we could have 32 types */ |
| 765 | bool have_field[32]; |
| 766 | |
| 767 | memset(have_field, 0, sizeof(have_field)); |
| 768 | b11->routes = tal_arr(b11, struct route_info *, 0); |
| 769 | |
| 770 | if (strlen(str) < 8) |
| 771 | return decode_fail(b11, fail, "Bad bech32 string"); |
| 772 | |
| 773 | if (!bech32_decode_alloc(tmpctx, &hrp, &data, &data_len, str)) |
| 774 | return decode_fail(b11, fail, "Bad bech32 string"); |
| 775 | |
| 776 | /* For signature checking at the end. */ |
| 777 | hash_u5_init(&hu5, hrp); |
| 778 | |
| 779 | /* BOLT #11: |
| 780 | * |
| 781 | * The human-readable part of a Lightning invoice consists of two sections: |
| 782 | * 1. `prefix`: `ln` + BIP-0173 currency prefix (e.g. `lnbc` for Bitcoin mainnet, |
| 783 | * `lntb` for Bitcoin testnet, `lntbs` for Bitcoin signet, and `lnbcrt` for Bitcoin regtest) |
| 784 | * 1. `amount`: optional number in that currency, followed by an optional |
| 785 | * `multiplier` letter. The unit encoded here is the 'social' convention of a payment unit -- in the case of Bitcoin the unit is 'bitcoin' NOT satoshis. |
| 786 | */ |
| 787 | prefix = tal_strndup(tmpctx, hrp, strcspn(hrp, "0123456789")); |
| 788 | |
| 789 | /* BOLT #11: |
| 790 | * |
| 791 | * A reader...if it does NOT understand the `prefix`... MUST fail the payment. |
| 792 | */ |
| 793 | if (!strstarts(prefix, "ln")) |
| 794 | return decode_fail(b11, fail, |
| 795 | "Prefix '%s' does not start with ln", prefix); |
| 796 | |
| 797 | if (must_be_chain) { |
| 798 | if (streq(prefix + 2, must_be_chain->lightning_hrp)) |
| 799 | b11->chain = must_be_chain; |
| 800 | else |
| 801 | return decode_fail(b11, fail, "Prefix %s is not for %s", |
| 802 | prefix + 2, |
| 803 | must_be_chain->network_name); |
| 804 | } else { |
| 805 | b11->chain = chainparams_by_lightning_hrp(prefix + 2); |
no test coverage detected