Skip to content

Commit c8b2fdf

Browse files
committed
Typescript SDK support for zk-nyms
1 parent 44cf9b0 commit c8b2fdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+8065
-1225
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ foxyfox.env
4848

4949
.next
5050
ppa-private-key.b64
51-
ppa-private-key.asc
51+
ppa-private-key.asc
52+
53+
yarn-error.log

Cargo.lock

Lines changed: 33 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ members = [
119119
# "wasm/full-nym-wasm", # If we uncomment this again, remember to also uncomment the profile settings below
120120
"wasm/mix-fetch",
121121
"wasm/node-tester",
122-
"wasm/zknym-lib",
122+
"wasm/zk-nym-lib",
123+
"wasm/zk-nym-faucet-lib",
123124
]
124125

125126
default-members = [
@@ -347,7 +348,6 @@ wasmtimer = "0.2.0"
347348
web-sys = "0.3.69"
348349
itertools = "0.12.0"
349350

350-
351351
# Profile settings for individual crates
352352

353353
[profile.release.package.nym-socks5-listener]

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ sdk-wasm-build:
104104
$(MAKE) -C wasm/client
105105
$(MAKE) -C wasm/node-tester
106106
$(MAKE) -C wasm/mix-fetch
107-
$(MAKE) -C wasm/zknym-lib
107+
$(MAKE) -C wasm/zk-nym-lib
108+
$(MAKE) -C wasm/zk-nym-faucet-lib
108109
#$(MAKE) -C wasm/full-nym-wasm
109110

110111
# run this from npm/yarn to ensure tools are in the path, e.g. yarn build:sdk from root of repo

common/bandwidth-controller/src/acquire/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ use zeroize::Zeroizing;
1717

1818
pub mod state;
1919

20-
pub async fn deposit<C>(client: &C, amount: Coin) -> Result<State, BandwidthControllerError>
20+
pub async fn deposit<C>(
21+
client: &C,
22+
amount: impl Into<Coin>,
23+
) -> Result<State, BandwidthControllerError>
2124
where
2225
C: CoconutBandwidthSigningClient + Sync,
2326
{
2427
let mut rng = OsRng;
2528
let signing_key = identity::PrivateKey::new(&mut rng);
2629
let encryption_key = encryption::PrivateKey::new(&mut rng);
30+
let amount = amount.into();
2731

2832
let tx_hash = client
2933
.deposit(

common/client-libs/validator-client/src/nyxd/error.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum NyxdError {
4444
#[error("{0} is not a valid tx hash")]
4545
InvalidTxHash(String),
4646

47-
#[error("Tendermint RPC request failed - {0}")]
47+
#[error("Tendermint RPC request failed: {0}")]
4848
TendermintErrorRpc(#[from] TendermintRpcError),
4949

5050
#[error("tendermint library failure: {0}")]
@@ -56,22 +56,22 @@ pub enum NyxdError {
5656
#[error("Failed when attempting to deserialize data ({0})")]
5757
DeserializationError(String),
5858

59-
#[error("Failed when attempting to encode our protobuf data - {0}")]
59+
#[error("Failed when attempting to encode our protobuf data: {0}")]
6060
ProtobufEncodingError(#[from] prost::EncodeError),
6161

62-
#[error("Failed to decode our protobuf data - {0}")]
62+
#[error("Failed to decode our protobuf data: {0}")]
6363
ProtobufDecodingError(#[from] prost::DecodeError),
6464

65-
#[error("Account {0} does not exist on the chain")]
65+
#[error("Account '{0}' does not exist on the chain")]
6666
NonExistentAccountError(AccountId),
6767

68-
#[error("Failed on json serialization/deserialization - {0}")]
68+
#[error("Failed on json serialization/deserialization: {0}")]
6969
SerdeJsonError(#[from] serde_json::Error),
7070

71-
#[error("Account {0} is not a valid account address")]
71+
#[error("Account '{0}' is not a valid account address")]
7272
MalformedAccountAddress(String),
7373

74-
#[error("Account {0} has an invalid associated public key")]
74+
#[error("Account '{0}' has an invalid associated public key")]
7575
InvalidPublicKey(AccountId),
7676

7777
#[error("Queried contract (code_id: {0}) did not have any code information attached")]
@@ -86,7 +86,7 @@ pub enum NyxdError {
8686
#[error("Block has an invalid height (either negative or larger than i64::MAX")]
8787
InvalidHeight,
8888

89-
#[error("Failed to compress provided wasm code - {0}")]
89+
#[error("Failed to compress provided wasm code: {0}")]
9090
WasmCompressionError(io::Error),
9191

9292
#[error("Logs returned from the validator were malformed")]

common/client-libs/validator-client/src/rpc/reqwest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ trait TendermintRpcErrorMap {
109109

110110
impl TendermintRpcErrorMap for reqwest::Error {
111111
fn into_rpc_err(self) -> Error {
112-
todo!()
112+
// that's not the best error converion, but it's better than a panic
113+
Error::client_internal(self.to_string())
113114
}
114115
}
115116

common/credential-storage/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ license.workspace = true
88

99
[dependencies]
1010
async-trait = { workspace = true }
11-
1211
log = { workspace = true }
1312
thiserror = { workspace = true }
1413
tokio = { workspace = true, features = ["sync"]}

common/credential-storage/src/backends/memory.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ impl CoconutCredentialManager {
3333
}
3434
}
3535

36+
pub async fn take_credentials(self) -> Vec<StoredIssuedCredential> {
37+
let mut inner = self.inner.write().await;
38+
inner.credential_usage = Vec::new();
39+
std::mem::take(&mut inner.credentials)
40+
}
41+
3642
pub async fn insert_issued_credential(
3743
&self,
3844
credential_type: String,

common/credential-storage/src/ephemeral_storage.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ pub struct EphemeralStorage {
1717
coconut_credential_manager: CoconutCredentialManager,
1818
}
1919

20+
impl EphemeralStorage {
21+
pub async fn take_credentials(self) -> Vec<StoredIssuedCredential> {
22+
self.coconut_credential_manager.take_credentials().await
23+
}
24+
}
25+
2026
impl Default for EphemeralStorage {
2127
fn default() -> Self {
2228
EphemeralStorage {

common/credential-storage/src/models.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@
33

44
use zeroize::{Zeroize, ZeroizeOnDrop};
55

6-
// #[derive(Clone)]
7-
// pub struct CoconutCredential {
8-
// #[allow(dead_code)]
9-
// pub id: i64,
10-
// pub voucher_value: String,
11-
// pub voucher_info: String,
12-
// pub serial_number: String,
13-
// pub binding_number: String,
14-
// pub signature: String,
15-
// pub epoch_id: String,
16-
// pub consumed: bool,
17-
// }
18-
196
#[cfg_attr(not(target_arch = "wasm32"), derive(sqlx::FromRow))]
207
#[derive(Zeroize, ZeroizeOnDrop, Clone)]
218
pub struct StoredIssuedCredential {

common/crypto/src/shared_key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
use crate::asymmetric::encryption;
55
use crate::hkdf;
6-
#[cfg(feature = "rand")]
7-
use cipher::crypto_common::rand_core::{CryptoRng, RngCore};
86
use cipher::{Key, KeyIvInit, StreamCipher};
97
use digest::crypto_common::BlockSizeUser;
108
use digest::Digest;
9+
#[cfg(feature = "rand")]
10+
use rand::{CryptoRng, RngCore};
1111

1212
/// Generate an ephemeral encryption keypair and perform diffie-hellman to establish
1313
/// shared key with the remote.

common/network-defaults/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ schemars = { workspace = true, features = ["preserve_order"] }
1717
serde = { workspace = true, features = ["derive"]}
1818
thiserror = { workspace = true }
1919
url = { workspace = true }
20+
21+
# 'wasm-serde-types' feature
22+
tsify = { workspace = true, features = ["js"], optional = true }
23+
wasm-bindgen = { workspace = true, optional = true }
24+
25+
[features]
26+
default = []
27+
wasm-serde-types = ["tsify", "wasm-bindgen"]

0 commit comments

Comments
 (0)