@@ -16,6 +16,8 @@ use crate::ln::msgs::{DecodeError, UnsignedChannelAnnouncement, UnsignedGossipMe
16
16
use crate :: ln:: script:: ShutdownScript ;
17
17
use crate :: ln:: PaymentPreimage ;
18
18
use crate :: sign:: ecdsa:: EcdsaChannelSigner ;
19
+ #[ cfg( taproot) ]
20
+ use crate :: sign:: taproot:: TaprootChannelSigner ;
19
21
use crate :: sign:: ChannelSigner ;
20
22
use crate :: sign:: InMemorySigner ;
21
23
use crate :: sign:: {
@@ -32,16 +34,28 @@ use bitcoin::absolute::LockTime;
32
34
use bitcoin:: bech32:: u5;
33
35
use bitcoin:: secp256k1:: All ;
34
36
use bitcoin:: { secp256k1, ScriptBuf , Transaction , TxOut } ;
37
+ #[ cfg( taproot) ]
38
+ use musig2:: types:: { PartialSignature , PublicNonce } ;
35
39
use secp256k1:: ecdsa:: RecoverableSignature ;
36
40
use secp256k1:: { ecdh:: SharedSecret , ecdsa:: Signature , PublicKey , Scalar , Secp256k1 , SecretKey } ;
37
41
42
+ #[ cfg( not( taproot) ) ]
43
+ /// A super-trait for all the traits that a dyn signer backing implements
44
+ pub trait DynSignerTrait : EcdsaChannelSigner + Send + Sync { }
45
+
46
+ #[ cfg( taproot) ]
47
+ /// A super-trait for all the traits that a dyn signer backing implements
48
+ pub trait DynSignerTrait : EcdsaChannelSigner + TaprootChannelSigner + Send + Sync { }
49
+
38
50
/// Helper to allow DynSigner to clone itself
39
- pub trait InnerSign : EcdsaChannelSigner + Send + Sync {
51
+ pub trait InnerSign : DynSignerTrait {
40
52
/// Clone into a Box
41
53
fn box_clone ( & self ) -> Box < dyn InnerSign > ;
42
54
/// Cast to Any for runtime type checking
43
55
fn as_any ( & self ) -> & dyn Any ;
44
- /// Serialize the signer
56
+ /// Serialize the signer.
57
+ /// We can't have a write method with a generic (i.e. `Writeable`) because that would make signers
58
+ /// dyn object incompatible.
45
59
fn vwrite ( & self , writer : & mut Vec < u8 > ) -> Result < ( ) , Error > ;
46
60
}
47
61
@@ -60,6 +74,73 @@ impl DynSigner {
60
74
61
75
impl WriteableEcdsaChannelSigner for DynSigner { }
62
76
77
+ #[ cfg( taproot) ]
78
+ #[ allow( unused_variables) ]
79
+ impl TaprootChannelSigner for DynSigner {
80
+ fn generate_local_nonce_pair (
81
+ & self , commitment_number : u64 , secp_ctx : & Secp256k1 < All > ,
82
+ ) -> PublicNonce {
83
+ todo ! ( )
84
+ }
85
+
86
+ fn partially_sign_counterparty_commitment (
87
+ & self , counterparty_nonce : PublicNonce , commitment_tx : & CommitmentTransaction ,
88
+ inbound_htlc_preimages : Vec < PaymentPreimage > ,
89
+ outbound_htlc_preimages : Vec < PaymentPreimage > , secp_ctx : & Secp256k1 < All > ,
90
+ ) -> Result < ( crate :: ln:: msgs:: PartialSignatureWithNonce , Vec < secp256k1:: schnorr:: Signature > ) , ( ) >
91
+ {
92
+ todo ! ( ) ;
93
+ }
94
+
95
+ fn finalize_holder_commitment (
96
+ & self , commitment_tx : & HolderCommitmentTransaction ,
97
+ counterparty_partial_signature : crate :: ln:: msgs:: PartialSignatureWithNonce ,
98
+ secp_ctx : & Secp256k1 < All > ,
99
+ ) -> Result < PartialSignature , ( ) > {
100
+ todo ! ( ) ;
101
+ }
102
+
103
+ fn sign_justice_revoked_output (
104
+ & self , justice_tx : & Transaction , input : usize , amount : u64 , per_commitment_key : & SecretKey ,
105
+ secp_ctx : & Secp256k1 < All > ,
106
+ ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
107
+ todo ! ( ) ;
108
+ }
109
+
110
+ fn sign_justice_revoked_htlc (
111
+ & self , justice_tx : & Transaction , input : usize , amount : u64 , per_commitment_key : & SecretKey ,
112
+ htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < All > ,
113
+ ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
114
+ todo ! ( ) ;
115
+ }
116
+
117
+ fn sign_holder_htlc_transaction (
118
+ & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor ,
119
+ secp_ctx : & Secp256k1 < All > ,
120
+ ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
121
+ todo ! ( ) ;
122
+ }
123
+
124
+ fn sign_counterparty_htlc_transaction (
125
+ & self , htlc_tx : & Transaction , input : usize , amount : u64 , per_commitment_point : & PublicKey ,
126
+ htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < All > ,
127
+ ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
128
+ todo ! ( ) ;
129
+ }
130
+
131
+ fn partially_sign_closing_transaction (
132
+ & self , closing_tx : & ClosingTransaction , secp_ctx : & Secp256k1 < All > ,
133
+ ) -> Result < PartialSignature , ( ) > {
134
+ todo ! ( ) ;
135
+ }
136
+
137
+ fn sign_holder_anchor_input (
138
+ & self , anchor_tx : & Transaction , input : usize , secp_ctx : & Secp256k1 < All > ,
139
+ ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
140
+ todo ! ( ) ;
141
+ }
142
+ }
143
+
63
144
impl Clone for DynSigner {
64
145
fn clone ( & self ) -> Self {
65
146
DynSigner { inner : self . inner . box_clone ( ) }
@@ -74,69 +155,104 @@ impl Readable for DynSigner {
74
155
}
75
156
76
157
impl EcdsaChannelSigner for DynSigner {
77
- delegate ! {
78
- to self . inner {
79
- fn sign_holder_commitment (
80
- & self , commitment_tx: & HolderCommitmentTransaction , secp_ctx: & Secp256k1 <secp256k1 :: All > ,
81
- ) -> Result < Signature , ( ) > ;
158
+ fn sign_holder_commitment (
159
+ & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < secp256k1 :: All > ,
160
+ ) -> Result < Signature , ( ) > {
161
+ self . inner . sign_holder_commitment ( commitment_tx, secp_ctx)
162
+ }
82
163
83
- #[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
84
- fn unsafe_sign_holder_commitment(
85
- & self , commitment_tx: & HolderCommitmentTransaction , secp_ctx: & Secp256k1 <secp256k1:: All >,
86
- ) -> Result <Signature , ( ) >;
164
+ #[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
165
+ fn unsafe_sign_holder_commitment (
166
+ & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < secp256k1:: All > ,
167
+ ) -> Result < Signature , ( ) > {
168
+ self . inner . unsafe_sign_holder_commitment ( commitment_tx, secp_ctx)
169
+ }
87
170
88
- fn sign_counterparty_commitment(
89
- & self , commitment_tx: & CommitmentTransaction , inbound_htlc_preimages: Vec <PaymentPreimage >,
90
- outbound_htlc_preimages: Vec <PaymentPreimage >, secp_ctx: & Secp256k1 <secp256k1:: All >,
91
- ) -> Result <( Signature , Vec <Signature >) , ( ) >;
171
+ fn sign_counterparty_commitment (
172
+ & self , commitment_tx : & CommitmentTransaction , inbound_htlc_preimages : Vec < PaymentPreimage > ,
173
+ outbound_htlc_preimages : Vec < PaymentPreimage > , secp_ctx : & Secp256k1 < secp256k1:: All > ,
174
+ ) -> Result < ( Signature , Vec < Signature > ) , ( ) > {
175
+ self . inner . sign_counterparty_commitment (
176
+ commitment_tx,
177
+ inbound_htlc_preimages,
178
+ outbound_htlc_preimages,
179
+ secp_ctx,
180
+ )
181
+ }
92
182
93
- fn sign_justice_revoked_output(
94
- & self ,
95
- justice_tx: & Transaction ,
96
- input: usize ,
97
- amount: u64 ,
98
- per_commitment_key: & SecretKey ,
99
- secp_ctx: & Secp256k1 <secp256k1:: All >,
100
- ) -> Result <Signature , ( ) >;
183
+ fn sign_justice_revoked_output (
184
+ & self , justice_tx : & Transaction , input : usize , amount : u64 , per_commitment_key : & SecretKey ,
185
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
186
+ ) -> Result < Signature , ( ) > {
187
+ EcdsaChannelSigner :: sign_justice_revoked_output (
188
+ & * self . inner ,
189
+ justice_tx,
190
+ input,
191
+ amount,
192
+ per_commitment_key,
193
+ secp_ctx,
194
+ )
195
+ }
101
196
102
- fn sign_justice_revoked_htlc(
103
- & self ,
104
- justice_tx: & Transaction ,
105
- input: usize ,
106
- amount: u64 ,
107
- per_commitment_key: & SecretKey ,
108
- htlc: & HTLCOutputInCommitment ,
109
- secp_ctx: & Secp256k1 <secp256k1:: All >,
110
- ) -> Result <Signature , ( ) >;
197
+ fn sign_justice_revoked_htlc (
198
+ & self , justice_tx : & Transaction , input : usize , amount : u64 , per_commitment_key : & SecretKey ,
199
+ htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < secp256k1:: All > ,
200
+ ) -> Result < Signature , ( ) > {
201
+ EcdsaChannelSigner :: sign_justice_revoked_htlc (
202
+ & * self . inner ,
203
+ justice_tx,
204
+ input,
205
+ amount,
206
+ per_commitment_key,
207
+ htlc,
208
+ secp_ctx,
209
+ )
210
+ }
111
211
112
- fn sign_counterparty_htlc_transaction(
113
- & self ,
114
- htlc_tx: & Transaction ,
115
- input: usize ,
116
- amount: u64 ,
117
- per_commitment_point: & PublicKey ,
118
- htlc: & HTLCOutputInCommitment ,
119
- secp_ctx: & Secp256k1 <secp256k1:: All >,
120
- ) -> Result <Signature , ( ) >;
212
+ fn sign_counterparty_htlc_transaction (
213
+ & self , htlc_tx : & Transaction , input : usize , amount : u64 , per_commitment_point : & PublicKey ,
214
+ htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < secp256k1:: All > ,
215
+ ) -> Result < Signature , ( ) > {
216
+ EcdsaChannelSigner :: sign_counterparty_htlc_transaction (
217
+ & * self . inner ,
218
+ htlc_tx,
219
+ input,
220
+ amount,
221
+ per_commitment_point,
222
+ htlc,
223
+ secp_ctx,
224
+ )
225
+ }
121
226
122
- fn sign_closing_transaction(
123
- & self ,
124
- closing_tx : & ClosingTransaction ,
125
- secp_ctx : & Secp256k1 <secp256k1 :: All > ,
126
- ) -> Result < Signature , ( ) > ;
227
+ fn sign_closing_transaction (
228
+ & self , closing_tx : & ClosingTransaction , secp_ctx : & Secp256k1 < secp256k1 :: All > ,
229
+ ) -> Result < Signature , ( ) > {
230
+ self . inner . sign_closing_transaction ( closing_tx , secp_ctx )
231
+ }
127
232
128
- fn sign_channel_announcement_with_funding_key(
129
- & self ,
130
- msg : & UnsignedChannelAnnouncement ,
131
- secp_ctx : & Secp256k1 <secp256k1 :: All > ,
132
- ) -> Result < Signature , ( ) > ;
233
+ fn sign_channel_announcement_with_funding_key (
234
+ & self , msg : & UnsignedChannelAnnouncement , secp_ctx : & Secp256k1 < secp256k1 :: All > ,
235
+ ) -> Result < Signature , ( ) > {
236
+ self . inner . sign_channel_announcement_with_funding_key ( msg , secp_ctx )
237
+ }
133
238
134
- fn sign_holder_anchor_input(
135
- & self , anchor_tx: & Transaction , input: usize , secp_ctx: & Secp256k1 <secp256k1:: All >,
136
- ) -> Result <Signature , ( ) >;
239
+ fn sign_holder_anchor_input (
240
+ & self , anchor_tx : & Transaction , input : usize , secp_ctx : & Secp256k1 < secp256k1:: All > ,
241
+ ) -> Result < Signature , ( ) > {
242
+ EcdsaChannelSigner :: sign_holder_anchor_input ( & * self . inner , anchor_tx, input, secp_ctx)
243
+ }
137
244
138
- fn sign_holder_htlc_transaction( & self , htlc_tx: & Transaction , input: usize , htlc_descriptor: & HTLCDescriptor , secp_ctx: & Secp256k1 <All >) -> Result <Signature , ( ) >;
139
- }
245
+ fn sign_holder_htlc_transaction (
246
+ & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor ,
247
+ secp_ctx : & Secp256k1 < All > ,
248
+ ) -> Result < Signature , ( ) > {
249
+ EcdsaChannelSigner :: sign_holder_htlc_transaction (
250
+ & * self . inner ,
251
+ htlc_tx,
252
+ input,
253
+ htlc_descriptor,
254
+ secp_ctx,
255
+ )
140
256
}
141
257
}
142
258
@@ -181,6 +297,8 @@ impl Writeable for DynSigner {
181
297
}
182
298
}
183
299
300
+ impl DynSignerTrait for InMemorySigner { }
301
+
184
302
impl InnerSign for InMemorySigner {
185
303
fn box_clone ( & self ) -> Box < dyn InnerSign > {
186
304
Box :: new ( self . clone ( ) )
@@ -198,12 +316,12 @@ impl InnerSign for InMemorySigner {
198
316
/// A convenience wrapper for DynKeysInterfaceTrait
199
317
pub struct DynKeysInterface {
200
318
/// The inner dyn keys interface
201
- pub inner : Box < dyn DynKeysInterfaceTrait < EcdsaSigner = DynSigner > > ,
319
+ pub inner : Box < dyn DynKeysInterfaceTrait > ,
202
320
}
203
321
204
322
impl DynKeysInterface {
205
323
/// Create a new DynKeysInterface
206
- pub fn new ( inner : Box < dyn DynKeysInterfaceTrait < EcdsaSigner = DynSigner > > ) -> Self {
324
+ pub fn new ( inner : Box < dyn DynKeysInterfaceTrait > ) -> Self {
207
325
DynKeysInterface { inner }
208
326
}
209
327
}
@@ -237,6 +355,8 @@ impl NodeSigner for DynKeysInterface {
237
355
238
356
impl SignerProvider for DynKeysInterface {
239
357
type EcdsaSigner = DynSigner ;
358
+ #[ cfg( taproot) ]
359
+ type TaprootSigner = DynSigner ;
240
360
241
361
delegate ! {
242
362
to self . inner {
@@ -273,12 +393,25 @@ impl OutputSpender for DynKeysInterface {
273
393
}
274
394
}
275
395
396
+ #[ cfg( not( taproot) ) ]
276
397
/// A supertrait for all the traits that a keys interface implements
277
398
pub trait DynKeysInterfaceTrait :
278
399
NodeSigner + OutputSpender + SignerProvider < EcdsaSigner = DynSigner > + EntropySource + Send + Sync
279
400
{
280
401
}
281
402
403
+ #[ cfg( taproot) ]
404
+ /// A supertrait for all the traits that a keys interface implements
405
+ pub trait DynKeysInterfaceTrait :
406
+ NodeSigner
407
+ + OutputSpender
408
+ + SignerProvider < EcdsaSigner = DynSigner , TaprootSigner = DynSigner >
409
+ + EntropySource
410
+ + Send
411
+ + Sync
412
+ {
413
+ }
414
+
282
415
/// A dyn wrapper for PhantomKeysManager
283
416
pub struct DynPhantomKeysInterface {
284
417
inner : PhantomKeysManager ,
@@ -320,6 +453,8 @@ impl NodeSigner for DynPhantomKeysInterface {
320
453
321
454
impl SignerProvider for DynPhantomKeysInterface {
322
455
type EcdsaSigner = DynSigner ;
456
+ #[ cfg( taproot) ]
457
+ type TaprootSigner = DynSigner ;
323
458
324
459
delegate ! {
325
460
to self . inner {
0 commit comments