//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vault/credentials/query`. Version: `0.1`.
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
/// Error from a `TryFrom` or `FromStr` implementation.
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
///A body-free projection of a stored credential. Carries no claim content by construction.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Credential descriptor",
/// "description": "A body-free projection of a stored credential. Carries no claim content by construction.",
/// "type": "object",
/// "required": [
/// "id",
/// "status",
/// "types"
/// ],
/// "properties": {
/// "archivedAt": {
/// "description": "Present iff `lifecycle` is `archived`.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "deletedAt": {
/// "description": "Present iff `lifecycle` is `deleted`.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "graceUntil": {
/// "description": "Present iff `lifecycle` is `deleted`. Restorable while now < graceUntil.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "id": {
/// "description": "Local handle. Opaque to the consumer; the id `get`, `archive`, `delete` and the rest are keyed on.",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
/// },
/// "issuerDid": {
/// "$ref": "#/definitions/Did"
/// },
/// "lifecycle": {
/// "description": "Omitted for active credentials, so an active-only result is unchanged by this member's existence.",
/// "$ref": "#/definitions/VaultLifecycle"
/// },
/// "purpose": {
/// "$ref": "#/definitions/CredentialPurpose"
/// },
/// "status": {
/// "$ref": "#/definitions/CredentialStatus"
/// },
/// "types": {
/// "description": "VC `type` tags carried by the credential.",
/// "type": "array",
/// "items": {
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
/// }
/// },
/// "validFrom": {
/// "type": "string",
/// "format": "date-time"
/// },
/// "validUntil": {
/// "type": "string",
/// "format": "date-time"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct CredentialDescriptor {
///Present iff `lifecycle` is `archived`.
#[serde(
rename = "archivedAt",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub archived_at: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
///Present iff `lifecycle` is `deleted`.
#[serde(
rename = "deletedAt",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub deleted_at: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
///Present iff `lifecycle` is `deleted`. Restorable while now < graceUntil.
#[serde(
rename = "graceUntil",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub grace_until: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
///Local handle. Opaque to the consumer; the id `get`, `archive`, `delete` and the rest are keyed on.
pub id: CredentialDescriptorId,
#[serde(
rename = "issuerDid",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub issuer_did: ::std::option::Option<Did>,
///Omitted for active credentials, so an active-only result is unchanged by this member's existence.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub lifecycle: ::std::option::Option<VaultLifecycle>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub purpose: ::std::option::Option<CredentialPurpose>,
pub status: CredentialStatus,
///VC `type` tags carried by the credential.
pub types: ::std::vec::Vec<CredentialDescriptorTypesItem>,
#[serde(
rename = "validFrom",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub valid_from: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
#[serde(
rename = "validUntil",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub valid_until: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
}
impl CredentialDescriptor {
pub fn builder() -> builder::CredentialDescriptor {
Default::default()
}
}
///Local handle. Opaque to the consumer; the id `get`, `archive`, `delete` and the rest are keyed on.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Local handle. Opaque to the consumer; the id `get`, `archive`, `delete` and the rest are keyed on.",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct CredentialDescriptorId(::std::string::String);
impl ::std::ops::Deref for CredentialDescriptorId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<CredentialDescriptorId> for ::std::string::String {
fn from(value: CredentialDescriptorId) -> Self {
value.0
}
}
impl ::std::str::FromStr for CredentialDescriptorId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 256usize {
return Err("longer than 256 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for CredentialDescriptorId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for CredentialDescriptorId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for CredentialDescriptorId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for CredentialDescriptorId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`CredentialDescriptorTypesItem`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct CredentialDescriptorTypesItem(::std::string::String);
impl ::std::ops::Deref for CredentialDescriptorTypesItem {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<CredentialDescriptorTypesItem> for ::std::string::String {
fn from(value: CredentialDescriptorTypesItem) -> Self {
value.0
}
}
impl ::std::str::FromStr for CredentialDescriptorTypesItem {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 256usize {
return Err("longer than 256 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for CredentialDescriptorTypesItem {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for CredentialDescriptorTypesItem {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for CredentialDescriptorTypesItem {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for CredentialDescriptorTypesItem {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Semantic classification. `invite`, `membership`, `role`, `endorsement` and `personhood` are defined; a maintainer MAY use another token.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Semantic classification. `invite`, `membership`, `role`, `endorsement` and `personhood` are defined; a maintainer MAY use another token.",
/// "type": "string",
/// "maxLength": 128,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct CredentialPurpose(::std::string::String);
impl ::std::ops::Deref for CredentialPurpose {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<CredentialPurpose> for ::std::string::String {
fn from(value: CredentialPurpose) -> Self {
value.0
}
}
impl ::std::str::FromStr for CredentialPurpose {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 128usize {
return Err("longer than 128 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for CredentialPurpose {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for CredentialPurpose {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for CredentialPurpose {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for CredentialPurpose {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Validity, driven by the credential's own window and by status-list checks. Orthogonal to lifecycle.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Validity, driven by the credential's own window and by status-list checks. Orthogonal to lifecycle.",
/// "type": "string",
/// "enum": [
/// "valid",
/// "expired",
/// "revoked",
/// "unknown"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum CredentialStatus {
#[serde(rename = "valid")]
Valid,
#[serde(rename = "expired")]
Expired,
#[serde(rename = "revoked")]
Revoked,
#[serde(rename = "unknown")]
Unknown,
}
impl ::std::fmt::Display for CredentialStatus {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Valid => f.write_str("valid"),
Self::Expired => f.write_str("expired"),
Self::Revoked => f.write_str("revoked"),
Self::Unknown => f.write_str("unknown"),
}
}
}
impl ::std::str::FromStr for CredentialStatus {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"valid" => Ok(Self::Valid),
"expired" => Ok(Self::Expired),
"revoked" => Ok(Self::Revoked),
"unknown" => Ok(Self::Unknown),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for CredentialStatus {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for CredentialStatus {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for CredentialStatus {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///`Did`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "maxLength": 2048,
/// "pattern": "^did:[a-z0-9]+:.+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct Did(::std::string::String);
impl ::std::ops::Deref for Did {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<Did> for ::std::string::String {
fn from(value: Did) -> Self {
value.0
}
}
impl ::std::str::FromStr for Did {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 2048usize {
return Err("longer than 2048 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^did:[a-z0-9]+:.+$").unwrap());
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^did:[a-z0-9]+:.+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for Did {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for Did {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for Did {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for Did {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A filtered, body-free search over stored credentials. At least one of `type`, `communityDid`, `issuerDid`, `purpose` or `status` MUST be present — see the specification; `includeArchived` and `includeDeleted` are modifiers and do not satisfy that requirement.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/vault/credentials/query/0.1",
/// "title": "Payload",
/// "description": "A filtered, body-free search over stored credentials. At least one of `type`, `communityDid`, `issuerDid`, `purpose` or `status` MUST be present — see the specification; `includeArchived` and `includeDeleted` are modifiers and do not satisfy that requirement.",
/// "type": "object",
/// "properties": {
/// "communityDid": {
/// "description": "Match credentials held for this community or context DID.",
/// "$ref": "#/definitions/Did"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "includeArchived": {
/// "description": "Modifier, not a filter: also return archived credentials matching the other constraints. Absent means false.",
/// "type": "boolean"
/// },
/// "includeDeleted": {
/// "description": "Modifier, not a filter: also return soft-deleted tombstones matching the other constraints. Absent means false.",
/// "type": "boolean"
/// },
/// "issuerDid": {
/// "description": "Match credentials issued by this DID.",
/// "$ref": "#/definitions/Did"
/// },
/// "purpose": {
/// "description": "Match the maintainer's semantic classification of the credential.",
/// "$ref": "#/definitions/CredentialPurpose"
/// },
/// "status": {
/// "description": "Match the validity dimension.",
/// "$ref": "#/definitions/CredentialStatus"
/// },
/// "type": {
/// "description": "Match credentials carrying this VC `type` tag.",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Match credentials held for this community or context DID.
#[serde(
rename = "communityDid",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub community_did: ::std::option::Option<Did>,
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Modifier, not a filter: also return archived credentials matching the other constraints. Absent means false.
#[serde(
rename = "includeArchived",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub include_archived: ::std::option::Option<bool>,
///Modifier, not a filter: also return soft-deleted tombstones matching the other constraints. Absent means false.
#[serde(
rename = "includeDeleted",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub include_deleted: ::std::option::Option<bool>,
///Match credentials issued by this DID.
#[serde(
rename = "issuerDid",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub issuer_did: ::std::option::Option<Did>,
///Match the maintainer's semantic classification of the credential.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub purpose: ::std::option::Option<CredentialPurpose>,
///Match the validity dimension.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub status: ::std::option::Option<CredentialStatus>,
///Match credentials carrying this VC `type` tag.
#[serde(
rename = "type",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub type_: ::std::option::Option<PayloadType>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
community_did: Default::default(),
ext: Default::default(),
include_archived: Default::default(),
include_deleted: Default::default(),
issuer_did: Default::default(),
purpose: Default::default(),
status: Default::default(),
type_: Default::default(),
}
}
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Match credentials carrying this VC `type` tag.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Match credentials carrying this VC `type` tag.",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadType(::std::string::String);
impl ::std::ops::Deref for PayloadType {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadType> for ::std::string::String {
fn from(value: PayloadType) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadType {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 256usize {
return Err("longer than 256 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadType {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadType {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadType {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadType {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`Response`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "type": "object",
/// "required": [
/// "credentials"
/// ],
/// "properties": {
/// "credentials": {
/// "description": "Matching descriptors. Empty when nothing matched — a successful answer, not an error.",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/CredentialDescriptor"
/// }
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///Matching descriptors. Empty when nothing matched — a successful answer, not an error.
pub credentials: ::std::vec::Vec<CredentialDescriptor>,
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///Archival state, chosen through this family. Orthogonal to validity.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Archival state, chosen through this family. Orthogonal to validity.",
/// "type": "string",
/// "enum": [
/// "active",
/// "archived",
/// "deleted"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum VaultLifecycle {
#[serde(rename = "active")]
Active,
#[serde(rename = "archived")]
Archived,
#[serde(rename = "deleted")]
Deleted,
}
impl ::std::fmt::Display for VaultLifecycle {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Active => f.write_str("active"),
Self::Archived => f.write_str("archived"),
Self::Deleted => f.write_str("deleted"),
}
}
}
impl ::std::str::FromStr for VaultLifecycle {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"active" => Ok(Self::Active),
"archived" => Ok(Self::Archived),
"deleted" => Ok(Self::Deleted),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for VaultLifecycle {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for VaultLifecycle {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for VaultLifecycle {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct CredentialDescriptor {
archived_at: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
deleted_at: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
grace_until: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
id: ::std::result::Result<super::CredentialDescriptorId, ::std::string::String>,
issuer_did: ::std::result::Result<::std::option::Option<super::Did>, ::std::string::String>,
lifecycle: ::std::result::Result<
::std::option::Option<super::VaultLifecycle>,
::std::string::String,
>,
purpose: ::std::result::Result<
::std::option::Option<super::CredentialPurpose>,
::std::string::String,
>,
status: ::std::result::Result<super::CredentialStatus, ::std::string::String>,
types: ::std::result::Result<
::std::vec::Vec<super::CredentialDescriptorTypesItem>,
::std::string::String,
>,
valid_from: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
valid_until: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
}
impl ::std::default::Default for CredentialDescriptor {
fn default() -> Self {
Self {
archived_at: Ok(Default::default()),
deleted_at: Ok(Default::default()),
grace_until: Ok(Default::default()),
id: Err("no value supplied for id".to_string()),
issuer_did: Ok(Default::default()),
lifecycle: Ok(Default::default()),
purpose: Ok(Default::default()),
status: Err("no value supplied for status".to_string()),
types: Err("no value supplied for types".to_string()),
valid_from: Ok(Default::default()),
valid_until: Ok(Default::default()),
}
}
}
impl CredentialDescriptor {
pub fn archived_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.archived_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for archived_at: {e}"));
self
}
pub fn deleted_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.deleted_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for deleted_at: {e}"));
self
}
pub fn grace_until<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.grace_until = value
.try_into()
.map_err(|e| format!("error converting supplied value for grace_until: {e}"));
self
}
pub fn id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::CredentialDescriptorId>,
T::Error: ::std::fmt::Display,
{
self.id = value
.try_into()
.map_err(|e| format!("error converting supplied value for id: {e}"));
self
}
pub fn issuer_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Did>>,
T::Error: ::std::fmt::Display,
{
self.issuer_did = value
.try_into()
.map_err(|e| format!("error converting supplied value for issuer_did: {e}"));
self
}
pub fn lifecycle<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::VaultLifecycle>>,
T::Error: ::std::fmt::Display,
{
self.lifecycle = value
.try_into()
.map_err(|e| format!("error converting supplied value for lifecycle: {e}"));
self
}
pub fn purpose<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::CredentialPurpose>>,
T::Error: ::std::fmt::Display,
{
self.purpose = value
.try_into()
.map_err(|e| format!("error converting supplied value for purpose: {e}"));
self
}
pub fn status<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::CredentialStatus>,
T::Error: ::std::fmt::Display,
{
self.status = value
.try_into()
.map_err(|e| format!("error converting supplied value for status: {e}"));
self
}
pub fn types<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::CredentialDescriptorTypesItem>>,
T::Error: ::std::fmt::Display,
{
self.types = value
.try_into()
.map_err(|e| format!("error converting supplied value for types: {e}"));
self
}
pub fn valid_from<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.valid_from = value
.try_into()
.map_err(|e| format!("error converting supplied value for valid_from: {e}"));
self
}
pub fn valid_until<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.valid_until = value
.try_into()
.map_err(|e| format!("error converting supplied value for valid_until: {e}"));
self
}
}
impl ::std::convert::TryFrom<CredentialDescriptor> for super::CredentialDescriptor {
type Error = super::error::ConversionError;
fn try_from(
value: CredentialDescriptor,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
archived_at: value.archived_at?,
deleted_at: value.deleted_at?,
grace_until: value.grace_until?,
id: value.id?,
issuer_did: value.issuer_did?,
lifecycle: value.lifecycle?,
purpose: value.purpose?,
status: value.status?,
types: value.types?,
valid_from: value.valid_from?,
valid_until: value.valid_until?,
})
}
}
impl ::std::convert::From<super::CredentialDescriptor> for CredentialDescriptor {
fn from(value: super::CredentialDescriptor) -> Self {
Self {
archived_at: Ok(value.archived_at),
deleted_at: Ok(value.deleted_at),
grace_until: Ok(value.grace_until),
id: Ok(value.id),
issuer_did: Ok(value.issuer_did),
lifecycle: Ok(value.lifecycle),
purpose: Ok(value.purpose),
status: Ok(value.status),
types: Ok(value.types),
valid_from: Ok(value.valid_from),
valid_until: Ok(value.valid_until),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
community_did:
::std::result::Result<::std::option::Option<super::Did>, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
include_archived: ::std::result::Result<::std::option::Option<bool>, ::std::string::String>,
include_deleted: ::std::result::Result<::std::option::Option<bool>, ::std::string::String>,
issuer_did: ::std::result::Result<::std::option::Option<super::Did>, ::std::string::String>,
purpose: ::std::result::Result<
::std::option::Option<super::CredentialPurpose>,
::std::string::String,
>,
status: ::std::result::Result<
::std::option::Option<super::CredentialStatus>,
::std::string::String,
>,
type_:
::std::result::Result<::std::option::Option<super::PayloadType>, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
community_did: Ok(Default::default()),
ext: Ok(Default::default()),
include_archived: Ok(Default::default()),
include_deleted: Ok(Default::default()),
issuer_did: Ok(Default::default()),
purpose: Ok(Default::default()),
status: Ok(Default::default()),
type_: Ok(Default::default()),
}
}
}
impl Payload {
pub fn community_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Did>>,
T::Error: ::std::fmt::Display,
{
self.community_did = value
.try_into()
.map_err(|e| format!("error converting supplied value for community_did: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn include_archived<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<bool>>,
T::Error: ::std::fmt::Display,
{
self.include_archived = value
.try_into()
.map_err(|e| format!("error converting supplied value for include_archived: {e}"));
self
}
pub fn include_deleted<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<bool>>,
T::Error: ::std::fmt::Display,
{
self.include_deleted = value
.try_into()
.map_err(|e| format!("error converting supplied value for include_deleted: {e}"));
self
}
pub fn issuer_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Did>>,
T::Error: ::std::fmt::Display,
{
self.issuer_did = value
.try_into()
.map_err(|e| format!("error converting supplied value for issuer_did: {e}"));
self
}
pub fn purpose<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::CredentialPurpose>>,
T::Error: ::std::fmt::Display,
{
self.purpose = value
.try_into()
.map_err(|e| format!("error converting supplied value for purpose: {e}"));
self
}
pub fn status<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::CredentialStatus>>,
T::Error: ::std::fmt::Display,
{
self.status = value
.try_into()
.map_err(|e| format!("error converting supplied value for status: {e}"));
self
}
pub fn type_<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadType>>,
T::Error: ::std::fmt::Display,
{
self.type_ = value
.try_into()
.map_err(|e| format!("error converting supplied value for type_: {e}"));
self
}
}
impl ::std::convert::TryFrom<Payload> for super::Payload {
type Error = super::error::ConversionError;
fn try_from(value: Payload) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
community_did: value.community_did?,
ext: value.ext?,
include_archived: value.include_archived?,
include_deleted: value.include_deleted?,
issuer_did: value.issuer_did?,
purpose: value.purpose?,
status: value.status?,
type_: value.type_?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
community_did: Ok(value.community_did),
ext: Ok(value.ext),
include_archived: Ok(value.include_archived),
include_deleted: Ok(value.include_deleted),
issuer_did: Ok(value.issuer_did),
purpose: Ok(value.purpose),
status: Ok(value.status),
type_: Ok(value.type_),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
credentials: ::std::result::Result<
::std::vec::Vec<super::CredentialDescriptor>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
credentials: Err("no value supplied for credentials".to_string()),
ext: Ok(Default::default()),
}
}
}
impl Response {
pub fn credentials<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::CredentialDescriptor>>,
T::Error: ::std::fmt::Display,
{
self.credentials = value
.try_into()
.map_err(|e| format!("error converting supplied value for credentials: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
credentials: value.credentials?,
ext: value.ext?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
credentials: Ok(value.credentials),
ext: Ok(value.ext),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vault/credentials/query/0.1";
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"CredentialDescriptor\": {\n \"additionalProperties\": false,\n \"description\": \"A body-free projection of a stored credential. Carries no claim content by construction.\",\n \"properties\": {\n \"archivedAt\": {\n \"description\": \"Present iff `lifecycle` is `archived`.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"deletedAt\": {\n \"description\": \"Present iff `lifecycle` is `deleted`.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"graceUntil\": {\n \"description\": \"Present iff `lifecycle` is `deleted`. Restorable while now < graceUntil.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"id\": {\n \"description\": \"Local handle. Opaque to the consumer; the id `get`, `archive`, `delete` and the rest are keyed on.\",\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"issuerDid\": {\n \"$ref\": \"#/$defs/Did\"\n },\n \"lifecycle\": {\n \"$ref\": \"#/$defs/VaultLifecycle\",\n \"description\": \"Omitted for active credentials, so an active-only result is unchanged by this member's existence.\"\n },\n \"purpose\": {\n \"$ref\": \"#/$defs/CredentialPurpose\"\n },\n \"status\": {\n \"$ref\": \"#/$defs/CredentialStatus\"\n },\n \"types\": {\n \"description\": \"VC `type` tags carried by the credential.\",\n \"items\": {\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"type\": \"array\"\n },\n \"validFrom\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"validUntil\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"id\",\n \"types\",\n \"status\"\n ],\n \"title\": \"Credential descriptor\",\n \"type\": \"object\"\n },\n \"CredentialPurpose\": {\n \"description\": \"Semantic classification. `invite`, `membership`, `role`, `endorsement` and `personhood` are defined; a maintainer MAY use another token.\",\n \"maxLength\": 128,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"CredentialStatus\": {\n \"description\": \"Validity, driven by the credential's own window and by status-list checks. Orthogonal to lifecycle.\",\n \"enum\": [\n \"valid\",\n \"expired\",\n \"revoked\",\n \"unknown\"\n ],\n \"type\": \"string\"\n },\n \"Did\": {\n \"maxLength\": 2048,\n \"pattern\": \"^did:[a-z0-9]+:.+$\",\n \"type\": \"string\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"credentials\": {\n \"description\": \"Matching descriptors. Empty when nothing matched — a successful answer, not an error.\",\n \"items\": {\n \"$ref\": \"#/$defs/CredentialDescriptor\"\n },\n \"type\": \"array\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n }\n },\n \"required\": [\n \"credentials\"\n ],\n \"title\": \"Vault Credentials Query — response payload\",\n \"type\": \"object\"\n },\n \"VaultLifecycle\": {\n \"description\": \"Archival state, chosen through this family. Orthogonal to validity.\",\n \"enum\": [\n \"active\",\n \"archived\",\n \"deleted\"\n ],\n \"type\": \"string\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/vault/credentials/query/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"A filtered, body-free search over stored credentials. At least one of `type`, `communityDid`, `issuerDid`, `purpose` or `status` MUST be present — see the specification; `includeArchived` and `includeDeleted` are modifiers and do not satisfy that requirement.\",\n \"properties\": {\n \"communityDid\": {\n \"$ref\": \"#/$defs/Did\",\n \"description\": \"Match credentials held for this community or context DID.\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"includeArchived\": {\n \"description\": \"Modifier, not a filter: also return archived credentials matching the other constraints. Absent means false.\",\n \"type\": \"boolean\"\n },\n \"includeDeleted\": {\n \"description\": \"Modifier, not a filter: also return soft-deleted tombstones matching the other constraints. Absent means false.\",\n \"type\": \"boolean\"\n },\n \"issuerDid\": {\n \"$ref\": \"#/$defs/Did\",\n \"description\": \"Match credentials issued by this DID.\"\n },\n \"purpose\": {\n \"$ref\": \"#/$defs/CredentialPurpose\",\n \"description\": \"Match the maintainer's semantic classification of the credential.\"\n },\n \"status\": {\n \"$ref\": \"#/$defs/CredentialStatus\",\n \"description\": \"Match the validity dimension.\"\n },\n \"type\": {\n \"description\": \"Match credentials carrying this VC `type` tag.\",\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"title\": \"Vault Credentials — Query\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/vault/credentials/query/0.1#response";
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"CredentialDescriptor\": {\n \"additionalProperties\": false,\n \"description\": \"A body-free projection of a stored credential. Carries no claim content by construction.\",\n \"properties\": {\n \"archivedAt\": {\n \"description\": \"Present iff `lifecycle` is `archived`.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"deletedAt\": {\n \"description\": \"Present iff `lifecycle` is `deleted`.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"graceUntil\": {\n \"description\": \"Present iff `lifecycle` is `deleted`. Restorable while now < graceUntil.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"id\": {\n \"description\": \"Local handle. Opaque to the consumer; the id `get`, `archive`, `delete` and the rest are keyed on.\",\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"issuerDid\": {\n \"$ref\": \"#/$defs/Did\"\n },\n \"lifecycle\": {\n \"$ref\": \"#/$defs/VaultLifecycle\",\n \"description\": \"Omitted for active credentials, so an active-only result is unchanged by this member's existence.\"\n },\n \"purpose\": {\n \"$ref\": \"#/$defs/CredentialPurpose\"\n },\n \"status\": {\n \"$ref\": \"#/$defs/CredentialStatus\"\n },\n \"types\": {\n \"description\": \"VC `type` tags carried by the credential.\",\n \"items\": {\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"type\": \"array\"\n },\n \"validFrom\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"validUntil\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"id\",\n \"types\",\n \"status\"\n ],\n \"title\": \"Credential descriptor\",\n \"type\": \"object\"\n },\n \"CredentialPurpose\": {\n \"description\": \"Semantic classification. `invite`, `membership`, `role`, `endorsement` and `personhood` are defined; a maintainer MAY use another token.\",\n \"maxLength\": 128,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"CredentialStatus\": {\n \"description\": \"Validity, driven by the credential's own window and by status-list checks. Orthogonal to lifecycle.\",\n \"enum\": [\n \"valid\",\n \"expired\",\n \"revoked\",\n \"unknown\"\n ],\n \"type\": \"string\"\n },\n \"Did\": {\n \"maxLength\": 2048,\n \"pattern\": \"^did:[a-z0-9]+:.+$\",\n \"type\": \"string\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"credentials\": {\n \"description\": \"Matching descriptors. Empty when nothing matched — a successful answer, not an error.\",\n \"items\": {\n \"$ref\": \"#/$defs/CredentialDescriptor\"\n },\n \"type\": \"array\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n }\n },\n \"required\": [\n \"credentials\"\n ],\n \"title\": \"Vault Credentials Query — response payload\",\n \"type\": \"object\"\n },\n \"VaultLifecycle\": {\n \"description\": \"Archival state, chosen through this family. Orthogonal to validity.\",\n \"enum\": [\n \"active\",\n \"archived\",\n \"deleted\"\n ],\n \"type\": \"string\"\n }\n },\n \"$ref\": \"#/$defs/Response\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\"\n}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
#[cfg(test)]
mod conformance {
//! Round-trip tests harvested from the spec's `spec.md`,
//! plus a `rejects_invalid_examples` test for any fixtures
//! in `payload.invalid-examples.json` (validate feature).
#[test]
fn request_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:00000000-0000-4000-8000-000000000001\",\n \"type\": \"https://trusttasks.org/spec/vault/credentials/query/0.1#request\",\n \"issuer\": \"did:example:wallet\",\n \"recipient\": \"did:example:agent\",\n \"issuedAt\": \"2026-01-01T00:00:00Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"purpose\": \"membership\",\n \"communityDid\": \"did:web:community.example\"\n }\n}\n";
let doc: crate::TrustTask<super::Payload> =
serde_json::from_str(JSON).expect("deserialize request example");
let rendered = serde_json::to_value(&doc).expect("re-serialize");
let expected: serde_json::Value = serde_json::from_str(JSON).expect("re-parse expected");
assert_eq!(rendered, expected, "request example failed round-trip");
}
#[test]
fn response_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:00000000-0000-4000-8000-000000000002\",\n \"type\": \"https://trusttasks.org/spec/vault/credentials/query/0.1#response\",\n \"issuer\": \"did:example:agent\",\n \"recipient\": \"did:example:wallet\",\n \"issuedAt\": \"2026-01-01T00:00:01Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"credentials\": [\n {\n \"id\": \"cred-7f3a91c2\",\n \"types\": [\"VerifiableCredential\", \"MembershipCredential\"],\n \"issuerDid\": \"did:web:community.example\",\n \"purpose\": \"membership\",\n \"status\": \"valid\",\n \"validFrom\": \"2026-01-01T00:00:00Z\",\n \"validUntil\": \"2027-01-01T00:00:00Z\"\n }\n ]\n }\n}\n";
let doc: crate::TrustTask<super::Response> =
serde_json::from_str(JSON).expect("deserialize response example");
let rendered = serde_json::to_value(&doc).expect("re-serialize");
let expected: serde_json::Value = serde_json::from_str(JSON).expect("re-parse expected");
assert_eq!(rendered, expected, "response example failed round-trip");
}
/// Each fixture in `payload.invalid-examples.json` MUST be
/// rejected by at least one of: serde deserialization, or
/// JSON-Schema validation under the `validate` feature. The
/// fixture file documents the producer-side bug class that
/// each payload exemplifies; this generated test pins it.
#[cfg(feature = "validate")]
#[test]
fn rejects_invalid_examples() {
use crate::validate::ValidatedPayload;
let fixtures: &[(&str, &str)] = &[
(
"Unknown top-level member — additionalProperties: false catches `frobnicate`.",
"{\n \"frobnicate\": true,\n \"purpose\": \"membership\"\n}",
),
(
"Bare/unnamespaced ext key — SPEC §4.5.1 requires every immediate child of ext to be reverse-DNS namespaced.",
"{\n \"ext\": {\n \"bare-key\": {\n \"anything\": \"here\"\n }\n },\n \"purpose\": \"membership\"\n}",
),
(
"status outside the validity enum. `archived` is a lifecycle state, and conflating the two axes is the misreading this schema exists to prevent.",
"{\n \"status\": \"archived\"\n}",
),
(
"issuerDid that is not a DID.",
"{\n \"issuerDid\": \"https://issuer.example\"\n}",
),
];
for (i, (note, raw)) in fixtures.iter().enumerate() {
let value: serde_json::Value = match serde_json::from_str(raw) {
Ok(v) => v,
Err(_) => continue,
};
let serde_ok = serde_json::from_value::<super::Payload>(value.clone()).is_ok();
let schema_ok = super::Payload::validate_value(&value).is_ok();
assert!(
!(serde_ok && schema_ok),
"invalid-example #{} ({:?}) was accepted by both serde and JSON Schema; \
the fixture's stated failure class is no longer caught:\n{}",
i + 1,
note,
raw
);
}
}
}