Add hash of bucket as type of proof of bridge knowledge
This commit is contained in:
parent
e153d58fd2
commit
086e1a6a70
26
src/lib.rs
26
src/lib.rs
|
@ -1,6 +1,6 @@
|
|||
use curve25519_dalek::scalar::Scalar;
|
||||
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
|
||||
use lox_library::bridge_table::BridgeLine;
|
||||
use lox_library::bridge_table::{BridgeLine, MAX_BRIDGES_PER_BUCKET};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha1::{Digest, Sha1};
|
||||
use sha3::Sha3_256;
|
||||
|
@ -33,11 +33,24 @@ pub fn get_bridge_signing_pubkey(fingerprint: &[u8; 20]) -> VerifyingKey {
|
|||
keypair.verifying_key()
|
||||
}
|
||||
|
||||
/// Get bucket from hash of bucket ID, requires some oracle
|
||||
pub fn get_bucket(beta_hash: &[u8; 32]) -> [BridgeLine; MAX_BRIDGES_PER_BUCKET] {
|
||||
// TODO
|
||||
// for now just return bucket of empty bridgelines
|
||||
[
|
||||
BridgeLine::default(),
|
||||
BridgeLine::default(),
|
||||
BridgeLine::default(),
|
||||
]
|
||||
}
|
||||
|
||||
/// Proof that the user knows (and should be able to access) a given bridge
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum ProofOfBridgeKnowledge {
|
||||
/// Hash of bridge line as proof of knowledge of bridge line
|
||||
HashOfBridgeLine { hash: [u8; 32] },
|
||||
/// Hash of bucket ID for Lox user
|
||||
HashOfBucket { hash: [u8; 32] },
|
||||
}
|
||||
|
||||
impl ProofOfBridgeKnowledge {
|
||||
|
@ -50,6 +63,17 @@ impl ProofOfBridgeKnowledge {
|
|||
let bl_hash: [u8; 32] = hasher.finalize().into();
|
||||
hash == &bl_hash
|
||||
}
|
||||
ProofOfBridgeKnowledge::HashOfBucket { ref hash } => {
|
||||
let bucket = get_bucket(&hash);
|
||||
for bl in bucket {
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.update(bl.uid_fingerprint.to_le_bytes());
|
||||
if fingerprint == <[u8; 20]>::from(hasher.finalize()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue