Skip to main content

p47h_engine/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025 P47H Team <https://p47h.com>
3
4//! # p47h-engine
5//!
6//! Core engine for P47H with cryptographic identity management
7//! and local policy evaluation.
8//!
9//! This crate provides a complete AuthN/AuthZ solution for web applications.
10//! It is designed to be used as a library (rlib) by WASM wrappers.
11
12#![forbid(unsafe_code)]
13#![warn(missing_docs)]
14
15mod client;
16mod types;
17mod utils;
18mod validation;
19
20/// Vault cryptographic operations (encryption/decryption)
21pub mod vault;
22mod wrappers;
23
24#[allow(unused_imports)]
25use wasm_bindgen::prelude::*;
26
27// Re-export main types
28pub use client::P47hClient;
29pub use types::{AuthDecision, AuthDecisionWithProof, PolicyDiagnostic};
30pub use utils::parse_resource;
31pub use validation::{validate_policy, validate_policy_detailed};
32pub use vault::VaultCrypto;
33pub use wrappers::{WasmIdentity, WasmPolicy};
34
35// Set panic hook for better error messages in browser console
36#[cfg(feature = "console_error_panic_hook")]
37pub use console_error_panic_hook::set_once as set_panic_hook;
38
39/// Initialize the engine (sets panic hook for debugging).
40/// This should be called by the WASM wrapper, not directly.
41pub fn init_engine() {
42    #[cfg(feature = "console_error_panic_hook")]
43    set_panic_hook();
44}