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 /// [`AuthSingleSigAcl`][crate::account::auth::AuthSingleSigAcl] module.
38 AuthSingleSigAcl,
39 /// Exposes procedures from the
40 /// [`AuthMultisig`][crate::account::auth::AuthMultisig] module.
41 AuthMultisig,
42 /// Exposes procedures from the
43 /// [`AuthMultisigSmart`][crate::account::auth::AuthMultisigSmart] module.
44 AuthMultisigSmart,
45 /// Exposes procedures from the
46 /// [`AuthGuardedMultisig`][crate::account::auth::AuthGuardedMultisig] module.
47 AuthGuardedMultisig,
48 /// Exposes procedures from the [`NoAuth`][crate::account::auth::NoAuth] module.
49 ///
50 /// This authentication scheme provides no cryptographic authentication and only increments
51 /// the nonce if the account state has actually changed during transaction execution.
52 AuthNoAuth,
53 /// Exposes procedures from the
54 /// [`AuthNetworkAccount`][crate::account::auth::AuthNetworkAccount] module.
55 ///
56 /// This authentication scheme is intended for network-owned accounts. It rejects transactions
57 /// that executed a tx script or consumed input notes outside of a fixed allowlist of note
58 /// script roots.
59 AuthNetworkAccount,
60 /// A non-standard, custom interface which exposes the contained procedures.
61 ///
62 /// Custom interface holds all procedures which are not part of some standard interface which is
63 /// used by this account.
64 Custom(Vec<AccountProcedureRoot>),
65}
66
67impl AccountComponentInterface {
68 /// Returns a string line with the name of the [AccountComponentInterface] enum variant.
69 ///
70 /// In case of a [AccountComponentInterface::Custom] along with the name of the enum variant
71 /// the vector of shortened hex representations of the used procedures is returned, e.g.
72 /// `Custom([0x6d93447, 0x0bf23d8])`.
73 pub fn name(&self) -> String {
74 match self {
75 AccountComponentInterface::BasicWallet => "Basic Wallet".to_string(),
76 AccountComponentInterface::NoteCreator => "Note Creator".to_string(),
77 AccountComponentInterface::FungibleFaucet => "Fungible Faucet".to_string(),
78 AccountComponentInterface::CodeInspection => "Code Inspection".to_string(),
79 AccountComponentInterface::Authority => "Authority".to_string(),
80 AccountComponentInterface::Ownable2Step => "Ownable2Step".to_string(),
81 AccountComponentInterface::RoleBasedAccessControl => {
82 "Role Based Access Control".to_string()
83 },
84 AccountComponentInterface::AuthSingleSig => "SingleSig".to_string(),
85 AccountComponentInterface::AuthSingleSigAcl => "SingleSig ACL".to_string(),
86 AccountComponentInterface::AuthMultisig => "Multisig".to_string(),
87 AccountComponentInterface::AuthMultisigSmart => "Multisig Smart".to_string(),
88 AccountComponentInterface::AuthGuardedMultisig => "Guarded Multisig".to_string(),
89 AccountComponentInterface::AuthNoAuth => "No Auth".to_string(),
90 AccountComponentInterface::AuthNetworkAccount => "Network Account Auth".to_string(),
91 AccountComponentInterface::Custom(proc_root_vec) => {
92 let result = proc_root_vec
93 .iter()
94 .map(|proc_root| proc_root.mast_root().to_hex()[..9].to_string())
95 .collect::<Vec<_>>()
96 .join(", ");
97 format!("Custom([{result}])")
98 },
99 }
100 }
101
102 /// Returns true if this component interface is an authentication component.
103 ///
104 /// TODO: currently this can identify only standard auth components
105 pub fn is_auth_component(&self) -> bool {
106 matches!(
107 self,
108 AccountComponentInterface::AuthSingleSig
109 | AccountComponentInterface::AuthSingleSigAcl
110 | AccountComponentInterface::AuthMultisig
111 | AccountComponentInterface::AuthMultisigSmart
112 | AccountComponentInterface::AuthGuardedMultisig
113 | AccountComponentInterface::AuthNoAuth
114 | AccountComponentInterface::AuthNetworkAccount
115 )
116 }
117}