Skip to main content

confium_wasm/
lib.rs

1//! Browser/Node.js **verifier** package for Confium.
2//!
3//! wasm-bindgen surface, `wasm32-unknown-unknown` target, verifier-only by
4//! design. Browsers verify; servers sign.
5//!
6//! Each subsystem is gated by a `verify-*` Cargo feature so consumers can
7//! tree-shake aggressively. All features are on by default for out-of-the-box
8//! ergonomics.
9
10#![forbid(unsafe_code)]
11#![allow(missing_docs)] // TODO: document before 1.0
12#![allow(rustdoc::broken_intra_doc_links)]
13#![allow(rustdoc::bare_urls)]
14#![allow(rustdoc::redundant_explicit_links)]
15#![allow(rustdoc::private_intra_doc_links)]
16#![allow(rustdoc::invalid_html_tags)]
17
18use wasm_bindgen::prelude::*;
19
20#[cfg(feature = "verify-composite")]
21mod composite;
22
23#[cfg(feature = "verify-composite")]
24pub use composite::{CompositeSignature, CompositeVerificationResult};
25
26#[cfg(feature = "verify-transparency")]
27mod transparency;
28
29#[cfg(feature = "verify-transparency")]
30pub use transparency::{
31    InclusionProof, MerkleTree, compute_artifact_hash, compute_leaf_hash, tree_head_from_json,
32    verify_inclusion_with_head,
33};
34
35#[cfg(feature = "verify-attributes")]
36mod attributes;
37
38#[cfg(feature = "verify-attributes")]
39pub use attributes::Predicate;
40
41#[cfg(feature = "verify-signatif")]
42pub mod signatif;
43
44#[cfg(feature = "verify-pki")]
45mod pki;
46
47#[cfg(feature = "verify-pki")]
48pub use pki::{Certificate, SignedData};
49
50#[cfg(feature = "sign")]
51mod signer;
52
53#[cfg(feature = "sign")]
54pub use signer::{Cmp20Signer, Gg18Signer};
55
56/// Package version (mirrors the Cargo version).
57#[wasm_bindgen]
58pub fn version() -> String {
59    env!("CARGO_PKG_VERSION").to_string()
60}
61
62/// Confium-core crate version this WASM blob was built against.
63#[wasm_bindgen]
64pub fn core_version() -> String {
65    "0.2.0".to_string()
66}
67
68/// Canonicalize XML per RFC 3076 (Canonical XML 1.0).
69#[cfg(feature = "verify-pki")]
70#[wasm_bindgen]
71pub fn canonicalize_xml(xml: &str) -> Result<String, JsValue> {
72    confium_pki::xmldsig::canonicalize(xml).map_err(|e| JsValue::from_str(&e.to_string()))
73}
74
75/// Canonicalize XML per Exclusive C14N (RFC 3741).
76#[cfg(feature = "verify-pki")]
77#[wasm_bindgen]
78pub fn canonicalize_exclusive_xml(xml: &str) -> Result<String, JsValue> {
79    confium_pki::xmldsig::canonicalize_exclusive(xml).map_err(|e| JsValue::from_str(&e.to_string()))
80}