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

Function make_unsigned_proof_

common/bolt12_proof.c:56–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56struct tlv_payer_proof *make_unsigned_proof_(const tal_t *ctx,
57 const struct tlv_invoice *inv,
58 const struct preimage *preimage,
59 const char *note,
60 bool (*include_field)(const struct tlv_field *f, void *),
61 void *arg)
62{
63 size_t last_type = 0, len;
64 struct sha256 *leaf_hashes, merkle;
65 struct creator creator;
66 struct tlv_payer_proof *pptlv;
67 struct tlv_field *included;
68 bigsize_t *omitted;
69 u8 *tlvstream;
70 struct sha256_ctx lnnonce_ctx;
71
72 /* Calculates (H("LnNonce"||TLV0,...) ready for calc_nonce */
73 bolt12_lnnonce_ctx(&lnnonce_ctx, &inv->fields[0]);
74
75 included = tal_arr(tmpctx, struct tlv_field, 0);
76 leaf_hashes = tal_arr(tmpctx, struct sha256, 0);
77 omitted = tal_arr(tmpctx, bigsize_t, 0);
78
79 /* BOLT-payer_proof #12:
80 * - For each non-signature TLV in the invoice in ascending-type order:
81 */
82 for (size_t i = 0; i < tal_count(inv->fields); i++) {
83 const struct tlv_field *f = &inv->fields[i];
84
85 if (is_tlv_signature_field(f))
86 continue;
87
88 /* BOLT-payer_proof #12:
89 * - If the field is to be included in the payer_proof:
90 * - MUST copy it into the payer_proof.
91 * - MUST append the nonce (H("LnNonce"||TLV0,type)) to
92 * `proof_leaf_hashes`.
93 */
94 if (include_field(f, arg)) {
95 struct sha256 hash;
96 tal_arr_expand(&included, *f);
97 bolt12_calc_nonce(&lnnonce_ctx, f->numtype, &hash, NULL);
98 tal_arr_expand(&leaf_hashes, hash);
99 last_type = f->numtype;
100 continue;
101 }
102 /* BOLT-payer_proof #12:
103 * - otherwise, if the TLV type is not zero:
104 * - MUST append a *marker number* to `proof_omitted_tlvs`
105 * - If the previous TLV type was included:
106 * - The *marker number* is that previous tlv type,
107 * plus one.
108 * - Otherwise, if `proof_omitted_tlvs` is empty:
109 * - The *marker number* is 1.
110 * - Otherwise:
111 * - The *marker number* is one greater than the last
112 * `proof_omitted_tlvs` entry.
113 */

Callers

nothing calls this directly

Calls 6

bolt12_lnnonce_ctxFunction · 0.85
is_tlv_signature_fieldFunction · 0.85
bolt12_calc_nonceFunction · 0.85
towire_tlvstream_rawFunction · 0.85
tal_bytelenFunction · 0.85
utf8_checkFunction · 0.70

Tested by

no test coverage detected