Agentra LabsAgentra Labs DocsPublic Documentation

Get Started

API Reference

Complete API documentation for the agentic-identity Rust library

This document covers the public API of the agentic-identity crate. The crate is organized into four top-level modules: identity, receipt, trust, and crypto.


identity

IdentityId

Unique identifier for an identity. Format: aid_ + base58 of first 16 bytes of SHA-256(public_key).

pub struct IdentityId(pub String);

Methods:

MethodSignatureDescription
from_verifying_keyfn from_verifying_key(key: &VerifyingKey) -> SelfCompute an identity ID from a public key
Displayimpl DisplayFormats as the inner string

IdentityAnchor

The root cryptographic identity. Contains an Ed25519 key pair, creation timestamp, optional name, and rotation history. The signing key is zeroized on drop.

pub struct IdentityAnchor {
    pub created_at: u64,
    pub name: Option<String>,
    pub rotation_history: Vec<KeyRotation>,
}

Methods:

MethodSignatureDescription
newfn new(name: Option<String>) -> SelfCreate a new anchor with a fresh key pair
from_partsfn from_parts(signing_key_bytes: &[u8; 32], created_at: u64, name: Option<String>, rotation_history: Vec<KeyRotation>) -> Result<Self>Reconstruct from existing key bytes and metadata
idfn id(&self) -> IdentityIdReturn the identity ID (derived from public key)
signing_keyfn signing_key(&self) -> &SigningKeyReturn a reference to the Ed25519 signing key
verifying_keyfn verifying_key(&self) -> &VerifyingKeyReturn the verifying (public) key
signing_key_bytesfn signing_key_bytes(&self) -> [u8; 32]Return signing key bytes (caller must zeroize)
verifying_key_bytesfn verifying_key_bytes(&self) -> [u8; 32]Return verifying key bytes
public_key_base64fn public_key_base64(&self) -> StringReturn the public key as base64
derive_session_keyfn derive_session_key(&self, session_id: &str) -> Result<SigningKey>Derive a scoped signing key for a session
derive_capability_keyfn derive_capability_key(&self, capability_uri: &str) -> Result<SigningKey>Derive a scoped signing key for a capability
derive_device_keyfn derive_device_key(&self, device_id: &str) -> Result<SigningKey>Derive a scoped signing key for a device
derive_revocation_keyfn derive_revocation_key(&self, trust_id: &str) -> Result<SigningKey>Derive a revocation signing key for a trust grant
rotatefn rotate(&self, reason: RotationReason) -> Result<Self>Rotate the root key, returning a new anchor
to_documentfn to_document(&self) -> IdentityDocumentGenerate the public identity document

IdentityDocument

Public identity document (shareable, does not contain private keys). Self-signed by the identity's key.

pub struct IdentityDocument {
    pub id: IdentityId,
    pub public_key: String,        // base64
    pub algorithm: String,         // "ed25519"
    pub created_at: u64,
    pub name: Option<String>,
    pub rotation_history: Vec<PublicKeyRotation>,
    pub attestations: Vec<Attestation>,
    pub signature: String,         // base64
}

Methods:

MethodSignatureDescription
verify_signaturefn verify_signature(&self) -> Result<()>Verify the self-signature on this document

RotationReason

Reason for key rotation.

pub enum RotationReason {
    Scheduled,
    Compromised,
    DeviceLost,
    PolicyRequired,
    Manual,
}

KeyRotation

Record of a key rotation. Stored in the anchor's rotation history.

pub struct KeyRotation {
    pub previous_key: String,              // base64
    pub new_key: String,                   // base64
    pub rotated_at: u64,                   // microseconds
    pub reason: RotationReason,
    pub authorization_signature: String,   // base64
}

receipt

ActionType

Type of action being recorded.

pub enum ActionType {
    Decision,
    Observation,
    Mutation,
    Delegation,
    Revocation,
    IdentityOperation,
    Custom(String),
}

Methods:

MethodSignatureDescription
as_tagfn as_tag(&self) -> &strReturn a stable string tag for hashing

ActionContent

Content of an action.

