Skip to content

Commit

Permalink
feat(lib): Expose component libraries in library method
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Nov 7, 2024
1 parent 84330a2 commit 33f158b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
10 changes: 10 additions & 0 deletions miden-lib/src/accounts/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use miden_objects::{
accounts::{AccountComponent, StorageSlot},
assembly::Library,
crypto::dsa::rpo_falcon512::PublicKey,
};

Expand All @@ -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<RpoFalcon512> for AccountComponent {
Expand Down
6 changes: 3 additions & 3 deletions miden-lib/src/accounts/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ static BASIC_FUNGIBLE_FAUCET_LIBRARY: LazyLock<Library> = 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()
}
Expand Down
10 changes: 10 additions & 0 deletions miden-lib/src/accounts/faucets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use miden_objects::{
accounts::{
Account, AccountBuilder, AccountComponent, AccountStorageMode, AccountType, StorageSlot,
},
assembly::Library,
assets::TokenSymbol,
AccountError, Felt, FieldElement, Word,
};
Expand Down Expand Up @@ -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<BasicFungibleFaucet> for AccountComponent {
Expand Down
2 changes: 1 addition & 1 deletion miden-lib/src/accounts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::auth::AuthScheme;

pub mod auth;
pub(super) mod components;
pub mod components;
pub mod faucets;
pub mod wallets;
12 changes: 12 additions & 0 deletions miden-lib/src/accounts/wallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use alloc::string::ToString;

use miden_objects::{
accounts::{Account, AccountBuilder, AccountComponent, AccountStorageMode, AccountType},
assembly::Library,
AccountError, Word,
};

Expand All @@ -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<BasicWallet> for AccountComponent {
fn from(_: BasicWallet) -> Self {
AccountComponent::new(basic_wallet_library().clone(), vec![])
Expand Down

0 comments on commit 33f158b

Please sign in to comment.