From d1b828c7750a2471e66caf73674dcb45cba8f133 Mon Sep 17 00:00:00 2001 From: DaevMithran Date: Sat, 16 Nov 2024 13:16:11 +0700 Subject: [PATCH] Initialize ether wallet --- src/clients/evm/OffChain/index.ts | 84 +++++----- src/clients/evm/OnChain/index.ts | 267 +++++++++++++++--------------- src/types/index.ts | 214 ++++++++++++------------ 3 files changed, 285 insertions(+), 280 deletions(-) diff --git a/src/clients/evm/OffChain/index.ts b/src/clients/evm/OffChain/index.ts index e5c8672..ec7613f 100644 --- a/src/clients/evm/OffChain/index.ts +++ b/src/clients/evm/OffChain/index.ts @@ -1,5 +1,5 @@ -import { ChainType, OffChainClientOptions, SignType } from '../../../types'; -import { OffChainClientBase } from '../../../interface/OffChainClientBase'; +import { ChainType, OffChainClientOptions, SignType } from "../../../types" +import { OffChainClientBase } from "../../../interface/OffChainClientBase" import { PrivateKeyAccount, PublicClient, @@ -8,36 +8,36 @@ import { createPublicClient, createWalletClient, custom, -} from 'viem'; -import { mainnet } from 'viem/chains'; -import { OffChainRpc } from '../../../types/offChain'; +} from "viem" +import { mainnet } from "viem/chains" +import { OffChainRpc } from "../../../types/offChain" export class OffChainClient extends OffChainClientBase { - rpc: OffChainRpc | string; - public walletClient!: WalletClient; - public publicClient!: PublicClient; - public privateKeyAccount?: PrivateKeyAccount; - public chain: any; - public account!: { address: `0x${string}` }; + rpc: OffChainRpc | string + public walletClient!: WalletClient + public publicClient!: PublicClient + public privateKeyAccount?: PrivateKeyAccount + public chain: any + public account!: { address: `0x${string}` } constructor({ signType, rpcUrl: rpc, account: privateKeyAccount, walletClient, }: { - signType: SignType; - rpcUrl?: OffChainRpc | string; - account?: PrivateKeyAccount; - walletClient?: WalletClient; + signType: SignType + rpcUrl?: OffChainRpc | string + account?: PrivateKeyAccount + walletClient?: WalletClient }) { - super(ChainType.evm, signType, rpc || OffChainRpc.mainnet); - this.rpc = rpc || OffChainRpc.mainnet; - const chain = mainnet; - this.chain = chain; + super(ChainType.evm, signType, rpc || OffChainRpc.mainnet) + this.rpc = rpc || OffChainRpc.mainnet + const chain = mainnet + this.chain = chain this.publicClient = createPublicClient({ chain, transport: http(), - }); + }) this.walletClient = walletClient || createWalletClient({ @@ -47,19 +47,19 @@ export class OffChainClient extends OffChainClientBase { : window.ethereum ? custom(window.ethereum) : http(), - }); - this.privateKeyAccount = privateKeyAccount; + }) + this.privateKeyAccount = privateKeyAccount } public async getAccount() { - let account; + let account if (this.privateKeyAccount) { - account = this.privateKeyAccount; + account = this.privateKeyAccount } else { - const accounts = await this.walletClient.getAddresses(); - account = { address: accounts[0] } as PrivateKeyAccount; + const accounts = await this.walletClient.getAddresses() + account = { address: accounts[0] } as PrivateKeyAccount } - return account; + return account } async signTypedData({ @@ -67,47 +67,47 @@ export class OffChainClient extends OffChainClientBase { types, primaryType, }: { - message: { [key: string]: any }; - types: { [key: string]: { name: string; type: string }[] }; - primaryType: string; + message: { [key: string]: any } + types: { [key: string]: { name: string; type: string }[] } + primaryType: string }): Promise<{ message: any; signature: string }> { const data: any = { domain: { - name: 'sign.global', - version: '1', + name: "sign.global", + version: "1", } as const, message: message, primaryType, types: { EIP712Domain: [ - { name: 'name', type: 'string' }, - { name: 'version', type: 'string' }, + { name: "name", type: "string" }, + { name: "version", type: "string" }, ], ...types, } as const, - }; - const account = await this.getAccount(); + } + const account = await this.getAccount() const signTypedData: any = this.privateKeyAccount ? account.signTypedData - : this.walletClient.signTypedData; + : this.walletClient.signTypedData const signature = await signTypedData({ account: account.address, ...data, - }); + }) return { message: data, signature, - }; + } } async signMessage(message: string): Promise { - const account = await this.getAccount(); + const account = await this.getAccount() const signMessage = this.privateKeyAccount ? account.signMessage - : this.walletClient.signMessage; + : this.walletClient.signMessage return await signMessage({ account: account.address, message, - }); + }) } } diff --git a/src/clients/evm/OnChain/index.ts b/src/clients/evm/OnChain/index.ts index c2f831e..0ff9184 100644 --- a/src/clients/evm/OnChain/index.ts +++ b/src/clients/evm/OnChain/index.ts @@ -13,7 +13,7 @@ import { createWalletClient, custom, isAddress, -} from 'viem'; +} from "viem" import { Attestation, AttestationResult, @@ -28,33 +28,36 @@ import { Schema, SchemaItem, SchemaResult, -} from '../../../types'; +} from "../../../types" import { decodeOnChainData, encodeOnChainData, validateObject, -} from '../../../utils'; -import { SignProtocolClientBase } from '../../../interface/SignProtocolClientBase'; -import { EvmChains } from '../types'; -import { ContractInfoMap } from '../constants'; -import abiJson from './abi/SignProtocal.json'; -import { getDataFromStorage } from '../../../services'; +} from "../../../utils" +import { SignProtocolClientBase } from "../../../interface/SignProtocolClientBase" +import { EvmChains } from "../types" +import { ContractInfoMap } from "../constants" +import abiJson from "./abi/SignProtocal.json" +import { getDataFromStorage } from "../../../services" +import { ethers } from "ethers" export class OnChainClient implements SignProtocolClientBase { - public walletClient: WalletClient; - public publicClient!: PublicClient; - public contractInfo!: ContractInfo; - public privateKeyAccount?: PrivateKeyAccount; - public chain: any; - public account!: { address: `0x${string}` }; + public walletClient: WalletClient + public publicClient!: PublicClient + public contractInfo!: ContractInfo + public privateKeyAccount?: PrivateKeyAccount + public chain: any + public account!: { address: `0x${string}` } + public wallet: ethers.Wallet constructor({ chain: chainType, rpcUrl: rpc, account: privateKeyAccount, walletClient, + wallet, }: OnChainClientOptions) { this.contractInfo = chainType ? ContractInfoMap[chainType] - : ContractInfoMap[EvmChains.sepolia]; + : ContractInfoMap[EvmChains.sepolia] const chain = { ...this.contractInfo?.chain, rpcUrls: rpc @@ -64,13 +67,14 @@ export class OnChainClient implements SignProtocolClientBase { }, } : this.contractInfo?.chain.rpcUrls, - }; - this.chain = chain; + } + this.chain = chain + this.wallet = wallet // @ts-ignore this.publicClient = createPublicClient({ chain, transport: http(), - }); + }) this.walletClient = walletClient || createWalletClient({ @@ -80,45 +84,45 @@ export class OnChainClient implements SignProtocolClientBase { : window.ethereum ? custom(window.ethereum) : http(), - }); - this.privateKeyAccount = privateKeyAccount; + }) + this.privateKeyAccount = privateKeyAccount } public async signMessage(message: string): Promise<`0x${string}`> { - const account = await this.getAccount(); + const account = await this.getAccount() return await this.walletClient.signMessage({ account: this.privateKeyAccount ? account : account.address, message: { raw: message as any }, - }); + }) } public async swithChain() { - const walletChainId = await this.walletClient.getChainId(); + const walletChainId = await this.walletClient.getChainId() if (walletChainId !== this.chain.id) { try { await this.walletClient.switchChain({ id: this.chain.id, - }); + }) } catch (error: any) { if (error?.code !== 4001) { await this.walletClient.addChain({ chain: this.chain, - }); + }) await this.walletClient.switchChain({ id: this.chain.id, - }); + }) } } } } public async getAccount() { - let account; + let account if (this.privateKeyAccount) { - account = this.privateKeyAccount; + account = this.privateKeyAccount } else { - const accounts = await this.walletClient.getAddresses(); - account = { address: accounts[0] } as PrivateKeyAccount; + const accounts = await this.walletClient.getAddresses() + account = { address: accounts[0] } as PrivateKeyAccount } - return account; + return account } public async invokeContractRead( @@ -131,10 +135,10 @@ export class OnChainClient implements SignProtocolClientBase { abi: abiJson.abi, functionName, args, - }); + }) } catch (error: any) { - console.error(error.message); - throw error; + console.error(error.message) + throw error } } @@ -145,8 +149,8 @@ export class OnChainClient implements SignProtocolClientBase { abi?: any ): Promise { try { - const account = await this.getAccount(); - await this.swithChain(); + const account = await this.getAccount() + await this.swithChain() const data = { account: this.privateKeyAccount ? account : account.address, address: this.contractInfo.address, @@ -155,20 +159,20 @@ export class OnChainClient implements SignProtocolClientBase { args, value, chain: this.chain, - }; - const { request } = await this.publicClient.simulateContract(data); - return this.walletClient.writeContract(request); + } + const { request } = await this.publicClient.simulateContract(data) + return this.walletClient.writeContract(request) } catch (error: any) { - console.error(error.message); - throw error; + console.error(error.message) + throw error } } async createSchema( schema: OnChainSchema, options?: { - delegationSignature?: string; - getTxHash?: (txHash: `0x${string}`) => void; + delegationSignature?: string + getTxHash?: (txHash: `0x${string}`) => void } ): Promise { const { @@ -180,44 +184,44 @@ export class OnChainClient implements SignProtocolClientBase { name, description, registrant, - } = schema; - const account = await this.getAccount(); - const dataLocation = schema.dataLocation || DataLocationOnChain.ONCHAIN; - const { delegationSignature, getTxHash } = options || {}; - const txHash = await this.invokeContractWrite('register', [ + } = schema + const account = await this.getAccount() + const dataLocation = schema.dataLocation || DataLocationOnChain.ONCHAIN + const { delegationSignature, getTxHash } = options || {} + const txHash = await this.invokeContractWrite("register", [ { registrant: registrant || account.address, revocable: revocable === undefined ? true : revocable, dataLocation: dataLocation, maxValidFor: maxValidFor || 0, - hook: hook || resolver || '0x0000000000000000000000000000000000000000', + hook: hook || resolver || "0x0000000000000000000000000000000000000000", timestamp: 0, data: dataLocation === DataLocationOnChain.ONCHAIN ? JSON.stringify({ name, description, data }) : data, }, - delegationSignature || '', - ]); - getTxHash && getTxHash(txHash); + delegationSignature || "", + ]) + getTxHash && getTxHash(txHash) const res = await this.publicClient.waitForTransactionReceipt({ hash: txHash, - }); + }) const decodedLog: any = decodeEventLog({ abi: abiJson.abi, topics: res.logs[0].topics, data: res.logs[0].data, - }); + }) - const schemaId = numberToHex(decodedLog.args.schemaId); - return { schemaId, txHash }; + const schemaId = numberToHex(decodedLog.args.schemaId) + return { schemaId, txHash } } async getSchema(schemaId: string): Promise { - const res: any = await this.invokeContractRead('getSchema', [schemaId]); - if (res.data === '') { - throw new Error('schema not found'); + const res: any = await this.invokeContractRead("getSchema", [schemaId]) + if (res.data === "") { + throw new Error("schema not found") } const { revocable, @@ -227,17 +231,17 @@ export class OnChainClient implements SignProtocolClientBase { hook, data, timestamp, - } = res; - const isOnChain = dataLocation === DataLocationOnChain.ONCHAIN; - let dataObj: any; + } = res + const isOnChain = dataLocation === DataLocationOnChain.ONCHAIN + let dataObj: any if (isOnChain) { - dataObj = JSON.parse(data); + dataObj = JSON.parse(data) } else if ( dataLocation === DataLocationOnChain.ARWEAVE || dataLocation === DataLocationOnChain.IPFS ) { - const res = await getDataFromStorage({ dataId: data, dataLocation }); - dataObj = res.data; + const res = await getDataFromStorage({ dataId: data, dataLocation }) + dataObj = res.data } const result: Schema = { name: dataObj.name, @@ -249,37 +253,37 @@ export class OnChainClient implements SignProtocolClientBase { hook: hook || resolver, data: dataObj.data, registrant: res.registrant, - }; - return result; + } + return result } async revokeAttestation( attestationId: string, options?: { - reason?: string; - delegationSignature?: string; - getTxHash?: (txHash: `0x${string}`) => void; + reason?: string + delegationSignature?: string + getTxHash?: (txHash: `0x${string}`) => void } ): Promise { - const { reason, delegationSignature, getTxHash } = options || {}; - const txHash = await this.invokeContractWrite('revoke', [ + const { reason, delegationSignature, getTxHash } = options || {} + const txHash = await this.invokeContractWrite("revoke", [ attestationId, - reason || '', - delegationSignature || '', - '', - ]); - getTxHash && getTxHash(txHash); + reason || "", + delegationSignature || "", + "", + ]) + getTxHash && getTxHash(txHash) const res = await this.publicClient.waitForTransactionReceipt({ hash: txHash, - }); + }) const decodedLog: any = decodeEventLog({ abi: abiJson.abi, topics: res.logs[0].topics, data: res.logs[0].data, - }); - const id = numberToHex(decodedLog.args.attestationId); - return { attestationId: id, txHash, reason: decodedLog.args.reason }; + }) + const id = numberToHex(decodedLog.args.attestationId) + return { attestationId: id, txHash, reason: decodedLog.args.reason } } async createAttestation( attestation: OnChainAttestation, @@ -296,17 +300,16 @@ export class OnChainClient implements SignProtocolClientBase { attester, attestTimestamp, revokeTimestamp, - } = attestation; + } = attestation const { delegationSignature, getTxHash, resolverFeesETH, recipientEncodingType, extraData, - } = options || {}; - const dataLocation = - attestation.dataLocation || DataLocationOnChain.ONCHAIN; - let attestationData; + } = options || {} + const dataLocation = attestation.dataLocation || DataLocationOnChain.ONCHAIN + let attestationData if (delegationSignature) { attestationData = { schemaId, @@ -319,29 +322,29 @@ export class OnChainClient implements SignProtocolClientBase { dataLocation, attestTimestamp, revokeTimestamp, - }; + } } else { - const account = await this.getAccount(); + const account = await this.getAccount() if (!attestation.schemaId) { - throw new Error('schemaId is required'); + throw new Error("schemaId is required") } - const schema = await this.getSchema(attestation.schemaId); - const schemaData = schema?.data; + const schema = await this.getSchema(attestation.schemaId) + const schemaData = schema?.data if (!schema) { - throw new Error('schema not found'); + throw new Error("schema not found") } if ( schema.dataLocation === DataLocationOnChain.ONCHAIN && dataLocation === DataLocationOnChain.ONCHAIN && !validateObject(data, schemaData as SchemaItem[]) ) { - throw new Error('data is not valid'); + throw new Error("data is not valid") } attestationData = { schemaId, - linkedAttestationId: linkedAttestationId || '', + linkedAttestationId: linkedAttestationId || "", attester: attester || account.address, validUntil: BigInt(validUntil || 0), revoked: revoked || false, @@ -350,11 +353,11 @@ export class OnChainClient implements SignProtocolClientBase { revokeTimestamp: 0, recipients: recipients?.map((item: string) => { - const isRecipientAddress = isAddress(item); + const isRecipientAddress = isAddress(item) return encodeAbiParameters( [ { - name: 'data', + name: "data", type: isRecipientAddress && recipientEncodingType === RecipientEncodingType.Address @@ -363,83 +366,83 @@ export class OnChainClient implements SignProtocolClientBase { }, ], [item] - ); + ) }) || [], data: encodeOnChainData( data, dataLocation as DataLocationOnChain, schemaData as SchemaItem[] ), - }; + } } const params: any = [ attestationData, - indexingValue || '', - delegationSignature || '', - extraData || '', - ]; + indexingValue || "", + delegationSignature || "", + extraData || "", + ] const attestAbis: any = abiJson.abi.filter( - (item: any) => item.name === 'attest' - ); - let attestAbi = [attestAbis[0]]; + (item: any) => item.name === "attest" + ) + let attestAbi = [attestAbis[0]] if (resolverFeesETH) { - params.splice(1, 0, resolverFeesETH); - attestAbi = [attestAbis[2]]; + params.splice(1, 0, resolverFeesETH) + attestAbi = [attestAbis[2]] } const txHash = await this.invokeContractWrite( - 'attest', + "attest", params, resolverFeesETH as bigint, [...attestAbi, ...abiJson.abi] - ); - getTxHash && getTxHash(txHash); + ) + getTxHash && getTxHash(txHash) const res = await this.publicClient.waitForTransactionReceipt({ hash: txHash, - }); + }) const decodedLog: any = decodeEventLog({ abi: abiJson.abi, topics: res.logs[0].topics, data: res.logs[0].data, - }); - const attestationId = numberToHex(decodedLog.args.attestationId); + }) + const attestationId = numberToHex(decodedLog.args.attestationId) return { attestationId, txHash, indexingValue: decodedLog.args.indexingKey, - }; + } } async getAttestation(attestationId: string): Promise { - const res: any = await this.invokeContractRead('getAttestation', [ + const res: any = await this.invokeContractRead("getAttestation", [ attestationId, - ]); - if (res.data === '0x') { - throw new Error('attestation not found'); + ]) + if (res.data === "0x") { + throw new Error("attestation not found") } - const schemaId = numberToHex(res.schemaId); - const schema = await this.getSchema(schemaId); - const schemaData = schema.data; + const schemaId = numberToHex(res.schemaId) + const schema = await this.getSchema(schemaId) + const schemaData = schema.data const data = decodeOnChainData( res.data, res.dataLocation, schemaData as SchemaItem[] - ); + ) const recipients = res.recipients.map((item: any) => { - let res; + let res try { res = decodeAbiParameters( - [{ name: 'data', type: RecipientEncodingType.String }], + [{ name: "data", type: RecipientEncodingType.String }], item - )[0]; + )[0] } catch (error) { res = decodeAbiParameters( - [{ name: 'data', type: RecipientEncodingType.Address }], + [{ name: "data", type: RecipientEncodingType.Address }], item - )[0]; + )[0] } - return res; - }); + return res + }) const result: Attestation = { attestTimestamp: Number(res.attestTimestamp), revokeTimestamp: Number(res.revokeTimestamp), @@ -450,10 +453,10 @@ export class OnChainClient implements SignProtocolClientBase { dataLocation: res.dataLocation, validUntil: Number(res.validUntil), linkedAttestationId: - '0x' + Number(res.linkedAttestationId).toString(16) || '', + "0x" + Number(res.linkedAttestationId).toString(16) || "", indexingValue: res.indexingKey, attester: res.attester, - }; - return result; + } + return result } } diff --git a/src/types/index.ts b/src/types/index.ts index df627a2..ad5f3ef 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,13 +1,13 @@ -import { PrivateKeyAccount } from 'viem/accounts'; -import { EvmChains } from '../clients/evm/types'; -import { OffChainRpc } from './offChain'; -import { WalletClient } from 'viem'; -import { AbiType } from 'abitype'; +import { PrivateKeyAccount } from "viem/accounts" +import { EvmChains } from "../clients/evm/types" +import { OffChainRpc } from "./offChain" +import { WalletClient } from "viem" +import { AbiType } from "abitype" export type ContractInfo = { - address: Address; - chain: any; -}; + address: Address + chain: any +} export enum DataLocationOnChain { ONCHAIN, // only when Mode=OnChain @@ -16,90 +16,92 @@ export enum DataLocationOnChain { } export enum DataLocationOffChain { - ARWEAVE = 'arweave', - IPFS = 'ipfs', - GREENFIELD = 'greenfield', - GREENFIELD_TESTTNET = 'greenfield-testnet', + ARWEAVE = "arweave", + IPFS = "ipfs", + GREENFIELD = "greenfield", + GREENFIELD_TESTTNET = "greenfield-testnet", } -export type DataLocation = DataLocationOnChain | DataLocationOffChain; +export type DataLocation = DataLocationOnChain | DataLocationOffChain export enum SignType { - 'eip712' = 'eip712', + "eip712" = "eip712", } export enum OffChainSignType { - EvmEip712 = 'evm-eip712', + EvmEip712 = "evm-eip712", } export type SchemaItem = { - name: string; - type: AbiType; -}; -export type Address = `0x${string}`; + name: string + type: AbiType +} +export type Address = `0x${string}` export type SchemaResult = { - schemaId: string; - txHash?: string; -}; + schemaId: string + txHash?: string +} export type AttestationResult = { - attestationId: string; - indexingValue: string; - txHash?: string; -}; + attestationId: string + indexingValue: string + txHash?: string +} export enum ChainType { - evm = 'evm', + evm = "evm", } export enum SpMode { - OnChain = 'OnChain', - OffChain = 'OffChain', + OnChain = "OnChain", + OffChain = "OffChain", } export type OnChainClientOptions = { - chain: EvmChains; - account?: PrivateKeyAccount; - rpcUrl?: string; - walletClient?: WalletClient; -}; + chain: EvmChains + account?: PrivateKeyAccount + wallet?: any + rpcUrl?: string + walletClient?: WalletClient +} export type OffChainClientOptions = { - signType: OffChainSignType; - account?: PrivateKeyAccount; - rpcUrl?: OffChainRpc | string; - walletClient?: WalletClient; -}; + signType: OffChainSignType + account?: PrivateKeyAccount + rpcUrl?: OffChainRpc | string + walletClient?: WalletClient + wallet?: any +} type CommonSchema = { - name: string; - description?: string; - revocable?: boolean; //Whether Attestations that adopt this Schema can be revoked. - maxValidFor?: number; //The maximum number of seconds that an Attestation can remain valid. 0 means Attestations can be valid forever. This is enforced through `Attestation.validUntil`. -}; + name: string + description?: string + revocable?: boolean //Whether Attestations that adopt this Schema can be revoked. + maxValidFor?: number //The maximum number of seconds that an Attestation can remain valid. 0 means Attestations can be valid forever. This is enforced through `Attestation.validUntil`. +} export type OnChainSchema = | (CommonSchema & { /** * @deprecated please use `hook` instead */ - resolver?: Address; - hook?: Address; - registrant: Address; - timestamp?: number; - dataLocation?: DataLocationOnChain.ONCHAIN; //Where `Schema.data` is stored. See `DataLocation.DataLocation`. - data: SchemaItem[]; // when dataLocation=ONCHAIN, data is SchemaItem[], when dataLocation=ARWEAVE or IPFS, data is id of the data, + resolver?: Address + hook?: Address + registrant: Address + timestamp?: number + dataLocation?: DataLocationOnChain.ONCHAIN //Where `Schema.data` is stored. See `DataLocation.DataLocation`. + data: SchemaItem[] // when dataLocation=ONCHAIN, data is SchemaItem[], when dataLocation=ARWEAVE or IPFS, data is id of the data, }) | (CommonSchema & { - resolver?: Address; - hook?: Address; - registrant: Address; - dataLocation: DataLocationOnChain.ARWEAVE | DataLocationOnChain.IPFS; //Where `Schema.data` is stored. See `DataLocation.DataLocation`. - data: string; // when dataLocation=ONCHAIN, data is SchemaItem[], when dataLocation=ARWEAVE or IPFS, data is id of the data, - }); + resolver?: Address + hook?: Address + registrant: Address + dataLocation: DataLocationOnChain.ARWEAVE | DataLocationOnChain.IPFS //Where `Schema.data` is stored. See `DataLocation.DataLocation`. + data: string // when dataLocation=ONCHAIN, data is SchemaItem[], when dataLocation=ARWEAVE or IPFS, data is id of the data, + }) export type OffChainSchema = CommonSchema & { dataLocation?: | DataLocationOffChain.ARWEAVE | DataLocationOffChain.IPFS - | DataLocationOffChain.GREENFIELD; - data: SchemaItem[]; -}; + | DataLocationOffChain.GREENFIELD + data: SchemaItem[] +} /** * Schema is a template for Attestations. It defines the structure of the data that can be included in an Attestation, and the rules that apply to it. @@ -113,37 +115,37 @@ export type OffChainSchema = CommonSchema & { * @property {Address} [resolver] - The `ISPResolver` that is called at the end of every function. 0 means there is no resolver set. See `ISPResolver`. * @property {SchemaItem[] | string} data - // when dataLocation=ONCHAIN, data is SchemaItem[], when dataLocation=ARWEAVE or IPFS, data is id of the data, */ -export type Schema = OnChainSchema | OffChainSchema; +export type Schema = OnChainSchema | OffChainSchema type CommonAttestation = { - schemaId: string; - linkedAttestationId?: string | null; - validUntil?: number; - revoked?: boolean | null; - recipients?: string[]; - indexingValue: string; - attester?: Address; -}; + schemaId: string + linkedAttestationId?: string | null + validUntil?: number + revoked?: boolean | null + recipients?: string[] + indexingValue: string + attester?: Address +} export type OnChainAttestation = | (CommonAttestation & { - attestTimestamp?: number; - revokeTimestamp?: number; - dataLocation?: DataLocationOnChain.ONCHAIN; //Where `Attestation.data` is stored. See `DataLocation.DataLocation`. - data: { [key: string]: any }; + attestTimestamp?: number + revokeTimestamp?: number + dataLocation?: DataLocationOnChain.ONCHAIN //Where `Attestation.data` is stored. See `DataLocation.DataLocation`. + data: { [key: string]: any } }) | (CommonAttestation & { - attestTimestamp?: number; - revokeTimestamp?: number; - dataLocation: DataLocationOnChain.ARWEAVE | DataLocationOnChain.IPFS; //Where `Attestation.data` is stored. See `DataLocation.DataLocation`. - data: string; - }); + attestTimestamp?: number + revokeTimestamp?: number + dataLocation: DataLocationOnChain.ARWEAVE | DataLocationOnChain.IPFS //Where `Attestation.data` is stored. See `DataLocation.DataLocation`. + data: string + }) type OffChainAttestation = CommonAttestation & { dataLocation?: | DataLocationOffChain.ARWEAVE | DataLocationOffChain.IPFS - | DataLocationOffChain.GREENFIELD; - data: { [key: string]: any }; -}; + | DataLocationOffChain.GREENFIELD + data: { [key: string]: any } +} /** * This struct represents an on-chain attestation record. This record is not deleted after revocation. * @typedef Attestation @@ -155,42 +157,42 @@ type OffChainAttestation = CommonAttestation & { * @property {string[]} [recipients] - The intended recipients of this Attestation. * @property {string} indexingValue - The value that is used to index this Attestation. */ -export type Attestation = OnChainAttestation | OffChainAttestation; +export type Attestation = OnChainAttestation | OffChainAttestation export type AttestationDelegationSignature = { - attestation: Attestation; - delegationSignature: `0x${string}`; -}; + attestation: Attestation + delegationSignature: `0x${string}` +} export type SchemaDelegationSignature = { - schema: OnChainSchema; - delegationSignature: `0x${string}`; -}; + schema: OnChainSchema + delegationSignature: `0x${string}` +} export type RevokeDelegationSignature = { - attestationId: string; - delegationSignature: `0x${string}`; - reason?: string; -}; + attestationId: string + delegationSignature: `0x${string}` + reason?: string +} export type RevokeAttestationResult = { - attestationId: string; - txHash?: string; - reason?: string; -}; + attestationId: string + txHash?: string + reason?: string +} export type AttestationRevokeInfo = { - attestationId: string; - revokeReason: string; -}; + attestationId: string + revokeReason: string +} export enum RecipientEncodingType { - Address = 'address', - String = 'string', + Address = "address", + String = "string", } export type CreateAttestationOnChainOptions = { - resolverFeesETH?: BigInt; //unit wei - delegationSignature?: string; - getTxHash?: (txHash: `0x${string}`) => void; - recipientEncodingType?: RecipientEncodingType; - extraData?: `0x${string}`; -}; + resolverFeesETH?: BigInt //unit wei + delegationSignature?: string + getTxHash?: (txHash: `0x${string}`) => void + recipientEncodingType?: RecipientEncodingType + extraData?: `0x${string}` +}