@@ -44,7 +44,7 @@ use crate::chain::transaction::OutPoint;
44
44
use crate :: ln:: channel:: ANCHOR_OUTPUT_VALUE_SATOSHI ;
45
45
use crate :: ln:: { chan_utils, PaymentPreimage } ;
46
46
use 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 } ;
48
48
use crate :: ln:: msgs:: { UnsignedChannelAnnouncement , UnsignedGossipMessage } ;
49
49
#[ cfg( taproot) ]
50
50
use crate :: ln:: msgs:: PartialSignatureWithNonce ;
@@ -104,7 +104,7 @@ pub struct DelayedPaymentOutputDescriptor {
104
104
/// The value of the channel which this output originated from, possibly indirectly.
105
105
pub channel_value_satoshis : u64 ,
106
106
/// 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 >
108
108
}
109
109
110
110
impl DelayedPaymentOutputDescriptor {
@@ -124,7 +124,7 @@ impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, {
124
124
( 8 , revocation_pubkey, required) ,
125
125
( 10 , channel_keys_id, required) ,
126
126
( 12 , channel_value_satoshis, required) ,
127
- ( 14 , delayed_payment_basepoint, required ) ,
127
+ ( 14 , delayed_payment_basepoint, option ) ,
128
128
} ) ;
129
129
130
130
pub ( crate ) const P2WPKH_WITNESS_WEIGHT : u64 = 1 /* num stack items */ +
@@ -319,21 +319,35 @@ impl SpendableOutputDescriptor {
319
319
}
320
320
} ,
321
321
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 )
333
337
} ;
338
+
339
+
334
340
bitcoin:: psbt:: Input {
335
341
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 ( ) ,
337
351
..Default :: default ( )
338
352
}
339
353
} ,
@@ -370,8 +384,6 @@ impl SpendableOutputDescriptor {
370
384
let mut input_value = 0 ;
371
385
let mut witness_weight = 0 ;
372
386
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 ;
375
387
for outp in descriptors {
376
388
match outp {
377
389
SpendableOutputDescriptor :: StaticPaymentOutput ( descriptor) => {
@@ -408,8 +420,6 @@ impl SpendableOutputDescriptor {
408
420
#[ cfg( feature = "grind_signatures" ) ]
409
421
{ witness_weight -= 1 ; } // Guarantees a low R signature
410
422
input_value += descriptor. output . value ;
411
-
412
- add_tweak = Some ( derive_add_tweak ( & descriptor. per_commitment_point , & descriptor. delayed_payment_basepoint ) ) ;
413
423
} ,
414
424
SpendableOutputDescriptor :: StaticOutput { ref outpoint, ref output, .. } => {
415
425
if !output_set. insert ( * outpoint) { return Err ( ( ) ) ; }
@@ -443,35 +453,13 @@ impl SpendableOutputDescriptor {
443
453
unsigned_tx : tx,
444
454
xpub : Default :: default ( ) ,
445
455
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 ( ) ,
454
457
unknown : Default :: default ( ) ,
455
458
} ;
456
459
Ok ( ( psbt, expected_max_weight) )
457
460
}
458
461
}
459
462
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
-
475
463
476
464
/// The parameters required to derive a channel signer via [`SignerProvider`].
477
465
#[ derive( Clone , Debug , PartialEq , Eq ) ]
0 commit comments