Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"ark-rust-secp256k1",
"ark-dlc-sample",
"ark-rs",
"ark-lightning",
]

resolver = "2"
19 changes: 19 additions & 0 deletions ark-lightning/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "ark-lightning"
version = "0.1.0"
edition = "2024"

[dependencies]
ark-core = { path = "../ark-core" }
bitcoin = { version = "0.32.4", features = ["base64", "rand", "serde"] }
musig = { package = "ark-secp256k1", path = "../ark-rust-secp256k1", features = ["serde", "rand"] }
serde = { version = "1.0", features = ["derive"] }
thiserror = "1.0"

[dev-dependencies]
hex = "0.4"
serde_json = "1.0"

[[example]]
name = "vhtlc_example"
path = "examples/vhtlc_example.rs"
56 changes: 56 additions & 0 deletions ark-lightning/examples/vhtlc_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use ark_lightning::vhtlc::VhtlcOptions;
use ark_lightning::vhtlc::VhtlcScript;
use bitcoin::Sequence;
use bitcoin::XOnlyPublicKey;
use std::str::FromStr;

fn main() {
// Create test keys for sender, receiver, and server
let sender = XOnlyPublicKey::from_str(
"18845781f631c48f1c9709e23092067d06837f30aa0cd0544ac887fe91ddd166",
)
.unwrap();

let receiver = XOnlyPublicKey::from_str(
"28845781f631c48f1c9709e23092067d06837f30aa0cd0544ac887fe91ddd166",
)
.unwrap();

let server = XOnlyPublicKey::from_str(
"38845781f631c48f1c9709e23092067d06837f30aa0cd0544ac887fe91ddd166",
)
.unwrap();

// Create a preimage hash (in a real scenario, this would be the hash of a secret)
let preimage_hash = [42u8; 20];

// Configure the VHTLC options
let options = VhtlcOptions {
sender,
receiver,
server,
preimage_hash,
refund_locktime: 100000, // Block height for CLTV
unilateral_claim_delay: Sequence::from_seconds_ceil(3600).unwrap(), // 1 hour
unilateral_refund_delay: Sequence::from_seconds_ceil(7200).unwrap(), // 2 hours
unilateral_refund_without_receiver_delay: Sequence::from_seconds_ceil(10800).unwrap(), /* 3 hours */
};

// Create the VHTLC script
let vhtlc = VhtlcScript::new(options).expect("Failed to create VHTLC");

// Get the taproot output key and script pubkey
if let Some(taproot_info) = vhtlc.taproot_info() {
println!("Taproot output key: {}", taproot_info.output_key());

if let Some(script_pubkey) = vhtlc.script_pubkey() {
println!("Script pubkey: {}", script_pubkey);
}
}

// Display all available spending paths
println!("\nAvailable spending paths:");
for (name, script) in vhtlc.get_script_map() {
println!(" {} - {} bytes", name, script.len());
}
}
58 changes: 58 additions & 0 deletions ark-lightning/scripts/generate_ts_vectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Script to generate test vectors from TypeScript SDK for comparison
// Run this in the arkade-os/ts-sdk repository to get the expected hex values

const { VhtlcScript } = require('../path/to/ts-sdk'); // Adjust path as needed

// Test data from fixtures (same as used in Rust tests)
const testData = {
preimageHash: Buffer.from('4d487dd3753a89bc9fe98401d1196523058251fc', 'hex'),
receiver: Buffer.from('021e1bb85455fe3f5aed60d101aa4dbdb9e7714f6226769a97a17a5331dadcd53b', 'hex'),
sender: Buffer.from('030192e796452d6df9697c280542e1560557bcf79a347d925895043136225c7cb4', 'hex'),
server: Buffer.from('03aad52d58162e9eefeafc7ad8a1cdca8060b5f01df1e7583362d052e266208f88', 'hex'),
refundLocktime: 265,
unilateralClaimDelay: { type: 'blocks', value: 17 },
unilateralRefundDelay: { type: 'blocks', value: 144 },
unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 144 }
};

try {
// Create VHTLC instance
const vhtlc = new VhtlcScript(testData);

console.log('=== TypeScript SDK VHTLC Script Vectors ===\n');

// Export all script hex values
const vectors = {
claim: vhtlc.claim().script.toString('hex'),
refund: vhtlc.refund().script.toString('hex'),
refundWithoutReceiver: vhtlc.refundWithoutReceiver().script.toString('hex'),
unilateralClaim: vhtlc.unilateralClaim().script.toString('hex'),
unilateralRefund: vhtlc.unilateralRefund().script.toString('hex'),
unilateralRefundWithoutReceiver: vhtlc.unilateralRefundWithoutReceiver().script.toString('hex')
};

// Output for comparison
console.log('TypeScript SDK Script Vectors:');
console.log('1. Claim Script: ', vectors.claim);
console.log('2. Refund Script: ', vectors.refund);
console.log('3. Refund Without Receiver Script: ', vectors.refundWithoutReceiver);
console.log('4. Unilateral Claim Script: ', vectors.unilateralClaim);
console.log('5. Unilateral Refund Script: ', vectors.unilateralRefund);
console.log('6. Unilateral Refund Without Receiver: ', vectors.unilateralRefundWithoutReceiver);

// Also output as JSON for easy parsing
console.log('\n=== JSON Format ===');
console.log(JSON.stringify(vectors, null, 2));

// Export taproot address for comparison
const address = vhtlc.address('testnet'); // or 'mainnet'
console.log('\n=== Address ===');
console.log('TypeScript SDK Address:', address);

} catch (error) {
console.error('Error generating TypeScript vectors:', error);
console.log('\nPlease ensure:');
console.log('1. You are running this in the arkade-os/ts-sdk directory');
console.log('2. The path to VhtlcScript is correct');
console.log('3. All dependencies are installed (npm install)');
}
5 changes: 5 additions & 0 deletions ark-lightning/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Lightning Network Module for the Ark Lightning Swap
//!
//! Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

pub mod vhtlc;
Loading
Loading