4444//!     .quantity(5)? 
4545//!     .payer_note("foo".to_string()) 
4646//!     .build()? 
47- //!     .sign::<_, Infallible>(|digest| Ok(secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))) 
47+ //!     .sign::<_, Infallible>(|digest, _, _, _ | Ok(secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))) 
4848//!     .expect("failed verifying signature") 
4949//!     .write(&mut buffer) 
5050//!     .unwrap(); 
@@ -268,7 +268,7 @@ impl<'a> UnsignedInvoiceRequest<'a> {
268268	/// Signs the invoice request using the given function. 
269269 	pub  fn  sign < F ,  E > ( self ,  sign :  F )  -> Result < InvoiceRequest ,  SignError < E > > 
270270	where 
271- 		F :  FnOnce ( & Message )  -> Result < Signature ,  E > 
271+ 		F :  FnOnce ( & Message ,   & str ,   & [ u8 ] ,   & [ u8 ] )  -> Result < Signature ,  E > 
272272	{ 
273273		// Use the offer bytes instead of the offer TLV stream as the offer may have contained 
274274		// unknown TLV records, which are not stored in `OfferContents`. 
@@ -280,8 +280,9 @@ impl<'a> UnsignedInvoiceRequest<'a> {
280280		let  mut  bytes = Vec :: new ( ) ; 
281281		unsigned_tlv_stream. write ( & mut  bytes) . unwrap ( ) ; 
282282
283+ 		let  metadata = self . offer . metadata ( ) . map ( |metadata| metadata. as_slice ( ) ) . unwrap_or ( & [ ] ) ; 
283284		let  pubkey = self . invoice_request . payer_id ; 
284- 		let  signature = merkle:: sign_message ( sign,  SIGNATURE_TAG ,  & bytes,  pubkey) ?; 
285+ 		let  signature = merkle:: sign_message ( sign,  SIGNATURE_TAG ,  & bytes,  metadata ,   pubkey) ?; 
285286
286287		// Append the signature TLV record to the bytes. 
287288		let  signature_tlv_stream = SignatureTlvStreamRef  { 
@@ -332,7 +333,7 @@ impl InvoiceRequest {
332333 	/// 
333334 	/// [`payer_id`]: Self::payer_id 
334335 	pub  fn  metadata ( & self )  -> & [ u8 ]  { 
335- 		& self . contents . payer . 0 [ .. ] 
336+ 		self . contents . metadata ( ) 
336337	} 
337338
338339	/// A chain from [`Offer::chains`] that the offer is valid for. 
@@ -442,6 +443,10 @@ impl InvoiceRequest {
442443} 
443444
444445impl  InvoiceRequestContents  { 
446+ 	pub ( super )  fn  metadata ( & self )  -> & [ u8 ]  { 
447+ 		& self . payer . 0 
448+ 	} 
449+ 
445450	pub ( super )  fn  chain ( & self )  -> ChainHash  { 
446451		self . chain . unwrap_or_else ( || self . offer . implied_chain ( ) ) 
447452	} 
@@ -755,7 +760,8 @@ mod tests {
755760		tlv_stream. write ( & mut  bytes) . unwrap ( ) ; 
756761
757762		let  signature = merkle:: sign_message ( 
758- 			recipient_sign,  INVOICE_SIGNATURE_TAG ,  & bytes,  recipient_pubkey ( ) 
763+ 			recipient_sign,  INVOICE_SIGNATURE_TAG ,  & bytes,  invoice_request. metadata ( ) , 
764+ 			recipient_pubkey ( ) 
759765		) . unwrap ( ) ; 
760766		signature_tlv_stream. signature  = Some ( & signature) ; 
761767
@@ -790,7 +796,9 @@ mod tests {
790796			. build ( ) . unwrap ( ) ; 
791797		let  invoice_request = offer. request_invoice_deriving_payer_id ( payer_pubkey) . unwrap ( ) 
792798			. build ( ) . unwrap ( ) 
793- 			. sign :: < _ ,  Infallible > ( |digest| Ok ( secp_ctx. sign_schnorr_no_aux_rand ( digest,  & keys) ) ) 
799+ 			. sign :: < _ ,  Infallible > ( 
800+ 				|digest,  _,  _,  _| Ok ( secp_ctx. sign_schnorr_no_aux_rand ( digest,  & keys) ) 
801+ 			) 
794802			. unwrap ( ) ; 
795803		assert_eq ! ( invoice_request. metadata( ) [ ..Nonce :: LENGTH ] ,  nonce. 0 ) ; 
796804		assert_eq ! ( invoice_request. payer_id( ) ,  keys. public_key( ) ) ; 
@@ -814,7 +822,8 @@ mod tests {
814822		tlv_stream. write ( & mut  bytes) . unwrap ( ) ; 
815823
816824		let  signature = merkle:: sign_message ( 
817- 			recipient_sign,  INVOICE_SIGNATURE_TAG ,  & bytes,  recipient_pubkey ( ) 
825+ 			recipient_sign,  INVOICE_SIGNATURE_TAG ,  & bytes,  invoice_request. metadata ( ) , 
826+ 			recipient_pubkey ( ) 
818827		) . unwrap ( ) ; 
819828		signature_tlv_stream. signature  = Some ( & signature) ; 
820829
@@ -1164,7 +1173,7 @@ mod tests {
11641173			. build ( ) . unwrap ( ) 
11651174			. request_invoice ( vec ! [ 1 ;  32 ] ,  payer_pubkey ( ) ) . unwrap ( ) 
11661175			. build ( ) . unwrap ( ) 
1167- 			. sign ( |_| Err ( ( ) ) ) 
1176+ 			. sign ( |_,  _ ,  _ ,  _ | Err ( ( ) ) ) 
11681177		{ 
11691178			Ok ( _)  => panic ! ( "expected error" ) , 
11701179			Err ( e)  => assert_eq ! ( e,  SignError :: Signing ( ( ) ) ) , 
@@ -1578,7 +1587,9 @@ mod tests {
15781587			. build ( ) . unwrap ( ) 
15791588			. request_invoice ( vec ! [ 1 ;  32 ] ,  keys. public_key ( ) ) . unwrap ( ) 
15801589			. build ( ) . unwrap ( ) 
1581- 			. sign :: < _ ,  Infallible > ( |digest| Ok ( secp_ctx. sign_schnorr_no_aux_rand ( digest,  & keys) ) ) 
1590+ 			. sign :: < _ ,  Infallible > ( 
1591+ 				|digest,  _,  _,  _| Ok ( secp_ctx. sign_schnorr_no_aux_rand ( digest,  & keys) ) 
1592+ 			) 
15821593			. unwrap ( ) ; 
15831594
15841595		let  mut  encoded_invoice_request = Vec :: new ( ) ; 
0 commit comments