From 196a606b8e2686e121065996e0e5992861ef97b6 Mon Sep 17 00:00:00 2001 From: Lorenzo Ronzani Date: Thu, 19 Dec 2024 11:36:51 +0100 Subject: [PATCH 1/6] Implemented BIP353 parsing feature --- libs/Cargo.lock | 153 ++++++++++++++++++++++++++-- libs/sdk-common/Cargo.toml | 1 + libs/sdk-common/src/input_parser.rs | 52 +++++++++- tools/sdk-cli/Cargo.lock | 149 ++++++++++++++++++++++++++- 4 files changed, 344 insertions(+), 11 deletions(-) diff --git a/libs/Cargo.lock b/libs/Cargo.lock index 56391823b..4ec92e92a 100644 --- a/libs/Cargo.lock +++ b/libs/Cargo.lock @@ -860,7 +860,7 @@ version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-error", "proc-macro2", "quote", @@ -1179,6 +1179,18 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "enum-as-inner" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "env_logger" version = "0.9.3" @@ -1599,6 +1611,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1659,6 +1677,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi", +] + [[package]] name = "http" version = "0.2.11" @@ -1791,6 +1820,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "0.5.0" @@ -1852,6 +1891,18 @@ dependencies = [ "generic-array", ] +[[package]] +name = "ipconfig" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" +dependencies = [ + "socket2 0.5.5", + "widestring", + "windows-sys 0.48.0", + "winreg", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -2004,6 +2055,12 @@ dependencies = [ "secp256k1 0.24.3", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.12" @@ -2026,6 +2083,21 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + [[package]] name = "matchit" version = "0.7.3" @@ -2708,7 +2780,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", - "heck", + "heck 0.4.1", "itertools", "lazy_static", "log", @@ -2751,6 +2823,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9318ead08c799aad12a55a3e78b82e0b6167271ffd1f627b758891282f739187" +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.35" @@ -2883,6 +2961,16 @@ dependencies = [ "winreg", ] +[[package]] +name = "resolv-conf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" +dependencies = [ + "hostname", + "quick-error", +] + [[package]] name = "ring" version = "0.16.20" @@ -3157,6 +3245,7 @@ dependencies = [ "tokio", "tonic", "tonic-build", + "trust-dns-resolver", "url", "urlencoding", ] @@ -3564,7 +3653,7 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -3971,6 +4060,52 @@ dependencies = [ "tracing", ] +[[package]] +name = "trust-dns-proto" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3119112651c157f4488931a01e586aa459736e9d6046d3bd9105ffb69352d374" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.4.0", + "ipnet", + "once_cell", + "rand", + "smallvec", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "trust-dns-resolver" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a3e6c3aff1718b3c73e395d1f35202ba2ffa847c6a62eea0db8fb4cfe30be6" +dependencies = [ + "cfg-if", + "futures-util", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot", + "rand", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", + "trust-dns-proto", +] + [[package]] name = "try-lock" version = "0.2.4" @@ -4053,7 +4188,7 @@ dependencies = [ "anyhow", "askama", "camino", - "heck", + "heck 0.4.1", "include_dir", "paste", "serde", @@ -4074,7 +4209,7 @@ dependencies = [ "fs-err", "glob", "goblin", - "heck", + "heck 0.4.1", "once_cell", "paste", "serde", @@ -4206,7 +4341,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", - "idna", + "idna 0.5.0", "percent-encoding", ] @@ -4440,6 +4575,12 @@ dependencies = [ "rustix", ] +[[package]] +name = "widestring" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" + [[package]] name = "winapi" version = "0.3.9" diff --git a/libs/sdk-common/Cargo.toml b/libs/sdk-common/Cargo.toml index e3a0b99b0..79526e653 100644 --- a/libs/sdk-common/Cargo.toml +++ b/libs/sdk-common/Cargo.toml @@ -33,6 +33,7 @@ url = "2.5.0" elements = { version = "0.24.1", optional = true } urlencoding = { version = "2.1.3" } percent-encoding = "2.3.1" +trust-dns-resolver = "0.23.2" [dev-dependencies] bitcoin = { workspace = true, features = ["rand"] } diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index ae6f64370..80ded8411 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -12,8 +12,14 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use LnUrlRequestData::*; +use trust_dns_resolver::config::*; +use trust_dns_resolver::TokioAsyncResolver; + use crate::prelude::*; +const USER_BITCOIN_PAYMENT_PREFIX: &str = "user._bitcoin-payment"; +const LNURL_PAY_PREFIX: &str = "lnurl="; + /// Parses generic user input, typically pasted from clipboard or scanned from a QR. /// /// Can optionally be provided a collection of [ExternalInputParser] that are used if an input is not @@ -180,11 +186,55 @@ use crate::prelude::*; /// } /// } /// ``` + +async fn bip353_parse(input: &str) -> Option { + if let Some((local_part, domain)) = input.split_once('@') { + let dns_resolver = + TokioAsyncResolver::tokio(ResolverConfig::default(), ResolverOpts::default()); + + let dns_name = format!("{}.{}.{}", local_part, USER_BITCOIN_PAYMENT_PREFIX, domain); + + // Query for TXT records of a domain + let txt_data = match dns_resolver.txt_lookup(dns_name).await { + Ok(records) => records + .iter() + .flat_map(|record| record.to_string().into_bytes()) + .collect::>(), + Err(e) => { + eprintln!("Failed to lookup TXT records: {}", e); + return None; + } + }; + + // Decode TXT data + match String::from_utf8(txt_data) { + Ok(decoded) => { + if let Some((_, lnurl)) = decoded.split_once(LNURL_PAY_PREFIX) { + return Some(lnurl.to_string()); + } + } + Err(e) => { + eprintln!("Failed to decode TXT data: {}", e); + } + } + } + + None +} + pub async fn parse( input: &str, external_input_parsers: Option<&[ExternalInputParser]>, ) -> Result { - let input = input.trim(); + let mut input = input.trim(); + + // Try to parse the destination as a bip353 address. + let input_str = match bip353_parse(input).await { + Some(value) => value, + None => input.to_string(), + }; + + input = input_str.as_str(); if let Ok(input_type) = parse_core(input).await { return Ok(input_type); diff --git a/tools/sdk-cli/Cargo.lock b/tools/sdk-cli/Cargo.lock index 685e4f60e..b017a8093 100644 --- a/tools/sdk-cli/Cargo.lock +++ b/tools/sdk-cli/Cargo.lock @@ -718,7 +718,7 @@ version = "4.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81d7dc0031c3a59a04fc2ba395c8e2dd463cba1859275f065d225f6122221b45" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "syn 2.0.48", @@ -1028,6 +1028,18 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" +[[package]] +name = "enum-as-inner" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "env_logger" version = "0.9.3" @@ -1448,6 +1460,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1511,6 +1529,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi", +] + [[package]] name = "http" version = "0.2.9" @@ -1643,6 +1672,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "0.5.0" @@ -1696,6 +1735,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "ipconfig" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" +dependencies = [ + "socket2 0.5.8", + "widestring", + "windows-sys 0.48.0", + "winreg", +] + [[package]] name = "ipnet" version = "2.7.2" @@ -1849,6 +1900,12 @@ dependencies = [ "secp256k1 0.24.3", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -1877,6 +1934,21 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + [[package]] name = "matchit" version = "0.7.0" @@ -2509,7 +2581,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", - "heck", + "heck 0.4.1", "itertools", "lazy_static", "log", @@ -2558,6 +2630,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9318ead08c799aad12a55a3e78b82e0b6167271ffd1f627b758891282f739187" +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.35" @@ -2700,6 +2778,16 @@ dependencies = [ "winreg", ] +[[package]] +name = "resolv-conf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" +dependencies = [ + "hostname", + "quick-error", +] + [[package]] name = "ring" version = "0.16.20" @@ -3001,6 +3089,7 @@ dependencies = [ "tokio", "tonic", "tonic-build", + "trust-dns-resolver", "url", "urlencoding", ] @@ -3345,7 +3434,7 @@ version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -3737,6 +3826,52 @@ dependencies = [ "tracing", ] +[[package]] +name = "trust-dns-proto" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3119112651c157f4488931a01e586aa459736e9d6046d3bd9105ffb69352d374" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.4.0", + "ipnet", + "once_cell", + "rand", + "smallvec", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "trust-dns-resolver" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a3e6c3aff1718b3c73e395d1f35202ba2ffa847c6a62eea0db8fb4cfe30be6" +dependencies = [ + "cfg-if", + "futures-util", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot", + "rand", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", + "trust-dns-proto", +] + [[package]] name = "try-lock" version = "0.2.4" @@ -3839,7 +3974,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", - "idna", + "idna 0.5.0", "percent-encoding", ] @@ -4070,6 +4205,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "widestring" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" + [[package]] name = "winapi" version = "0.3.9" From 3d27ed67ce8facd4702fb3fa953cfcc5309d4288 Mon Sep 17 00:00:00 2001 From: Lorenzo Ronzani Date: Thu, 19 Dec 2024 15:28:30 +0100 Subject: [PATCH 2/6] Edited the dns_resolver dependency from trust-dns-resolver to the new one hickory-resolver adn exported from the sdk_common --- libs/Cargo.lock | 364 +++++++++++++++++++++++++++++++------ libs/sdk-common/Cargo.toml | 2 +- libs/sdk-common/src/lib.rs | 1 + libs/sdk-core/src/lib.rs | 1 + tools/sdk-cli/Cargo.lock | 364 +++++++++++++++++++++++++++++++------ 5 files changed, 619 insertions(+), 113 deletions(-) diff --git a/libs/Cargo.lock b/libs/Cargo.lock index 4ec92e92a..b9cf08b0e 100644 --- a/libs/Cargo.lock +++ b/libs/Cargo.lock @@ -238,7 +238,7 @@ dependencies = [ "proc-macro2", "quote", "syn 1.0.109", - "synstructure", + "synstructure 0.12.6", ] [[package]] @@ -1650,6 +1650,51 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" +[[package]] +name = "hickory-proto" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447afdcdb8afb9d0a852af6dc65d9b285ce720ed7a59e42a8bf2e931c67bc1b5" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 1.0.3", + "ipnet", + "once_cell", + "rand", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a2e2aba9c389ce5267d31cf1e4dace82390ae276b0b364ea55630b1fa1b44b4" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot", + "rand", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "hkdf" version = "0.12.3" @@ -1814,6 +1859,124 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -1822,9 +1985,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -1832,12 +1995,23 @@ dependencies = [ [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -2067,6 +2241,12 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + [[package]] name = "lock_api" version = "0.4.11" @@ -3228,6 +3408,7 @@ dependencies = [ "cbc", "elements", "hex", + "hickory-resolver", "lightning", "lightning-invoice", "log", @@ -3245,7 +3426,6 @@ dependencies = [ "tokio", "tonic", "tonic-build", - "trust-dns-resolver", "url", "urlencoding", ] @@ -3583,9 +3763,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" @@ -3629,6 +3809,12 @@ dependencies = [ "der", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -3706,6 +3892,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "tempfile" version = "3.10.1" @@ -3818,6 +4015,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -4060,52 +4267,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "trust-dns-proto" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3119112651c157f4488931a01e586aa459736e9d6046d3bd9105ffb69352d374" -dependencies = [ - "async-trait", - "cfg-if", - "data-encoding", - "enum-as-inner", - "futures-channel", - "futures-io", - "futures-util", - "idna 0.4.0", - "ipnet", - "once_cell", - "rand", - "smallvec", - "thiserror", - "tinyvec", - "tokio", - "tracing", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a3e6c3aff1718b3c73e395d1f35202ba2ffa847c6a62eea0db8fb4cfe30be6" -dependencies = [ - "cfg-if", - "futures-util", - "ipconfig", - "lru-cache", - "once_cell", - "parking_lot", - "rand", - "resolv-conf", - "smallvec", - "thiserror", - "tokio", - "tracing", - "trust-dns-proto", -] - [[package]] name = "try-lock" version = "0.2.4" @@ -4351,6 +4512,18 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "uuid" version = "1.8.0" @@ -4763,6 +4936,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "x509-certificate" version = "0.23.1" @@ -4810,6 +4995,30 @@ dependencies = [ "time", ] +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "synstructure 0.13.1", +] + [[package]] name = "zbase32" version = "0.1.2" @@ -4836,6 +5045,27 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "synstructure 0.13.1", +] + [[package]] name = "zeroize" version = "1.7.0" @@ -4855,3 +5085,25 @@ dependencies = [ "quote", "syn 2.0.48", ] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] diff --git a/libs/sdk-common/Cargo.toml b/libs/sdk-common/Cargo.toml index 79526e653..3d868b43d 100644 --- a/libs/sdk-common/Cargo.toml +++ b/libs/sdk-common/Cargo.toml @@ -33,7 +33,7 @@ url = "2.5.0" elements = { version = "0.24.1", optional = true } urlencoding = { version = "2.1.3" } percent-encoding = "2.3.1" -trust-dns-resolver = "0.23.2" +hickory-resolver = "0.24.2" [dev-dependencies] bitcoin = { workspace = true, features = ["rand"] } diff --git a/libs/sdk-common/src/lib.rs b/libs/sdk-common/src/lib.rs index d7d49ebba..7542627ed 100644 --- a/libs/sdk-common/src/lib.rs +++ b/libs/sdk-common/src/lib.rs @@ -18,6 +18,7 @@ mod utils; // use a different version, the Into traits defined here would not be usable by them // (e.g. impl From for LnUrlError) pub use bitcoin; +pub use hickory_resolver; pub use lightning; pub use lightning_invoice; diff --git a/libs/sdk-core/src/lib.rs b/libs/sdk-core/src/lib.rs index e06498d28..9e24f88ff 100644 --- a/libs/sdk-core/src/lib.rs +++ b/libs/sdk-core/src/lib.rs @@ -196,5 +196,6 @@ pub use breez_services::{ pub use chain::RecommendedFees; pub use lsp::LspInformation; pub use models::*; +pub use sdk_common::hickory_resolver; pub use sdk_common::prelude::*; pub use swap_out::reverseswap::{ESTIMATED_CLAIM_TX_VSIZE, ESTIMATED_LOCKUP_TX_VSIZE}; diff --git a/tools/sdk-cli/Cargo.lock b/tools/sdk-cli/Cargo.lock index b017a8093..353c94892 100644 --- a/tools/sdk-cli/Cargo.lock +++ b/tools/sdk-cli/Cargo.lock @@ -186,7 +186,7 @@ dependencies = [ "proc-macro2", "quote", "syn 1.0.109", - "synstructure", + "synstructure 0.12.6", ] [[package]] @@ -1502,6 +1502,51 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" +[[package]] +name = "hickory-proto" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447afdcdb8afb9d0a852af6dc65d9b285ce720ed7a59e42a8bf2e931c67bc1b5" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 1.0.3", + "ipnet", + "once_cell", + "rand", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a2e2aba9c389ce5267d31cf1e4dace82390ae276b0b364ea55630b1fa1b44b4" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot", + "rand", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "hkdf" version = "0.12.3" @@ -1666,6 +1711,124 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -1674,9 +1837,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -1684,12 +1847,23 @@ dependencies = [ [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -1918,6 +2092,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + [[package]] name = "lock_api" version = "0.4.9" @@ -3074,6 +3254,7 @@ dependencies = [ "bitcoin 0.29.2", "cbc", "hex", + "hickory-resolver", "lightning", "lightning-invoice", "log", @@ -3089,7 +3270,6 @@ dependencies = [ "tokio", "tonic", "tonic-build", - "trust-dns-resolver", "url", "urlencoding", ] @@ -3364,9 +3544,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" @@ -3410,6 +3590,12 @@ dependencies = [ "der", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "str-buf" version = "1.0.6" @@ -3487,6 +3673,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "tempfile" version = "3.10.1" @@ -3593,6 +3790,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -3826,52 +4033,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "trust-dns-proto" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3119112651c157f4488931a01e586aa459736e9d6046d3bd9105ffb69352d374" -dependencies = [ - "async-trait", - "cfg-if", - "data-encoding", - "enum-as-inner", - "futures-channel", - "futures-io", - "futures-util", - "idna 0.4.0", - "ipnet", - "once_cell", - "rand", - "smallvec", - "thiserror", - "tinyvec", - "tokio", - "tracing", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a3e6c3aff1718b3c73e395d1f35202ba2ffa847c6a62eea0db8fb4cfe30be6" -dependencies = [ - "cfg-if", - "futures-util", - "ipconfig", - "lru-cache", - "once_cell", - "parking_lot", - "rand", - "resolv-conf", - "smallvec", - "thiserror", - "tokio", - "tracing", - "trust-dns-proto", -] - [[package]] name = "try-lock" version = "0.2.4" @@ -3984,6 +4145,18 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.1" @@ -4481,6 +4654,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "x509-certificate" version = "0.23.1" @@ -4528,12 +4713,57 @@ dependencies = [ "time", ] +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "synstructure 0.13.1", +] + [[package]] name = "zbase32" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f9079049688da5871a7558ddacb7f04958862c703e68258594cb7a862b5e33f" +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "synstructure 0.13.1", +] + [[package]] name = "zeroize" version = "1.6.0" @@ -4553,3 +4783,25 @@ dependencies = [ "quote", "syn 2.0.48", ] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] From d5e2a191664c87d529dedbe284b653322263651f Mon Sep 17 00:00:00 2001 From: Lorenzo Ronzani Date: Thu, 19 Dec 2024 15:30:35 +0100 Subject: [PATCH 3/6] Edited bip353_parse to use it in the common version of the sdk. Edited to accept the dns_resolver from outside --- libs/sdk-common/src/input_parser.rs | 74 ++++++++++++++++----------- libs/sdk-core/src/binding.rs | 2 +- tools/sdk-cli/src/command_handlers.rs | 12 +++-- tools/sdk-cli/src/main.rs | 9 +++- 4 files changed, 60 insertions(+), 37 deletions(-) diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index 80ded8411..da11adce7 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -6,18 +6,20 @@ use ::bip21::Uri; use anyhow::{anyhow, Context, Result}; use bitcoin::bech32; use bitcoin::bech32::FromBase32; +use hickory_resolver::name_server::GenericConnector; +use hickory_resolver::AsyncResolver; use log::error; use percent_encoding::NON_ALPHANUMERIC; use regex::Regex; use serde::{Deserialize, Serialize}; use LnUrlRequestData::*; -use trust_dns_resolver::config::*; -use trust_dns_resolver::TokioAsyncResolver; +use hickory_resolver::name_server::*; use crate::prelude::*; const USER_BITCOIN_PAYMENT_PREFIX: &str = "user._bitcoin-payment"; +const BOLT12_PREFIX: &str = "lno="; const LNURL_PAY_PREFIX: &str = "lnurl="; /// Parses generic user input, typically pasted from clipboard or scanned from a QR. @@ -186,12 +188,43 @@ const LNURL_PAY_PREFIX: &str = "lnurl="; /// } /// } /// ``` +pub async fn parse( + input: &str, + external_input_parsers: Option<&[ExternalInputParser]>, + dns_resolver: Option<&AsyncResolver>>, +) -> Result { + let mut input = input.trim(); -async fn bip353_parse(input: &str) -> Option { - if let Some((local_part, domain)) = input.split_once('@') { - let dns_resolver = - TokioAsyncResolver::tokio(ResolverConfig::default(), ResolverOpts::default()); + // Try to parse the destination as a bip353 address. + let input_str = if let Some(resolver) = dns_resolver { + match bip353_parse(input, resolver).await { + Some(value) => value, + None => input.to_string(), + } + } else { + input.to_string() + }; + + println!("Input {}, input_str {}", input, input_str); + input = input_str.as_str(); + + if let Ok(input_type) = parse_core(input).await { + return Ok(input_type); + } + + if let Some(external_input_parsers) = external_input_parsers { + return parse_external(input, external_input_parsers).await; + } + + Err(anyhow!("Unrecognized input type")) +} + +async fn bip353_parse( + input: &str, + dns_resolver: &AsyncResolver>, +) -> Option { + if let Some((local_part, domain)) = input.split_once('@') { let dns_name = format!("{}.{}.{}", local_part, USER_BITCOIN_PAYMENT_PREFIX, domain); // Query for TXT records of a domain @@ -209,6 +242,10 @@ async fn bip353_parse(input: &str) -> Option { // Decode TXT data match String::from_utf8(txt_data) { Ok(decoded) => { + if let Some((_, bolt12_address)) = decoded.split_once(BOLT12_PREFIX) { + return Some(bolt12_address.to_string()); + } + if let Some((_, lnurl)) = decoded.split_once(LNURL_PAY_PREFIX) { return Some(lnurl.to_string()); } @@ -222,31 +259,6 @@ async fn bip353_parse(input: &str) -> Option { None } -pub async fn parse( - input: &str, - external_input_parsers: Option<&[ExternalInputParser]>, -) -> Result { - let mut input = input.trim(); - - // Try to parse the destination as a bip353 address. - let input_str = match bip353_parse(input).await { - Some(value) => value, - None => input.to_string(), - }; - - input = input_str.as_str(); - - if let Ok(input_type) = parse_core(input).await { - return Ok(input_type); - } - - if let Some(external_input_parsers) = external_input_parsers { - return parse_external(input, external_input_parsers).await; - } - - Err(anyhow!("Unrecognized input type")) -} - /// Core parse implementation async fn parse_core(input: &str) -> Result { // Covers BIP 21 URIs and simple onchain BTC addresses (which are valid BIP 21 with the 'bitcoin:' prefix) diff --git a/libs/sdk-core/src/binding.rs b/libs/sdk-core/src/binding.rs index 09b0db4f1..1fbb3e4f6 100644 --- a/libs/sdk-core/src/binding.rs +++ b/libs/sdk-core/src/binding.rs @@ -504,7 +504,7 @@ pub fn parse_invoice(invoice: String) -> Result { } pub fn parse_input(input: String) -> Result { - block_on(async { parse(&input, None).await }) + block_on(async { parse(&input, None, None).await }) } /* Payment API's */ diff --git a/tools/sdk-cli/src/command_handlers.rs b/tools/sdk-cli/src/command_handlers.rs index fd58acec6..bc863b0fb 100644 --- a/tools/sdk-cli/src/command_handlers.rs +++ b/tools/sdk-cli/src/command_handlers.rs @@ -29,6 +29,9 @@ use rustyline::hint::HistoryHinter; use rustyline::Editor; use rustyline::{Completer, Helper, Hinter, Validator}; +use breez_sdk_core::hickory_resolver::name_server::{GenericConnector, TokioRuntimeProvider}; +use breez_sdk_core::hickory_resolver::AsyncResolver; + static BREEZ_SERVICES: OnceCell> = OnceCell::new(); fn sdk() -> Result> { @@ -72,6 +75,7 @@ pub(crate) async fn handle_command( rl: &mut Editor, persistence: &CliPersistence, command: Commands, + dns_resolver: &AsyncResolver>, ) -> Result { match command { Commands::SetAPIKey { key } => { @@ -124,7 +128,7 @@ pub(crate) async fn handle_command( sdk()?.sync().await?; Ok("Sync finished successfully".to_string()) } - Commands::Parse { input } => parse(&input, None) + Commands::Parse { input } => parse(&input, None, Some(dns_resolver)) .await .map(|res| serde_json::to_string_pretty(&res))? .map_err(|e| e.into()), @@ -466,7 +470,7 @@ pub(crate) async fn handle_command( label, validate_success_url, use_trampoline, - } => match parse(&lnurl, None).await? { + } => match parse(&lnurl, None, Some(dns_resolver)).await? { LnUrlPay { data: pd } => { let prompt = format!( "Amount to pay in millisatoshi (min {} msat, max {} msat: ", @@ -494,7 +498,7 @@ pub(crate) async fn handle_command( _ => Err(anyhow!("Invalid input")), }, Commands::LnurlWithdraw { lnurl } => { - match parse(&lnurl, None).await? { + match parse(&lnurl, None, Some(dns_resolver)).await? { LnUrlWithdraw { data: wd } => { info!("Endpoint description: {}", wd.default_description); @@ -536,7 +540,7 @@ pub(crate) async fn handle_command( Commands::LnurlAuth { lnurl } => { let lnurl_endpoint = lnurl.trim(); - match parse(lnurl_endpoint, None).await? { + match parse(lnurl_endpoint, None, Some(dns_resolver)).await? { LnUrlAuth { data: ad } => { let auth_res = sdk()?.lnurl_auth(ad).await?; serde_json::to_string_pretty(&auth_res).map_err(|e| e.into()) diff --git a/tools/sdk-cli/src/main.rs b/tools/sdk-cli/src/main.rs index 78c50a223..ab4208701 100644 --- a/tools/sdk-cli/src/main.rs +++ b/tools/sdk-cli/src/main.rs @@ -7,6 +7,8 @@ mod persist; use crate::command_handlers::CliHelper; use anyhow::{anyhow, ensure, Result}; +use breez_sdk_core::hickory_resolver::config::{ResolverConfig, ResolverOpts}; +use breez_sdk_core::hickory_resolver::TokioAsyncResolver; use breez_sdk_core::BreezServices; use clap::Parser; use command_handlers::handle_command; @@ -40,6 +42,11 @@ async fn main() -> Result<()> { info!("No previous history."); } + let mut dns_resolvers_opts = ResolverOpts::default(); + dns_resolvers_opts.validate = true; + + let dns_resolver = TokioAsyncResolver::tokio(ResolverConfig::default(), dns_resolvers_opts); + loop { let readline = rl.readline("sdk> "); match readline { @@ -52,7 +59,7 @@ async fn main() -> Result<()> { println!("{}", cli_res.unwrap_err()); continue; } - let res = handle_command(rl, &persistence, cli_res.unwrap()).await; + let res = handle_command(rl, &persistence, cli_res.unwrap(), &dns_resolver).await; show_results(res); continue; } From 92087061f2699c714b24ab7e45246be01704d322 Mon Sep 17 00:00:00 2001 From: Lorenzo Ronzani Date: Thu, 19 Dec 2024 16:05:18 +0100 Subject: [PATCH 4/6] Integrating the requested changes --- libs/sdk-common/src/input_parser.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index 2008544a9..8d8c282c2 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -205,8 +205,6 @@ pub async fn parse( input.to_string() }; - println!("Input {}, input_str {}", input, input_str); - input = input_str.as_str(); if let Ok(input_type) = parse_core(input).await { @@ -242,6 +240,8 @@ async fn bip353_parse( // Decode TXT data match String::from_utf8(txt_data) { Ok(decoded) => { + // The idea is to return from this parse only the BIP21 address and do logic on it inside the parse_core function. + // return Some(decoded); if let Some((_, bolt12_address)) = decoded.split_once(BOLT12_PREFIX) { return Some(bolt12_address.to_string()); } From f070aaf011094fe0095ba7d55b4f43f5c9eccbaa Mon Sep 17 00:00:00 2001 From: Lorenzo Ronzani Date: Fri, 20 Dec 2024 17:34:25 +0100 Subject: [PATCH 5/6] Refactored according to the provided feedback --- libs/sdk-common/src/input_parser.rs | 48 +++++++++++++++++---------- libs/sdk-core/src/binding.rs | 2 +- tools/sdk-cli/src/command_handlers.rs | 12 +++---- tools/sdk-cli/src/main.rs | 9 +---- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index 8d8c282c2..e8acbaffc 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -6,9 +6,11 @@ use ::bip21::Uri; use anyhow::{anyhow, Context, Result}; use bitcoin::bech32; use bitcoin::bech32::FromBase32; +use hickory_resolver::config::{ResolverConfig, ResolverOpts}; use hickory_resolver::name_server::GenericConnector; use hickory_resolver::AsyncResolver; -use log::error; +use hickory_resolver::TokioAsyncResolver; +use log::{debug, error}; use percent_encoding::NON_ALPHANUMERIC; use regex::Regex; use serde::{Deserialize, Serialize}; @@ -21,6 +23,7 @@ use crate::prelude::*; const USER_BITCOIN_PAYMENT_PREFIX: &str = "user._bitcoin-payment"; const BOLT12_PREFIX: &str = "lno="; const LNURL_PAY_PREFIX: &str = "lnurl="; +const BIP353_PREFIX: &str = "bitcoin:"; /// Parses generic user input, typically pasted from clipboard or scanned from a QR. /// @@ -191,21 +194,21 @@ const LNURL_PAY_PREFIX: &str = "lnurl="; pub async fn parse( input: &str, external_input_parsers: Option<&[ExternalInputParser]>, - dns_resolver: Option<&AsyncResolver>>, ) -> Result { - let mut input = input.trim(); + let input = input.trim(); + + let mut dns_resolvers_opts = ResolverOpts::default(); + dns_resolvers_opts.validate = true; + + let dns_resolver = TokioAsyncResolver::tokio(ResolverConfig::default(), dns_resolvers_opts); // Try to parse the destination as a bip353 address. - let input_str = if let Some(resolver) = dns_resolver { - match bip353_parse(input, resolver).await { - Some(value) => value, - None => input.to_string(), - } - } else { - input.to_string() + let input_parsed = match bip353_parse(input, &dns_resolver).await { + Some(value) => value, + None => input.to_string(), }; - input = input_str.as_str(); + let input = input_parsed.as_str(); if let Ok(input_type) = parse_core(input).await { return Ok(input_type); @@ -232,7 +235,7 @@ async fn bip353_parse( .flat_map(|record| record.to_string().into_bytes()) .collect::>(), Err(e) => { - eprintln!("Failed to lookup TXT records: {}", e); + debug!("No BIP353 TXT records found: {}", e); return None; } }; @@ -240,18 +243,29 @@ async fn bip353_parse( // Decode TXT data match String::from_utf8(txt_data) { Ok(decoded) => { - // The idea is to return from this parse only the BIP21 address and do logic on it inside the parse_core function. - // return Some(decoded); - if let Some((_, bolt12_address)) = decoded.split_once(BOLT12_PREFIX) { + if !decoded.to_lowercase().starts_with(BIP353_PREFIX) { + error!( + "Invalid decoded TXT data (doesn't begin with: {})", + BIP353_PREFIX + ); + + return None; + } + + if let Some((_, bolt12_address)) = + decoded.split_once(&format!("{}?{}", BIP353_PREFIX, BOLT12_PREFIX)) + { return Some(bolt12_address.to_string()); } - if let Some((_, lnurl)) = decoded.split_once(LNURL_PAY_PREFIX) { + if let Some((_, lnurl)) = + decoded.split_once(&format!("{}?{}", BIP353_PREFIX, LNURL_PAY_PREFIX)) + { return Some(lnurl.to_string()); } } Err(e) => { - eprintln!("Failed to decode TXT data: {}", e); + error!("Failed to decode TXT data: {}", e); } } } diff --git a/libs/sdk-core/src/binding.rs b/libs/sdk-core/src/binding.rs index 1fbb3e4f6..09b0db4f1 100644 --- a/libs/sdk-core/src/binding.rs +++ b/libs/sdk-core/src/binding.rs @@ -504,7 +504,7 @@ pub fn parse_invoice(invoice: String) -> Result { } pub fn parse_input(input: String) -> Result { - block_on(async { parse(&input, None, None).await }) + block_on(async { parse(&input, None).await }) } /* Payment API's */ diff --git a/tools/sdk-cli/src/command_handlers.rs b/tools/sdk-cli/src/command_handlers.rs index bc863b0fb..fd58acec6 100644 --- a/tools/sdk-cli/src/command_handlers.rs +++ b/tools/sdk-cli/src/command_handlers.rs @@ -29,9 +29,6 @@ use rustyline::hint::HistoryHinter; use rustyline::Editor; use rustyline::{Completer, Helper, Hinter, Validator}; -use breez_sdk_core::hickory_resolver::name_server::{GenericConnector, TokioRuntimeProvider}; -use breez_sdk_core::hickory_resolver::AsyncResolver; - static BREEZ_SERVICES: OnceCell> = OnceCell::new(); fn sdk() -> Result> { @@ -75,7 +72,6 @@ pub(crate) async fn handle_command( rl: &mut Editor, persistence: &CliPersistence, command: Commands, - dns_resolver: &AsyncResolver>, ) -> Result { match command { Commands::SetAPIKey { key } => { @@ -128,7 +124,7 @@ pub(crate) async fn handle_command( sdk()?.sync().await?; Ok("Sync finished successfully".to_string()) } - Commands::Parse { input } => parse(&input, None, Some(dns_resolver)) + Commands::Parse { input } => parse(&input, None) .await .map(|res| serde_json::to_string_pretty(&res))? .map_err(|e| e.into()), @@ -470,7 +466,7 @@ pub(crate) async fn handle_command( label, validate_success_url, use_trampoline, - } => match parse(&lnurl, None, Some(dns_resolver)).await? { + } => match parse(&lnurl, None).await? { LnUrlPay { data: pd } => { let prompt = format!( "Amount to pay in millisatoshi (min {} msat, max {} msat: ", @@ -498,7 +494,7 @@ pub(crate) async fn handle_command( _ => Err(anyhow!("Invalid input")), }, Commands::LnurlWithdraw { lnurl } => { - match parse(&lnurl, None, Some(dns_resolver)).await? { + match parse(&lnurl, None).await? { LnUrlWithdraw { data: wd } => { info!("Endpoint description: {}", wd.default_description); @@ -540,7 +536,7 @@ pub(crate) async fn handle_command( Commands::LnurlAuth { lnurl } => { let lnurl_endpoint = lnurl.trim(); - match parse(lnurl_endpoint, None, Some(dns_resolver)).await? { + match parse(lnurl_endpoint, None).await? { LnUrlAuth { data: ad } => { let auth_res = sdk()?.lnurl_auth(ad).await?; serde_json::to_string_pretty(&auth_res).map_err(|e| e.into()) diff --git a/tools/sdk-cli/src/main.rs b/tools/sdk-cli/src/main.rs index ab4208701..78c50a223 100644 --- a/tools/sdk-cli/src/main.rs +++ b/tools/sdk-cli/src/main.rs @@ -7,8 +7,6 @@ mod persist; use crate::command_handlers::CliHelper; use anyhow::{anyhow, ensure, Result}; -use breez_sdk_core::hickory_resolver::config::{ResolverConfig, ResolverOpts}; -use breez_sdk_core::hickory_resolver::TokioAsyncResolver; use breez_sdk_core::BreezServices; use clap::Parser; use command_handlers::handle_command; @@ -42,11 +40,6 @@ async fn main() -> Result<()> { info!("No previous history."); } - let mut dns_resolvers_opts = ResolverOpts::default(); - dns_resolvers_opts.validate = true; - - let dns_resolver = TokioAsyncResolver::tokio(ResolverConfig::default(), dns_resolvers_opts); - loop { let readline = rl.readline("sdk> "); match readline { @@ -59,7 +52,7 @@ async fn main() -> Result<()> { println!("{}", cli_res.unwrap_err()); continue; } - let res = handle_command(rl, &persistence, cli_res.unwrap(), &dns_resolver).await; + let res = handle_command(rl, &persistence, cli_res.unwrap()).await; show_results(res); continue; } From 36f65d9132f29edd3c27ec21f994d5976e924562 Mon Sep 17 00:00:00 2001 From: Lorenzo Ronzani Date: Fri, 20 Dec 2024 17:36:31 +0100 Subject: [PATCH 6/6] Fixed import --- libs/sdk-common/src/input_parser.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index e8acbaffc..9cfb31f7f 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -7,7 +7,7 @@ use anyhow::{anyhow, Context, Result}; use bitcoin::bech32; use bitcoin::bech32::FromBase32; use hickory_resolver::config::{ResolverConfig, ResolverOpts}; -use hickory_resolver::name_server::GenericConnector; +use hickory_resolver::name_server::{GenericConnector, TokioRuntimeProvider}; use hickory_resolver::AsyncResolver; use hickory_resolver::TokioAsyncResolver; use log::{debug, error}; @@ -16,8 +16,6 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use LnUrlRequestData::*; -use hickory_resolver::name_server::*; - use crate::prelude::*; const USER_BITCOIN_PAYMENT_PREFIX: &str = "user._bitcoin-payment";