Skip to main content

Crate agentstategraph_policy_sign

Crate agentstategraph_policy_sign 

Source
Expand description

Ed25519 signing and verification for AgentStateGraph policies.

This crate is an opt-in sibling of agentstategraph-policy. Consumers that never sign policies (the common case in 0.7.x) don’t pay the ed25519-dalek / sha2 compile-time cost. §2c of the 0.7.5 plan wires the types exposed here into the MCP server.

§Layering

  • canonicalize produces the deterministic UTF-8 byte representation of a Policy that is fed to the signer and verifier. The signature field is stripped before serialization so sign/verify round-trip cleanly once §2b adds the field.
  • PolicySigner / Ed25519Signer produces (signer_key_id, 64-byte signature) over those bytes.
  • PolicyVerifier / Ed25519Verifier checks such a pair against a KeyRegistry lookup.

§Canonical-JSON spec choice

This crate uses “sorted keys + no whitespace + UTF-8” rather than full RFC 8785 JCS. Policy values never contain f64 fields today, so the extra IEEE-754 canonicalization JCS requires is pure overhead. See [canonical] for the full contract.

Structs§

Ed25519Signer
Default Ed25519 signer. Holds a key id (opaque string the verifier uses to look up the corresponding VerifyingKey in a crate::keys::KeyRegistry) and a SigningKey.
Ed25519Verifier
Default verifier — looks up a [VerifyingKey] in the registry and runs ed25519_dalek::VerifyingKey::verify_strict.
InMemoryKeyRegistry
Simple in-memory KeyRegistry. Suitable for tests and for servers that load keys from disk at startup (D4 / pre-GA key rotation is out of scope per the 0.7.5 plan).

Enums§

SignError
Errors produced by the signing pipeline.
VerifyError
Errors produced by the verification pipeline.

Traits§

KeyRegistry
Lookup of verifying keys by opaque signer_key_id.
PolicySigner
Produces an Ed25519 signature over canonical policy bytes.
PolicyVerifier
Checks an Ed25519 signature against canonical policy bytes.

Functions§

canonicalize
Serialize policy into the canonical bytes used as the signing input. The signature key is removed from the top-level object before serialization; see module docs for the full spec.
canonicalize_value
Same as canonicalize but operates on an arbitrary serde_json::Value. Exposed for tests that want to prove the sort-and-strip behavior without building a full Policy.