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

Function bolt11_decode_nosig

common/bolt11.c:748–975  ·  view source on GitHub ↗

Extracts signature but does not check it. */

Source from the content-addressed store, hash-verified

746
747/* Extracts signature but does not check it. */
748struct 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);

Callers 4

json_createinvoiceFunction · 0.85
json_signinvoiceFunction · 0.85
bolt11_decodeFunction · 0.85
fetch_out_desc_invstrFunction · 0.85

Calls 12

new_bolt11Function · 0.85
decode_failFunction · 0.85
bech32_decode_allocFunction · 0.85
hash_u5_initFunction · 0.85
pull_uintFunction · 0.85
find_decoderFunction · 0.85
hash_u5_doneFunction · 0.85
amount_msatClass · 0.70
unknown_fieldFunction · 0.70
sha256Class · 0.70
decodeMethod · 0.45

Tested by

no test coverage detected