diff --git a/libs/Cargo.lock b/libs/Cargo.lock index aac2f2e60..3a354cf0c 100644 --- a/libs/Cargo.lock +++ b/libs/Cargo.lock @@ -162,6 +162,12 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "as-any" version = "0.3.1" @@ -378,6 +384,16 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals 0.3.0", + "bitcoin_hashes 0.14.0", +] + [[package]] name = "base64" version = "0.13.1" @@ -424,6 +440,12 @@ version = "0.10.0-beta" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "bincode" version = "1.3.3" @@ -435,11 +457,11 @@ dependencies = [ [[package]] name = "bip21" -version = "0.2.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1998475af29ccfb7c761bb624a16e501fc321510366012bc9cce267bc134aedc" +checksum = "ebe7a7f5928d264879d5b65eb18a72ea1890c57f22d62ee2eba93f207a6a020b" dependencies = [ - "bitcoin 0.29.2", + "bitcoin 0.32.2", "percent-encoding-rfc3986", ] @@ -483,13 +505,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" dependencies = [ "bech32 0.10.0-beta", - "bitcoin-internals", + "bitcoin-internals 0.2.0", "bitcoin_hashes 0.13.0", - "hex-conservative", + "hex-conservative 0.1.2", "hex_lit", "secp256k1 0.28.2", ] +[[package]] +name = "bitcoin" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" +dependencies = [ + "base58ck", + "bech32 0.11.0", + "bitcoin-internals 0.3.0", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes 0.14.0", + "hex-conservative 0.2.1", + "hex_lit", + "secp256k1 0.29.1", + "serde", +] + [[package]] name = "bitcoin-consensus-derive" version = "0.1.0" @@ -507,6 +547,21 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] + +[[package]] +name = "bitcoin-io" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf" + [[package]] name = "bitcoin-private" version = "0.1.0" @@ -523,6 +578,16 @@ dependencies = [ "log", ] +[[package]] +name = "bitcoin-units" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" +dependencies = [ + "bitcoin-internals 0.3.0", + "serde", +] + [[package]] name = "bitcoin_hashes" version = "0.11.0" @@ -548,8 +613,19 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" dependencies = [ - "bitcoin-internals", - "hex-conservative", + "bitcoin-internals 0.2.0", + "hex-conservative 0.1.2", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative 0.2.1", + "serde", ] [[package]] @@ -626,6 +702,7 @@ dependencies = [ "aes 0.8.3", "anyhow", "base64 0.13.1", + "bech32 0.11.0", "chrono", "const_format", "ecies", @@ -1626,6 +1703,15 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212ab92002354b4819390025006c897e8140934349e8635c9b077f47b4dcbd20" +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + [[package]] name = "hex_lit" version = "0.1.1" @@ -1990,6 +2076,18 @@ dependencies = [ "regex", ] +[[package]] +name = "lightning" +version = "0.0.125" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "767f388e50251da71f95a3737d6db32c9729f9de6427a54fa92bb994d04d793f" +dependencies = [ + "bech32 0.9.1", + "bitcoin 0.32.2", + "lightning-invoice 0.32.0", + "lightning-types", +] + [[package]] name = "lightning-invoice" version = "0.26.0" @@ -1999,11 +2097,33 @@ dependencies = [ "bech32 0.9.1", "bitcoin 0.29.2", "bitcoin_hashes 0.11.0", - "lightning", + "lightning 0.0.118", "num-traits", "secp256k1 0.24.3", ] +[[package]] +name = "lightning-invoice" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ab9f6ea77e20e3129235e62a2e6bd64ed932363df104e864ee65ccffb54a8f" +dependencies = [ + "bech32 0.9.1", + "bitcoin 0.32.2", + "lightning-types", +] + +[[package]] +name = "lightning-types" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1083b8d9137000edf3bfcb1ff011c0d25e0cdd2feb98cc21d6765e64a494148f" +dependencies = [ + "bech32 0.9.1", + "bitcoin 0.32.2", + "hex-conservative 0.2.1", +] + [[package]] name = "linux-raw-sys" version = "0.4.12" @@ -3134,13 +3254,14 @@ dependencies = [ "aes 0.8.3", "anyhow", "base64 0.13.1", + "bech32 0.11.0", "bip21", - "bitcoin 0.29.2", + "bitcoin 0.32.2", "cbc", "elements", "hex", - "lightning", - "lightning-invoice", + "lightning 0.0.125", + "lightning-invoice 0.32.0", "log", "mockito", "once_cell", @@ -3202,6 +3323,18 @@ dependencies = [ "secp256k1-sys 0.9.2", ] +[[package]] +name = "secp256k1" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" +dependencies = [ + "bitcoin_hashes 0.14.0", + "rand", + "secp256k1-sys 0.10.1", + "serde", +] + [[package]] name = "secp256k1-sys" version = "0.6.1" @@ -3229,6 +3362,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9" +dependencies = [ + "cc", +] + [[package]] name = "secp256k1-zkp" version = "0.10.1" @@ -4252,8 +4394,8 @@ dependencies = [ "hashbrown 0.8.2", "hex", "itertools", - "lightning", - "lightning-invoice", + "lightning 0.0.118", + "lightning-invoice 0.26.0", "log", "scopeguard", "serde", diff --git a/libs/Cargo.toml b/libs/Cargo.toml index a782c38b2..b6035f18c 100644 --- a/libs/Cargo.toml +++ b/libs/Cargo.toml @@ -20,10 +20,12 @@ version = "0.6.2" aes = "0.8" anyhow = { version = "1.0.79", features = ["backtrace"] } base64 = "0.13.0" -bitcoin = "=0.29.2" # Same version as used in gl-client +bech32 = "0.11" +bitcoin = "=0.32.2" hex = "0.4" -lightning = "=0.0.118" # Same version as used in gl-client -lightning-invoice = "=0.26.0" # Same version as used in gl-client +# We need at least lightning v0.0.125 for the latest Bolt12 features +lightning = "0.0.125" +lightning-invoice = "=0.32.0" log = "0.4" mockito = "1" once_cell = "1" diff --git a/libs/sdk-bindings/src/breez_sdk.udl b/libs/sdk-bindings/src/breez_sdk.udl index 38419cd7c..887f695e0 100644 --- a/libs/sdk-bindings/src/breez_sdk.udl +++ b/libs/sdk-bindings/src/breez_sdk.udl @@ -747,8 +747,8 @@ interface Amount { dictionary LNOffer { string bolt12; sequence chains; - string description; - string signing_pubkey; + string? description; + string? signing_pubkey; Amount? amount; u64? absolute_expiry; string? issuer; diff --git a/libs/sdk-common/Cargo.toml b/libs/sdk-common/Cargo.toml index d124fe9e8..de5b631e3 100644 --- a/libs/sdk-common/Cargo.toml +++ b/libs/sdk-common/Cargo.toml @@ -7,8 +7,9 @@ version.workspace = true aes = { workspace = true } anyhow = { workspace = true } base64 = { workspace = true } -bip21 = "0.2" -bitcoin = { workspace = true } +bech32 = { workspace = true } +bip21 = "0.5" +bitcoin = { workspace = true, features = ["rand", "serde"] } cbc = { version = "0.1", features = ["std"] } hex = { workspace = true } lightning = { workspace = true } @@ -34,7 +35,6 @@ elements = { version = "0.24.1", optional = true } urlencoding = { version = "2.1.3" } [dev-dependencies] -bitcoin = { workspace = true, features = ["rand"] } mockito = { workspace = true } once_cell = { workspace = true } diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index a9e4dd571..a73dd501a 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -2,11 +2,13 @@ use std::str::FromStr; use ::bip21::Uri; use anyhow::{anyhow, Result}; -use bitcoin::bech32; -use bitcoin::bech32::FromBase32; +use bitcoin::address::NetworkUnchecked; use lightning::offers::offer::Offer; use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use bech32; +use bech32::primitives::decode::CheckedHrpstring; +use bech32::Bech32; use LnUrlRequestData::*; use crate::prelude::*; @@ -155,7 +157,9 @@ pub async fn parse(input: &str) -> Result { let input = input.trim(); // Covers BIP 21 URIs and simple onchain BTC addresses (which are valid BIP 21 with the 'bitcoin:' prefix) - if let Ok(bip21_uri) = prepend_if_missing("bitcoin:", input).parse::>() { + if let Ok(bip21_uri) = + prepend_if_missing("bitcoin:", input).parse::>() + { let bitcoin_addr_data = bip21_uri.into(); // Special case of LN BOLT11 with onchain fallback @@ -196,10 +200,10 @@ pub async fn parse(input: &str) -> Result { .map(|chain| chain.to_string()) .collect(), amount: offer.amount().map(|amount| amount.clone().into()), - description: offer.description().to_string(), + description: offer.description().map(|d| d.to_string()), absolute_expiry: offer.absolute_expiry().map(|expiry| expiry.as_secs()), issuer: offer.issuer().map(|s| s.to_string()), - signing_pubkey: offer.signing_pubkey().to_string(), + signing_pubkey: offer.signing_pubkey().map(|pk| pk.to_string()), }, }); } @@ -322,8 +326,9 @@ fn lnurl_decode(encoded: &str) -> LnUrlResult<(String, String, Option)> } match bech32::decode(encoded) { - Ok((_hrp, payload, _variant)) => { - let decoded = String::from_utf8(Vec::from_base32(&payload)?)?; + Ok((_hrp, payload)) => { + let b = CheckedHrpstring::new::(encoded).unwrap(); // TODO + let decoded = String::from_utf8(b.byte_iter().collect())?; let url = reqwest::Url::parse(&decoded) .map_err(|e| super::prelude::LnUrlError::InvalidUri(e.to_string()))?; @@ -632,8 +637,7 @@ impl BitcoinAddressData { /// Converts the structure to a BIP21 URI while also /// ensuring that all the fields are valid pub fn to_uri(&self) -> Result { - self.address - .parse::() + bitcoin::Address::from_str(&self.address) .map_err(|_| URISerializationError::InvalidAddress)?; let mut optional_keys = HashMap::new(); @@ -666,11 +670,23 @@ impl BitcoinAddressData { } } -impl From> for BitcoinAddressData { - fn from(uri: Uri) -> Self { +impl From> for BitcoinAddressData { + fn from(uri: Uri<'_, NetworkUnchecked>) -> Self { + // TODO Is there a nicer way to get the network? + let network = if uri.address.is_valid_for_network(bitcoin::Network::Bitcoin) { + bitcoin::Network::Bitcoin + } else if uri.address.is_valid_for_network(bitcoin::Network::Testnet) { + bitcoin::Network::Testnet + } else if uri.address.is_valid_for_network(bitcoin::Network::Signet) { + bitcoin::Network::Signet + } else { + bitcoin::Network::Regtest + } + .into(); + BitcoinAddressData { - address: uri.address.to_string(), - network: uri.address.network.into(), + address: uri.address.assume_checked().to_string(), + network, amount_sat: uri.amount.map(|a| a.to_sat()), label: uri.label.map(|label| label.try_into().unwrap()), message: uri.message.map(|msg| msg.try_into().unwrap()), diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index c59a6de78..e68d62def 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -1,6 +1,6 @@ use std::num::ParseIntError; use std::str::FromStr; -use std::time::{SystemTimeError, UNIX_EPOCH}; +use std::time::SystemTimeError; use bitcoin::secp256k1::{self, PublicKey}; use hex::ToHex; @@ -136,10 +136,10 @@ pub struct LNOffer { pub bolt12: String, pub chains: Vec, pub amount: Option, - pub description: String, + pub description: Option, pub absolute_expiry: Option, pub issuer: Option, - pub signing_pubkey: String, + pub signing_pubkey: Option, // pub paths: Vec, } @@ -244,6 +244,13 @@ pub fn add_routing_hints( let signed = invoice.parse::()?; let invoice = Bolt11Invoice::from_signed(signed)?; + let since_the_epoch = invoice + .clone() + .into_signed_raw() + .data + .timestamp + .as_duration_since_epoch(); + let mut ldk_hints: Vec = vec![]; for h in route_hints { ldk_hints.push(h.to_ldk_hint()?); @@ -252,7 +259,7 @@ pub fn add_routing_hints( let mut invoice_builder = InvoiceBuilder::new(invoice.currency()) .invoice_description(invoice.description()) .payment_hash(*invoice.payment_hash()) - .timestamp(invoice.timestamp()) + .duration_since_epoch(since_the_epoch) .expiry_time(invoice.expiry_time()) .payment_secret(*invoice.payment_secret()) .min_final_cltv_expiry_delta(invoice.min_final_cltv_expiry_delta()); @@ -320,7 +327,12 @@ pub fn parse_invoice(bolt11: &str) -> InvoiceResult { let bolt11 = re.replace_all(bolt11, ""); let signed = bolt11.parse::()?; let invoice = Bolt11Invoice::from_signed(signed)?; - let since_the_epoch = invoice.timestamp().duration_since(UNIX_EPOCH)?; + let since_the_epoch = invoice + .clone() + .into_signed_raw() + .data + .timestamp + .as_duration_since_epoch(); // make sure signature is valid invoice.check_signature()?; diff --git a/libs/sdk-common/src/lnurl/error.rs b/libs/sdk-common/src/lnurl/error.rs index 9ccaac8c5..f8c14dc91 100644 --- a/libs/sdk-common/src/lnurl/error.rs +++ b/libs/sdk-common/src/lnurl/error.rs @@ -1,6 +1,6 @@ use std::{array::TryFromSliceError, string::FromUtf8Error}; -use bitcoin::{bech32, secp256k1, util::bip32}; +use bitcoin::{bip32, secp256k1}; use crate::prelude::InvoiceError; @@ -55,11 +55,6 @@ impl From for LnUrlError { } } -impl From for LnUrlError { - fn from(err: bech32::Error) -> Self { - Self::Generic(err.to_string()) - } -} impl From for LnUrlError { fn from(err: FromUtf8Error) -> Self { diff --git a/libs/sdk-common/src/lnurl/specs/auth.rs b/libs/sdk-common/src/lnurl/specs/auth.rs index 76ab3be36..098a3af63 100644 --- a/libs/sdk-common/src/lnurl/specs/auth.rs +++ b/libs/sdk-common/src/lnurl/specs/auth.rs @@ -1,7 +1,6 @@ use std::str::FromStr; -use bitcoin::hashes::hex::ToHex; -use bitcoin::util::bip32::{ChildNumber, ExtendedPubKey}; +use bitcoin::bip32::{ChildNumber, Xpub}; use reqwest::Url; use crate::prelude::*; @@ -31,25 +30,21 @@ pub async fn perform_lnurl_auth( ) -> LnUrlResult { let url = Url::from_str(&req_data.url).map_err(|e| LnUrlError::InvalidUri(e.to_string()))?; let derivation_path = get_derivation_path(signer, url).await?; - let sig = signer - .sign_ecdsa( - &hex::decode(&req_data.k1) - .map_err(|e| LnUrlError::Generic(format!("Error decoding k1: {e}")))?, - &derivation_path, - ) - .await?; + let k1_bytes = hex::decode(&req_data.k1) + .map_err(|e| LnUrlError::Generic(format!("Error decoding k1: {e}")))?; + let sig_bytes = signer.sign_ecdsa(&k1_bytes, &derivation_path).await?; let xpub_bytes = signer.derive_bip32_pub_key(&derivation_path).await?; - let xpub = ExtendedPubKey::decode(xpub_bytes.as_slice())?; + let xpub = Xpub::decode(xpub_bytes.as_slice())?; // ?&sig=&key= let mut callback_url = Url::from_str(&req_data.url).map_err(|e| LnUrlError::InvalidUri(e.to_string()))?; callback_url .query_pairs_mut() - .append_pair("sig", &sig.to_hex()); + .append_pair("sig", &hex::encode(&sig_bytes)); callback_url .query_pairs_mut() - .append_pair("key", &xpub.public_key.to_hex()); + .append_pair("key", &(format!("{:x}", xpub.public_key))); get_parse_and_log_response(callback_url.as_ref(), false) .await diff --git a/libs/sdk-common/src/lnurl/specs/pay.rs b/libs/sdk-common/src/lnurl/specs/pay.rs index 65fc47a5e..c5375cffb 100644 --- a/libs/sdk-common/src/lnurl/specs/pay.rs +++ b/libs/sdk-common/src/lnurl/specs/pay.rs @@ -441,8 +441,8 @@ pub mod model { } } - impl From for LnUrlPayError { - fn from(err: bitcoin::hashes::hex::Error) -> Self { + impl From for LnUrlPayError { + fn from(err: hex::FromHexError) -> Self { Self::Generic { err: err.to_string(), } diff --git a/libs/sdk-common/src/model.rs b/libs/sdk-common/src/model.rs index c5a9de542..3c340fd78 100644 --- a/libs/sdk-common/src/model.rs +++ b/libs/sdk-common/src/model.rs @@ -11,24 +11,24 @@ pub enum Network { Regtest, } -impl From for Network { - fn from(network: bitcoin::network::constants::Network) -> Self { +impl From for Network { + fn from(network: bitcoin::Network) -> Self { match network { - bitcoin::network::constants::Network::Bitcoin => Network::Bitcoin, - bitcoin::network::constants::Network::Testnet => Network::Testnet, - bitcoin::network::constants::Network::Signet => Network::Signet, - bitcoin::network::constants::Network::Regtest => Network::Regtest, + bitcoin::Network::Bitcoin => Network::Bitcoin, + bitcoin::Network::Testnet => Network::Testnet, + bitcoin::Network::Signet => Network::Signet, + _ => Network::Regtest, } } } -impl From for bitcoin::network::constants::Network { +impl From for bitcoin::Network { fn from(network: Network) -> Self { match network { - Network::Bitcoin => bitcoin::network::constants::Network::Bitcoin, - Network::Testnet => bitcoin::network::constants::Network::Testnet, - Network::Signet => bitcoin::network::constants::Network::Signet, - Network::Regtest => bitcoin::network::constants::Network::Regtest, + Network::Bitcoin => bitcoin::Network::Bitcoin, + Network::Testnet => bitcoin::Network::Testnet, + Network::Signet => bitcoin::Network::Signet, + Network::Regtest => bitcoin::Network::Regtest, } } } diff --git a/libs/sdk-core/Cargo.toml b/libs/sdk-core/Cargo.toml index d350adb4b..7fb6e3bbb 100644 --- a/libs/sdk-core/Cargo.toml +++ b/libs/sdk-core/Cargo.toml @@ -17,6 +17,7 @@ gl-client = { git = "https://github.com/Blockstream/greenlight.git", features = ], rev = "c09c1be59994b35aadfe4747b78bcdc8fffbe45a" } zbase32 = "0.1.2" base64 = { workspace = true } +bech32 = { workspace = true } chrono = "0.4" ecies = { version = "0.2.6", default-features = false, features = ["pure"] } env_logger = "0.10" @@ -55,4 +56,3 @@ ryu = "1.0.18" [dev-dependencies] mockito = { workspace = true } - diff --git a/libs/sdk-core/src/greenlight/node_api.rs b/libs/sdk-core/src/greenlight/node_api.rs index 658fb6d1d..3963a0c11 100644 --- a/libs/sdk-core/src/greenlight/node_api.rs +++ b/libs/sdk-core/src/greenlight/node_api.rs @@ -37,23 +37,23 @@ use tokio::time::{sleep, Instant, MissedTickBehavior}; use tokio_stream::StreamExt; use tonic::Streaming; -use crate::bitcoin::bech32::{u5, ToBase32}; -use crate::bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR; -use crate::bitcoin::hashes::Hash; -use crate::bitcoin::secp256k1::ecdsa::{RecoverableSignature, RecoveryId}; -use crate::bitcoin::secp256k1::PublicKey; -use crate::bitcoin::secp256k1::Secp256k1; -use crate::bitcoin::util::bip32::{ChildNumber, ExtendedPrivKey}; -use crate::bitcoin::{ - Address, OutPoint, Script, Sequence, Transaction, TxIn, TxOut, Txid, Witness, -}; -use crate::lightning::util::message_signing::verify; -use crate::lightning_invoice::{RawBolt11Invoice, SignedRawBolt11Invoice}; use crate::node_api::{CreateInvoiceRequest, FetchBolt11Result, NodeAPI, NodeError, NodeResult}; use crate::persist::db::SqliteStorage; use crate::persist::send_pays::{SendPay, SendPayStatus}; use crate::{models::*, LspInformation}; use crate::{NodeConfig, PrepareRedeemOnchainFundsRequest, PrepareRedeemOnchainFundsResponse}; +use gl_client::bitcoin::bech32::{u5, ToBase32}; +use gl_client::bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR; +use gl_client::bitcoin::hashes::Hash; +use gl_client::bitcoin::secp256k1::ecdsa::{RecoverableSignature, RecoveryId}; +use gl_client::bitcoin::secp256k1::PublicKey; +use gl_client::bitcoin::secp256k1::Secp256k1; +use gl_client::bitcoin::util::bip32::{ChildNumber, ExtendedPrivKey}; +use gl_client::bitcoin::{ + Address, OutPoint, Script, Sequence, Transaction, TxIn, TxOut, Txid, Witness, +}; +use gl_client::lightning::util::message_signing::verify; +use gl_client::lightning_invoice::{RawBolt11Invoice, SignedRawBolt11Invoice}; const MAX_PAYMENT_AMOUNT_MSAT: u64 = 4294967000; const MAX_INBOUND_LIQUIDITY_MSAT: u64 = 4000000000; @@ -1531,7 +1531,7 @@ impl NodeAPI for Greenlight { }]; let tx = Transaction { version: 2, - lock_time: crate::bitcoin::PackedLockTime(0), + lock_time: gl_client::bitcoin::PackedLockTime(0), input: txins.clone(), output: tx_out, }; diff --git a/libs/sdk-core/src/models.rs b/libs/sdk-core/src/models.rs index 7d6b28c30..84ff8b0e8 100644 --- a/libs/sdk-core/src/models.rs +++ b/libs/sdk-core/src/models.rs @@ -4,6 +4,7 @@ use std::str::FromStr; use anyhow::{anyhow, ensure, Result}; use chrono::{DateTime, Duration, Utc}; +use gl_client::bitcoin::hashes::hex::ToHex; use ripemd::Digest; use ripemd::Ripemd160; use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef}; @@ -20,7 +21,7 @@ use crate::bitcoin::blockdata::script::Builder; use crate::bitcoin::hashes::hex::{FromHex, ToHex}; use crate::bitcoin::hashes::{sha256, Hash}; use crate::bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; -use crate::bitcoin::{Address, Script}; +use crate::bitcoin::{Address, Script, ScriptBuf}; use crate::error::SdkResult; use crate::lsp::LspInformation; use crate::persist::swap::SwapChainInfo; @@ -180,19 +181,25 @@ pub struct ReverseSwapInfoCached { impl FullReverseSwapInfo { /// Builds the expected redeem script pub(crate) fn build_expected_reverse_swap_script( - preimage_hash: Vec, - compressed_pub_key: Vec, + preimage_hash: &[u8; 32], + compressed_pub_key: [u8; 33], sig: Vec, lock_height: u32, - ) -> ReverseSwapResult