Skip to content

Commit

Permalink
feat: add test func for otp gen
Browse files Browse the repository at this point in the history
  • Loading branch information
driemworks committed Oct 28, 2024
1 parent 27e570a commit 93a66ca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
rand_core = { version = "0.6.4", default-features = false }
ark-ec = { version = "0.4", default-features = false }
ark-serialize = { version = "0.4.0", default-features = false }
ark-std = { version = "0.4", default-features = false }
w3f-bls = { version = "0.1.3", default-features = false }
murmur-core = { package = "murmur-core", path = "../core/", features = ["client"] }
dleq_vrf = { git = "https://github.com/w3f/ring-vrf.git", default-features = false, features = ["getrandom"]}

[features]
default = ["std"]
std = [
"ark-ec/std",
"ark-serialize/std",
"ark-std/std",
"w3f-bls/std",
"murmur-core/std",
"dleq_vrf/std",
]
no_std = []
22 changes: 21 additions & 1 deletion test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,35 @@
use alloc::vec::Vec;
use ark_serialize::CanonicalSerialize;
use ark_std::rand::{CryptoRng, Rng};
use rand_core::OsRng;
use w3f_bls::{DoublePublicKey, DoublePublicKeyScheme, TinyBLS377};
use ark_ec::CurveGroup;
use w3f_bls::{DoublePublicKey, DoublePublicKeyScheme, EngineBLS, TinyBLS377};
use dleq_vrf::SecretKey;

extern crate alloc;

pub use murmur_core::otp::BOTPGenerator;

pub use murmur_core::murmur::MurmurStore;

pub use murmur_core::murmur::generate_witness;

pub fn otp<E: EngineBLS, R: Rng + CryptoRng + Sized>(
seed: Vec<u8>,
when: u64,
rng: &mut R
) -> Vec<u8> {
let witness = generate_witness(seed.clone(), rng);
let secret_key =
SecretKey::<<E::SignatureGroup as CurveGroup>::Affine>::from_seed(&witness);
let pubkey = secret_key.as_publickey();
let mut pubkey_bytes = Vec::new();
pubkey.serialize_compressed(&mut pubkey_bytes).unwrap();
let totp = BOTPGenerator::new(witness.to_vec()).unwrap();
totp.generate(when).as_bytes().to_vec()
}

pub fn get_dummy_beacon_pubkey() -> Vec<u8> {
let keypair = w3f_bls::KeypairVT::<TinyBLS377>::generate(&mut OsRng);
let double_public: DoublePublicKey<TinyBLS377> =
Expand Down

0 comments on commit 93a66ca

Please sign in to comment.