Add VeilidRoutingContext class for WASM

This commit is contained in:
Brandon Vandegrift
2023-09-02 14:15:38 -04:00
parent 9aeec3cfa8
commit c5d7922fc5
9 changed files with 323 additions and 21 deletions

View File

@@ -0,0 +1,2 @@
[build]
target = "wasm32-unknown-unknown"

View File

@@ -2,16 +2,20 @@ use super::*;
/// DHT Record Descriptor
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct DHTRecordDescriptor {
/// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
#[schemars(with = "String")]
#[cfg_attr(target_arch = "wasm32", tsify(type = "string"))]
key: TypedKey,
/// The public key of the owner
#[schemars(with = "String")]
#[cfg_attr(target_arch = "wasm32", tsify(type = "string"))]
owner: PublicKey,
/// If this key is being created: Some(the secret key of the owner)
/// If this key is just being opened: None
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(type = "string | undefined"))]
owner_secret: Option<SecretKey>,
/// The schema in use associated with the key
schema: DHTSchema,

View File

@@ -9,6 +9,7 @@ pub use smpl::*;
/// Enum over all the supported DHT Schemas
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "kind")]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))]
pub enum DHTSchema {
DFLT(DHTSchemaDFLT),
SMPL(DHTSchemaSMPL),

View File

@@ -10,10 +10,12 @@ pub struct ValueData {
/// The contents of a DHT Record
#[serde(with = "as_human_base64")]
#[schemars(with = "String")]
#[cfg_attr(target_arch = "wasm32", tsify(type = "string"))]
data: Vec<u8>,
/// The public identity key of the writer of the data
#[schemars(with = "String")]
#[cfg_attr(target_arch = "wasm32", tsify(type = "string"))]
writer: PublicKey,
}
impl ValueData {

View File

@@ -4,6 +4,7 @@ use super::*;
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi, namespace))]
pub enum Sequencing {
NoPreference = 0,
PreferOrdered = 1,
@@ -20,6 +21,7 @@ impl Default for Sequencing {
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi, namespace))]
pub enum Stability {
LowLatency = 0,
Reliable = 1,
@@ -35,6 +37,7 @@ impl Default for Stability {
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi, namespace))]
pub enum SafetySelection {
/// Don't use a safety route, only specify the sequencing preference
Unsafe(Sequencing),
@@ -61,9 +64,11 @@ impl Default for SafetySelection {
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct SafetySpec {
/// preferred safety route set id if it still exists
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(type = "string | undefined"))]
pub preferred_route: Option<RouteId>,
/// must be greater than 0
pub hop_count: usize,