#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, format, string::String, string::ToString, vec, vec::Vec};
use alloc::collections::BTreeMap;
use serde::de::{Error as DeError, MapAccess, SeqAccess, Visitor};
use serde::ser::{SerializeMap, SerializeSeq, Serializer};
use serde::{Deserialize, Deserializer, Serialize};
use core::fmt;
pub const PROTOCOL_VERSION: i32 = 1;
pub const NO_EXPIRY_SENTINEL: i64 = 4070908799;
pub const MAX_DELEGATION_CHAIN_DEPTH: usize = 8;
pub const CHALLENGE_WINDOW_SECONDS: i64 = 300;
pub const MAX_PROOF_BUNDLE_BYTES: usize = 131072; pub const MAX_SCOPES_PER_CERT: usize = 128;
pub const MAX_CONSTRAINTS_PER_CERT: usize = 32;
pub const MAX_SCOPE_LENGTH_BYTES: usize = 256;
pub const MAX_IDENTIFIER_LENGTH_BYTES: usize = 512;
pub const MAX_AGENT_NAME_LENGTH_BYTES: usize = 256;
pub const MAX_JSON_NESTING_DEPTH: usize = 16;
pub const ED25519_PUBLIC_KEY_SIZE: usize = 32;
pub const ED25519_SIGNATURE_SIZE: usize = 64;
pub const MLDSA65_PUBLIC_KEY_SIZE: usize = 1952;
pub const MLDSA65_SIGNATURE_SIZE: usize = 3309;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct HybridPublicKey {
#[serde(with = "crate::canonical::base64_bytes")]
pub ed25519: Vec<u8>, #[serde(with = "crate::canonical::base64_bytes")]
pub ml_dsa_65: Vec<u8>, }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct HybridSignature {
#[serde(with = "crate::canonical::base64_bytes")]
pub ed25519: Vec<u8>, #[serde(with = "crate::canonical::base64_bytes")]
pub ml_dsa_65: Vec<u8>, }
#[derive(Clone)]
pub struct HybridPrivateKey {
ed25519: Vec<u8>, ml_dsa_65: Vec<u8>, }
impl HybridPrivateKey {
pub fn from_components(ed25519: Vec<u8>, ml_dsa_65: Vec<u8>) -> Self {
HybridPrivateKey { ed25519, ml_dsa_65 }
}
pub fn ed25519(&self) -> &[u8] {
&self.ed25519
}
pub fn ml_dsa_65(&self) -> &[u8] {
&self.ml_dsa_65
}
}
impl Drop for HybridPrivateKey {
fn drop(&mut self) {
use zeroize::Zeroize;
self.ed25519.zeroize();
self.ml_dsa_65.zeroize();
}
}
impl fmt::Debug for HybridPrivateKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let public = self
.ed25519
.get(..32)
.and_then(|s| <[u8; 32]>::try_from(s).ok())
.map(zeroize::Zeroizing::new)
.map(|seed| {
hex::encode(ed25519_dalek::SigningKey::from_bytes(&seed).verifying_key().to_bytes())
});
f.debug_struct("HybridPrivateKey")
.field("ed25519_public", &public)
.finish_non_exhaustive()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Anchor {
#[serde(rename = "type")]
pub anchor_type: String,
pub provider: String,
pub reference: String,
pub verified_at: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HumanRoot {
pub id: String,
pub public_key: HybridPublicKey,
pub created_at: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub anchors: Option<Vec<Anchor>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentIdentity {
pub id: String,
pub public_key: HybridPublicKey,
pub name: String,
pub agent_type: String,
pub created_at: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct DelegationCert {
pub cert_id: String,
pub version: i32,
pub issuer_id: String,
pub issuer_pub_key: HybridPublicKey,
pub subject_id: String,
pub subject_pub_key: HybridPublicKey,
pub scope: Vec<String>,
#[serde(default)]
pub constraints: Vec<Constraint>,
#[serde(
serialize_with = "crate::canonical::wire_int::serialize",
deserialize_with = "crate::canonical::wire_int::deserialize"
)]
pub issued_at: i64,
#[serde(
serialize_with = "crate::canonical::wire_int::serialize",
deserialize_with = "crate::canonical::wire_int::deserialize"
)]
pub expires_at: i64,
pub signature: HybridSignature,
}
impl DelegationCert {
pub fn is_no_expiry(&self) -> bool {
self.expires_at == NO_EXPIRY_SENTINEL
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ParamsValue {
Null,
Bool(bool),
Int(i64),
Str(String),
Array(Vec<ParamsValue>),
Object(BTreeMap<String, ParamsValue>),
}
impl Serialize for ParamsValue {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
ParamsValue::Null => serializer.serialize_unit(),
ParamsValue::Bool(b) => serializer.serialize_bool(*b),
ParamsValue::Int(n) => {
if !crate::canonical::wire_int::in_domain(*n) {
return Err(serde::ser::Error::custom(
"params integer exceeds the safe-integer range; carry it as a decimal string",
));
}
serializer.serialize_i64(*n)
}
ParamsValue::Str(s) => serializer.serialize_str(s),
ParamsValue::Array(items) => {
let mut seq = serializer.serialize_seq(Some(items.len()))?;
for item in items {
seq.serialize_element(item)?;
}
seq.end()
}
ParamsValue::Object(map) => {
let mut m = serializer.serialize_map(Some(map.len()))?;
for (k, v) in map {
m.serialize_entry(k, v)?;
}
m.end()
}
}
}
}
struct ParamsValueVisitor;
impl<'de> Visitor<'de> for ParamsValueVisitor {
type Value = ParamsValue;
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("a restricted params value (null, bool, string, safe integer, array, or object)")
}
fn visit_bool<E: DeError>(self, v: bool) -> Result<Self::Value, E> {
Ok(ParamsValue::Bool(v))
}
fn visit_i64<E: DeError>(self, v: i64) -> Result<Self::Value, E> {
Ok(ParamsValue::Int(v))
}
fn visit_u64<E: DeError>(self, v: u64) -> Result<Self::Value, E> {
if v > i64::MAX as u64 {
return Err(E::custom(
"params integer exceeds the safe-integer range; carry it as a decimal string",
));
}
Ok(ParamsValue::Int(v as i64))
}
fn visit_f64<E: DeError>(self, v: f64) -> Result<Self::Value, E> {
if !v.is_finite() || v.fract() != 0.0 {
return Err(E::custom(
"params values must be safe integers, not floats (carry non-integers as strings)",
));
}
let max = crate::canonical::wire_int::MAX_SAFE_INTEGER as f64;
if v.abs() > max {
return Err(E::custom(
"params integer exceeds the safe-integer range; carry it as a decimal string",
));
}
Ok(ParamsValue::Int(v as i64))
}
fn visit_str<E: DeError>(self, v: &str) -> Result<Self::Value, E> {
Ok(ParamsValue::Str(v.to_string()))
}
fn visit_string<E: DeError>(self, v: String) -> Result<Self::Value, E> {
Ok(ParamsValue::Str(v))
}
fn visit_none<E: DeError>(self) -> Result<Self::Value, E> {
Ok(ParamsValue::Null)
}
fn visit_unit<E: DeError>(self) -> Result<Self::Value, E> {
Ok(ParamsValue::Null)
}
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
let mut out = Vec::new();
while let Some(item) = seq.next_element()? {
out.push(item);
}
Ok(ParamsValue::Array(out))
}
fn visit_map<A: MapAccess<'de>>(self, mut map: A) -> Result<Self::Value, A::Error> {
let mut out: BTreeMap<String, ParamsValue> = BTreeMap::new();
while let Some((k, v)) = map.next_entry::<String, ParamsValue>()? {
if out.insert(k, v).is_some() {
return Err(A::Error::custom("params contains a duplicate object key"));
}
}
Ok(ParamsValue::Object(out))
}
}
impl<'de> Deserialize<'de> for ParamsValue {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
deserializer.deserialize_any(ParamsValueVisitor)
}
}
pub fn is_canonical_constraint_type(t: &str) -> bool {
matches!(
t,
"geo_circle"
| "geo_polygon"
| "geo_bbox"
| "time_window"
| "max_speed_mps"
| "max_amount"
| "max_rate"
| "resource_path"
)
}
fn de_path_prefix<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
if s.is_empty() {
return Err(D::Error::custom(
"constraint path_prefix must not be empty or null; omit the field to authorize the entire resource",
));
}
Ok(Some(s))
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(deny_unknown_fields)]
struct ConstraintWire {
#[serde(default, deserialize_with = "crate::canonical::wire_int::deserialize")]
count: i64,
#[serde(default)]
currency: String,
#[serde(default)]
end: String,
#[serde(default)]
lat: f64,
#[serde(default)]
lon: f64,
#[serde(default)]
max_alt_m: f64,
#[serde(default)]
max_amount: f64,
#[serde(default)]
max_lat: f64,
#[serde(default)]
max_lon: f64,
#[serde(default)]
max_mps: f64,
#[serde(default)]
min_alt_m: f64,
#[serde(default)]
min_lat: f64,
#[serde(default)]
min_lon: f64,
#[serde(default)]
params: Option<BTreeMap<String, ParamsValue>>,
#[serde(default, deserialize_with = "de_path_prefix")]
path_prefix: Option<String>,
#[serde(default)]
points: Vec<[f64; 2]>,
#[serde(default)]
radius_m: f64,
#[serde(default)]
resource_id: String,
#[serde(default)]
start: String,
#[serde(default)]
tz: String,
#[serde(rename = "type")]
kind: String,
#[serde(default, deserialize_with = "crate::canonical::wire_int::deserialize")]
window_s: i64,
}
impl TryFrom<ConstraintWire> for Constraint {
type Error = String;
fn try_from(w: ConstraintWire) -> Result<Self, Self::Error> {
if w.kind == "resource_path" && w.resource_id.is_empty() {
return Err(
"resource_path constraint requires a non-empty resource_id".into(),
);
}
Ok(Constraint {
count: w.count,
currency: w.currency,
end: w.end,
lat: w.lat,
lon: w.lon,
max_alt_m: w.max_alt_m,
max_amount: w.max_amount,
max_lat: w.max_lat,
max_lon: w.max_lon,
max_mps: w.max_mps,
min_alt_m: w.min_alt_m,
min_lat: w.min_lat,
min_lon: w.min_lon,
params: w.params,
path_prefix: w.path_prefix,
points: w.points,
radius_m: w.radius_m,
resource_id: w.resource_id,
start: w.start,
tz: w.tz,
kind: w.kind,
window_s: w.window_s,
})
}
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(try_from = "ConstraintWire")]
pub struct Constraint {
pub count: i64,
pub currency: String,
pub end: String,
pub lat: f64,
pub lon: f64,
pub max_alt_m: f64,
pub max_amount: f64,
pub max_lat: f64,
pub max_lon: f64,
pub max_mps: f64,
pub min_alt_m: f64,
pub min_lat: f64,
pub min_lon: f64,
pub params: Option<BTreeMap<String, ParamsValue>>,
pub path_prefix: Option<String>,
pub points: Vec<[f64; 2]>,
pub radius_m: f64,
pub resource_id: String,
pub start: String,
pub tz: String,
pub kind: String,
pub window_s: i64,
}
impl Serialize for Constraint {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
if self.params.is_some() && is_canonical_constraint_type(&self.kind) {
return Err(serde::ser::Error::custom(format!(
"canonical constraint type \"{}\" must not carry params",
self.kind
)));
}
let entries: Vec<(&'static str, FieldValue)> = match self.kind.as_str() {
"geo_circle" => vec![
("lat", FieldValue::F64(self.lat)),
("lon", FieldValue::F64(self.lon)),
("radius_m", FieldValue::F64(self.radius_m)),
("type", FieldValue::Str(self.kind.clone())),
],
"geo_polygon" => vec![
("points", FieldValue::Points(self.points.clone())),
("type", FieldValue::Str(self.kind.clone())),
],
"geo_bbox" => {
let mut v = vec![
("max_lat", FieldValue::F64(self.max_lat)),
("max_lon", FieldValue::F64(self.max_lon)),
("min_lat", FieldValue::F64(self.min_lat)),
("min_lon", FieldValue::F64(self.min_lon)),
];
if self.min_alt_m != 0.0 || self.max_alt_m != 0.0 {
v.insert(0, ("max_alt_m", FieldValue::F64(self.max_alt_m)));
v.insert(3, ("min_alt_m", FieldValue::F64(self.min_alt_m)));
}
v.push(("type", FieldValue::Str(self.kind.clone())));
v
}
"time_window" => vec![
("end", FieldValue::Str(self.end.clone())),
("start", FieldValue::Str(self.start.clone())),
("type", FieldValue::Str(self.kind.clone())),
("tz", FieldValue::Str(self.tz.clone())),
],
"max_speed_mps" => vec![
("max_mps", FieldValue::F64(self.max_mps)),
("type", FieldValue::Str(self.kind.clone())),
],
"max_amount" => vec![
("currency", FieldValue::Str(self.currency.clone())),
("max_amount", FieldValue::F64(self.max_amount)),
("type", FieldValue::Str(self.kind.clone())),
],
"max_rate" => vec![
("count", FieldValue::I64(self.count)),
("type", FieldValue::Str(self.kind.clone())),
("window_s", FieldValue::I64(self.window_s)),
],
"resource_path" => {
if self.resource_id.is_empty() {
return Err(serde::ser::Error::custom(
"resource_path constraint requires a non-empty resource_id",
));
}
let mut v = Vec::new();
if let Some(prefix) = &self.path_prefix {
v.push(("path_prefix", FieldValue::Str(prefix.clone())));
}
v.push(("resource_id", FieldValue::Str(self.resource_id.clone())));
v.push(("type", FieldValue::Str(self.kind.clone())));
v
}
_ => {
let mut v = Vec::new();
if let Some(params) = &self.params {
v.push(("params", FieldValue::Params(params.clone())));
}
v.push(("type", FieldValue::Str(self.kind.clone())));
v
}
};
let mut m = serializer.serialize_map(Some(entries.len()))?;
for (k, v) in entries {
match v {
FieldValue::F64(x) => m.serialize_entry(k, &x)?,
FieldValue::I64(x) => {
if !crate::canonical::wire_int::in_domain(x) {
return Err(serde::ser::Error::custom(
"integer outside the safe-integer range [-(2^53-1), 2^53-1]",
));
}
m.serialize_entry(k, &x)?
}
FieldValue::Str(x) => m.serialize_entry(k, &x)?,
FieldValue::Points(x) => m.serialize_entry(k, &x)?,
FieldValue::Params(x) => m.serialize_entry(k, &x)?,
}
}
m.end()
}
}
enum FieldValue {
F64(f64),
I64(i64),
Str(String),
Points(Vec<[f64; 2]>),
Params(BTreeMap<String, ParamsValue>),
}
pub type InvocationCounter<'a> = Box<dyn Fn(&str, i64) -> i64 + 'a>;
#[derive(Default)]
pub struct VerifierContext<'a> {
pub current_lat: Option<f64>,
pub current_lon: Option<f64>,
pub current_alt_m: Option<f64>,
pub current_speed_mps: Option<f64>,
pub requested_amount: Option<f64>,
pub requested_currency: Option<String>,
pub invocations_in_window: Option<InvocationCounter<'a>>,
pub requested_resource_id: Option<String>,
pub requested_path: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ProofBundle {
pub agent_id: String,
pub agent_pub_key: HybridPublicKey,
pub delegations: Vec<DelegationCert>,
#[serde(with = "crate::canonical::base64_bytes")]
pub challenge: Vec<u8>,
#[serde(
serialize_with = "crate::canonical::wire_int::serialize",
deserialize_with = "crate::canonical::wire_int::deserialize"
)]
pub challenge_at: i64,
pub challenge_sig: HybridSignature,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
with = "crate::canonical::base64_bytes"
)]
pub session_context: Vec<u8>,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
with = "crate::canonical::base64_bytes"
)]
pub stream_id: Vec<u8>,
#[serde(
default,
skip_serializing_if = "is_zero_i64",
serialize_with = "crate::canonical::wire_int::serialize",
deserialize_with = "crate::canonical::wire_int::deserialize"
)]
pub stream_seq: i64,
}
fn is_zero_i64(v: &i64) -> bool {
*v == 0
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum IdentityStatus {
VerifiedHuman,
AuthorizedAgent,
Expired,
Revoked,
ScopeDenied,
ConstraintDenied,
ConstraintUnverifiable,
ConstraintUnknown,
DelegationNotAuthorized,
InvalidScope,
Invalid,
Unauthorized,
}
impl IdentityStatus {
pub fn as_str(&self) -> &'static str {
match self {
Self::VerifiedHuman => "verified_human",
Self::AuthorizedAgent => "authorized_agent",
Self::Expired => "expired",
Self::Revoked => "revoked",
Self::ScopeDenied => "scope_denied",
Self::ConstraintDenied => "constraint_denied",
Self::ConstraintUnverifiable => "constraint_unverifiable",
Self::ConstraintUnknown => "constraint_unknown",
Self::DelegationNotAuthorized => "delegation_not_authorized",
Self::InvalidScope => "invalid_scope",
Self::Invalid => "invalid",
Self::Unauthorized => "unauthorized",
}
}
pub fn from_wire(s: &str) -> Option<Self> {
Some(match s {
"verified_human" => Self::VerifiedHuman,
"authorized_agent" => Self::AuthorizedAgent,
"expired" => Self::Expired,
"revoked" => Self::Revoked,
"scope_denied" => Self::ScopeDenied,
"constraint_denied" => Self::ConstraintDenied,
"constraint_unverifiable" => Self::ConstraintUnverifiable,
"constraint_unknown" => Self::ConstraintUnknown,
"delegation_not_authorized" => Self::DelegationNotAuthorized,
"invalid_scope" => Self::InvalidScope,
"invalid" => Self::Invalid,
"unauthorized" => Self::Unauthorized,
_ => return None,
})
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerifyResult {
pub valid: bool,
pub identity_status: IdentityStatus,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub human_id: String,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub agent_id: String,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub agent_name: String,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub agent_type: String,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub granted_scope: Vec<String>,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub error_reason: String,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub anchor: Option<Anchor>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RevocationList {
pub issuer_id: String,
pub updated_at: i64,
pub revoked_certs: Vec<String>,
pub signature: HybridSignature,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RevocationPush {
pub issuer_id: String,
pub seq_no: i64,
pub entries: Vec<String>,
pub pushed_at: i64,
pub signature: HybridSignature,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WitnessEntry {
#[serde(with = "crate::canonical::base64_bytes")]
pub prev_hash: Vec<u8>,
#[serde(with = "crate::canonical::base64_bytes")]
pub entry_data: Vec<u8>,
pub timestamp: i64,
pub witness_id: String,
pub signature: HybridSignature,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SessionToken {
pub version: i32,
pub session_id: String,
pub agent_id: String,
pub agent_pub_key: HybridPublicKey,
pub human_id: String,
pub granted_scope: Vec<String>,
#[serde(
serialize_with = "crate::canonical::wire_int::serialize",
deserialize_with = "crate::canonical::wire_int::deserialize"
)]
pub issued_at: i64,
#[serde(
serialize_with = "crate::canonical::wire_int::serialize",
deserialize_with = "crate::canonical::wire_int::deserialize"
)]
pub valid_until: i64,
#[serde(with = "crate::canonical::base64_bytes")]
pub chain_hash: Vec<u8>,
#[serde(with = "crate::canonical::base64_bytes")]
pub mac: Vec<u8>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionReceipt {
pub version: i32,
pub transaction_id: String,
pub created_at: i64,
pub terms_schema_uri: String,
#[serde(with = "crate::canonical::base64_bytes")]
pub terms_canonical_json: Vec<u8>,
pub parties: Vec<ReceiptParty>,
pub party_signatures: Vec<ReceiptPartySignature>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReceiptParty {
pub party_id: String,
pub role: String,
pub agent_id: String,
pub agent_pub_key: HybridPublicKey,
pub proof_bundle: ProofBundle,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReceiptPartySignature {
pub party_id: String,
pub signature: HybridSignature,
}
pub struct TransactionReceiptResult {
pub valid: bool,
pub error_reason: String,
pub party_results: Vec<VerifyResult>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyRotationStatement {
pub version: i32,
pub old_id: String,
pub old_pub_key: HybridPublicKey,
pub new_id: String,
pub new_pub_key: HybridPublicKey,
pub rotated_at: i64,
pub reason: String,
pub signature_old: HybridSignature,
pub signature_new: HybridSignature,
}
#[derive(Debug, Clone, Default)]
pub struct StreamContext {
pub stream_id: Vec<u8>,
pub last_seen_seq: i64,
}
pub trait RevocationProvider {
fn is_revoked(&self, cert_id: &str) -> Result<bool, String>;
}
pub trait PolicyProvider {
fn evaluate_policy(
&self,
bundle: &ProofBundle,
context: &VerifierContext,
) -> Result<bool, String>;
}
pub trait AuditProvider {
fn log_verification(&self, result: &VerifyResult, bundle: &ProofBundle);
}
pub trait ConstraintEvaluator {
fn evaluate(
&self,
constraint: &Constraint,
cert_id: &str,
context: &VerifierContext,
now: i64,
) -> Result<(), String>;
}
pub trait AnchorResolver {
fn resolve_anchor(&self, human_id: &str) -> Result<Option<Anchor>, String>;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PolicyVerdict {
pub version: i32,
pub verdict_id: String,
pub agent_id: String,
pub scope: String,
pub allow: bool,
#[serde(with = "crate::canonical::base64_bytes")]
pub context_hash: Vec<u8>, pub issued_at: i64,
pub valid_until: i64,
#[serde(with = "crate::canonical::base64_bytes")]
pub mac: Vec<u8>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerificationReceipt {
pub version: i32,
pub verifier_id: String,
pub verifier_pub: HybridPublicKey,
#[serde(with = "crate::canonical::base64_bytes")]
pub bundle_hash: Vec<u8>, pub decision: String,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub human_id: String,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub agent_id: String,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub granted_scope: Vec<String>,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub error_reason: String,
pub verified_at: i64,
#[serde(with = "crate::canonical::base64_bytes")]
pub prev_hash: Vec<u8>, pub signature: HybridSignature,
}
pub struct VerifyOptions<'a> {
pub required_scope: String,
#[deprecated(since = "1.0.0-alpha.7", note = "use `revocation` (SPEC §17.1) instead")]
#[allow(clippy::type_complexity)]
pub is_revoked: Option<Box<dyn Fn(&str) -> bool + 'a>>,
pub revocation: Option<Box<dyn RevocationProvider + 'a>>,
pub force_revocation_check: bool,
pub now: Option<i64>,
pub session_context: Vec<u8>,
pub stream: Option<StreamContext>,
pub context: VerifierContext<'a>,
pub policy: Option<Box<dyn PolicyProvider + 'a>>,
pub audit: Option<Box<dyn AuditProvider + 'a>>,
pub constraint_evaluators:
Option<alloc::collections::BTreeMap<String, Box<dyn ConstraintEvaluator + 'a>>>,
pub policy_verdict: Option<PolicyVerdict>,
pub policy_secret: Option<Vec<u8>>,
pub anchor_resolver: Option<Box<dyn AnchorResolver + 'a>>,
pub challenge_store: Option<Box<dyn crate::challenge_store::ChallengeStore + 'a>>,
}
#[allow(clippy::derivable_impls)]
impl<'a> Default for VerifyOptions<'a> {
fn default() -> Self {
#[allow(deprecated)]
Self {
required_scope: String::new(),
is_revoked: None,
revocation: None,
force_revocation_check: false,
now: None,
session_context: Vec::new(),
stream: None,
context: VerifierContext::default(),
policy: None,
audit: None,
constraint_evaluators: None,
policy_verdict: None,
policy_secret: None,
anchor_resolver: None,
challenge_store: None,
}
}
}