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

Function bolt11_decode_nosig

common/bolt11.c:592–843  ·  view source on GitHub ↗

Extracts signature but does not check it. */

Source from the content-addressed store, hash-verified

590
591/* Extracts signature but does not check it. */
592struct bolt11 *bolt11_decode_nosig(const tal_t *ctx, const char *str,
593 const struct feature_set *our_features,
594 const char *description,
595 const struct chainparams *must_be_chain,
596 struct sha256 *hash,
597 u5 **sig,
598 bool *have_n,
599 char **fail)
600{
601 char *hrp, *amountstr, *prefix;
602 u5 *data;
603 size_t data_len;
604 struct bolt11 *b11 = new_bolt11(ctx, NULL);
605 struct hash_u5 hu5;
606 bool have_p = false, have_d = false, have_h = false,
607 have_x = false, have_c = false, have_s = false, have_m = false;
608
609 *have_n = false;
610 b11->routes = tal_arr(b11, struct route_info *, 0);
611
612 /* BOLT #11:
613 *
614 * If a URI scheme is desired, the current recommendation is to either
615 * use 'lightning:' as a prefix before the BOLT-11 encoding
616 */
617 if (strstarts(str, "lightning:") || strstarts(str, "LIGHTNING:"))
618 str += strlen("lightning:");
619
620 if (strlen(str) < 8)
621 return decode_fail(b11, fail, "Bad bech32 string");
622
623 hrp = tal_arr(tmpctx, char, strlen(str) - 6);
624 data = tal_arr(tmpctx, u5, strlen(str) - 8);
625
626 if (bech32_decode(hrp, data, &data_len, str, (size_t)-1)
627 != BECH32_ENCODING_BECH32)
628 return decode_fail(b11, fail, "Bad bech32 string");
629
630 /* For signature checking at the end. */
631 hash_u5_init(&hu5, hrp);
632
633 /* BOLT #11:
634 *
635 * The human-readable part of a Lightning invoice consists of two sections:
636 * 1. `prefix`: `ln` + BIP-0173 currency prefix (e.g. `lnbc` for Bitcoin mainnet,
637 * `lntb` for Bitcoin testnet, `lntbs` for Bitcoin signet, and `lnbcrt` for Bitcoin regtest)
638 * 1. `amount`: optional number in that currency, followed by an optional
639 * `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.
640 */
641 prefix = tal_strndup(tmpctx, hrp, strcspn(hrp, "0123456789"));
642
643 /* BOLT #11:
644 *
645 * A reader...if it does NOT understand the `prefix`... MUST fail the payment.
646 */
647 if (!strstarts(prefix, "ln"))
648 return decode_fail(b11, fail,
649 "Prefix '%s' does not start with ln", prefix);

Callers 2

bolt11_decodeFunction · 0.70
fetch_out_desc_invstrFunction · 0.50

Calls 15

decode_failFunction · 0.85
hash_u5_initFunction · 0.85
pull_uintFunction · 0.85
decode_pFunction · 0.85
decode_dFunction · 0.85
decode_hFunction · 0.85
decode_nFunction · 0.85
decode_xFunction · 0.85
decode_cFunction · 0.85
decode_fFunction · 0.85
decode_rFunction · 0.85

Tested by

no test coverage detected