//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `keys/import-wrapping-key`. Version: `0.1`.
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
/// Error from a `TryFrom` or `FromStr` implementation.
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Asks a key custodian for a fresh, short-lived, single-use public key to seal a private key to before sending it in a keys/import request's `privateKeySealed` carrier. The request carries nothing. 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/keys/import-wrapping-key/0.1",
/// "title": "Payload",
/// "description": "Asks a key custodian for a fresh, short-lived, single-use public key to seal a private key to before sending it in a keys/import request's `privateKeySealed` carrier. The request carries nothing. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.",
/// "type": "object",
/// "properties": {
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Default::default(),
}
}
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///The wrapping key the custodian has just generated, carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/import-wrapping-key/0.1#response. Failures use trust-task-error, not this shape.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "The wrapping key the custodian has just generated, carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/import-wrapping-key/0.1#response. Failures use trust-task-error, not this shape.",
/// "type": "object",
/// "required": [
/// "expiresAt",
/// "keyId",
/// "wrappingKey"
/// ],
/// "properties": {
/// "expiresAt": {
/// "description": "The instant after which the custodian will no longer open anything sealed to this key. RFC 3339 with an explicit offset. A producer that cannot complete keys/import before it asks for a new wrapping key rather than sending a bundle it knows will be refused.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "keyId": {
/// "description": "The custodian's opaque handle for this wrapping key. A `privateKeyJwe` carrier names it as its JWE `kid`. A `privateKeySealed` carrier does not need it: the custodian finds the key by trying the bundle against its unexpired, unused wrapping keys. Carries no meaning to the producer beyond equality.",
/// "type": "string",
/// "maxLength": 128,
/// "minLength": 1
/// },
/// "wrappingKey": {
/// "description": "The wrapping key as an Ed25519 did:key. A producer seals to its X25519 counterpart (the birational map of RFC 7748 §4.1 applied to the Ed25519 public key), exactly as the sealed-transfer recipient of vta/attestation/mnemonic-export is addressed. Generated for this response alone: the custodian MUST NOT return the same key twice.",
/// "type": "string",
/// "maxLength": 128,
/// "pattern": "^did:key:z6Mk[1-9A-HJ-NP-Za-km-z]+$"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///The instant after which the custodian will no longer open anything sealed to this key. RFC 3339 with an explicit offset. A producer that cannot complete keys/import before it asks for a new wrapping key rather than sending a bundle it knows will be refused.
#[serde(rename = "expiresAt")]
pub expires_at: ::chrono::DateTime<::chrono::offset::Utc>,
///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>,
///The custodian's opaque handle for this wrapping key. A `privateKeyJwe` carrier names it as its JWE `kid`. A `privateKeySealed` carrier does not need it: the custodian finds the key by trying the bundle against its unexpired, unused wrapping keys. Carries no meaning to the producer beyond equality.
#[serde(rename = "keyId")]
pub key_id: ResponseKeyId,
///The wrapping key as an Ed25519 did:key. A producer seals to its X25519 counterpart (the birational map of RFC 7748 §4.1 applied to the Ed25519 public key), exactly as the sealed-transfer recipient of vta/attestation/mnemonic-export is addressed. Generated for this response alone: the custodian MUST NOT return the same key twice.
#[serde(rename = "wrappingKey")]
pub wrapping_key: ResponseWrappingKey,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///The custodian's opaque handle for this wrapping key. A `privateKeyJwe` carrier names it as its JWE `kid`. A `privateKeySealed` carrier does not need it: the custodian finds the key by trying the bundle against its unexpired, unused wrapping keys. Carries no meaning to the producer beyond equality.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The custodian's opaque handle for this wrapping key. A `privateKeyJwe` carrier names it as its JWE `kid`. A `privateKeySealed` carrier does not need it: the custodian finds the key by trying the bundle against its unexpired, unused wrapping keys. Carries no meaning to the producer beyond equality.",
/// "type": "string",
/// "maxLength": 128,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseKeyId(::std::string::String);
impl ::std::ops::Deref for ResponseKeyId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseKeyId> for ::std::string::String {
fn from(value: ResponseKeyId) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseKeyId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 128usize {
return Err("longer than 128 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseKeyId {
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 ResponseKeyId {
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 ResponseKeyId {
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 ResponseKeyId {
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 wrapping key as an Ed25519 did:key. A producer seals to its X25519 counterpart (the birational map of RFC 7748 §4.1 applied to the Ed25519 public key), exactly as the sealed-transfer recipient of vta/attestation/mnemonic-export is addressed. Generated for this response alone: the custodian MUST NOT return the same key twice.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The wrapping key as an Ed25519 did:key. A producer seals to its X25519 counterpart (the birational map of RFC 7748 §4.1 applied to the Ed25519 public key), exactly as the sealed-transfer recipient of vta/attestation/mnemonic-export is addressed. Generated for this response alone: the custodian MUST NOT return the same key twice.",
/// "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 ResponseWrappingKey(::std::string::String);
impl ::std::ops::Deref for ResponseWrappingKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseWrappingKey> for ::std::string::String {
fn from(value: ResponseWrappingKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseWrappingKey {
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 ResponseWrappingKey {
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 ResponseWrappingKey {
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 ResponseWrappingKey {
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 ResponseWrappingKey {
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>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
}
}
}
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
}
}
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? })
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self { ext: Ok(value.ext) }
}
}
#[derive(Clone, Debug)]
pub struct Response {
expires_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
key_id: ::std::result::Result<super::ResponseKeyId, ::std::string::String>,
wrapping_key: ::std::result::Result<super::ResponseWrappingKey, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
expires_at: Err("no value supplied for expires_at".to_string()),
ext: Ok(Default::default()),
key_id: Err("no value supplied for key_id".to_string()),
wrapping_key: Err("no value supplied for wrapping_key".to_string()),
}
}
}
impl Response {
pub fn expires_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.expires_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for expires_at: {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 key_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseKeyId>,
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 wrapping_key<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseWrappingKey>,
T::Error: ::std::fmt::Display,
{
self.wrapping_key = value
.try_into()
.map_err(|e| format!("error converting supplied value for wrapping_key: {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 {
expires_at: value.expires_at?,
ext: value.ext?,
key_id: value.key_id?,
wrapping_key: value.wrapping_key?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
expires_at: Ok(value.expires_at),
ext: Ok(value.ext),
key_id: Ok(value.key_id),
wrapping_key: Ok(value.wrapping_key),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/keys/import-wrapping-key/0.1";
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 wrapping key the custodian has just generated, carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/import-wrapping-key/0.1#response. Failures use trust-task-error, not this shape.\",\n \"properties\": {\n \"expiresAt\": {\n \"description\": \"The instant after which the custodian will no longer open anything sealed to this key. RFC 3339 with an explicit offset. A producer that cannot complete keys/import before it asks for a new wrapping key rather than sending a bundle it knows will be refused.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"keyId\": {\n \"description\": \"The custodian's opaque handle for this wrapping key. A `privateKeyJwe` carrier names it as its JWE `kid`. A `privateKeySealed` carrier does not need it: the custodian finds the key by trying the bundle against its unexpired, unused wrapping keys. Carries no meaning to the producer beyond equality.\",\n \"maxLength\": 128,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"wrappingKey\": {\n \"description\": \"The wrapping key as an Ed25519 did:key. A producer seals to its X25519 counterpart (the birational map of RFC 7748 §4.1 applied to the Ed25519 public key), exactly as the sealed-transfer recipient of vta/attestation/mnemonic-export is addressed. Generated for this response alone: the custodian MUST NOT return the same key twice.\",\n \"maxLength\": 128,\n \"pattern\": \"^did:key:z6Mk[1-9A-HJ-NP-Za-km-z]+$\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"wrappingKey\",\n \"keyId\",\n \"expiresAt\"\n ],\n \"title\": \"Keys — Import Wrapping Key — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/keys/import-wrapping-key/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Asks a key custodian for a fresh, short-lived, single-use public key to seal a private key to before sending it in a keys/import request's `privateKeySealed` carrier. The request carries nothing. 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 \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n }\n },\n \"title\": \"Keys — Import Wrapping Key — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/keys/import-wrapping-key/0.1#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The wrapping key the custodian has just generated, carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/import-wrapping-key/0.1#response. Failures use trust-task-error, not this shape.\",\n \"properties\": {\n \"expiresAt\": {\n \"description\": \"The instant after which the custodian will no longer open anything sealed to this key. RFC 3339 with an explicit offset. A producer that cannot complete keys/import before it asks for a new wrapping key rather than sending a bundle it knows will be refused.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"keyId\": {\n \"description\": \"The custodian's opaque handle for this wrapping key. A `privateKeyJwe` carrier names it as its JWE `kid`. A `privateKeySealed` carrier does not need it: the custodian finds the key by trying the bundle against its unexpired, unused wrapping keys. Carries no meaning to the producer beyond equality.\",\n \"maxLength\": 128,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"wrappingKey\": {\n \"description\": \"The wrapping key as an Ed25519 did:key. A producer seals to its X25519 counterpart (the birational map of RFC 7748 §4.1 applied to the Ed25519 public key), exactly as the sealed-transfer recipient of vta/attestation/mnemonic-export is addressed. Generated for this response alone: the custodian MUST NOT return the same key twice.\",\n \"maxLength\": 128,\n \"pattern\": \"^did:key:z6Mk[1-9A-HJ-NP-Za-km-z]+$\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"wrappingKey\",\n \"keyId\",\n \"expiresAt\"\n ],\n \"title\": \"Keys — Import Wrapping Key — 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:3b9f4a1e-7c2d-4e8f-9a6b-1c0d2e3f4a5b\",\n \"type\": \"https://trusttasks.org/spec/keys/import-wrapping-key/0.1\",\n \"issuer\": \"did:web:operator.example\",\n \"recipient\": \"did:web:custodian.example\",\n \"issuedAt\": \"2026-09-27T09:10:00Z\",\n \"payload\": {}\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:8d7c6b5a-4e3f-4a2b-9c1d-0e9f8a7b6c5d\",\n \"type\": \"https://trusttasks.org/spec/keys/import-wrapping-key/0.1#response\",\n \"threadId\": \"urn:uuid:3b9f4a1e-7c2d-4e8f-9a6b-1c0d2e3f4a5b\",\n \"issuer\": \"did:web:custodian.example\",\n \"recipient\": \"did:web:operator.example\",\n \"issuedAt\": \"2026-09-27T09:10:00Z\",\n \"payload\": {\n \"wrappingKey\": \"did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH\",\n \"keyId\": \"5f2c0a9e-1b7d-4c3e-8f6a-2d9b0e4c7a18\",\n \"expiresAt\": \"2026-09-27T09:11:00Z\"\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"verificationMethod\": \"did:web:custodian.example#key-1\",\n \"created\": \"2026-09-27T09:10:00Z\",\n \"proofPurpose\": \"authentication\",\n \"proofValue\": \"z3kg…\"\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)] = &[
(
"The request carries nothing — an unknown top-level member is rejected (additionalProperties: false). A producer cannot choose the key's type, lifetime or value.",
"{\n \"wrappingKey\": \"did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH\"\n}",
),
(
"Bare/unnamespaced ext key — SPEC §4.5.1 requires every immediate child of ext to be reverse-DNS namespaced.",
"{\n \"ext\": {\n \"bare-key\": {\n \"anything\": \"here\"\n }\n }\n}",
),
("`ext` must be an object, not a string.", "{\n \"ext\": \"vendor\"\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
);
}
}
}