You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Built-in note types from miden-standards: P2ID, P2IDE (with expiration), and SWAP (atomic exchange)."
5
5
---
6
6
7
-
# Note Types
7
+
# Standard Note Types
8
8
9
-
Miden provides built-in note patterns for common asset transfer scenarios. These are protocol primitives you can use directly or extend for custom behavior.
9
+
The `miden-standards` crate provides built-in note patterns for common asset transfer scenarios. These are pre-compiled note scripts you can use directly via the builder API in client code.
10
10
11
11
## P2ID (Pay to ID)
12
12
@@ -155,8 +155,8 @@ create_swap_note(
155
155
156
156
Returns a tuple of `(Note, NoteDetails)` — the SWAP note to submit and the expected payback note details (for tracking).
157
157
158
-
`NoteAttachment` is defined in the `miden-standards` crate (not the core `miden` SDK). It wraps the attachment data that gets set on output notes — see [note attachments](./output-notes#note-attachments) for the underlying SDK API.
158
+
`NoteAttachment` is defined in the `miden-standards` crate (not the core `miden` SDK). It wraps the attachment data that gets set on output notes — see [note attachments](../smart-contracts/notes/output-notes#note-attachments) for the underlying SDK API.
159
159
160
160
## More note types
161
161
162
-
For writing custom note scripts, see [Note Scripts](./note-scripts). For the transaction context and `#[tx_script]`, see [Transaction Context](../transactions/transaction-context). For common patterns, see [Patterns & Security](../patterns).
162
+
For writing custom note scripts, see [Note Scripts](../smart-contracts/notes/note-scripts). For the transaction context and `#[tx_script]`, see [Transaction Context](../smart-contracts/transactions/transaction-context).
description: "Query account state with active_account and mutate the vault with native_account."
4
+
description: "Query account state and mutate the vault using self methods in Miden components."
5
5
---
6
6
7
7
# Account Operations
8
8
9
-
Miden provides two modules for interacting with the current account during a transaction: `active_account` for read-only queries (balance, nonce, commitments) and `native_account` for mutations (add/remove assets, increment nonce). The split reflects the ZK proof model — `active_account` calls don't affect the proof's state transition, while `native_account` calls represent state changes that must be proven. The vault is the account's asset container where all fungible and non-fungible assets live.
9
+
The `#[component]` macro automatically provides methods on `self`for interacting with the current account during a transaction. Read-only queries are available on `&self`, and mutations (add/remove assets, increment nonce) require `&mut self`.
10
10
11
-
## `active_account` — Read-only queries
12
-
13
-
These functions query the current account's state without modifying it. They're available in both `&self` and `&mut self` methods.
14
-
15
-
```rust
16
-
usemiden::active_account;
17
-
```
18
-
19
-
### Account identity
20
-
21
-
```rust
22
-
// Get the account ID
23
-
letid:AccountId=active_account::get_id();
24
-
25
-
// Get the current nonce
26
-
letnonce:Felt=active_account::get_nonce();
27
-
```
28
-
29
-
### Vault queries
30
-
31
-
```rust
32
-
// Get fungible asset balance for a specific faucet
`add_asset`, `remove_asset`, and `incr_nonce` require `&mut self` and modify account state. `compute_delta_commitment` and `was_procedure_called` take `&self` — they are read-only queries on the native account.
77
-
78
-
```rust
79
-
usemiden::native_account;
80
-
```
81
-
82
-
### Asset operations
83
-
84
-
```rust
85
-
// Add an asset to the vault — returns the asset as stored
86
-
letstored:Asset=native_account::add_asset(asset);
87
-
88
-
// Remove an asset from the vault — returns the removed asset
89
-
// Proof generation fails if the asset doesn't exist or insufficient balance
The nonce must be incremented for any transaction that modifies account state. Without it, the same transaction could be replayed.
75
+
:::
164
76
165
77
## When proof generation fails
166
78
@@ -179,7 +91,7 @@ When proof generation fails:
179
91
3. No state changes occur
180
92
4. The client receives an error describing the failure
181
93
182
-
## ManagedWallet component
94
+
## Example: ManagedWallet
183
95
184
96
```rust
185
97
#![no_std]
@@ -210,8 +122,8 @@ impl ManagedWallet {
210
122
}
211
123
```
212
124
213
-
To move assets out of an account, create [output notes](../notes/output-notes) with `output_note::add_asset`. For signature verification and nonce management, see [Authentication](./authentication). For complete function signatures, see the [Cheatsheet](../api-reference).
125
+
To move assets out of an account, create [output notes](../notes/output-notes) with `output_note::add_asset`. For signature verification and nonce management, see [Authentication](./authentication).
214
126
215
127
:::info API Reference
216
-
Full API docs on docs.rs: [`miden::active_account`](https://docs.rs/miden/latest/miden/active_account/), [`miden::native_account`](https://docs.rs/miden/latest/miden/native_account/)
128
+
Full API docs on docs.rs: [`miden`](https://docs.rs/miden/latest/miden/)
// On the advice stack the words are expected to be in reverse order
62
+
tx_summary.reverse();
63
+
// Insert tx summary into advice map under key `msg`
64
+
adv_insert(msg, &tx_summary);
52
65
53
-
// 4. Verify the signature
54
-
// Panics if signature is invalid -> proof generation fails
55
-
rpo_falcon512_verify(pub_key, msg);
66
+
letpub_key:Word=self.owner_public_key.read();
56
67
57
-
felt!(1)
68
+
// Emit signature request event to advice stack
69
+
miden::emit_falcon_sig_to_stack(msg, pub_key);
70
+
71
+
// Verify the signature loaded on the advice stack
72
+
miden::rpo_falcon512_verify(pub_key, msg);
58
73
}
59
74
}
60
75
```
@@ -66,14 +81,11 @@ The nonce prevents replay attacks — each transaction must use a unique nonce:
66
81
```rust
67
82
// Increment and return the new nonce
68
83
letnew_nonce:Felt=self.incr_nonce();
69
-
70
-
// Or via the module function
71
-
letnew_nonce:Felt=native_account::incr_nonce();
72
84
```
73
85
74
86
The nonce is automatically included in the transaction's proof. If someone tries to replay a transaction, the nonce won't match and verification will fail.
75
87
76
-
Auth components are typically called via [cross-component calls](../cross-component-calls) from note scripts or [transaction scripts](../transactions/transaction-scripts). For access control and security patterns, see [Patterns & Security](../patterns).
88
+
Auth components are typically called via [cross-component calls](../cross-component-calls) from note scripts or [transaction scripts](../transactions/transaction-scripts). For access control and security patterns, see [Patterns](../patterns).
77
89
78
90
:::info API Reference
79
91
Full API docs on docs.rs: [`miden`](https://docs.rs/miden/latest/miden/) (`rpo_falcon512_verify`)
@@ -83,4 +95,4 @@ Full API docs on docs.rs: [`miden`](https://docs.rs/miden/latest/miden/) (`rpo_f
83
95
84
96
-[Cryptography](./cryptography) — RPO-Falcon512 verification and hashing primitives
85
97
-[Advice Provider](../transactions/advice-provider) — supplying auxiliary data during proof generation
86
-
-[Patterns & Security](../patterns) — access control, rate limiting, and anti-patterns
98
+
-[Patterns](../patterns) — access control, rate limiting, and anti-patterns
0 commit comments