148 lines
4.4 KiB
Rust
148 lines
4.4 KiB
Rust
use lox_library::bridge_table::{
|
|
from_scalar, BridgeLine, BridgeTable, EncryptedBucket, MAX_BRIDGES_PER_BUCKET,
|
|
};
|
|
use lox_library::cred::{BucketReachability, Invitation, Lox};
|
|
use lox_library::proto::{self, check_blockage, level_up, trust_promotion};
|
|
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,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
pub struct LoxSystemInfo {
|
|
pub max_level: usize,
|
|
pub untrusted_interval: u32,
|
|
pub max_blockages: [u32; level_up::MAX_LEVEL + 1],
|
|
pub level_interval: [u32; level_up::MAX_LEVEL + 1],
|
|
pub level_invitations: [u32; level_up::MAX_LEVEL + 1],
|
|
pub min_blockage_migration_trust_level: u32,
|
|
}
|
|
|
|
pub const LOX_SYSTEM_INFO: LoxSystemInfo = LoxSystemInfo {
|
|
max_level: level_up::MAX_LEVEL,
|
|
untrusted_interval: trust_promotion::UNTRUSTED_INTERVAL,
|
|
max_blockages: level_up::MAX_BLOCKAGES,
|
|
level_interval: level_up::LEVEL_INTERVAL,
|
|
level_invitations: level_up::LEVEL_INVITATIONS,
|
|
min_blockage_migration_trust_level: check_blockage::MIN_TRUST_LEVEL,
|
|
};
|
|
|
|
#[serde_as]
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct EncBridgeTable {
|
|
pub etable: HashMap<u32, EncryptedBucket>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
pub struct LoxCredential {
|
|
pub lox_credential: Lox,
|
|
pub bridgelines: Option<Vec<BridgeLine>>,
|
|
pub invitation: Option<Invitation>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
pub struct IssuedInvitation {
|
|
pub invitation: Invitation,
|
|
}
|
|
|
|
// 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 fn get_credential_bridgelines(
|
|
lox_cred: &Lox,
|
|
encrypted_table: String,
|
|
) -> [BridgeLine; MAX_BRIDGES_PER_BUCKET] {
|
|
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.0
|
|
}
|
|
|
|
//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
|
|
}
|