| 153 | } |
| 154 | |
| 155 | static void generate_valid_vector(const char *name, |
| 156 | struct tlv_invoice *inv, |
| 157 | const struct preimage *preimage, |
| 158 | char payer_letter, |
| 159 | const char *note, |
| 160 | bool (*include_field)(const struct tlv_field *, void *), |
| 161 | bool explicit_empty_omitted) |
| 162 | { |
| 163 | struct sha256 mroot, pproot, shash; |
| 164 | struct tlv_payer_proof *proof; |
| 165 | secp256k1_keypair kp = keypair_for_letter(payer_letter); |
| 166 | u8 *invoice_wire; |
| 167 | |
| 168 | invoice_wire = tal_arr(tmpctx, u8, 0); |
| 169 | towire_tlv_invoice(&invoice_wire, inv); |
| 170 | |
| 171 | merkle_tlv(inv->fields, &mroot); |
| 172 | sighash_from_merkle("invoice", "signature", &mroot, &shash); |
| 173 | proof = make_unsigned_proof(tmpctx, inv, preimage, note, include_field, NULL); |
| 174 | /* Force proof_omitted_tlvs to be present-but-empty rather than absent, |
| 175 | * then refresh fields so payer_proof_signature signs the updated merkle. */ |
| 176 | if (explicit_empty_omitted) { |
| 177 | proof->proof_omitted_tlvs = tal_arr(proof, bigsize_t, 0); |
| 178 | tlv_update_fields(proof, tlv_payer_proof, &proof->fields); |
| 179 | } |
| 180 | proof->proof_signature = payer_proof_signature(proof, proof, sign_payer, &kp); |
| 181 | assert(proof->proof_signature); |
| 182 | /* Refresh fields to include proof_signature */ |
| 183 | tlv_update_fields(proof, tlv_payer_proof, &proof->fields); |
| 184 | |
| 185 | bolt12_payer_proof_merkle(proof, &pproot); |
| 186 | |
| 187 | printf("{\n"); |
| 188 | printf("\"name\":\"%s\",\n", name); |
| 189 | |
| 190 | printf("\"input\":{\n"); |
| 191 | printf("\"invoice\":\"%s\",\n", invoice_encode(tmpctx, inv)); |
| 192 | printf("\"invoice_hex\":\"%s\",\n", |
| 193 | tal_hexstr(tmpctx, invoice_wire, tal_bytelen(invoice_wire))); |
| 194 | printf("\"preimage\":\"%s\",\n", |
| 195 | tal_hexstr(tmpctx, preimage->r, sizeof(preimage->r))); |
| 196 | if (note) |
| 197 | printf("\"note\":\"%s\",\n", note); |
| 198 | printf("\"invoice_fields\":[\n"); |
| 199 | print_fields_json(inv->fields, tal_count(inv->fields), include_field, NULL); |
| 200 | printf("]\n"); |
| 201 | printf("},\n"); |
| 202 | |
| 203 | printf("\"working\":{\n"); |
| 204 | printf("\"invoice_merkle_root\":\"%s\",\n", fmt_sha256(tmpctx, &mroot)); |
| 205 | printf("\"invoice_sighash\":\"%s\",\n", fmt_sha256(tmpctx, &shash)); |
| 206 | printf("\"invoice_signature\":\"%s\",\n", |
| 207 | tal_hexstr(tmpctx, inv->signature->u8, sizeof(inv->signature->u8))); |
| 208 | printf("\"proof_merkle_root\":\"%s\",\n", fmt_sha256(tmpctx, &pproot)); |
| 209 | printf("\"proof_leaf_hashes\":[\n"); |
| 210 | print_hashes_json(proof->proof_leaf_hashes, tal_count(proof->proof_leaf_hashes)); |
| 211 | printf("],\n"); |
| 212 | printf("\"proof_omitted_tlvs\":[\n"); |
no test coverage detected