X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Foffers%2Finvoice_request.rs;h=03af068d1d61912738f23ac71ff3c91079161ffe;hb=7a992ba40f6192bce138cf3eafdf41c3d050b9f7;hp=5704dcbd3e2172bdf01bb0b46cdc3f8eab3ed481;hpb=bde982344a685a04bcd219c1c040b8fabe8f08af;p=rust-lightning diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index 5704dcbd..03af068d 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -372,6 +372,11 @@ impl UnsignedInvoiceRequest { Self { bytes, contents, tagged_hash } } + /// Returns the [`TaggedHash`] of the invoice to sign. + pub fn tagged_hash(&self) -> &TaggedHash { + &self.tagged_hash + } + /// Signs the [`TaggedHash`] of the invoice request using the given function. /// /// Note: The hash computation may have included unknown, odd TLV records. @@ -635,15 +640,15 @@ impl InvoiceRequestContents { self.inner.chain() } - fn amount_msats(&self) -> Option { + pub(super) fn amount_msats(&self) -> Option { self.inner.amount_msats } - fn features(&self) -> &InvoiceRequestFeatures { + pub(super) fn features(&self) -> &InvoiceRequestFeatures { &self.inner.features } - fn quantity(&self) -> Option { + pub(super) fn quantity(&self) -> Option { self.inner.quantity } @@ -651,7 +656,7 @@ impl InvoiceRequestContents { self.payer_id } - fn payer_note(&self) -> Option { + pub(super) fn payer_note(&self) -> Option { self.inner.payer_note.as_ref() .map(|payer_note| PrintableString(payer_note.as_str())) } @@ -799,7 +804,8 @@ impl TryFrom> for InvoiceRequest { None => return Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature)), Some(signature) => signature, }; - merkle::verify_signature(&signature, SIGNATURE_TAG, &bytes, contents.payer_id)?; + let message = TaggedHash::new(SIGNATURE_TAG, &bytes); + merkle::verify_signature(&signature, message, contents.payer_id)?; Ok(InvoiceRequest { bytes, contents, signature }) } @@ -933,11 +939,9 @@ mod tests { assert_eq!(invoice_request.quantity(), None); assert_eq!(invoice_request.payer_id(), payer_pubkey()); assert_eq!(invoice_request.payer_note(), None); - assert!( - merkle::verify_signature( - &invoice_request.signature, SIGNATURE_TAG, &invoice_request.bytes, payer_pubkey() - ).is_ok() - ); + + let message = TaggedHash::new(SIGNATURE_TAG, &invoice_request.bytes); + assert!(merkle::verify_signature(&invoice_request.signature, message, payer_pubkey()).is_ok()); assert_eq!( invoice_request.as_tlv_stream(),