//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `did-management/did/log`. 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())
}
}
}
///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())
})
}
}
///`Payload`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/did-management/did/log/0.1",
/// "title": "Payload",
/// "type": "object",
/// "required": [
/// "mnemonic"
/// ],
/// "properties": {
/// "domain": {
/// "description": "Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain.",
/// "type": "string",
/// "maxLength": 253,
/// "minLength": 1
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "mnemonic": {
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
/// },
/// "raw": {
/// "description": "When true, the response also carries the stored artifacts verbatim. Absent or false means parsed entries only.",
/// "type": "boolean"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub domain: ::std::option::Option<PayloadDomain>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
pub mnemonic: PayloadMnemonic,
///When true, the response also carries the stored artifacts verbatim. Absent or false means parsed entries only.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub raw: ::std::option::Option<bool>,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain.",
/// "type": "string",
/// "maxLength": 253,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadDomain(::std::string::String);
impl ::std::ops::Deref for PayloadDomain {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadDomain> for ::std::string::String {
fn from(value: PayloadDomain) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadDomain {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 253usize {
return Err("longer than 253 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 PayloadDomain {
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 PayloadDomain {
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 PayloadDomain {
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 PayloadDomain {
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())
})
}
}
///`PayloadMnemonic`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadMnemonic(::std::string::String);
impl ::std::ops::Deref for PayloadMnemonic {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadMnemonic> for ::std::string::String {
fn from(value: PayloadMnemonic) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadMnemonic {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 512usize {
return Err("longer than 512 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 PayloadMnemonic {
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 PayloadMnemonic {
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 PayloadMnemonic {
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 PayloadMnemonic {
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": [
/// "entries",
/// "method",
/// "mnemonic"
/// ],
/// "properties": {
/// "entries": {
/// "description": "The slot's history, oldest first. For did:webvh, one per log line; for a method with no log (did:web) a single entry for the current document; for did:webs one per establishment event that changed the document.",
/// "type": "array",
/// "items": {
/// "type": "object",
/// "required": [
/// "state"
/// ],
/// "properties": {
/// "parameters": {
/// "description": "The method's parameters as of this entry (did:webvh log parameters). Absent for a method that has none.",
/// "type": "object"
/// },
/// "state": {
/// "description": "The DID document as of this entry.",
/// "type": "object"
/// },
/// "versionId": {
/// "description": "The entry's version identifier. Absent for a method that has none.",
/// "type": "string"
/// },
/// "versionTime": {
/// "description": "When the entry was made, as the entry states it. Absent for a method that records none.",
/// "type": "string",
/// "format": "date-time"
/// }
/// },
/// "additionalProperties": false
/// }
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "logContent": {
/// "description": "The stored primary artifact verbatim — did.jsonl for did:webvh, the key event stream for did:webs, did.json for did:web. Present iff the request set raw: true.",
/// "type": "string"
/// },
/// "method": {
/// "description": "The slot's DID method (`webvh`, `web`, `webs`, …). Determines what an entry is.",
/// "type": "string",
/// "minLength": 1
/// },
/// "mnemonic": {
/// "type": "string"
/// },
/// "witnessContent": {
/// "description": "The stored did-witness.json verbatim. Present iff the request set raw: true and the slot holds witness proofs.",
/// "type": "string"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///The slot's history, oldest first. For did:webvh, one per log line; for a method with no log (did:web) a single entry for the current document; for did:webs one per establishment event that changed the document.
pub entries: ::std::vec::Vec<ResponseEntriesItem>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The stored primary artifact verbatim — did.jsonl for did:webvh, the key event stream for did:webs, did.json for did:web. Present iff the request set raw: true.
#[serde(
rename = "logContent",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub log_content: ::std::option::Option<::std::string::String>,
///The slot's DID method (`webvh`, `web`, `webs`, …). Determines what an entry is.
pub method: ResponseMethod,
pub mnemonic: ::std::string::String,
///The stored did-witness.json verbatim. Present iff the request set raw: true and the slot holds witness proofs.
#[serde(
rename = "witnessContent",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub witness_content: ::std::option::Option<::std::string::String>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`ResponseEntriesItem`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "object",
/// "required": [
/// "state"
/// ],
/// "properties": {
/// "parameters": {
/// "description": "The method's parameters as of this entry (did:webvh log parameters). Absent for a method that has none.",
/// "type": "object"
/// },
/// "state": {
/// "description": "The DID document as of this entry.",
/// "type": "object"
/// },
/// "versionId": {
/// "description": "The entry's version identifier. Absent for a method that has none.",
/// "type": "string"
/// },
/// "versionTime": {
/// "description": "When the entry was made, as the entry states it. Absent for a method that records none.",
/// "type": "string",
/// "format": "date-time"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct ResponseEntriesItem {
///The method's parameters as of this entry (did:webvh log parameters). Absent for a method that has none.
#[serde(default, skip_serializing_if = "::serde_json::Map::is_empty")]
pub parameters: ::serde_json::Map<::std::string::String, ::serde_json::Value>,
///The DID document as of this entry.
pub state: ::serde_json::Map<::std::string::String, ::serde_json::Value>,
///The entry's version identifier. Absent for a method that has none.
#[serde(
rename = "versionId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub version_id: ::std::option::Option<::std::string::String>,
///When the entry was made, as the entry states it. Absent for a method that records none.
#[serde(
rename = "versionTime",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub version_time: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
}
impl ResponseEntriesItem {
pub fn builder() -> builder::ResponseEntriesItem {
Default::default()
}
}
///The slot's DID method (`webvh`, `web`, `webs`, …). Determines what an entry is.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The slot's DID method (`webvh`, `web`, `webs`, …). Determines what an entry is.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseMethod(::std::string::String);
impl ::std::ops::Deref for ResponseMethod {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseMethod> for ::std::string::String {
fn from(value: ResponseMethod) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseMethod {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseMethod {
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 ResponseMethod {
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 ResponseMethod {
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 ResponseMethod {
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())
})
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct Payload {
domain: ::std::result::Result<
::std::option::Option<super::PayloadDomain>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
mnemonic: ::std::result::Result<super::PayloadMnemonic, ::std::string::String>,
raw: ::std::result::Result<::std::option::Option<bool>, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
domain: Ok(Default::default()),
ext: Ok(Default::default()),
mnemonic: Err("no value supplied for mnemonic".to_string()),
raw: Ok(Default::default()),
}
}
}
impl Payload {
pub fn domain<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadDomain>>,
T::Error: ::std::fmt::Display,
{
self.domain = value
.try_into()
.map_err(|e| format!("error converting supplied value for domain: {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 mnemonic<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadMnemonic>,
T::Error: ::std::fmt::Display,
{
self.mnemonic = value
.try_into()
.map_err(|e| format!("error converting supplied value for mnemonic: {e}"));
self
}
pub fn raw<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<bool>>,
T::Error: ::std::fmt::Display,
{
self.raw = value
.try_into()
.map_err(|e| format!("error converting supplied value for raw: {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 {
domain: value.domain?,
ext: value.ext?,
mnemonic: value.mnemonic?,
raw: value.raw?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
domain: Ok(value.domain),
ext: Ok(value.ext),
mnemonic: Ok(value.mnemonic),
raw: Ok(value.raw),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
entries: ::std::result::Result<
::std::vec::Vec<super::ResponseEntriesItem>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
log_content: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
method: ::std::result::Result<super::ResponseMethod, ::std::string::String>,
mnemonic: ::std::result::Result<::std::string::String, ::std::string::String>,
witness_content: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
entries: Err("no value supplied for entries".to_string()),
ext: Ok(Default::default()),
log_content: Ok(Default::default()),
method: Err("no value supplied for method".to_string()),
mnemonic: Err("no value supplied for mnemonic".to_string()),
witness_content: Ok(Default::default()),
}
}
}
impl Response {
pub fn entries<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::ResponseEntriesItem>>,
T::Error: ::std::fmt::Display,
{
self.entries = value
.try_into()
.map_err(|e| format!("error converting supplied value for entries: {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 log_content<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.log_content = value
.try_into()
.map_err(|e| format!("error converting supplied value for log_content: {e}"));
self
}
pub fn method<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseMethod>,
T::Error: ::std::fmt::Display,
{
self.method = value
.try_into()
.map_err(|e| format!("error converting supplied value for method: {e}"));
self
}
pub fn mnemonic<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::string::String>,
T::Error: ::std::fmt::Display,
{
self.mnemonic = value
.try_into()
.map_err(|e| format!("error converting supplied value for mnemonic: {e}"));
self
}
pub fn witness_content<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.witness_content = value
.try_into()
.map_err(|e| format!("error converting supplied value for witness_content: {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 {
entries: value.entries?,
ext: value.ext?,
log_content: value.log_content?,
method: value.method?,
mnemonic: value.mnemonic?,
witness_content: value.witness_content?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
entries: Ok(value.entries),
ext: Ok(value.ext),
log_content: Ok(value.log_content),
method: Ok(value.method),
mnemonic: Ok(value.mnemonic),
witness_content: Ok(value.witness_content),
}
}
}
#[derive(Clone, Debug)]
pub struct ResponseEntriesItem {
parameters: ::std::result::Result<
::serde_json::Map<::std::string::String, ::serde_json::Value>,
::std::string::String,
>,
state: ::std::result::Result<
::serde_json::Map<::std::string::String, ::serde_json::Value>,
::std::string::String,
>,
version_id: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
version_time: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
}
impl ::std::default::Default for ResponseEntriesItem {
fn default() -> Self {
Self {
parameters: Ok(Default::default()),
state: Err("no value supplied for state".to_string()),
version_id: Ok(Default::default()),
version_time: Ok(Default::default()),
}
}
}
impl ResponseEntriesItem {
pub fn parameters<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::serde_json::Map<::std::string::String, ::serde_json::Value>,
>,
T::Error: ::std::fmt::Display,
{
self.parameters = value
.try_into()
.map_err(|e| format!("error converting supplied value for parameters: {e}"));
self
}
pub fn state<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::serde_json::Map<::std::string::String, ::serde_json::Value>,
>,
T::Error: ::std::fmt::Display,
{
self.state = value
.try_into()
.map_err(|e| format!("error converting supplied value for state: {e}"));
self
}
pub fn version_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.version_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for version_id: {e}"));
self
}
pub fn version_time<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.version_time = value
.try_into()
.map_err(|e| format!("error converting supplied value for version_time: {e}"));
self
}
}
impl ::std::convert::TryFrom<ResponseEntriesItem> for super::ResponseEntriesItem {
type Error = super::error::ConversionError;
fn try_from(
value: ResponseEntriesItem,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
parameters: value.parameters?,
state: value.state?,
version_id: value.version_id?,
version_time: value.version_time?,
})
}
}
impl ::std::convert::From<super::ResponseEntriesItem> for ResponseEntriesItem {
fn from(value: super::ResponseEntriesItem) -> Self {
Self {
parameters: Ok(value.parameters),
state: Ok(value.state),
version_id: Ok(value.version_id),
version_time: Ok(value.version_time),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/did-management/did/log/0.1";
const IS_PROOF_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\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 \"entries\": {\n \"description\": \"The slot's history, oldest first. For did:webvh, one per log line; for a method with no log (did:web) a single entry for the current document; for did:webs one per establishment event that changed the document.\",\n \"items\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"parameters\": {\n \"description\": \"The method's parameters as of this entry (did:webvh log parameters). Absent for a method that has none.\",\n \"type\": \"object\"\n },\n \"state\": {\n \"description\": \"The DID document as of this entry.\",\n \"type\": \"object\"\n },\n \"versionId\": {\n \"description\": \"The entry's version identifier. Absent for a method that has none.\",\n \"type\": \"string\"\n },\n \"versionTime\": {\n \"description\": \"When the entry was made, as the entry states it. Absent for a method that records none.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"state\"\n ],\n \"type\": \"object\"\n },\n \"type\": \"array\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"logContent\": {\n \"description\": \"The stored primary artifact verbatim — did.jsonl for did:webvh, the key event stream for did:webs, did.json for did:web. Present iff the request set raw: true.\",\n \"type\": \"string\"\n },\n \"method\": {\n \"description\": \"The slot's DID method (`webvh`, `web`, `webs`, …). Determines what an entry is.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"mnemonic\": {\n \"type\": \"string\"\n },\n \"witnessContent\": {\n \"description\": \"The stored did-witness.json verbatim. Present iff the request set raw: true and the slot holds witness proofs.\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mnemonic\",\n \"method\",\n \"entries\"\n ],\n \"title\": \"DID Log — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/did-management/did/log/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"properties\": {\n \"domain\": {\n \"description\": \"Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain.\",\n \"maxLength\": 253,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"mnemonic\": {\n \"maxLength\": 512,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"raw\": {\n \"description\": \"When true, the response also carries the stored artifacts verbatim. Absent or false means parsed entries only.\",\n \"type\": \"boolean\"\n }\n },\n \"required\": [\n \"mnemonic\"\n ],\n \"title\": \"DID Log — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/did-management/did/log/0.1#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\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 \"entries\": {\n \"description\": \"The slot's history, oldest first. For did:webvh, one per log line; for a method with no log (did:web) a single entry for the current document; for did:webs one per establishment event that changed the document.\",\n \"items\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"parameters\": {\n \"description\": \"The method's parameters as of this entry (did:webvh log parameters). Absent for a method that has none.\",\n \"type\": \"object\"\n },\n \"state\": {\n \"description\": \"The DID document as of this entry.\",\n \"type\": \"object\"\n },\n \"versionId\": {\n \"description\": \"The entry's version identifier. Absent for a method that has none.\",\n \"type\": \"string\"\n },\n \"versionTime\": {\n \"description\": \"When the entry was made, as the entry states it. Absent for a method that records none.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"state\"\n ],\n \"type\": \"object\"\n },\n \"type\": \"array\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"logContent\": {\n \"description\": \"The stored primary artifact verbatim — did.jsonl for did:webvh, the key event stream for did:webs, did.json for did:web. Present iff the request set raw: true.\",\n \"type\": \"string\"\n },\n \"method\": {\n \"description\": \"The slot's DID method (`webvh`, `web`, `webs`, …). Determines what an entry is.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"mnemonic\": {\n \"type\": \"string\"\n },\n \"witnessContent\": {\n \"description\": \"The stored did-witness.json verbatim. Present iff the request set raw: true and the slot holds witness proofs.\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mnemonic\",\n \"method\",\n \"entries\"\n ],\n \"title\": \"DID Log — response payload\",\n \"type\": \"object\"\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;
}
/// The extended error codes this specification declares (SPEC §7.3 item 9,
/// §8.5), in declaration order. Empty when it declares none.
pub const ERROR_CODES: &[crate::DeclaredErrorCode] =
&[error_codes::NOT_FOUND, error_codes::UNKNOWN_DOMAIN];
/// One constant per extended error code this specification declares
/// (SPEC §7.3 item 9), named for its local part.
///
/// Emit these rather than a string literal: the code is read from the
/// specification, so it cannot name a code the specification never
/// declared.
pub mod error_codes {
/// `did-management/did/log:notFound`
///
/// No slot the caller may read has this `mnemonic`, or the slot holds no published content yet. Returned alike for a slot that does not exist and one the caller does not own.
///
/// Declared `retryable: false`.
pub const NOT_FOUND: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "did-management/did/log:notFound",
retryable: false,
};
/// `did-management:unknownDomain`
///
/// The submitted `domain` is not a known hosting domain on this consumer. See [category conventions](../../../_shared/0.1/CONVENTIONS.md#2-unknown-domain-error).
///
/// Declared `retryable: false`.
pub const UNKNOWN_DOMAIN: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "did-management:unknownDomain",
retryable: false,
};
}
#[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:f4a0cd21-b1df-4023-9c2d-0f1a2b3c4d01\",\n \"type\": \"https://trusttasks.org/spec/did-management/did/log/0.1\",\n \"issuer\": \"did:webvh:QmVtaScid5:vta.example.com\",\n \"recipient\": \"did:webvh:QmControlScid2:control.example.com\",\n \"issuedAt\": \"2026-09-27T09:00:00Z\",\n \"payload\": { \"mnemonic\": \"alice\" }\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:f4a0cd21-b1df-4023-9c2d-0f1a2b3c4d02\",\n \"type\": \"https://trusttasks.org/spec/did-management/did/log/0.1#response\",\n \"threadId\": \"urn:uuid:f4a0cd21-b1df-4023-9c2d-0f1a2b3c4d01\",\n \"issuer\": \"did:webvh:QmControlScid2:control.example.com\",\n \"recipient\": \"did:webvh:QmVtaScid5:vta.example.com\",\n \"issuedAt\": \"2026-09-27T09:00:01Z\",\n \"payload\": {\n \"mnemonic\": \"alice\",\n \"method\": \"webvh\",\n \"entries\": [\n {\n \"versionId\": \"1-QmHashOfEntryOne\",\n \"versionTime\": \"2026-09-01T10:00:00Z\",\n \"state\": {\n \"@context\": [\"https://www.w3.org/ns/did/v1\"],\n \"id\": \"did:webvh:QmAliceScid7:did.example.com:alice\"\n },\n \"parameters\": { \"method\": \"did:webvh:1.0\", \"scid\": \"QmAliceScid7\", \"updateKeys\": [\"z6MkUpdateKey1\"] }\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)] = &[
("Missing mnemonic.", "{}"),
(
"raw as a string.",
"{\n \"mnemonic\": \"alice\",\n \"raw\": \"yes\"\n}",
),
(
"Paging is not offered — the log is returned whole.",
"{\n \"fromVersion\": 3,\n \"mnemonic\": \"alice\"\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
);
}
}
}