From 4c7499b02b619f6bdbdbcba703f8bfbaaaddde84 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Thu, 17 Aug 2023 21:54:16 +0300 Subject: [PATCH] fix ngaccount, reintroduce reqwest for wasm32 only --- Cargo.lock | 83 ++++++++++++++++++++++++++ ng-app/src/routes/WalletCreate.svelte | 2 +- ng-sdk-js/src/lib.rs | 7 ++- ngaccount/web/src/routes/Create.svelte | 2 +- p2p-net/Cargo.toml | 5 +- p2p-net/src/utils.rs | 15 ++--- 6 files changed, 101 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cddead2..14a5c5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2206,6 +2206,19 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" version = "0.1.57" @@ -2742,6 +2755,24 @@ dependencies = [ "getrandom 0.2.10", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "ndk" version = "0.6.0" @@ -3168,6 +3199,12 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + [[package]] name = "openssl-src" version = "111.26.0+1.1.1u" @@ -3275,6 +3312,7 @@ dependencies = [ "num_enum", "once_cell", "p2p-repo", + "reqwest", "serde", "serde_bare", "serde_bytes", @@ -3961,10 +3999,12 @@ dependencies = [ "http", "http-body", "hyper", + "hyper-tls", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -3972,6 +4012,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "tokio", + "tokio-native-tls", "tokio-util", "tower-service", "url", @@ -4138,6 +4179,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +dependencies = [ + "windows-sys", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -4150,6 +4200,29 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "selectors" version = "0.22.0" @@ -5078,6 +5151,16 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.14" diff --git a/ng-app/src/routes/WalletCreate.svelte b/ng-app/src/routes/WalletCreate.svelte index 91ca879..57cf8d2 100644 --- a/ng-app/src/routes/WalletCreate.svelte +++ b/ng-app/src/routes/WalletCreate.svelte @@ -292,7 +292,7 @@ } else { local_url = await ng.get_local_url(location.href); } - redirect_url = local_url + APP_WALLET_CREATE_SUFFIX; + if (local_url) redirect_url = local_url + APP_WALLET_CREATE_SUFFIX; } let create = { diff --git a/ng-sdk-js/src/lib.rs b/ng-sdk-js/src/lib.rs index 1978447..cf4eac4 100644 --- a/ng-sdk-js/src/lib.rs +++ b/ng-sdk-js/src/lib.rs @@ -25,10 +25,13 @@ use p2p_net::types::{ BootstrapContent, BootstrapContentV0, ClientId, ClientInfo, ClientInfoV0, ClientType, CreateAccountBSP, DirectPeerId, UserId, IP, }; +#[cfg(target_arch = "wasm32")] +use p2p_net::utils::retrieve_local_url; use p2p_net::utils::{ - decode_invitation_string, retrieve_local_bootstrap, retrieve_local_url, spawn_and_log_error, - Receiver, ResultSend, Sender, + decode_invitation_string, retrieve_local_bootstrap, spawn_and_log_error, Receiver, ResultSend, + Sender, }; + use p2p_net::WS_PORT; use p2p_repo::log::*; use p2p_repo::types::*; diff --git a/ngaccount/web/src/routes/Create.svelte b/ngaccount/web/src/routes/Create.svelte index c3e391f..3ee936e 100644 --- a/ngaccount/web/src/routes/Create.svelte +++ b/ngaccount/web/src/routes/Create.svelte @@ -276,7 +276,7 @@ link https://account.{domain}/#/delete or by entering in your NextGraph application and selecting the menu, - then Account, then delete
  • diff --git a/p2p-net/Cargo.toml b/p2p-net/Cargo.toml index 16e6ef9..e01a559 100644 --- a/p2p-net/Cargo.toml +++ b/p2p-net/Cargo.toml @@ -25,12 +25,13 @@ noise-protocol = "0.2.0-rc1" noise-rust-crypto = "0.6.0-rc.1" ed25519-dalek = "1.0.1" either = "1.8.1" -# reqwest = { version = "0.11.18", features = ["json"] } -#,"native-tls-vendored" url = "2.4.0" base64-url = "2.0.0" web-time = "0.2.0" +[target.'cfg(target_arch = "wasm32")'.dependencies] +reqwest = { version = "0.11.18", features = ["json"] } +#,"native-tls-vendored" [target.'cfg(target_arch = "wasm32")'.dependencies.getrandom] version = "0.2.7" diff --git a/p2p-net/src/utils.rs b/p2p-net/src/utils.rs index ae03f6f..8f10278 100644 --- a/p2p-net/src/utils.rs +++ b/p2p-net/src/utils.rs @@ -114,15 +114,16 @@ pub fn check_is_local_url(bootstrap: &BrokerServerV0, location: &String) -> Opti None } +#[cfg(target_arch = "wasm32")] pub async fn retrieve_local_url(location: String) -> Option { let bootstraps: BootstrapContent = { - // let resp = reqwest::get(format!("{}{}", APP_PREFIX, NG_BOOTSTRAP_LOCAL_PATH)).await; - // if resp.is_ok() { - // let resp = resp.unwrap().json::().await; - // resp.unwrap() - // } else { - return None; - // } + let resp = reqwest::get(format!("{}{}", APP_PREFIX, NG_BOOTSTRAP_LOCAL_PATH)).await; + if resp.is_ok() { + let resp = resp.unwrap().json::().await; + resp.unwrap() + } else { + return None; + } }; for bootstrap in bootstraps.servers() { let res = check_is_local_url(bootstrap, &location);