From 33f158bd3d35ad31acf15d300cbe86345ce1c2b1 Mon Sep 17 00:00:00 2001 From: Philipp Gackstatter Date: Thu, 7 Nov 2024 14:57:37 +0100 Subject: [PATCH] feat(lib): Expose component libraries in `library` method --- miden-lib/src/accounts/auth/mod.rs | 10 ++++++++++ miden-lib/src/accounts/components/mod.rs | 6 +++--- miden-lib/src/accounts/faucets/mod.rs | 10 ++++++++++ miden-lib/src/accounts/mod.rs | 2 +- miden-lib/src/accounts/wallets/mod.rs | 12 ++++++++++++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/miden-lib/src/accounts/auth/mod.rs b/miden-lib/src/accounts/auth/mod.rs index 8a5d7c8c1..5f2a961ea 100644 --- a/miden-lib/src/accounts/auth/mod.rs +++ b/miden-lib/src/accounts/auth/mod.rs @@ -1,5 +1,6 @@ use miden_objects::{ accounts::{AccountComponent, StorageSlot}, + assembly::Library, crypto::dsa::rpo_falcon512::PublicKey, }; @@ -22,6 +23,15 @@ impl RpoFalcon512 { pub fn new(public_key: PublicKey) -> Self { Self { public_key } } + + /// Returns a reference to the RPO Falcon 512 library whose procedures can be imported from + /// `account_components::rpo_falcon_512`. + /// + /// This can be used in the assembly of programs that want to call procedures from this + /// component. + pub fn library() -> &'static Library { + rpo_falcon_512_library() + } } impl From for AccountComponent { diff --git a/miden-lib/src/accounts/components/mod.rs b/miden-lib/src/accounts/components/mod.rs index f0ec5a934..fec4be142 100644 --- a/miden-lib/src/accounts/components/mod.rs +++ b/miden-lib/src/accounts/components/mod.rs @@ -26,17 +26,17 @@ static BASIC_FUNGIBLE_FAUCET_LIBRARY: LazyLock = LazyLock::new(|| { Library::read_from_bytes(bytes).expect("Shipped Basic Fungible Faucet library is well-formed") }); -/// Returns the Basic Wallet Library. +/// Returns a reference to the Basic Wallet Library. pub fn basic_wallet_library() -> &'static Library { BASIC_WALLET_LIBRARY.as_ref() } -/// Returns the Rpo Falcon 512 Library. +/// Returns a reference to the Rpo Falcon 512 Library. pub fn rpo_falcon_512_library() -> &'static Library { RPO_FALCON_512_LIBRARY.as_ref() } -/// Returns the Basic Fungible Faucet Library. +/// Returns a reference to the Basic Fungible Faucet Library. pub fn basic_fungible_faucet_library() -> &'static Library { BASIC_FUNGIBLE_FAUCET_LIBRARY.as_ref() } diff --git a/miden-lib/src/accounts/faucets/mod.rs b/miden-lib/src/accounts/faucets/mod.rs index 3c9d00dd1..21e65576e 100644 --- a/miden-lib/src/accounts/faucets/mod.rs +++ b/miden-lib/src/accounts/faucets/mod.rs @@ -4,6 +4,7 @@ use miden_objects::{ accounts::{ Account, AccountBuilder, AccountComponent, AccountStorageMode, AccountType, StorageSlot, }, + assembly::Library, assets::TokenSymbol, AccountError, Felt, FieldElement, Word, }; @@ -47,6 +48,15 @@ impl BasicFungibleFaucet { Ok(Self { symbol, decimals, max_supply }) } + + /// Returns a reference to the Basic Fungible Faucet library whose procedures can be imported + /// from `account_components::basic_fungible_faucet`. + /// + /// This can be used in the assembly of programs that want to call procedures from this + /// component. + pub fn library() -> &'static Library { + basic_fungible_faucet_library() + } } impl From for AccountComponent { diff --git a/miden-lib/src/accounts/mod.rs b/miden-lib/src/accounts/mod.rs index 6ec9777ce..d1141e765 100644 --- a/miden-lib/src/accounts/mod.rs +++ b/miden-lib/src/accounts/mod.rs @@ -1,6 +1,6 @@ use super::auth::AuthScheme; pub mod auth; -pub(super) mod components; +pub mod components; pub mod faucets; pub mod wallets; diff --git a/miden-lib/src/accounts/wallets/mod.rs b/miden-lib/src/accounts/wallets/mod.rs index aee8bda88..1d14f40f4 100644 --- a/miden-lib/src/accounts/wallets/mod.rs +++ b/miden-lib/src/accounts/wallets/mod.rs @@ -2,6 +2,7 @@ use alloc::string::ToString; use miden_objects::{ accounts::{Account, AccountBuilder, AccountComponent, AccountStorageMode, AccountType}, + assembly::Library, AccountError, Word, }; @@ -25,6 +26,17 @@ use crate::accounts::{auth::RpoFalcon512, components::basic_wallet_library}; /// This component supports all account types. pub struct BasicWallet; +impl BasicWallet { + /// Returns a reference to the Basic Wallet library whose procedures can be imported from + /// `account_components::basic_wallet`. + /// + /// This can be used in the assembly of programs that want to call procedures from this + /// component. + pub fn library() -> &'static Library { + basic_wallet_library() + } +} + impl From for AccountComponent { fn from(_: BasicWallet) -> Self { AccountComponent::new(basic_wallet_library().clone(), vec![])