#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[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};
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::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "tech.lenooby09.didgit.signatureProof",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct SignatureProof<S: BosStr = DefaultStr> {
pub object_id: S,
pub object_type: SignatureProofObjectType<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pds_endpoint: Option<S>,
pub signature: S,
pub signature_type: S,
pub signed_at: i64,
pub signer: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SignatureProofObjectType<S: BosStr = DefaultStr> {
Blob,
Tree,
Commit,
Tag,
Other(S),
}
impl<S: BosStr> SignatureProofObjectType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Blob => "blob",
Self::Tree => "tree",
Self::Commit => "commit",
Self::Tag => "tag",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"blob" => Self::Blob,
"tree" => Self::Tree,
"commit" => Self::Commit,
"tag" => Self::Tag,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for SignatureProofObjectType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for SignatureProofObjectType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for SignatureProofObjectType<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for SignatureProofObjectType<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for SignatureProofObjectType<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for SignatureProofObjectType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = SignatureProofObjectType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
SignatureProofObjectType::Blob => SignatureProofObjectType::Blob,
SignatureProofObjectType::Tree => SignatureProofObjectType::Tree,
SignatureProofObjectType::Commit => SignatureProofObjectType::Commit,
SignatureProofObjectType::Tag => SignatureProofObjectType::Tag,
SignatureProofObjectType::Other(v) => SignatureProofObjectType::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SignatureProofGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: SignatureProof<S>,
}
impl<S: BosStr> SignatureProof<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, SignatureProofRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SignatureProofRecord;
impl XrpcResp for SignatureProofRecord {
const NSID: &'static str = "tech.lenooby09.didgit.signatureProof";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = SignatureProofGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<SignatureProofGetRecordOutput<S>> for SignatureProof<S> {
fn from(output: SignatureProofGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for SignatureProof<S> {
const NSID: &'static str = "tech.lenooby09.didgit.signatureProof";
type Record = SignatureProofRecord;
}
impl Collection for SignatureProofRecord {
const NSID: &'static str = "tech.lenooby09.didgit.signatureProof";
type Record = SignatureProofRecord;
}
impl<S: BosStr> LexiconSchema for SignatureProof<S> {
fn nsid() -> &'static str {
"tech.lenooby09.didgit.signatureProof"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_tech_lenooby09_didgit_signatureProof()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.object_id;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("object_id"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.object_type;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 16usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("object_type"),
max: 16usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.pds_endpoint {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 256usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("pds_endpoint"),
max: 256usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.signature;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("signature"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.signature_type;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("signature_type"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.signer;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 128usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("signer"),
max: 128usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod signature_proof_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type SignatureType;
type Signature;
type SignedAt;
type ObjectId;
type ObjectType;
type Signer;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type SignatureType = Unset;
type Signature = Unset;
type SignedAt = Unset;
type ObjectId = Unset;
type ObjectType = Unset;
type Signer = Unset;
}
pub struct SetSignatureType<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSignatureType<St> {}
impl<St: State> State for SetSignatureType<St> {
type SignatureType = Set<members::signature_type>;
type Signature = St::Signature;
type SignedAt = St::SignedAt;
type ObjectId = St::ObjectId;
type ObjectType = St::ObjectType;
type Signer = St::Signer;
}
pub struct SetSignature<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSignature<St> {}
impl<St: State> State for SetSignature<St> {
type SignatureType = St::SignatureType;
type Signature = Set<members::signature>;
type SignedAt = St::SignedAt;
type ObjectId = St::ObjectId;
type ObjectType = St::ObjectType;
type Signer = St::Signer;
}
pub struct SetSignedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSignedAt<St> {}
impl<St: State> State for SetSignedAt<St> {
type SignatureType = St::SignatureType;
type Signature = St::Signature;
type SignedAt = Set<members::signed_at>;
type ObjectId = St::ObjectId;
type ObjectType = St::ObjectType;
type Signer = St::Signer;
}
pub struct SetObjectId<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetObjectId<St> {}
impl<St: State> State for SetObjectId<St> {
type SignatureType = St::SignatureType;
type Signature = St::Signature;
type SignedAt = St::SignedAt;
type ObjectId = Set<members::object_id>;
type ObjectType = St::ObjectType;
type Signer = St::Signer;
}
pub struct SetObjectType<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetObjectType<St> {}
impl<St: State> State for SetObjectType<St> {
type SignatureType = St::SignatureType;
type Signature = St::Signature;
type SignedAt = St::SignedAt;
type ObjectId = St::ObjectId;
type ObjectType = Set<members::object_type>;
type Signer = St::Signer;
}
pub struct SetSigner<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSigner<St> {}
impl<St: State> State for SetSigner<St> {
type SignatureType = St::SignatureType;
type Signature = St::Signature;
type SignedAt = St::SignedAt;
type ObjectId = St::ObjectId;
type ObjectType = St::ObjectType;
type Signer = Set<members::signer>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct signature_type(());
pub struct signature(());
pub struct signed_at(());
pub struct object_id(());
pub struct object_type(());
pub struct signer(());
}
}
pub struct SignatureProofBuilder<S: BosStr, St: signature_proof_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<SignatureProofObjectType<S>>,
Option<S>,
Option<S>,
Option<S>,
Option<i64>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> SignatureProof<S> {
pub fn new() -> SignatureProofBuilder<S, signature_proof_state::Empty> {
SignatureProofBuilder::new()
}
}
impl<S: BosStr> SignatureProofBuilder<S, signature_proof_state::Empty> {
pub fn new() -> Self {
SignatureProofBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SignatureProofBuilder<S, St>
where
St: signature_proof_state::State,
St::ObjectId: signature_proof_state::IsUnset,
{
pub fn object_id(
mut self,
value: impl Into<S>,
) -> SignatureProofBuilder<S, signature_proof_state::SetObjectId<St>> {
self._fields.0 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SignatureProofBuilder<S, St>
where
St: signature_proof_state::State,
St::ObjectType: signature_proof_state::IsUnset,
{
pub fn object_type(
mut self,
value: impl Into<SignatureProofObjectType<S>>,
) -> SignatureProofBuilder<S, signature_proof_state::SetObjectType<St>> {
self._fields.1 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: signature_proof_state::State> SignatureProofBuilder<S, St> {
pub fn pds_endpoint(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_pds_endpoint(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> SignatureProofBuilder<S, St>
where
St: signature_proof_state::State,
St::Signature: signature_proof_state::IsUnset,
{
pub fn signature(
mut self,
value: impl Into<S>,
) -> SignatureProofBuilder<S, signature_proof_state::SetSignature<St>> {
self._fields.3 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SignatureProofBuilder<S, St>
where
St: signature_proof_state::State,
St::SignatureType: signature_proof_state::IsUnset,
{
pub fn signature_type(
mut self,
value: impl Into<S>,
) -> SignatureProofBuilder<S, signature_proof_state::SetSignatureType<St>> {
self._fields.4 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SignatureProofBuilder<S, St>
where
St: signature_proof_state::State,
St::SignedAt: signature_proof_state::IsUnset,
{
pub fn signed_at(
mut self,
value: impl Into<i64>,
) -> SignatureProofBuilder<S, signature_proof_state::SetSignedAt<St>> {
self._fields.5 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SignatureProofBuilder<S, St>
where
St: signature_proof_state::State,
St::Signer: signature_proof_state::IsUnset,
{
pub fn signer(
mut self,
value: impl Into<S>,
) -> SignatureProofBuilder<S, signature_proof_state::SetSigner<St>> {
self._fields.6 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SignatureProofBuilder<S, St>
where
St: signature_proof_state::State,
St::SignatureType: signature_proof_state::IsSet,
St::Signature: signature_proof_state::IsSet,
St::SignedAt: signature_proof_state::IsSet,
St::ObjectId: signature_proof_state::IsSet,
St::ObjectType: signature_proof_state::IsSet,
St::Signer: signature_proof_state::IsSet,
{
pub fn build(self) -> SignatureProof<S> {
SignatureProof {
object_id: self._fields.0.unwrap(),
object_type: self._fields.1.unwrap(),
pds_endpoint: self._fields.2,
signature: self._fields.3.unwrap(),
signature_type: self._fields.4.unwrap(),
signed_at: self._fields.5.unwrap(),
signer: self._fields.6.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> SignatureProof<S> {
SignatureProof {
object_id: self._fields.0.unwrap(),
object_type: self._fields.1.unwrap(),
pds_endpoint: self._fields.2,
signature: self._fields.3.unwrap(),
signature_type: self._fields.4.unwrap(),
signed_at: self._fields.5.unwrap(),
signer: self._fields.6.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_tech_lenooby09_didgit_signatureProof() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("tech.lenooby09.didgit.signatureProof"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A cryptographic proof that a did-git object was signed by a specific DID. This provides key-rotation-independent verification by anchoring the proof to a PDS or signing event.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("objectId"),
SmolStr::new_static("objectType"),
SmolStr::new_static("signatureType"),
SmolStr::new_static("signature"),
SmolStr::new_static("signedAt"),
SmolStr::new_static("signer")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("objectId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The hex SHA-256 object ID being proven.",
),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("objectType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The type of object."),
),
max_length: Some(16usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("pdsEndpoint"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The PDS endpoint that issued this proof (for service auth proofs).",
),
),
max_length: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signature"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The base64url-encoded signature or JWT token.",
),
),
max_length: Some(2048usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signatureType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The signature algorithm or token type (e.g., 'atproto-service-auth', 'jws', 'raw-ed25519', 'raw-ecdsa-secp256k1').",
),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signedAt"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signer"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The DID of the signer."),
),
max_length: Some(128usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}