Skip to content

Commit 2a6df89

Browse files
committed
feat(eas): restore all work on EAS portal implementation
1 parent 72c70c6 commit 2a6df89

17 files changed

+4835
-267
lines changed

sdk/eas/README.md

Lines changed: 272 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,223 @@ Will throw an error if the options fail validation
9090
import { createEASClient } from '@settlemint/sdk-eas';
9191

9292
const client = createEASClient({
93-
schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
94-
attestationAddress: "0x1234567890123456789012345678901234567890",
93+
instance: "https://attestation-portal-ee231.gke-europe.settlemint.com/graphql",
94+
accessToken: "your-portal-access-token",
95+
debug: true,
96+
});
97+
98+
// Deploy contracts
99+
const deployment = await client.deploy("0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6");
100+
101+
// Register schema
102+
const schema = await client.registerSchema({
103+
fields: [
104+
{ name: "user", type: "address" },
105+
{ name: "score", type: "uint256" },
106+
],
107+
resolver: ZERO_ADDRESS, // No resolver
108+
revocable: true,
109+
}, "0x8ba1f109551bD432803012645Hac136c22C177ec");
110+
111+
// Create attestation
112+
const attestation = await client.attest({
113+
schema: schema.hash,
114+
data: {
115+
recipient: "0x9876543210987654321098765432109876543210",
116+
expirationTime: BigInt(0), // No expiration
117+
revocable: true,
118+
refUID: ZERO_BYTES32, // No reference
119+
data: "0x1234",
120+
value: BigInt(0),
121+
},
122+
}, "0x8ba1f109551bD432803012645Hac136c22C177ec");
123+
```
124+
125+
## Configuration Constants
126+
127+
The SDK provides configurable constants instead of hardcoded values:
128+
129+
### Address Constants
130+
131+
```typescript
132+
import { ZERO_ADDRESS, ZERO_BYTES32 } from "@settlemint/sdk-eas";
133+
134+
// Use ZERO_ADDRESS for:
135+
ZERO_ADDRESS // "0x0000000000000000000000000000000000000000"
136+
137+
// Use ZERO_BYTES32 for:
138+
ZERO_BYTES32 // "0x0000000000000000000000000000000000000000000000000000000000000000"
139+
```
140+
141+
### Configurable Parameters
142+
143+
#### 1. Forwarder Address (Contract Deployment)
144+
145+
```typescript
146+
// Option 1: No meta-transaction forwarder (default)
147+
await client.deploy(deployerAddress); // Uses ZERO_ADDRESS
148+
149+
// Option 2: Custom forwarder for meta-transactions
150+
await client.deploy(deployerAddress, "0x1234567890123456789012345678901234567890");
151+
```
152+
153+
#### 2. Resolver Address (Schema Registration)
154+
155+
```typescript
156+
// Option 1: No resolver (most common)
157+
await client.registerSchema({
158+
fields: [...],
159+
resolver: ZERO_ADDRESS, // No custom validation
160+
revocable: true,
161+
}, fromAddress);
162+
163+
// Option 2: Custom resolver contract
164+
await client.registerSchema({
165+
fields: [...],
166+
resolver: "0x5678901234567890123456789012345678901234", // Custom validation
167+
revocable: true,
168+
}, fromAddress);
169+
```
170+
171+
#### 3. Reference UID (Attestation Creation)
172+
173+
```typescript
174+
// Option 1: Standalone attestation (most common)
175+
await client.attest({
176+
schema: schemaUID,
177+
data: {
178+
recipient: recipientAddress,
179+
refUID: ZERO_BYTES32, // No reference to other attestations
180+
// ... other fields
181+
},
182+
}, fromAddress);
183+
184+
// Option 2: Reference another attestation
185+
await client.attest({
186+
schema: schemaUID,
187+
data: {
188+
recipient: recipientAddress,
189+
refUID: "0x1234567890123456789012345678901234567890123456789012345678901234", // Links to parent
190+
// ... other fields
191+
},
192+
}, fromAddress);
193+
```
194+
195+
#### 4. Expiration Time
196+
197+
```typescript
198+
// Option 1: No expiration (permanent)
199+
expirationTime: BigInt(0)
200+
201+
// Option 2: Expires in 24 hours
202+
expirationTime: BigInt(Math.floor(Date.now() / 1000) + 86400)
203+
204+
// Option 3: Specific timestamp
205+
expirationTime: BigInt(1735689600) // January 1, 2025
206+
```
207+
208+
#### 5. Value (ETH Amount)
209+
210+
```typescript
211+
// Option 1: No ETH sent (most common)
212+
value: BigInt(0)
213+
214+
// Option 2: Send ETH with attestation
215+
value: BigInt("1000000000000000000") // 1 ETH in wei
216+
```
217+
218+
## API Reference
219+
220+
### Functions
221+
222+
#### createEASClient()
223+
224+
> **createEASClient**(`options`): [`EASPortalClient`](#easportalclient)
225+
226+
Creates a Portal-based EAS client for interacting with the Ethereum Attestation Service.
227+
Defined in: [sdk/eas/src/eas.ts:36](https://github.com/settlemint/sdk/blob/v2.3.8/sdk/eas/src/eas.ts#L36)
228+
229+
Creates an EAS client for interacting with the Ethereum Attestation Service.
230+
231+
##### Parameters
232+
233+
| Parameter | Type | Description |
234+
| ------ | ------ | ------ |
235+
| `options` | [`PortalClientOptions`](#portalclientoptions) | Configuration options for the Portal-based client |
236+
237+
##### Returns
238+
239+
[`EASPortalClient`](#easportalclient)
240+
241+
An EAS Portal client instance
242+
`object`
243+
244+
An object containing the EAS client instance
245+
246+
| Name | Type | Defined in |
247+
| ------ | ------ | ------ |
248+
| `getSchema()` | (`uid`) => `Promise`\<`string`\> | [sdk/eas/src/eas.ts:96](https://github.com/settlemint/sdk/blob/v2.3.8/sdk/eas/src/eas.ts#L96) |
249+
| `registerSchema()` | (`options`) => `Promise`\<`string`\> | [sdk/eas/src/eas.ts:95](https://github.com/settlemint/sdk/blob/v2.3.8/sdk/eas/src/eas.ts#L95) |
250+
251+
##### Throws
252+
253+
Will throw an error if the options fail validation
254+
255+
##### Example
256+
257+
```ts
258+
import { createEASClient } from '@settlemint/sdk-eas';
259+
260+
const client = createEASClient({
261+
instance: "https://portal.settlemint.com",
95262
accessToken: "your-access-token",
96-
chainId: "1",
97-
chainName: "Ethereum",
98-
rpcUrl: "http://localhost:8545"
263+
easContractAddress: "0x...",
264+
schemaRegistryContractAddress: "0x...",
99265
});
100266
```
101267

268+
### Classes
269+
270+
#### EASPortalClient
271+
272+
The main client class for interacting with EAS contracts via Portal.
273+
274+
##### Methods
275+
276+
- `registerSchema(request: SchemaRequest): Promise<TransactionResult>` - Register a new schema
277+
- `attest(request: AttestationRequest): Promise<TransactionResult>` - Create an attestation
278+
- `multiAttest(requests: AttestationRequest[]): Promise<TransactionResult>` - Create multiple attestations
279+
- `revoke(uid: Hex, value?: bigint): Promise<TransactionResult>` - Revoke an attestation
280+
- `getAttestation(uid: Hex): Promise<AttestationData>` - Retrieve attestation data
281+
- `getSchema(uid: Hex): Promise<SchemaData>` - Retrieve schema data
282+
- `isValidAttestation(uid: Hex): Promise<boolean>` - Check if attestation is valid
283+
- `getTimestamp(): Promise<bigint>` - Get current contract timestamp
284+
- `getPortalClient(): unknown` - Access underlying Portal client
285+
- `getOptions(): PortalClientOptions` - Get client configuration
286+
- `getAbis(): { easAbi: Abi; schemaRegistryAbi: Abi }` - Get current ABIs
287+
102288
### Interfaces
103289

104-
#### RegisterSchemaOptions
290+
#### PortalClientOptions
105291

292+
Configuration options for the EAS Portal client.
106293
Defined in: [sdk/eas/src/types.ts:34](https://github.com/settlemint/sdk/blob/v2.3.8/sdk/eas/src/types.ts#L34)
107294

108295
Options for registering a new schema in the EAS Schema Registry.
109296

110297
##### Properties
111298

299+
| Property | Type | Description |
300+
| ------ | ------ | ------ |
301+
| `instance` | `string` | Portal instance URL or path |
302+
| `accessToken` | `string` | Access token for Portal authentication |
303+
| `easContractAddress` | `string` | The address of the EAS Attestation contract |
304+
| `schemaRegistryContractAddress` | `string` | The address of the EAS Schema Registry contract |
305+
| `abiSource?` | [`AbiSource`](#abisource) | ABI source configuration (defaults to hardcoded) |
306+
| `wsUrl?` | `string` | Optional WebSocket URL for real-time monitoring |
307+
| `timeout?` | `number` | Request timeout in milliseconds (default: 30000) |
308+
| `debug?` | `boolean` | Enable debug logging (default: false) |
309+
| `cache?` | `string` | Cache configuration for GraphQL requests |
112310
| Property | Type | Description | Defined in |
113311
| ------ | ------ | ------ | ------ |
114312
| <a id="fields"></a> `fields` | [`SchemaField`](#schemafield)[] | Array of fields that make up the schema | [sdk/eas/src/types.ts:36](https://github.com/settlemint/sdk/blob/v2.3.8/sdk/eas/src/types.ts#L36) |
@@ -125,6 +323,11 @@ Represents a single field in an EAS schema.
125323

126324
##### Properties
127325

326+
| Property | Type | Description |
327+
| ------ | ------ | ------ |
328+
| `name` | `string` | The name of the field |
329+
| `type` | `EASFieldType` | The Solidity type of the field |
330+
| `description?` | `string` | Optional description of the field's purpose |
128331
| Property | Type | Description | Defined in |
129332
| ------ | ------ | ------ | ------ |
130333
| <a id="description"></a> `description?` | `string` | Optional description of the field's purpose | [sdk/eas/src/types.ts:28](https://github.com/settlemint/sdk/blob/v2.3.8/sdk/eas/src/types.ts#L28) |
@@ -133,6 +336,16 @@ Represents a single field in an EAS schema.
133336

134337
### Type Aliases
135338

339+
#### AbiSource
340+
341+
Configuration for ABI sources with priority system.
342+
343+
```typescript
344+
type AbiSource =
345+
| { type: "hardcoded" }
346+
| { type: "custom"; easAbi: Abi; schemaRegistryAbi: Abi }
347+
| { type: "predeployed"; abiNames?: string[] };
348+
```
136349
#### ClientOptions
137350

138351
> **ClientOptions** = `z.infer`\<*typeof* [`ClientOptionsSchema`](#clientoptionsschema)\>
@@ -157,13 +370,66 @@ Extends the base Viem client options with EAS-specific requirements.
157370

158371
#### EAS\_FIELD\_TYPES
159372

373+
Supported field types for EAS schema fields. Maps to the Solidity types that can be used in EAS schemas.
160374
> `const` **EAS\_FIELD\_TYPES**: `object`
161375
162376
Defined in: [sdk/eas/src/types.ts:5](https://github.com/settlemint/sdk/blob/v2.3.8/sdk/eas/src/types.ts#L5)
163377

164378
Supported field types for EAS schema fields.
165379
Maps to the Solidity types that can be used in EAS schemas.
166380

381+
```typescript
382+
interface SchemaRequest {
383+
fields?: SchemaField[]; // Alternative to schema string
384+
schema?: string; // Alternative to fields
385+
resolver: Address; // Use ZERO_ADDRESS for no resolver
386+
revocable: boolean; // Whether attestations can be revoked
387+
}
388+
389+
async registerSchema(
390+
request: SchemaRequest,
391+
fromAddress: Address,
392+
gasLimit?: string
393+
): Promise<TransactionResult>
394+
```
395+
396+
### Attestation Creation
397+
398+
```typescript
399+
import { EASErrorCode, EASPortalError } from "@settlemint/sdk-eas";
400+
401+
try {
402+
await client.getAttestation("invalid-uid");
403+
} catch (error) {
404+
if (error instanceof EASPortalError) {
405+
switch (error.code) {
406+
case EASErrorCode.ATTESTATION_NOT_FOUND:
407+
console.log("Attestation not found");
408+
break;
409+
case EASErrorCode.TRANSACTION_FAILED:
410+
console.log("Transaction failed");
411+
break;
412+
case EASErrorCode.SCHEMA_NOT_FOUND:
413+
console.log("Schema not found");
414+
break;
415+
// ... other error codes
416+
}
417+
}
418+
}
419+
```
420+
421+
### Available Error Codes
422+
423+
- `INVALID_SCHEMA` - Schema validation failed
424+
- `SCHEMA_NOT_FOUND` - Schema not found
425+
- `ATTESTATION_NOT_FOUND` - Attestation not found
426+
- `UNAUTHORIZED` - Unauthorized access
427+
- `TRANSACTION_FAILED` - Transaction execution failed
428+
- `INVALID_SIGNATURE` - Invalid signature
429+
- `EXPIRED_ATTESTATION` - Attestation has expired
430+
- `NON_REVOCABLE` - Attestation cannot be revoked
431+
- `ALREADY_REVOKED` - Attestation already revoked
432+
- `PORTAL_ERROR` - Portal-specific error
167433
##### Type declaration
168434

169435
| Name | Type | Default value | Defined in |

0 commit comments

Comments
 (0)