//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vta/attestation/mnemonic-export`. Version: `1.0`.
#[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())
})
}
}
///Asks an agent running in a trusted execution environment to release its seed mnemonic, once, sealed to a key only the producer holds. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/vta/attestation/mnemonic-export/1.0",
/// "title": "Payload",
/// "description": "Asks an agent running in a trusted execution environment to release its seed mnemonic, once, sealed to a key only the producer holds. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.",
/// "type": "object",
/// "required": [
/// "clientDid",
/// "nonce"
/// ],
/// "properties": {
/// "clientDid": {
/// "description": "The Ed25519 did:key the mnemonic is sealed to, by its X25519 counterpart, so only the holder of this key's private half can open the answer. Over an end-to-end channel, a key generated for this one export on the machine that will hold the backup, and discarded after. On the signed first-boot path over a hop-by-hop channel, exactly the document's issuer: the key that signed the request.",
/// "type": "string",
/// "maxLength": 128,
/// "pattern": "^did:key:z6Mk[1-9A-HJ-NP-Za-km-z]+$"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "label": {
/// "description": "Operator-visible label for the request. Never sealed into the answer and never treated as an instruction.",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
/// },
/// "nonce": {
/// "description": "Sixteen random bytes, base64url without padding. It becomes the sealed bundle's identifier, and the recipient binds it into its attestation quote, so an answer cannot be replayed to a different request.",
/// "type": "string",
/// "pattern": "^[A-Za-z0-9_-]{22}$"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///The Ed25519 did:key the mnemonic is sealed to, by its X25519 counterpart, so only the holder of this key's private half can open the answer. Over an end-to-end channel, a key generated for this one export on the machine that will hold the backup, and discarded after. On the signed first-boot path over a hop-by-hop channel, exactly the document's issuer: the key that signed the request.
#[serde(rename = "clientDid")]
pub client_did: PayloadClientDid,
///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>,
///Operator-visible label for the request. Never sealed into the answer and never treated as an instruction.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub label: ::std::option::Option<PayloadLabel>,
///Sixteen random bytes, base64url without padding. It becomes the sealed bundle's identifier, and the recipient binds it into its attestation quote, so an answer cannot be replayed to a different request.
pub nonce: PayloadNonce,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///The Ed25519 did:key the mnemonic is sealed to, by its X25519 counterpart, so only the holder of this key's private half can open the answer. Over an end-to-end channel, a key generated for this one export on the machine that will hold the backup, and discarded after. On the signed first-boot path over a hop-by-hop channel, exactly the document's issuer: the key that signed the request.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The Ed25519 did:key the mnemonic is sealed to, by its X25519 counterpart, so only the holder of this key's private half can open the answer. Over an end-to-end channel, a key generated for this one export on the machine that will hold the backup, and discarded after. On the signed first-boot path over a hop-by-hop channel, exactly the document's issuer: the key that signed the request.",
/// "type": "string",
/// "maxLength": 128,
/// "pattern": "^did:key:z6Mk[1-9A-HJ-NP-Za-km-z]+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadClientDid(::std::string::String);
impl ::std::ops::Deref for PayloadClientDid {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadClientDid> for ::std::string::String {
fn from(value: PayloadClientDid) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadClientDid {
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());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^did:key:z6Mk[1-9A-HJ-NP-Za-km-z]+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^did:key:z6Mk[1-9A-HJ-NP-Za-km-z]+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadClientDid {
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 PayloadClientDid {
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 PayloadClientDid {
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 PayloadClientDid {
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())
})
}
}
///Operator-visible label for the request. Never sealed into the answer and never treated as an instruction.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Operator-visible label for the request. Never sealed into the answer and never treated as an instruction.",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadLabel(::std::string::String);
impl ::std::ops::Deref for PayloadLabel {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadLabel> for ::std::string::String {
fn from(value: PayloadLabel) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadLabel {
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 PayloadLabel {
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 PayloadLabel {
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 PayloadLabel {
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 PayloadLabel {
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())
})
}
}
///Sixteen random bytes, base64url without padding. It becomes the sealed bundle's identifier, and the recipient binds it into its attestation quote, so an answer cannot be replayed to a different request.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Sixteen random bytes, base64url without padding. It becomes the sealed bundle's identifier, and the recipient binds it into its attestation quote, so an answer cannot be replayed to a different request.",
/// "type": "string",
/// "pattern": "^[A-Za-z0-9_-]{22}$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadNonce(::std::string::String);
impl ::std::ops::Deref for PayloadNonce {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadNonce> for ::std::string::String {
fn from(value: PayloadNonce) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadNonce {
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-Za-z0-9_-]{22}$").unwrap());
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[A-Za-z0-9_-]{22}$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadNonce {
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 PayloadNonce {
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 PayloadNonce {
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 PayloadNonce {
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": [
/// "bundle",
/// "digest",
/// "windowRemainingSecs"
/// ],
/// "properties": {
/// "bundle": {
/// "description": "The ASCII-armored sealed bundle. It carries the mnemonic sealed to clientDid under a producer assertion whose attestation quote binds the client key, the nonce and the recipient's own sealing key.",
/// "type": "string",
/// "maxLength": 65536,
/// "minLength": 1
/// },
/// "digest": {
/// "description": "SHA-256 of the bundle, lowercase hex. The producer confirms it out of band before opening, so a substituted bundle is caught before any key is applied to it.",
/// "type": "string",
/// "pattern": "^[0-9a-f]{64}$"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "windowRemainingSecs": {
/// "description": "Seconds that were left in the export window when the mnemonic was released. Informational: the window is spent either way.",
/// "type": "integer",
/// "minimum": 0.0
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///The ASCII-armored sealed bundle. It carries the mnemonic sealed to clientDid under a producer assertion whose attestation quote binds the client key, the nonce and the recipient's own sealing key.
pub bundle: ResponseBundle,
///SHA-256 of the bundle, lowercase hex. The producer confirms it out of band before opening, so a substituted bundle is caught before any key is applied to it.
pub digest: ResponseDigest,
///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>,
///Seconds that were left in the export window when the mnemonic was released. Informational: the window is spent either way.
#[serde(rename = "windowRemainingSecs")]
pub window_remaining_secs: u64,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///The ASCII-armored sealed bundle. It carries the mnemonic sealed to clientDid under a producer assertion whose attestation quote binds the client key, the nonce and the recipient's own sealing key.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The ASCII-armored sealed bundle. It carries the mnemonic sealed to clientDid under a producer assertion whose attestation quote binds the client key, the nonce and the recipient's own sealing key.",
/// "type": "string",
/// "maxLength": 65536,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseBundle(::std::string::String);
impl ::std::ops::Deref for ResponseBundle {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseBundle> for ::std::string::String {
fn from(value: ResponseBundle) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseBundle {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 65536usize {
return Err("longer than 65536 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 ResponseBundle {
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 ResponseBundle {
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 ResponseBundle {
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 ResponseBundle {
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())
})
}
}
///SHA-256 of the bundle, lowercase hex. The producer confirms it out of band before opening, so a substituted bundle is caught before any key is applied to it.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "SHA-256 of the bundle, lowercase hex. The producer confirms it out of band before opening, so a substituted bundle is caught before any key is applied to it.",
/// "type": "string",
/// "pattern": "^[0-9a-f]{64}$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseDigest(::std::string::String);
impl ::std::ops::Deref for ResponseDigest {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseDigest> for ::std::string::String {
fn from(value: ResponseDigest) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseDigest {
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("^[0-9a-f]{64}$").unwrap());
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[0-9a-f]{64}$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseDigest {
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 ResponseDigest {
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 ResponseDigest {
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 ResponseDigest {
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 {
client_did: ::std::result::Result<super::PayloadClientDid, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
label: ::std::result::Result<
::std::option::Option<super::PayloadLabel>,
::std::string::String,
>,
nonce: ::std::result::Result<super::PayloadNonce, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
client_did: Err("no value supplied for client_did".to_string()),
ext: Ok(Default::default()),
label: Ok(Default::default()),
nonce: Err("no value supplied for nonce".to_string()),
}
}
}
impl Payload {
pub fn client_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadClientDid>,
T::Error: ::std::fmt::Display,
{
self.client_did = value
.try_into()
.map_err(|e| format!("error converting supplied value for client_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 label<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadLabel>>,
T::Error: ::std::fmt::Display,
{
self.label = value
.try_into()
.map_err(|e| format!("error converting supplied value for label: {e}"));
self
}
pub fn nonce<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadNonce>,
T::Error: ::std::fmt::Display,
{
self.nonce = value
.try_into()
.map_err(|e| format!("error converting supplied value for nonce: {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 {
client_did: value.client_did?,
ext: value.ext?,
label: value.label?,
nonce: value.nonce?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
client_did: Ok(value.client_did),
ext: Ok(value.ext),
label: Ok(value.label),
nonce: Ok(value.nonce),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
bundle: ::std::result::Result<super::ResponseBundle, ::std::string::String>,
digest: ::std::result::Result<super::ResponseDigest, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
window_remaining_secs: ::std::result::Result<u64, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
bundle: Err("no value supplied for bundle".to_string()),
digest: Err("no value supplied for digest".to_string()),
ext: Ok(Default::default()),
window_remaining_secs: Err(
"no value supplied for window_remaining_secs".to_string()
),
}
}
}
impl Response {
pub fn bundle<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseBundle>,
T::Error: ::std::fmt::Display,
{
self.bundle = value
.try_into()
.map_err(|e| format!("error converting supplied value for bundle: {e}"));
self
}
pub fn digest<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseDigest>,
T::Error: ::std::fmt::Display,
{
self.digest = value
.try_into()
.map_err(|e| format!("error converting supplied value for digest: {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 window_remaining_secs<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.window_remaining_secs = value.try_into().map_err(|e| {
format!("error converting supplied value for window_remaining_secs: {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 {
bundle: value.bundle?,
digest: value.digest?,
ext: value.ext?,
window_remaining_secs: value.window_remaining_secs?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
bundle: Ok(value.bundle),
digest: Ok(value.digest),
ext: Ok(value.ext),
window_remaining_secs: Ok(value.window_remaining_secs),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/vta/attestation/mnemonic-export/1.0";
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 \"bundle\": {\n \"description\": \"The ASCII-armored sealed bundle. It carries the mnemonic sealed to clientDid under a producer assertion whose attestation quote binds the client key, the nonce and the recipient's own sealing key.\",\n \"maxLength\": 65536,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"digest\": {\n \"description\": \"SHA-256 of the bundle, lowercase hex. The producer confirms it out of band before opening, so a substituted bundle is caught before any key is applied to it.\",\n \"pattern\": \"^[0-9a-f]{64}$\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"windowRemainingSecs\": {\n \"description\": \"Seconds that were left in the export window when the mnemonic was released. Informational: the window is spent either way.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"bundle\",\n \"digest\",\n \"windowRemainingSecs\"\n ],\n \"title\": \"VTA Attestation Mnemonic Export — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/vta/attestation/mnemonic-export/1.0\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Asks an agent running in a trusted execution environment to release its seed mnemonic, once, sealed to a key only the producer holds. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.\",\n \"properties\": {\n \"clientDid\": {\n \"description\": \"The Ed25519 did:key the mnemonic is sealed to, by its X25519 counterpart, so only the holder of this key's private half can open the answer. Over an end-to-end channel, a key generated for this one export on the machine that will hold the backup, and discarded after. On the signed first-boot path over a hop-by-hop channel, exactly the document's issuer: the key that signed the request.\",\n \"maxLength\": 128,\n \"pattern\": \"^did:key:z6Mk[1-9A-HJ-NP-Za-km-z]+$\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"label\": {\n \"description\": \"Operator-visible label for the request. Never sealed into the answer and never treated as an instruction.\",\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"nonce\": {\n \"description\": \"Sixteen random bytes, base64url without padding. It becomes the sealed bundle's identifier, and the recipient binds it into its attestation quote, so an answer cannot be replayed to a different request.\",\n \"pattern\": \"^[A-Za-z0-9_-]{22}$\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"clientDid\",\n \"nonce\"\n ],\n \"title\": \"VTA Attestation — Mnemonic Export — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/vta/attestation/mnemonic-export/1.0#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 \"bundle\": {\n \"description\": \"The ASCII-armored sealed bundle. It carries the mnemonic sealed to clientDid under a producer assertion whose attestation quote binds the client key, the nonce and the recipient's own sealing key.\",\n \"maxLength\": 65536,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"digest\": {\n \"description\": \"SHA-256 of the bundle, lowercase hex. The producer confirms it out of band before opening, so a substituted bundle is caught before any key is applied to it.\",\n \"pattern\": \"^[0-9a-f]{64}$\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"windowRemainingSecs\": {\n \"description\": \"Seconds that were left in the export window when the mnemonic was released. Informational: the window is spent either way.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"bundle\",\n \"digest\",\n \"windowRemainingSecs\"\n ],\n \"title\": \"VTA Attestation Mnemonic Export — 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] = &[];
#[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/vta/attestation/mnemonic-export/1.0#request\",\n \"issuer\": \"did:example:operator\",\n \"recipient\": \"did:example:agent\",\n \"issuedAt\": \"2026-01-01T00:00:00Z\",\n \"payload\": {\n \"clientDid\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"nonce\": \"BwcHBwcHBwcHBwcHBwcHBw\"\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"created\": \"2026-01-01T00:00:00Z\",\n \"verificationMethod\": \"did:example:operator#key-0\",\n \"proofPurpose\": \"authentication\",\n \"proofValue\": \"z3FXQjecWufY46yg5abdVZsXqLhxhueuSoZgNSARiKBk9czhSePTNQ2p4D5eQzGnakbDwhXSbpYKMFwHUdktgYZZT\"\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 request_example_2() {
const JSON: &str = "{\n \"id\": \"urn:uuid:00000000-0000-4000-8000-000000000003\",\n \"type\": \"https://trusttasks.org/spec/vta/attestation/mnemonic-export/1.0#request\",\n \"issuer\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"recipient\": \"did:example:agent\",\n \"issuedAt\": \"2026-01-01T00:00:00Z\",\n \"payload\": {\n \"clientDid\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"nonce\": \"CAgICAgICAgICAgICAgICA\"\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"created\": \"2026-01-01T00:00:00Z\",\n \"verificationMethod\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"proofPurpose\": \"authentication\",\n \"proofValue\": \"z4oey5q2M3XKaxup3tmzN4DRFTLVqpLMweBrSxMY2xHX5XTYVQeVbY8nQAVHMrXFkXJpmEAXm5Yjv8fbvq7FxpLpJ\"\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/vta/attestation/mnemonic-export/1.0#response\",\n \"issuer\": \"did:example:agent\",\n \"recipient\": \"did:example:operator\",\n \"issuedAt\": \"2026-01-01T00:00:01Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-000000000001\",\n \"payload\": {\n \"bundle\": \"-----BEGIN VTA SEALED BUNDLE-----\\n…\\n-----END VTA SEALED BUNDLE-----\",\n \"digest\": \"9f2c3a7e5d1b4c8a6e0f2d4b6a8c0e2f4a6c8e0b2d4f6a8c0e2b4d6f8a0c2e4b\",\n \"windowRemainingSecs\": 412\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)] = &[
(
"`clientDid` is required — an answer sealed to nobody is an answer in the clear.",
"{\n \"nonce\": \"BwcHBwcHBwcHBwcHBwcHBw\"\n}",
),
(
"`nonce` is required. It binds the attestation quote to this request; without it an old answer could be replayed as a new one.",
"{\n \"clientDid\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\"\n}",
),
(
"Only an Ed25519 did:key. A DID that must be resolved would let whoever controls its resolution choose the key the root mnemonic is sealed to.",
"{\n \"clientDid\": \"did:web:example.com\",\n \"nonce\": \"BwcHBwcHBwcHBwcHBwcHBw\"\n}",
),
(
"The nonce is exactly sixteen bytes, base64url without padding.",
"{\n \"clientDid\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"nonce\": \"short\"\n}",
),
(
"No plaintext option. The mnemonic is only ever sealed, so there is no member that could ask for it otherwise.",
"{\n \"clientDid\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"nonce\": \"BwcHBwcHBwcHBwcHBwcHBw\",\n \"plaintext\": true\n}",
),
(
"Nor a destination. The answer goes to the producer that asked, over the channel it asked on.",
"{\n \"clientDid\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"deliverTo\": \"did:example:elsewhere\",\n \"nonce\": \"BwcHBwcHBwcHBwcHBwcHBw\"\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
);
}
}
}