//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vta/contexts/secrets`. 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())
})
}
}
///Names the trust context whose DID key material is being asked for. 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/contexts/secrets/1.0",
/// "title": "Payload",
/// "description": "Names the trust context whose DID key material is being asked for. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.",
/// "type": "object",
/// "required": [
/// "id"
/// ],
/// "properties": {
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "id": {
/// "description": "Context id. For a nested context this is the full path (`parent/leaf`). Named `id` to match the rest of the `vta/contexts/*` family, where it always identifies the context being acted on.",
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Context id. For a nested context this is the full path (`parent/leaf`). Named `id` to match the rest of the `vta/contexts/*` family, where it always identifies the context being acted on.
pub id: PayloadId,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Context id. For a nested context this is the full path (`parent/leaf`). Named `id` to match the rest of the `vta/contexts/*` family, where it always identifies the context being acted on.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Context id. For a nested context this is the full path (`parent/leaf`). Named `id` to match the rest of the `vta/contexts/*` family, where it always identifies the context being acted on.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadId(::std::string::String);
impl ::std::ops::Deref for PayloadId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadId> for ::std::string::String {
fn from(value: PayloadId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadId {
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 PayloadId {
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 PayloadId {
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 PayloadId {
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 PayloadId {
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 context's DID and the private key material behind it, sufficient to operate as that DID and nothing more. Failures use trust-task-error, not this shape. Type https://trusttasks.org/spec/vta/contexts/secrets/1.0#response.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "The context's DID and the private key material behind it, sufficient to operate as that DID and nothing more. Failures use trust-task-error, not this shape. Type https://trusttasks.org/spec/vta/contexts/secrets/1.0#response.",
/// "type": "object",
/// "required": [
/// "did",
/// "secrets"
/// ],
/// "properties": {
/// "did": {
/// "description": "The DID the returned secrets belong to — the DID recorded on the named context. Every `keyId` below is a verification method of this DID, so a consumer can check the two agree before installing anything.",
/// "type": "string",
/// "minLength": 1
/// },
/// "secrets": {
/// "description": "One entry per verification method of `did` whose secret the recipient holds and is willing to release. MAY be empty: a context whose DID has no releasable key material is not an error, and a consumer that treats an empty array as a failure will misreport a context that is merely not provisioned yet.",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/SecretEntry"
/// }
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///The DID the returned secrets belong to — the DID recorded on the named context. Every `keyId` below is a verification method of this DID, so a consumer can check the two agree before installing anything.
pub did: ResponseDid,
///One entry per verification method of `did` whose secret the recipient holds and is willing to release. MAY be empty: a context whose DID has no releasable key material is not an error, and a consumer that treats an empty array as a failure will misreport a context that is merely not provisioned yet.
pub secrets: ::std::vec::Vec<SecretEntry>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///The DID the returned secrets belong to — the DID recorded on the named context. Every `keyId` below is a verification method of this DID, so a consumer can check the two agree before installing anything.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The DID the returned secrets belong to — the DID recorded on the named context. Every `keyId` below is a verification method of this DID, so a consumer can check the two agree before installing anything.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseDid(::std::string::String);
impl ::std::ops::Deref for ResponseDid {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseDid> for ::std::string::String {
fn from(value: ResponseDid) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseDid {
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 ResponseDid {
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 ResponseDid {
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 ResponseDid {
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 ResponseDid {
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())
})
}
}
///One private key, named by the verification method it backs.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Secret entry",
/// "description": "One private key, named by the verification method it backs.",
/// "type": "object",
/// "required": [
/// "keyId",
/// "keyType",
/// "privateKeyMultibase"
/// ],
/// "properties": {
/// "keyId": {
/// "description": "The verification method this key backs, as an absolute DID URL under the response's `did` (`{did}#key-0`). It is the DID document — not the recipient's own storage — that decides this name, so a consumer installs the key under a `kid` that an inbound message's recipient field will actually match.",
/// "type": "string",
/// "minLength": 1
/// },
/// "keyType": {
/// "description": "What the key is for, and how to reconstruct it. `ed25519` signs, `x25519` is a key-agreement key and signs nothing, `p256` is an ECDSA key for ES256. Stated as well as encoded in `privateKeyMultibase` so a consumer can select a key by purpose without decoding every entry.",
/// "type": "string",
/// "enum": [
/// "ed25519",
/// "x25519",
/// "p256"
/// ]
/// },
/// "privateKeyMultibase": {
/// "description": "The private key, multibase-encoded (Base58BTC, `z` prefix) over its multicodec-prefixed bytes — `0x1300` Ed25519, `0x1302` X25519, `0x1306` P-256. The multicodec prefix, not this member's position in the array, is what identifies the key material.",
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct SecretEntry {
///The verification method this key backs, as an absolute DID URL under the response's `did` (`{did}#key-0`). It is the DID document — not the recipient's own storage — that decides this name, so a consumer installs the key under a `kid` that an inbound message's recipient field will actually match.
#[serde(rename = "keyId")]
pub key_id: SecretEntryKeyId,
///What the key is for, and how to reconstruct it. `ed25519` signs, `x25519` is a key-agreement key and signs nothing, `p256` is an ECDSA key for ES256. Stated as well as encoded in `privateKeyMultibase` so a consumer can select a key by purpose without decoding every entry.
#[serde(rename = "keyType")]
pub key_type: SecretEntryKeyType,
///The private key, multibase-encoded (Base58BTC, `z` prefix) over its multicodec-prefixed bytes — `0x1300` Ed25519, `0x1302` X25519, `0x1306` P-256. The multicodec prefix, not this member's position in the array, is what identifies the key material.
#[serde(rename = "privateKeyMultibase")]
pub private_key_multibase: SecretEntryPrivateKeyMultibase,
}
impl SecretEntry {
pub fn builder() -> builder::SecretEntry {
Default::default()
}
}
///The verification method this key backs, as an absolute DID URL under the response's `did` (`{did}#key-0`). It is the DID document — not the recipient's own storage — that decides this name, so a consumer installs the key under a `kid` that an inbound message's recipient field will actually match.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The verification method this key backs, as an absolute DID URL under the response's `did` (`{did}#key-0`). It is the DID document — not the recipient's own storage — that decides this name, so a consumer installs the key under a `kid` that an inbound message's recipient field will actually match.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SecretEntryKeyId(::std::string::String);
impl ::std::ops::Deref for SecretEntryKeyId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SecretEntryKeyId> for ::std::string::String {
fn from(value: SecretEntryKeyId) -> Self {
value.0
}
}
impl ::std::str::FromStr for SecretEntryKeyId {
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 SecretEntryKeyId {
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 SecretEntryKeyId {
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 SecretEntryKeyId {
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 SecretEntryKeyId {
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())
})
}
}
///What the key is for, and how to reconstruct it. `ed25519` signs, `x25519` is a key-agreement key and signs nothing, `p256` is an ECDSA key for ES256. Stated as well as encoded in `privateKeyMultibase` so a consumer can select a key by purpose without decoding every entry.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "What the key is for, and how to reconstruct it. `ed25519` signs, `x25519` is a key-agreement key and signs nothing, `p256` is an ECDSA key for ES256. Stated as well as encoded in `privateKeyMultibase` so a consumer can select a key by purpose without decoding every entry.",
/// "type": "string",
/// "enum": [
/// "ed25519",
/// "x25519",
/// "p256"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum SecretEntryKeyType {
#[serde(rename = "ed25519")]
Ed25519,
#[serde(rename = "x25519")]
X25519,
#[serde(rename = "p256")]
P256,
}
impl ::std::fmt::Display for SecretEntryKeyType {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Ed25519 => f.write_str("ed25519"),
Self::X25519 => f.write_str("x25519"),
Self::P256 => f.write_str("p256"),
}
}
}
impl ::std::str::FromStr for SecretEntryKeyType {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"ed25519" => Ok(Self::Ed25519),
"x25519" => Ok(Self::X25519),
"p256" => Ok(Self::P256),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for SecretEntryKeyType {
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 SecretEntryKeyType {
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 SecretEntryKeyType {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///The private key, multibase-encoded (Base58BTC, `z` prefix) over its multicodec-prefixed bytes — `0x1300` Ed25519, `0x1302` X25519, `0x1306` P-256. The multicodec prefix, not this member's position in the array, is what identifies the key material.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The private key, multibase-encoded (Base58BTC, `z` prefix) over its multicodec-prefixed bytes — `0x1300` Ed25519, `0x1302` X25519, `0x1306` P-256. The multicodec prefix, not this member's position in the array, is what identifies the key material.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SecretEntryPrivateKeyMultibase(::std::string::String);
impl ::std::ops::Deref for SecretEntryPrivateKeyMultibase {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SecretEntryPrivateKeyMultibase> for ::std::string::String {
fn from(value: SecretEntryPrivateKeyMultibase) -> Self {
value.0
}
}
impl ::std::str::FromStr for SecretEntryPrivateKeyMultibase {
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 SecretEntryPrivateKeyMultibase {
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 SecretEntryPrivateKeyMultibase {
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 SecretEntryPrivateKeyMultibase {
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 SecretEntryPrivateKeyMultibase {
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 {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
id: ::std::result::Result<super::PayloadId, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
id: Err("no value supplied for id".to_string()),
}
}
}
impl Payload {
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 id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadId>,
T::Error: ::std::fmt::Display,
{
self.id = value
.try_into()
.map_err(|e| format!("error converting supplied value for id: {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 {
ext: value.ext?,
id: value.id?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
ext: Ok(value.ext),
id: Ok(value.id),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
did: ::std::result::Result<super::ResponseDid, ::std::string::String>,
secrets: ::std::result::Result<::std::vec::Vec<super::SecretEntry>, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
did: Err("no value supplied for did".to_string()),
secrets: Err("no value supplied for secrets".to_string()),
}
}
}
impl Response {
pub fn did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseDid>,
T::Error: ::std::fmt::Display,
{
self.did = value
.try_into()
.map_err(|e| format!("error converting supplied value for did: {e}"));
self
}
pub fn secrets<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::SecretEntry>>,
T::Error: ::std::fmt::Display,
{
self.secrets = value
.try_into()
.map_err(|e| format!("error converting supplied value for secrets: {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 {
did: value.did?,
secrets: value.secrets?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
did: Ok(value.did),
secrets: Ok(value.secrets),
}
}
}
#[derive(Clone, Debug)]
pub struct SecretEntry {
key_id: ::std::result::Result<super::SecretEntryKeyId, ::std::string::String>,
key_type: ::std::result::Result<super::SecretEntryKeyType, ::std::string::String>,
private_key_multibase:
::std::result::Result<super::SecretEntryPrivateKeyMultibase, ::std::string::String>,
}
impl ::std::default::Default for SecretEntry {
fn default() -> Self {
Self {
key_id: Err("no value supplied for key_id".to_string()),
key_type: Err("no value supplied for key_type".to_string()),
private_key_multibase: Err(
"no value supplied for private_key_multibase".to_string()
),
}
}
}
impl SecretEntry {
pub fn key_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SecretEntryKeyId>,
T::Error: ::std::fmt::Display,
{
self.key_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for key_id: {e}"));
self
}
pub fn key_type<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SecretEntryKeyType>,
T::Error: ::std::fmt::Display,
{
self.key_type = value
.try_into()
.map_err(|e| format!("error converting supplied value for key_type: {e}"));
self
}
pub fn private_key_multibase<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SecretEntryPrivateKeyMultibase>,
T::Error: ::std::fmt::Display,
{
self.private_key_multibase = value.try_into().map_err(|e| {
format!("error converting supplied value for private_key_multibase: {e}")
});
self
}
}
impl ::std::convert::TryFrom<SecretEntry> for super::SecretEntry {
type Error = super::error::ConversionError;
fn try_from(
value: SecretEntry,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
key_id: value.key_id?,
key_type: value.key_type?,
private_key_multibase: value.private_key_multibase?,
})
}
}
impl ::std::convert::From<super::SecretEntry> for SecretEntry {
fn from(value: super::SecretEntry) -> Self {
Self {
key_id: Ok(value.key_id),
key_type: Ok(value.key_type),
private_key_multibase: Ok(value.private_key_multibase),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vta/contexts/secrets/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 \"description\": \"The context's DID and the private key material behind it, sufficient to operate as that DID and nothing more. Failures use trust-task-error, not this shape. Type https://trusttasks.org/spec/vta/contexts/secrets/1.0#response.\",\n \"properties\": {\n \"did\": {\n \"description\": \"The DID the returned secrets belong to — the DID recorded on the named context. Every `keyId` below is a verification method of this DID, so a consumer can check the two agree before installing anything.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"secrets\": {\n \"description\": \"One entry per verification method of `did` whose secret the recipient holds and is willing to release. MAY be empty: a context whose DID has no releasable key material is not an error, and a consumer that treats an empty array as a failure will misreport a context that is merely not provisioned yet.\",\n \"items\": {\n \"$ref\": \"#/$defs/SecretEntry\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"did\",\n \"secrets\"\n ],\n \"title\": \"VTA Context Secrets — response payload\",\n \"type\": \"object\"\n },\n \"SecretEntry\": {\n \"additionalProperties\": false,\n \"description\": \"One private key, named by the verification method it backs.\",\n \"properties\": {\n \"keyId\": {\n \"description\": \"The verification method this key backs, as an absolute DID URL under the response's `did` (`{did}#key-0`). It is the DID document — not the recipient's own storage — that decides this name, so a consumer installs the key under a `kid` that an inbound message's recipient field will actually match.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"keyType\": {\n \"description\": \"What the key is for, and how to reconstruct it. `ed25519` signs, `x25519` is a key-agreement key and signs nothing, `p256` is an ECDSA key for ES256. Stated as well as encoded in `privateKeyMultibase` so a consumer can select a key by purpose without decoding every entry.\",\n \"enum\": [\n \"ed25519\",\n \"x25519\",\n \"p256\"\n ],\n \"type\": \"string\"\n },\n \"privateKeyMultibase\": {\n \"description\": \"The private key, multibase-encoded (Base58BTC, `z` prefix) over its multicodec-prefixed bytes — `0x1300` Ed25519, `0x1302` X25519, `0x1306` P-256. The multicodec prefix, not this member's position in the array, is what identifies the key material.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"keyId\",\n \"keyType\",\n \"privateKeyMultibase\"\n ],\n \"title\": \"Secret entry\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/vta/contexts/secrets/1.0\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Names the trust context whose DID key material is being asked for. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.\",\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"id\": {\n \"description\": \"Context id. For a nested context this is the full path (`parent/leaf`). Named `id` to match the rest of the `vta/contexts/*` family, where it always identifies the context being acted on.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"id\"\n ],\n \"title\": \"VTA Context Secrets — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vta/contexts/secrets/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 \"description\": \"The context's DID and the private key material behind it, sufficient to operate as that DID and nothing more. Failures use trust-task-error, not this shape. Type https://trusttasks.org/spec/vta/contexts/secrets/1.0#response.\",\n \"properties\": {\n \"did\": {\n \"description\": \"The DID the returned secrets belong to — the DID recorded on the named context. Every `keyId` below is a verification method of this DID, so a consumer can check the two agree before installing anything.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"secrets\": {\n \"description\": \"One entry per verification method of `did` whose secret the recipient holds and is willing to release. MAY be empty: a context whose DID has no releasable key material is not an error, and a consumer that treats an empty array as a failure will misreport a context that is merely not provisioned yet.\",\n \"items\": {\n \"$ref\": \"#/$defs/SecretEntry\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"did\",\n \"secrets\"\n ],\n \"title\": \"VTA Context Secrets — response payload\",\n \"type\": \"object\"\n },\n \"SecretEntry\": {\n \"additionalProperties\": false,\n \"description\": \"One private key, named by the verification method it backs.\",\n \"properties\": {\n \"keyId\": {\n \"description\": \"The verification method this key backs, as an absolute DID URL under the response's `did` (`{did}#key-0`). It is the DID document — not the recipient's own storage — that decides this name, so a consumer installs the key under a `kid` that an inbound message's recipient field will actually match.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"keyType\": {\n \"description\": \"What the key is for, and how to reconstruct it. `ed25519` signs, `x25519` is a key-agreement key and signs nothing, `p256` is an ECDSA key for ES256. Stated as well as encoded in `privateKeyMultibase` so a consumer can select a key by purpose without decoding every entry.\",\n \"enum\": [\n \"ed25519\",\n \"x25519\",\n \"p256\"\n ],\n \"type\": \"string\"\n },\n \"privateKeyMultibase\": {\n \"description\": \"The private key, multibase-encoded (Base58BTC, `z` prefix) over its multicodec-prefixed bytes — `0x1300` Ed25519, `0x1302` X25519, `0x1306` P-256. The multicodec prefix, not this member's position in the array, is what identifies the key material.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"keyId\",\n \"keyType\",\n \"privateKeyMultibase\"\n ],\n \"title\": \"Secret entry\",\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;
}
#[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/contexts/secrets/1.0#request\",\n \"issuer\": \"did:example:room-host\",\n \"recipient\": \"did:example:agent\",\n \"issuedAt\": \"2026-01-01T00:00:00Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"id\": \"rooms/host-1\"\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/contexts/secrets/1.0#response\",\n \"issuer\": \"did:example:agent\",\n \"recipient\": \"did:example:room-host\",\n \"issuedAt\": \"2026-01-01T00:00:01Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"did\": \"did:webvh:QmExample:example.com:rooms:host-1\",\n \"secrets\": [\n {\n \"keyId\": \"did:webvh:QmExample:example.com:rooms:host-1#key-0\",\n \"keyType\": \"ed25519\",\n \"privateKeyMultibase\": \"z3u2en7t5LR2WtQH5PfFqMqtVcSdd7ELrcFtnP63HKq4KLg\"\n },\n {\n \"keyId\": \"did:webvh:QmExample:example.com:rooms:host-1#key-1\",\n \"keyType\": \"x25519\",\n \"privateKeyMultibase\": \"z3wei82HkeQBoBJXbtEbnH3ohvHYqRJmDwtjEZ7Bn5UWMwZ\"\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)] = &[
(
"`id` is required — a request that names no context has nothing to authorize against, and must not be read as \"all of them\".",
"{}",
),
(
"`id` must not be empty. An empty string is the shape a caller lands on when its own context configuration is unset, and the recipient must refuse it rather than resolve it to a default.",
"{\n \"id\": \"\"\n}",
),
(
"`id` must be a string, not an array. A caller operating several contexts fetches each one separately; the task deliberately has no batch form.",
"{\n \"id\": [\n \"rooms/host-1\",\n \"rooms/host-2\"\n ]\n}",
),
("`id` must be a string, not a number.", "{\n \"id\": 42\n}"),
(
"Unknown top-level member is rejected (additionalProperties: false). A `did` on the *request* is the likeliest one to be invented — the recipient chooses which DID answers, and a caller must not be able to ask for one.",
"{\n \"did\": \"did:webvh:QmExample:example.com:rooms:host-1\",\n \"id\": \"rooms/host-1\"\n}",
),
(
"Nor may a request narrow the answer by verification method. The response is the context's key material or an error; there is no per-key form.",
"{\n \"id\": \"rooms/host-1\",\n \"keyId\": \"did:webvh:QmExample:example.com:rooms:host-1#key-0\"\n}",
),
(
"`ext` keys must be reverse-DNS namespaces (SPEC §4.5.1); a bare word is not one.",
"{\n \"ext\": {\n \"mine\": {\n \"anything\": true\n }\n },\n \"id\": \"rooms/host-1\"\n}",
),
(
"`ext` must not be empty — an empty extension object carries no vendor namespace and says nothing.",
"{\n \"ext\": {},\n \"id\": \"rooms/host-1\"\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
);
}
}
}