Skip to content

Instantly share code, notes, and snippets.

@vincenzopalazzo
Last active January 15, 2025 18:48
Show Gist options
  • Save vincenzopalazzo/3e6bab3a522226bf1d9c2e434ea082e9 to your computer and use it in GitHub Desktop.
Save vincenzopalazzo/3e6bab3a522226bf1d9c2e434ea082e9 to your computer and use it in GitHub Desktop.
diff --git a/vls-core/src/channel.rs b/vls-core/src/channel.rs
index 99825743..7aa2c398 100644
--- a/vls-core/src/channel.rs
+++ b/vls-core/src/channel.rs
@@ -2537,6 +2537,7 @@ impl Channel {
pub fn sign_holder_htlc_tx_phase2(
&self,
tx: &Transaction,
+ witness_script: &ScriptBuf,
commitment_number: u64,
feerate: u32,
is_offered: bool,
@@ -2544,7 +2545,7 @@ impl Channel {
htlc_amount_msat: u64,
payment_hash: PaymentHash,
) -> Result<TypedSignature, Status> {
- self.sing_holder_htlc_tx(tx, 0, commitment_number, htlc_amount_msat, &self.secp_ctx)
+ self.sing_holder_htlc_tx(tx, witness_script, 0, commitment_number, htlc_amount_msat, &self.secp_ctx)
}
/// Phase 1
@@ -2574,6 +2575,7 @@ impl Channel {
fn sing_holder_htlc_tx(
&self,
htlc_tx: &Transaction,
+ witness_script: &ScriptBuf,
input: usize,
commitment_number: u64,
amount_msat: u64,
@@ -2598,9 +2600,6 @@ impl Channel {
let per_commitment_point = self.get_per_commitment_point(commitment_number)?;
- // TODO(vincenzopalazzo): We should get somehow the witness script here, but without `HtlcDescriptor` we need a lot of code
- // or I am missing something in there or we can pass down script as a parameter of the function.
- let witness_script = ScriptBuf::new();
let sighash = &sighash::SighashCache::new(htlc_tx)
.segwit_signature_hash(input, &witness_script, amount_msat, EcdsaSighashType::All)
.unwrap();
diff --git a/vls-protocol-client/src/lib.rs b/vls-protocol-client/src/lib.rs
index 9040e5a8..cb389777 100644
--- a/vls-protocol-client/src/lib.rs
+++ b/vls-protocol-client/src/lib.rs
@@ -269,9 +269,10 @@ impl EcdsaChannelSigner for SignerClient {
htlc_tx: &Transaction,
input: usize,
htlc_descriptor: &HTLCDescriptor,
- _secp_ctx: &Secp256k1<All>,
+ secp_ctx: &Secp256k1<All>,
) -> Result<Signature, ()> {
let htlc = &htlc_descriptor.htlc;
+ let witness_script = htlc_descriptor.witness_script(secp_ctx);
let message = SignLocalHtlcTx2 {
per_commitment_number: htlc_descriptor.per_commitment_number,
feerate_per_kw: htlc_descriptor.feerate_per_kw,
@@ -281,6 +282,7 @@ impl EcdsaChannelSigner for SignerClient {
input: input as u64,
payment_hash: model::Sha256(htlc.payment_hash.0),
htlc_amount_msat: htlc_descriptor.htlc.amount_msat,
+ witness_script,
};
let result: SignTxReply = self.call(message).map_err(|_| ())?;
Ok(Signature::from_compact(&result.signature.signature.0).unwrap())
diff --git a/vls-protocol-signer/src/handler.rs b/vls-protocol-signer/src/handler.rs
index 9944f405..2faee406 100644
--- a/vls-protocol-signer/src/handler.rs
+++ b/vls-protocol-signer/src/handler.rs
@@ -1255,6 +1255,7 @@ impl Handler for ChannelHandler {
let signature = self.node.with_channel(&self.channel_id, |chan| {
chan.sign_holder_htlc_tx_phase2(
&m.tx.0,
+ &m.witness_script,
m.per_commitment_number,
m.feerate_per_kw,
m.offered,
diff --git a/vls-protocol/src/msgs.rs b/vls-protocol/src/msgs.rs
index 2a9d3fbd..6ec3a563 100644
--- a/vls-protocol/src/msgs.rs
+++ b/vls-protocol/src/msgs.rs
@@ -29,6 +29,7 @@ use serde_bolt::{
use txoo::proof::{ProofType, TxoProof};
use log::error;
+use serde_bolt::bitcoin::ScriptBuf;
const MAX_MESSAGE_SIZE: u32 = 128 * 1024;
@@ -916,6 +917,7 @@ pub struct SignLocalHtlcTx2 {
pub cltv_expiry: u32,
pub htlc_amount_msat: u64,
pub payment_hash: Sha256,
+ pub witness_script: ScriptBuf,
}
///
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment