diff --git a/crates/lox-utils/src/lib.rs b/crates/lox-utils/src/lib.rs index 3c759bc..5d518e3 100644 --- a/crates/lox-utils/src/lib.rs +++ b/crates/lox-utils/src/lib.rs @@ -1,12 +1,10 @@ -/*! A small util library for Lox credential helpers -useful across many Lox crates -*/ use lox::bridge_table::{BridgeLine, ENC_BUCKET_BYTES}; use lox::cred::{Invitation, Lox}; -use lox::IssuerPubKey; -use lox::{proto, scalar_u32}; +use lox::proto; +use lox::{IssuerPubKey, OPENINV_LENGTH}; use serde::{Deserialize, Serialize}; use serde_with::serde_as; +use std::array::TryFromSliceError; #[derive(Deserialize, Serialize)] pub struct OpenReqState { @@ -78,3 +76,8 @@ pub struct LoxCredential { pub bridgeline: Option, pub invitation: Option, } + +// This should also check the pubkey +pub fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> { + invite.try_into() +} diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index 5158a65..5958665 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -6,8 +6,7 @@ use lox::proto::{ blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite, redeem_invite, trust_promotion, }; -use lox::{scalar_u32, OPENINV_LENGTH}; -use std::array::TryFromSliceError; +use lox::scalar_u32; use std::panic; use wasm_bindgen::prelude::*; use zkp::ProofError; @@ -55,7 +54,7 @@ pub fn open_invite(invite: &[u8]) -> Result { unsafe { log(&format!("Using invite: {:?}", invite)); } - let token = match validate(invite) { + let token = match lox_utils::validate(invite) { Ok(token) => token, Err(e) => return Err(JsValue::from(e.to_string())), }; @@ -588,8 +587,3 @@ pub fn handle_blockage_migration( } Ok(serde_json::to_string(&lox_cred).unwrap()) } - -// This should also check the pubkey -fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> { - invite.try_into() -}