Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(web3): bind web3 execution approvals to cached quotes

Steven Enamakel5d0ed3f0d732
diff --git a/Cargo.lock b/Cargo.lock
index 28da21b24f..ebd4a99a32 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7551,7 +7551,7 @@ dependencies = [
[[package]]
name = "tinywallet"
-version = "0.13.0"
+version = "0.14.1"
dependencies = [
"coins-bip32",
"coins-bip39",
@@ -7569,7 +7569,7 @@ dependencies = [
[[package]]
name = "tinywallet-bus"
-version = "0.13.0"
+version = "0.14.1"
dependencies = [
"serde",
"serde_json",
@@ -7578,7 +7578,7 @@ dependencies = [
[[package]]
name = "tinywallet-crypto"
-version = "0.13.0"
+version = "0.14.1"
dependencies = [
"async-trait",
"bech32 0.12.0",
@@ -7594,7 +7594,7 @@ dependencies = [
[[package]]
name = "tinywallet-web3"
-version = "0.13.0"
+version = "0.14.1"
dependencies = [
"anyhow",
"async-trait",
@@ -7615,7 +7615,7 @@ dependencies = [
[[package]]
name = "tinywallet-x402"
-version = "0.13.0"
+version = "0.14.1"
dependencies = [
"anyhow",
"async-trait",
diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rs
index ae611f3730..9e9d69b7b6 100644
--- a/crates/openhuman-core/src/modules/mod.rs
+++ b/crates/openhuman-core/src/modules/mod.rs
@@ -90,6 +90,8 @@ pub mod wallet;
mod wallet_host;
#[cfg(feature = "web3")]
pub(crate) mod wallet_service;
+#[cfg(feature = "web3")]
+pub(crate) mod web3_service;
#[cfg(feature = "modules")]
pub use ops::{ensure_loaded, ensure_loaded_within, state_of, LoadError};
diff --git a/crates/openhuman-core/src/modules/registry/records_docs_wallet.rs b/crates/openhuman-core/src/modules/registry/records_docs_wallet.rs
index fd825aa5d2..2937d6b0a6 100644
--- a/crates/openhuman-core/src/modules/registry/records_docs_wallet.rs
+++ b/crates/openhuman-core/src/modules/registry/records_docs_wallet.rs
@@ -95,101 +95,101 @@ pub(crate) const TINYDOCS: ModuleRecord = ModuleRecord {
/// The contract also exposes `ExportKey` for downstream hosts that must drive
/// a signer locally; OpenHuman itself does not call it.
///
-/// The pinned v0.13.0 release carries the native wallet, Web3, and x402 bus
-/// operations. Secret-bearing operations remain confidential and require both
+/// The pinned v0.14.1 release carries the native wallet, Web3, and x402 bus
+/// operations, including typed configured-endpoint references. Secret-bearing operations remain confidential and require both
/// attestation and a matching pinned digest.
pub(crate) const TINYWALLET: ModuleRecord = ModuleRecord {
id: "tinywallet",
description: "Transaction building and assembly for Bitcoin, EVM, Solana and Tron",
bus_name: "ai.tinyhumans.tinywallet.Wallet",
object_path: "/ai/tinyhumans/tinywallet/Wallet",
- version: "0.13.0",
- release_url: "https://github.com/tinyhumansai/tinywallet/releases/tag/v0.13.0",
+ version: "0.14.1",
+ release_url: "https://github.com/tinyhumansai/tinywallet/releases/tag/v0.14.1",
assets: &[
PlatformAsset {
host_key: "ubuntu-24.04-x86_64",
- archive: "tinywallet-module-0.13.0-ubuntu-24.04-x86_64.tar.gz",
- sha256: "284983d01c548109b3e9d5bbca1951787912f713b4a98920b9b45cfd034b6760",
+ archive: "tinywallet-module-0.14.1-ubuntu-24.04-x86_64.tar.gz",
+ sha256: "4165b555daaa88305aedffc58aaa05cbb9349b2024ae88d1f27b85497d12f34c",
},
PlatformAsset {
host_key: "ubuntu-24.04-arm64",
- archive: "tinywallet-module-0.13.0-ubuntu-24.04-arm64.tar.gz",
- sha256: "18ef8ffe518f731dc594d1606554ca12c840219e54f230382937061c395ab860",
+ archive: "tinywallet-module-0.14.1-ubuntu-24.04-arm64.tar.gz",
+ sha256: "36ef748e79eca9b3ef38b8fbc76f1cd084ee68b1db776d783ee9ec0be00fa1eb",
},
PlatformAsset {
host_key: "ubuntu-22.04-x86_64",
- archive: "tinywallet-module-0.13.0-ubuntu-22.04-x86_64.tar.gz",
- sha256: "92d0d0fe9ab20fdf4c44aa58d762b7e28b6a08876899a5b2d368df3feabcd2d5",
+ archive: "tinywallet-module-0.14.1-ubuntu-22.04-x86_64.tar.gz",
+ sha256: "313f6d7fc9e744236ec7a923070b8a3267798b4834a501935dfe108dde5cf3e8",
},
PlatformAsset {
host_key: "ubuntu-22.04-arm64",
- archive: "tinywallet-module-0.13.0-ubuntu-22.04-arm64.tar.gz",
- sha256: "4d0e17d778c0c84df17e4c5b7fa60aa9296efecc5726902008946409b3a3c9e1",
+ archive: "tinywallet-module-0.14.1-ubuntu-22.04-arm64.tar.gz",
+ sha256: "3f47a5eaa3db37a3ecb846ba93d83630a6c62188224248557b230f60dbfa3000",
},
PlatformAsset {
host_key: "macos-26-arm64",
- archive: "tinywallet-module-0.13.0-macos-26-arm64.tar.gz",
- sha256: "e01a70efbcece8e134abfa84c70181425802415525303d7ba2a7798afbab1041",
+ archive: "tinywallet-module-0.14.1-macos-26-arm64.tar.gz",
+ sha256: "06154b2fe6fb222e2332a8891c7384acb0b42b45e442d9832932351cd1d95bcc",
},
PlatformAsset {
host_key: "macos-26-x86_64",
- archive: "tinywallet-module-0.13.0-macos-26-x86_64.tar.gz",
- sha256: "c48f1f7807d0b25c2b54dca97237f6e64d02ec3a9396370cd8e3b1857419296a",
+ archive: "tinywallet-module-0.14.1-macos-26-x86_64.tar.gz",
+ sha256: "d51d954794620fc106c5bf90ca67b2f35b5fcf7d54752c777af14e1c4189ede2",
},
PlatformAsset {
host_key: "macos-15-arm64",
- archive: "tinywallet-module-0.13.0-macos-15-arm64.tar.gz",
- sha256: "95f69f2e17ff1785d032f6e1017e12de5c6dc09af9633e67fc9c225dfcef9ce6",
+ archive: "tinywallet-module-0.14.1-macos-15-arm64.tar.gz",
+ sha256: "aa0e77605cd7da33aed7f3c535f6dca3d9eadc0ba01b7030d5d675097562c502",
},
PlatformAsset {
host_key: "macos-15-x86_64",
- archive: "tinywallet-module-0.13.0-macos-15-x86_64.tar.gz",
- sha256: "f3114694e2d666ea1b030db952c589f08d79c60ab79aadb844327e273c5faaf5",
+ archive: "tinywallet-module-0.14.1-macos-15-x86_64.tar.gz",
+ sha256: "25cbba1d1898d3bfdff2f7d7d8bbccb3a8d55bc2b25fcb5e800bbbb3cbbc63e4",
},
PlatformAsset {
host_key: "windows-2025-x86_64",
- archive: "tinywallet-module-0.13.0-windows-2025-x86_64.zip",
- sha256: "7b79a25a1fccef17a4c6e0d400f49646c3a5f321821bb03ddc23e76d6030717a",
+ archive: "tinywallet-module-0.14.1-windows-2025-x86_64.zip",
+ sha256: "628b67ebf7e52dc2c40bb58e09b56af6cd1bb4698634297b15023bbfd092eb78",
},
PlatformAsset {
host_key: "windows-2022-x86_64",
- archive: "tinywallet-module-0.13.0-windows-2022-x86_64.zip",
- sha256: "0b7126be04b23dd5fad883d7f1dd33dd65c1042af68f93593590ea07c5daa95e",
+ archive: "tinywallet-module-0.14.1-windows-2022-x86_64.zip",
+ sha256: "b11b0a92daba13b2fa1afe0c9cefb5632c085a3ddea61ef5477b97cfd335d6b0",
},
PlatformAsset {
host_key: "windows-11-arm64",
- archive: "tinywallet-module-0.13.0-windows-11-arm64.zip",
- sha256: "483d3fda2c46de71c8efd5dfa4ec828c0b6c86bb164c8362c1356f85cb8ec231",
+ archive: "tinywallet-module-0.14.1-windows-11-arm64.zip",
+ sha256: "7459aec5c7f0e0e8ab0c3dd11461938b0d7a99c8ba7e9a0ee4beaeb894db8907",
},
PlatformAsset {
host_key: "archlinux-arm64",
- archive: "tinywallet-module-0.13.0-archlinux-arm64.tar.gz",
- sha256: "ad2222bd1d2dd680568f486e40389c0b963cf5ba2d170f9d658985f31cabb511",
+ archive: "tinywallet-module-0.14.1-archlinux-arm64.tar.gz",
+ sha256: "4e8eddcedbab8dd7f4d03ffdba9d1f8f7f00003240ff55abb9b22381d4ebcc00",
},
PlatformAsset {
host_key: "archlinux-x86_64",
- archive: "tinywallet-module-0.13.0-archlinux-x86_64.tar.gz",
- sha256: "d67f541330f7712106238b90d993550d2e2e55f33d3c8c9f50669a1a51c1e981",
+ archive: "tinywallet-module-0.14.1-archlinux-x86_64.tar.gz",
+ sha256: "1e267ec642d89fdc9a630d6ab963abdd1d311fea054b2fae5a2b1055be8261bc",
},
PlatformAsset {
host_key: "fedora-43-arm64",
- archive: "tinywallet-module-0.13.0-fedora-43-arm64.tar.gz",
- sha256: "a2d62b03f2e99008ee3fe7ea84290fd050e12016ce36e89fda24d5449e795261",
+ archive: "tinywallet-module-0.14.1-fedora-43-arm64.tar.gz",
+ sha256: "df9f1ad060cb4282a369f8c353e2859b88f92dc5511b328922f14efd7411d6bd",
},
PlatformAsset {
host_key: "fedora-43-x86_64",
- archive: "tinywallet-module-0.13.0-fedora-43-x86_64.tar.gz",
- sha256: "0c8c5dbf2aa7b7caa371aa6366c7cfdd232fda41e2dbd894d2ef344c7c2cfa0a",
+ archive: "tinywallet-module-0.14.1-fedora-43-x86_64.tar.gz",
+ sha256: "4b178adbd9d1ff7e59d9066299f5cd8fef9d686f8a35d1afed6410162fa1a0bd",
},
PlatformAsset {
host_key: "fedora-44-arm64",
- archive: "tinywallet-module-0.13.0-fedora-44-arm64.tar.gz",
- sha256: "272b535910fc4bc84099887b7ccfbdd9d41a6d187616086c174f86cb77f21757",
+ archive: "tinywallet-module-0.14.1-fedora-44-arm64.tar.gz",
+ sha256: "e3da4a7f315d3d4d90563a37ae72d617dbd4c2f0042f835222e7fa86e04eb82e",
},
PlatformAsset {
host_key: "fedora-44-x86_64",
- archive: "tinywallet-module-0.13.0-fedora-44-x86_64.tar.gz",
- sha256: "3dcad60a65d4f0bbb1af838468a2f52d648d22b2fbc849ae0548a30ed9806646",
+ archive: "tinywallet-module-0.14.1-fedora-44-x86_64.tar.gz",
+ sha256: "d7ddd11719ab9b6431d6a4c264d6bd8d24764037f2724cb6e280b714793db6fc",
},
],
load: LoadPolicy::Lazy,
diff --git a/crates/openhuman-core/src/modules/registry_tests.rs b/crates/openhuman-core/src/modules/registry_tests.rs
index b52ed27251..43018bb042 100644
--- a/crates/openhuman-core/src/modules/registry_tests.rs
+++ b/crates/openhuman-core/src/modules/registry_tests.rs
@@ -20,12 +20,13 @@ fn tinycomputer_registry_matches_bus_contract_and_published_release() {
}
#[test]
-fn tinywallet_registry_matches_the_verified_v013_release_manifest() {
+fn tinywallet_registry_matches_the_verified_v0141_release_manifest() {
let wallet = find("tinywallet").expect("compiled TinyWallet module");
- assert_eq!(wallet.version, "0.13.0");
+ assert_eq!(wallet.version, "0.14.1");
+ assert_eq!(tinywallet_bus::CONTRACT_VERSION, (1, 8));
assert_eq!(
wallet.release_url,
- "https://github.com/tinyhumansai/tinywallet/releases/tag/v0.13.0"
+ "https://github.com/tinyhumansai/tinywallet/releases/tag/v0.14.1"
);
let actual = wallet
@@ -36,88 +37,88 @@ fn tinywallet_registry_matches_the_verified_v013_release_manifest() {
let published = [
(
"ubuntu-24.04-x86_64",
- "tinywallet-module-0.13.0-ubuntu-24.04-x86_64.tar.gz",
- "284983d01c548109b3e9d5bbca1951787912f713b4a98920b9b45cfd034b6760",
+ "tinywallet-module-0.14.1-ubuntu-24.04-x86_64.tar.gz",
+ "4165b555daaa88305aedffc58aaa05cbb9349b2024ae88d1f27b85497d12f34c",
),
(
"ubuntu-24.04-arm64",
- "tinywallet-module-0.13.0-ubuntu-24.04-arm64.tar.gz",
- "18ef8ffe518f731dc594d1606554ca12c840219e54f230382937061c395ab860",
+ "tinywallet-module-0.14.1-ubuntu-24.04-arm64.tar.gz",
+ "36ef748e79eca9b3ef38b8fbc76f1cd084ee68b1db776d783ee9ec0be00fa1eb",
),
(
"ubuntu-22.04-x86_64",
- "tinywallet-module-0.13.0-ubuntu-22.04-x86_64.tar.gz",
- "92d0d0fe9ab20fdf4c44aa58d762b7e28b6a08876899a5b2d368df3feabcd2d5",
+ "tinywallet-module-0.14.1-ubuntu-22.04-x86_64.tar.gz",
+ "313f6d7fc9e744236ec7a923070b8a3267798b4834a501935dfe108dde5cf3e8",
),
(
"ubuntu-22.04-arm64",
- "tinywallet-module-0.13.0-ubuntu-22.04-arm64.tar.gz",
- "4d0e17d778c0c84df17e4c5b7fa60aa9296efecc5726902008946409b3a3c9e1",
+ "tinywallet-module-0.14.1-ubuntu-22.04-arm64.tar.gz",
+ "3f47a5eaa3db37a3ecb846ba93d83630a6c62188224248557b230f60dbfa3000",
),
(
"macos-26-arm64",
- "tinywallet-module-0.13.0-macos-26-arm64.tar.gz",
- "e01a70efbcece8e134abfa84c70181425802415525303d7ba2a7798afbab1041",
+ "tinywallet-module-0.14.1-macos-26-arm64.tar.gz",
+ "06154b2fe6fb222e2332a8891c7384acb0b42b45e442d9832932351cd1d95bcc",
),
(
"macos-26-x86_64",
- "tinywallet-module-0.13.0-macos-26-x86_64.tar.gz",
- "c48f1f7807d0b25c2b54dca97237f6e64d02ec3a9396370cd8e3b1857419296a",
+ "tinywallet-module-0.14.1-macos-26-x86_64.tar.gz",
+ "d51d954794620fc106c5bf90ca67b2f35b5fcf7d54752c777af14e1c4189ede2",
),
(
"macos-15-arm64",
- "tinywallet-module-0.13.0-macos-15-arm64.tar.gz",
- "95f69f2e17ff1785d032f6e1017e12de5c6dc09af9633e67fc9c225dfcef9ce6",
+ "tinywallet-module-0.14.1-macos-15-arm64.tar.gz",
+ "aa0e77605cd7da33aed7f3c535f6dca3d9eadc0ba01b7030d5d675097562c502",
),
(
"macos-15-x86_64",
- "tinywallet-module-0.13.0-macos-15-x86_64.tar.gz",
- "f3114694e2d666ea1b030db952c589f08d79c60ab79aadb844327e273c5faaf5",
+ "tinywallet-module-0.14.1-macos-15-x86_64.tar.gz",
+ "25cbba1d1898d3bfdff2f7d7d8bbccb3a8d55bc2b25fcb5e800bbbb3cbbc63e4",
),
(
"windows-2025-x86_64",
- "tinywallet-module-0.13.0-windows-2025-x86_64.zip",
- "7b79a25a1fccef17a4c6e0d400f49646c3a5f321821bb03ddc23e76d6030717a",
+ "tinywallet-module-0.14.1-windows-2025-x86_64.zip",
+ "628b67ebf7e52dc2c40bb58e09b56af6cd1bb4698634297b15023bbfd092eb78",
),
(
"windows-2022-x86_64",
- "tinywallet-module-0.13.0-windows-2022-x86_64.zip",
- "0b7126be04b23dd5fad883d7f1dd33dd65c1042af68f93593590ea07c5daa95e",
+ "tinywallet-module-0.14.1-windows-2022-x86_64.zip",
+ "b11b0a92daba13b2fa1afe0c9cefb5632c085a3ddea61ef5477b97cfd335d6b0",
),
(
"windows-11-arm64",
- "tinywallet-module-0.13.0-windows-11-arm64.zip",
- "483d3fda2c46de71c8efd5dfa4ec828c0b6c86bb164c8362c1356f85cb8ec231",
+ "tinywallet-module-0.14.1-windows-11-arm64.zip",
+ "7459aec5c7f0e0e8ab0c3dd11461938b0d7a99c8ba7e9a0ee4beaeb894db8907",
),
(
"archlinux-arm64",
- "tinywallet-module-0.13.0-archlinux-arm64.tar.gz",
- "ad2222bd1d2dd680568f486e40389c0b963cf5ba2d170f9d658985f31cabb511",
+ "tinywallet-module-0.14.1-archlinux-arm64.tar.gz",
+ "4e8eddcedbab8dd7f4d03ffdba9d1f8f7f00003240ff55abb9b22381d4ebcc00",
),
(
"archlinux-x86_64",
- "tinywallet-module-0.13.0-archlinux-x86_64.tar.gz",
- "d67f541330f7712106238b90d993550d2e2e55f33d3c8c9f50669a1a51c1e981",
+ "tinywallet-module-0.14.1-archlinux-x86_64.tar.gz",
+ "1e267ec642d89fdc9a630d6ab963abdd1d311fea054b2fae5a2b1055be8261bc",
),
(
"fedora-43-arm64",
- "tinywallet-module-0.13.0-fedora-43-arm64.tar.gz",
- "a2d62b03f2e99008ee3fe7ea84290fd050e12016ce36e89fda24d5449e795261",
+ "tinywallet-module-0.14.1-fedora-43-arm64.tar.gz",
+ "df9f1ad060cb4282a369f8c353e2859b88f92dc5511b328922f14efd7411d6bd",
),
(
"fedora-43-x86_64",
- "tinywallet-module-0.13.0-fedora-43-x86_64.tar.gz",
- "0c8c5dbf2aa7b7caa371aa6366c7cfdd232fda41e2dbd894d2ef344c7c2cfa0a",
+ "tinywallet-module-0.14.1-fedora-43-x86_64.tar.gz",
+ "4b178adbd9d1ff7e59d9066299f5cd8fef9d686f8a35d1afed6410162fa1a0bd",
),
(
"fedora-44-arm64",
- "tinywallet-module-0.13.0-fedora-44-arm64.tar.gz",
- "272b535910fc4bc84099887b7ccfbdd9d41a6d187616086c174f86cb77f21757",
+ "tinywallet-module-0.14.1-fedora-44-arm64.tar.gz",
+ "e3da4a7f315d3d4d90563a37ae72d617dbd4c2f0042f835222e7fa86e04eb82e",
),
(
"fedora-44-x86_64",
- "tinywallet-module-0.13.0-fedora-44-x86_64.tar.gz",
- "3dcad60a65d4f0bbb1af838468a2f52d648d22b2fbc849ae0548a30ed9806646",
+ "tinywallet-module-0.14.1-fedora-44-x86_64.tar.gz",
+ "d7ddd11719ab9b6431d6a4c264d6bd8d24764037f2724cb6e280b714793db6fc",
),
];
assert_eq!(actual, published);
diff --git a/crates/openhuman-core/src/modules/wallet_host.rs b/crates/openhuman-core/src/modules/wallet_host.rs
index cf7d8958ef..37da64003e 100644
--- a/crates/openhuman-core/src/modules/wallet_host.rs
+++ b/crates/openhuman-core/src/modules/wallet_host.rs
@@ -15,7 +15,7 @@ use tinywallet_bus::wire::{
AuthorizeX402PaymentRequest, ChainTransportRequest, ChainTransportResult, HostResponse,
WalletAccountInfo, WalletAccountsResponse, WalletBackendRequest, WalletBackendResponse,
};
-use tinywallet_crypto::rpc::{NetworkId, Transport, TransportError};
+use tinywallet_bus::wire::HostEndpointReference;
const HOST_ERROR_NAME: &str = "ai.tinyhumans.tinywallet.Host.Error.CallbackFailed";
@@ -35,10 +35,20 @@ static APPROVALS: OnceLock<Mutex<HashSet<ApprovalKey>>> = OnceLock::new();
static NATIVE_APPROVAL_QUOTES: OnceLock<
Mutex<HashMap<String, tinywallet_bus::wire::PreparedTransaction>>,
> = OnceLock::new();
+static WEB3_APPROVAL_QUOTES: OnceLock<
+ Mutex<HashMap<String, tinywallet_bus::wire::Web3QuoteResponse>>,
+> = OnceLock::new();
static ENDPOINT_REFERENCES: OnceLock<
- Mutex<HashMap<String, (tinywallet_bus::wire::RpcEndpointKey, String)>>,
+ Mutex<HashMap<String, EndpointReference>>,
> = OnceLock::new();
+#[derive(Debug, Clone)]
+struct EndpointReference {
+ service: String,
+ key: tinywallet_bus::wire::RpcEndpointKey,
+ url: String,
+}
+
fn approvals() -> &'static Mutex<HashSet<ApprovalKey>> {
APPROVALS.get_or_init(|| Mutex::new(HashSet::new()))
}
@@ -48,20 +58,25 @@ fn native_approval_quotes(
NATIVE_APPROVAL_QUOTES.get_or_init(|| Mutex::new(HashMap::new()))
}
-fn endpoint_references(
-) -> &'static Mutex<HashMap<String, (tinywallet_bus::wire::RpcEndpointKey, String)>> {
+fn web3_approval_quotes(
+) -> &'static Mutex<HashMap<String, tinywallet_bus::wire::Web3QuoteResponse>> {
+ WEB3_APPROVAL_QUOTES.get_or_init(|| Mutex::new(HashMap::new()))
+}
+
+fn endpoint_references() -> &'static Mutex<HashMap<String, EndpointReference>> {
ENDPOINT_REFERENCES.get_or_init(|| Mutex::new(HashMap::new()))
}
/// Bind module-issued opaque endpoint aliases to the current host configuration.
/// Actual URLs remain in this process and are never serialized onto TinyBus.
pub(crate) fn bind_endpoint_references(
- configured: &tinywallet_bus::wire::NativeWalletConfigResponse,
+ service: &str,
+ references: &[HostEndpointReference],
) -> Result<(), String> {
use tinywallet_bus::wire::RpcEndpointKey;
let mut resolved = HashMap::new();
- for endpoint in &configured.endpoint_references {
+ for endpoint in references {
let url = match endpoint.key {
RpcEndpointKey::Evm { network } => {
crate::web3::wallet::endpoints::rpc_url_for_evm_network(network)
@@ -78,21 +93,26 @@ pub(crate) fn bind_endpoint_references(
};
if endpoint.reference.trim().is_empty()
|| resolved
- .insert(endpoint.reference.clone(), (endpoint.key, url))
+ .insert(endpoint.reference.clone(), EndpointReference {
+ service: service.to_owned(),
+ key: endpoint.key,
+ url,
+ })
.is_some()
{
return Err("wallet module returned an invalid endpoint reference".into());
}
}
- *endpoint_references()
+ endpoint_references()
.lock()
- .map_err(|_| "wallet endpoint reference store is unavailable".to_string())? = resolved;
+ .map_err(|_| "wallet endpoint reference store is unavailable".to_string())?
+ .extend(resolved);
Ok(())
}
-pub(crate) fn clear_endpoint_references() {
+pub(crate) fn clear_endpoint_references(service: &str) {
if let Ok(mut references) = endpoint_references().lock() {
- references.clear();
+ references.retain(|_, endpoint| endpoint.service != service);
}
}
@@ -133,6 +153,7 @@ impl ApprovalPermit {
kind: ApprovalKind,
quote_id: &str,
expected_native_quote: Option<tinywallet_bus::wire::PreparedTransaction>,
+ expected_web3_quote: Option<tinywallet_bus::wire::Web3QuoteResponse>,
) -> Self {
let key = ApprovalKey {
kind,
@@ -148,6 +169,13 @@ impl ApprovalPermit {
active.insert(quote_id.to_owned(), quote);
}
}
+ if kind == ApprovalKind::Web3 {
+ if let (Some(quote), Ok(mut active)) =
+ (expected_web3_quote, web3_approval_quotes().lock())
+ {
+ active.insert(quote_id.to_owned(), quote);
+ }
+ }
Self(key)
}
}
@@ -162,6 +190,11 @@ impl Drop for ApprovalPermit {
active.remove(&self.0.quote_id);
}
}
+ if self.0.kind == ApprovalKind::Web3 {
+ if let Ok(mut active) = web3_approval_quotes().lock() {
+ active.remove(&self.0.quote_id);
+ }
+ }
}
}
@@ -186,6 +219,108 @@ pub(super) fn native_approval_matches_request(
&& native_intent_matches_quote(expected_quote, &request.intent)
}
+fn web3_approval_matches_request(
+ quote: &tinywallet_bus::wire::Web3QuoteResponse,
+ request: &AuthorizeWeb3ExecutionRequest,
+) -> bool {
+ use tinywallet_bus::wire::{Web3ExecutionIntent, Web3QuoteKind, WalletChain};
+
+ let operation_matches = matches!(
+ (quote.kind, request.operation.as_str()),
+ (Web3QuoteKind::Swap, "swap")
+ | (Web3QuoteKind::Bridge, "bridge")
+ | (Web3QuoteKind::DappCall, "dapp_call")
+ );
+ if quote.quote_id != request.quote_id || !operation_matches {
+ return false;
+ }
+
+ match (&request.transaction, quote.signing_chain) {
+ (
+ Web3ExecutionIntent::Evm {
+ network,
+ to,
+ data,
+ value,
+ chain_id,
+ ..
+ },
+ WalletChain::Evm,
+ ) => {
+ let expected_network = quote
+ .quote
+ .get("network")
+ .and_then(serde_json::Value::as_str);
+ if expected_network.is_some_and(|expected| expected != network)
+ || !known_evm_chain(network, *chain_id)
+ {
+ return false;
+ }
+ let transaction = quote.quote.get("tx");
+ match quote.kind {
+ Web3QuoteKind::DappCall => {
+ let expected_to = quote
+ .quote
+ .get("contractAddress")
+ .and_then(serde_json::Value::as_str);
+ let expected_data = quote
+ .quote
+ .get("calldata")
+ .and_then(serde_json::Value::as_str);
+ let expected_value = quote
+ .quote
+ .get("valueRaw")
+ .and_then(serde_json::Value::as_str);
+ expected_to.is_some_and(|expected| expected.eq_ignore_ascii_case(to))
+ && expected_data.is_some_and(|expected| data.as_deref() == Some(expected))
+ && expected_value.is_some_and(|expected| expected == value)
+ }
+ Web3QuoteKind::Swap | Web3QuoteKind::Bridge => {
+ transaction.is_some_and(|transaction| {
+ transaction
+ .get("to")
+ .and_then(serde_json::Value::as_str)
+ .is_some_and(|expected| expected.eq_ignore_ascii_case(to))
+ && transaction
+ .get("data")
+ .and_then(serde_json::Value::as_str)
+ == data.as_deref()
+ && decimal_json(transaction.get("value")).as_deref()
+ == Some(value.as_str())
+ })
+ }
+ }
+ }
+ (
+ Web3ExecutionIntent::Solana { tx_blob_hex },
+ WalletChain::Solana,
+ ) => {
+ let expected = quote
+ .quote
+ .get("tx")
+ .and_then(|transaction| transaction.get("data"))
+ .and_then(serde_json::Value::as_str);
+ matches!(quote.kind, Web3QuoteKind::Swap | Web3QuoteKind::Bridge)
+ && expected == Some(tx_blob_hex.as_str())
+ }
+ _ => false,
+ }
+}
+
+fn known_evm_chain(network: &str, chain_id: u64) -> bool {
+ tinywallet_bus::wire::EvmNetwork::ALL.into_iter().any(|known| {
+ known.as_str() == network && known.chain_id() == chain_id
+ })
+}
+
+fn decimal_json(value: Option<&serde_json::Value>) -> Option<String> {
+ match value? {
+ serde_json::Value::String(value) => Some(value.clone()),
+ serde_json::Value::Number(value) => Some(value.to_string()),
+ _ => None,
+ }
+}
+
fn native_intent_matches_quote(
quote: &tinywallet_bus::wire::PreparedTransaction,
intent: &tinywallet_bus::wire::NativeWalletExecutionIntent,
@@ -332,9 +467,15 @@ pub(crate) async fn with_confirmed_execution<F: Future>(
kind: ApprovalKind,
quote_id: &str,
expected_native_quote: Option<tinywallet_bus::wire::PreparedTransaction>,
+ expected_web3_quote: Option<tinywallet_bus::wire::Web3QuoteResponse>,
future: F,
) -> F::Output {
- let _permit = ApprovalPermit::new(kind, quote_id, expected_native_quote);
+ let _permit = ApprovalPermit::new(
+ kind,
+ quote_id,
+ expected_native_quote,
+ expected_web3_quote,
+ );
future.await
}
@@ -356,19 +497,27 @@ impl WalletHost {
&self,
request: ChainTransportRequest,
) -> tinybus::Result<HostResponse> {
- let (network, endpoint_ref, chain, evm_chain_id) = match &request {
+ let (endpoint_ref, module_endpoint_url, chain, evm_chain_id) = match &request {
ChainTransportRequest::JsonRpc { network, .. }
| ChainTransportRequest::RestGet { network, .. }
| ChainTransportRequest::RestPost { network, .. } => (
- network_id(network.chain, network.evm_chain_id),
network.endpoint_ref.as_deref(),
+ network.endpoint_url.as_deref(),
network.chain,
network.evm_chain_id,
),
};
- let endpoint_url = match endpoint_ref {
- Some(reference) => {
- let Some((key, url)) = endpoint_references()
+ let endpoint_url = match (endpoint_ref, module_endpoint_url) {
+ (Some(_), Some(_)) => {
+ return Ok(HostResponse::ChainTransport(
+ ChainTransportResult::RpcError {
+ message: "wallet request cannot combine an endpoint reference and URL"
+ .into(),
+ },
+ ));
+ }
+ (Some(reference), None) => {
+ let Some(endpoint) = endpoint_references()
.lock()
.ok()
.and_then(|references| references.get(reference).cloned())
@@ -381,7 +530,7 @@ impl WalletHost {
},
));
};
- if Some(key) != endpoint_key(chain, evm_chain_id) {
+ if Some(endpoint.key) != endpoint_key(chain, evm_chain_id) {
return Ok(HostResponse::ChainTransport(
ChainTransportResult::RpcError {
message:
@@ -390,59 +539,62 @@ impl WalletHost {
},
));
}
- Some(url)
+ endpoint.url
+ }
+ (None, Some(url)) => match validate_module_endpoint_url(url) {
+ Ok(url) => url,
+ Err(message) => {
+ return Ok(HostResponse::ChainTransport(
+ ChainTransportResult::RpcError { message },
+ ));
+ }
+ },
+ (None, None) => {
+ return Ok(HostResponse::ChainTransport(
+ ChainTransportResult::RpcError {
+ message: "wallet module did not select an RPC endpoint".into(),
+ },
+ ));
}
- None => None,
};
- let transport = crate::web3::wallet::transport::OpenHumanTransport::new();
let result = match request {
- ChainTransportRequest::JsonRpc { method, params, .. } => match endpoint_url {
- Some(url) => crate::web3::wallet::rpc::rpc_call_to::<serde_json::Value>(
- &url, &method, params,
+ ChainTransportRequest::JsonRpc { method, params, .. } => {
+ crate::web3::wallet::rpc::rpc_call_to::<serde_json::Value>(
+ &endpoint_url,
+ &method,
+ params,
)
.await
- .map_err(|message| crate::web3::wallet::transport::classify(network, message)),
- None => transport.json_rpc(network, &method, params).await,
- },
- ChainTransportRequest::RestGet { path, .. } => match endpoint_url {
- Some(url) => crate::web3::wallet::rpc::rest_get_text(&join_endpoint(&url, &path))
+ .map_err(classify_transport_error)
+ }
+ ChainTransportRequest::RestGet { path, .. } => {
+ crate::web3::wallet::rpc::rest_get_text(&join_endpoint(&endpoint_url, &path))
.await
.map(serde_json::Value::String)
- .map_err(|message| crate::web3::wallet::transport::classify(network, message)),
- None => transport
- .rest_get(network, &path)
- .await
- .map(serde_json::Value::String),
- },
+ .map_err(classify_transport_error)
+ }
ChainTransportRequest::RestPost {
path,
body,
content_type,
..
- } => match endpoint_url {
- Some(url) => crate::web3::wallet::rpc::rest_post_text(
- &join_endpoint(&url, &path),
+ } => {
+ crate::web3::wallet::rpc::rest_post_text(
+ &join_endpoint(&endpoint_url, &path),
&body,
&content_type,
)
.await
.map(serde_json::Value::String)
- .map_err(|message| crate::web3::wallet::transport::classify(network, message)),
- None => transport
- .rest_post(network, &path, body, &content_type)
- .await
- .map(serde_json::Value::String),
- },
+ .map_err(classify_transport_error)
+ }
};
let response = match result {
Ok(body) => ChainTransportResult::Ok { body },
- Err(TransportError::Unreachable { message, .. }) => {
+ Err(TransportFailure::Unreachable(message)) => {
ChainTransportResult::Unreachable { message }
}
- Err(TransportError::Rpc { message, .. }) => ChainTransportResult::RpcError { message },
- Err(error) => ChainTransportResult::RpcError {
- message: error.to_string(),
- },
+ Err(TransportFailure::Rpc(message)) => ChainTransportResult::RpcError { message },
};
Ok(HostResponse::ChainTransport(response))
}
@@ -470,8 +622,15 @@ impl WalletHost {
&self,
request: AuthorizeWeb3ExecutionRequest,
) -> tinybus::Result<HostResponse> {
+ let quote = web3_approval_quotes()
+ .lock()
+ .ok()
+ .and_then(|mut quotes| quotes.remove(&request.quote_id));
Ok(HostResponse::Authorization(AuthorizationResult {
- approved: consume_approval(ApprovalKind::Web3, &request.quote_id),
+ approved: quote
+ .as_ref()
+ .is_some_and(|quote| web3_approval_matches_request(quote, &request))
+ && consume_approval(ApprovalKind::Web3, &request.quote_id),
reason: None,
}))
}
@@ -508,15 +667,33 @@ impl WalletHost {
}
}
-fn network_id(chain: tinywallet_bus::Chain, evm_chain_id: Option<u64>) -> NetworkId {
- if chain == tinywallet_bus::Chain::Evm {
- NetworkId {
- chain,
- evm_chain_id,
- }
+enum TransportFailure {
+ Unreachable(String),
+ Rpc(String),
+}
+
+fn classify_transport_error(message: String) -> TransportFailure {
+ if ["transport failed", "read body failed"]
+ .iter()
+ .any(|marker| message.contains(marker))
+ {
+ TransportFailure::Unreachable(message)
} else {
- NetworkId::chain(chain)
+ TransportFailure::Rpc(message)
+ }
+}
+
+fn validate_module_endpoint_url(raw: &str) -> Result<String, String> {
+ let url = reqwest::Url::parse(raw)
+ .map_err(|_| "wallet module selected an invalid RPC endpoint URL".to_string())?;
+ if !matches!(url.scheme(), "http" | "https")
+ || url.host_str().is_none()
+ || !url.username().is_empty()
+ || url.password().is_some()
+ {
+ return Err("wallet module selected an unsafe RPC endpoint URL".into());
}
+ Ok(raw.to_owned())
}
fn endpoint_key(
diff --git a/crates/openhuman-core/src/modules/wallet_host_tests.rs b/crates/openhuman-core/src/modules/wallet_host_tests.rs
index 5caa7a1590..545427703f 100644
--- a/crates/openhuman-core/src/modules/wallet_host_tests.rs
+++ b/crates/openhuman-core/src/modules/wallet_host_tests.rs
@@ -1,12 +1,21 @@
-use super::{consume_approval, native_approval_matches_request, ApprovalKind, ApprovalPermit};
+use super::{
+ consume_approval, native_approval_matches_request, validate_module_endpoint_url,
+ web3_approval_matches_request, ApprovalKind, ApprovalPermit,
+};
use tinywallet_bus::wire::{
- AuthorizeNativeWalletExecutionRequest, EvmNetwork, NativeWalletExecutionIntent, PreparedKind,
- PreparedStatus, PreparedTransaction, TransactionSpec, WalletChain,
+ AuthorizeNativeWalletExecutionRequest, AuthorizeWeb3ExecutionRequest, EvmNetwork,
+ NativeWalletExecutionIntent, PreparedKind, PreparedStatus, PreparedTransaction, TransactionSpec,
+ WalletChain, Web3ExecutionIntent, Web3QuoteKind, Web3QuoteResponse,
};
#[test]
fn execution_authorization_is_bound_to_one_confirmed_quote_id() {
- let permit = ApprovalPermit::new(ApprovalKind::Web3, "quote-17", None);
+ let permit = ApprovalPermit::new(
+ ApprovalKind::Web3,
+ "quote-17",
+ None,
+ Some(web3_quote("quote-17")),
+ );
assert!(!consume_approval(ApprovalKind::Web3, "quote-18"));
assert!(!consume_approval(ApprovalKind::Native, "quote-17"));
assert!(consume_approval(ApprovalKind::Web3, "quote-17"));
@@ -18,7 +27,12 @@ fn execution_authorization_is_bound_to_one_confirmed_quote_id() {
fn an_unconsumed_confirmation_is_removed_when_the_execution_ends() {
{
let quote = native_quote("quote-cancelled");
- let _permit = ApprovalPermit::new(ApprovalKind::Native, "quote-cancelled", Some(quote));
+ let _permit = ApprovalPermit::new(
+ ApprovalKind::Native,
+ "quote-cancelled",
+ Some(quote),
+ None,
+ );
}
assert!(!consume_approval(ApprovalKind::Native, "quote-cancelled"));
}
@@ -26,7 +40,12 @@ fn an_unconsumed_confirmation_is_removed_when_the_execution_ends() {
#[test]
fn native_approval_rejects_a_quote_that_differs_from_the_confirmed_quote() {
let quote = native_quote("native-quote-facts");
- let permit = ApprovalPermit::new(ApprovalKind::Native, &quote.quote_id, Some(quote.clone()));
+ let permit = ApprovalPermit::new(
+ ApprovalKind::Native,
+ &quote.quote_id,
+ Some(quote.clone()),
+ None,
+ );
let mut changed_quote = quote.clone();
changed_quote.amount_raw = "43".into();
let request = native_request(changed_quote, "0xrecipient", "42");
@@ -39,7 +58,12 @@ fn native_approval_rejects_a_quote_that_differs_from_the_confirmed_quote() {
#[test]
fn native_approval_rejects_signer_intent_that_changes_the_confirmed_transfer() {
let quote = native_quote("native-quote-intent");
- let permit = ApprovalPermit::new(ApprovalKind::Native, &quote.quote_id, Some(quote.clone()));
+ let permit = ApprovalPermit::new(
+ ApprovalKind::Native,
+ &quote.quote_id,
+ Some(quote.clone()),
+ None,
+ );
let request = native_request(quote.clone(), "0xattacker", "42");
assert!(!native_approval_matches_request(&quote, &request));
@@ -50,7 +74,12 @@ fn native_approval_rejects_signer_intent_that_changes_the_confirmed_transfer() {
#[test]
fn native_approval_accepts_the_exact_confirmed_quote_and_signer_intent_once() {
let quote = native_quote("native-quote-valid");
- let permit = ApprovalPermit::new(ApprovalKind::Native, &quote.quote_id, Some(quote.clone()));
+ let permit = ApprovalPermit::new(
+ ApprovalKind::Native,
+ &quote.quote_id,
+ Some(quote.clone()),
+ None,
+ );
let request = native_request(quote.clone(), &quote.to_address, &quote.amount_raw);
assert!(native_approval_matches_request(&quote, &request));
@@ -58,6 +87,75 @@ fn native_approval_accepts_the_exact_confirmed_quote_and_signer_intent_once() {
drop(permit);
}
+#[test]
+fn web3_approval_requires_the_cached_quote_operation_chain_and_transaction() {
+ let quote = web3_quote("web3-valid-quote");
+ let permit = ApprovalPermit::new(ApprovalKind::Web3, &quote.quote_id, None, Some(quote.clone()));
+ let request = AuthorizeWeb3ExecutionRequest {
+ quote_id: quote.quote_id.clone(),
+ operation: "dapp_call".into(),
+ transaction: Web3ExecutionIntent::Evm {
+ network: "polygon_mainnet".into(),
+ to: "0x1111111111111111111111111111111111111111".into(),
+ data: Some("0xabcd".into()),
+ value: "5".into(),
+ nonce: 4,
+ gas_limit: 30_000,
+ gas_price_wei: "7".into(),
+ chain_id: 137,
+ },
+ };
+ assert!(web3_approval_matches_request(&quote, &request));
+ assert!(consume_approval(ApprovalKind::Web3, &quote.quote_id));
+ drop(permit);
+}
+
+#[test]
+fn web3_approval_rejects_changed_quote_intent_before_signing() {
+ let quote = web3_quote("web3-changed-quote");
+ let permit = ApprovalPermit::new(ApprovalKind::Web3, &quote.quote_id, None, Some(quote.clone()));
+ let request = AuthorizeWeb3ExecutionRequest {
+ quote_id: quote.quote_id.clone(),
+ operation: "dapp_call".into(),
+ transaction: Web3ExecutionIntent::Evm {
+ network: "polygon_mainnet".into(),
+ to: "0xattacker".into(),
+ data: Some("0xabcd".into()),
+ value: "5".into(),
+ nonce: 4,
+ gas_limit: 30_000,
+ gas_price_wei: "7".into(),
+ chain_id: 137,
+ },
+ };
+ assert!(!web3_approval_matches_request(&quote, &request));
+ drop(permit);
+ assert!(!consume_approval(ApprovalKind::Web3, &quote.quote_id));
+}
+
+#[test]
+fn module_selected_rpc_endpoints_are_public_http_urls_without_credentials() {
+ assert_eq!(
+ validate_module_endpoint_url("https://rpc.example.test/v1"),
+ Ok("https://rpc.example.test/v1".to_owned())
+ );
+ assert_eq!(
+ validate_module_endpoint_url("http://127.0.0.1:8545"),
+ Ok("http://127.0.0.1:8545".to_owned())
+ );
+ for unsafe_url in [
+ "file:///tmp/rpc",
+ "ftp://rpc.example.test",
+ "https://user:[email protected]",
+ "https:///missing-host",
+ ] {
+ assert!(
+ validate_module_endpoint_url(unsafe_url).is_err(),
+ "accepted unsafe endpoint {unsafe_url}"
+ );
+ }
+}
+
fn native_quote(quote_id: &str) -> PreparedTransaction {
PreparedTransaction {
quote_id: quote_id.into(),
@@ -81,6 +179,22 @@ fn native_quote(quote_id: &str) -> PreparedTransaction {
}
}
+fn web3_quote(quote_id: &str) -> Web3QuoteResponse {
+ Web3QuoteResponse {
+ quote_id: quote_id.into(),
+ kind: Web3QuoteKind::DappCall,
+ expires_at_ms: u64::MAX,
+ signing_chain: WalletChain::Evm,
+ quote: serde_json::json!({
+ "type": "dapp_call",
+ "network": "polygon_mainnet",
+ "contractAddress": "0x1111111111111111111111111111111111111111",
+ "calldata": "0xabcd",
+ "valueRaw": "5"
+ }),
+ }
+}
+
fn native_request(
quote: PreparedTransaction,
recipient: &str,
diff --git a/crates/openhuman-core/src/modules/wallet_service.rs b/crates/openhuman-core/src/modules/wallet_service.rs
index 8794ffbc82..324955c728 100644
--- a/crates/openhuman-core/src/modules/wallet_service.rs
+++ b/crates/openhuman-core/src/modules/wallet_service.rs
@@ -90,7 +90,10 @@ async fn ensure_native_wallet(
configuration.clone(),
)
.await?;
- if let Err(error) = super::wallet_host::bind_endpoint_references(&response) {
+ if let Err(error) = super::wallet_host::bind_endpoint_references(
+ &response.service.handle,
+ &response.endpoint_references,
+ ) {
let _ = wallet::call::<_, ()>(
config,
methods::NATIVE_WALLET_CLOSE,
@@ -207,6 +210,7 @@ pub(crate) async fn execute_native_transfer(
super::wallet_host::ApprovalKind::Native,
&params.quote_id,
Some(quote),
+ None,
wallet::call_confidential(config, methods::NATIVE_WALLET_EXECUTE_PREPARED, &request),
)
.await;
@@ -272,7 +276,7 @@ async fn close_native_wallet(
},
)
.await?;
- super::wallet_host::clear_endpoint_references();
+ super::wallet_host::clear_endpoint_references(&service.response.service.handle);
Ok(())
}
@@ -304,14 +308,19 @@ where
F: FnOnce(NativeWalletCloseRequest) -> Fut,
Fut: Future<Output = Result<(), WalletCallError>>,
{
- if let Some(service) = active.as_ref() {
+ let handle = if let Some(service) = active.as_ref() {
close(NativeWalletCloseRequest {
service: service.response.service.clone(),
})
.await?;
- }
+ Some(service.response.service.handle.clone())
+ } else {
+ None
+ };
*active = None;
- super::wallet_host::clear_endpoint_references();
+ if let Some(handle) = handle {
+ super::wallet_host::clear_endpoint_references(&handle);
+ }
Ok(())
}
@@ -335,7 +344,7 @@ fn finish_shutdown_hook_registration(registered: &AtomicBool) {
registered.store(false, Ordering::Release);
}
-fn native_wallet_config_request() -> NativeWalletConfigRequest {
+pub(super) fn native_wallet_config_request() -> NativeWalletConfigRequest {
let mut overridden_endpoints = Vec::new();
for network in EvmNetwork::ALL {
let name = crate::web3::wallet::endpoints::evm_rpc_env_var(network);
diff --git a/crates/openhuman-core/src/modules/wallet_service_tests.rs b/crates/openhuman-core/src/modules/wallet_service_tests.rs
index a02f790e36..0ed1a166eb 100644
--- a/crates/openhuman-core/src/modules/wallet_service_tests.rs
+++ b/crates/openhuman-core/src/modules/wallet_service_tests.rs
@@ -74,14 +74,17 @@ async fn explicit_close_retains_state_for_retry_then_releases_user_state_once()
);
let configured = tinywallet_bus::wire::NativeWalletConfigResponse {
service: NativeWalletServiceHandle {
- handle: "old-user-service".into(),
+ handle: "opaque-service-handle".into(),
},
endpoint_references: vec![tinywallet_bus::wire::HostEndpointReference {
key: tinywallet_bus::wire::RpcEndpointKey::Btc,
reference: "old-user-endpoint".into(),
}],
};
- super::super::wallet_host::bind_endpoint_references(&configured)
+ super::super::wallet_host::bind_endpoint_references(
+ &configured.service.handle,
+ &configured.endpoint_references,
+ )
.expect("fixture endpoint alias should bind");
let close_calls = Arc::new(AtomicUsize::new(0));
let observed_calls = close_calls.clone();
diff --git a/crates/openhuman-core/src/modules/web3_service.rs b/crates/openhuman-core/src/modules/web3_service.rs
new file mode 100644
index 0000000000..bd66923969
--- /dev/null
+++ b/crates/openhuman-core/src/modules/web3_service.rs
@@ -0,0 +1,219 @@
+//! User-scoped lifecycle and host transport for TinyWallet Web3 quotes.
+
+use std::collections::HashMap;
+use std::path::PathBuf;
+use std::sync::OnceLock;
+
+use serde::Deserialize;
+use tinywallet_bus::names::methods;
+use tinywallet_bus::wire::{
+ QuoteOwner, WalletChain, Web3CloseRequest, Web3ConfigureRequest, Web3ConfigureResponse,
+ Web3ExecuteRequest, Web3QuoteRequest, Web3QuoteResponse,
+};
+
+use crate::config::Config;
+
+use super::{wallet, wallet_host};
+
+struct Web3Service {
+ workspace: PathBuf,
+ accounts: tinywallet_bus::wire::WalletAccountsResponse,
+ configuration: Web3ConfigureRequest,
+ response: Web3ConfigureResponse,
+ quotes: HashMap<String, Web3QuoteResponse>,
+}
+
+static WEB3_SERVICE: OnceLock<tokio::sync::Mutex<Option<Web3Service>>> = OnceLock::new();
+
+fn service() -> &'static tokio::sync::Mutex<Option<Web3Service>> {
+ WEB3_SERVICE.get_or_init(|| tokio::sync::Mutex::new(None))
+}
+
+async fn ensure_service(
+ config: &Config,
+ active: &mut Option<Web3Service>,
+) -> Result<(), wallet::WalletCallError> {
+ let accounts = wallet_host::wallet_accounts_snapshot()
+ .await
+ .map_err(wallet::WalletCallError::Failed)?;
+ let workspace = config.workspace_dir.clone();
+ let native_configuration = super::wallet_service::native_wallet_config_request();
+ let configuration = Web3ConfigureRequest {
+ solana_cluster: native_configuration.solana_cluster,
+ overridden_endpoints: native_configuration.overridden_endpoints,
+ };
+ if active
+ .as_ref()
+ .is_some_and(|current| {
+ current.workspace != workspace
+ || current.accounts != accounts
+ || current.configuration != configuration
+ })
+ {
+ if let Some(current) = active.as_ref() {
+ wallet::call::<_, ()>(
+ config,
+ methods::WEB3_CLOSE,
+ Web3CloseRequest {
+ service: current.response.service.clone(),
+ },
+ )
+ .await?;
+ wallet_host::clear_endpoint_references(&current.response.service.handle);
+ }
+ *active = None;
+ }
+ if active.is_none() {
+ let response: Web3ConfigureResponse = wallet::call(
+ config,
+ methods::WEB3_CONFIGURE_WITH_ENDPOINTS,
+ configuration.clone(),
+ )
+ .await?;
+ if let Err(error) = wallet_host::bind_endpoint_references(
+ &response.service.handle,
+ &response.endpoint_references,
+ ) {
+ let _ = wallet::call::<_, ()>(
+ config,
+ methods::WEB3_CLOSE,
+ Web3CloseRequest {
+ service: response.service.clone(),
+ },
+ )
+ .await;
+ return Err(wallet::WalletCallError::Failed(error));
+ }
+ *active = Some(Web3Service {
+ workspace,
+ accounts,
+ configuration,
+ response,
+ quotes: HashMap::new(),
+ });
+ }
+ Ok(())
+}
+
+fn owner() -> Option<QuoteOwner> {
+ crate::security::approval::APPROVAL_CHAT_CONTEXT
+ .try_with(|context| QuoteOwner {
+ thread_id: context.thread_id.clone(),
+ client_id: context.client_id.clone(),
+ })
+ .ok()
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct ExecuteParams {
+ pub(crate) quote_id: String,
+ pub(crate) confirmed: bool,
+}
+
+/// Prepare one implementation-owned Web3 quote.
+pub(crate) async fn quote(
+ config: &Config,
+ member: &'static str,
+ params: serde_json::Value,
+) -> Result<Web3QuoteResponse, wallet::WalletCallError> {
+ let mut active = service().lock().await;
+ ensure_service(config, &mut active).await?;
+ let service_handle = active
+ .as_ref()
+ .expect("ensure_service installs a handle")
+ .response
+ .service
+ .clone();
+ let response: Web3QuoteResponse = wallet::call(
+ config,
+ member,
+ Web3QuoteRequest {
+ service: service_handle,
+ owner: owner(),
+ params,
+ },
+ )
+ .await?;
+ if let Some(current) = active.as_mut() {
+ current
+ .quotes
+ .insert(response.quote_id.clone(), response.clone());
+ }
+ Ok(response)
+}
+
+/// Call the module-owned authenticated-backend route operation.
+pub(crate) async fn routes(config: &Config) -> Result<serde_json::Value, wallet::WalletCallError> {
+ let mut active = service().lock().await;
+ ensure_service(config, &mut active).await?;
+ wallet::call(config, methods::WEB3_ROUTES, ()).await
+}
+
+/// Execute one explicitly confirmed quote using its module-declared signer chain.
+pub(crate) async fn execute(
+ config: &Config,
+ quote_id: String,
+ confirmed: bool,
+) -> Result<serde_json::Value, wallet::WalletCallError> {
+ if !confirmed {
+ return Err(wallet::WalletCallError::InvalidInput(
+ "Web3 execution requires confirmed: true".into(),
+ ));
+ }
+ let mut active = service().lock().await;
+ ensure_service(config, &mut active).await?;
+ let service_handle = active
+ .as_ref()
+ .expect("ensure_service installs a handle")
+ .response
+ .service
+ .clone();
+ let quote = active
+ .as_ref()
+ .and_then(|active| active.quotes.get(&quote_id))
+ .cloned()
+ .ok_or_else(|| {
+ wallet::WalletCallError::InvalidInput("prepared Web3 quote is unavailable".into())
+ })?;
+ let chain = match quote.signing_chain {
+ WalletChain::Evm => crate::web3::wallet::WalletChain::Evm,
+ WalletChain::Btc => crate::web3::wallet::WalletChain::Btc,
+ WalletChain::Solana => crate::web3::wallet::WalletChain::Solana,
+ WalletChain::Tron => crate::web3::wallet::WalletChain::Tron,
+ };
+ let stored = crate::web3::wallet::secret_material(chain)
+ .await
+ .map_err(|error| wallet::WalletCallError::Failed(error.to_string()))?;
+ let mnemonic =
+ crate::security::encryption::rpc::decrypt_secret(config, &stored.encrypted_mnemonic)
+ .await
+ .map_err(|error| wallet::WalletCallError::Failed(error.to_string()))?
+ .value;
+ let mut request = Web3ExecuteRequest {
+ service: service_handle,
+ owner: owner(),
+ quote_id: quote_id.clone(),
+ confirmed,
+ secret: tinywallet_bus::wire::SecretMaterial {
+ mnemonic,
+ derivation_path: stored.derivation_path,
+ chain: quote.signing_chain.to_chain(),
+ },
+ };
+ let result = wallet_host::with_confirmed_execution(
+ wallet_host::ApprovalKind::Web3,
+ &quote_id,
+ None,
+ Some(quote),
+ wallet::call_confidential(config, methods::WEB3_EXECUTE, &request),
+ )
+ .await;
+ zeroize::Zeroize::zeroize(&mut request.secret.mnemonic);
+ if result.is_ok() {
+ active
+ .as_mut()
+ .map(|active| active.quotes.remove(&quote_id));
+ }
+ result
+}
diff --git a/crates/openhuman-core/src/web3/bridge/schemas.rs b/crates/openhuman-core/src/web3/bridge/schemas.rs
index bfdc180b2f..a6ee060c2b 100644
--- a/crates/openhuman-core/src/web3/bridge/schemas.rs
+++ b/crates/openhuman-core/src/web3/bridge/schemas.rs
@@ -6,9 +6,10 @@ use serde_json::{Map, Value};
use crate::core::all::{ControllerFuture, RegisteredController};
use crate::core::{ControllerSchema, FieldSchema, Outcome, TypeSchema};
-use super::super::seams::service;
-use super::super::types::{BridgeQuoteParams, ExecuteQuoteParams};
use super::super::{execute_inputs, json_result, opt_str, req_json};
+use crate::config::rpc as config_rpc;
+use crate::modules::web3_service;
+use tinywallet_bus::names::methods;
pub fn schemas() -> Vec<ControllerSchema> {
vec![schema("quote"), schema("execute")]
@@ -32,28 +33,48 @@ pub fn schema(function: &str) -> ControllerSchema {
"quote" => ControllerSchema {
namespace: "web3_bridge",
function: "quote",
- description:
- "Prepare a cross-chain bridge via deBridge DLN. Returns a quote plus a prepared quoteId to confirm+execute; the unsigned transaction is signed+broadcast on the source chain.",
+ description: "Prepare a cross-chain bridge via deBridge DLN. Returns a quote plus a prepared quoteId to confirm+execute; the unsigned transaction is signed+broadcast on the source chain.",
inputs: vec![
req_json("srcChainId", "Source deBridge chain id."),
req_json("srcChainTokenIn", "Source token address."),
- req_json("srcChainTokenInAmount", "Source amount in the token's smallest unit."),
- req_json("dstChainId", "Destination deBridge chain id (must differ from source)."),
+ req_json(
+ "srcChainTokenInAmount",
+ "Source amount in the token's smallest unit.",
+ ),
+ req_json(
+ "dstChainId",
+ "Destination deBridge chain id (must differ from source).",
+ ),
req_json("dstChainTokenOut", "Destination token address."),
- opt_str("dstChainTokenOutAmount", "Destination amount, or 'auto' for market rate (default 'auto')."),
- opt_str("dstChainTokenOutRecipient", "Recipient on the destination chain. Defaults to the wallet's own address."),
- opt_str("srcChainOrderAuthorityAddress", "Source-chain order authority. Defaults to the wallet's source address."),
- opt_str("dstChainOrderAuthorityAddress", "Destination-chain order authority. Defaults to the wallet's destination address."),
+ opt_str(
+ "dstChainTokenOutAmount",
+ "Destination amount, or 'auto' for market rate (default 'auto').",
+ ),
+ opt_str(
+ "dstChainTokenOutRecipient",
+ "Recipient on the destination chain. Defaults to the wallet's own address.",
+ ),
+ opt_str(
+ "srcChainOrderAuthorityAddress",
+ "Source-chain order authority. Defaults to the wallet's source address.",
+ ),
+ opt_str(
+ "dstChainOrderAuthorityAddress",
+ "Destination-chain order authority. Defaults to the wallet's destination address.",
+ ),
],
- outputs: vec![json_result("Prepared web3 quote {quoteId, kind, expiresAtMs, quote}.")],
+ outputs: vec![json_result(
+ "Prepared web3 quote {quoteId, kind, expiresAtMs, quote}.",
+ )],
},
"execute" => ControllerSchema {
namespace: "web3_bridge",
function: "execute",
- description:
- "Confirm and execute a prepared web3_bridge quote: signs the source-chain transaction in-core and broadcasts it.",
+ description: "Confirm and execute a prepared web3_bridge quote: signs the source-chain transaction in-core and broadcasts it.",
inputs: execute_inputs(),
- outputs: vec![json_result("ExecutionResult {quoteId, kind, transactionHash, explorerUrl?, feeRaw}.")],
+ outputs: vec![json_result(
+ "ExecutionResult {quoteId, kind, transactionHash, explorerUrl?, feeRaw}.",
+ )],
},
_ => ControllerSchema {
namespace: "web3_bridge",
@@ -72,18 +93,22 @@ pub fn schema(function: &str) -> ControllerSchema {
fn handle_quote(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- let parsed: BridgeQuoteParams = serde_json::from_value(Value::Object(params))
- .map_err(|e| format!("invalid params: {e}"))?;
- let quote = service().quote_bridge(parsed).await?;
+ let config = config_rpc::load_config_with_timeout().await?;
+ let quote = web3_service::quote(&config, methods::WEB3_BRIDGE_QUOTE, Value::Object(params))
+ .await
+ .map_err(|error| error.to_string())?;
Outcome::new(quote, vec!["web3 bridge prepared".to_string()]).into_cli_compatible_json()
})
}
fn handle_execute(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- let parsed: ExecuteQuoteParams = serde_json::from_value(Value::Object(params))
+ let parsed: web3_service::ExecuteParams = serde_json::from_value(Value::Object(params))
.map_err(|e| format!("invalid params: {e}"))?;
- let result = service().execute_quote(parsed).await?;
+ let config = config_rpc::load_config_with_timeout().await?;
+ let result = web3_service::execute(&config, parsed.quote_id, parsed.confirmed)
+ .await
+ .map_err(|error| error.to_string())?;
Outcome::new(result, vec!["web3 transaction broadcast".to_string()])
.into_cli_compatible_json()
})
diff --git a/crates/openhuman-core/src/web3/dapp/schemas.rs b/crates/openhuman-core/src/web3/dapp/schemas.rs
index 011a0639d5..dffb156e59 100644
--- a/crates/openhuman-core/src/web3/dapp/schemas.rs
+++ b/crates/openhuman-core/src/web3/dapp/schemas.rs
@@ -6,9 +6,10 @@ use serde_json::{Map, Value};
use crate::core::all::{ControllerFuture, RegisteredController};
use crate::core::{ControllerSchema, FieldSchema, Outcome, TypeSchema};
-use super::super::seams::service;
-use super::super::types::{DappCallParams, ExecuteQuoteParams};
use super::super::{execute_inputs, json_result, opt_str, req_json};
+use crate::config::rpc as config_rpc;
+use crate::modules::web3_service;
+use tinywallet_bus::names::methods;
pub fn schemas() -> Vec<ControllerSchema> {
vec![schema("call"), schema("execute")]
@@ -32,23 +33,31 @@ pub fn schema(function: &str) -> ControllerSchema {
"call" => ControllerSchema {
namespace: "web3_dapp",
function: "call",
- description:
- "Prepare a generic EVM dapp contract call from pre-encoded calldata. Returns a prepared quoteId to confirm+execute.",
+ description: "Prepare a generic EVM dapp contract call from pre-encoded calldata. Returns a prepared quoteId to confirm+execute.",
inputs: vec![
req_json("contractAddress", "Target contract address."),
req_json("calldata", "0x-prefixed hex calldata."),
- opt_str("valueRaw", "Native value attached, smallest unit. Defaults to '0'."),
- opt_str("evmNetwork", "EVM network selector. Defaults to ethereum_mainnet."),
+ opt_str(
+ "valueRaw",
+ "Native value attached, smallest unit. Defaults to '0'.",
+ ),
+ opt_str(
+ "evmNetwork",
+ "EVM network selector. Defaults to ethereum_mainnet.",
+ ),
],
- outputs: vec![json_result("Prepared web3 quote {quoteId, kind, expiresAtMs, quote}.")],
+ outputs: vec![json_result(
+ "Prepared web3 quote {quoteId, kind, expiresAtMs, quote}.",
+ )],
},
"execute" => ControllerSchema {
namespace: "web3_dapp",
function: "execute",
- description:
- "Confirm and execute a prepared web3_dapp call: signs the contract call in-core and broadcasts it.",
+ description: "Confirm and execute a prepared web3_dapp call: signs the contract call in-core and broadcasts it.",
inputs: execute_inputs(),
- outputs: vec![json_result("ExecutionResult {quoteId, kind, transactionHash, explorerUrl?, feeRaw}.")],
+ outputs: vec![json_result(
+ "ExecutionResult {quoteId, kind, transactionHash, explorerUrl?, feeRaw}.",
+ )],
},
_ => ControllerSchema {
namespace: "web3_dapp",
@@ -67,18 +76,22 @@ pub fn schema(function: &str) -> ControllerSchema {
fn handle_call(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- let parsed: DappCallParams = serde_json::from_value(Value::Object(params))
- .map_err(|e| format!("invalid params: {e}"))?;
- let quote = service().prepare_dapp_call(parsed).await?;
+ let config = config_rpc::load_config_with_timeout().await?;
+ let quote = web3_service::quote(&config, methods::WEB3_DAPP_QUOTE, Value::Object(params))
+ .await
+ .map_err(|error| error.to_string())?;
Outcome::new(quote, vec!["web3 dapp call prepared".to_string()]).into_cli_compatible_json()
})
}
fn handle_execute(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- let parsed: ExecuteQuoteParams = serde_json::from_value(Value::Object(params))
+ let parsed: web3_service::ExecuteParams = serde_json::from_value(Value::Object(params))
.map_err(|e| format!("invalid params: {e}"))?;
- let result = service().execute_quote(parsed).await?;
+ let config = config_rpc::load_config_with_timeout().await?;
+ let result = web3_service::execute(&config, parsed.quote_id, parsed.confirmed)
+ .await
+ .map_err(|error| error.to_string())?;
Outcome::new(result, vec!["web3 transaction broadcast".to_string()])
.into_cli_compatible_json()
})
diff --git a/crates/openhuman-core/src/web3/mod.rs b/crates/openhuman-core/src/web3/mod.rs
index 8940b8dd51..3f0a4c1bb5 100644
--- a/crates/openhuman-core/src/web3/mod.rs
+++ b/crates/openhuman-core/src/web3/mod.rs
@@ -30,6 +30,8 @@ pub mod client;
#[cfg(feature = "web3")]
pub mod dapp;
#[cfg(feature = "web3")]
+mod module_tools;
+#[cfg(feature = "web3")]
pub mod seams;
#[cfg(feature = "web3")]
pub mod swap;
@@ -129,19 +131,13 @@ pub fn all_web3_registered_controllers() -> Vec<RegisteredController> {
/// gracefully (rather than being hidden) when the user is not signed in.
#[cfg(feature = "web3")]
pub fn all_web3_agent_tools() -> Vec<Box<dyn Tool>> {
- use tinywallet_web3::tools::web3::{
- Web3BridgeExecuteTool, Web3BridgeQuoteTool, Web3DappCallTool, Web3DappExecuteTool,
- Web3SwapExecuteTool, Web3SwapQuoteTool, Web3SwapRoutesTool,
- };
-
- let service = seams::service();
- vec![
- Box::new(Web3SwapQuoteTool::new(service.clone())),
- Box::new(Web3SwapExecuteTool::new(service.clone())),
- Box::new(Web3SwapRoutesTool::new(service.clone())),
- Box::new(Web3BridgeQuoteTool::new(service.clone())),
- Box::new(Web3BridgeExecuteTool::new(service.clone())),
- Box::new(Web3DappCallTool::new(service.clone())),
- Box::new(Web3DappExecuteTool::new(service)),
- ]
+ tinywallet_bus::tools::web3_tool_declarations()
+ .iter()
+ .map(|declaration| {
+ Box::new(module_tools::Web3ModuleTool::new(
+ tinywallet_bus::tools::find_web3_tool_declaration(declaration.name)
+ .expect("the declaration came from the shipped Web3 list"),
+ )) as Box<dyn Tool>
+ })
+ .collect()
}
diff --git a/crates/openhuman-core/src/web3/module_tools.rs b/crates/openhuman-core/src/web3/module_tools.rs
new file mode 100644
index 0000000000..5a4efa1d43
--- /dev/null
+++ b/crates/openhuman-core/src/web3/module_tools.rs
@@ -0,0 +1,108 @@
+//! Agent tool adapters that route Web3 operations through the TinyWallet bus.
+
+use async_trait::async_trait;
+use serde_json::Value;
+use tinytools::{Tool, ToolCallOptions, ToolExposure, ToolResult};
+use tinywallet_bus::tools::ToolDeclaration;
+
+#[derive(Debug)]
+pub(super) struct Web3ModuleTool {
+ declaration: &'static ToolDeclaration,
+}
+
+impl Web3ModuleTool {
+ pub(super) const fn new(declaration: &'static ToolDeclaration) -> Self {
+ Self { declaration }
+ }
+}
+
+#[async_trait]
+impl Tool for Web3ModuleTool {
+ fn exposure(&self) -> ToolExposure {
+ ToolExposure::Deferred
+ }
+
+ fn name(&self) -> &'static str {
+ self.declaration.name
+ }
+
+ fn description(&self) -> &'static str {
+ self.declaration.description
+ }
+
+ fn parameters_schema(&self) -> Value {
+ self.declaration.parameters.clone()
+ }
+
+ async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ let config = match crate::config::rpc::load_config_with_timeout().await {
+ Ok(config) => config,
+ Err(error) => return Ok(ToolResult::error(error)),
+ };
+ let result: anyhow::Result<Value> = match self.name() {
+ "web3_swap_quote" => {
+ crate::modules::web3_service::quote(
+ &config,
+ tinywallet_bus::names::methods::WEB3_SWAP_QUOTE,
+ args,
+ )
+ .await
+ .map_err(|error| anyhow::anyhow!(error.to_string()))
+ .and_then(|value| serde_json::to_value(value).map_err(Into::into))
+ }
+ "web3_bridge_quote" => {
+ crate::modules::web3_service::quote(
+ &config,
+ tinywallet_bus::names::methods::WEB3_BRIDGE_QUOTE,
+ args,
+ )
+ .await
+ .map_err(|error| anyhow::anyhow!(error.to_string()))
+ .and_then(|value| serde_json::to_value(value).map_err(Into::into))
+ }
+ "web3_dapp_call" => {
+ crate::modules::web3_service::quote(
+ &config,
+ tinywallet_bus::names::methods::WEB3_DAPP_QUOTE,
+ args,
+ )
+ .await
+ .map_err(|error| anyhow::anyhow!(error.to_string()))
+ .and_then(|value| serde_json::to_value(value).map_err(Into::into))
+ }
+ "web3_swap_routes" => crate::modules::web3_service::routes(&config)
+ .await
+ .map_err(|error| anyhow::anyhow!(error.to_string())),
+ "web3_swap_execute" | "web3_bridge_execute" | "web3_dapp_execute" => {
+ match serde_json::from_value::<crate::modules::web3_service::ExecuteParams>(args) {
+ Ok(params) => {
+ crate::modules::web3_service::execute(
+ &config,
+ params.quote_id,
+ params.confirmed,
+ )
+ .await
+ .map_err(|error| anyhow::anyhow!(error.to_string()))
+ .and_then(|value| serde_json::to_value(value).map_err(Into::into))
+ }
+ Err(error) => {
+ return Ok(ToolResult::error(format!("invalid arguments: {error}")));
+ }
+ }
+ }
+ _ => return Ok(ToolResult::error("unknown Web3 tool")),
+ };
+ match result {
+ Ok(value) => Ok(ToolResult::success(serde_json::to_string_pretty(&value)?)),
+ Err(error) => Ok(ToolResult::error(error.to_string())),
+ }
+ }
+
+ async fn execute_with_options(
+ &self,
+ args: Value,
+ _options: ToolCallOptions,
+ ) -> anyhow::Result<ToolResult> {
+ self.execute(args).await
+ }
+}
diff --git a/crates/openhuman-core/src/web3/swap/schemas.rs b/crates/openhuman-core/src/web3/swap/schemas.rs
index f9f47281e3..49884540db 100644
--- a/crates/openhuman-core/src/web3/swap/schemas.rs
+++ b/crates/openhuman-core/src/web3/swap/schemas.rs
@@ -7,9 +7,10 @@ use serde_json::{Map, Value};
use crate::core::all::{ControllerFuture, RegisteredController};
use crate::core::{ControllerSchema, FieldSchema, Outcome, TypeSchema};
-use super::super::seams::service;
-use super::super::types::{ExecuteQuoteParams, SwapQuoteParams};
use super::super::{execute_inputs, json_result, opt_str, req_json};
+use crate::config::rpc as config_rpc;
+use crate::modules::web3_service;
+use tinywallet_bus::names::methods;
pub fn schemas() -> Vec<ControllerSchema> {
vec![schema("quote"), schema("execute"), schema("routes")]
@@ -37,26 +38,43 @@ pub fn schema(function: &str) -> ControllerSchema {
"quote" => ControllerSchema {
namespace: "web3_swap",
function: "quote",
- description:
- "Prepare a single-chain token swap via deBridge. Returns a quote plus a prepared quoteId to confirm+execute. For cross-chain swaps use web3_bridge.",
+ description: "Prepare a single-chain token swap via deBridge. Returns a quote plus a prepared quoteId to confirm+execute. For cross-chain swaps use web3_bridge.",
inputs: vec![
- req_json("chainId", "deBridge chain id the swap executes on (e.g. 1 ETH, 56 BNB, 7565164 Solana)."),
- req_json("tokenIn", "Input token address (use the zero address for native)."),
- req_json("tokenInAmount", "Input amount in the token's smallest unit."),
+ req_json(
+ "chainId",
+ "deBridge chain id the swap executes on (e.g. 1 ETH, 56 BNB, 7565164 Solana).",
+ ),
+ req_json(
+ "tokenIn",
+ "Input token address (use the zero address for native).",
+ ),
+ req_json(
+ "tokenInAmount",
+ "Input amount in the token's smallest unit.",
+ ),
req_json("tokenOut", "Output token address."),
- opt_str("tokenOutRecipient", "Address receiving output. Defaults to the wallet's own address on this chain."),
- opt_str("senderAddress", "Sender. Defaults to the wallet's own address on this chain."),
+ opt_str(
+ "tokenOutRecipient",
+ "Address receiving output. Defaults to the wallet's own address on this chain.",
+ ),
+ opt_str(
+ "senderAddress",
+ "Sender. Defaults to the wallet's own address on this chain.",
+ ),
opt_str("slippage", "Slippage percent or 'auto' (default 'auto')."),
],
- outputs: vec![json_result("Prepared web3 quote {quoteId, kind, expiresAtMs, quote}.")],
+ outputs: vec![json_result(
+ "Prepared web3 quote {quoteId, kind, expiresAtMs, quote}.",
+ )],
},
"execute" => ControllerSchema {
namespace: "web3_swap",
function: "execute",
- description:
- "Confirm and execute a prepared web3_swap quote: signs the unsigned transaction in-core and broadcasts it.",
+ description: "Confirm and execute a prepared web3_swap quote: signs the unsigned transaction in-core and broadcasts it.",
inputs: execute_inputs(),
- outputs: vec![json_result("ExecutionResult {quoteId, kind, transactionHash, explorerUrl?, feeRaw}.")],
+ outputs: vec![json_result(
+ "ExecutionResult {quoteId, kind, transactionHash, explorerUrl?, feeRaw}.",
+ )],
},
"routes" => ControllerSchema {
namespace: "web3_swap",
@@ -86,18 +104,22 @@ fn unknown_schema() -> ControllerSchema {
fn handle_quote(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- let parsed: SwapQuoteParams = serde_json::from_value(Value::Object(params))
- .map_err(|e| format!("invalid params: {e}"))?;
- let quote = service().quote_swap(parsed).await?;
+ let config = config_rpc::load_config_with_timeout().await?;
+ let quote = web3_service::quote(&config, methods::WEB3_SWAP_QUOTE, Value::Object(params))
+ .await
+ .map_err(|error| error.to_string())?;
Outcome::new(quote, vec!["web3 swap prepared".to_string()]).into_cli_compatible_json()
})
}
fn handle_execute(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- let parsed: ExecuteQuoteParams = serde_json::from_value(Value::Object(params))
+ let parsed: web3_service::ExecuteParams = serde_json::from_value(Value::Object(params))
.map_err(|e| format!("invalid params: {e}"))?;
- let result = service().execute_quote(parsed).await?;
+ let config = config_rpc::load_config_with_timeout().await?;
+ let result = web3_service::execute(&config, parsed.quote_id, parsed.confirmed)
+ .await
+ .map_err(|error| error.to_string())?;
Outcome::new(result, vec!["web3 transaction broadcast".to_string()])
.into_cli_compatible_json()
})
@@ -105,7 +127,10 @@ fn handle_execute(params: Map<String, Value>) -> ControllerFuture {
fn handle_routes(_params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- let routes = service().routes().await?;
+ let config = config_rpc::load_config_with_timeout().await?;
+ let routes = web3_service::routes(&config)
+ .await
+ .map_err(|error| error.to_string())?;
Outcome::new(routes, vec!["web3 supported routes listed".to_string()])
.into_cli_compatible_json()
})
diff --git a/vendor/tinywallet b/vendor/tinywallet
index 53dbb5462b..ff3dfb09f2 160000
--- a/vendor/tinywallet
+++ b/vendor/tinywallet
@@ -1 +1 @@
-Subproject commit 53dbb5462b1d8be02287ab5d9193fed2eabc2670
+Subproject commit ff3dfb09f253473f3157d6fbb9ae16879bf33f46