From 89fb4ef03fa24a000aec7c2ffaf8b87486df0d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Fri, 10 May 2024 10:45:44 +0100 Subject: [PATCH] fixing more build issues --- wasm/mix-fetch/Makefile | 23 ++++++++ wasm/zknym-lib/Cargo.toml | 2 +- wasm/zknym-lib/src/bandwidth_voucher.rs | 59 +++++++++++---------- wasm/zknym-lib/src/error.rs | 13 ++--- wasm/zknym-lib/src/vpn_api_client/client.rs | 10 ++-- wasm/zknym-lib/src/vpn_api_client/mod.rs | 5 ++ 6 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 wasm/mix-fetch/Makefile diff --git a/wasm/mix-fetch/Makefile b/wasm/mix-fetch/Makefile new file mode 100644 index 0000000000..1a4a871050 --- /dev/null +++ b/wasm/mix-fetch/Makefile @@ -0,0 +1,23 @@ +build: build-go-opt build-rust build-package-json + +check-fmt: check-fmt-go check-fmt-rust + +build-go: + $(MAKE) -C go-mix-conn build-go + +build-go-opt: + $(MAKE) -C go-mix-conn build-go-opt + +build-rust: + wasm-pack build --scope nymproject --target web --out-dir ../../dist/wasm/mix-fetch + wasm-opt -Oz -o ../../dist/wasm/mix-fetch/mix_fetch_wasm_bg.wasm ../../dist/wasm/mix-fetch/mix_fetch_wasm_bg.wasm + +build-package-json: + node build.mjs + +check-fmt-go: + $(MAKE) -C go-mix-conn check-fmt + +check-fmt-rust: + cargo fmt --check + cargo clippy --target wasm32-unknown-unknown -- -Dwarnings \ No newline at end of file diff --git a/wasm/zknym-lib/Cargo.toml b/wasm/zknym-lib/Cargo.toml index df62bac819..6fdfb431bb 100644 --- a/wasm/zknym-lib/Cargo.toml +++ b/wasm/zknym-lib/Cargo.toml @@ -38,7 +38,7 @@ nym-http-api-client = { path = "../../common/http-api-client" } wasm-utils = { path = "../../common/wasm/utils" } [dev-dependencies] -anyhow = { workspac = true } +anyhow = { workspace = true } tokio = { workspace = true, features = ["full"] } diff --git a/wasm/zknym-lib/src/bandwidth_voucher.rs b/wasm/zknym-lib/src/bandwidth_voucher.rs index 746cde5290..b047550c1e 100644 --- a/wasm/zknym-lib/src/bandwidth_voucher.rs +++ b/wasm/zknym-lib/src/bandwidth_voucher.rs @@ -197,32 +197,33 @@ pub struct SerialisedNymIssuedBandwidthVoucher { pub bs58_encoded_data: String, } -#[cfg(test)] -mod tests { - use super::*; - use crate::vpn_api_client::client::{new_client, NymVpnApiClient}; - - #[tokio::test] - async fn end_to_end() -> anyhow::Result<()> { - let client = new_client("http://0.0.0.0:8080", "foomp")?; - let opts = client.get_prehashed_public_attributes().await?; - let issuance = NymIssuanceBandwidthVoucher::prepare_new(opts, None)?; - - let shares = client - .get_bandwidth_voucher_blinded_shares(issuance.blind_sign_request.clone()) - .await?; - let keys = client.get_partial_verification_keys().await?; - let master_key = client.get_master_verification_key().await?; - - let voucher = issuance.unblind_shares(shares, keys)?; - - println!( - "valid: {}", - voucher.ensure_is_valid(master_key.bs58_encoded_key, None) - ); - let serialised = voucher.serialise(); - println!("final: {serialised:#?}"); - - Ok(()) - } -} +// #[cfg(test)] +// mod tests { +// use super::*; +// use crate::vpn_api_client::client::{new_client, NymVpnApiClient}; +// +// #[ignore] +// #[tokio::test] +// async fn end_to_end() -> anyhow::Result<()> { +// let client = new_client("http://0.0.0.0:8080", "foomp")?; +// let opts = client.get_prehashed_public_attributes().await?; +// let issuance = NymIssuanceBandwidthVoucher::prepare_new(opts, None)?; +// +// let shares = client +// .get_bandwidth_voucher_blinded_shares(issuance.blind_sign_request.clone()) +// .await?; +// let keys = client.get_partial_verification_keys().await?; +// let master_key = client.get_master_verification_key().await?; +// +// let voucher = issuance.unblind_shares(shares, keys)?; +// +// println!( +// "valid: {}", +// voucher.ensure_is_valid(master_key.bs58_encoded_key, None) +// ); +// let serialised = voucher.serialise(); +// println!("final: {serialised:#?}"); +// +// Ok(()) +// } +// } diff --git a/wasm/zknym-lib/src/error.rs b/wasm/zknym-lib/src/error.rs index e318a2ce87..b283908438 100644 --- a/wasm/zknym-lib/src/error.rs +++ b/wasm/zknym-lib/src/error.rs @@ -1,6 +1,7 @@ // Copyright 2024 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use crate::vpn_api_client::NymVpnApiClientError; use thiserror::Error; use wasm_utils::wasm_error; @@ -11,12 +12,12 @@ pub enum ZkNymError { #[from] source: nym_coconut::CoconutError, }, - // - // #[error("failed to contact the vpn api")] - // HttpClientFailure { - // #[from] - // source: NymVpnApiClientError, - // }, + + #[error("failed to contact the vpn api")] + HttpClientFailure { + #[from] + source: NymVpnApiClientError, + }, #[error("the provided shares and issuers are not from the same epoch! {shares} and {issuers}")] InconsistentEpochId { shares: u64, issuers: u64 }, diff --git a/wasm/zknym-lib/src/vpn_api_client/client.rs b/wasm/zknym-lib/src/vpn_api_client/client.rs index b07353ec6e..38627d7838 100644 --- a/wasm/zknym-lib/src/vpn_api_client/client.rs +++ b/wasm/zknym-lib/src/vpn_api_client/client.rs @@ -1,25 +1,26 @@ // Copyright 2024 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use super::NymVpnApiClientError; use crate::error::ZkNymError; use crate::vpn_api_client::types::{ - AttributesResponse, BandwidthVoucherRequest, BandwidthVoucherResponse, ErrorResponse, + AttributesResponse, BandwidthVoucherRequest, BandwidthVoucherResponse, MasterVerificationKeyResponse, PartialVerificationKeysResponse, }; use async_trait::async_trait; use nym_coconut::BlindSignRequest; pub use nym_http_api_client::Client; -use nym_http_api_client::{parse_response, HttpClientError, PathSegments, NO_PARAMS}; +use nym_http_api_client::{parse_response, PathSegments, NO_PARAMS}; use reqwest::IntoUrl; use serde::de::DeserializeOwned; -pub type NymVpnApiClientError = HttpClientError; - +#[allow(dead_code)] pub struct VpnApiClient { inner: Client, bearer_token: String, } +#[allow(dead_code)] pub fn new_client( base_url: impl IntoUrl, bearer_token: impl Into, @@ -33,6 +34,7 @@ pub fn new_client( } // TODO: do it properly by implementing auth headers on `ApiClient` trait +#[allow(dead_code)] #[async_trait(?Send)] pub trait NymVpnApiClient { async fn simple_get(&self, path: PathSegments<'_>) -> Result diff --git a/wasm/zknym-lib/src/vpn_api_client/mod.rs b/wasm/zknym-lib/src/vpn_api_client/mod.rs index 366fa05443..041e9f0bc1 100644 --- a/wasm/zknym-lib/src/vpn_api_client/mod.rs +++ b/wasm/zknym-lib/src/vpn_api_client/mod.rs @@ -1,7 +1,12 @@ // Copyright 2024 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use crate::vpn_api_client::types::ErrorResponse; +use nym_http_api_client::HttpClientError; + #[cfg(test)] pub(crate) mod client; pub mod types; + +pub type NymVpnApiClientError = HttpClientError;