@@ -44,7 +44,7 @@ use crate::chain::transaction::OutPoint;
4444use crate :: ln:: channel:: ANCHOR_OUTPUT_VALUE_SATOSHI ;
4545use crate :: ln:: { chan_utils, PaymentPreimage } ;
4646use crate :: ln:: chan_utils:: { HTLCOutputInCommitment , make_funding_redeemscript, ChannelPublicKeys , HolderCommitmentTransaction , ChannelTransactionParameters , CommitmentTransaction , ClosingTransaction , get_revokeable_redeemscript} ;
47- use crate :: ln:: channel_keys:: { DelayedPaymentBasepoint , DelayedPaymentKey , HtlcKey , HtlcBasepoint , RevocationKey , RevocationBasepoint } ;
47+ use crate :: ln:: channel_keys:: { DelayedPaymentBasepoint , DelayedPaymentKey , HtlcKey , HtlcBasepoint , RevocationKey , RevocationBasepoint , derive_add_tweak } ;
4848use crate :: ln:: msgs:: { UnsignedChannelAnnouncement , UnsignedGossipMessage } ;
4949#[ cfg( taproot) ]
5050use crate :: ln:: msgs:: PartialSignatureWithNonce ;
@@ -104,7 +104,7 @@ pub struct DelayedPaymentOutputDescriptor {
104104 /// The value of the channel which this output originated from, possibly indirectly.
105105 pub channel_value_satoshis : u64 ,
106106 /// Channel base key used to generate a witness data to spend this output.
107- pub delayed_payment_basepoint : DelayedPaymentBasepoint
107+ pub delayed_payment_basepoint : Option < DelayedPaymentBasepoint >
108108}
109109
110110impl DelayedPaymentOutputDescriptor {
@@ -124,7 +124,7 @@ impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, {
124124 ( 8 , revocation_pubkey, required) ,
125125 ( 10 , channel_keys_id, required) ,
126126 ( 12 , channel_value_satoshis, required) ,
127- ( 14 , delayed_payment_basepoint, required ) ,
127+ ( 14 , delayed_payment_basepoint, option ) ,
128128} ) ;
129129
130130pub ( crate ) const P2WPKH_WITNESS_WEIGHT : u64 = 1 /* num stack items */ +
@@ -319,21 +319,35 @@ impl SpendableOutputDescriptor {
319319 }
320320 } ,
321321 SpendableOutputDescriptor :: DelayedPaymentOutput ( descriptor) => {
322- let witness_script = {
323- let payment_key = DelayedPaymentKey :: from_basepoint (
324- secp_ctx,
325- & descriptor. delayed_payment_basepoint ,
326- & descriptor. per_commitment_point ,
327- ) ;
328- get_revokeable_redeemscript (
329- & descriptor. revocation_pubkey ,
330- descriptor. to_self_delay ,
331- & payment_key,
332- )
322+ let ( witness_script, add_tweak) = if let Some ( basepoint) = descriptor. delayed_payment_basepoint . as_ref ( ) {
323+ let payment_key = DelayedPaymentKey :: from_basepoint (
324+ secp_ctx,
325+ basepoint,
326+ & descriptor. per_commitment_point ,
327+ ) ;
328+ // Required to derive signing key: privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)
329+ let add_tweak = derive_add_tweak ( & descriptor. per_commitment_point , basepoint) ;
330+ ( Some ( get_revokeable_redeemscript (
331+ & descriptor. revocation_pubkey ,
332+ descriptor. to_self_delay ,
333+ & payment_key,
334+ ) ) , Some ( add_tweak) )
335+ } else {
336+ ( None , None )
333337 } ;
338+
339+
334340 bitcoin:: psbt:: Input {
335341 witness_utxo : Some ( descriptor. output . clone ( ) ) ,
336- witness_script : Some ( witness_script) ,
342+ witness_script,
343+ proprietary : add_tweak. map ( |add_tweak| { vec ! [ (
344+ raw:: ProprietaryKey {
345+ prefix: "LDK_spendable_output" . as_bytes( ) . to_vec( ) ,
346+ subtype: 0 ,
347+ key: "add_tweak" . as_bytes( ) . to_vec( ) ,
348+ } ,
349+ add_tweak,
350+ ) ] . into_iter ( ) . collect ( ) } ) . unwrap_or_default ( ) ,
337351 ..Default :: default ( )
338352 }
339353 } ,
@@ -370,8 +384,6 @@ impl SpendableOutputDescriptor {
370384 let mut input_value = 0 ;
371385 let mut witness_weight = 0 ;
372386 let mut output_set = HashSet :: with_capacity ( descriptors. len ( ) ) ;
373- // Required to derive signing key: privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)
374- let mut add_tweak: Option < Vec < u8 > > = None ;
375387 for outp in descriptors {
376388 match outp {
377389 SpendableOutputDescriptor :: StaticPaymentOutput ( descriptor) => {
@@ -408,8 +420,6 @@ impl SpendableOutputDescriptor {
408420 #[ cfg( feature = "grind_signatures" ) ]
409421 { witness_weight -= 1 ; } // Guarantees a low R signature
410422 input_value += descriptor. output . value ;
411-
412- add_tweak = Some ( derive_add_tweak ( & descriptor. per_commitment_point , & descriptor. delayed_payment_basepoint ) ) ;
413423 } ,
414424 SpendableOutputDescriptor :: StaticOutput { ref outpoint, ref output, .. } => {
415425 if !output_set. insert ( * outpoint) { return Err ( ( ) ) ; }
@@ -443,35 +453,13 @@ impl SpendableOutputDescriptor {
443453 unsigned_tx : tx,
444454 xpub : Default :: default ( ) ,
445455 version : 0 ,
446- proprietary : add_tweak. map ( |add_tweak| { vec ! [ (
447- raw:: ProprietaryKey {
448- prefix: "spendable_output" . as_bytes( ) . to_vec( ) ,
449- subtype: 0 ,
450- key: "add_tweak" . as_bytes( ) . to_vec( ) ,
451- } ,
452- add_tweak,
453- ) ] . into_iter ( ) . collect ( ) } ) . unwrap_or_default ( ) ,
456+ proprietary : Default :: default ( ) ,
454457 unknown : Default :: default ( ) ,
455458 } ;
456459 Ok ( ( psbt, expected_max_weight) )
457460 }
458461}
459462
460- /// Derives a per-commitment-transaction (eg an htlc key or delayed_payment key) private key addition tweak
461- /// from a delayed payment basepoint and a per_commitment_point:
462- /// `privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`
463- /// TODO(oleg): refactor after migration to LDK v119
464- pub fn derive_add_tweak (
465- per_commitment_point : & PublicKey ,
466- basepoint : & DelayedPaymentBasepoint ,
467- ) -> Vec < u8 > {
468- let mut sha = Sha256 :: engine ( ) ;
469- sha. input ( & per_commitment_point. serialize ( ) ) ;
470- sha. input ( & basepoint. to_public_key ( ) . serialize ( ) ) ;
471- let res = Sha256 :: from_engine ( sha) . to_byte_array ( ) ;
472- res. to_vec ( )
473- }
474-
475463
476464/// The parameters required to derive a channel signer via [`SignerProvider`].
477465#[ derive( Clone , Debug , PartialEq , Eq ) ]
0 commit comments