#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::bytes::Bytes;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::zone_stratos::boundary::Domain;
use crate::zone_stratos::actor::enrollment;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "zone.stratos.actor.enrollment",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Enrollment<S: BosStr = DefaultStr> {
pub attestation: enrollment::ServiceAttestation<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub boundaries: Option<Vec<Domain<S>>>,
pub created_at: Datetime,
pub service: UriValue<S>,
pub signing_key: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EnrollmentGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Enrollment<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ServiceAttestation<S: BosStr = DefaultStr> {
#[serde(with = "jacquard_common::serde_bytes_helper")]
pub sig: Bytes,
pub signing_key: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Enrollment<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, EnrollmentRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct EnrollmentRecord;
impl XrpcResp for EnrollmentRecord {
const NSID: &'static str = "zone.stratos.actor.enrollment";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = EnrollmentGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<EnrollmentGetRecordOutput<S>> for Enrollment<S> {
fn from(output: EnrollmentGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Enrollment<S> {
const NSID: &'static str = "zone.stratos.actor.enrollment";
type Record = EnrollmentRecord;
}
impl Collection for EnrollmentRecord {
const NSID: &'static str = "zone.stratos.actor.enrollment";
type Record = EnrollmentRecord;
}
impl<S: BosStr> LexiconSchema for Enrollment<S> {
fn nsid() -> &'static str {
"zone.stratos.actor.enrollment"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_zone_stratos_actor_enrollment()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.boundaries {
#[allow(unused_comparisons)]
if value.len() > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("boundaries"),
max: 50usize,
actual: value.len(),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for ServiceAttestation<S> {
fn nsid() -> &'static str {
"zone.stratos.actor.enrollment"
}
fn def_name() -> &'static str {
"serviceAttestation"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_zone_stratos_actor_enrollment()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod enrollment_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Service;
type Attestation;
type CreatedAt;
type SigningKey;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Service = Unset;
type Attestation = Unset;
type CreatedAt = Unset;
type SigningKey = Unset;
}
pub struct SetService<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetService<St> {}
impl<St: State> State for SetService<St> {
type Service = Set<members::service>;
type Attestation = St::Attestation;
type CreatedAt = St::CreatedAt;
type SigningKey = St::SigningKey;
}
pub struct SetAttestation<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAttestation<St> {}
impl<St: State> State for SetAttestation<St> {
type Service = St::Service;
type Attestation = Set<members::attestation>;
type CreatedAt = St::CreatedAt;
type SigningKey = St::SigningKey;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type Service = St::Service;
type Attestation = St::Attestation;
type CreatedAt = Set<members::created_at>;
type SigningKey = St::SigningKey;
}
pub struct SetSigningKey<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSigningKey<St> {}
impl<St: State> State for SetSigningKey<St> {
type Service = St::Service;
type Attestation = St::Attestation;
type CreatedAt = St::CreatedAt;
type SigningKey = Set<members::signing_key>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct service(());
pub struct attestation(());
pub struct created_at(());
pub struct signing_key(());
}
}
pub struct EnrollmentBuilder<S: BosStr, St: enrollment_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<enrollment::ServiceAttestation<S>>,
Option<Vec<Domain<S>>>,
Option<Datetime>,
Option<UriValue<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Enrollment<S> {
pub fn new() -> EnrollmentBuilder<S, enrollment_state::Empty> {
EnrollmentBuilder::new()
}
}
impl<S: BosStr> EnrollmentBuilder<S, enrollment_state::Empty> {
pub fn new() -> Self {
EnrollmentBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EnrollmentBuilder<S, St>
where
St: enrollment_state::State,
St::Attestation: enrollment_state::IsUnset,
{
pub fn attestation(
mut self,
value: impl Into<enrollment::ServiceAttestation<S>>,
) -> EnrollmentBuilder<S, enrollment_state::SetAttestation<St>> {
self._fields.0 = Option::Some(value.into());
EnrollmentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: enrollment_state::State> EnrollmentBuilder<S, St> {
pub fn boundaries(mut self, value: impl Into<Option<Vec<Domain<S>>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_boundaries(mut self, value: Option<Vec<Domain<S>>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> EnrollmentBuilder<S, St>
where
St: enrollment_state::State,
St::CreatedAt: enrollment_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> EnrollmentBuilder<S, enrollment_state::SetCreatedAt<St>> {
self._fields.2 = Option::Some(value.into());
EnrollmentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EnrollmentBuilder<S, St>
where
St: enrollment_state::State,
St::Service: enrollment_state::IsUnset,
{
pub fn service(
mut self,
value: impl Into<UriValue<S>>,
) -> EnrollmentBuilder<S, enrollment_state::SetService<St>> {
self._fields.3 = Option::Some(value.into());
EnrollmentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EnrollmentBuilder<S, St>
where
St: enrollment_state::State,
St::SigningKey: enrollment_state::IsUnset,
{
pub fn signing_key(
mut self,
value: impl Into<S>,
) -> EnrollmentBuilder<S, enrollment_state::SetSigningKey<St>> {
self._fields.4 = Option::Some(value.into());
EnrollmentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EnrollmentBuilder<S, St>
where
St: enrollment_state::State,
St::Service: enrollment_state::IsSet,
St::Attestation: enrollment_state::IsSet,
St::CreatedAt: enrollment_state::IsSet,
St::SigningKey: enrollment_state::IsSet,
{
pub fn build(self) -> Enrollment<S> {
Enrollment {
attestation: self._fields.0.unwrap(),
boundaries: self._fields.1,
created_at: self._fields.2.unwrap(),
service: self._fields.3.unwrap(),
signing_key: self._fields.4.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> Enrollment<S> {
Enrollment {
attestation: self._fields.0.unwrap(),
boundaries: self._fields.1,
created_at: self._fields.2.unwrap(),
service: self._fields.3.unwrap(),
signing_key: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_zone_stratos_actor_enrollment() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("zone.stratos.actor.enrollment"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A record indicating the user is enrolled in a Stratos service. Published to the user's PDS during OAuth enrollment for endpoint discovery by AppViews. Multiple enrollment records are supported — one per Stratos service.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("service"),
SmolStr::new_static("signingKey"),
SmolStr::new_static("attestation"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("attestation"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#serviceAttestation"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("boundaries"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"List of boundaries the user has access to on this Stratos service.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"zone.stratos.boundary.defs#Domain",
),
..Default::default()
}),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp when the enrollment was created.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("service"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The Stratos service endpoint URL where this user's private data is stored.",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signingKey"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The user's P-256 public key as a did:key string, generated by the Stratos service for user-level record signing.",
),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("serviceAttestation"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"An attestation signed by the Stratos service key. The signed payload is DAG-CBOR encoded {boundaries, did, signingKey} with sorted keys.",
),
),
required: Some(
vec![
SmolStr::new_static("sig"), SmolStr::new_static("signingKey")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("sig"),
LexObjectProperty::Bytes(LexBytes { ..Default::default() }),
);
map.insert(
SmolStr::new_static("signingKey"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The Stratos service's public key as a did:key string, used to verify the attestation signature.",
),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod service_attestation_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type SigningKey;
type Sig;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type SigningKey = Unset;
type Sig = Unset;
}
pub struct SetSigningKey<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSigningKey<St> {}
impl<St: State> State for SetSigningKey<St> {
type SigningKey = Set<members::signing_key>;
type Sig = St::Sig;
}
pub struct SetSig<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSig<St> {}
impl<St: State> State for SetSig<St> {
type SigningKey = St::SigningKey;
type Sig = Set<members::sig>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct signing_key(());
pub struct sig(());
}
}
pub struct ServiceAttestationBuilder<S: BosStr, St: service_attestation_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Bytes>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> ServiceAttestation<S> {
pub fn new() -> ServiceAttestationBuilder<S, service_attestation_state::Empty> {
ServiceAttestationBuilder::new()
}
}
impl<S: BosStr> ServiceAttestationBuilder<S, service_attestation_state::Empty> {
pub fn new() -> Self {
ServiceAttestationBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ServiceAttestationBuilder<S, St>
where
St: service_attestation_state::State,
St::Sig: service_attestation_state::IsUnset,
{
pub fn sig(
mut self,
value: impl Into<Bytes>,
) -> ServiceAttestationBuilder<S, service_attestation_state::SetSig<St>> {
self._fields.0 = Option::Some(value.into());
ServiceAttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ServiceAttestationBuilder<S, St>
where
St: service_attestation_state::State,
St::SigningKey: service_attestation_state::IsUnset,
{
pub fn signing_key(
mut self,
value: impl Into<S>,
) -> ServiceAttestationBuilder<S, service_attestation_state::SetSigningKey<St>> {
self._fields.1 = Option::Some(value.into());
ServiceAttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ServiceAttestationBuilder<S, St>
where
St: service_attestation_state::State,
St::SigningKey: service_attestation_state::IsSet,
St::Sig: service_attestation_state::IsSet,
{
pub fn build(self) -> ServiceAttestation<S> {
ServiceAttestation {
sig: self._fields.0.unwrap(),
signing_key: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> ServiceAttestation<S> {
ServiceAttestation {
sig: self._fields.0.unwrap(),
signing_key: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}