Skip to main content

ratify_protocol/
lib.rs

1//! Ratify Protocol — Rust reference SDK (2.x line).
2//!
3//! The `v2` module is the Protocol v2 API. The crate-root items are the
4//! Protocol v1 API, retained so one dependency can verify both during the
5//! migration window; v1-only consumers stay on the 1.0.0-alpha.x releases.
6//!
7//! Delegated-authority proofs for human-agent and agent-agent interactions.
8//! Every signature is a post-quantum hybrid of Ed25519 and ML-DSA-65 (NIST FIPS 204), and it verifies
9//! only when both components verify.
10//!
11//! See docs/EXPLAINED.md and docs/AGENT_TO_AGENT.md in the repository for
12//! architecture, threat model, and agent-to-agent patterns.
13//!
14//! # `no_std` support
15//!
16//! Disable the default `std` feature to use this crate without the standard
17//! library. An `alloc` crate is required. I/O, `SystemTime`, and `serde_json`
18//! support are only available with `std`.
19
20#![cfg_attr(not(feature = "std"), no_std)]
21extern crate alloc;
22
23pub mod canonical;
24pub mod challenge_store;
25pub mod constraints;
26pub mod operation_context;
27pub mod crypto;
28pub mod crypto_v2;
29pub mod receipts;
30pub mod resource_path;
31pub mod scope;
32pub mod types;
33pub mod verify;
34pub mod wire;
35#[cfg(feature = "std")]
36pub mod v2;
37
38pub use canonical::{base64_std_decode, base64_std_encode, hex_decode, hex_encode};
39#[cfg(feature = "std")]
40pub use canonical::canonical_json;
41pub use challenge_store::{ChallengeStore, UNKNOWN_CHALLENGE};
42#[cfg(feature = "std")]
43pub use v2::{
44    build_session_context_v2, challenge_claim_digest_v2, decode_payload_digest_v2,
45    operation_context_v2_bytes, operation_context_v2_hash, protocol_claim_id_from_digest_v2,
46    protocol_claim_id_v2, session_context_v2_bytes, OperationContextV2, SessionContextV2Inputs,
47};
48pub use operation_context::{
49    build_session_context, operation_context_bytes, operation_context_hash,
50    session_context_bytes, OperationContext, SessionContextInputs,
51};
52#[cfg(feature = "std")]
53pub use challenge_store::MemoryChallengeStore;
54pub use crypto::{
55    chain_hash, challenge_sign_bytes, challenge_sign_bytes_with_session_context,
56    challenge_sign_bytes_with_stream, delegation_sign_bytes, derive_id, generate_challenge,
57    generate_hybrid_keypair, hybrid_keypair_from_seeds, issue_delegation, issue_key_rotation_statement, issue_revocation_list,
58    issue_revocation_push, issue_session_token, issue_witness_entry, key_rotation_sign_bytes,
59    revocation_push_sign_bytes, revocation_sign_bytes, session_token_sign_bytes, sign_both,
60    sign_challenge, sign_challenge_with_session_context, sign_challenge_with_stream,
61    sign_transaction_receipt_party, transaction_receipt_sign_bytes, verify_both,
62    verify_challenge_signature, verify_challenge_signature_with_session_context,
63    verify_challenge_signature_with_stream, verify_delegation_signature,
64    verify_delegation_signature_e, verify_key_rotation_statement, verify_revocation_list,
65    verify_revocation_push, verify_session_token, verify_session_token_e, verify_witness_entry,
66    witness_entry_sign_bytes,
67};
68pub use crypto_v2::{delegation_signature_message_v2, derive_key_id_v2, verify_delegation_v2};
69#[cfg(feature = "std")]
70pub use crypto::{generate_agent, generate_human_root};
71pub use scope::{
72    expand_scopes, has_scope, intersect_scopes, is_sensitive, scope_wildcards, validate_scopes,
73    vocabulary, CUSTOM_SCOPE_PREFIX,
74    SCOPE_COMMS_CALENDAR_READ, SCOPE_COMMS_CALENDAR_WRITE, SCOPE_COMMS_EMAIL_DELETE,
75    SCOPE_COMMS_EMAIL_READ, SCOPE_COMMS_EMAIL_SEND, SCOPE_COMMS_MESSAGE_DELETE,
76    SCOPE_COMMS_MESSAGE_READ, SCOPE_COMMS_MESSAGE_SEND, SCOPE_CONTRACT_READ, SCOPE_CONTRACT_SIGN,
77    SCOPE_DATA_DELETE, SCOPE_DATA_EXPORT, SCOPE_DATA_READ, SCOPE_DATA_SHARE, SCOPE_DATA_WRITE,
78    SCOPE_EXECUTE_CODE, SCOPE_EXECUTE_TOOL, SCOPE_FILES_READ, SCOPE_FILES_WRITE,
79    SCOPE_GENERATE_CONTENT, SCOPE_GENERATE_DEEPFAKE, SCOPE_IDENTITY_DELEGATE, SCOPE_IDENTITY_PROVE,
80    SCOPE_MEETING_ATTEND, SCOPE_MEETING_CHAT, SCOPE_MEETING_RECORD, SCOPE_MEETING_SHARE_SCREEN,
81    SCOPE_MEETING_SPEAK, SCOPE_MEETING_VIDEO, SCOPE_PAYMENTS_AUTHORIZE, SCOPE_PAYMENTS_RECEIVE,
82    SCOPE_PAYMENTS_SEND, SCOPE_PRESENCE_REPRESENT, SCOPE_TRANSACT_PURCHASE, SCOPE_TRANSACT_SELL,
83};
84pub use receipts::{
85    bundle_hash, issue_policy_verdict, issue_verification_receipt,
86    policy_verdict_sign_bytes_buf, receipt_hash, verification_receipt_sign_bytes_buf,
87    verifier_context_hash, verify_policy_verdict, verify_verification_receipt,
88};
89pub use resource_path::{
90    normalize_resource_path, resource_path_matches, validate_constraint_params,
91    validate_params_value, validate_resource_constraints,
92};
93pub use wire::{
94    check_json_nesting_depth, check_receipt_structure, encode_verification_receipt,
95};
96#[cfg(feature = "std")]
97pub use wire::{decode_delegation_cert, decode_proof_bundle, decode_verification_receipt};
98pub use types::{
99    is_canonical_constraint_type, AgentIdentity, Anchor, AnchorResolver, AuditProvider, Constraint,
100    ConstraintEvaluator, DelegationCert, HumanRoot, HybridPrivateKey, HybridPublicKey,
101    HybridSignature, IdentityStatus, KeyRotationStatement, ParamsValue, PolicyProvider,
102    PolicyVerdict, ProofBundle, ReceiptParty, ReceiptPartySignature, RevocationList,
103    RevocationProvider, RevocationPush, SessionToken, StreamContext, TransactionReceipt,
104    TransactionReceiptResult, VerificationReceipt, InvocationCounter, VerifierContext,
105    VerifyOptions, VerifyResult, WitnessEntry, CHALLENGE_WINDOW_SECONDS, ED25519_PUBLIC_KEY_SIZE,
106    ED25519_SIGNATURE_SIZE, MAX_AGENT_NAME_LENGTH_BYTES, MAX_CONSTRAINTS_PER_CERT,
107    MAX_DELEGATION_CHAIN_DEPTH, MAX_IDENTIFIER_LENGTH_BYTES, MAX_JSON_NESTING_DEPTH,
108    MAX_PROOF_BUNDLE_BYTES, MAX_SCOPES_PER_CERT, MAX_SCOPE_LENGTH_BYTES, MLDSA65_PUBLIC_KEY_SIZE,
109    MLDSA65_SIGNATURE_SIZE, NO_EXPIRY_SENTINEL, PROTOCOL_VERSION,
110};
111#[allow(deprecated)]
112pub use verify::verify_streamed_turn;
113pub use verify::{
114    verify_bundle, verify_streamed_turn_with_options, verify_transaction_receipt, StreamedTurn,
115    StreamedVerifyOptions,
116};