use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CapabilitiesDocument {
pub acdp_version: String,
pub registry_did: String,
pub supported_signature_algorithms: Vec<String>,
pub supported_did_methods: Vec<String>,
pub profiles: Vec<String>,
pub limits: Limits,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub read_authentication_methods: Vec<String>,
#[serde(default)]
pub anonymous_public_reads: bool,
#[serde(default)]
pub supports_idempotency_key: bool,
#[serde(flatten)]
pub extensions: serde_json::Map<String, serde_json::Value>,
}
impl CapabilitiesDocument {
pub fn supports_discovery(&self) -> bool {
self.profiles.iter().any(|p| p == "acdp-registry-discovery")
}
pub fn supports_federation(&self) -> bool {
self.profiles.iter().any(|p| p == "acdp-registry-federated")
}
pub fn supports_algorithm(&self, algorithm: &str) -> bool {
self.supported_signature_algorithms
.iter()
.any(|a| a == algorithm)
}
pub fn supports_did_method(&self, method: &str) -> bool {
self.supported_did_methods.iter().any(|m| m == method)
}
pub fn idempotency_ttl(&self) -> Option<std::time::Duration> {
self.limits
.idempotency_key_ttl_seconds
.map(|s| std::time::Duration::from_secs(u64::from(s)))
}
pub fn requires_anonymous_auth(&self) -> bool {
!self.anonymous_public_reads
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Limits {
pub max_payload_bytes: u64,
pub max_embedded_bytes: u64,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "crate::types::serde_helpers::de_present"
)]
pub idempotency_key_ttl_seconds: Option<u32>,
}