Skip to main content

miden_standards/account/auth/
no_auth.rs

1use miden_protocol::account::component::AccountComponentMetadata;
2use miden_protocol::account::{AccountComponent, AccountType};
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::standards::components::auth::no_auth";
25
26    /// Creates a new [`NoAuth`] component.
27    pub fn new() -> Self {
28        Self
29    }
30
31    /// Returns the [`AccountComponentMetadata`] for this component.
32    pub fn component_metadata() -> AccountComponentMetadata {
33        AccountComponentMetadata::new(Self::NAME, AccountType::all())
34            .with_description("No authentication component")
35    }
36}
37
38impl Default for NoAuth {
39    fn default() -> Self {
40        Self::new()
41    }
42}
43
44impl From<NoAuth> for AccountComponent {
45    fn from(_: NoAuth) -> Self {
46        let metadata = NoAuth::component_metadata();
47
48        AccountComponent::new(no_auth_library(), vec![], metadata)
49            .expect("NoAuth component should satisfy the requirements of a valid account component")
50    }
51}
52
53// TESTS
54// ================================================================================================
55
56#[cfg(test)]
57mod tests {
58    use miden_protocol::account::AccountBuilder;
59
60    use super::*;
61    use crate::account::wallets::BasicWallet;
62
63    #[test]
64    fn test_no_auth_component() {
65        // Create an account using the NoAuth component
66        let _account = AccountBuilder::new([0; 32])
67            .with_auth_component(NoAuth)
68            .with_component(BasicWallet)
69            .build()
70            .expect("account building failed");
71    }
72}