miden_testing/mock_chain/
auth.rs1use miden_crypto::dsa::rpo_falcon512::SecretKey;
5use miden_lib::account::auth::RpoFalcon512;
6use miden_objects::account::{AccountComponent, AuthSecretKey};
7use miden_tx::auth::BasicAuthenticator;
8use rand::SeedableRng;
9use rand_chacha::ChaCha20Rng;
10
11#[derive(Debug, Clone, Copy)]
13pub enum Auth {
14 BasicAuth,
17
18 NoAuth,
20}
21
22impl Auth {
23 pub(super) fn build_component(
26 &self,
27 ) -> Option<(AccountComponent, BasicAuthenticator<ChaCha20Rng>)> {
28 match self {
29 Auth::BasicAuth => {
30 let mut rng = ChaCha20Rng::from_seed(Default::default());
31 let sec_key = SecretKey::with_rng(&mut rng);
32 let pub_key = sec_key.public_key();
33
34 let component = RpoFalcon512::new(pub_key).into();
35
36 let authenticator = BasicAuthenticator::<ChaCha20Rng>::new_with_rng(
37 &[(pub_key.into(), AuthSecretKey::RpoFalcon512(sec_key))],
38 rng,
39 );
40
41 Some((component, authenticator))
42 },
43 Auth::NoAuth => None,
44 }
45 }
46}