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