pub struct ActionContent {
    pub description: String,
    pub data: Option<serde_json::Value>,
    pub references: Vec<String>,
}

Methods:

MethodSignatureDescription
newfn new(description: impl Into<String>) -> SelfCreate with just a description
with_datafn with_data(description: impl Into<String>, data: serde_json::Value) -> SelfCreate with description and structured data

ReceiptId

Unique identifier for a receipt. Format: arec_ + base58 of first 16 bytes of SHA-256(receipt_hash).

pub struct ReceiptId(pub String);

ActionReceipt

A signed proof that an agent took an action.

pub struct ActionReceipt {
    pub id: ReceiptId,
    pub actor: IdentityId,
    pub actor_key: String,               // base64
    pub action_type: ActionType,
    pub action: ActionContent,
    pub timestamp: u64,                  // microseconds
    pub context_hash: Option<String>,
    pub previous_receipt: Option<ReceiptId>,
    pub receipt_hash: String,            // hex SHA-256
    pub signature: String,               // base64
    pub witnesses: Vec<WitnessSignature>,
}

Methods:

MethodSignatureDescription
add_witnessfn add_witness(&mut self, witness: WitnessSignature)Add a witness signature

ReceiptBuilder

Builder for creating action receipts.

pub struct ReceiptBuilder { /* private */ }

Methods:

MethodSignatureDescription
newfn new(actor: IdentityId, action_type: ActionType, action: ActionContent) -> SelfStart building a receipt
context_hashfn context_hash(self, hash: String) -> SelfSet the context hash
chain_tofn chain_to(self, previous: ReceiptId) -> SelfChain this receipt to a previous one
signfn sign(self, signing_key: &SigningKey) -> Result<ActionReceipt>Sign and finalize the receipt

ReceiptVerification

Result of verifying a receipt.

pub struct ReceiptVerification {
    pub signature_valid: bool,
    pub chain_valid: Option<bool>,
    pub witnesses_valid: Vec<bool>,
    pub is_valid: bool,
    pub verified_at: u64,
}

verify_receipt

pub fn verify_receipt(receipt: &ActionReceipt) -> Result<ReceiptVerification>

Verify that a receipt's signature (and any witness signatures) are valid.

verify_chain

pub fn verify_chain(chain: &[ActionReceipt]) -> Result<bool>

Verify a chain of receipts ordered from oldest to newest. Checks every signature and the chain linkage between consecutive receipts.

WitnessSignature

A witness co-signature on a receipt.

pub struct WitnessSignature {
    pub witness: IdentityId,
    pub witness_key: String,     // base64
    pub witnessed_at: u64,
    pub signature: String,       // base64
}

Methods:

MethodSignatureDescription
createfn create(witness_id: IdentityId, signing_key: &SigningKey, receipt_hash: &str) -> SelfCreate a witness signature

trust

Capability

A capability being granted.

pub struct Capability {
    pub uri: String,
    pub description: Option<String>,
    pub constraints: Option<serde_json::Value>,
}

Methods:

MethodSignatureDescription
newfn new(uri: impl Into<String>) -> SelfCreate from a URI string
with_descriptionfn with_description(uri: impl Into<String>, description: impl Into<String>) -> SelfCreate with a description
coversfn covers(&self, requested: &str) -> boolCheck if this capability covers a requested URI

Standalone functions:

FunctionSignatureDescription
capabilities_coverfn capabilities_cover(granted: &[Capability], requested: &str) -> boolCheck if any granted capability covers a request
capabilities_cover_allfn capabilities_cover_all(granted: &[Capability], requested: &[&str]) -> boolCheck if grants cover ALL requests

TrustConstraints

Constraints on a trust grant.

pub struct TrustConstraints {
    pub not_before: u64,
    pub not_after: Option<u64>,
    pub max_uses: Option<u64>,
    pub geographic: Option<Vec<String>>,
    pub ip_allowlist: Option<Vec<String>>,
    pub custom: Option<serde_json::Value>,
}

Methods:

