use lox_library::bridge_table::{from_scalar, BridgeLine, BridgeTable, EncryptedBucket}; use lox_library::cred::{BucketReachability, Invitation, Lox}; use lox_library::proto; use lox_library::{IssuerPubKey, OPENINV_LENGTH}; use serde::{Deserialize, Serialize}; use serde_with::serde_as; use std::array::TryFromSliceError; use std::collections::HashMap; #[serde_as] #[derive(Serialize, Deserialize)] pub struct Invite { #[serde_as(as = "[_; OPENINV_LENGTH]")] pub invite: [u8; OPENINV_LENGTH], } #[derive(Deserialize, Serialize)] pub struct OpenReqState { pub request: proto::open_invite::Request, pub state: proto::open_invite::State, } #[derive(Deserialize, Serialize)] pub struct TrustReqState { pub request: proto::trust_promotion::Request, pub state: proto::trust_promotion::State, } #[derive(Deserialize, Serialize)] pub struct MigReqState { pub request: proto::migration::Request, pub state: proto::migration::State, } #[derive(Deserialize, Serialize)] pub struct LevelupReqState { pub request: proto::level_up::Request, pub state: proto::level_up::State, } #[derive(Deserialize, Serialize)] pub struct IssueInviteReqState { pub request: proto::issue_invite::Request, pub state: proto::issue_invite::State, } #[derive(Deserialize, Serialize)] pub struct RedeemReqState { pub request: proto::redeem_invite::Request, pub state: proto::redeem_invite::State, } #[derive(Deserialize, Serialize)] pub struct CheckBlockageReqState { pub request: proto::check_blockage::Request, pub state: proto::check_blockage::State, } #[derive(Deserialize, Serialize)] pub struct BlockageMigReqState { pub request: proto::blockage_migration::Request, pub state: proto::blockage_migration::State, } #[derive(Debug, Deserialize, Serialize)] pub struct PubKeys { pub lox_pub: IssuerPubKey, pub migration_pub: IssuerPubKey, pub migrationkey_pub: IssuerPubKey, pub reachability_pub: IssuerPubKey, pub invitation_pub: IssuerPubKey, } #[serde_as] #[derive(Serialize, Deserialize)] pub struct EncBridgeTable { pub etable: HashMap, } #[derive(Debug, Deserialize, Serialize)] pub struct LoxCredential { pub lox_credential: Lox, 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() } pub fn generate_reachability_cred(lox_cred: &Lox, encrypted_table: String) -> BucketReachability { let (id, key) = from_scalar(lox_cred.bucket).unwrap(); let enc_buckets: EncBridgeTable = serde_json::from_str(&encrypted_table).unwrap(); let bucket = BridgeTable::decrypt_bucket(id, &key, enc_buckets.etable.get(&id).unwrap()).unwrap(); bucket.1.unwrap() } //pub const MAX_LEVEL: usize = 4; //pub const LEVEL_INTERVAL: [u32; MAX_LEVEL + 1] = [0, 14, 28, 56, 84]; pub fn calc_test_days(trust_level: i64) -> i64 { let mut total = 31; // for level in 0..trust_level { // let level_interval: u32 = LEVEL_INTERVAL[trust_level as usize]; // total += level_interval; total += trust_level * 85; // } total }