Skip to main content

miden_standards/account/auth/
no_auth.rs

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