MethodSignatureDescription
openfn open() -> SelfValid immediately with no expiry
time_boundedfn time_bounded(not_before: u64, not_after: u64) -> SelfValid within a specific time window
with_max_usesfn with_max_uses(self, max: u64) -> SelfAdd a maximum use count
validatefn validate(&self, now: u64, current_uses: u64) -> Result<()>Check all constraints
is_time_validfn is_time_valid(&self, now: u64) -> boolCheck time window only
is_within_usesfn is_within_uses(&self, current_uses: u64) -> boolCheck use count only

TrustId

Unique identifier for a trust grant. Format: atrust_ + base58 of first 16 bytes of SHA-256(grant_hash).

pub struct TrustId(pub String);

TrustGrant

A signed trust relationship between two identities.

pub struct TrustGrant {
    pub id: TrustId,
    pub grantor: IdentityId,
    pub grantor_key: String,                  // base64
    pub grantee: IdentityId,
    pub grantee_key: String,                  // base64
    pub capabilities: Vec<Capability>,
    pub constraints: TrustConstraints,
    pub delegation_allowed: bool,
    pub max_delegation_depth: Option<u32>,
    pub parent_grant: Option<TrustId>,
    pub delegation_depth: u32,
    pub revocation: RevocationConfig,
    pub granted_at: u64,
    pub grant_hash: String,                   // hex SHA-256
    pub grantor_signature: String,            // base64
    pub grantee_acknowledgment: Option<String>, // base64
}

Methods:

MethodSignatureDescription
verify_signaturefn verify_signature(&self) -> Result<()>Verify the grantor's signature
acknowledgefn acknowledge(&mut self, grantee_signing_key: &SigningKey) -> Result<()>Add the grantee's acknowledgment signature

TrustGrantBuilder

Builder for creating trust grants.

pub struct TrustGrantBuilder { /* private */ }

Methods:

MethodSignatureDescription
newfn new(grantor: IdentityId, grantee: IdentityId, grantee_key: String) -> SelfStart building a trust grant
capabilityfn capability(self, cap: Capability) -> SelfAdd a capability
capabilitiesfn capabilities(self, caps: Vec<Capability>) -> SelfAdd multiple capabilities
constraintsfn constraints(self, constraints: TrustConstraints) -> SelfSet the constraints
allow_delegationfn allow_delegation(self, max_depth: u32) -> SelfAllow the grantee to delegate
delegated_fromfn delegated_from(self, parent: TrustId, depth: u32) -> SelfMark as delegated from a parent
revocation_channelfn revocation_channel(self, channel: RevocationChannel) -> SelfSet the revocation channel
revocation_witnessesfn revocation_witnesses(self, witnesses: Vec<IdentityId>) -> SelfSet required revocation witnesses
signfn sign(self, grantor_signing_key: &SigningKey) -> Result<TrustGrant>Sign and finalize the grant

TrustVerification

Result of verifying a trust grant.

pub struct TrustVerification {
    pub signature_valid: bool,
    pub time_valid: bool,
    pub not_revoked: bool,
    pub uses_valid: bool,
    pub capability_granted: bool,
    pub trust_chain: Vec<TrustId>,
    pub is_valid: bool,
    pub verified_at: u64,
}

verify_trust_grant

pub fn verify_trust_grant(
    grant: &TrustGrant,
    requested_capability: &str,
    current_uses: u64,
    revocations: &[Revocation],
) -> Result<TrustVerification>

Verify a trust grant for a specific capability at the current time.

is_grant_valid

pub fn is_grant_valid(
    grant: &TrustGrant,
    requested_capability: &str,
    current_uses: u64,
    revocations: &[Revocation],
) -> bool

Convenience function: returns true if the grant is valid for the requested capability.

verify_trust_chain

pub fn verify_trust_chain(
    chain: &[TrustGrant],
    requested_capability: &str,
    revocations: &[Revocation],
) -> Result<TrustVerification>

Verify a delegation chain from root to leaf. Each link must be signed, time-valid, not revoked, capability-covering, and properly delegated.

validate_delegation

pub fn validate_delegation(
    parent_grant: &TrustGrant,
    requested_capabilities: &[Capability],
) -> Result<()>

Check whether a delegation from a parent grant would be valid: delegation must be allowed, depth must not be exceeded, and capabilities must be covered.

