Files
nym/common/topology/src/wasm_helpers.rs
T
mfahampshire cf3fd00350 Max/crates io prep v2 (#6270)
* - standardise versions for all nym-sdk workspace dependencies
- prepend sqlx-pool-guard with 'nym-'

* Test remove nym-api from deps

* Add oneliner to client_pool doc comments

* Add note to commented out docs.rs link in sdk

* remove nym-api from script

* add publishing file

* bring non-binary / contract / tools into workspace version

* added more info to publishing.md

* make deps workspace version

* remove uploaded sphinx-types crate from script

* remove erroueously included ignore-defaults

* add zeroise to feature

* chore: Release

* add topology to batch

* more cargo versioning

* more cargo versioning - wasm utils

* more cargo versioning - wasm utils

* Add publish=false to manifest for cargo workspaces / crates.io
publishing exclusion

* remove script now switched to manifest based exclusion

* rename import based on rename of contracts-common dep

* Making workspace versions for publication + removing unnecessary crates
from publication

* Remove OOD info from publishing sdk guide

* rename contract imports + remove package

* temp commit: continuing with removal of path from cargo manifest and
replacing with workspace version import for publication

* continuing with cargo.toml updates

* dryrun only erroring on known version problem crates

* remove old published-crates file

* Minor comment change

* remove default features warning

* Additional info on workspace dep comment re publish list

* Add missing description to cargo.toml

* Fix missing feature flags

* Add missing descriptions

* Fix remaining path import

* Add workspace repo / homepage / documentation links to cargo.toml files

* remove workspace version from excluded crate

* Remove todo descriptions

* Minor comment change

* add homepage etc

* move from bls git import to nym_bls_fork crate

* Modify rest of imports from path to workspace import, excluding binaries

* add directory/homepage info

* fix cargo fmt

* add notes to gitignore

* better solution to contracts/ experiment

* wasm -> nym_wasm crate renaming

* fix fatfinger

* add metadata to ecash cargo.toml

* stub publishing guide

* fix misrevolved netlink- version

* Fixes and block publication of rebase re: LP

* first pass @ workflows
2026-01-19 13:19:45 +00:00

131 lines
3.9 KiB
Rust

// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
// due to the code generated by Tsify
#![allow(clippy::empty_docs)]
use crate::node::{EntryDetails, RoutingNode, RoutingNodeError, SupportedRoles};
use crate::{CachedEpochRewardedSet, NymTopology, NymTopologyMetadata};
use nym_wasm_utils::error::simple_js_error;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::net::SocketAddr;
use thiserror::Error;
use tsify::Tsify;
use wasm_bindgen::{JsValue, prelude::wasm_bindgen};
#[derive(Debug, Error)]
pub enum SerializableTopologyError {
#[error(transparent)]
NodeConversion(#[from] RoutingNodeError),
#[error("{provided} is not a valid ed25519 public key")]
MalformedIdentity { provided: String },
#[error("{provided} is not a valid x25519 public key")]
MalformedSphinxKey { provided: String },
}
#[cfg(feature = "wasm-serde-types")]
impl From<SerializableTopologyError> for JsValue {
fn from(value: SerializableTopologyError) -> Self {
simple_js_error(value.to_string())
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct WasmFriendlyNymTopology {
pub metadata: NymTopologyMetadata,
pub rewarded_set: CachedEpochRewardedSet,
pub node_details: HashMap<u32, WasmFriendlyRoutingNode>,
}
impl TryFrom<WasmFriendlyNymTopology> for NymTopology {
type Error = SerializableTopologyError;
fn try_from(value: WasmFriendlyNymTopology) -> Result<Self, Self::Error> {
let node_details = value
.node_details
.into_values()
.map(|details| details.try_into())
.collect::<Result<_, _>>()?;
Ok(NymTopology::new(
value.metadata,
value.rewarded_set,
node_details,
))
}
}
impl From<NymTopology> for WasmFriendlyNymTopology {
fn from(value: NymTopology) -> Self {
WasmFriendlyNymTopology {
metadata: value.metadata,
rewarded_set: value.rewarded_set,
node_details: value
.node_details
.into_iter()
.map(|(k, v)| (k, v.into()))
.collect(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct WasmFriendlyRoutingNode {
pub node_id: u32,
pub mix_host: SocketAddr,
pub entry: Option<EntryDetails>,
pub identity_key: String,
pub sphinx_key: String,
pub supported_roles: SupportedRoles,
}
impl TryFrom<WasmFriendlyRoutingNode> for RoutingNode {
type Error = SerializableTopologyError;
fn try_from(value: WasmFriendlyRoutingNode) -> Result<Self, Self::Error> {
Ok(RoutingNode {
node_id: value.node_id,
mix_host: value.mix_host,
entry: value.entry,
identity_key: value.identity_key.as_str().parse().map_err(|_| {
SerializableTopologyError::MalformedIdentity {
provided: value.identity_key,
}
})?,
sphinx_key: value.sphinx_key.as_str().parse().map_err(|_| {
SerializableTopologyError::MalformedIdentity {
provided: value.sphinx_key,
}
})?,
supported_roles: value.supported_roles,
})
}
}
impl From<RoutingNode> for WasmFriendlyRoutingNode {
fn from(node: RoutingNode) -> Self {
WasmFriendlyRoutingNode {
node_id: node.node_id,
mix_host: node.mix_host,
entry: node.entry,
identity_key: node.identity_key.to_string(),
sphinx_key: node.sphinx_key.to_string(),
supported_roles: node.supported_roles,
}
}
}