1#![no_std]
2
3use alloc::sync::Arc;
4
5#[macro_use]
6extern crate alloc;
7
8#[cfg(feature = "std")]
9extern crate std;
10
11use miden_objects::{
12 assembly::{Library, mast::MastForest},
13 utils::{serde::Deserializable, sync::LazyLock},
14};
15
16mod auth;
17pub use auth::AuthScheme;
18
19pub mod account;
20pub mod errors;
21pub mod note;
22pub mod transaction;
23pub mod utils;
24
25pub use miden_stdlib::StdLibrary;
28
29const MIDEN_LIB_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/assets/miden.masl"));
33
34#[derive(Clone)]
38pub struct MidenLib(Library);
39
40impl MidenLib {
41 pub fn mast_forest(&self) -> &Arc<MastForest> {
43 self.0.mast_forest()
44 }
45}
46
47impl AsRef<Library> for MidenLib {
48 fn as_ref(&self) -> &Library {
49 &self.0
50 }
51}
52
53impl From<MidenLib> for Library {
54 fn from(value: MidenLib) -> Self {
55 value.0
56 }
57}
58
59impl Default for MidenLib {
60 fn default() -> Self {
61 static MIDEN_LIB: LazyLock<MidenLib> = LazyLock::new(|| {
62 let contents =
63 Library::read_from_bytes(MIDEN_LIB_BYTES).expect("failed to read miden lib masl!");
64 MidenLib(contents)
65 });
66 MIDEN_LIB.clone()
67 }
68}
69
70#[cfg(all(test, feature = "std"))]
75mod tests {
76 use miden_objects::assembly::LibraryPath;
77
78 use super::MidenLib;
79
80 #[test]
81 fn test_compile() {
82 let path = "miden::account::get_id".parse::<LibraryPath>().unwrap();
83 let miden = MidenLib::default();
84 let exists = miden.0.module_infos().any(|module| {
85 module
86 .procedures()
87 .any(|(_, proc)| module.path().clone().append(&proc.name).unwrap() == path)
88 });
89
90 assert!(exists);
91 }
92}