// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: tech.lenooby09.didgit.signatureProof // // This file was automatically generated from Lexicon schemas. // Any manual changes will be overwritten on the next regeneration. #[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}; /// 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. #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct SignatureProof<'a> { ///The hex SHA-256 object ID being proven. #[serde(borrow)] pub object_id: CowStr<'a>, ///The type of object. #[serde(borrow)] pub object_type: SignatureProofObjectType<'a>, ///The PDS endpoint that issued this proof (for service auth proofs). #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub pds_endpoint: Option>, ///The base64url-encoded signature or JWT token. #[serde(borrow)] pub signature: CowStr<'a>, ///The signature algorithm or token type (e.g., 'atproto-service-auth', 'jws', 'raw-ed25519', 'raw-ecdsa-secp256k1'). #[serde(borrow)] pub signature_type: CowStr<'a>, ///Unix timestamp (seconds) when the proof was created. pub signed_at: i64, ///The DID of the signer. #[serde(borrow)] pub signer: CowStr<'a>, } /// The type of object. #[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 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 for SignatureProofObjectType<'a> { fn as_ref(&self) -> &str { self.as_str() } } impl<'a> serde::Serialize for SignatureProofObjectType<'a> { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de, 'a> serde::Deserialize<'de> for SignatureProofObjectType<'a> where 'de: 'a, { fn deserialize(deserializer: D) -> Result 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()) } } } } /// Typed wrapper for GetRecord response with this collection's record type. #[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>, #[serde(borrow)] pub uri: AtUri<'a>, #[serde(borrow)] pub value: SignatureProof<'a>, } impl<'a> SignatureProof<'a> { pub fn uri( uri: impl Into>, ) -> Result, UriError> { RecordUri::try_from_uri(AtUri::new_cow(uri.into())?) } } /// Marker type for deserializing records from this collection. #[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> 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 ::len(value.as_ref()) > 64usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("object_id"), max: 64usize, actual: ::len(value.as_ref()), }); } } { let value = &self.object_type; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 16usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("object_type"), max: 16usize, actual: ::len(value.as_ref()), }); } } if let Some(ref value) = self.pds_endpoint { #[allow(unused_comparisons)] if ::len(value.as_ref()) > 256usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("pds_endpoint"), max: 256usize, actual: ::len(value.as_ref()), }); } } { let value = &self.signature; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 2048usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("signature"), max: 2048usize, actual: ::len(value.as_ref()), }); } } { let value = &self.signature_type; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 64usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("signature_type"), max: 64usize, actual: ::len(value.as_ref()), }); } } { let value = &self.signer; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 128usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("signer"), max: 128usize, actual: ::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 {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type Signer; type ObjectType; type Signature; type ObjectId; type SignatureType; type SignedAt; } /// Empty state - all required fields are unset 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; } ///State transition - sets the `signer` field to Set pub struct SetSigner(PhantomData S>); impl sealed::Sealed for SetSigner {} impl State for SetSigner { type Signer = Set; type ObjectType = S::ObjectType; type Signature = S::Signature; type ObjectId = S::ObjectId; type SignatureType = S::SignatureType; type SignedAt = S::SignedAt; } ///State transition - sets the `object_type` field to Set pub struct SetObjectType(PhantomData S>); impl sealed::Sealed for SetObjectType {} impl State for SetObjectType { type Signer = S::Signer; type ObjectType = Set; type Signature = S::Signature; type ObjectId = S::ObjectId; type SignatureType = S::SignatureType; type SignedAt = S::SignedAt; } ///State transition - sets the `signature` field to Set pub struct SetSignature(PhantomData S>); impl sealed::Sealed for SetSignature {} impl State for SetSignature { type Signer = S::Signer; type ObjectType = S::ObjectType; type Signature = Set; type ObjectId = S::ObjectId; type SignatureType = S::SignatureType; type SignedAt = S::SignedAt; } ///State transition - sets the `object_id` field to Set pub struct SetObjectId(PhantomData S>); impl sealed::Sealed for SetObjectId {} impl State for SetObjectId { type Signer = S::Signer; type ObjectType = S::ObjectType; type Signature = S::Signature; type ObjectId = Set; type SignatureType = S::SignatureType; type SignedAt = S::SignedAt; } ///State transition - sets the `signature_type` field to Set pub struct SetSignatureType(PhantomData S>); impl sealed::Sealed for SetSignatureType {} impl State for SetSignatureType { type Signer = S::Signer; type ObjectType = S::ObjectType; type Signature = S::Signature; type ObjectId = S::ObjectId; type SignatureType = Set; type SignedAt = S::SignedAt; } ///State transition - sets the `signed_at` field to Set pub struct SetSignedAt(PhantomData S>); impl sealed::Sealed for SetSignedAt {} impl State for SetSignedAt { type Signer = S::Signer; type ObjectType = S::ObjectType; type Signature = S::Signature; type ObjectId = S::ObjectId; type SignatureType = S::SignatureType; type SignedAt = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `signer` field pub struct signer(()); ///Marker type for the `object_type` field pub struct object_type(()); ///Marker type for the `signature` field pub struct signature(()); ///Marker type for the `object_id` field pub struct object_id(()); ///Marker type for the `signature_type` field pub struct signature_type(()); ///Marker type for the `signed_at` field pub struct signed_at(()); } } /// Builder for constructing an instance of this type pub struct SignatureProofBuilder<'a, S: signature_proof_state::State> { _state: PhantomData S>, _fields: ( Option>, Option>, Option>, Option>, Option>, Option, Option>, ), _lifetime: PhantomData<&'a ()>, } impl<'a> SignatureProof<'a> { /// Create a new builder for this type pub fn new() -> SignatureProofBuilder<'a, signature_proof_state::Empty> { SignatureProofBuilder::new() } } impl<'a> SignatureProofBuilder<'a, signature_proof_state::Empty> { /// Create a new builder with all fields unset 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, { /// Set the `objectId` field (required) pub fn object_id( mut self, value: impl Into>, ) -> SignatureProofBuilder<'a, signature_proof_state::SetObjectId> { 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, { /// Set the `objectType` field (required) pub fn object_type( mut self, value: impl Into>, ) -> SignatureProofBuilder<'a, signature_proof_state::SetObjectType> { 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> { /// Set the `pdsEndpoint` field (optional) pub fn pds_endpoint(mut self, value: impl Into>>) -> Self { self._fields.2 = value.into(); self } /// Set the `pdsEndpoint` field to an Option value (optional) pub fn maybe_pds_endpoint(mut self, value: Option>) -> Self { self._fields.2 = value; self } } impl<'a, S> SignatureProofBuilder<'a, S> where S: signature_proof_state::State, S::Signature: signature_proof_state::IsUnset, { /// Set the `signature` field (required) pub fn signature( mut self, value: impl Into>, ) -> SignatureProofBuilder<'a, signature_proof_state::SetSignature> { 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, { /// Set the `signatureType` field (required) pub fn signature_type( mut self, value: impl Into>, ) -> SignatureProofBuilder<'a, signature_proof_state::SetSignatureType> { 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, { /// Set the `signedAt` field (required) pub fn signed_at( mut self, value: impl Into, ) -> SignatureProofBuilder<'a, signature_proof_state::SetSignedAt> { 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, { /// Set the `signer` field (required) pub fn signer( mut self, value: impl Into>, ) -> SignatureProofBuilder<'a, signature_proof_state::SetSigner> { 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, { /// Build the final struct 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(), } } /// Build the final struct with custom extra_data 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() } }