From 8b62ca10f83c82bad98e8c1a3003cdc1f0be5c1a Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Wed, 4 Sep 2024 12:24:25 +0200 Subject: [PATCH 1/3] rusk: HTTP - add `/static/drivers/wallet-core.wasm` endpoint Resolves #2256 --- rusk/src/lib/http.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rusk/src/lib/http.rs b/rusk/src/lib/http.rs index f2e4ee60eb..474f09a52a 100644 --- a/rusk/src/lib/http.rs +++ b/rusk/src/lib/http.rs @@ -753,6 +753,13 @@ where .await; } + if path == "/static/drivers/wallet-core.wasm" { + let wallet_wasm = include_bytes!( + "../../../target/wasm32-unknown-unknown/release/wallet_core.wasm" + ); + return Ok(Response::new(Full::from(wallet_wasm.to_vec()).into())); + } + if hyper_tungstenite::is_upgrade_request(&req) { let target = req.uri().path().try_into()?; From d36ed7cfecca762b29b2bc35f9faff0ba9901454 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Wed, 4 Sep 2024 12:59:26 +0200 Subject: [PATCH 2/3] rusk: fix circular dependency - Serving wasm with rusk requires `make wasm` - `make wasm` requires `make keys` - `make keys` requires `rusk` to be built --- rusk/Cargo.toml | 3 ++- rusk/src/lib/http.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rusk/Cargo.toml b/rusk/Cargo.toml index 4918e1d2ef..7aff30111b 100644 --- a/rusk/Cargo.toml +++ b/rusk/Cargo.toml @@ -93,13 +93,14 @@ criterion = "0.5" rustc_tools_util = "0.3" [features] -default = ["ephemeral", "recovery-state", "recovery-keys", "prover", "node"] +default = ["ephemeral", "recovery-state", "recovery-keys", "prover", "node", "http-wasm"] ephemeral = ["dep:rusk-recovery", "dep:tempfile", "recovery-state", "node"] recovery-state = ["rusk-recovery/state", "dep:tempfile"] recovery-keys = ["rusk-recovery/keys"] prover = ["dep:rusk-prover"] testwallet = ["dep:futures"] node = ["dep:node", "dep:dusk-consensus", "dep:node-data"] +http-wasm = [] [[bench]] name = "block_ingestion" diff --git a/rusk/src/lib/http.rs b/rusk/src/lib/http.rs index 474f09a52a..4e789cd8b1 100644 --- a/rusk/src/lib/http.rs +++ b/rusk/src/lib/http.rs @@ -753,6 +753,7 @@ where .await; } + #[cfg(feature = "http-wasm")] if path == "/static/drivers/wallet-core.wasm" { let wallet_wasm = include_bytes!( "../../../target/wasm32-unknown-unknown/release/wallet_core.wasm" From 4e400a0a3b8fb971f668a851206f071ef4e87c83 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Wed, 4 Sep 2024 14:29:43 +0200 Subject: [PATCH 3/3] rusk: add content-type wasm --- rusk/src/lib/http.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rusk/src/lib/http.rs b/rusk/src/lib/http.rs index 4e789cd8b1..64eb6e4122 100644 --- a/rusk/src/lib/http.rs +++ b/rusk/src/lib/http.rs @@ -758,7 +758,13 @@ where let wallet_wasm = include_bytes!( "../../../target/wasm32-unknown-unknown/release/wallet_core.wasm" ); - return Ok(Response::new(Full::from(wallet_wasm.to_vec()).into())); + let mut response = + Response::new(Full::from(wallet_wasm.to_vec()).into()); + response.headers_mut().append( + "Content-Type", + HeaderValue::from_static("application/wasm"), + ); + return Ok(response); } if hyper_tungstenite::is_upgrade_request(&req) {