@@ -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 ;
@@ -429,6 +429,51 @@ impl Refund {
429
429
InvoiceBuilder :: for_refund ( self , payment_paths, created_at, payment_hash, signing_pubkey)
430
430
}
431
431
432
+ /// Creates an [`InvoiceBuilder`] for the refund using the given required fields and that uses
433
+ /// derived signing keys to sign the [`Invoice`].
434
+ ///
435
+ /// See [`Refund::respond_with`] for further details.
436
+ ///
437
+ /// [`Invoice`]: crate::offers::invoice::Invoice
438
+ #[ cfg( feature = "std" ) ]
439
+ pub fn respond_using_derived_keys < ES : Deref > (
440
+ & self , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > , payment_hash : PaymentHash ,
441
+ expanded_key : & ExpandedKey , entropy_source : ES
442
+ ) -> Result < InvoiceBuilder < DerivedSigningPubkey > , SemanticError >
443
+ where
444
+ ES :: Target : EntropySource ,
445
+ {
446
+ let created_at = std:: time:: SystemTime :: now ( )
447
+ . duration_since ( std:: time:: SystemTime :: UNIX_EPOCH )
448
+ . expect ( "SystemTime::now() should come after SystemTime::UNIX_EPOCH" ) ;
449
+
450
+ self . respond_using_derived_keys_no_std (
451
+ payment_paths, payment_hash, created_at, expanded_key, entropy_source
452
+ )
453
+ }
454
+
455
+ /// Creates an [`InvoiceBuilder`] for the refund using the given required fields and that uses
456
+ /// derived signing keys to sign the [`Invoice`].
457
+ ///
458
+ /// See [`Refund::respond_with_no_std`] for further details.
459
+ ///
460
+ /// [`Invoice`]: crate::offers::invoice::Invoice
461
+ pub fn respond_using_derived_keys_no_std < ES : Deref > (
462
+ & self , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > , payment_hash : PaymentHash ,
463
+ created_at : core:: time:: Duration , expanded_key : & ExpandedKey , entropy_source : ES
464
+ ) -> Result < InvoiceBuilder < DerivedSigningPubkey > , SemanticError >
465
+ where
466
+ ES :: Target : EntropySource ,
467
+ {
468
+ if self . features ( ) . requires_unknown_bits ( ) {
469
+ return Err ( SemanticError :: UnknownRequiredFeatures ) ;
470
+ }
471
+
472
+ let nonce = Nonce :: from_entropy_source ( entropy_source) ;
473
+ let keys = signer:: derive_keys ( nonce, expanded_key) ;
474
+ InvoiceBuilder :: for_refund_using_keys ( self , payment_paths, created_at, payment_hash, keys)
475
+ }
476
+
432
477
#[ cfg( test) ]
433
478
fn as_tlv_stream ( & self ) -> RefundTlvStreamRef {
434
479
self . contents . as_tlv_stream ( )
0 commit comments