Skip to main content

boundary_compiler/
lib.rs

1//! boundary-compiler — RFC 8785 JCS with boundary profiles and duplicate-key rejection.
2//!
3//! # Overview
4//!
5//! This crate implements [RFC 8785](https://www.rfc-editor.org/rfc/rfc8785.html) — JSON Canonicalization Scheme (JCS):
6//!
7//! - Canonicalizer that serializes JSON into deterministic byte sequences
8//! - Duplicate-key rejection (RFC 8785 mandates duplicate object keys are errors)
9//! - blake3 Content-Digest of the JCS string
10//! - Boundary profiles with enforced byte, node, depth, and container ceilings
11//! - Fail-closed schema admission when no validator/schema is configured
12//!
13//! # Integration
14//!
15//! This crate is intended to replace `semantic_memory::graph::canonical_json_string()`
16//! with a standards-compliant JCS implementation.
17//!
18//! # Example
19//!
20//! ```rust
21//! use boundary_compiler::{Canonicalizer, ContentDigest, BoundaryProfile};
22//! use serde_json::json;
23//!
24//! let c = Canonicalizer::new();
25//! let val = json!({"b": 2, "a": 1});
26//! let canonical = c.canonicalize(&val).unwrap();
27//! assert_eq!(canonical, r#"{"a":1,"b":2}"#);
28//!
29//! let digest = ContentDigest::compute(&val).unwrap();
30//! println!("Digest: {}", digest);
31//! ```
32//!
33//! # Error handling
34//!
35//! All fallible operations use `thiserror` errors — no `unwrap()` or `expect()` in production.
36//! Duplicate keys return `JcsError::DuplicateKey`, and schema validation failures return
37//! `JcsError::SchemaValidation`.
38
39pub mod canonicalizer;
40pub mod digest;
41pub mod error;
42pub mod profile;
43pub mod schema;
44
45pub use canonicalizer::{
46    canonicalize_flexible, parse_and_validate, parse_with_dup_check, Canonicalizer,
47};
48pub use digest::{
49    ContentDigest, DigestMetadata, CANONICALIZATION_PROFILE, CANONICAL_JSON_DOMAIN,
50    DEFAULT_SCHEMA_ID, DEFAULT_SCHEMA_VERSION, DIGEST_ALGORITHM,
51};
52pub use error::JcsError;
53pub use profile::{
54    BoundaryAdmission, BoundaryEnforcementReceipt, BoundaryProfile, EnforcedRule, ResourceCeilings,
55};
56pub use schema::SchemaValidator;