Skip to main content

agentstategraph_policy_sign/
lib.rs

1//! Ed25519 signing and verification for AgentStateGraph policies.
2//!
3//! This crate is an **opt-in sibling** of `agentstategraph-policy`.
4//! Consumers that never sign policies (the common case in 0.7.x)
5//! don't pay the `ed25519-dalek` / `sha2` compile-time cost. §2c of
6//! the 0.7.5 plan wires the types exposed here into the MCP server.
7//!
8//! # Layering
9//!
10//! - [`canonicalize`] produces the deterministic UTF-8 byte
11//!   representation of a `Policy` that is fed to the signer and
12//!   verifier. The `signature` field is stripped before serialization
13//!   so sign/verify round-trip cleanly once §2b adds the field.
14//! - [`PolicySigner`] / [`Ed25519Signer`] produces
15//!   `(signer_key_id, 64-byte signature)` over those bytes.
16//! - [`PolicyVerifier`] / [`Ed25519Verifier`] checks such a pair
17//!   against a [`KeyRegistry`] lookup.
18//!
19//! # Canonical-JSON spec choice
20//!
21//! This crate uses "sorted keys + no whitespace + UTF-8" rather than
22//! full RFC 8785 JCS. Policy values never contain `f64` fields today,
23//! so the extra IEEE-754 canonicalization JCS requires is pure
24//! overhead. See [`canonical`] for the full contract.
25
26mod canonical;
27mod error;
28mod keys;
29mod signer;
30mod verifier;
31
32pub use canonical::{canonicalize, canonicalize_value};
33pub use error::{SignError, VerifyError};
34pub use keys::{InMemoryKeyRegistry, KeyRegistry};
35pub use signer::{Ed25519Signer, PolicySigner};
36pub use verifier::{Ed25519Verifier, PolicyVerifier};