Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: polished EAS Types and docs #210

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified site/.yarn/install-state.gz
Binary file not shown.
71 changes: 31 additions & 40 deletions site/docs/pages/identity/get-eas-attestations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,50 @@ based on schema IDs, revocation status, expiration time, and the number of attes
import { getEASAttestations } from '@coinbase/onchainkit/identity';
import { base } from 'viem/chains';

const attestations = await getEASAttestations({
'0x1234567890abcdef1234567890abcdef12345678',
const address = '0x1234567890abcdef1234567890abcdef12345678';
const attestationsOptions = {
schemas: [
'0x1801901fabd0e6189356b4fb52bb0ab855276d84f7ec140839fbd1f6801ca065'
],
};

const attestations = await getEASAttestations(
address,
base,
{
// Optional schemas to filter the attestations.
schemas: ['0x1801901fabd0e6189356b4fb52bb0ab855276d84f7ec140839fbd1f6801ca065'],
},
});
attestationsOptions,
);
```

## Returns

```ts
// Array of EAS Attestation objects
type GetEASAttestationsResponse = EASAttestation[];
[`Promise<EASAttestation[]>`](/identity/types#easattestation)

type EASAttestation = {
attester: EASAttesterAddress; // the attester who created the attestation.
decodedDataJson: string; // The attestation data decoded to JSON.
expirationTime: number; // The Unix timestamp when the attestation expires (0 for no expiration).
id: string; // The unique identifier of the attestation.
recipient: Address; // The Ethereum address of the recipient of the attestation.
revocationTime: number; // The Unix timestamp when the attestation was revoked, if applicable.
revoked: boolean; // A boolean indicating whether the attestation is revocable or not.
schemaId: EASSchemaUid; // The schema identifier associated with the attestation.
time: number; // The Unix timestamp when the attestation was created.
};

type EASAttesterAddress = Address;
## Parameters

type EASSchemaUid = Address;
### Address

```ts
type Address = `0x${string}`;
```

## Parameters
### Chain

```ts
// Address - Ethereum address for which attestations are being queried
address: Address;

// Chain - The blockchain of interest
chain: Chain;

// Optional filtering options for the attestations query
type GetEASAttestationsOptions = {
schemas?: EASSchemaUid[]; // Schema IDs to filter attestations
revoked?: boolean; // Filter for revoked attestations (default: false)
expirationTime?: number; // Unix timestamp to filter based on expiration time (default: current time)
limit?: number; // Maximum number of attestations to return (default: 10)
type Chain = {
id: string;
name: string;
network: string;
chainId: number;
nativeCurrency: {
name: string;
symbol: string;
decimals: number;
};
rpcUrls: string[];
blockExplorerUrls: string[];
};
```

type EASSchemaUid = Address;
### GetEASAttestationsOptions

type Address = `0x${string}`;
```
[`GetEASAttestationsOptions`](/identity/types#geteasttestationsoptions)
33 changes: 33 additions & 0 deletions site/docs/pages/identity/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,36 @@ deescription: Glossary of Types in Identity Kit.
---

# Types [Glossary of Types in Identity Kit.]

## `EASSchemaUid`

```ts
type EASSchemaUid = `0x${string}`;
```

## `EASAttestation`

```ts
type EASAttestation = {
attester: Address; // the attester who created the attestation.
decodedDataJson: string; // The attestation data decoded to JSON.
expirationTime: number; // The Unix timestamp when the attestation expires (0 for no expiration).
id: string; // The unique identifier of the attestation.
recipient: Address; // The Ethereum address of the recipient of the attestation.
revocationTime: number; // The Unix timestamp when the attestation was revoked, if applicable.
revoked: boolean; // A boolean indicating whether the attestation is revocable or not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit revocable or not -> revoked or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet, done!

schemaId: EASSchemaUid; // The schema identifier associated with the attestation.
time: number; // The Unix timestamp when the attestation was created.
};
```

## `GetEASAttestationsOptions`

```ts
type GetEASAttestationsOptions = {
schemas?: EASSchemaUid[];
revoked?: boolean;
expirationTime?: number;
limit?: number;
};
```
8 changes: 4 additions & 4 deletions site/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const sidebar = [
items: [{ text: 'Getting Started', link: '/getting-started' }],
},
{
text: 'Farcaster Kit',
text: 'Farcaster',
items: [
{
text: 'Introduction',
Expand All @@ -28,7 +28,7 @@ export const sidebar = [
],
},
{
text: 'Frame Kit',
text: 'Frame',
items: [
{ text: 'Introduction', link: '/frame/introduction' },
{
Expand Down Expand Up @@ -68,7 +68,7 @@ export const sidebar = [
],
},
{
text: 'Identity Kit',
text: 'Identity',
items: [
{ text: 'Introduction', link: '/identity/introduction' },
{
Expand Down Expand Up @@ -100,7 +100,7 @@ export const sidebar = [
],
},
{
text: 'XMTP Kit',
text: 'XMTP',
items: [
{ text: 'Introduction', link: '/xmtp/introduction' },
{
Expand Down
3 changes: 2 additions & 1 deletion src/identity/getEASAttestations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*/

import { getEASAttestationsByFilter } from '../queries/easAttestations';
import { getEASAttestations, GetEASAttestationsOptions } from './getEASAttestations';
import { getEASAttestations } from './getEASAttestations';
import { easSupportedChains } from '../utils/easAttestation';
import { base, opBNBTestnet } from 'viem/chains';
import { GetEASAttestationsOptions } from './types';

jest.mock('../queries/easAttestations');

Expand Down
14 changes: 3 additions & 11 deletions src/identity/getEASAttestations.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { getEASAttestationsByFilter } from '../queries/easAttestations';
import { isChainSupported, easSupportedChains } from '../utils/easAttestation';
import { EASAttestation, EASSchemaUid } from './types';
import { EASAttestation, GetEASAttestationsOptions } from './types';
import type { Address, Chain } from 'viem';

export type GetEASAttestationsOptions = {
schemas?: EASSchemaUid[];
revoked?: boolean;
expirationTime?: number;
limit?: number;
};

type GetEASAttestationsResponse = EASAttestation[];
/**
* Fetches Ethereum Attestation Service (EAS) attestations for a given address and chain,
* optionally filtered by schemas associated with the attestation.
Expand All @@ -21,7 +13,7 @@ type GetEASAttestationsResponse = EASAttestation[];
* options.revoked - Filter for revoked attestations (default: false).
* options.expirationTime - Unix timestamp to filter attestations based on expiration time (default: current time).
* options.limit - The maximum number of attestations to return (default: 10).
* @returns {Promise<GetEASAttestationsResponse[]>} A promise that resolves to an array of EAS Attestations.
* @returns {Promise<EASAttestation[]>} A promise that resolves to an array of EAS Attestations.
* @throws Will throw an error if the request to the GraphQL API fails.
*
* @example
Expand All @@ -46,7 +38,7 @@ export async function getEASAttestations<TChain extends Chain>(
address: Address,
chain: TChain,
options?: GetEASAttestationsOptions,
): Promise<GetEASAttestationsResponse> {
): Promise<EASAttestation[]> {
try {
if (!isChainSupported(chain)) {
throw new Error(
Expand Down
7 changes: 6 additions & 1 deletion src/identity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ export { Name } from './components/Name';
export { useAvatar } from './hooks/useAvatar';
export { useName } from './hooks/useName';
export { getEASAttestations } from './getEASAttestations';
export type { EASSchemaUid, EASAttestation, EASChainDefinition } from './types';
export type {
EASSchemaUid,
EASAttestation,
EASChainDefinition,
GetEASAttestationsOptions,
} from './types';
22 changes: 14 additions & 8 deletions src/identity/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { Address } from 'viem';

/**
* Ethereum Attestation Service (EAS) Attester Address
* The Ethereum address of the attester who created the attestation.
*/
type EASAttesterAddress = Address;

/**
* Ethereum Attestation Service (EAS) Schema Uid
* The schema identifier associated with the EAS attestation.
*
* Note: exported as public Type
*/
export type EASSchemaUid = Address;
export type EASSchemaUid = `0x${string}`;

/**
* Ethereum Attestation Service (EAS) Attestation
Expand All @@ -21,7 +15,7 @@ export type EASSchemaUid = Address;
* Note: exported as public Type
*/
export type EASAttestation = {
attester: EASAttesterAddress; // the attester who created the attestation.
attester: Address; // the attester who created the attestation.
decodedDataJson: string; // The attestation data decoded to JSON.
expirationTime: number; // The Unix timestamp when the attestation expires (0 for no expiration).
id: string; // The unique identifier of the attestation.
Expand All @@ -43,3 +37,15 @@ export type EASChainDefinition = {
id: number; // blockchain source id
schemaUids: EASSchemaUid[]; // Array of EAS Schema UIDs
};

/**
* Attestation Options
*
* Note: exported as public Type
*/
export type GetEASAttestationsOptions = {
schemas?: EASSchemaUid[];
revoked?: boolean;
expirationTime?: number;
limit?: number;
};
Loading