@@ -120,7 +120,7 @@ use crate::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures, InvoiceRequ
120
120
use crate :: ln:: inbound_payment:: ExpandedKey ;
121
121
use crate :: ln:: msgs:: DecodeError ;
122
122
use crate :: offers:: invoice_request:: { INVOICE_REQUEST_PAYER_ID_TYPE , INVOICE_REQUEST_TYPES , IV_BYTES as INVOICE_REQUEST_IV_BYTES , InvoiceRequest , InvoiceRequestContents , InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef } ;
123
- use crate :: offers:: merkle:: { SignError , SignFunction , SignatureTlvStream , SignatureTlvStreamRef , TaggedHash , TlvStream , WithoutSignatures , self } ;
123
+ use crate :: offers:: merkle:: { SignError , SignFn , SignatureTlvStream , SignatureTlvStreamRef , TaggedHash , TlvStream , WithoutSignatures , self } ;
124
124
use crate :: offers:: offer:: { Amount , OFFER_TYPES , OfferTlvStream , OfferTlvStreamRef , Quantity } ;
125
125
use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
126
126
use crate :: offers:: payer:: { PAYER_METADATA_TYPE , PayerTlvStream , PayerTlvStreamRef } ;
@@ -508,6 +508,37 @@ pub struct UnsignedBolt12Invoice {
508
508
tagged_hash : TaggedHash ,
509
509
}
510
510
511
+ /// A function for signing an [`UnsignedBolt12Invoice`].
512
+ pub trait SignBolt12InvoiceFn {
513
+ /// Error type returned by the function.
514
+ type Error ;
515
+
516
+ /// Signs a [`TaggedHash`] computed over the merkle root of `message`'s TLV stream.
517
+ fn sign_invoice ( & self , message : & UnsignedBolt12Invoice ) -> Result < Signature , Self :: Error > ;
518
+ }
519
+
520
+ impl < F , E > SignBolt12InvoiceFn for F
521
+ where
522
+ F : Fn ( & UnsignedBolt12Invoice ) -> Result < Signature , E > ,
523
+ {
524
+ type Error = E ;
525
+
526
+ fn sign_invoice ( & self , message : & UnsignedBolt12Invoice ) -> Result < Signature , E > {
527
+ self ( message)
528
+ }
529
+ }
530
+
531
+ impl < F , E > SignFn < UnsignedBolt12Invoice > for F
532
+ where
533
+ F : SignBolt12InvoiceFn < Error = E > ,
534
+ {
535
+ type Error = E ;
536
+
537
+ fn sign ( & self , message : & UnsignedBolt12Invoice ) -> Result < Signature , Self :: Error > {
538
+ self . sign_invoice ( message)
539
+ }
540
+ }
541
+
511
542
impl UnsignedBolt12Invoice {
512
543
fn new ( invreq_bytes : & [ u8 ] , contents : InvoiceContents ) -> Self {
513
544
// Use the invoice_request bytes instead of the invoice_request TLV stream as the latter may
@@ -535,12 +566,9 @@ macro_rules! unsigned_invoice_sign_method { ($self: ident, $self_type: ty $(, $s
535
566
/// Signs the [`TaggedHash`] of the invoice using the given function.
536
567
///
537
568
/// Note: The hash computation may have included unknown, odd TLV records.
538
- pub fn sign<F >(
569
+ pub fn sign<F : SignBolt12InvoiceFn >(
539
570
$( $self_mut) * $self: $self_type, sign: F
540
- ) -> Result <Bolt12Invoice , SignError <F :: Error >>
541
- where
542
- F : SignFunction <Self >,
543
- {
571
+ ) -> Result <Bolt12Invoice , SignError <F :: Error >> {
544
572
let pubkey = $self. contents. fields( ) . signing_pubkey;
545
573
let signature = merkle:: sign_message( sign, & $self, pubkey) ?;
546
574
0 commit comments