miden_standards/account/interface/component.rs
1use alloc::string::{String, ToString};
2use alloc::vec::Vec;
3
4use miden_protocol::account::AccountProcedureRoot;
5
6// ACCOUNT COMPONENT INTERFACE
7// ================================================================================================
8
9/// The enum holding all possible account interfaces which could be loaded to some account.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum AccountComponentInterface {
12 /// Exposes procedures from the [`BasicWallet`][crate::account::wallets::BasicWallet] module.
13 BasicWallet,
14 /// Exposes the `create_note` procedure from the
15 /// [`NoteCreator`][crate::account::wallets::NoteCreator] component.
16 NoteCreator,
17 /// Exposes procedures from the
18 /// [`FungibleFaucet`][crate::account::faucets::FungibleFaucet] module.
19 FungibleFaucet,
20 /// Exposes procedures from the
21 /// [`CodeInspection`][crate::account::inspection::CodeInspection] component.
22 CodeInspection,
23 /// Exposes procedures from the
24 /// [`Authority`][crate::account::access::Authority] access component.
25 Authority,
26 /// Exposes procedures from the
27 /// [`Ownable2Step`][crate::account::access::Ownable2Step] access component.
28 Ownable2Step,
29 /// Exposes procedures from the
30 /// [`RoleBasedAccessControl`][crate::account::access::RoleBasedAccessControl] access
31 /// component.
32 RoleBasedAccessControl,
33 /// Exposes procedures from the
34 /// [`AuthSingleSig`][crate::account::auth::AuthSingleSig] module.
35 AuthSingleSig,
36 /// Exposes procedures from the
37 /// [`AuthMultisig`][crate::account::auth::AuthMultisig] module.
38 AuthMultisig,
39 /// Exposes procedures from the
40 /// [`AuthMultisigSmart`][crate::account::auth::AuthMultisigSmart] module.
41 AuthMultisigSmart,
42 /// Exposes procedures from the
43 /// [`AuthGuardedMultisig`][crate::account::auth::AuthGuardedMultisig] module.
44 AuthGuardedMultisig,
45 /// Exposes procedures from the [`NoAuth`][crate::account::auth::NoAuth] module.
46 ///
47 /// This authentication scheme provides no cryptographic authentication and only increments
48 /// the nonce if the account state has actually changed during transaction execution.
49 AuthNoAuth,
50 /// Exposes procedures from the
51 /// [`AuthNetworkAccount`][crate::account::auth::AuthNetworkAccount] module.
52 ///
53 /// This authentication scheme is intended for network-owned accounts. It rejects transactions
54 /// that executed a tx script or consumed input notes outside of a fixed allowlist of note
55 /// script roots.
56 AuthNetworkAccount,
57 /// A non-standard, custom interface which exposes the contained procedures.
58 ///
59 /// Custom interface holds all procedures which are not part of some standard interface which is
60 /// used by this account.
61 Custom(Vec<AccountProcedureRoot>),
62}
63
64impl AccountComponentInterface {
65 /// Returns a string line with the name of the [AccountComponentInterface] enum variant.
66 ///
67 /// In case of a [AccountComponentInterface::Custom] along with the name of the enum variant
68 /// the vector of shortened hex representations of the used procedures is returned, e.g.
69 /// `Custom([0x6d93447, 0x0bf23d8])`.
70 pub fn name(&self) -> String {
71 match self {
72 AccountComponentInterface::BasicWallet => "Basic Wallet".to_string(),
73 AccountComponentInterface::NoteCreator => "Note Creator".to_string(),
74 AccountComponentInterface::FungibleFaucet => "Fungible Faucet".to_string(),
75 AccountComponentInterface::CodeInspection => "Code Inspection".to_string(),
76 AccountComponentInterface::Authority => "Authority".to_string(),
77 AccountComponentInterface::Ownable2Step => "Ownable2Step".to_string(),
78 AccountComponentInterface::RoleBasedAccessControl => {
79 "Role Based Access Control".to_string()
80 },
81 AccountComponentInterface::AuthSingleSig => "SingleSig".to_string(),
82 AccountComponentInterface::AuthMultisig => "Multisig".to_string(),
83 AccountComponentInterface::AuthMultisigSmart => "Multisig Smart".to_string(),
84 AccountComponentInterface::AuthGuardedMultisig => "Guarded Multisig".to_string(),
85 AccountComponentInterface::AuthNoAuth => "No Auth".to_string(),
86 AccountComponentInterface::AuthNetworkAccount => "Network Account Auth".to_string(),
87 AccountComponentInterface::Custom(proc_root_vec) => {
88 let result = proc_root_vec
89 .iter()
90 .map(|proc_root| proc_root.mast_root().to_hex()[..9].to_string())
91 .collect::<Vec<_>>()
92 .join(", ");
93 format!("Custom([{result}])")
94 },
95 }
96 }
97
98 /// Returns true if this component interface is an authentication component.
99 ///
100 /// TODO: currently this can identify only standard auth components
101 pub fn is_auth_component(&self) -> bool {
102 matches!(
103 self,
104 AccountComponentInterface::AuthSingleSig
105 | AccountComponentInterface::AuthMultisig
106 | AccountComponentInterface::AuthMultisigSmart
107 | AccountComponentInterface::AuthGuardedMultisig
108 | AccountComponentInterface::AuthNoAuth
109 | AccountComponentInterface::AuthNetworkAccount
110 )
111 }
112}