Skip to content

Commit fddbd59

Browse files
committed
Add TaprootSigner variant to SignerProvider.
1 parent 5e87b8f commit fddbd59

File tree

8 files changed

+111
-5
lines changed

8 files changed

+111
-5
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ impl NodeSigner for KeyProvider {
235235

236236
impl SignerProvider for KeyProvider {
237237
type EcdsaSigner = EnforcingSigner;
238+
#[cfg(taproot)]
239+
type TaprootSigner = EnforcingSigner;
238240

239241
fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] {
240242
let id = self.rand_bytes_id.fetch_add(1, atomic::Ordering::Relaxed) as u8;

fuzz/src/full_stack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ impl NodeSigner for KeyProvider {
340340

341341
impl SignerProvider for KeyProvider {
342342
type EcdsaSigner = EnforcingSigner;
343+
#[cfg(taproot)]
344+
type TaprootSigner = EnforcingSigner;
343345

344346
fn generate_channel_keys_id(&self, inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] {
345347
let ctr = self.counter.fetch_add(1, Ordering::Relaxed) as u8;

fuzz/src/onion_message.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ impl NodeSigner for KeyProvider {
175175

176176
impl SignerProvider for KeyProvider {
177177
type EcdsaSigner = EnforcingSigner;
178+
#[cfg(taproot)]
179+
type TaprootSigner = EnforcingSigner;
178180

179181
fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] { unreachable!() }
180182

lightning/src/ln/channel.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7544,6 +7544,8 @@ mod tests {
75447544

75457545
impl SignerProvider for Keys {
75467546
type EcdsaSigner = InMemorySigner;
7547+
#[cfg(taproot)]
7548+
type TaprootSigner = InMemorySigner;
75477549

75487550
fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] {
75497551
self.signer.channel_keys_id()

lightning/src/sign/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ use core::sync::atomic::{AtomicUsize, Ordering};
5252
use crate::io::{self, Error};
5353
use crate::ln::features::ChannelTypeFeatures;
5454
use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
55+
#[cfg(taproot)]
56+
use crate::sign::taproot::TaprootChannelSigner;
5557
use crate::util::atomic_counter::AtomicCounter;
5658
use crate::util::chacha20::ChaCha20;
5759
use crate::util::invoice::construct_invoice_preimage;
@@ -670,6 +672,9 @@ pub trait NodeSigner {
670672
pub trait SignerProvider {
671673
/// A type which implements [`WriteableEcdsaChannelSigner`] which will be returned by [`Self::derive_channel_signer`].
672674
type EcdsaSigner: WriteableEcdsaChannelSigner;
675+
#[cfg(taproot)]
676+
/// A type which implements [`TaprootChannelSigner`]
677+
type TaprootSigner: TaprootChannelSigner;
673678

674679
/// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::EcdsaSigner`] through
675680
/// [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
@@ -1513,6 +1518,8 @@ impl NodeSigner for KeysManager {
15131518

15141519
impl SignerProvider for KeysManager {
15151520
type EcdsaSigner = InMemorySigner;
1521+
#[cfg(taproot)]
1522+
type TaprootSigner = InMemorySigner;
15161523

15171524
fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, user_channel_id: u128) -> [u8; 32] {
15181525
let child_idx = self.channel_child_index.fetch_add(1, Ordering::AcqRel);
@@ -1632,6 +1639,8 @@ impl NodeSigner for PhantomKeysManager {
16321639

16331640
impl SignerProvider for PhantomKeysManager {
16341641
type EcdsaSigner = InMemorySigner;
1642+
#[cfg(taproot)]
1643+
type TaprootSigner = InMemorySigner;
16351644

16361645
fn generate_channel_keys_id(&self, inbound: bool, channel_value_satoshis: u64, user_channel_id: u128) -> [u8; 32] {
16371646
self.inner.generate_channel_keys_id(inbound, channel_value_satoshis, user_channel_id)

lightning/src/sign/taproot.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use bitcoin::blockdata::transaction::Transaction;
44
use bitcoin::secp256k1;
55
use bitcoin::secp256k1::{PublicKey, schnorr::Signature, Secp256k1, SecretKey};
6+
#[cfg(taproot)]
7+
use bitcoin::secp256k1::All;
68

79
use musig2::types::{PartialSignature, PublicNonce};
810

@@ -147,3 +149,41 @@ pub trait TaprootChannelSigner: ChannelSigner {
147149

148150
// TODO: sign channel announcement
149151
}
152+
153+
impl TaprootChannelSigner for super::InMemorySigner {
154+
fn generate_local_nonce_pair(&self, secp_ctx: &Secp256k1<All>) -> PublicNonce {
155+
todo!()
156+
}
157+
158+
fn partially_sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction, preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<All>) -> Result<(PartialSignature, Vec<Signature>), ()> {
159+
todo!()
160+
}
161+
162+
fn partially_sign_holder_commitment_and_htlcs(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<All>) -> Result<(PartialSignature, Vec<Signature>), ()> {
163+
todo!()
164+
}
165+
166+
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<All>) -> Result<Signature, ()> {
167+
todo!()
168+
}
169+
170+
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<All>) -> Result<Signature, ()> {
171+
todo!()
172+
}
173+
174+
fn sign_holder_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor, secp_ctx: &Secp256k1<All>) -> Result<Signature, ()> {
175+
todo!()
176+
}
177+
178+
fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<All>) -> Result<Signature, ()> {
179+
todo!()
180+
}
181+
182+
fn partially_sign_closing_transaction(&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<All>) -> Result<PartialSignature, ()> {
183+
todo!()
184+
}
185+
186+
fn sign_holder_anchor_input(&self, anchor_tx: &Transaction, input: usize, secp_ctx: &Secp256k1<All>) -> Result<Signature, ()> {
187+
todo!()
188+
}
189+
}

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ use bitcoin::blockdata::transaction::{Transaction, EcdsaSighashType};
2121
use bitcoin::util::sighash;
2222

2323
use bitcoin::secp256k1;
24+
#[cfg(taproot)]
25+
use bitcoin::secp256k1::All;
2426
use bitcoin::secp256k1::{SecretKey, PublicKey};
2527
use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature};
28+
#[cfg(taproot)]
29+
use musig2::types::{PartialSignature, PublicNonce};
2630
use crate::events::bump_transaction::HTLCDescriptor;
2731
use crate::util::ser::{Writeable, Writer};
2832
use crate::io::Error;
2933
use crate::ln::features::ChannelTypeFeatures;
34+
#[cfg(taproot)]
35+
use crate::sign::taproot::TaprootChannelSigner;
3036

3137
/// Initial value for revoked commitment downward counter
3238
pub const INITIAL_REVOKED_COMMITMENT_NUMBER: u64 = 1 << 48;
@@ -198,11 +204,11 @@ impl EcdsaChannelSigner for EnforcingSigner {
198204
}
199205

200206
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
201-
Ok(self.inner.sign_justice_revoked_output(justice_tx, input, amount, per_commitment_key, secp_ctx).unwrap())
207+
Ok(EcdsaChannelSigner::sign_justice_revoked_output(&self.inner, justice_tx, input, amount, per_commitment_key, secp_ctx).unwrap())
202208
}
203209

204210
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
205-
Ok(self.inner.sign_justice_revoked_htlc(justice_tx, input, amount, per_commitment_key, htlc, secp_ctx).unwrap())
211+
Ok(EcdsaChannelSigner::sign_justice_revoked_htlc(&self.inner, justice_tx, input, amount, per_commitment_key, htlc, secp_ctx).unwrap())
206212
}
207213

208214
fn sign_holder_htlc_transaction(
@@ -211,11 +217,11 @@ impl EcdsaChannelSigner for EnforcingSigner {
211217
) -> Result<Signature, ()> {
212218
assert_eq!(htlc_tx.input[input], htlc_descriptor.unsigned_tx_input());
213219
assert_eq!(htlc_tx.output[input], htlc_descriptor.tx_output(secp_ctx));
214-
Ok(self.inner.sign_holder_htlc_transaction(htlc_tx, input, htlc_descriptor, secp_ctx).unwrap())
220+
Ok(EcdsaChannelSigner::sign_holder_htlc_transaction(&self.inner, htlc_tx, input, htlc_descriptor, secp_ctx).unwrap())
215221
}
216222

217223
fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
218-
Ok(self.inner.sign_counterparty_htlc_transaction(htlc_tx, input, amount, per_commitment_point, htlc, secp_ctx).unwrap())
224+
Ok(EcdsaChannelSigner::sign_counterparty_htlc_transaction(&self.inner, htlc_tx, input, amount, per_commitment_point, htlc, secp_ctx).unwrap())
219225
}
220226

221227
fn sign_closing_transaction(&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
@@ -231,7 +237,7 @@ impl EcdsaChannelSigner for EnforcingSigner {
231237
// As long as our minimum dust limit is enforced and is greater than our anchor output
232238
// value, an anchor output can only have an index within [0, 1].
233239
assert!(anchor_tx.input[input].previous_output.vout == 0 || anchor_tx.input[input].previous_output.vout == 1);
234-
self.inner.sign_holder_anchor_input(anchor_tx, input, secp_ctx)
240+
EcdsaChannelSigner::sign_holder_anchor_input(&self.inner, anchor_tx, input, secp_ctx)
235241
}
236242

237243
fn sign_channel_announcement_with_funding_key(
@@ -243,6 +249,45 @@ impl EcdsaChannelSigner for EnforcingSigner {
243249

244250
impl WriteableEcdsaChannelSigner for EnforcingSigner {}
245251

252+
#[cfg(taproot)]
253+
impl TaprootChannelSigner for EnforcingSigner {
254+
fn generate_local_nonce_pair(&self, secp_ctx: &Secp256k1<All>) -> PublicNonce {
255+
todo!()
256+
}
257+
258+
fn partially_sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction, preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<All>) -> Result<(PartialSignature, Vec<secp256k1::schnorr::Signature>), ()> {
259+
todo!()
260+
}
261+
262+
fn partially_sign_holder_commitment_and_htlcs(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<All>) -> Result<(PartialSignature, Vec<secp256k1::schnorr::Signature>), ()> {
263+
todo!()
264+
}
265+
266+
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, ()> {
267+
todo!()
268+
}
269+
270+
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, ()> {
271+
todo!()
272+
}
273+
274+
fn sign_holder_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor, secp_ctx: &Secp256k1<All>) -> Result<secp256k1::schnorr::Signature, ()> {
275+
todo!()
276+
}
277+
278+
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, ()> {
279+
todo!()
280+
}
281+
282+
fn partially_sign_closing_transaction(&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<All>) -> Result<PartialSignature, ()> {
283+
todo!()
284+
}
285+
286+
fn sign_holder_anchor_input(&self, anchor_tx: &Transaction, input: usize, secp_ctx: &Secp256k1<All>) -> Result<secp256k1::schnorr::Signature, ()> {
287+
todo!()
288+
}
289+
}
290+
246291
impl Writeable for EnforcingSigner {
247292
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
248293
// EnforcingSigner has two fields - `inner` ([`InMemorySigner`]) and `state`

lightning/src/util/test_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ impl EntropySource for OnlyReadsKeysInterface {
172172

173173
impl SignerProvider for OnlyReadsKeysInterface {
174174
type EcdsaSigner = EnforcingSigner;
175+
#[cfg(taproot)]
176+
type TaprootSigner = EnforcingSigner;
175177

176178
fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] { unreachable!(); }
177179

@@ -874,6 +876,8 @@ impl NodeSigner for TestKeysInterface {
874876

875877
impl SignerProvider for TestKeysInterface {
876878
type EcdsaSigner = EnforcingSigner;
879+
#[cfg(taproot)]
880+
type TaprootSigner = EnforcingSigner;
877881

878882
fn generate_channel_keys_id(&self, inbound: bool, channel_value_satoshis: u64, user_channel_id: u128) -> [u8; 32] {
879883
self.backing.generate_channel_keys_id(inbound, channel_value_satoshis, user_channel_id)

0 commit comments

Comments
 (0)