//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `webvh/sync/update`. Version: `0.2`.
#[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())
})
}
}
///The same shape as webvh/_shared/0.1 SyncUpdate (the element of webvh/sync/batch/0.1), inlined because a top-level $ref payload does not survive every binding generator. The two MUST stay identical.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/webvh/sync/update/0.2",
/// "title": "Payload",
/// "description": "The same shape as webvh/_shared/0.1 SyncUpdate (the element of webvh/sync/batch/0.1), inlined because a top-level $ref payload does not survive every binding generator. The two MUST stay identical.",
/// "type": "object",
/// "required": [
/// "didId",
/// "disabled",
/// "logContent",
/// "mnemonic",
/// "versionCount"
/// ],
/// "properties": {
/// "didId": {
/// "description": "The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.",
/// "type": "string",
/// "minLength": 1
/// },
/// "disabled": {
/// "description": "Whether the source has disabled the slot. A replica MUST stop serving a disabled slot and MUST resume only on an update carrying `false`.",
/// "type": "boolean"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "logContent": {
/// "description": "The slot's complete did.jsonl — one log entry per line — not a delta.",
/// "type": "string",
/// "minLength": 1
/// },
/// "mnemonic": {
/// "description": "The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).",
/// "type": "string",
/// "minLength": 1
/// },
/// "versionCount": {
/// "description": "Number of entries in `logContent`, as the source counts them. A replica MUST refuse an update whose `logContent` does not contain exactly this many entries.",
/// "type": "integer",
/// "minimum": 1.0
/// },
/// "witnessContent": {
/// "description": "The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means \"unchanged\".",
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.
#[serde(rename = "didId")]
pub did_id: PayloadDidId,
///Whether the source has disabled the slot. A replica MUST stop serving a disabled slot and MUST resume only on an update carrying `false`.
pub disabled: bool,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The slot's complete did.jsonl — one log entry per line — not a delta.
#[serde(rename = "logContent")]
pub log_content: PayloadLogContent,
///The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).
pub mnemonic: PayloadMnemonic,
///Number of entries in `logContent`, as the source counts them. A replica MUST refuse an update whose `logContent` does not contain exactly this many entries.
#[serde(rename = "versionCount")]
pub version_count: ::std::num::NonZeroU64,
///The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means "unchanged".
#[serde(
rename = "witnessContent",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub witness_content: ::std::option::Option<PayloadWitnessContent>,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadDidId(::std::string::String);
impl ::std::ops::Deref for PayloadDidId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadDidId> for ::std::string::String {
fn from(value: PayloadDidId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadDidId {
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 PayloadDidId {
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 PayloadDidId {
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 PayloadDidId {
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 PayloadDidId {
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())
})
}
}
///The slot's complete did.jsonl — one log entry per line — not a delta.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The slot's complete did.jsonl — one log entry per line — not a delta.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadLogContent(::std::string::String);
impl ::std::ops::Deref for PayloadLogContent {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadLogContent> for ::std::string::String {
fn from(value: PayloadLogContent) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadLogContent {
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 PayloadLogContent {
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 PayloadLogContent {
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 PayloadLogContent {
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 PayloadLogContent {
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())
})
}
}
///The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).",
/// "type": "string",
/// "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() < 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())
})
}
}
///The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means "unchanged".
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means \"unchanged\".",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadWitnessContent(::std::string::String);
impl ::std::ops::Deref for PayloadWitnessContent {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadWitnessContent> for ::std::string::String {
fn from(value: PayloadWitnessContent) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadWitnessContent {
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 PayloadWitnessContent {
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 PayloadWitnessContent {
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 PayloadWitnessContent {
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 PayloadWitnessContent {
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": [
/// "mnemonic",
/// "status"
/// ],
/// "properties": {
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "mnemonic": {
/// "type": "string",
/// "minLength": 1
/// },
/// "status": {
/// "description": "`applied` — the replica now holds and serves exactly the submitted state. `unchanged` — it already held that state (or a newer version with identical content), and nothing was written.",
/// "type": "string",
/// "enum": [
/// "applied",
/// "unchanged"
/// ]
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
pub mnemonic: ResponseMnemonic,
///`applied` — the replica now holds and serves exactly the submitted state. `unchanged` — it already held that state (or a newer version with identical content), and nothing was written.
pub status: ResponseStatus,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`ResponseMnemonic`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseMnemonic(::std::string::String);
impl ::std::ops::Deref for ResponseMnemonic {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseMnemonic> for ::std::string::String {
fn from(value: ResponseMnemonic) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseMnemonic {
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 ResponseMnemonic {
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 ResponseMnemonic {
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 ResponseMnemonic {
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 ResponseMnemonic {
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())
})
}
}
///`applied` — the replica now holds and serves exactly the submitted state. `unchanged` — it already held that state (or a newer version with identical content), and nothing was written.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "`applied` — the replica now holds and serves exactly the submitted state. `unchanged` — it already held that state (or a newer version with identical content), and nothing was written.",
/// "type": "string",
/// "enum": [
/// "applied",
/// "unchanged"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum ResponseStatus {
#[serde(rename = "applied")]
Applied,
#[serde(rename = "unchanged")]
Unchanged,
}
impl ::std::fmt::Display for ResponseStatus {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Applied => f.write_str("applied"),
Self::Unchanged => f.write_str("unchanged"),
}
}
}
impl ::std::str::FromStr for ResponseStatus {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"applied" => Ok(Self::Applied),
"unchanged" => Ok(Self::Unchanged),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for ResponseStatus {
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 ResponseStatus {
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 ResponseStatus {
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 Payload {
did_id: ::std::result::Result<super::PayloadDidId, ::std::string::String>,
disabled: ::std::result::Result<bool, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
log_content: ::std::result::Result<super::PayloadLogContent, ::std::string::String>,
mnemonic: ::std::result::Result<super::PayloadMnemonic, ::std::string::String>,
version_count: ::std::result::Result<::std::num::NonZeroU64, ::std::string::String>,
witness_content: ::std::result::Result<
::std::option::Option<super::PayloadWitnessContent>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
did_id: Err("no value supplied for did_id".to_string()),
disabled: Err("no value supplied for disabled".to_string()),
ext: Ok(Default::default()),
log_content: Err("no value supplied for log_content".to_string()),
mnemonic: Err("no value supplied for mnemonic".to_string()),
version_count: Err("no value supplied for version_count".to_string()),
witness_content: Ok(Default::default()),
}
}
}
impl Payload {
pub fn did_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadDidId>,
T::Error: ::std::fmt::Display,
{
self.did_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for did_id: {e}"));
self
}
pub fn disabled<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<bool>,
T::Error: ::std::fmt::Display,
{
self.disabled = value
.try_into()
.map_err(|e| format!("error converting supplied value for disabled: {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<super::PayloadLogContent>,
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 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 version_count<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::num::NonZeroU64>,
T::Error: ::std::fmt::Display,
{
self.version_count = value
.try_into()
.map_err(|e| format!("error converting supplied value for version_count: {e}"));
self
}
pub fn witness_content<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadWitnessContent>>,
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<Payload> for super::Payload {
type Error = super::error::ConversionError;
fn try_from(value: Payload) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
did_id: value.did_id?,
disabled: value.disabled?,
ext: value.ext?,
log_content: value.log_content?,
mnemonic: value.mnemonic?,
version_count: value.version_count?,
witness_content: value.witness_content?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
did_id: Ok(value.did_id),
disabled: Ok(value.disabled),
ext: Ok(value.ext),
log_content: Ok(value.log_content),
mnemonic: Ok(value.mnemonic),
version_count: Ok(value.version_count),
witness_content: Ok(value.witness_content),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
mnemonic: ::std::result::Result<super::ResponseMnemonic, ::std::string::String>,
status: ::std::result::Result<super::ResponseStatus, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
mnemonic: Err("no value supplied for mnemonic".to_string()),
status: Err("no value supplied for status".to_string()),
}
}
}
impl Response {
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::ResponseMnemonic>,
T::Error: ::std::fmt::Display,
{
self.mnemonic = value
.try_into()
.map_err(|e| format!("error converting supplied value for mnemonic: {e}"));
self
}
pub fn status<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseStatus>,
T::Error: ::std::fmt::Display,
{
self.status = value
.try_into()
.map_err(|e| format!("error converting supplied value for status: {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 {
ext: value.ext?,
mnemonic: value.mnemonic?,
status: value.status?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
ext: Ok(value.ext),
mnemonic: Ok(value.mnemonic),
status: Ok(value.status),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/webvh/sync/update/0.2";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_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 \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"mnemonic\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"status\": {\n \"description\": \"`applied` — the replica now holds and serves exactly the submitted state. `unchanged` — it already held that state (or a newer version with identical content), and nothing was written.\",\n \"enum\": [\n \"applied\",\n \"unchanged\"\n ],\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mnemonic\",\n \"status\"\n ],\n \"title\": \"WebVH Sync Update — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/webvh/sync/update/0.2\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"The same shape as webvh/_shared/0.1 SyncUpdate (the element of webvh/sync/batch/0.1), inlined because a top-level $ref payload does not survive every binding generator. The two MUST stay identical.\",\n \"properties\": {\n \"didId\": {\n \"description\": \"The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"disabled\": {\n \"description\": \"Whether the source has disabled the slot. A replica MUST stop serving a disabled slot and MUST resume only on an update carrying `false`.\",\n \"type\": \"boolean\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"logContent\": {\n \"description\": \"The slot's complete did.jsonl — one log entry per line — not a delta.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"mnemonic\": {\n \"description\": \"The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"versionCount\": {\n \"description\": \"Number of entries in `logContent`, as the source counts them. A replica MUST refuse an update whose `logContent` does not contain exactly this many entries.\",\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"witnessContent\": {\n \"description\": \"The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means \\\"unchanged\\\".\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mnemonic\",\n \"didId\",\n \"logContent\",\n \"versionCount\",\n \"disabled\"\n ],\n \"title\": \"WebVH Sync Update — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/webvh/sync/update/0.2#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_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 \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"mnemonic\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"status\": {\n \"description\": \"`applied` — the replica now holds and serves exactly the submitted state. `unchanged` — it already held that state (or a newer version with identical content), and nothing was written.\",\n \"enum\": [\n \"applied\",\n \"unchanged\"\n ],\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mnemonic\",\n \"status\"\n ],\n \"title\": \"WebVH Sync Update — 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_AUTHORIZED,
error_codes::INVALID_LOG,
error_codes::HISTORY_REWRITE,
error_codes::DEACTIVATED,
];
/// 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 {
/// `webvh/sync/update:notAuthorized`
///
/// The document's proven issuer is not a configured source of this replica.
///
/// Declared `retryable: false`.
pub const NOT_AUTHORIZED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "webvh/sync/update:notAuthorized",
retryable: false,
};
/// `webvh/sync/update:invalidLog`
///
/// `logContent` does not verify as a did:webvh log establishing `didId` — a broken hash chain, a bad proof, a pre-rotation violation, or an entry count that is not `versionCount`.
///
/// Declared `retryable: false`.
pub const INVALID_LOG: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "webvh/sync/update:invalidLog",
retryable: false,
};
/// `webvh/sync/update:historyRewrite`
///
/// `logContent` does not strictly extend the log the replica holds for the slot, or falls below the replica's high-water mark for the DID: it rewrites or truncates history the replica has already served.
///
/// Declared `retryable: false`.
pub const HISTORY_REWRITE: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "webvh/sync/update:historyRewrite",
retryable: false,
};
/// `webvh/sync/update:deactivated`
///
/// The replica holds the DID as deactivated; a deactivated DID takes no further entries.
///
/// Declared `retryable: false`.
pub const DEACTIVATED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "webvh/sync/update:deactivated",
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:3c1a9e70-6f2b-4d8e-a1c3-5b7d9f0e2a11\",\n \"type\": \"https://trusttasks.org/spec/webvh/sync/update/0.2\",\n \"issuer\": \"did:webvh:QmControlScid2:control.example.com\",\n \"recipient\": \"did:webvh:QmNodeScid3:node1.example.com\",\n \"issuedAt\": \"2026-09-27T09:00:00Z\",\n \"payload\": {\n \"mnemonic\": \"alice\",\n \"didId\": \"did:webvh:QmAliceScid4:did.example.com:alice\",\n \"logContent\": \"{\\\"versionId\\\":\\\"1-QmA\\\",\\\"versionTime\\\":\\\"2026-09-01T10:00:00Z\\\"}\\n{\\\"versionId\\\":\\\"2-QmB\\\",\\\"versionTime\\\":\\\"2026-09-27T08:59:00Z\\\"}\",\n \"witnessContent\": \"[{\\\"versionId\\\":\\\"2-QmB\\\",\\\"proof\\\":[]}]\",\n \"versionCount\": 2,\n \"disabled\": false\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:3c1a9e70-6f2b-4d8e-a1c3-5b7d9f0e2a12\",\n \"type\": \"https://trusttasks.org/spec/webvh/sync/update/0.2#response\",\n \"threadId\": \"urn:uuid:3c1a9e70-6f2b-4d8e-a1c3-5b7d9f0e2a11\",\n \"issuer\": \"did:webvh:QmNodeScid3:node1.example.com\",\n \"recipient\": \"did:webvh:QmControlScid2:control.example.com\",\n \"issuedAt\": \"2026-09-27T09:00:01Z\",\n \"payload\": { \"mnemonic\": \"alice\", \"status\": \"applied\" }\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 disabled — a replica must never guess whether to serve the slot.",
"{\n \"didId\": \"did:webvh:QmA:did.example.com:alice\",\n \"logContent\": \"{}\",\n \"mnemonic\": \"alice\",\n \"versionCount\": 1\n}",
),
(
"snake_case members from 0.1's wire drift are not accepted.",
"{\n \"did_id\": \"did:webvh:QmA:did.example.com:alice\",\n \"disabled\": false,\n \"log_content\": \"{}\",\n \"mnemonic\": \"alice\",\n \"version_count\": 1\n}",
),
(
"Empty logContent.",
"{\n \"didId\": \"did:webvh:QmA:did.example.com:alice\",\n \"disabled\": false,\n \"logContent\": \"\",\n \"mnemonic\": \"alice\",\n \"versionCount\": 1\n}",
),
(
"versionCount below 1.",
"{\n \"didId\": \"did:webvh:QmA:did.example.com:alice\",\n \"disabled\": false,\n \"logContent\": \"{}\",\n \"mnemonic\": \"alice\",\n \"versionCount\": 0\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
);
}
}
}