Move validate function to lox_utils
This commit is contained in:
parent
b016bc9742
commit
c7c5f57864
|
@ -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::bridge_table::{BridgeLine, ENC_BUCKET_BYTES};
|
||||||
use lox::cred::{Invitation, Lox};
|
use lox::cred::{Invitation, Lox};
|
||||||
use lox::IssuerPubKey;
|
use lox::proto;
|
||||||
use lox::{proto, scalar_u32};
|
use lox::{IssuerPubKey, OPENINV_LENGTH};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::serde_as;
|
use serde_with::serde_as;
|
||||||
|
use std::array::TryFromSliceError;
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct OpenReqState {
|
pub struct OpenReqState {
|
||||||
|
@ -78,3 +76,8 @@ pub struct LoxCredential {
|
||||||
pub bridgeline: Option<BridgeLine>,
|
pub bridgeline: Option<BridgeLine>,
|
||||||
pub invitation: Option<Invitation>,
|
pub invitation: Option<Invitation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This should also check the pubkey
|
||||||
|
pub fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> {
|
||||||
|
invite.try_into()
|
||||||
|
}
|
||||||
|
|
|
@ -6,8 +6,7 @@ use lox::proto::{
|
||||||
blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite,
|
blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite,
|
||||||
redeem_invite, trust_promotion,
|
redeem_invite, trust_promotion,
|
||||||
};
|
};
|
||||||
use lox::{scalar_u32, OPENINV_LENGTH};
|
use lox::scalar_u32;
|
||||||
use std::array::TryFromSliceError;
|
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use zkp::ProofError;
|
use zkp::ProofError;
|
||||||
|
@ -55,7 +54,7 @@ pub fn open_invite(invite: &[u8]) -> Result<String, JsValue> {
|
||||||
unsafe {
|
unsafe {
|
||||||
log(&format!("Using invite: {:?}", invite));
|
log(&format!("Using invite: {:?}", invite));
|
||||||
}
|
}
|
||||||
let token = match validate(invite) {
|
let token = match lox_utils::validate(invite) {
|
||||||
Ok(token) => token,
|
Ok(token) => token,
|
||||||
Err(e) => return Err(JsValue::from(e.to_string())),
|
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())
|
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()
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue