| Crates.io | miden-protocol-macros |
| lib.rs | miden-protocol-macros |
| version | 0.13.2 |
| created_at | 2026-01-17 07:41:42.041567+00 |
| updated_at | 2026-01-22 08:42:22.350345+00 |
| description | Procedural macros for Miden protocol |
| homepage | https://miden.xyz |
| repository | https://github.com/0xMiden/miden-base |
| max_upload_size | |
| id | 2050099 |
| size | 12,809 |
A collection of procedural macros for the Miden protocol.
The WordWrapper derive macro automatically implements helpful accessor methods and conversions for tuple structs that wrap a Word type.
Add the derive macro to any tuple struct with a single Word field:
use miden_protocol_macros::WordWrapper;
use miden_crypto::word::Word;
#[derive(WordWrapper)]
pub struct NoteId(Word);
The macro automatically generates the following methods:
new_unchecked(Word) -> Self - Construct without any checksas_elements(&self) -> &[Felt] - Returns the elements representation of the wrapped Wordas_bytes(&self) -> [u8; 32] - Returns the byte representationto_hex(&self) -> String - Returns a big-endian, hex-encoded stringas_word(&self) -> Word - Returns the underlying Word valueuse miden_protocol_macros::WordWrapper;
use miden_crypto::word::Word;
#[derive(Debug, Clone, Copy, PartialEq, Eq, WordWrapper)]
pub struct NoteId(Word);
// Create using new_unchecked (generated by the macro)
let word = Word::from([Felt::ONE, Felt::ZERO, Felt::ONE, Felt::ZERO]);
let note_id = NoteId::from_raw(word);
// Use accessor methods
let elements = note_id.as_elements();
let bytes = note_id.as_bytes();
let hex = note_id.to_hex();
let word_back = note_id.as_word();
The macro can only be applied to:
struct Foo(Word))WordUsing this macro eliminates boilerplate code. Instead of manually writing ~50 lines of implementation code for each Word wrapper type, you can simply add #[derive(WordWrapper)] to your struct definition.
This is particularly useful in the Miden codebase where many types like NoteId, TransactionId, Nullifier, BatchId, etc. all follow the same pattern of wrapping a Word and providing similar accessor methods.
new_unchecked constructor. You should not manually implement this method.From<T> and From<&T> trait implementations for Word and [u8; 32]. These have been removed to give types more control over their conversions. If you need these conversions, implement them manually for your specific type.