miden_standards/account/wallets/note_creator.rs
1use miden_protocol::account::component::{AccountComponentCode, AccountComponentMetadata};
2use miden_protocol::account::{AccountComponent, AccountComponentName, AccountProcedureRoot};
3
4use crate::account::account_component_code;
5use crate::procedure_root;
6
7// NOTE CREATOR
8// ================================================================================================
9
10account_component_code!(NOTE_CREATOR_CODE, "miden-standards-wallets-note-creator.masp");
11
12// PROCEDURE ROOTS
13// ================================================================================================
14
15/// MASL library namespace used for procedure-root lookups. Distinct from [`NoteCreator::NAME`],
16/// which mirrors the standards-side MASM module path.
17const NOTE_CREATOR_LIBRARY_PATH: &str = "miden::standards::components::wallets::note_creator";
18
19// Initialize the procedure root of the `create_note` procedure of the Note Creator only once.
20procedure_root!(
21 NOTE_CREATOR_CREATE_NOTE,
22 NOTE_CREATOR_LIBRARY_PATH,
23 NoteCreator::CREATE_NOTE_PROC_NAME,
24 NoteCreator::code()
25);
26
27/// An [`AccountComponent`] exposing only the `create_note` procedure.
28///
29/// When linking against this component, the `miden` library (i.e.
30/// [`ProtocolLib`](miden_protocol::ProtocolLib)) must be available to the assembler which is the
31/// case when using [`CodeBuilder`][builder].
32///
33/// `create_note` requires authentication. Thus, this component must be combined with a component
34/// providing authentication.
35///
36/// [builder]: crate::code_builder::CodeBuilder
37pub struct NoteCreator;
38
39impl NoteCreator {
40 // CONSTANTS
41 // --------------------------------------------------------------------------------------------
42
43 /// The name of the component.
44 pub const NAME: &'static str = "miden::standards::note::note_creator";
45
46 const CREATE_NOTE_PROC_NAME: &str = "create_note";
47
48 /// Returns the canonical [`AccountComponentName`] of this component.
49 pub const fn name() -> AccountComponentName {
50 AccountComponentName::from_static_str(Self::NAME)
51 }
52
53 // PUBLIC ACCESSORS
54 // --------------------------------------------------------------------------------------------
55
56 /// Returns the [`AccountComponentCode`] of this component.
57 pub fn code() -> &'static AccountComponentCode {
58 &NOTE_CREATOR_CODE
59 }
60
61 /// Returns the procedure root of the `create_note` procedure.
62 pub fn create_note_root() -> AccountProcedureRoot {
63 *NOTE_CREATOR_CREATE_NOTE
64 }
65
66 /// Returns the [`AccountComponentMetadata`] for this component.
67 pub fn component_metadata() -> AccountComponentMetadata {
68 AccountComponentMetadata::new(Self::NAME)
69 .with_description("Note creator component exposing only the create_note procedure")
70 }
71}
72
73impl From<NoteCreator> for AccountComponent {
74 fn from(_: NoteCreator) -> Self {
75 let metadata = NoteCreator::component_metadata();
76
77 AccountComponent::new(NoteCreator::code().clone(), vec![], metadata).expect(
78 "note creator component should satisfy the requirements of a valid account component",
79 )
80 }
81}