//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `keys/derive-and-sign-document`. 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())
})
}
}
///Cryptographic algorithm the key material belongs to. `ed25519` signs (EdDSA), `x25519` performs key agreement and never signs, `p256` signs (ES256).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "KeyType",
/// "description": "Cryptographic algorithm the key material belongs to. `ed25519` signs (EdDSA), `x25519` performs key agreement and never signs, `p256` signs (ES256).",
/// "type": "string",
/// "enum": [
/// "ed25519",
/// "x25519",
/// "p256"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
pub enum KeyType {
#[serde(rename = "ed25519")]
Ed25519,
#[serde(rename = "x25519")]
X25519,
#[serde(rename = "p256")]
P256,
}
impl ::std::fmt::Display for KeyType {
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 KeyType {
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 KeyType {
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 KeyType {
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 KeyType {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///Derive a key at a path and return the supplied JSON document with a Data Integrity proof grafted on. Unlike keys/derive-and-sign, the custodian canonicalizes the document itself.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/keys/derive-and-sign-document/0.1",
/// "title": "Payload",
/// "description": "Derive a key at a path and return the supplied JSON document with a Data Integrity proof grafted on. Unlike keys/derive-and-sign, the custodian canonicalizes the document itself.",
/// "type": "object",
/// "required": [
/// "derivationPath",
/// "document",
/// "keyType"
/// ],
/// "properties": {
/// "derivationPath": {
/// "description": "Hierarchical-deterministic path to derive at.",
/// "type": "string",
/// "minLength": 1
/// },
/// "document": {
/// "description": "The JSON document to sign. Any `proof` member present is stripped before canonicalization — the custodian signs the document's content, never a previous signature over it.",
/// "type": "object"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "keyType": {
/// "description": "Algorithm to derive. MUST be one that can sign.",
/// "$ref": "#/definitions/KeyType"
/// },
/// "proofPurpose": {
/// "description": "Proof purpose to record in the generated proof. Absent means `assertionMethod`.",
/// "default": "assertionMethod",
/// "type": "string"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct Payload {
///Hierarchical-deterministic path to derive at.
#[serde(rename = "derivationPath")]
pub derivation_path: PayloadDerivationPath,
///The JSON document to sign. Any `proof` member present is stripped before canonicalization — the custodian signs the document's content, never a previous signature over it.
pub document: ::serde_json::Map<::std::string::String, ::serde_json::Value>,
///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>,
///Algorithm to derive. MUST be one that can sign.
#[serde(rename = "keyType")]
pub key_type: KeyType,
///Proof purpose to record in the generated proof. Absent means `assertionMethod`.
#[serde(rename = "proofPurpose", default = "defaults::payload_proof_purpose")]
pub proof_purpose: ::std::string::String,
}
///Hierarchical-deterministic path to derive at.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Hierarchical-deterministic path to derive at.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadDerivationPath(::std::string::String);
impl ::std::ops::Deref for PayloadDerivationPath {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadDerivationPath> for ::std::string::String {
fn from(value: PayloadDerivationPath) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadDerivationPath {
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 PayloadDerivationPath {
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 PayloadDerivationPath {
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 PayloadDerivationPath {
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 PayloadDerivationPath {
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 success response to a keys/derive-and-sign-document request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/derive-and-sign-document/0.1#response.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "The success response to a keys/derive-and-sign-document request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/derive-and-sign-document/0.1#response.",
/// "type": "object",
/// "required": [
/// "document",
/// "signerDid"
/// ],
/// "properties": {
/// "document": {
/// "description": "The document with the Data Integrity `proof` grafted on.",
/// "type": "object"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "signerDid": {
/// "description": "The `did:key` of the derived signer — the identity the document was signed as, and the DID a verifier resolves the proof's verification method against.",
/// "type": "string"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct Response {
///The document with the Data Integrity `proof` grafted on.
pub document: ::serde_json::Map<::std::string::String, ::serde_json::Value>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The `did:key` of the derived signer — the identity the document was signed as, and the DID a verifier resolves the proof's verification method against.
#[serde(rename = "signerDid")]
pub signer_did: ::std::string::String,
}
/// Generation of default values for serde.
pub mod defaults {
pub(super) fn payload_proof_purpose() -> ::std::string::String {
"assertionMethod".to_string()
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/keys/derive-and-sign-document/0.1";
const IS_RECIPIENT_REQUIRED: bool = true;
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/keys/derive-and-sign-document/0.1#response";
const IS_RECIPIENT_REQUIRED: bool = true;
}
#[cfg(feature = "validate")]
impl crate::validate::ValidatedPayload for Payload {
const SCHEMA_JSON: &'static str = "{\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 \"KeyType\": {\n \"description\": \"Cryptographic algorithm the key material belongs to. `ed25519` signs (EdDSA), `x25519` performs key agreement and never signs, `p256` signs (ES256).\",\n \"enum\": [\n \"ed25519\",\n \"x25519\",\n \"p256\"\n ],\n \"title\": \"KeyType\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The success response to a keys/derive-and-sign-document request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/derive-and-sign-document/0.1#response.\",\n \"properties\": {\n \"document\": {\n \"description\": \"The document with the Data Integrity `proof` grafted on.\",\n \"type\": \"object\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"signerDid\": {\n \"description\": \"The `did:key` of the derived signer — the identity the document was signed as, and the DID a verifier resolves the proof's verification method against.\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"signerDid\",\n \"document\"\n ],\n \"title\": \"Keys Derive-and-Sign-Document — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/keys/derive-and-sign-document/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Derive a key at a path and return the supplied JSON document with a Data Integrity proof grafted on. Unlike keys/derive-and-sign, the custodian canonicalizes the document itself.\",\n \"properties\": {\n \"derivationPath\": {\n \"description\": \"Hierarchical-deterministic path to derive at.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"document\": {\n \"description\": \"The JSON document to sign. Any `proof` member present is stripped before canonicalization — the custodian signs the document's content, never a previous signature over it.\",\n \"type\": \"object\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"keyType\": {\n \"$ref\": \"#/$defs/KeyType\",\n \"description\": \"Algorithm to derive. MUST be one that can sign.\"\n },\n \"proofPurpose\": {\n \"default\": \"assertionMethod\",\n \"description\": \"Proof purpose to record in the generated proof. Absent means `assertionMethod`.\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"keyType\",\n \"derivationPath\",\n \"document\"\n ],\n \"title\": \"Keys Derive-and-Sign-Document — payload\",\n \"type\": \"object\"\n}\n";
}
#[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\": \"e8f90112-2334-4459-5667-788990011223\",\n \"type\": \"https://trusttasks.org/spec/keys/derive-and-sign-document/0.1\",\n \"issuer\": \"did:web:app.example\",\n \"recipient\": \"did:web:custodian.example\",\n \"issuedAt\": \"2026-07-31T09:50:00Z\",\n \"payload\": {\n \"keyType\": \"ed25519\",\n \"derivationPath\": \"m/26'/9'/0'\",\n \"document\": {\n \"id\": \"urn:uuid:6f1b2c3d-4e5f-4061-8293-a4b5c6d7e8f9\",\n \"type\": \"https://trusttasks.org/spec/auth/authenticate/0.1\",\n \"issuer\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"payload\": { \"sessionId\": \"s-1\", \"challenge\": \"c-1\" }\n },\n \"proofPurpose\": \"assertionMethod\"\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\": \"f9011223-3445-4560-6778-899001122334\",\n \"type\": \"https://trusttasks.org/spec/keys/derive-and-sign-document/0.1#response\",\n \"threadId\": \"e8f90112-2334-4459-5667-788990011223\",\n \"issuer\": \"did:web:custodian.example\",\n \"recipient\": \"did:web:app.example\",\n \"issuedAt\": \"2026-07-31T09:50:01Z\",\n \"payload\": {\n \"signerDid\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"document\": {\n \"id\": \"urn:uuid:6f1b2c3d-4e5f-4061-8293-a4b5c6d7e8f9\",\n \"type\": \"https://trusttasks.org/spec/auth/authenticate/0.1\",\n \"issuer\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"payload\": { \"sessionId\": \"s-1\", \"challenge\": \"c-1\" },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"created\": \"2026-07-31T09:50:01Z\",\n \"verificationMethod\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"proofPurpose\": \"assertionMethod\",\n \"proofValue\": \"z3FXQjecWufY46yg5abdVZsXqLhxhueuSoZgNSTjXwT2c1h2G5nP8aQ\"\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");
}
}