#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid};
use jacquard_common::types::uri::{RecordUri, UriError};
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};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SignatureProof<'a> {
#[serde(borrow)]
pub object_id: CowStr<'a>,
#[serde(borrow)]
pub object_type: SignatureProofObjectType<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub pds_endpoint: Option<CowStr<'a>>,
#[serde(borrow)]
pub signature: CowStr<'a>,
#[serde(borrow)]
pub signature_type: CowStr<'a>,
pub signed_at: i64,
#[serde(borrow)]
pub signer: CowStr<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SignatureProofObjectType<'a> {
Blob,
Tree,
Commit,
Tag,
Other(CowStr<'a>),
}
impl<'a> SignatureProofObjectType<'a> {
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(),
}
}
}
impl<'a> From<&'a str> for SignatureProofObjectType<'a> {
fn from(s: &'a str) -> Self {
match s {
"blob" => Self::Blob,
"tree" => Self::Tree,
"commit" => Self::Commit,
"tag" => Self::Tag,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for SignatureProofObjectType<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"blob" => Self::Blob,
"tree" => Self::Tree,
"commit" => Self::Commit,
"tag" => Self::Tag,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for SignatureProofObjectType<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for SignatureProofObjectType<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for SignatureProofObjectType<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for SignatureProofObjectType<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for SignatureProofObjectType<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for SignatureProofObjectType<'_> {
type Output = SignatureProofObjectType<'static>;
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<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: SignatureProof<'a>,
}
impl<'a> SignatureProof<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, SignatureProofRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[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<'de> = SignatureProofGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<SignatureProofGetRecordOutput<'_>> for SignatureProof<'_> {
fn from(output: SignatureProofGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for SignatureProof<'_> {
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<'a> LexiconSchema for SignatureProof<'a> {
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::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Signer;
type ObjectType;
type Signature;
type ObjectId;
type SignatureType;
type SignedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Signer = Unset;
type ObjectType = Unset;
type Signature = Unset;
type ObjectId = Unset;
type SignatureType = Unset;
type SignedAt = Unset;
}
pub struct SetSigner<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSigner<S> {}
impl<S: State> State for SetSigner<S> {
type Signer = Set<members::signer>;
type ObjectType = S::ObjectType;
type Signature = S::Signature;
type ObjectId = S::ObjectId;
type SignatureType = S::SignatureType;
type SignedAt = S::SignedAt;
}
pub struct SetObjectType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetObjectType<S> {}
impl<S: State> State for SetObjectType<S> {
type Signer = S::Signer;
type ObjectType = Set<members::object_type>;
type Signature = S::Signature;
type ObjectId = S::ObjectId;
type SignatureType = S::SignatureType;
type SignedAt = S::SignedAt;
}
pub struct SetSignature<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSignature<S> {}
impl<S: State> State for SetSignature<S> {
type Signer = S::Signer;
type ObjectType = S::ObjectType;
type Signature = Set<members::signature>;
type ObjectId = S::ObjectId;
type SignatureType = S::SignatureType;
type SignedAt = S::SignedAt;
}
pub struct SetObjectId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetObjectId<S> {}
impl<S: State> State for SetObjectId<S> {
type Signer = S::Signer;
type ObjectType = S::ObjectType;
type Signature = S::Signature;
type ObjectId = Set<members::object_id>;
type SignatureType = S::SignatureType;
type SignedAt = S::SignedAt;
}
pub struct SetSignatureType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSignatureType<S> {}
impl<S: State> State for SetSignatureType<S> {
type Signer = S::Signer;
type ObjectType = S::ObjectType;
type Signature = S::Signature;
type ObjectId = S::ObjectId;
type SignatureType = Set<members::signature_type>;
type SignedAt = S::SignedAt;
}
pub struct SetSignedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSignedAt<S> {}
impl<S: State> State for SetSignedAt<S> {
type Signer = S::Signer;
type ObjectType = S::ObjectType;
type Signature = S::Signature;
type ObjectId = S::ObjectId;
type SignatureType = S::SignatureType;
type SignedAt = Set<members::signed_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct signer(());
pub struct object_type(());
pub struct signature(());
pub struct object_id(());
pub struct signature_type(());
pub struct signed_at(());
}
}
pub struct SignatureProofBuilder<'a, S: signature_proof_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<SignatureProofObjectType<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<i64>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> SignatureProof<'a> {
pub fn new() -> SignatureProofBuilder<'a, signature_proof_state::Empty> {
SignatureProofBuilder::new()
}
}
impl<'a> SignatureProofBuilder<'a, signature_proof_state::Empty> {
pub fn new() -> Self {
SignatureProofBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> SignatureProofBuilder<'a, S>
where
S: signature_proof_state::State,
S::ObjectId: signature_proof_state::IsUnset,
{
pub fn object_id(
mut self,
value: impl Into<CowStr<'a>>,
) -> SignatureProofBuilder<'a, signature_proof_state::SetObjectId<S>> {
self._fields.0 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> SignatureProofBuilder<'a, S>
where
S: signature_proof_state::State,
S::ObjectType: signature_proof_state::IsUnset,
{
pub fn object_type(
mut self,
value: impl Into<SignatureProofObjectType<'a>>,
) -> SignatureProofBuilder<'a, signature_proof_state::SetObjectType<S>> {
self._fields.1 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: signature_proof_state::State> SignatureProofBuilder<'a, S> {
pub fn pds_endpoint(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_pds_endpoint(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> SignatureProofBuilder<'a, S>
where
S: signature_proof_state::State,
S::Signature: signature_proof_state::IsUnset,
{
pub fn signature(
mut self,
value: impl Into<CowStr<'a>>,
) -> SignatureProofBuilder<'a, signature_proof_state::SetSignature<S>> {
self._fields.3 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> SignatureProofBuilder<'a, S>
where
S: signature_proof_state::State,
S::SignatureType: signature_proof_state::IsUnset,
{
pub fn signature_type(
mut self,
value: impl Into<CowStr<'a>>,
) -> SignatureProofBuilder<'a, signature_proof_state::SetSignatureType<S>> {
self._fields.4 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> SignatureProofBuilder<'a, S>
where
S: signature_proof_state::State,
S::SignedAt: signature_proof_state::IsUnset,
{
pub fn signed_at(
mut self,
value: impl Into<i64>,
) -> SignatureProofBuilder<'a, signature_proof_state::SetSignedAt<S>> {
self._fields.5 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> SignatureProofBuilder<'a, S>
where
S: signature_proof_state::State,
S::Signer: signature_proof_state::IsUnset,
{
pub fn signer(
mut self,
value: impl Into<CowStr<'a>>,
) -> SignatureProofBuilder<'a, signature_proof_state::SetSigner<S>> {
self._fields.6 = Option::Some(value.into());
SignatureProofBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> SignatureProofBuilder<'a, S>
where
S: signature_proof_state::State,
S::Signer: signature_proof_state::IsSet,
S::ObjectType: signature_proof_state::IsSet,
S::Signature: signature_proof_state::IsSet,
S::ObjectId: signature_proof_state::IsSet,
S::SignatureType: signature_proof_state::IsSet,
S::SignedAt: signature_proof_state::IsSet,
{
pub fn build(self) -> SignatureProof<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> SignatureProof<'a> {
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> {
#[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("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()
}
}