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

Function bolt11_decode

common/bolt11.c:980–1062  ·  view source on GitHub ↗

Decodes and checks signature; returns NULL on error. */

Source from the content-addressed store, hash-verified

978
979/* Decodes and checks signature; returns NULL on error. */
980struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
981 const struct feature_set *our_features,
982 const char *description,
983 const struct chainparams *must_be_chain,
984 const char **fail)
985{
986 const u5 *sigdata;
987 size_t data_len;
988 u8 sig_and_recid[65];
989 secp256k1_ecdsa_recoverable_signature sig;
990 struct bolt11 *b11;
991 struct sha256 hash;
992 bool have_n;
993 const char *err;
994
995 b11 = bolt11_decode_nosig(ctx, str, our_features, description,
996 must_be_chain, &hash, &sigdata, &have_n,
997 fail);
998 if (!b11)
999 return NULL;
1000
1001 /* BOLT #11:
1002 *
1003 * A writer...MUST set `signature` to a valid
1004 * compact ECDSA signature over secp256k1 of the SHA-256 hash of:
1005 * the human-readable part (as UTF-8 bytes) concatenated with the data part
1006 * (excluding the signature), with 0 bits appended to pad to a byte boundary.
1007 * The signature is encoded as 64 bytes (R || S), followed by a trailing 1-byte
1008 * recovery id in {0,1,2,3}.
1009 */
1010 data_len = tal_count(sigdata);
1011 err = pull_bits(NULL, &sigdata, &data_len, sig_and_recid, 520, false);
1012 if (err)
1013 return decode_fail(b11, fail, "can't read signature: %s",
1014 err);
1015
1016 assert(data_len == 0);
1017
1018 if (!valid_recovery_id(sig_and_recid[64]))
1019 return decode_fail(b11, fail, "invalid recovery ID: %u",
1020 sig_and_recid[64]);
1021
1022 if (!secp256k1_ecdsa_recoverable_signature_parse_compact
1023 (secp256k1_ctx, &sig, sig_and_recid, sig_and_recid[64]))
1024 return decode_fail(b11, fail, "signature invalid");
1025
1026 secp256k1_ecdsa_recoverable_signature_convert(secp256k1_ctx,
1027 &b11->sig, &sig);
1028
1029 /* BOLT #11:
1030 *
1031 * A reader:
1032 * - MUST check that the `signature` is valid (see the `n` tagged field specified below).
1033 */
1034 /* BOLT #11:
1035 *
1036 * A reader:
1037 * ...

Callers 14

json_injectpaymentonionFunction · 0.85
json_listsendpaysFunction · 0.85
check_inv_conditionFunction · 0.85
json_listinvoicesFunction · 0.85
runFunction · 0.85
test_b11Function · 0.85
mainFunction · 0.85
json_payFunction · 0.85
param_decodableFunction · 0.85
json_renepaystatusFunction · 0.85
json_renepayFunction · 0.85
xpay_coreFunction · 0.85

Calls 7

bolt11_decode_nosigFunction · 0.85
pull_bitsFunction · 0.85
decode_failFunction · 0.85
valid_recovery_idFunction · 0.85
node_id_from_pubkeyFunction · 0.85
abortFunction · 0.85
pubkey_from_node_idFunction · 0.70

Tested by 2

test_b11Function · 0.68
mainFunction · 0.68