//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `auth/signing-key/authorize`. 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())
}
}
}
///A human-readable name for where the key lives, chosen by the enrolling identity — e.g. `Work laptop — Chrome`. Read by that identity and by administrators deciding which key to revoke; retained with the delegation. Free text authored by the enrolling identity, untrusted, and attributed to it wherever it is rendered. Absent rather than invented when none was chosen: an invented label is indistinguishable from a chosen one to somebody deciding which key to revoke.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "DeviceLabel",
/// "description": "A human-readable name for where the key lives, chosen by the enrolling identity — e.g. `Work laptop — Chrome`. Read by that identity and by administrators deciding which key to revoke; retained with the delegation. Free text authored by the enrolling identity, untrusted, and attributed to it wherever it is rendered. Absent rather than invented when none was chosen: an invented label is indistinguishable from a chosen one to somebody deciding which key to revoke.",
/// "type": "string",
/// "maxLength": 128,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct DeviceLabel(::std::string::String);
impl ::std::ops::Deref for DeviceLabel {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<DeviceLabel> for ::std::string::String {
fn from(value: DeviceLabel) -> Self {
value.0
}
}
impl ::std::str::FromStr for DeviceLabel {
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 DeviceLabel {
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 DeviceLabel {
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 DeviceLabel {
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 DeviceLabel {
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())
})
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///The terms of one signing-key enrolment, signed by the identity the key will act for. Exactly the payload of the auth/signing-key/enroll/0.2 document that carries this one as its `authorization`, with that member removed; the consumer compares the two and refuses any difference. 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/auth/signing-key/authorize/0.1",
/// "title": "Payload",
/// "description": "The terms of one signing-key enrolment, signed by the identity the key will act for. Exactly the payload of the auth/signing-key/enroll/0.2 document that carries this one as its `authorization`, with that member removed; the consumer compares the two and refuses any difference. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.",
/// "type": "object",
/// "required": [
/// "identityDid",
/// "scope",
/// "signingKeyDid"
/// ],
/// "properties": {
/// "deviceLabel": {
/// "$ref": "#/definitions/DeviceLabel"
/// },
/// "expiresAt": {
/// "description": "The lifetime the enrolment requests, as in auth/signing-key/enroll/0.2.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "identityDid": {
/// "description": "The identity authorizing the delegation. Equal to the document's `issuer`: the identity signs for itself.",
/// "type": "string",
/// "maxLength": 2048,
/// "minLength": 5,
/// "pattern": "^did:"
/// },
/// "replaces": {
/// "description": "The identity's active key the enrolment replaces, as in auth/signing-key/enroll/0.2. Signed here so an authorization to add a key cannot be reused to remove one.",
/// "$ref": "#/definitions/SigningKeyDid"
/// },
/// "scope": {
/// "$ref": "#/definitions/SigningKeyScope"
/// },
/// "signingKeyDid": {
/// "$ref": "#/definitions/SigningKeyDid"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
#[serde(
rename = "deviceLabel",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub device_label: ::std::option::Option<DeviceLabel>,
///The lifetime the enrolment requests, as in auth/signing-key/enroll/0.2.
#[serde(
rename = "expiresAt",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub expires_at: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The identity authorizing the delegation. Equal to the document's `issuer`: the identity signs for itself.
#[serde(rename = "identityDid")]
pub identity_did: PayloadIdentityDid,
///The identity's active key the enrolment replaces, as in auth/signing-key/enroll/0.2. Signed here so an authorization to add a key cannot be reused to remove one.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub replaces: ::std::option::Option<SigningKeyDid>,
pub scope: SigningKeyScope,
#[serde(rename = "signingKeyDid")]
pub signing_key_did: SigningKeyDid,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///The identity authorizing the delegation. Equal to the document's `issuer`: the identity signs for itself.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The identity authorizing the delegation. Equal to the document's `issuer`: the identity signs for itself.",
/// "type": "string",
/// "maxLength": 2048,
/// "minLength": 5,
/// "pattern": "^did:"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadIdentityDid(::std::string::String);
impl ::std::ops::Deref for PayloadIdentityDid {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadIdentityDid> for ::std::string::String {
fn from(value: PayloadIdentityDid) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadIdentityDid {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 2048usize {
return Err("longer than 2048 characters".into());
}
if value.chars().count() < 5usize {
return Err("shorter than 5 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^did:").unwrap());
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^did:\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadIdentityDid {
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 PayloadIdentityDid {
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 PayloadIdentityDid {
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 PayloadIdentityDid {
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 delegated key, as a `did:key` — an Ed25519 multikey (`z6Mk…`) derived from the public half of a keypair the holder generated for itself, typically a non-extractable browser key. `did:key` only, because its document is a function of the key and resolves with no network: a key whose DID document could be rewritten after enrolment is not the key that was enrolled.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "SigningKeyDid",
/// "description": "The delegated key, as a `did:key` — an Ed25519 multikey (`z6Mk…`) derived from the public half of a keypair the holder generated for itself, typically a non-extractable browser key. `did:key` only, because its document is a function of the key and resolves with no network: a key whose DID document could be rewritten after enrolment is not the key that was enrolled.",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 9,
/// "pattern": "^did:key:z[1-9A-HJ-NP-Za-km-z]+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SigningKeyDid(::std::string::String);
impl ::std::ops::Deref for SigningKeyDid {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SigningKeyDid> for ::std::string::String {
fn from(value: SigningKeyDid) -> Self {
value.0
}
}
impl ::std::str::FromStr for SigningKeyDid {
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() < 9usize {
return Err("shorter than 9 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^did:key:z[1-9A-HJ-NP-Za-km-z]+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^did:key:z[1-9A-HJ-NP-Za-km-z]+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for SigningKeyDid {
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 SigningKeyDid {
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 SigningKeyDid {
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 SigningKeyDid {
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 a delegated key may be accepted for. `console`: the operations an administration console performs on the identity's behalf, authorized by the identity's own standing. Never an approver's signature on a consent or approval decision, whatever the scope: those require an `assertionMethod` key of the approver's own DID document, which a delegated key never is. A closed enumeration so a consumer cannot be asked for a scope it does not define; a later version adds values.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "SigningKeyScope",
/// "description": "What a delegated key may be accepted for. `console`: the operations an administration console performs on the identity's behalf, authorized by the identity's own standing. Never an approver's signature on a consent or approval decision, whatever the scope: those require an `assertionMethod` key of the approver's own DID document, which a delegated key never is. A closed enumeration so a consumer cannot be asked for a scope it does not define; a later version adds values.",
/// "type": "string",
/// "enum": [
/// "console"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum SigningKeyScope {
#[serde(rename = "console")]
Console,
}
impl ::std::fmt::Display for SigningKeyScope {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Console => f.write_str("console"),
}
}
}
impl ::std::str::FromStr for SigningKeyScope {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"console" => Ok(Self::Console),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for SigningKeyScope {
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 SigningKeyScope {
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 SigningKeyScope {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct Payload {
device_label:
::std::result::Result<::std::option::Option<super::DeviceLabel>, ::std::string::String>,
expires_at: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
identity_did: ::std::result::Result<super::PayloadIdentityDid, ::std::string::String>,
replaces: ::std::result::Result<
::std::option::Option<super::SigningKeyDid>,
::std::string::String,
>,
scope: ::std::result::Result<super::SigningKeyScope, ::std::string::String>,
signing_key_did: ::std::result::Result<super::SigningKeyDid, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
device_label: Ok(Default::default()),
expires_at: Ok(Default::default()),
ext: Ok(Default::default()),
identity_did: Err("no value supplied for identity_did".to_string()),
replaces: Ok(Default::default()),
scope: Err("no value supplied for scope".to_string()),
signing_key_did: Err("no value supplied for signing_key_did".to_string()),
}
}
}
impl Payload {
pub fn device_label<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::DeviceLabel>>,
T::Error: ::std::fmt::Display,
{
self.device_label = value
.try_into()
.map_err(|e| format!("error converting supplied value for device_label: {e}"));
self
}
pub fn expires_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::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 identity_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadIdentityDid>,
T::Error: ::std::fmt::Display,
{
self.identity_did = value
.try_into()
.map_err(|e| format!("error converting supplied value for identity_did: {e}"));
self
}
pub fn replaces<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::SigningKeyDid>>,
T::Error: ::std::fmt::Display,
{
self.replaces = value
.try_into()
.map_err(|e| format!("error converting supplied value for replaces: {e}"));
self
}
pub fn scope<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SigningKeyScope>,
T::Error: ::std::fmt::Display,
{
self.scope = value
.try_into()
.map_err(|e| format!("error converting supplied value for scope: {e}"));
self
}
pub fn signing_key_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SigningKeyDid>,
T::Error: ::std::fmt::Display,
{
self.signing_key_did = value
.try_into()
.map_err(|e| format!("error converting supplied value for signing_key_did: {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 {
device_label: value.device_label?,
expires_at: value.expires_at?,
ext: value.ext?,
identity_did: value.identity_did?,
replaces: value.replaces?,
scope: value.scope?,
signing_key_did: value.signing_key_did?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
device_label: Ok(value.device_label),
expires_at: Ok(value.expires_at),
ext: Ok(value.ext),
identity_did: Ok(value.identity_did),
replaces: Ok(value.replaces),
scope: Ok(value.scope),
signing_key_did: Ok(value.signing_key_did),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/auth/signing-key/authorize/0.1";
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 \"DeviceLabel\": {\n \"description\": \"A human-readable name for where the key lives, chosen by the enrolling identity — e.g. `Work laptop — Chrome`. Read by that identity and by administrators deciding which key to revoke; retained with the delegation. Free text authored by the enrolling identity, untrusted, and attributed to it wherever it is rendered. Absent rather than invented when none was chosen: an invented label is indistinguishable from a chosen one to somebody deciding which key to revoke.\",\n \"maxLength\": 128,\n \"minLength\": 1,\n \"title\": \"DeviceLabel\",\n \"type\": \"string\"\n },\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 \"SigningKeyDid\": {\n \"description\": \"The delegated key, as a `did:key` — an Ed25519 multikey (`z6Mk…`) derived from the public half of a keypair the holder generated for itself, typically a non-extractable browser key. `did:key` only, because its document is a function of the key and resolves with no network: a key whose DID document could be rewritten after enrolment is not the key that was enrolled.\",\n \"maxLength\": 256,\n \"minLength\": 9,\n \"pattern\": \"^did:key:z[1-9A-HJ-NP-Za-km-z]+$\",\n \"title\": \"SigningKeyDid\",\n \"type\": \"string\"\n },\n \"SigningKeyScope\": {\n \"description\": \"What a delegated key may be accepted for. `console`: the operations an administration console performs on the identity's behalf, authorized by the identity's own standing. Never an approver's signature on a consent or approval decision, whatever the scope: those require an `assertionMethod` key of the approver's own DID document, which a delegated key never is. A closed enumeration so a consumer cannot be asked for a scope it does not define; a later version adds values.\",\n \"enum\": [\n \"console\"\n ],\n \"title\": \"SigningKeyScope\",\n \"type\": \"string\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/auth/signing-key/authorize/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"The terms of one signing-key enrolment, signed by the identity the key will act for. Exactly the payload of the auth/signing-key/enroll/0.2 document that carries this one as its `authorization`, with that member removed; the consumer compares the two and refuses any difference. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.\",\n \"properties\": {\n \"deviceLabel\": {\n \"$ref\": \"#/$defs/DeviceLabel\"\n },\n \"expiresAt\": {\n \"description\": \"The lifetime the enrolment requests, as in auth/signing-key/enroll/0.2.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"identityDid\": {\n \"description\": \"The identity authorizing the delegation. Equal to the document's `issuer`: the identity signs for itself.\",\n \"maxLength\": 2048,\n \"minLength\": 5,\n \"pattern\": \"^did:\",\n \"type\": \"string\"\n },\n \"replaces\": {\n \"$ref\": \"#/$defs/SigningKeyDid\",\n \"description\": \"The identity's active key the enrolment replaces, as in auth/signing-key/enroll/0.2. Signed here so an authorization to add a key cannot be reused to remove one.\"\n },\n \"scope\": {\n \"$ref\": \"#/$defs/SigningKeyScope\"\n },\n \"signingKeyDid\": {\n \"$ref\": \"#/$defs/SigningKeyDid\"\n }\n },\n \"required\": [\n \"signingKeyDid\",\n \"identityDid\",\n \"scope\"\n ],\n \"title\": \"Auth — Signing Key Authorize — payload\",\n \"type\": \"object\"\n}\n",
);
}
/// 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:7f1d2c3b-4a5e-4f60-8a71-b2c3d4e5f601\",\n \"type\": \"https://trusttasks.org/spec/auth/signing-key/authorize/0.1\",\n \"issuer\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"recipient\": \"did:web:community.example\",\n \"issuedAt\": \"2026-10-02T10:00:00Z\",\n \"payload\": {\n \"signingKeyDid\": \"did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp\",\n \"identityDid\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"scope\": \"console\",\n \"deviceLabel\": \"Work laptop — Chrome\"\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");
}
/// 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)] = &[
(
"identityDid missing — the authorization names the identity it is made by, which the consumer compares to the issuer and to the enrolment.",
"{\n \"scope\": \"console\",\n \"signingKeyDid\": \"did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp\"\n}",
),
(
"replaces is a did:web — only a delegated did:key can be replaced.",
"{\n \"identityDid\": \"did:web:alice.example\",\n \"replaces\": \"did:web:old-laptop.example\",\n \"scope\": \"console\",\n \"signingKeyDid\": \"did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp\"\n}",
),
(
"authorization nested inside an authorization — the authorize payload is the enrolment's payload with `authorization` removed.",
"{\n \"authorization\": {},\n \"identityDid\": \"did:web:alice.example\",\n \"scope\": \"console\",\n \"signingKeyDid\": \"did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp\"\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
);
}
}
}