#[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, Datetime};
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};
use crate::org_impactindexer::link::attestation;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Eip712Message<'a> {
#[serde(borrow)]
pub chain_id: CowStr<'a>,
#[serde(borrow)]
pub did: CowStr<'a>,
#[serde(borrow)]
pub evm_address: CowStr<'a>,
#[serde(borrow)]
pub nonce: CowStr<'a>,
#[serde(borrow)]
pub timestamp: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Attestation<'a> {
#[serde(borrow)]
pub address: CowStr<'a>,
pub chain_id: i64,
pub created_at: Datetime,
#[serde(borrow)]
pub message: attestation::Eip712Message<'a>,
#[serde(borrow)]
pub signature: CowStr<'a>,
#[serde(borrow)]
pub signature_type: AttestationSignatureType<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AttestationSignatureType<'a> {
Eoa,
Erc1271,
Erc6492,
Other(CowStr<'a>),
}
impl<'a> AttestationSignatureType<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Eoa => "eoa",
Self::Erc1271 => "erc1271",
Self::Erc6492 => "erc6492",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for AttestationSignatureType<'a> {
fn from(s: &'a str) -> Self {
match s {
"eoa" => Self::Eoa,
"erc1271" => Self::Erc1271,
"erc6492" => Self::Erc6492,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for AttestationSignatureType<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"eoa" => Self::Eoa,
"erc1271" => Self::Erc1271,
"erc6492" => Self::Erc6492,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for AttestationSignatureType<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for AttestationSignatureType<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for AttestationSignatureType<'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 AttestationSignatureType<'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 AttestationSignatureType<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for AttestationSignatureType<'_> {
type Output = AttestationSignatureType<'static>;
fn into_static(self) -> Self::Output {
match self {
AttestationSignatureType::Eoa => AttestationSignatureType::Eoa,
AttestationSignatureType::Erc1271 => AttestationSignatureType::Erc1271,
AttestationSignatureType::Erc6492 => AttestationSignatureType::Erc6492,
AttestationSignatureType::Other(v) => {
AttestationSignatureType::Other(v.into_static())
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct AttestationGetRecordOutput<'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: Attestation<'a>,
}
impl<'a> Attestation<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, AttestationRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
impl<'a> LexiconSchema for Eip712Message<'a> {
fn nsid() -> &'static str {
"org.impactindexer.link.attestation"
}
fn def_name() -> &'static str {
"eip712Message"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_impactindexer_link_attestation()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.chain_id;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 78usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("chain_id"),
max: 78usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.did;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("did"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.evm_address;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 42usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("evm_address"),
max: 42usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.evm_address;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 42usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("evm_address"),
min: 42usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.nonce;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 78usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("nonce"),
max: 78usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.timestamp;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 78usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("timestamp"),
max: 78usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AttestationRecord;
impl XrpcResp for AttestationRecord {
const NSID: &'static str = "org.impactindexer.link.attestation";
const ENCODING: &'static str = "application/json";
type Output<'de> = AttestationGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<AttestationGetRecordOutput<'_>> for Attestation<'_> {
fn from(output: AttestationGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Attestation<'_> {
const NSID: &'static str = "org.impactindexer.link.attestation";
type Record = AttestationRecord;
}
impl Collection for AttestationRecord {
const NSID: &'static str = "org.impactindexer.link.attestation";
type Record = AttestationRecord;
}
impl<'a> LexiconSchema for Attestation<'a> {
fn nsid() -> &'static str {
"org.impactindexer.link.attestation"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_impactindexer_link_attestation()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.address;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 42usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("address"),
max: 42usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.address;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 42usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("address"),
min: 42usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.chain_id;
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("chain_id"),
min: 1i64,
actual: *value,
});
}
}
{
let value = &self.signature;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("signature"),
max: 1000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.signature;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 132usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("signature"),
min: 132usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.signature_type;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("signature_type"),
max: 10usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
fn lexicon_doc_org_impactindexer_link_attestation() -> 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("org.impactindexer.link.attestation"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("eip712Message"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("The EIP-712 typed data message structure"),
),
required: Some(
vec![
SmolStr::new_static("did"),
SmolStr::new_static("evmAddress"),
SmolStr::new_static("chainId"),
SmolStr::new_static("timestamp"),
SmolStr::new_static("nonce")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("chainId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The chain ID as a string (for bigint compatibility, max uint256)",
),
),
max_length: Some(78usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("did"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The ATProto DID being linked"),
),
max_length: Some(2048usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("evmAddress"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The EVM address being linked (0x-prefixed)",
),
),
min_length: Some(42usize),
max_length: Some(42usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("nonce"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Replay protection nonce as a string (for bigint compatibility)",
),
),
max_length: Some(78usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("timestamp"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Unix timestamp as a string (for bigint compatibility)",
),
),
max_length: Some(78usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"An attestation linking an ATProto DID to an EVM wallet address, signed with EIP-712.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("address"),
SmolStr::new_static("chainId"),
SmolStr::new_static("signature"),
SmolStr::new_static("message"),
SmolStr::new_static("signatureType"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("address"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The EVM wallet address (checksummed or lowercase, 0x-prefixed)",
),
),
min_length: Some(42usize),
max_length: Some(42usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("chainId"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp when the attestation was created",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("message"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#eip712Message"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signature"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The EIP-712 signature in hex format (0x-prefixed, 65 bytes for ECDSA, longer for smart contract sigs)",
),
),
min_length: Some(132usize),
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signatureType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The type of signature: eoa (EOA/ECDSA), erc1271 (smart contract), erc6492 (counterfactual)",
),
),
max_length: Some(10usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod 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 Address;
type ChainId;
type Signature;
type SignatureType;
type CreatedAt;
type Message;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Address = Unset;
type ChainId = Unset;
type Signature = Unset;
type SignatureType = Unset;
type CreatedAt = Unset;
type Message = Unset;
}
pub struct SetAddress<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetAddress<S> {}
impl<S: State> State for SetAddress<S> {
type Address = Set<members::address>;
type ChainId = S::ChainId;
type Signature = S::Signature;
type SignatureType = S::SignatureType;
type CreatedAt = S::CreatedAt;
type Message = S::Message;
}
pub struct SetChainId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetChainId<S> {}
impl<S: State> State for SetChainId<S> {
type Address = S::Address;
type ChainId = Set<members::chain_id>;
type Signature = S::Signature;
type SignatureType = S::SignatureType;
type CreatedAt = S::CreatedAt;
type Message = S::Message;
}
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 Address = S::Address;
type ChainId = S::ChainId;
type Signature = Set<members::signature>;
type SignatureType = S::SignatureType;
type CreatedAt = S::CreatedAt;
type Message = S::Message;
}
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 Address = S::Address;
type ChainId = S::ChainId;
type Signature = S::Signature;
type SignatureType = Set<members::signature_type>;
type CreatedAt = S::CreatedAt;
type Message = S::Message;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type Address = S::Address;
type ChainId = S::ChainId;
type Signature = S::Signature;
type SignatureType = S::SignatureType;
type CreatedAt = Set<members::created_at>;
type Message = S::Message;
}
pub struct SetMessage<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetMessage<S> {}
impl<S: State> State for SetMessage<S> {
type Address = S::Address;
type ChainId = S::ChainId;
type Signature = S::Signature;
type SignatureType = S::SignatureType;
type CreatedAt = S::CreatedAt;
type Message = Set<members::message>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct address(());
pub struct chain_id(());
pub struct signature(());
pub struct signature_type(());
pub struct created_at(());
pub struct message(());
}
}
pub struct AttestationBuilder<'a, S: attestation_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<i64>,
Option<Datetime>,
Option<attestation::Eip712Message<'a>>,
Option<CowStr<'a>>,
Option<AttestationSignatureType<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Attestation<'a> {
pub fn new() -> AttestationBuilder<'a, attestation_state::Empty> {
AttestationBuilder::new()
}
}
impl<'a> AttestationBuilder<'a, attestation_state::Empty> {
pub fn new() -> Self {
AttestationBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::Address: attestation_state::IsUnset,
{
pub fn address(
mut self,
value: impl Into<CowStr<'a>>,
) -> AttestationBuilder<'a, attestation_state::SetAddress<S>> {
self._fields.0 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::ChainId: attestation_state::IsUnset,
{
pub fn chain_id(
mut self,
value: impl Into<i64>,
) -> AttestationBuilder<'a, attestation_state::SetChainId<S>> {
self._fields.1 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::CreatedAt: attestation_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> AttestationBuilder<'a, attestation_state::SetCreatedAt<S>> {
self._fields.2 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::Message: attestation_state::IsUnset,
{
pub fn message(
mut self,
value: impl Into<attestation::Eip712Message<'a>>,
) -> AttestationBuilder<'a, attestation_state::SetMessage<S>> {
self._fields.3 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::Signature: attestation_state::IsUnset,
{
pub fn signature(
mut self,
value: impl Into<CowStr<'a>>,
) -> AttestationBuilder<'a, attestation_state::SetSignature<S>> {
self._fields.4 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::SignatureType: attestation_state::IsUnset,
{
pub fn signature_type(
mut self,
value: impl Into<AttestationSignatureType<'a>>,
) -> AttestationBuilder<'a, attestation_state::SetSignatureType<S>> {
self._fields.5 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::Address: attestation_state::IsSet,
S::ChainId: attestation_state::IsSet,
S::Signature: attestation_state::IsSet,
S::SignatureType: attestation_state::IsSet,
S::CreatedAt: attestation_state::IsSet,
S::Message: attestation_state::IsSet,
{
pub fn build(self) -> Attestation<'a> {
Attestation {
address: self._fields.0.unwrap(),
chain_id: self._fields.1.unwrap(),
created_at: self._fields.2.unwrap(),
message: self._fields.3.unwrap(),
signature: self._fields.4.unwrap(),
signature_type: self._fields.5.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>,
>,
) -> Attestation<'a> {
Attestation {
address: self._fields.0.unwrap(),
chain_id: self._fields.1.unwrap(),
created_at: self._fields.2.unwrap(),
message: self._fields.3.unwrap(),
signature: self._fields.4.unwrap(),
signature_type: self._fields.5.unwrap(),
extra_data: Some(extra_data),
}
}
}