#[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, Datetime};
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;
use crate::org_impactindexer::link::attestation;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Eip712Message<S: BosStr = DefaultStr> {
pub chain_id: S,
pub did: S,
pub evm_address: S,
pub nonce: S,
pub timestamp: 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",
rename = "org.impactindexer.link.attestation",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Attestation<S: BosStr = DefaultStr> {
pub address: S,
pub chain_id: i64,
pub created_at: Datetime,
pub message: attestation::Eip712Message<S>,
pub signature: S,
pub signature_type: AttestationSignatureType<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 AttestationSignatureType<S: BosStr = DefaultStr> {
Eoa,
Erc1271,
Erc6492,
Other(S),
}
impl<S: BosStr> AttestationSignatureType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Eoa => "eoa",
Self::Erc1271 => "erc1271",
Self::Erc6492 => "erc6492",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"eoa" => Self::Eoa,
"erc1271" => Self::Erc1271,
"erc6492" => Self::Erc6492,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for AttestationSignatureType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for AttestationSignatureType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for AttestationSignatureType<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 AttestationSignatureType<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 AttestationSignatureType<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for AttestationSignatureType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = AttestationSignatureType<S::Output>;
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<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Attestation<S>,
}
impl<S: BosStr> Attestation<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, AttestationRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for Eip712Message<S> {
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<S: BosStr> = AttestationGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<AttestationGetRecordOutput<S>> for Attestation<S> {
fn from(output: AttestationGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Attestation<S> {
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<S: BosStr> LexiconSchema for Attestation<S> {
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> {
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("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::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Address;
type CreatedAt;
type Message;
type SignatureType;
type ChainId;
type Signature;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Address = Unset;
type CreatedAt = Unset;
type Message = Unset;
type SignatureType = Unset;
type ChainId = Unset;
type Signature = Unset;
}
pub struct SetAddress<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAddress<St> {}
impl<St: State> State for SetAddress<St> {
type Address = Set<members::address>;
type CreatedAt = St::CreatedAt;
type Message = St::Message;
type SignatureType = St::SignatureType;
type ChainId = St::ChainId;
type Signature = St::Signature;
}
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 Address = St::Address;
type CreatedAt = Set<members::created_at>;
type Message = St::Message;
type SignatureType = St::SignatureType;
type ChainId = St::ChainId;
type Signature = St::Signature;
}
pub struct SetMessage<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetMessage<St> {}
impl<St: State> State for SetMessage<St> {
type Address = St::Address;
type CreatedAt = St::CreatedAt;
type Message = Set<members::message>;
type SignatureType = St::SignatureType;
type ChainId = St::ChainId;
type Signature = St::Signature;
}
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 Address = St::Address;
type CreatedAt = St::CreatedAt;
type Message = St::Message;
type SignatureType = Set<members::signature_type>;
type ChainId = St::ChainId;
type Signature = St::Signature;
}
pub struct SetChainId<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetChainId<St> {}
impl<St: State> State for SetChainId<St> {
type Address = St::Address;
type CreatedAt = St::CreatedAt;
type Message = St::Message;
type SignatureType = St::SignatureType;
type ChainId = Set<members::chain_id>;
type Signature = St::Signature;
}
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 Address = St::Address;
type CreatedAt = St::CreatedAt;
type Message = St::Message;
type SignatureType = St::SignatureType;
type ChainId = St::ChainId;
type Signature = Set<members::signature>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct address(());
pub struct created_at(());
pub struct message(());
pub struct signature_type(());
pub struct chain_id(());
pub struct signature(());
}
}
pub struct AttestationBuilder<S: BosStr, St: attestation_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<i64>,
Option<Datetime>,
Option<attestation::Eip712Message<S>>,
Option<S>,
Option<AttestationSignatureType<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Attestation<S> {
pub fn new() -> AttestationBuilder<S, attestation_state::Empty> {
AttestationBuilder::new()
}
}
impl<S: BosStr> AttestationBuilder<S, attestation_state::Empty> {
pub fn new() -> Self {
AttestationBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AttestationBuilder<S, St>
where
St: attestation_state::State,
St::Address: attestation_state::IsUnset,
{
pub fn address(
mut self,
value: impl Into<S>,
) -> AttestationBuilder<S, attestation_state::SetAddress<St>> {
self._fields.0 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AttestationBuilder<S, St>
where
St: attestation_state::State,
St::ChainId: attestation_state::IsUnset,
{
pub fn chain_id(
mut self,
value: impl Into<i64>,
) -> AttestationBuilder<S, attestation_state::SetChainId<St>> {
self._fields.1 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AttestationBuilder<S, St>
where
St: attestation_state::State,
St::CreatedAt: attestation_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> AttestationBuilder<S, attestation_state::SetCreatedAt<St>> {
self._fields.2 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AttestationBuilder<S, St>
where
St: attestation_state::State,
St::Message: attestation_state::IsUnset,
{
pub fn message(
mut self,
value: impl Into<attestation::Eip712Message<S>>,
) -> AttestationBuilder<S, attestation_state::SetMessage<St>> {
self._fields.3 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AttestationBuilder<S, St>
where
St: attestation_state::State,
St::Signature: attestation_state::IsUnset,
{
pub fn signature(
mut self,
value: impl Into<S>,
) -> AttestationBuilder<S, attestation_state::SetSignature<St>> {
self._fields.4 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AttestationBuilder<S, St>
where
St: attestation_state::State,
St::SignatureType: attestation_state::IsUnset,
{
pub fn signature_type(
mut self,
value: impl Into<AttestationSignatureType<S>>,
) -> AttestationBuilder<S, attestation_state::SetSignatureType<St>> {
self._fields.5 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AttestationBuilder<S, St>
where
St: attestation_state::State,
St::Address: attestation_state::IsSet,
St::CreatedAt: attestation_state::IsSet,
St::Message: attestation_state::IsSet,
St::SignatureType: attestation_state::IsSet,
St::ChainId: attestation_state::IsSet,
St::Signature: attestation_state::IsSet,
{
pub fn build(self) -> Attestation<S> {
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<SmolStr, Data<S>>) -> Attestation<S> {
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),
}
}
}