@@ -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,46 @@ impl DynSigner {
61
77
62
78
impl WriteableEcdsaChannelSigner for DynSigner { }
63
79
80
+ #[ cfg( taproot) ]
81
+ #[ allow( unused_variables) ]
82
+ impl TaprootChannelSigner for DynSigner {
83
+ fn generate_local_nonce_pair ( & self , commitment_number : u64 , secp_ctx : & Secp256k1 < All > ) -> PublicNonce {
84
+ todo ! ( )
85
+ }
86
+
87
+ 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 > ) , ( ) > {
88
+ todo ! ( ) ;
89
+ }
90
+
91
+ fn finalize_holder_commitment ( & self , commitment_tx : & HolderCommitmentTransaction , counterparty_partial_signature : crate :: ln:: msgs:: PartialSignatureWithNonce , secp_ctx : & Secp256k1 < All > ) -> Result < PartialSignature , ( ) > {
92
+ todo ! ( ) ;
93
+ }
94
+
95
+ 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 , ( ) > {
96
+ todo ! ( ) ;
97
+ }
98
+
99
+ 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 , ( ) > {
100
+ todo ! ( ) ;
101
+ }
102
+
103
+ fn sign_holder_htlc_transaction ( & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor , secp_ctx : & Secp256k1 < All > ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
104
+ todo ! ( ) ;
105
+ }
106
+
107
+ 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 , ( ) > {
108
+ todo ! ( ) ;
109
+ }
110
+
111
+ fn partially_sign_closing_transaction ( & self , closing_tx : & ClosingTransaction , secp_ctx : & Secp256k1 < All > ) -> Result < PartialSignature , ( ) > {
112
+ todo ! ( ) ;
113
+ }
114
+
115
+ fn sign_holder_anchor_input ( & self , anchor_tx : & Transaction , input : usize , secp_ctx : & Secp256k1 < All > ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
116
+ todo ! ( ) ;
117
+ }
118
+ }
119
+
64
120
impl Clone for DynSigner {
65
121
fn clone ( & self ) -> Self {
66
122
DynSigner { inner : self . inner . box_clone ( ) }
@@ -75,69 +131,85 @@ impl Readable for DynSigner {
75
131
}
76
132
77
133
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 , ( ) > ;
134
+ fn sign_holder_commitment (
135
+ & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < secp256k1 :: All > ,
136
+ ) -> Result < Signature , ( ) > {
137
+ self . inner . sign_holder_commitment ( commitment_tx, secp_ctx)
138
+ }
83
139
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 , ( ) >;
140
+ #[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
141
+ fn unsafe_sign_holder_commitment (
142
+ & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < secp256k1:: All > ,
143
+ ) -> Result < Signature , ( ) > {
144
+ self . inner . unsafe_sign_holder_commitment ( commitment_tx, secp_ctx)
145
+ }
88
146
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 >) , ( ) >;
147
+ fn sign_counterparty_commitment (
148
+ & self , commitment_tx : & CommitmentTransaction , inbound_htlc_preimages : Vec < PaymentPreimage > ,
149
+ outbound_htlc_preimages : Vec < PaymentPreimage > , secp_ctx : & Secp256k1 < secp256k1:: All > ,
150
+ ) -> Result < ( Signature , Vec < Signature > ) , ( ) > {
151
+ self . inner . sign_counterparty_commitment ( commitment_tx, inbound_htlc_preimages, outbound_htlc_preimages, secp_ctx)
152
+ }
93
153
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 , ( ) >;
154
+ fn sign_justice_revoked_output (
155
+ & self ,
156
+ justice_tx : & Transaction ,
157
+ input : usize ,
158
+ amount : u64 ,
159
+ per_commitment_key : & SecretKey ,
160
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
161
+ ) -> Result < Signature , ( ) > {
162
+ EcdsaChannelSigner :: sign_justice_revoked_output ( & * self . inner , justice_tx, input, amount, per_commitment_key, secp_ctx)
163
+ }
102
164
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 , ( ) >;
165
+ fn sign_justice_revoked_htlc (
166
+ & self ,
167
+ justice_tx : & Transaction ,
168
+ input : usize ,
169
+ amount : u64 ,
170
+ per_commitment_key : & SecretKey ,
171
+ htlc : & HTLCOutputInCommitment ,
172
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
173
+ ) -> Result < Signature , ( ) > {
174
+ EcdsaChannelSigner :: sign_justice_revoked_htlc ( & * self . inner , justice_tx, input, amount, per_commitment_key, htlc, secp_ctx)
175
+ }
112
176
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 , ( ) >;
177
+ fn sign_counterparty_htlc_transaction (
178
+ & self ,
179
+ htlc_tx : & Transaction ,
180
+ input : usize ,
181
+ amount : u64 ,
182
+ per_commitment_point : & PublicKey ,
183
+ htlc : & HTLCOutputInCommitment ,
184
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
185
+ ) -> Result < Signature , ( ) > {
186
+ EcdsaChannelSigner :: sign_counterparty_htlc_transaction ( & * self . inner , htlc_tx, input, amount, per_commitment_point, htlc, secp_ctx)
187
+ }
122
188
123
- fn sign_closing_transaction(
124
- & self ,
125
- closing_tx: & ClosingTransaction ,
126
- secp_ctx: & Secp256k1 <secp256k1:: All >,
127
- ) -> Result <Signature , ( ) >;
189
+ fn sign_closing_transaction (
190
+ & self ,
191
+ closing_tx : & ClosingTransaction ,
192
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
193
+ ) -> Result < Signature , ( ) > {
194
+ self . inner . sign_closing_transaction ( closing_tx, secp_ctx)
195
+ }
128
196
129
- fn sign_channel_announcement_with_funding_key(
130
- & self ,
131
- msg: & UnsignedChannelAnnouncement ,
132
- secp_ctx: & Secp256k1 <secp256k1:: All >,
133
- ) -> Result <Signature , ( ) >;
197
+ fn sign_channel_announcement_with_funding_key (
198
+ & self ,
199
+ msg : & UnsignedChannelAnnouncement ,
200
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
201
+ ) -> Result < Signature , ( ) > {
202
+ self . inner . sign_channel_announcement_with_funding_key ( msg, secp_ctx)
203
+ }
134
204
135
- fn sign_holder_anchor_input(
136
- & self , anchor_tx: & Transaction , input: usize , secp_ctx: & Secp256k1 <secp256k1:: All >,
137
- ) -> Result <Signature , ( ) >;
205
+ fn sign_holder_anchor_input (
206
+ & self , anchor_tx : & Transaction , input : usize , secp_ctx : & Secp256k1 < secp256k1:: All > ,
207
+ ) -> Result < Signature , ( ) > {
208
+ EcdsaChannelSigner :: sign_holder_anchor_input ( & * self . inner , anchor_tx, input, secp_ctx)
209
+ }
138
210
139
- fn sign_holder_htlc_transaction( & self , htlc_tx: & Transaction , input: usize , htlc_descriptor: & HTLCDescriptor , secp_ctx: & Secp256k1 <All >) -> Result <Signature , ( ) >;
140
- }
211
+ fn sign_holder_htlc_transaction ( & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor , secp_ctx : & Secp256k1 < All > ) -> Result < Signature , ( ) > {
212
+ EcdsaChannelSigner :: sign_holder_htlc_transaction ( & * self . inner , htlc_tx , input , htlc_descriptor , secp_ctx )
141
213
}
142
214
}
143
215
@@ -200,12 +272,12 @@ impl InnerSign for InMemorySigner {
200
272
/// A convenience wrapper for DynKeysInterfaceTrait
201
273
pub struct DynKeysInterface {
202
274
/// The inner dyn keys interface
203
- pub inner : Box < dyn DynKeysInterfaceTrait < EcdsaSigner = DynSigner > > ,
275
+ pub inner : Box < dyn DynKeysInterfaceTrait > ,
204
276
}
205
277
206
278
impl DynKeysInterface {
207
279
/// Create a new DynKeysInterface
208
- pub fn new ( inner : Box < dyn DynKeysInterfaceTrait < EcdsaSigner = DynSigner > > ) -> Self {
280
+ pub fn new ( inner : Box < dyn DynKeysInterfaceTrait > ) -> Self {
209
281
DynKeysInterface { inner }
210
282
}
211
283
}
@@ -239,6 +311,8 @@ impl NodeSigner for DynKeysInterface {
239
311
240
312
impl SignerProvider for DynKeysInterface {
241
313
type EcdsaSigner = DynSigner ;
314
+ #[ cfg( taproot) ]
315
+ type TaprootSigner = DynSigner ;
242
316
243
317
delegate ! {
244
318
to self . inner {
@@ -275,10 +349,16 @@ impl OutputSpender for DynKeysInterface {
275
349
}
276
350
}
277
351
352
+ #[ cfg( not( taproot) ) ]
278
353
/// A supertrait for all the traits that a keys interface implements
279
354
pub trait DynKeysInterfaceTrait : NodeSigner + OutputSpender + SignerProvider < EcdsaSigner =DynSigner > + EntropySource + Send + Sync {
280
355
}
281
356
357
+ #[ cfg( taproot) ]
358
+ /// A supertrait for all the traits that a keys interface implements
359
+ pub trait DynKeysInterfaceTrait : NodeSigner + OutputSpender + SignerProvider < EcdsaSigner =DynSigner , TaprootSigner =DynSigner > + EntropySource + Send + Sync {
360
+ }
361
+
282
362
/// A dyn wrapper for PhantomKeysManager
283
363
pub struct DynPhantomKeysInterface {
284
364
inner : PhantomKeysManager ,
@@ -320,6 +400,8 @@ impl NodeSigner for DynPhantomKeysInterface {
320
400
321
401
impl SignerProvider for DynPhantomKeysInterface {
322
402
type EcdsaSigner = DynSigner ;
403
+ #[ cfg( taproot) ]
404
+ type TaprootSigner = DynSigner ;
323
405
324
406
delegate ! {
325
407
to self . inner {
0 commit comments