@@ -350,29 +350,11 @@ pub trait KeysInterface: Send + Sync {
350
350
fn get_secure_random_bytes ( & self ) -> [ u8 ; 32 ] ;
351
351
}
352
352
353
- #[ derive( Clone ) ]
354
- /// Holds late-bound static channel data.
355
- /// This data is available after the channel is readied, either
356
- /// when receiving an funding_created for an inbound channel or when
357
- /// creating a funding transaction for an outbound channel.
358
- struct StaticChannelData {
359
- /// Counterparty public keys and base points
360
- counterparty_channel_pubkeys : ChannelPublicKeys ,
361
- /// The contest_delay value specified by our counterparty and applied on holder-broadcastable
362
- /// transactions, ie the amount of time that we have to wait to recover our funds if we
363
- /// broadcast a transaction. You'll likely want to pass this to the
364
- /// ln::chan_utils::build*_transaction functions when signing holder's transactions.
365
- counterparty_selected_contest_delay : u16 ,
366
- /// The contest_delay value specified by us and applied on transactions broadcastable
367
- /// by our counterparty, ie the amount of time that they have to wait to recover their funds
368
- /// if they broadcast a transaction.
369
- holder_selected_contest_delay : u16 ,
370
- /// Whether the holder is the initiator of this channel
371
- is_outbound : bool ,
372
- }
373
-
374
353
#[ derive( Clone ) ]
375
354
/// A simple implementation of ChannelKeys that just keeps the private keys in memory.
355
+ ///
356
+ /// This implementation performs no policy checks and is insufficient by itself as
357
+ /// a secure external signer.
376
358
pub struct InMemoryChannelKeys {
377
359
/// Private key of anchor tx
378
360
pub funding_key : SecretKey ,
@@ -481,26 +463,26 @@ impl ChannelKeys for InMemoryChannelKeys {
481
463
fn key_derivation_params ( & self ) -> ( u64 , u64 ) { self . key_derivation_params }
482
464
483
465
fn sign_counterparty_commitment < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , commitment_tx : & CommitmentTransaction , secp_ctx : & Secp256k1 < T > ) -> Result < ( Signature , Vec < Signature > ) , ( ) > {
484
- let keys = commitment_tx. trust_key_derivation ( ) ;
466
+ let keys = commitment_tx. untrusted_key_derivation ( ) ;
485
467
486
468
let funding_pubkey = PublicKey :: from_secret_key ( secp_ctx, & self . funding_key ) ;
487
469
let channel_funding_redeemscript = make_funding_redeemscript ( & funding_pubkey, & self . counterparty_pubkeys ( ) . funding_pubkey ) ;
488
470
489
- let built_tx = & commitment_tx. built ;
490
- let commitment_sig = built_tx. get_signature ( & self . funding_key , & channel_funding_redeemscript, self . channel_value_satoshis , secp_ctx) ;
471
+ let built_tx = commitment_tx. untrusted_built_transaction ( ) ;
472
+ let commitment_sig = built_tx. sign ( & self . funding_key , & channel_funding_redeemscript, self . channel_value_satoshis , secp_ctx) ;
491
473
492
- let commitment_txid = commitment_tx. trust_txid ( ) ;
474
+ let commitment_txid = commitment_tx. untrusted_txid ( ) ;
493
475
494
- let mut htlc_sigs = Vec :: with_capacity ( commitment_tx. htlcs . len ( ) ) ;
495
- for htlc in & commitment_tx. htlcs {
496
- let htlc_tx = chan_utils:: build_htlc_transaction ( & commitment_txid, commitment_tx. feerate_per_kw , self . holder_selected_contest_delay ( ) , htlc, & keys. broadcaster_delayed_payment_key , & keys. revocation_key ) ;
476
+ let mut htlc_sigs = Vec :: with_capacity ( commitment_tx. htlcs ( ) . len ( ) ) ;
477
+ for htlc in commitment_tx. htlcs ( ) {
478
+ let htlc_tx = chan_utils:: build_htlc_transaction ( & commitment_txid, commitment_tx. feerate_per_kw ( ) , self . holder_selected_contest_delay ( ) , htlc, & keys. broadcaster_delayed_payment_key , & keys. revocation_key ) ;
497
479
let htlc_redeemscript = chan_utils:: get_htlc_redeemscript ( & htlc, & keys) ;
498
480
let htlc_sighash = hash_to_message ! ( & bip143:: SigHashCache :: new( & htlc_tx) . signature_hash( 0 , & htlc_redeemscript, htlc. amount_msat / 1000 , SigHashType :: All ) [ ..] ) ;
499
- let our_htlc_key = match chan_utils:: derive_private_key ( & secp_ctx, & keys. per_commitment_point , & self . htlc_base_key ) {
481
+ let holder_htlc_key = match chan_utils:: derive_private_key ( & secp_ctx, & keys. per_commitment_point , & self . htlc_base_key ) {
500
482
Ok ( s) => s,
501
483
Err ( _) => return Err ( ( ) ) ,
502
484
} ;
503
- htlc_sigs. push ( secp_ctx. sign ( & htlc_sighash, & our_htlc_key ) ) ;
485
+ htlc_sigs. push ( secp_ctx. sign ( & htlc_sighash, & holder_htlc_key ) ) ;
504
486
}
505
487
506
488
Ok ( ( commitment_sig, htlc_sigs) )
@@ -510,8 +492,8 @@ impl ChannelKeys for InMemoryChannelKeys {
510
492
let funding_pubkey = PublicKey :: from_secret_key ( secp_ctx, & self . funding_key ) ;
511
493
let funding_redeemscript = make_funding_redeemscript ( & funding_pubkey, & self . counterparty_pubkeys ( ) . funding_pubkey ) ;
512
494
513
- let built_tx = & commitment_tx. inner . built ;
514
- let sig = built_tx. get_signature ( & self . funding_key , & funding_redeemscript, self . channel_value_satoshis , secp_ctx) ;
495
+ let built_tx = commitment_tx. inner . untrusted_built_transaction ( ) ;
496
+ let sig = built_tx. sign ( & self . funding_key , & funding_redeemscript, self . channel_value_satoshis , secp_ctx) ;
515
497
let htlc_sigs_o = self . sign_holder_commitment_htlc_transactions ( & commitment_tx, secp_ctx) ?;
516
498
let htlc_sigs = htlc_sigs_o. iter ( ) . map ( |o| o. unwrap ( ) ) . collect ( ) ;
517
499
@@ -523,13 +505,13 @@ impl ChannelKeys for InMemoryChannelKeys {
523
505
let funding_pubkey = PublicKey :: from_secret_key ( secp_ctx, & self . funding_key ) ;
524
506
let channel_funding_redeemscript = make_funding_redeemscript ( & funding_pubkey, & self . counterparty_pubkeys ( ) . funding_pubkey ) ;
525
507
526
- let built_tx = & holder_commitment_tx. inner . built ;
527
- Ok ( built_tx. get_signature ( & self . funding_key , & channel_funding_redeemscript, self . channel_value_satoshis , secp_ctx) )
508
+ let built_tx = holder_commitment_tx. inner . untrusted_built_transaction ( ) ;
509
+ Ok ( built_tx. sign ( & self . funding_key , & channel_funding_redeemscript, self . channel_value_satoshis , secp_ctx) )
528
510
}
529
511
530
512
fn sign_holder_commitment_htlc_transactions < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < T > ) -> Result < Vec < Option < Signature > > , ( ) > {
531
513
let channel_parameters = self . make_channel_parameters ( ) ;
532
- let channel_parameters = channel_parameters. to_directed ( true ) ;
514
+ let channel_parameters = channel_parameters. as_holder_broadcastable ( ) ;
533
515
commitment_tx. inner . get_htlc_sigs ( & self . htlc_base_key , & channel_parameters, secp_ctx)
534
516
}
535
517
0 commit comments