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

Function bolt11_decode

common/bolt11.c:988–1070  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

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