| 651 | } |
| 652 | |
| 653 | static void json_add_invoice_request(struct json_stream *js, |
| 654 | const struct tlv_invoice_request *invreq) |
| 655 | { |
| 656 | bool valid = true; |
| 657 | |
| 658 | if (invreq->chain) |
| 659 | json_add_sha256(js, "chain", &invreq->chain->shad.sha); |
| 660 | |
| 661 | /* BOLT-offers #12: |
| 662 | * - MUST fail the request if `payer_key` is not present. |
| 663 | *... |
| 664 | * - MUST fail the request if `features` contains unknown even bits. |
| 665 | * - MUST fail the request if `offer_id` is not present. |
| 666 | */ |
| 667 | if (invreq->offer_id) |
| 668 | json_add_sha256(js, "offer_id", invreq->offer_id); |
| 669 | else { |
| 670 | json_add_string(js, "warning_invoice_request_missing_offer_id", |
| 671 | "invoice_request requires offer_id"); |
| 672 | valid = false; |
| 673 | } |
| 674 | if (invreq->amount) |
| 675 | json_add_amount_msat_only(js, "amount_msat", |
| 676 | amount_msat(*invreq->amount)); |
| 677 | if (invreq->features) |
| 678 | json_add_hex_talarr(js, "features", invreq->features); |
| 679 | if (invreq->quantity) |
| 680 | json_add_u64(js, "quantity", *invreq->quantity); |
| 681 | |
| 682 | if (invreq->recurrence_counter) |
| 683 | json_add_u32(js, "recurrence_counter", |
| 684 | *invreq->recurrence_counter); |
| 685 | if (invreq->recurrence_start) |
| 686 | json_add_u32(js, "recurrence_start", |
| 687 | *invreq->recurrence_start); |
| 688 | if (invreq->payer_key) |
| 689 | json_add_point32(js, "payer_key", invreq->payer_key); |
| 690 | else { |
| 691 | json_add_string(js, "warning_invoice_request_missing_payer_key", |
| 692 | "invoice_request requires payer_key"); |
| 693 | valid = false; |
| 694 | } |
| 695 | if (invreq->payer_info) |
| 696 | json_add_hex_talarr(js, "payer_info", invreq->payer_info); |
| 697 | if (invreq->payer_note) |
| 698 | json_add_stringn(js, "payer_note", invreq->payer_note, |
| 699 | tal_bytelen(invreq->payer_note)); |
| 700 | |
| 701 | /* BOLT-offers #12: |
| 702 | * - MUST fail the request if there is no `signature` field. |
| 703 | * - MUST fail the request if `signature` is not correct. |
| 704 | */ |
| 705 | if (invreq->signature) { |
| 706 | if (invreq->payer_key |
| 707 | && !bolt12_check_signature(invreq->fields, |
| 708 | "invoice_request", |
| 709 | "signature", |
| 710 | invreq->payer_key, |
no test coverage detected