Added serialization and deserialization for all but check blockage and trust promotion
This commit is contained in:
parent
fd05dce77d
commit
179fea5e23
|
@ -12,6 +12,8 @@ zkp = "0.8"
|
|||
bincode = "1"
|
||||
rand = "0.7"
|
||||
serde = "1"
|
||||
serde-big-array = "0.3.2"
|
||||
serde_with = "1.9.1"
|
||||
sha2 = "0.9"
|
||||
lazy_static = "1"
|
||||
hex_fmt = "0.3"
|
||||
|
|
|
@ -18,10 +18,17 @@ use curve25519_dalek::ristretto::CompressedRistretto;
|
|||
use curve25519_dalek::ristretto::RistrettoBasepointTable;
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
use rand::RngCore;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_big_array::big_array;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::convert::TryInto;
|
||||
use subtle::ConstantTimeEq;
|
||||
|
||||
big_array! {
|
||||
BigArray;
|
||||
+202,
|
||||
}
|
||||
|
||||
/// Each bridge information line is serialized into this many bytes
|
||||
pub const BRIDGE_BYTES: usize = 220;
|
||||
|
||||
|
@ -35,7 +42,7 @@ pub const MAX_BRIDGES_PER_BUCKET: usize = 3;
|
|||
pub const MIN_BUCKET_REACHABILITY: usize = 2;
|
||||
|
||||
/// A bridge information line
|
||||
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Hash, Eq, PartialEq, Debug)]
|
||||
pub struct BridgeLine {
|
||||
/// IPv4 or IPv6 address
|
||||
pub addr: [u8; 16],
|
||||
|
@ -43,6 +50,7 @@ pub struct BridgeLine {
|
|||
pub port: u16,
|
||||
/// other protocol information, including pluggable transport,
|
||||
/// public key, etc.
|
||||
#[serde(with = "BigArray")]
|
||||
pub info: [u8; BRIDGE_BYTES - 18],
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ use zkp::CompactProof;
|
|||
use zkp::ProofError;
|
||||
use zkp::Transcript;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use super::super::cred;
|
||||
use super::super::dup_filter::SeenType;
|
||||
use super::super::migration_table::MigrationType;
|
||||
|
@ -52,6 +54,7 @@ use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
|
|||
use super::check_blockage::MIN_TRUST_LEVEL;
|
||||
use super::level_up::LEVEL_INVITATIONS;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Request {
|
||||
// Fields for blind showing the Lox credential
|
||||
P_lox: RistrettoPoint,
|
||||
|
@ -92,6 +95,8 @@ pub struct State {
|
|||
blockages: Scalar,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Response {
|
||||
// The new attributes; the trust_level and invites_remaining are
|
||||
// implicit
|
||||
|
|
|
@ -54,12 +54,15 @@ use zkp::CompactProof;
|
|||
use zkp::ProofError;
|
||||
use zkp::Transcript;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use super::super::cred;
|
||||
use super::super::dup_filter::SeenType;
|
||||
use super::super::scalar_u32;
|
||||
use super::super::{BridgeAuth, IssuerPubKey};
|
||||
use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Request {
|
||||
// Fields for blind showing the Lox credential
|
||||
P: RistrettoPoint,
|
||||
|
@ -116,6 +119,7 @@ pub struct State {
|
|||
inv_id_client: Scalar,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Response {
|
||||
// The fields for the new Lox credential; the new invites_remaining
|
||||
// is one less than the old value, so we don't have to include it
|
||||
|
|
|
@ -47,6 +47,8 @@ use zkp::CompactProof;
|
|||
use zkp::ProofError;
|
||||
use zkp::Transcript;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use super::super::cred;
|
||||
use super::super::dup_filter::SeenType;
|
||||
use super::super::{pt_dbl, scalar_dbl, scalar_u32};
|
||||
|
@ -80,6 +82,7 @@ pub const LEVEL_INVITATIONS: [u32; MAX_LEVEL + 1] = [0, 2, 4, 6, 8];
|
|||
// one or more bits to the ZKP.
|
||||
pub const MAX_BLOCKAGES: [u32; MAX_LEVEL + 1] = [0, 4, 3, 2, 2];
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Request {
|
||||
// Fields for blind showing the Lox credential
|
||||
P: RistrettoPoint,
|
||||
|
@ -148,6 +151,7 @@ pub struct State {
|
|||
blockages: Scalar,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Response {
|
||||
// The fields for the new Lox credential; the new trust level is one
|
||||
// more than the old trust level, so we don't have to include it
|
||||
|
|
|
@ -39,11 +39,14 @@ use zkp::CompactProof;
|
|||
use zkp::ProofError;
|
||||
use zkp::Transcript;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use super::super::cred;
|
||||
use super::super::dup_filter::SeenType;
|
||||
use super::super::{BridgeAuth, IssuerPubKey};
|
||||
use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Request {
|
||||
// Fields for blind showing the Lox credential
|
||||
// We don't need to include invites_remaining or blockages,
|
||||
|
@ -80,6 +83,7 @@ pub struct State {
|
|||
to_bucket: Scalar,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Response {
|
||||
// The new attributes; trust_level = 1 is implicit
|
||||
level_since: Scalar,
|
||||
|
|
|
@ -22,6 +22,9 @@ use zkp::CompactProof;
|
|||
use zkp::ProofError;
|
||||
use zkp::Transcript;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_big_array::big_array;
|
||||
|
||||
use super::super::bridge_table;
|
||||
use super::super::bridge_table::BridgeLine;
|
||||
use super::super::cred;
|
||||
|
@ -30,16 +33,20 @@ use super::super::OPENINV_LENGTH;
|
|||
use super::super::{BridgeAuth, BridgeDb, IssuerPubKey};
|
||||
use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
|
||||
|
||||
big_array! { BigArray; }
|
||||
|
||||
/// The request message for this protocol
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Request {
|
||||
#[serde(with = "BigArray")]
|
||||
invite: [u8; OPENINV_LENGTH],
|
||||
D: RistrettoPoint,
|
||||
EncIdClient: (RistrettoPoint, RistrettoPoint),
|
||||
piUserBlinding: CompactProof,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// The client state for this protocol
|
||||
#[derive(Debug)]
|
||||
pub struct State {
|
||||
d: Scalar,
|
||||
D: RistrettoPoint,
|
||||
|
@ -48,6 +55,7 @@ pub struct State {
|
|||
}
|
||||
|
||||
/// The response message for this protocol
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Response {
|
||||
P: RistrettoPoint,
|
||||
EncQ: (RistrettoPoint, RistrettoPoint),
|
||||
|
|
|
@ -30,6 +30,8 @@ use zkp::CompactProof;
|
|||
use zkp::ProofError;
|
||||
use zkp::Transcript;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use super::super::cred;
|
||||
use super::super::dup_filter::SeenType;
|
||||
use super::super::{pt_dbl, scalar_dbl, scalar_u32};
|
||||
|
@ -41,6 +43,7 @@ use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
|
|||
/// also add bits to the zero knowledge proof.
|
||||
pub const INVITATION_EXPIRY: u32 = 15;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Request {
|
||||
// Fields for showing the Invitation credential
|
||||
P: RistrettoPoint,
|
||||
|
@ -82,6 +85,7 @@ pub struct State {
|
|||
blockages: Scalar,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Response {
|
||||
// The fields for the new Lox credential; the new trust level is 1
|
||||
// and the new invites_remaining is 0, so we don't have to include
|
||||
|
|
Loading…
Reference in New Issue