Revocation

pub struct Revocation {
    pub trust_id: TrustId,
    pub revoked_by: IdentityId,
    pub reason: RevocationReason,
    pub revoked_at: u64,
    pub signature: String,
}

RevocationReason

pub enum RevocationReason {
    ManualRevocation,
    PolicyViolation,
    KeyCompromise,
    Expired,
    Superseded,
}

RevocationChannel

Where revocation is published.

pub enum RevocationChannel {
    Local,
    Http { url: String },
    Ledger { ledger_id: String },
    Multi(Vec<RevocationChannel>),
}

crypto

Low-level cryptographic operations. Most users should use the higher-level identity, receipt, and trust APIs.

keys

FunctionDescription
Ed25519KeyPair::generate()Generate a fresh Ed25519 key pair
Ed25519KeyPair::from_signing_key_bytes(&[u8; 32])Reconstruct from existing key bytes
Ed25519KeyPair::verifying_key_from_bytes(&[u8; 32])Reconstruct a verifying key from bytes

signing

FunctionDescription
sign(key: &SigningKey, message: &[u8]) -> SignatureSign a message
verify(key: &VerifyingKey, message: &[u8], sig: &Signature) -> Result<()>Verify a signature
sign_to_base64(key: &SigningKey, message: &[u8]) -> StringSign and return base64-encoded signature
verify_from_base64(key: &VerifyingKey, message: &[u8], sig_b64: &str) -> Result<()>Verify a base64-encoded signature

derivation

FunctionDescription
derive_key(root: &[u8; 32], context: &str) -> Result<[u8; 32]>Derive a 32-byte child key via HKDF-SHA256
derive_signing_key(root: &[u8; 32], context: &str) -> Result<SigningKey>Derive an Ed25519 signing key
session_context(session_id: &str) -> StringBuild derivation path for a session key
capability_context(uri: &str) -> StringBuild derivation path for a capability key
device_context(device_id: &str) -> StringBuild derivation path for a device key

encryption

FunctionDescription
derive_passphrase_key(passphrase: &[u8], salt: &[u8; 16]) -> Result<[u8; 32]>Argon2id passphrase-based key derivation
encrypt(key: &[u8; 32], plaintext: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>ChaCha20-Poly1305 encrypt; returns (nonce, ciphertext)
decrypt(key: &[u8; 32], nonce: &[u8], ciphertext: &[u8]) -> Result<Vec<u8>>ChaCha20-Poly1305 decrypt
encrypt_with_passphrase(passphrase: &[u8], plaintext: &[u8]) -> Result<([u8; 16], Vec<u8>, Vec<u8>)>Encrypt with passphrase; returns (salt, nonce, ciphertext)
decrypt_with_passphrase(passphrase: &[u8], salt: &[u8; 16], nonce: &[u8], ciphertext: &[u8]) -> Result<Vec<u8>>Decrypt with passphrase

storage

File Operations

FunctionSignatureDescription
save_identityfn save_identity(anchor: &IdentityAnchor, path: &Path, passphrase: &str) -> Result<()>Save identity to .aid file with passphrase encryption
load_identityfn load_identity(path: &Path, passphrase: &str) -> Result<IdentityAnchor>Load identity from .aid file with passphrase decryption
read_public_documentfn read_public_document(path: &Path) -> Result<IdentityDocument>Read only the public document (no passphrase needed)

error

IdentityError

All errors are strongly typed. Private key material is never included in error messages.

pub enum IdentityError {
    InvalidKey(String),
    SignatureInvalid,
    NotFound(String),
    DerivationFailed(String),
    EncryptionFailed(String),
    DecryptionFailed(String),
    InvalidPassphrase,
    TrustNotGranted(String),
    TrustRevoked(String),
    TrustExpired,
    TrustNotYetValid,
    MaxUsesExceeded,
    DelegationNotAllowed,
    DelegationDepthExceeded,
    InvalidChain,
    StorageError(String),
    SerializationError(String),
    InvalidFileFormat(String),
    Io(std::io::Error),
}
pub type Result<T> = std::result::Result<T, IdentityError>;