@@ -84,12 +84,12 @@ use crate::ln::PaymentHash;
84
84
use crate :: ln:: features:: InvoiceRequestFeatures ;
85
85
use crate :: ln:: inbound_payment:: { ExpandedKey , IV_LEN , Nonce } ;
86
86
use crate :: ln:: msgs:: { DecodeError , MAX_VALUE_MSAT } ;
87
- use crate :: offers:: invoice:: { BlindedPayInfo , ExplicitSigningPubkey , InvoiceBuilder } ;
87
+ use crate :: offers:: invoice:: { BlindedPayInfo , DerivedSigningPubkey , ExplicitSigningPubkey , InvoiceBuilder } ;
88
88
use crate :: offers:: invoice_request:: { InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef } ;
89
89
use crate :: offers:: offer:: { OfferTlvStream , OfferTlvStreamRef } ;
90
90
use crate :: offers:: parse:: { Bech32Encode , ParseError , ParsedMessage , SemanticError } ;
91
91
use crate :: offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
92
- use crate :: offers:: signer:: { Metadata , MetadataMaterial } ;
92
+ use crate :: offers:: signer:: { Metadata , MetadataMaterial , self } ;
93
93
use crate :: onion_message:: BlindedPath ;
94
94
use crate :: util:: ser:: { SeekReadable , WithoutLength , Writeable , Writer } ;
95
95
use crate :: util:: string:: PrintableString ;
@@ -431,6 +431,51 @@ impl Refund {
431
431
InvoiceBuilder :: for_refund ( self , payment_paths, created_at, payment_hash, signing_pubkey)
432
432
}
433
433
434
+ /// Creates an [`InvoiceBuilder`] for the refund using the given required fields and that uses
435
+ /// derived signing keys to sign the [`Invoice`].
436
+ ///
437
+ /// See [`Refund::respond_with`] for further details.
438
+ ///
439
+ /// [`Invoice`]: crate::offers::invoice::Invoice
440
+ #[ cfg( feature = "std" ) ]
441
+ pub fn respond_using_derived_keys < ES : Deref > (
442
+ & self , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > , payment_hash : PaymentHash ,
443
+ expanded_key : & ExpandedKey , entropy_source : ES
444
+ ) -> Result < InvoiceBuilder < DerivedSigningPubkey > , SemanticError >
445
+ where
446
+ ES :: Target : EntropySource ,
447
+ {
448
+ let created_at = std:: time:: SystemTime :: now ( )
449
+ . duration_since ( std:: time:: SystemTime :: UNIX_EPOCH )
450
+ . expect ( "SystemTime::now() should come after SystemTime::UNIX_EPOCH" ) ;
451
+
452
+ self . respond_using_derived_keys_no_std (
453
+ payment_paths, payment_hash, created_at, expanded_key, entropy_source
454
+ )
455
+ }
456
+
457
+ /// Creates an [`InvoiceBuilder`] for the refund using the given required fields and that uses
458
+ /// derived signing keys to sign the [`Invoice`].
459
+ ///
460
+ /// See [`Refund::respond_with_no_std`] for further details.
461
+ ///
462
+ /// [`Invoice`]: crate::offers::invoice::Invoice
463
+ pub fn respond_using_derived_keys_no_std < ES : Deref > (
464
+ & self , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > , payment_hash : PaymentHash ,
465
+ created_at : core:: time:: Duration , expanded_key : & ExpandedKey , entropy_source : ES
466
+ ) -> Result < InvoiceBuilder < DerivedSigningPubkey > , SemanticError >
467
+ where
468
+ ES :: Target : EntropySource ,
469
+ {
470
+ if self . features ( ) . requires_unknown_bits ( ) {
471
+ return Err ( SemanticError :: UnknownRequiredFeatures ) ;
472
+ }
473
+
474
+ let nonce = Nonce :: from_entropy_source ( entropy_source) ;
475
+ let keys = signer:: derive_keys ( nonce, expanded_key) ;
476
+ InvoiceBuilder :: for_refund_using_keys ( self , payment_paths, created_at, payment_hash, keys)
477
+ }
478
+
434
479
#[ cfg( test) ]
435
480
fn as_tlv_stream ( & self ) -> RefundTlvStreamRef {
436
481
self . contents . as_tlv_stream ( )
0 commit comments