+impl UnsignedBolt12Invoice {
+ fn new(invreq_bytes: &[u8], invoice: InvoiceContents) -> Self {
+ // Use the invoice_request bytes instead of the invoice_request TLV stream as the latter may
+ // have contained unknown TLV records, which are not stored in `InvoiceRequestContents` or
+ // `RefundContents`.
+ let (_, _, _, invoice_tlv_stream) = invoice.as_tlv_stream();
+ let invoice_request_bytes = WithoutSignatures(invreq_bytes);
+ let unsigned_tlv_stream = (invoice_request_bytes, invoice_tlv_stream);
+
+ let mut bytes = Vec::new();
+ unsigned_tlv_stream.write(&mut bytes).unwrap();
+
+ let tagged_hash = TaggedHash::new(SIGNATURE_TAG, &bytes);
+
+ Self { bytes, invoice, tagged_hash }
+ }
+