miden_lib/account/auth/no_auth.rs
1use miden_objects::account::AccountComponent;
2
3use crate::account::components::no_auth_library;
4
5/// An [`AccountComponent`] implementing a no-authentication scheme.
6///
7/// This component provides **no authentication**! It only checks if the account
8/// state has actually changed during transaction execution by comparing the initial
9/// account commitment with the current commitment and increments the nonce if
10/// they differ. This avoids unnecessary nonce increments for transactions that don't
11/// modify the account state.
12///
13/// It exports the procedure `auth_no_auth`, which:
14/// - Checks if the account state has changed by comparing initial and final commitments
15/// - Only increments the nonce if the account state has actually changed
16/// - Provides no cryptographic authentication
17///
18/// This component supports all account types.
19pub struct NoAuth;
20
21impl NoAuth {
22 /// Creates a new [`NoAuth`] component.
23 pub fn new() -> Self {
24 Self
25 }
26}
27
28impl Default for NoAuth {
29 fn default() -> Self {
30 Self::new()
31 }
32}
33
34impl From<NoAuth> for AccountComponent {
35 fn from(_: NoAuth) -> Self {
36 AccountComponent::new(no_auth_library(), vec![])
37 .expect("NoAuth component should satisfy the requirements of a valid account component")
38 .with_supports_all_types()
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use miden_objects::account::AccountBuilder;
45
46 use super::*;
47 use crate::account::wallets::BasicWallet;
48
49 #[test]
50 fn test_no_auth_component() {
51 // Create an account using the NoAuth component
52 let _account = AccountBuilder::new([0; 32])
53 .with_auth_component(NoAuth)
54 .with_component(BasicWallet)
55 .build()
56 .expect("account building failed");
57 }
58}