Skip to content

Commit

Permalink
feat: polished EAS Types and docs (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia authored Mar 5, 2024
1 parent 57bdb68 commit 3476d8a
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 68 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-weeks-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@coinbase/onchainkit': patch
---

- **feat**: exported `GetEASAttestationsOptions` type, and polished EAS docs. By @zizzamia #210
Binary file modified site/.yarn/install-state.gz
Binary file not shown.
67 changes: 26 additions & 41 deletions site/docs/pages/identity/get-eas-attestations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,44 @@ 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',
base,
{
// Optional schemas to filter the attestations.
schemas: ['0x1801901fabd0e6189356b4fb52bb0ab855276d84f7ec140839fbd1f6801ca065'],
},
});
const address = '0x1234567890abcdef1234567890abcdef12345678';
const attestationsOptions = {
schemas: ['0x1801901fabd0e6189356b4fb52bb0ab855276d84f7ec140839fbd1f6801ca065'],
};

const attestations = await getEASAttestations(address, base, 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.
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';
24 changes: 15 additions & 9 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,13 +15,13 @@ 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.
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.
revoked: boolean; // A boolean indicating whether the attestation is revoked or not.
schemaId: EASSchemaUid; // The schema identifier associated with the attestation.
time: number; // The Unix timestamp when the attestation was created.
};
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;
};
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '0.9.7';
export const version = '0.9.8';

0 comments on commit 3476d8a

Please sign in to comment.