@@ -21,8 +21,12 @@ use crate::sign::ecdsa::EcdsaChannelSigner;
21
21
use crate :: sign:: InMemorySigner ;
22
22
use crate :: sign:: {
23
23
KeyMaterial , NodeSigner , Recipient , SignerProvider , SpendableOutputDescriptor ,
24
- ecdsa:: WriteableEcdsaChannelSigner ,
24
+ ecdsa:: WriteableEcdsaChannelSigner
25
25
} ;
26
+ #[ cfg( taproot) ]
27
+ use crate :: sign:: taproot:: { TaprootChannelSigner } ;
28
+ #[ cfg( taproot) ]
29
+ use musig2:: types:: { PartialSignature , PublicNonce } ;
26
30
use crate :: util:: ser:: { Readable , ReadableArgs } ;
27
31
use crate :: util:: ser:: { Writeable , Writer } ;
28
32
use bitcoin;
@@ -36,6 +40,7 @@ use crate::ln::features::ChannelTypeFeatures;
36
40
#[ cfg( any( test, feature = "_test_utils" ) ) ]
37
41
use crate :: util:: test_utils:: OnlyReadsKeysInterface ;
38
42
43
+ #[ cfg( not( taproot) ) ]
39
44
/// Helper to allow DynSigner to clone itself
40
45
pub trait InnerSign : EcdsaChannelSigner + Send + Sync {
41
46
/// Clone into a Box
@@ -46,6 +51,17 @@ pub trait InnerSign: EcdsaChannelSigner + Send + Sync {
46
51
fn vwrite ( & self , writer : & mut Vec < u8 > ) -> Result < ( ) , Error > ;
47
52
}
48
53
54
+ #[ cfg( taproot) ]
55
+ /// Helper to allow DynSigner to clone itself
56
+ pub trait InnerSign : EcdsaChannelSigner + TaprootChannelSigner + Send + Sync {
57
+ /// Clone into a Box
58
+ fn box_clone ( & self ) -> Box < dyn crate :: util:: dyn_signer:: InnerSign > ;
59
+ /// Cast to Any for runtime type checking
60
+ fn as_any ( & self ) -> & dyn Any ;
61
+ /// Serialize the signer
62
+ fn vwrite ( & self , writer : & mut Vec < u8 > ) -> Result < ( ) , Error > ;
63
+ }
64
+
49
65
/// A ChannelSigner derived struct allowing run-time selection of a signer
50
66
pub struct DynSigner {
51
67
/// The inner signer
@@ -61,6 +77,45 @@ impl DynSigner {
61
77
62
78
impl WriteableEcdsaChannelSigner for DynSigner { }
63
79
80
+ #[ allow( unused_variables) ]
81
+ impl TaprootChannelSigner for DynSigner {
82
+ fn generate_local_nonce_pair ( & self , commitment_number : u64 , secp_ctx : & Secp256k1 < All > ) -> PublicNonce {
83
+ todo ! ( )
84
+ }
85
+
86
+ fn partially_sign_counterparty_commitment ( & self , counterparty_nonce : PublicNonce , commitment_tx : & CommitmentTransaction , inbound_htlc_preimages : Vec < PaymentPreimage > , outbound_htlc_preimages : Vec < PaymentPreimage > , secp_ctx : & Secp256k1 < All > ) -> Result < ( crate :: ln:: msgs:: PartialSignatureWithNonce , Vec < secp256k1:: schnorr:: Signature > ) , ( ) > {
87
+ todo ! ( ) ;
88
+ }
89
+
90
+ fn finalize_holder_commitment ( & self , commitment_tx : & HolderCommitmentTransaction , counterparty_partial_signature : crate :: ln:: msgs:: PartialSignatureWithNonce , secp_ctx : & Secp256k1 < All > ) -> Result < PartialSignature , ( ) > {
91
+ todo ! ( ) ;
92
+ }
93
+
94
+ fn sign_justice_revoked_output ( & self , justice_tx : & Transaction , input : usize , amount : u64 , per_commitment_key : & SecretKey , secp_ctx : & Secp256k1 < All > ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
95
+ todo ! ( ) ;
96
+ }
97
+
98
+ fn sign_justice_revoked_htlc ( & self , justice_tx : & Transaction , input : usize , amount : u64 , per_commitment_key : & SecretKey , htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < All > ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
99
+ todo ! ( ) ;
100
+ }
101
+
102
+ fn sign_holder_htlc_transaction ( & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor , secp_ctx : & Secp256k1 < All > ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
103
+ todo ! ( ) ;
104
+ }
105
+
106
+ fn sign_counterparty_htlc_transaction ( & self , htlc_tx : & Transaction , input : usize , amount : u64 , per_commitment_point : & PublicKey , htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < All > ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
107
+ todo ! ( ) ;
108
+ }
109
+
110
+ fn partially_sign_closing_transaction ( & self , closing_tx : & ClosingTransaction , secp_ctx : & Secp256k1 < All > ) -> Result < PartialSignature , ( ) > {
111
+ todo ! ( ) ;
112
+ }
113
+
114
+ fn sign_holder_anchor_input ( & self , anchor_tx : & Transaction , input : usize , secp_ctx : & Secp256k1 < All > ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
115
+ todo ! ( ) ;
116
+ }
117
+ }
118
+
64
119
impl Clone for DynSigner {
65
120
fn clone ( & self ) -> Self {
66
121
DynSigner { inner : self . inner . box_clone ( ) }
@@ -75,69 +130,85 @@ impl Readable for DynSigner {
75
130
}
76
131
77
132
impl EcdsaChannelSigner for DynSigner {
78
- delegate ! {
79
- to self . inner {
80
- fn sign_holder_commitment (
81
- & self , commitment_tx: & HolderCommitmentTransaction , secp_ctx: & Secp256k1 <secp256k1 :: All > ,
82
- ) -> Result < Signature , ( ) > ;
133
+ fn sign_holder_commitment (
134
+ & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < secp256k1 :: All > ,
135
+ ) -> Result < Signature , ( ) > {
136
+ self . inner . sign_holder_commitment ( commitment_tx, secp_ctx)
137
+ }
83
138
84
- #[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
85
- fn unsafe_sign_holder_commitment(
86
- & self , commitment_tx: & HolderCommitmentTransaction , secp_ctx: & Secp256k1 <secp256k1:: All >,
87
- ) -> Result <Signature , ( ) >;
139
+ #[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
140
+ fn unsafe_sign_holder_commitment (
141
+ & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < secp256k1:: All > ,
142
+ ) -> Result < Signature , ( ) > {
143
+ self . inner . unsafe_sign_holder_commitment ( commitment_tx, secp_ctx)
144
+ }
88
145
89
- fn sign_counterparty_commitment(
90
- & self , commitment_tx: & CommitmentTransaction , inbound_htlc_preimages: Vec <PaymentPreimage >,
91
- outbound_htlc_preimages: Vec <PaymentPreimage >, secp_ctx: & Secp256k1 <secp256k1:: All >,
92
- ) -> Result <( Signature , Vec <Signature >) , ( ) >;
146
+ fn sign_counterparty_commitment (
147
+ & self , commitment_tx : & CommitmentTransaction , inbound_htlc_preimages : Vec < PaymentPreimage > ,
148
+ outbound_htlc_preimages : Vec < PaymentPreimage > , secp_ctx : & Secp256k1 < secp256k1:: All > ,
149
+ ) -> Result < ( Signature , Vec < Signature > ) , ( ) > {
150
+ self . inner . sign_counterparty_commitment ( commitment_tx, inbound_htlc_preimages, outbound_htlc_preimages, secp_ctx)
151
+ }
93
152
94
- fn sign_justice_revoked_output(
95
- & self ,
96
- justice_tx: & Transaction ,
97
- input: usize ,
98
- amount: u64 ,
99
- per_commitment_key: & SecretKey ,
100
- secp_ctx: & Secp256k1 <secp256k1:: All >,
101
- ) -> Result <Signature , ( ) >;
153
+ fn sign_justice_revoked_output (
154
+ & self ,
155
+ justice_tx : & Transaction ,
156
+ input : usize ,
157
+ amount : u64 ,
158
+ per_commitment_key : & SecretKey ,
159
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
160
+ ) -> Result < Signature , ( ) > {
161
+ EcdsaChannelSigner :: sign_justice_revoked_output ( & * self . inner , justice_tx, input, amount, per_commitment_key, secp_ctx)
162
+ }
102
163
103
- fn sign_justice_revoked_htlc(
104
- & self ,
105
- justice_tx: & Transaction ,
106
- input: usize ,
107
- amount: u64 ,
108
- per_commitment_key: & SecretKey ,
109
- htlc: & HTLCOutputInCommitment ,
110
- secp_ctx: & Secp256k1 <secp256k1:: All >,
111
- ) -> Result <Signature , ( ) >;
164
+ fn sign_justice_revoked_htlc (
165
+ & self ,
166
+ justice_tx : & Transaction ,
167
+ input : usize ,
168
+ amount : u64 ,
169
+ per_commitment_key : & SecretKey ,
170
+ htlc : & HTLCOutputInCommitment ,
171
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
172
+ ) -> Result < Signature , ( ) > {
173
+ EcdsaChannelSigner :: sign_justice_revoked_htlc ( & * self . inner , justice_tx, input, amount, per_commitment_key, htlc, secp_ctx)
174
+ }
112
175
113
- fn sign_counterparty_htlc_transaction(
114
- & self ,
115
- htlc_tx: & Transaction ,
116
- input: usize ,
117
- amount: u64 ,
118
- per_commitment_point: & PublicKey ,
119
- htlc: & HTLCOutputInCommitment ,
120
- secp_ctx: & Secp256k1 <secp256k1:: All >,
121
- ) -> Result <Signature , ( ) >;
176
+ fn sign_counterparty_htlc_transaction (
177
+ & self ,
178
+ htlc_tx : & Transaction ,
179
+ input : usize ,
180
+ amount : u64 ,
181
+ per_commitment_point : & PublicKey ,
182
+ htlc : & HTLCOutputInCommitment ,
183
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
184
+ ) -> Result < Signature , ( ) > {
185
+ EcdsaChannelSigner :: sign_counterparty_htlc_transaction ( & * self . inner , htlc_tx, input, amount, per_commitment_point, htlc, secp_ctx)
186
+ }
122
187
123
- fn sign_closing_transaction(
124
- & self ,
125
- closing_tx: & ClosingTransaction ,
126
- secp_ctx: & Secp256k1 <secp256k1:: All >,
127
- ) -> Result <Signature , ( ) >;
188
+ fn sign_closing_transaction (
189
+ & self ,
190
+ closing_tx : & ClosingTransaction ,
191
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
192
+ ) -> Result < Signature , ( ) > {
193
+ self . inner . sign_closing_transaction ( closing_tx, secp_ctx)
194
+ }
128
195
129
- fn sign_channel_announcement_with_funding_key(
130
- & self ,
131
- msg: & UnsignedChannelAnnouncement ,
132
- secp_ctx: & Secp256k1 <secp256k1:: All >,
133
- ) -> Result <Signature , ( ) >;
196
+ fn sign_channel_announcement_with_funding_key (
197
+ & self ,
198
+ msg : & UnsignedChannelAnnouncement ,
199
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
200
+ ) -> Result < Signature , ( ) > {
201
+ self . inner . sign_channel_announcement_with_funding_key ( msg, secp_ctx)
202
+ }
134
203
135
- fn sign_holder_anchor_input(
136
- & self , anchor_tx: & Transaction , input: usize , secp_ctx: & Secp256k1 <secp256k1:: All >,
137
- ) -> Result <Signature , ( ) >;
204
+ fn sign_holder_anchor_input (
205
+ & self , anchor_tx : & Transaction , input : usize , secp_ctx : & Secp256k1 < secp256k1:: All > ,
206
+ ) -> Result < Signature , ( ) > {
207
+ EcdsaChannelSigner :: sign_holder_anchor_input ( & * self . inner , anchor_tx, input, secp_ctx)
208
+ }
138
209
139
- fn sign_holder_htlc_transaction( & self , htlc_tx: & Transaction , input: usize , htlc_descriptor: & HTLCDescriptor , secp_ctx: & Secp256k1 <All >) -> Result <Signature , ( ) >;
140
- }
210
+ fn sign_holder_htlc_transaction ( & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor , secp_ctx : & Secp256k1 < All > ) -> Result < Signature , ( ) > {
211
+ EcdsaChannelSigner :: sign_holder_htlc_transaction ( & * self . inner , htlc_tx , input , htlc_descriptor , secp_ctx )
141
212
}
142
213
}
143
214
@@ -200,12 +271,12 @@ impl InnerSign for InMemorySigner {
200
271
/// A convenience wrapper for DynKeysInterfaceTrait
201
272
pub struct DynKeysInterface {
202
273
/// The inner dyn keys interface
203
- pub inner : Box < dyn DynKeysInterfaceTrait < EcdsaSigner = DynSigner > > ,
274
+ pub inner : Box < dyn DynKeysInterfaceTrait > ,
204
275
}
205
276
206
277
impl DynKeysInterface {
207
278
/// Create a new DynKeysInterface
208
- pub fn new ( inner : Box < dyn DynKeysInterfaceTrait < EcdsaSigner = DynSigner > > ) -> Self {
279
+ pub fn new ( inner : Box < dyn DynKeysInterfaceTrait > ) -> Self {
209
280
DynKeysInterface { inner }
210
281
}
211
282
}
@@ -239,6 +310,8 @@ impl NodeSigner for DynKeysInterface {
239
310
240
311
impl SignerProvider for DynKeysInterface {
241
312
type EcdsaSigner = DynSigner ;
313
+ #[ cfg( taproot) ]
314
+ type TaprootSigner = DynSigner ;
242
315
243
316
delegate ! {
244
317
to self . inner {
@@ -275,10 +348,16 @@ impl OutputSpender for DynKeysInterface {
275
348
}
276
349
}
277
350
351
+ #[ cfg( not( taproot) ) ]
278
352
/// A supertrait for all the traits that a keys interface implements
279
353
pub trait DynKeysInterfaceTrait : NodeSigner + OutputSpender + SignerProvider < EcdsaSigner =DynSigner > + EntropySource + Send + Sync {
280
354
}
281
355
356
+ #[ cfg( taproot) ]
357
+ /// A supertrait for all the traits that a keys interface implements
358
+ pub trait DynKeysInterfaceTrait : NodeSigner + OutputSpender + SignerProvider < EcdsaSigner =DynSigner , TaprootSigner =DynSigner > + EntropySource + Send + Sync {
359
+ }
360
+
282
361
/// A dyn wrapper for PhantomKeysManager
283
362
pub struct DynPhantomKeysInterface {
284
363
inner : PhantomKeysManager ,
@@ -320,6 +399,8 @@ impl NodeSigner for DynPhantomKeysInterface {
320
399
321
400
impl SignerProvider for DynPhantomKeysInterface {
322
401
type EcdsaSigner = DynSigner ;
402
+ #[ cfg( taproot) ]
403
+ type TaprootSigner = DynSigner ;
323
404
324
405
delegate ! {
325
406
to self . inner {
0 commit comments