//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `auth/passkey/enroll/invite`. Version: `0.2`.
#[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())
})
}
}
///An administrator issues a single-use invite, redeemed with a separately delivered claim code, that binds a passkey to a subject who cannot yet authorise the binding themselves: their first passkey, or — for `purpose: stepUp` — a step-up-only passkey that never opens a session.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/auth/passkey/enroll/invite/0.2",
/// "title": "Payload",
/// "description": "An administrator issues a single-use invite, redeemed with a separately delivered claim code, that binds a passkey to a subject who cannot yet authorise the binding themselves: their first passkey, or — for `purpose: stepUp` — a step-up-only passkey that never opens a session.",
/// "type": "object",
/// "required": [
/// "subject"
/// ],
/// "properties": {
/// "deviceLabel": {
/// "description": "Suggested label for the credential. Used as a default; the invitee MAY override during redemption.",
/// "type": "string",
/// "maxLength": 256
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "purpose": {
/// "description": "What the redeemed credential may authenticate. `session` (the default, and 0.1's only behaviour): it signs the subject in, with the role and scopes the invite carries. `stepUp`: it is accepted only as the user-verification evidence of a step-up bound to one operation (auth/step-up/approve-response `evidence.kind: webauthn`), never to open or elevate a session; `role` and `scopes` MUST then be absent.",
/// "default": "session",
/// "type": "string",
/// "enum": [
/// "session",
/// "stepUp"
/// ]
/// },
/// "role": {
/// "description": "Role the invitee receives on successful enrollment. Consumer-defined vocabulary; if absent the consumer applies its default role.",
/// "type": "string"
/// },
/// "scopes": {
/// "description": "Optional scopes to attach on enrollment.",
/// "type": "array",
/// "items": {
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "subject": {
/// "description": "The VID the invitee will enroll. The admin asserts this binding; the redemption ceremony verifies the invitee controls a passkey and holds the claim code, but does NOT independently verify the subject — trust flows from the admin. For `purpose: stepUp` the consumer MUST already recognise the subject (a member, say).",
/// "type": "string",
/// "minLength": 1
/// },
/// "ttl": {
/// "description": "Seconds the invite remains valid. Consumers SHOULD pick 15 min – 24 h, and MAY cap it lower; longer windows widen the attack surface.",
/// "type": "integer",
/// "minimum": 1.0
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Suggested label for the credential. Used as a default; the invitee MAY override during redemption.
#[serde(
rename = "deviceLabel",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub device_label: ::std::option::Option<PayloadDeviceLabel>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///What the redeemed credential may authenticate. `session` (the default, and 0.1's only behaviour): it signs the subject in, with the role and scopes the invite carries. `stepUp`: it is accepted only as the user-verification evidence of a step-up bound to one operation (auth/step-up/approve-response `evidence.kind: webauthn`), never to open or elevate a session; `role` and `scopes` MUST then be absent.
#[serde(default = "defaults::payload_purpose")]
pub purpose: PayloadPurpose,
///Role the invitee receives on successful enrollment. Consumer-defined vocabulary; if absent the consumer applies its default role.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub role: ::std::option::Option<::std::string::String>,
///Optional scopes to attach on enrollment.
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
pub scopes: ::std::vec::Vec<PayloadScopesItem>,
///The VID the invitee will enroll. The admin asserts this binding; the redemption ceremony verifies the invitee controls a passkey and holds the claim code, but does NOT independently verify the subject — trust flows from the admin. For `purpose: stepUp` the consumer MUST already recognise the subject (a member, say).
pub subject: PayloadSubject,
///Seconds the invite remains valid. Consumers SHOULD pick 15 min – 24 h, and MAY cap it lower; longer windows widen the attack surface.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ttl: ::std::option::Option<::std::num::NonZeroU64>,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Suggested label for the credential. Used as a default; the invitee MAY override during redemption.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Suggested label for the credential. Used as a default; the invitee MAY override during redemption.",
/// "type": "string",
/// "maxLength": 256
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadDeviceLabel(::std::string::String);
impl ::std::ops::Deref for PayloadDeviceLabel {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadDeviceLabel> for ::std::string::String {
fn from(value: PayloadDeviceLabel) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadDeviceLabel {
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());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadDeviceLabel {
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 PayloadDeviceLabel {
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 PayloadDeviceLabel {
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 PayloadDeviceLabel {
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 redeemed credential may authenticate. `session` (the default, and 0.1's only behaviour): it signs the subject in, with the role and scopes the invite carries. `stepUp`: it is accepted only as the user-verification evidence of a step-up bound to one operation (auth/step-up/approve-response `evidence.kind: webauthn`), never to open or elevate a session; `role` and `scopes` MUST then be absent.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "What the redeemed credential may authenticate. `session` (the default, and 0.1's only behaviour): it signs the subject in, with the role and scopes the invite carries. `stepUp`: it is accepted only as the user-verification evidence of a step-up bound to one operation (auth/step-up/approve-response `evidence.kind: webauthn`), never to open or elevate a session; `role` and `scopes` MUST then be absent.",
/// "default": "session",
/// "type": "string",
/// "enum": [
/// "session",
/// "stepUp"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum PayloadPurpose {
#[serde(rename = "session")]
Session,
#[serde(rename = "stepUp")]
StepUp,
}
impl ::std::fmt::Display for PayloadPurpose {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Session => f.write_str("session"),
Self::StepUp => f.write_str("stepUp"),
}
}
}
impl ::std::str::FromStr for PayloadPurpose {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"session" => Ok(Self::Session),
"stepUp" => Ok(Self::StepUp),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for PayloadPurpose {
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 PayloadPurpose {
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 PayloadPurpose {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::default::Default for PayloadPurpose {
fn default() -> Self {
PayloadPurpose::Session
}
}
///`PayloadScopesItem`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadScopesItem(::std::string::String);
impl ::std::ops::Deref for PayloadScopesItem {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadScopesItem> for ::std::string::String {
fn from(value: PayloadScopesItem) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadScopesItem {
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 PayloadScopesItem {
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 PayloadScopesItem {
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 PayloadScopesItem {
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 PayloadScopesItem {
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 VID the invitee will enroll. The admin asserts this binding; the redemption ceremony verifies the invitee controls a passkey and holds the claim code, but does NOT independently verify the subject — trust flows from the admin. For `purpose: stepUp` the consumer MUST already recognise the subject (a member, say).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The VID the invitee will enroll. The admin asserts this binding; the redemption ceremony verifies the invitee controls a passkey and holds the claim code, but does NOT independently verify the subject — trust flows from the admin. For `purpose: stepUp` the consumer MUST already recognise the subject (a member, say).",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadSubject(::std::string::String);
impl ::std::ops::Deref for PayloadSubject {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadSubject> for ::std::string::String {
fn from(value: PayloadSubject) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadSubject {
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 PayloadSubject {
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 PayloadSubject {
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 PayloadSubject {
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 PayloadSubject {
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 issued invite. Carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/passkey/enroll/invite/0.2#response.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "The issued invite. Carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/passkey/enroll/invite/0.2#response.",
/// "type": "object",
/// "required": [
/// "claimCode",
/// "expiresAt",
/// "invite",
/// "purpose",
/// "subject"
/// ],
/// "properties": {
/// "claimCode": {
/// "description": "A short code the invitee types at redemption, returned exactly once. The administrator delivers it over a different channel from `url`, so that intercepting one channel is not enough to redeem. The consumer stores only a slow hash of it.",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 8
/// },
/// "expiresAt": {
/// "type": "string",
/// "format": "date-time"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "invite": {
/// "type": "object",
/// "required": [
/// "token",
/// "url"
/// ],
/// "properties": {
/// "token": {
/// "description": "Opaque single-use invite token. The invitee presents it to the consumer during enrollment. ≥128 bits entropy.",
/// "type": "string",
/// "minLength": 16
/// },
/// "url": {
/// "description": "Operator-shareable URL that, when opened in a WebAuthn-capable browser, drives the redemption ceremony (auth/passkey/enroll/redeem/start). Carries the token. MUST NOT carry the claim code.",
/// "type": "string",
/// "format": "uri"
/// }
/// },
/// "additionalProperties": false
/// },
/// "purpose": {
/// "description": "Echo of the purpose the redeemed credential will have.",
/// "type": "string",
/// "enum": [
/// "session",
/// "stepUp"
/// ]
/// },
/// "subject": {
/// "description": "Echo of the invitee's VID.",
/// "type": "string"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///A short code the invitee types at redemption, returned exactly once. The administrator delivers it over a different channel from `url`, so that intercepting one channel is not enough to redeem. The consumer stores only a slow hash of it.
#[serde(rename = "claimCode")]
pub claim_code: ResponseClaimCode,
#[serde(rename = "expiresAt")]
pub expires_at: ::chrono::DateTime<::chrono::offset::Utc>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
pub invite: ResponseInvite,
///Echo of the purpose the redeemed credential will have.
pub purpose: ResponsePurpose,
///Echo of the invitee's VID.
pub subject: ::std::string::String,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///A short code the invitee types at redemption, returned exactly once. The administrator delivers it over a different channel from `url`, so that intercepting one channel is not enough to redeem. The consumer stores only a slow hash of it.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "A short code the invitee types at redemption, returned exactly once. The administrator delivers it over a different channel from `url`, so that intercepting one channel is not enough to redeem. The consumer stores only a slow hash of it.",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 8
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseClaimCode(::std::string::String);
impl ::std::ops::Deref for ResponseClaimCode {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseClaimCode> for ::std::string::String {
fn from(value: ResponseClaimCode) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseClaimCode {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 64usize {
return Err("longer than 64 characters".into());
}
if value.chars().count() < 8usize {
return Err("shorter than 8 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseClaimCode {
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 ResponseClaimCode {
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 ResponseClaimCode {
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 ResponseClaimCode {
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())
})
}
}
///`ResponseInvite`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "object",
/// "required": [
/// "token",
/// "url"
/// ],
/// "properties": {
/// "token": {
/// "description": "Opaque single-use invite token. The invitee presents it to the consumer during enrollment. ≥128 bits entropy.",
/// "type": "string",
/// "minLength": 16
/// },
/// "url": {
/// "description": "Operator-shareable URL that, when opened in a WebAuthn-capable browser, drives the redemption ceremony (auth/passkey/enroll/redeem/start). Carries the token. MUST NOT carry the claim code.",
/// "type": "string",
/// "format": "uri"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct ResponseInvite {
///Opaque single-use invite token. The invitee presents it to the consumer during enrollment. ≥128 bits entropy.
pub token: ResponseInviteToken,
///Operator-shareable URL that, when opened in a WebAuthn-capable browser, drives the redemption ceremony (auth/passkey/enroll/redeem/start). Carries the token. MUST NOT carry the claim code.
pub url: ::std::string::String,
}
impl ResponseInvite {
pub fn builder() -> builder::ResponseInvite {
Default::default()
}
}
///Opaque single-use invite token. The invitee presents it to the consumer during enrollment. ≥128 bits entropy.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Opaque single-use invite token. The invitee presents it to the consumer during enrollment. ≥128 bits entropy.",
/// "type": "string",
/// "minLength": 16
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseInviteToken(::std::string::String);
impl ::std::ops::Deref for ResponseInviteToken {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseInviteToken> for ::std::string::String {
fn from(value: ResponseInviteToken) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseInviteToken {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 16usize {
return Err("shorter than 16 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseInviteToken {
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 ResponseInviteToken {
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 ResponseInviteToken {
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 ResponseInviteToken {
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())
})
}
}
///Echo of the purpose the redeemed credential will have.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Echo of the purpose the redeemed credential will have.",
/// "type": "string",
/// "enum": [
/// "session",
/// "stepUp"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum ResponsePurpose {
#[serde(rename = "session")]
Session,
#[serde(rename = "stepUp")]
StepUp,
}
impl ::std::fmt::Display for ResponsePurpose {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Session => f.write_str("session"),
Self::StepUp => f.write_str("stepUp"),
}
}
}
impl ::std::str::FromStr for ResponsePurpose {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"session" => Ok(Self::Session),
"stepUp" => Ok(Self::StepUp),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for ResponsePurpose {
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 ResponsePurpose {
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 ResponsePurpose {
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::PayloadDeviceLabel>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
purpose: ::std::result::Result<super::PayloadPurpose, ::std::string::String>,
role: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
scopes:
::std::result::Result<::std::vec::Vec<super::PayloadScopesItem>, ::std::string::String>,
subject: ::std::result::Result<super::PayloadSubject, ::std::string::String>,
ttl: ::std::result::Result<
::std::option::Option<::std::num::NonZeroU64>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
device_label: Ok(Default::default()),
ext: Ok(Default::default()),
purpose: Ok(super::defaults::payload_purpose()),
role: Ok(Default::default()),
scopes: Ok(Default::default()),
subject: Err("no value supplied for subject".to_string()),
ttl: Ok(Default::default()),
}
}
}
impl Payload {
pub fn device_label<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadDeviceLabel>>,
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 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 purpose<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadPurpose>,
T::Error: ::std::fmt::Display,
{
self.purpose = value
.try_into()
.map_err(|e| format!("error converting supplied value for purpose: {e}"));
self
}
pub fn role<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.role = value
.try_into()
.map_err(|e| format!("error converting supplied value for role: {e}"));
self
}
pub fn scopes<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::PayloadScopesItem>>,
T::Error: ::std::fmt::Display,
{
self.scopes = value
.try_into()
.map_err(|e| format!("error converting supplied value for scopes: {e}"));
self
}
pub fn subject<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadSubject>,
T::Error: ::std::fmt::Display,
{
self.subject = value
.try_into()
.map_err(|e| format!("error converting supplied value for subject: {e}"));
self
}
pub fn ttl<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::num::NonZeroU64>>,
T::Error: ::std::fmt::Display,
{
self.ttl = value
.try_into()
.map_err(|e| format!("error converting supplied value for ttl: {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?,
ext: value.ext?,
purpose: value.purpose?,
role: value.role?,
scopes: value.scopes?,
subject: value.subject?,
ttl: value.ttl?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
device_label: Ok(value.device_label),
ext: Ok(value.ext),
purpose: Ok(value.purpose),
role: Ok(value.role),
scopes: Ok(value.scopes),
subject: Ok(value.subject),
ttl: Ok(value.ttl),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
claim_code: ::std::result::Result<super::ResponseClaimCode, ::std::string::String>,
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>,
invite: ::std::result::Result<super::ResponseInvite, ::std::string::String>,
purpose: ::std::result::Result<super::ResponsePurpose, ::std::string::String>,
subject: ::std::result::Result<::std::string::String, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
claim_code: Err("no value supplied for claim_code".to_string()),
expires_at: Err("no value supplied for expires_at".to_string()),
ext: Ok(Default::default()),
invite: Err("no value supplied for invite".to_string()),
purpose: Err("no value supplied for purpose".to_string()),
subject: Err("no value supplied for subject".to_string()),
}
}
}
impl Response {
pub fn claim_code<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseClaimCode>,
T::Error: ::std::fmt::Display,
{
self.claim_code = value
.try_into()
.map_err(|e| format!("error converting supplied value for claim_code: {e}"));
self
}
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 invite<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseInvite>,
T::Error: ::std::fmt::Display,
{
self.invite = value
.try_into()
.map_err(|e| format!("error converting supplied value for invite: {e}"));
self
}
pub fn purpose<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponsePurpose>,
T::Error: ::std::fmt::Display,
{
self.purpose = value
.try_into()
.map_err(|e| format!("error converting supplied value for purpose: {e}"));
self
}
pub fn subject<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::string::String>,
T::Error: ::std::fmt::Display,
{
self.subject = value
.try_into()
.map_err(|e| format!("error converting supplied value for subject: {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 {
claim_code: value.claim_code?,
expires_at: value.expires_at?,
ext: value.ext?,
invite: value.invite?,
purpose: value.purpose?,
subject: value.subject?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
claim_code: Ok(value.claim_code),
expires_at: Ok(value.expires_at),
ext: Ok(value.ext),
invite: Ok(value.invite),
purpose: Ok(value.purpose),
subject: Ok(value.subject),
}
}
}
#[derive(Clone, Debug)]
pub struct ResponseInvite {
token: ::std::result::Result<super::ResponseInviteToken, ::std::string::String>,
url: ::std::result::Result<::std::string::String, ::std::string::String>,
}
impl ::std::default::Default for ResponseInvite {
fn default() -> Self {
Self {
token: Err("no value supplied for token".to_string()),
url: Err("no value supplied for url".to_string()),
}
}
}
impl ResponseInvite {
pub fn token<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseInviteToken>,
T::Error: ::std::fmt::Display,
{
self.token = value
.try_into()
.map_err(|e| format!("error converting supplied value for token: {e}"));
self
}
pub fn url<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::string::String>,
T::Error: ::std::fmt::Display,
{
self.url = value
.try_into()
.map_err(|e| format!("error converting supplied value for url: {e}"));
self
}
}
impl ::std::convert::TryFrom<ResponseInvite> for super::ResponseInvite {
type Error = super::error::ConversionError;
fn try_from(
value: ResponseInvite,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
token: value.token?,
url: value.url?,
})
}
}
impl ::std::convert::From<super::ResponseInvite> for ResponseInvite {
fn from(value: super::ResponseInvite) -> Self {
Self {
token: Ok(value.token),
url: Ok(value.url),
}
}
}
}
/// Generation of default values for serde.
pub mod defaults {
pub(super) fn payload_purpose() -> super::PayloadPurpose {
super::PayloadPurpose::Session
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/auth/passkey/enroll/invite/0.2";
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 issued invite. Carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/passkey/enroll/invite/0.2#response.\",\n \"properties\": {\n \"claimCode\": {\n \"description\": \"A short code the invitee types at redemption, returned exactly once. The administrator delivers it over a different channel from `url`, so that intercepting one channel is not enough to redeem. The consumer stores only a slow hash of it.\",\n \"maxLength\": 64,\n \"minLength\": 8,\n \"type\": \"string\"\n },\n \"expiresAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"invite\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"token\": {\n \"description\": \"Opaque single-use invite token. The invitee presents it to the consumer during enrollment. ≥128 bits entropy.\",\n \"minLength\": 16,\n \"type\": \"string\"\n },\n \"url\": {\n \"description\": \"Operator-shareable URL that, when opened in a WebAuthn-capable browser, drives the redemption ceremony (auth/passkey/enroll/redeem/start). Carries the token. MUST NOT carry the claim code.\",\n \"format\": \"uri\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"token\",\n \"url\"\n ],\n \"type\": \"object\"\n },\n \"purpose\": {\n \"description\": \"Echo of the purpose the redeemed credential will have.\",\n \"enum\": [\n \"session\",\n \"stepUp\"\n ],\n \"type\": \"string\"\n },\n \"subject\": {\n \"description\": \"Echo of the invitee's VID.\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"invite\",\n \"subject\",\n \"purpose\",\n \"expiresAt\",\n \"claimCode\"\n ],\n \"title\": \"Auth Passkey Enroll Invite — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/auth/passkey/enroll/invite/0.2\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"An administrator issues a single-use invite, redeemed with a separately delivered claim code, that binds a passkey to a subject who cannot yet authorise the binding themselves: their first passkey, or — for `purpose: stepUp` — a step-up-only passkey that never opens a session.\",\n \"properties\": {\n \"deviceLabel\": {\n \"description\": \"Suggested label for the credential. Used as a default; the invitee MAY override during redemption.\",\n \"maxLength\": 256,\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"purpose\": {\n \"default\": \"session\",\n \"description\": \"What the redeemed credential may authenticate. `session` (the default, and 0.1's only behaviour): it signs the subject in, with the role and scopes the invite carries. `stepUp`: it is accepted only as the user-verification evidence of a step-up bound to one operation (auth/step-up/approve-response `evidence.kind: webauthn`), never to open or elevate a session; `role` and `scopes` MUST then be absent.\",\n \"enum\": [\n \"session\",\n \"stepUp\"\n ],\n \"type\": \"string\"\n },\n \"role\": {\n \"description\": \"Role the invitee receives on successful enrollment. Consumer-defined vocabulary; if absent the consumer applies its default role.\",\n \"type\": \"string\"\n },\n \"scopes\": {\n \"description\": \"Optional scopes to attach on enrollment.\",\n \"items\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"type\": \"array\"\n },\n \"subject\": {\n \"description\": \"The VID the invitee will enroll. The admin asserts this binding; the redemption ceremony verifies the invitee controls a passkey and holds the claim code, but does NOT independently verify the subject — trust flows from the admin. For `purpose: stepUp` the consumer MUST already recognise the subject (a member, say).\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"ttl\": {\n \"description\": \"Seconds the invite remains valid. Consumers SHOULD pick 15 min – 24 h, and MAY cap it lower; longer windows widen the attack surface.\",\n \"minimum\": 1,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"subject\"\n ],\n \"title\": \"Auth — Passkey Enroll (invite)\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/auth/passkey/enroll/invite/0.2#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 issued invite. Carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/passkey/enroll/invite/0.2#response.\",\n \"properties\": {\n \"claimCode\": {\n \"description\": \"A short code the invitee types at redemption, returned exactly once. The administrator delivers it over a different channel from `url`, so that intercepting one channel is not enough to redeem. The consumer stores only a slow hash of it.\",\n \"maxLength\": 64,\n \"minLength\": 8,\n \"type\": \"string\"\n },\n \"expiresAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"invite\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"token\": {\n \"description\": \"Opaque single-use invite token. The invitee presents it to the consumer during enrollment. ≥128 bits entropy.\",\n \"minLength\": 16,\n \"type\": \"string\"\n },\n \"url\": {\n \"description\": \"Operator-shareable URL that, when opened in a WebAuthn-capable browser, drives the redemption ceremony (auth/passkey/enroll/redeem/start). Carries the token. MUST NOT carry the claim code.\",\n \"format\": \"uri\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"token\",\n \"url\"\n ],\n \"type\": \"object\"\n },\n \"purpose\": {\n \"description\": \"Echo of the purpose the redeemed credential will have.\",\n \"enum\": [\n \"session\",\n \"stepUp\"\n ],\n \"type\": \"string\"\n },\n \"subject\": {\n \"description\": \"Echo of the invitee's VID.\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"invite\",\n \"subject\",\n \"purpose\",\n \"expiresAt\",\n \"claimCode\"\n ],\n \"title\": \"Auth Passkey Enroll Invite — 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] = &[
error_codes::SUBJECT_ALREADY_ENROLLED,
error_codes::ROLE_NOT_PERMITTED,
error_codes::PURPOSE_NOT_SUPPORTED,
error_codes::SUBJECT_UNKNOWN,
];
/// One constant per extended error code this specification declares
/// (SPEC §7.3 item 9), named for its local part.
///
/// Emit these rather than a string literal: the code is read from the
/// specification, so it cannot name a code the specification never
/// declared.
pub mod error_codes {
/// `auth/passkey/enroll/invite:subjectAlreadyEnrolled`
///
/// For `purpose: session`, the invitee VID already has a session credential on file. Use auth/passkey/enroll/start with the existing credential instead.
///
/// Declared `retryable: false`.
pub const SUBJECT_ALREADY_ENROLLED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/passkey/enroll/invite:subjectAlreadyEnrolled",
retryable: false,
};
/// `auth/passkey/enroll/invite:roleNotPermitted`
///
/// The administrator's authority does not allow assigning the requested role, or issuing an invite of this purpose.
///
/// Declared `retryable: false`.
pub const ROLE_NOT_PERMITTED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/passkey/enroll/invite:roleNotPermitted",
retryable: false,
};
/// `auth/passkey/enroll/invite:purposeNotSupported`
///
/// This auth service does not issue credentials of the requested purpose.
///
/// Declared `retryable: false`.
pub const PURPOSE_NOT_SUPPORTED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/passkey/enroll/invite:purposeNotSupported",
retryable: false,
};
/// `auth/passkey/enroll/invite:subjectUnknown`
///
/// For `purpose: stepUp`, the auth service does not recognise the subject — it holds no standing a step-up could ever be asked of.
///
/// Declared `retryable: false`.
pub const SUBJECT_UNKNOWN: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/passkey/enroll/invite:subjectUnknown",
retryable: false,
};
}
#[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 response_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:5d1e7c2a-3b4f-4e8a-9c61-0f2a7b3c9d02\",\n \"type\": \"https://trusttasks.org/spec/auth/passkey/enroll/invite/0.2#response\",\n \"threadId\": \"urn:uuid:5d1e7c2a-3b4f-4e8a-9c61-0f2a7b3c9d01\",\n \"issuer\": \"did:webvh:QmVtcScid7:acme-vtc.example\",\n \"recipient\": \"did:webvh:QmDanaScid8:acme-vtc.example:dana\",\n \"issuedAt\": \"2026-09-25T10:00:01Z\",\n \"payload\": {\n \"subject\": \"did:webvh:QmCarolScid3:acme-vtc.example:carol\",\n \"purpose\": \"stepUp\",\n \"expiresAt\": \"2026-09-25T11:00:01Z\",\n \"claimCode\": \"7KQ4-MX2P-9TDA\",\n \"invite\": {\n \"token\": \"inv_8f2c1d4e9a7b30568f2c1d4e9a7b3056a1b2c3d4\",\n \"url\": \"https://acme-vtc.example/admin/enroll-passkey?token=inv_8f2c1d4e9a7b30568f2c1d4e9a7b3056a1b2c3d4\"\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)] = &[
(
"Missing subject — an invite always names whose credential it binds.",
"{\n \"purpose\": \"stepUp\"\n}",
),
(
"Unknown purpose — only session and stepUp are defined.",
"{\n \"purpose\": \"admin\",\n \"subject\": \"did:webvh:QmCarolScid3:acme-vtc.example:carol\"\n}",
),
(
"ttl of zero — an invite must remain valid for at least a second.",
"{\n \"purpose\": \"stepUp\",\n \"subject\": \"did:webvh:QmCarolScid3:acme-vtc.example:carol\",\n \"ttl\": 0\n}",
),
(
"A claim code in the request — the consumer generates it; an inviter who chose it would know it before it was delivered.",
"{\n \"claimCode\": \"7KQ4-MX2P-9TDA\",\n \"purpose\": \"stepUp\",\n \"subject\": \"did:webvh:QmCarolScid3:acme-vtc.example:carol\"\n}",
),
(
"deviceLabel longer than 256 characters.",
"{\n \"deviceLabel\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\n \"subject\": \"did:webvh:QmCarolScid3:acme-vtc.example:carol\"\n}",
),
(
"Bare/unnamespaced ext key.",
"{\n \"ext\": {\n \"bare-key\": {\n \"anything\": \"here\"\n }\n },\n \"subject\": \"did:webvh:QmCarolScid3:acme-vtc.example:carol\"\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
);
}
}
}