dyolo-kya 1.0.0

Know Your Agent (KYA): cryptographic chain-of-custody for recursive AI delegation with provable scope narrowing
//! # dyolo-kya — Know Your Agent
//!
//! Cryptographic chain-of-custody for recursive AI agent delegation.
//!
//! ## The Problem
//!
//! When an AI agent delegates a task to another agent — which may delegate
//! further — the authorization chain breaks down. There is no irrefutable
//! proof that the action traces back to an original human authorization,
//! no guarantee that the delegated scope is a valid subset of the delegator's
//! own permissions, and no replay or revocation enforcement across hops.
//! This is the *Recursive Delegation Gap*.
//!
//! ## The Solution
//!
//! `dyolo-kya` closes every gap through a minimal, formally verifiable design:
//!
//! | Primitive | Role |
//! |---|---|
//! | [`IntentTree`] | Merkle tree over authorized actions; root is the scope commitment |
//! | [`SubScopeProof`] | Proof that a delegated scope is a strict subset of the parent's |
//! | [`DelegationCert`] | Signed, domain-separated record binding scope + temporal bounds + nonce |
//! | [`DyoloChain`] | Verifies all invariants in one pass, produces [`AuthorizedAction`] |
//! | [`AuthorizedAction`] | Type-level proof of authorization; the only valid execution token |
//!
//! ## Quick Start
//!
//! ```rust
//! use dyolo_kya::{
//!     DyoloIdentity, DyoloChain, Intent,
//!     CertBuilder, IntentTree, SubScopeProof, MerkleProof,
//!     MemoryRevocationStore, MemoryNonceStore, SystemClock,
//! };
//!
//! // Identities
//! let human   = DyoloIdentity::generate();
//! let agent_a = DyoloIdentity::generate();
//! let agent_b = DyoloIdentity::generate();
//!
//! // Human defines the authorized intent set.
//! let trade = Intent::new("trade.equity")
//!     .param("symbol", "AAPL")
//!     .param("limit_usd", "182.50")
//!     .param("qty", "100")
//!     .hash();
//! let query = Intent::new("query.portfolio").hash();
//! let tree  = IntentTree::build(vec![trade, query]).unwrap();
//! let root  = tree.root();
//!
//! // Human → Agent A (full scope).
//! let now    = 1_700_000_000u64;
//! let expiry = now + 3600;
//! let cert_a = CertBuilder::new(agent_a.verifying_key(), root, now, expiry)
//!     .sign(&human);
//!
//! // Agent A → Agent B (trade-only, depth-capped).
//! let sub_proof = SubScopeProof::build(&tree, &[trade]).unwrap();
//! let sub_root  = dyolo_kya::IntentTree::build(vec![trade]).unwrap().root();
//! let cert_b    = CertBuilder::new(agent_b.verifying_key(), sub_root, now, expiry)
//!     .scope_proof(sub_proof)
//!     .max_depth(0)
//!     .sign(&agent_a);
//!
//! // Assemble and authorize.
//! let mut chain = DyoloChain::new(human.verifying_key(), root);
//! chain.push(cert_a).push(cert_b);
//!
//! let action = chain.authorize(
//!     &agent_b.verifying_key(),
//!     &trade,
//!     &MerkleProof::default(),
//!     &SystemClock,
//!     &MemoryRevocationStore::new(),
//!     &MemoryNonceStore::new(),
//! ).unwrap();
//!
//! println!("Authorized: depth={}", action.receipt.chain_depth);
//! ```

#![deny(unsafe_code)]

mod crypto;

pub mod cert;
pub mod chain;
pub mod error;
pub mod identity;
pub mod intent;
pub mod registry;

pub use cert::{CertBuilder, DelegationCert};
pub use chain::{AuthorizedAction, Clock, DyoloChain, SystemClock, VerificationReceipt};
pub use error::KyaError;
pub use identity::DyoloIdentity;
pub use intent::{Intent, IntentHash, IntentTree, MerkleProof, SiblingNode, SubScopeProof, intent_hash};
pub use registry::{
    MemoryNonceStore, MemoryRevocationStore, NonceStore, RevocationStore, fresh_nonce,
};