@settlemint/sdk-eas 2.2.2-prf0823a06 → 2.2.3-main0f4b90ca
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -295
- package/dist/eas.cjs +1 -1
- package/dist/eas.cjs.map +1 -1
- package/dist/eas.d.cts +70 -164
- package/dist/eas.d.ts +70 -164
- package/dist/eas.mjs +1 -1
- package/dist/eas.mjs.map +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -29,18 +29,14 @@
|
|
|
29
29
|
- [About](#about)
|
|
30
30
|
- [API Reference](#api-reference)
|
|
31
31
|
- [Functions](#functions)
|
|
32
|
-
- [
|
|
33
|
-
- [registerSchema()](#registerschema)
|
|
34
|
-
- [validateEthereumAddress()](#validateethereumaddress)
|
|
35
|
-
- [validateFieldName()](#validatefieldname)
|
|
36
|
-
- [validateFieldType()](#validatefieldtype)
|
|
37
|
-
- [validateSchemaFields()](#validateschemafields)
|
|
32
|
+
- [createEASClient()](#createeasclient)
|
|
38
33
|
- [Interfaces](#interfaces)
|
|
39
34
|
- [RegisterSchemaOptions](#registerschemaoptions)
|
|
40
35
|
- [SchemaField](#schemafield)
|
|
41
36
|
- [Type Aliases](#type-aliases)
|
|
42
|
-
- [
|
|
37
|
+
- [ClientOptions](#clientoptions)
|
|
43
38
|
- [Variables](#variables)
|
|
39
|
+
- [ClientOptionsSchema](#clientoptionsschema)
|
|
44
40
|
- [EAS\_FIELD\_TYPES](#eas_field_types)
|
|
45
41
|
- [Contributing](#contributing)
|
|
46
42
|
- [License](#license)
|
|
@@ -53,351 +49,112 @@ The SettleMint EAS SDK provides a lightweight wrapper for the Ethereum Attestati
|
|
|
53
49
|
|
|
54
50
|
### Functions
|
|
55
51
|
|
|
56
|
-
####
|
|
52
|
+
#### createEASClient()
|
|
57
53
|
|
|
58
|
-
> **
|
|
54
|
+
> **createEASClient**(`options`): `object`
|
|
59
55
|
|
|
60
|
-
Defined in: [
|
|
56
|
+
Defined in: [sdk/eas/src/eas.ts:36](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/eas.ts#L36)
|
|
61
57
|
|
|
62
|
-
|
|
58
|
+
Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
63
59
|
|
|
64
60
|
##### Parameters
|
|
65
61
|
|
|
66
62
|
| Parameter | Type | Description |
|
|
67
63
|
| ------ | ------ | ------ |
|
|
68
|
-
| `
|
|
64
|
+
| `options` | [`ClientOptions`](#clientoptions) | Configuration options for the client |
|
|
69
65
|
|
|
70
66
|
##### Returns
|
|
71
67
|
|
|
72
|
-
`
|
|
68
|
+
`object`
|
|
73
69
|
|
|
74
|
-
|
|
70
|
+
An object containing the EAS client instance
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Error if any field is invalid
|
|
79
|
-
|
|
80
|
-
##### Example
|
|
81
|
-
|
|
82
|
-
```ts
|
|
83
|
-
import { buildSchemaString, SchemaField } from '@settlemint/sdk-eas';
|
|
84
|
-
|
|
85
|
-
const fields: SchemaField[] = [
|
|
86
|
-
{ name: "userAddress", type: "address" },
|
|
87
|
-
{ name: "age", type: "uint8" },
|
|
88
|
-
{ name: "isActive", type: "bool" }
|
|
89
|
-
];
|
|
90
|
-
|
|
91
|
-
const schemaString = buildSchemaString(fields);
|
|
92
|
-
// Result: "address userAddress, uint8 age, bool isActive"
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
***
|
|
96
|
-
|
|
97
|
-
#### registerSchema()
|
|
98
|
-
|
|
99
|
-
> **registerSchema**(`options`): `Promise`\<`string`\>
|
|
100
|
-
|
|
101
|
-
Defined in: [schema.ts:246](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L246)
|
|
102
|
-
|
|
103
|
-
Registers a new schema with EAS.
|
|
104
|
-
|
|
105
|
-
##### Parameters
|
|
106
|
-
|
|
107
|
-
| Parameter | Type | Description |
|
|
72
|
+
| Name | Type | Defined in |
|
|
108
73
|
| ------ | ------ | ------ |
|
|
109
|
-
| `
|
|
110
|
-
|
|
111
|
-
##### Returns
|
|
112
|
-
|
|
113
|
-
`Promise`\<`string`\>
|
|
114
|
-
|
|
115
|
-
A promise that resolves to the schema UID
|
|
74
|
+
| `getSchema()` | (`uid`) => `Promise`\<`string`\> | [sdk/eas/src/eas.ts:96](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/eas.ts#L96) |
|
|
75
|
+
| `registerSchema()` | (`options`) => `Promise`\<`string`\> | [sdk/eas/src/eas.ts:95](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/eas.ts#L95) |
|
|
116
76
|
|
|
117
77
|
##### Throws
|
|
118
78
|
|
|
119
|
-
|
|
79
|
+
Will throw an error if the options fail validation
|
|
120
80
|
|
|
121
81
|
##### Example
|
|
122
82
|
|
|
123
83
|
```ts
|
|
124
|
-
import {
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
134
|
-
revocable: true
|
|
84
|
+
import { createEASClient } from '@settlemint/sdk-eas';
|
|
85
|
+
|
|
86
|
+
const client = createEASClient({
|
|
87
|
+
schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
88
|
+
attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
89
|
+
accessToken: "your-access-token",
|
|
90
|
+
chainId: "1",
|
|
91
|
+
chainName: "Ethereum",
|
|
92
|
+
rpcUrl: "http://localhost:8545"
|
|
135
93
|
});
|
|
136
|
-
|
|
137
|
-
console.log(`Schema registered with UID: ${schemaUID}`);
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
***
|
|
141
|
-
|
|
142
|
-
#### validateEthereumAddress()
|
|
143
|
-
|
|
144
|
-
> **validateEthereumAddress**(`address`): `void`
|
|
145
|
-
|
|
146
|
-
Defined in: [schema.ts:214](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L214)
|
|
147
|
-
|
|
148
|
-
Validates an Ethereum address.
|
|
149
|
-
|
|
150
|
-
##### Parameters
|
|
151
|
-
|
|
152
|
-
| Parameter | Type | Description |
|
|
153
|
-
| ------ | ------ | ------ |
|
|
154
|
-
| `address` | `string` | The address to validate |
|
|
155
|
-
|
|
156
|
-
##### Returns
|
|
157
|
-
|
|
158
|
-
`void`
|
|
159
|
-
|
|
160
|
-
##### Throws
|
|
161
|
-
|
|
162
|
-
Error if the address is invalid
|
|
163
|
-
|
|
164
|
-
##### Example
|
|
165
|
-
|
|
166
|
-
```ts
|
|
167
|
-
import { validateEthereumAddress } from '@settlemint/sdk-eas';
|
|
168
|
-
|
|
169
|
-
// Valid address
|
|
170
|
-
validateEthereumAddress("0x1234567890123456789012345678901234567890"); // OK
|
|
171
|
-
|
|
172
|
-
// Invalid addresses
|
|
173
|
-
validateEthereumAddress("0x123"); // Throws: "Invalid Ethereum address format"
|
|
174
|
-
validateEthereumAddress(""); // Throws: "Resolver address cannot be empty"
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
***
|
|
178
|
-
|
|
179
|
-
#### validateFieldName()
|
|
180
|
-
|
|
181
|
-
> **validateFieldName**(`name`): `void`
|
|
182
|
-
|
|
183
|
-
Defined in: [schema.ts:71](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L71)
|
|
184
|
-
|
|
185
|
-
Validates a schema field name.
|
|
186
|
-
|
|
187
|
-
##### Parameters
|
|
188
|
-
|
|
189
|
-
| Parameter | Type | Description |
|
|
190
|
-
| ------ | ------ | ------ |
|
|
191
|
-
| `name` | `string` | The field name to validate |
|
|
192
|
-
|
|
193
|
-
##### Returns
|
|
194
|
-
|
|
195
|
-
`void`
|
|
196
|
-
|
|
197
|
-
##### Throws
|
|
198
|
-
|
|
199
|
-
Error if the name is invalid
|
|
200
|
-
|
|
201
|
-
##### Example
|
|
202
|
-
|
|
203
|
-
```ts
|
|
204
|
-
import { validateFieldName } from '@settlemint/sdk-eas';
|
|
205
|
-
|
|
206
|
-
// Valid names
|
|
207
|
-
validateFieldName("userAddress"); // OK
|
|
208
|
-
validateFieldName("user_address"); // OK
|
|
209
|
-
|
|
210
|
-
// Invalid names
|
|
211
|
-
validateFieldName("user address"); // Throws: "Field name cannot contain spaces"
|
|
212
|
-
validateFieldName("123user"); // Throws: "Field name must start with a letter or underscore"
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
***
|
|
216
|
-
|
|
217
|
-
#### validateFieldType()
|
|
218
|
-
|
|
219
|
-
> **validateFieldType**(`type`): asserts type is "string" \| "address" \| "bool" \| "bytes" \| "bytes32" \| "uint256" \| "int256" \| "uint8" \| "int8"
|
|
220
|
-
|
|
221
|
-
Defined in: [schema.ts:101](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L101)
|
|
222
|
-
|
|
223
|
-
Validates a schema field type.
|
|
224
|
-
|
|
225
|
-
##### Parameters
|
|
226
|
-
|
|
227
|
-
| Parameter | Type | Description |
|
|
228
|
-
| ------ | ------ | ------ |
|
|
229
|
-
| `type` | `string` | The field type to validate |
|
|
230
|
-
|
|
231
|
-
##### Returns
|
|
232
|
-
|
|
233
|
-
asserts type is "string" \| "address" \| "bool" \| "bytes" \| "bytes32" \| "uint256" \| "int256" \| "uint8" \| "int8"
|
|
234
|
-
|
|
235
|
-
##### Throws
|
|
236
|
-
|
|
237
|
-
Error if the type is invalid
|
|
238
|
-
|
|
239
|
-
##### Example
|
|
240
|
-
|
|
241
|
-
```ts
|
|
242
|
-
import { validateFieldType } from '@settlemint/sdk-eas';
|
|
243
|
-
|
|
244
|
-
// Valid types
|
|
245
|
-
validateFieldType("string"); // OK
|
|
246
|
-
validateFieldType("address"); // OK
|
|
247
|
-
|
|
248
|
-
// Invalid types
|
|
249
|
-
validateFieldType("invalidType"); // Throws: "Invalid field type: invalidType"
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
***
|
|
253
|
-
|
|
254
|
-
#### validateSchemaFields()
|
|
255
|
-
|
|
256
|
-
> **validateSchemaFields**(`fields`): `void`
|
|
257
|
-
|
|
258
|
-
Defined in: [schema.ts:130](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L130)
|
|
259
|
-
|
|
260
|
-
Validates an array of schema fields.
|
|
261
|
-
|
|
262
|
-
##### Parameters
|
|
263
|
-
|
|
264
|
-
| Parameter | Type | Description |
|
|
265
|
-
| ------ | ------ | ------ |
|
|
266
|
-
| `fields` | [`SchemaField`](#schemafield)[] | The fields to validate |
|
|
267
|
-
|
|
268
|
-
##### Returns
|
|
269
|
-
|
|
270
|
-
`void`
|
|
271
|
-
|
|
272
|
-
##### Throws
|
|
273
|
-
|
|
274
|
-
Error if any field is invalid
|
|
275
|
-
|
|
276
|
-
##### Example
|
|
277
|
-
|
|
278
|
-
```ts
|
|
279
|
-
import { validateSchemaFields, SchemaField } from '@settlemint/sdk-eas';
|
|
280
|
-
|
|
281
|
-
const fields: SchemaField[] = [
|
|
282
|
-
{ name: "userAddress", type: "address" },
|
|
283
|
-
{ name: "age", type: "uint8" }
|
|
284
|
-
];
|
|
285
|
-
|
|
286
|
-
validateSchemaFields(fields); // OK
|
|
287
|
-
|
|
288
|
-
// Invalid fields
|
|
289
|
-
validateSchemaFields([]); // Throws: "Schema must have at least one field"
|
|
290
|
-
validateSchemaFields([
|
|
291
|
-
{ name: "userAddress", type: "address" },
|
|
292
|
-
{ name: "userAddress", type: "uint8" }
|
|
293
|
-
]); // Throws: "Duplicate field name: userAddress"
|
|
294
94
|
```
|
|
295
95
|
|
|
296
96
|
### Interfaces
|
|
297
97
|
|
|
298
98
|
#### RegisterSchemaOptions
|
|
299
99
|
|
|
300
|
-
Defined in: [
|
|
301
|
-
|
|
302
|
-
Options for registering a schema.
|
|
303
|
-
|
|
304
|
-
##### Example
|
|
305
|
-
|
|
306
|
-
```ts
|
|
307
|
-
import { RegisterSchemaOptions, SchemaField } from '@settlemint/sdk-eas';
|
|
308
|
-
|
|
309
|
-
const options: RegisterSchemaOptions = {
|
|
310
|
-
fields: [
|
|
311
|
-
{ name: "userAddress", type: "address" },
|
|
312
|
-
{ name: "age", type: "uint8" }
|
|
313
|
-
],
|
|
314
|
-
resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
315
|
-
revocable: true
|
|
316
|
-
};
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
##### Properties
|
|
100
|
+
Defined in: [sdk/eas/src/types.ts:39](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L39)
|
|
320
101
|
|
|
321
|
-
|
|
322
|
-
| ------ | ------ | ------ | ------ |
|
|
323
|
-
| <a id="fields"></a> `fields` | [`SchemaField`](#schemafield)[] | The fields that make up the schema | [schema.ts:189](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L189) |
|
|
324
|
-
| <a id="resolveraddress"></a> `resolverAddress` | `string` | The Ethereum address of the resolver | [schema.ts:191](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L191) |
|
|
325
|
-
| <a id="revocable"></a> `revocable` | `boolean` | Whether attestations using this schema can be revoked | [schema.ts:193](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L193) |
|
|
102
|
+
Options for registering a new schema in the EAS Schema Registry.
|
|
326
103
|
|
|
327
104
|
***
|
|
328
105
|
|
|
329
106
|
#### SchemaField
|
|
330
107
|
|
|
331
|
-
Defined in: [
|
|
108
|
+
Defined in: [sdk/eas/src/types.ts:26](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L26)
|
|
332
109
|
|
|
333
|
-
|
|
110
|
+
Represents a single field in an EAS schema.
|
|
334
111
|
|
|
335
|
-
|
|
112
|
+
### Type Aliases
|
|
336
113
|
|
|
337
|
-
|
|
338
|
-
import { SchemaField } from '@settlemint/sdk-eas';
|
|
114
|
+
#### ClientOptions
|
|
339
115
|
|
|
340
|
-
|
|
341
|
-
name: "userAddress",
|
|
342
|
-
type: "address",
|
|
343
|
-
description: "The Ethereum address of the user"
|
|
344
|
-
};
|
|
345
|
-
```
|
|
116
|
+
> **ClientOptions** = `z.infer`\<*typeof* [`ClientOptionsSchema`](#clientoptionsschema)\> & `Pick`\<`ViemClientOptions`, `"accessToken"` \| `"chainId"` \| `"chainName"` \| `"rpcUrl"`\>
|
|
346
117
|
|
|
347
|
-
|
|
118
|
+
Defined in: [sdk/eas/src/client-options.schema.ts:32](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/client-options.schema.ts#L32)
|
|
348
119
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
| <a id="description"></a> `description?` | `string` | Optional description of the field | [schema.ts:51](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L51) |
|
|
352
|
-
| <a id="name"></a> `name` | `string` | The name of the field | [schema.ts:47](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L47) |
|
|
353
|
-
| <a id="type"></a> `type` | `"string"` \| `"address"` \| `"bool"` \| `"bytes"` \| `"bytes32"` \| `"uint256"` \| `"int256"` \| `"uint8"` \| `"int8"` | The type of the field | [schema.ts:49](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L49) |
|
|
120
|
+
Configuration options for creating an EAS client.
|
|
121
|
+
Combines EAS-specific options with base Viem client options.
|
|
354
122
|
|
|
355
|
-
###
|
|
123
|
+
### Variables
|
|
356
124
|
|
|
357
|
-
####
|
|
125
|
+
#### ClientOptionsSchema
|
|
358
126
|
|
|
359
|
-
> **
|
|
127
|
+
> `const` **ClientOptionsSchema**: `ZodObject`\<\{ `accessToken`: `ZodString`; `attestationAddress`: `ZodEffects`\<`ZodString`, `` `0x${string}` ``, `string`\>; `chainId`: `ZodString`; `chainName`: `ZodString`; `rpcUrl`: `ZodString`; `schemaRegistryAddress`: `ZodEffects`\<`ZodString`, `` `0x${string}` ``, `string`\>; \}, `"strip"`, `ZodTypeAny`, \{ `accessToken`: `string`; `attestationAddress`: `` `0x${string}` ``; `chainId`: `string`; `chainName`: `string`; `rpcUrl`: `string`; `schemaRegistryAddress`: `` `0x${string}` ``; \}, \{ `accessToken`: `string`; `attestationAddress`: `string`; `chainId`: `string`; `chainName`: `string`; `rpcUrl`: `string`; `schemaRegistryAddress`: `string`; \}\>
|
|
360
128
|
|
|
361
|
-
Defined in: [schema.ts:
|
|
129
|
+
Defined in: [sdk/eas/src/client-options.schema.ts:10](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/client-options.schema.ts#L10)
|
|
362
130
|
|
|
363
|
-
|
|
131
|
+
Schema for validating EAS client configuration options.
|
|
132
|
+
Extends the base Viem client options with EAS-specific requirements.
|
|
364
133
|
|
|
365
|
-
|
|
134
|
+
***
|
|
366
135
|
|
|
367
136
|
#### EAS\_FIELD\_TYPES
|
|
368
137
|
|
|
369
138
|
> `const` **EAS\_FIELD\_TYPES**: `object`
|
|
370
139
|
|
|
371
|
-
Defined in: [
|
|
140
|
+
Defined in: [sdk/eas/src/types.ts:5](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L5)
|
|
372
141
|
|
|
373
|
-
Supported EAS schema
|
|
374
|
-
Maps
|
|
142
|
+
Supported field types for EAS schema fields.
|
|
143
|
+
Maps to the Solidity types that can be used in EAS schemas.
|
|
375
144
|
|
|
376
145
|
##### Type declaration
|
|
377
146
|
|
|
378
147
|
| Name | Type | Default value | Defined in |
|
|
379
148
|
| ------ | ------ | ------ | ------ |
|
|
380
|
-
| <a id="address"></a> `address` | `"address"` | `"address"` | [
|
|
381
|
-
| <a id="bool"></a> `bool` | `"bool"` | `"bool"` | [
|
|
382
|
-
| <a id="bytes"></a> `bytes` | `"bytes"` | `"bytes"` | [
|
|
383
|
-
| <a id="bytes32"></a> `bytes32` | `"bytes32"` | `"bytes32"` | [
|
|
384
|
-
| <a id="int256"></a> `int256` | `"int256"` | `"int256"` | [
|
|
385
|
-
| <a id="int8"></a> `int8` | `"int8"` | `"int8"` | [
|
|
386
|
-
| <a id="string"></a> `string` | `"string"` | `"string"` | [
|
|
387
|
-
| <a id="uint256"></a> `uint256` | `"uint256"` | `"uint256"` | [
|
|
388
|
-
| <a id="uint8"></a> `uint8` | `"uint8"` | `"uint8"` | [
|
|
389
|
-
|
|
390
|
-
##### Example
|
|
391
|
-
|
|
392
|
-
```ts
|
|
393
|
-
import { EAS_FIELD_TYPES } from '@settlemint/sdk-eas';
|
|
394
|
-
|
|
395
|
-
// Use in type definitions
|
|
396
|
-
type MyFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
397
|
-
|
|
398
|
-
// Check if a type is supported
|
|
399
|
-
const isValidType = "string" in EAS_FIELD_TYPES;
|
|
400
|
-
```
|
|
149
|
+
| <a id="address"></a> `address` | `"address"` | `"address"` | [sdk/eas/src/types.ts:7](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L7) |
|
|
150
|
+
| <a id="bool"></a> `bool` | `"bool"` | `"bool"` | [sdk/eas/src/types.ts:8](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L8) |
|
|
151
|
+
| <a id="bytes"></a> `bytes` | `"bytes"` | `"bytes"` | [sdk/eas/src/types.ts:9](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L9) |
|
|
152
|
+
| <a id="bytes32"></a> `bytes32` | `"bytes32"` | `"bytes32"` | [sdk/eas/src/types.ts:10](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L10) |
|
|
153
|
+
| <a id="int256"></a> `int256` | `"int256"` | `"int256"` | [sdk/eas/src/types.ts:12](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L12) |
|
|
154
|
+
| <a id="int8"></a> `int8` | `"int8"` | `"int8"` | [sdk/eas/src/types.ts:14](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L14) |
|
|
155
|
+
| <a id="string"></a> `string` | `"string"` | `"string"` | [sdk/eas/src/types.ts:6](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L6) |
|
|
156
|
+
| <a id="uint256"></a> `uint256` | `"uint256"` | `"uint256"` | [sdk/eas/src/types.ts:11](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L11) |
|
|
157
|
+
| <a id="uint8"></a> `uint8` | `"uint8"` | `"uint8"` | [sdk/eas/src/types.ts:13](https://github.com/settlemint/sdk/blob/v2.2.3/sdk/eas/src/types.ts#L13) |
|
|
401
158
|
|
|
402
159
|
## Contributing
|
|
403
160
|
|
package/dist/eas.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var viem=require('viem');var
|
|
1
|
+
'use strict';var easSdk=require('@ethereum-attestation-service/eas-sdk'),validation=require('@settlemint/sdk-utils/validation'),sdkViem=require('@settlemint/sdk-viem'),viem=require('viem'),zod=require('zod'),ethers=require('ethers');var u=zod.z.object({schemaRegistryAddress:zod.z.string().refine(viem.isAddress,"Invalid Ethereum address format"),attestationAddress:zod.z.string().refine(viem.isAddress,"Invalid Ethereum address format"),...zod.z.object({accessToken:validation.AccessTokenSchema,chainId:zod.z.string().min(1),chainName:zod.z.string().min(1),rpcUrl:validation.UrlSchema}).shape});function y(e){let{chain:t,transport:r}=e;if(!t)throw new Error("Chain is required");let n={chainId:t.id,name:t.name,ensAddress:t.contracts?.ensRegistry?.address};if(r.type==="fallback"){let s=r.transports.map(({value:i})=>{if(!i?.url)return null;try{return new ethers.JsonRpcProvider(i.url,n)}catch{return null}}).filter(i=>i!=null);if(s.length===0)throw new Error("No valid RPC URLs found");return s[0]}return new ethers.JsonRpcProvider(r.url,n)}function g(e){let{account:t,chain:r,transport:n}=e;if(!r)throw new Error("Chain is required");if(!t)throw new Error("Account is required");let s={chainId:r.id,name:r.name,ensAddress:r.contracts?.ensRegistry?.address},i=new ethers.JsonRpcProvider(n.url,s),c=t.privateKey;if(!c||typeof c!="string")throw new Error("Private key is required and must be a string");return new ethers.Wallet(c,i)}var d={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function b(e){if(!e)throw new Error("Field name cannot be empty");if(e.includes(" "))throw new Error("Field name cannot contain spaces");if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))throw new Error("Field name must start with a letter or underscore and contain only alphanumeric characters and underscores")}function F(e){if(!(e in d))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(d).join(", ")}`)}function h(e){if(!e||e.length===0)throw new Error("Schema must have at least one field");let t=new Set;for(let r of e){if(b(r.name),F(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function w(e){return h(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function K(e){validation.validate(u,e);let t=sdkViem.getPublicClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl}),r=sdkViem.getWalletClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl})(),n=y(t),s=g(r),i=new easSdk.SchemaRegistry(e.schemaRegistryAddress);i.connect(s);async function c(a){h(a.fields);let m=w(a.fields);try{await n.getNetwork();let l=await i.register({schema:m,resolverAddress:a.resolverAddress,revocable:a.revocable});return await l.wait(),l.toString()}catch(l){throw new Error(`Failed to register schema: ${l.message}`,{cause:l})}}async function S(a){try{return await n.getNetwork(),(await i.getSchema({uid:a})).toString()}catch(m){throw new Error(`Failed to get schema: ${m.message}`)}}return {registerSchema:c,getSchema:S}}exports.EAS_FIELD_TYPES=d;exports.createEASClient=K;//# sourceMappingURL=eas.cjs.map
|
|
2
2
|
//# sourceMappingURL=eas.cjs.map
|
package/dist/eas.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema.ts","../src/eas.ts"],"names":["EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","validateEthereumAddress","address","isAddress","registerSchema","options","resolverAddress","revocable","schemaString","createEASClient"],"mappings":"sCAcO,IAAMA,CAAkB,CAAA,CAC7B,MAAQ,CAAA,QAAA,CACR,OAAS,CAAA,SAAA,CACT,IAAM,CAAA,MAAA,CACN,MAAO,OACP,CAAA,OAAA,CAAS,SACT,CAAA,OAAA,CAAS,SACT,CAAA,MAAA,CAAQ,QACR,CAAA,KAAA,CAAO,OACP,CAAA,IAAA,CAAM,MACR,EA8CO,SAASC,CAAAA,CAAkBC,CAAoB,CAAA,CACpD,GAAI,CAACA,CAAAA,CACH,MAAM,IAAI,KAAM,CAAA,4BAA4B,CAE9C,CAAA,GAAIA,CAAK,CAAA,QAAA,CAAS,GAAG,CAAA,CACnB,MAAM,IAAI,KAAM,CAAA,kCAAkC,EAEpD,GAAI,CAAC,0BAA2B,CAAA,IAAA,CAAKA,CAAI,CAAA,CACvC,MAAM,IAAI,KACR,CAAA,4GACF,CAEJ,CAkBO,SAASC,CAAAA,CAAkBC,CAA4C,CAAA,CAC5E,GAAI,EAAEA,CAAAA,IAAQJ,CACZ,CAAA,CAAA,MAAM,IAAI,KAAA,CAAM,CAAuBI,oBAAAA,EAAAA,CAAI,CAAqB,kBAAA,EAAA,MAAA,CAAO,IAAKJ,CAAAA,CAAe,CAAE,CAAA,IAAA,CAAK,IAAI,CAAC,EAAE,CAE7G,CAyBO,SAASK,CAAAA,CAAqBC,CAA6B,CAAA,CAChE,GAAI,CAACA,CAAUA,EAAAA,CAAAA,CAAO,MAAW,GAAA,CAAA,CAC/B,MAAM,IAAI,KAAM,CAAA,qCAAqC,EAGvD,IAAMC,CAAAA,CAAY,IAAI,GAAA,CACtB,IAAWC,IAAAA,CAAAA,IAASF,CAAQ,CAAA,CAI1B,GAHAL,CAAAA,CAAkBO,CAAM,CAAA,IAAI,CAC5BL,CAA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,EAAE,CAAC,CAC5B,CAAA,CCvQO,SAASE,CAAAA,EAAkB,CAChC,OAAO,CACL,iBAAoB,EAAA,CAClB,OAAQ,CAAA,GAAA,CAAI,8BAA8B,EAC5C,CAEA,CAAA,gBAAA,EAAmB,CACjB,OAAA,CAAQ,GAAI,CAAA,2BAA2B,EACzC,CAAA,CAEA,YAAe,EAAA,CACb,QAAQ,GAAI,CAAA,uBAAuB,EACrC,CAAA,CAEA,SAAY,EAAA,CACV,OAAQ,CAAA,GAAA,CAAI,sBAAsB,EACpC,CAAA,CAEA,eAAkB,EAAA,CAChB,OAAQ,CAAA,GAAA,CAAI,4BAA4B,EAC1C,CACF,CACF","file":"eas.cjs","sourcesContent":["/**\n * Supported EAS schema field types.\n * Maps user-friendly type names to EAS-compatible type strings.\n * @example\n * ```ts\n * import { EAS_FIELD_TYPES } from '@settlemint/sdk-eas';\n *\n * // Use in type definitions\n * type MyFieldType = keyof typeof EAS_FIELD_TYPES;\n *\n * // Check if a type is supported\n * const isValidType = \"string\" in EAS_FIELD_TYPES;\n * ```\n */\nexport const EAS_FIELD_TYPES = {\n string: \"string\",\n address: \"address\",\n bool: \"bool\",\n bytes: \"bytes\",\n bytes32: \"bytes32\",\n uint256: \"uint256\",\n int256: \"int256\",\n uint8: \"uint8\",\n int8: \"int8\",\n} as const;\n\n/**\n * Type representing all valid EAS field types.\n */\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Interface for defining a schema field.\n * @example\n * ```ts\n * import { SchemaField } from '@settlemint/sdk-eas';\n *\n * const field: SchemaField = {\n * name: \"userAddress\",\n * type: \"address\",\n * description: \"The Ethereum address of the user\"\n * };\n * ```\n */\nexport interface SchemaField {\n /** The name of the field */\n name: string;\n /** The type of the field */\n type: EASFieldType;\n /** Optional description of the field */\n description?: string;\n}\n\n/**\n * Validates a schema field name.\n * @param name - The field name to validate\n * @throws Error if the name is invalid\n * @example\n * ```ts\n * import { validateFieldName } from '@settlemint/sdk-eas';\n *\n * // Valid names\n * validateFieldName(\"userAddress\"); // OK\n * validateFieldName(\"user_address\"); // OK\n *\n * // Invalid names\n * validateFieldName(\"user address\"); // Throws: \"Field name cannot contain spaces\"\n * validateFieldName(\"123user\"); // Throws: \"Field name must start with a letter or underscore\"\n * ```\n */\nexport function validateFieldName(name: string): void {\n if (!name) {\n throw new Error(\"Field name cannot be empty\");\n }\n if (name.includes(\" \")) {\n throw new Error(\"Field name cannot contain spaces\");\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n throw new Error(\n \"Field name must start with a letter or underscore and contain only alphanumeric characters and underscores\",\n );\n }\n}\n\n/**\n * Validates a schema field type.\n * @param type - The field type to validate\n * @throws Error if the type is invalid\n * @example\n * ```ts\n * import { validateFieldType } from '@settlemint/sdk-eas';\n *\n * // Valid types\n * validateFieldType(\"string\"); // OK\n * validateFieldType(\"address\"); // OK\n *\n * // Invalid types\n * validateFieldType(\"invalidType\"); // Throws: \"Invalid field type: invalidType\"\n * ```\n */\nexport function validateFieldType(type: string): asserts type is EASFieldType {\n if (!(type in EAS_FIELD_TYPES)) {\n throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(\", \")}`);\n }\n}\n\n/**\n * Validates an array of schema fields.\n * @param fields - The fields to validate\n * @throws Error if any field is invalid\n * @example\n * ```ts\n * import { validateSchemaFields, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ];\n *\n * validateSchemaFields(fields); // OK\n *\n * // Invalid fields\n * validateSchemaFields([]); // Throws: \"Schema must have at least one field\"\n * validateSchemaFields([\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"userAddress\", type: \"uint8\" }\n * ]); // Throws: \"Duplicate field name: userAddress\"\n * ```\n */\nexport function validateSchemaFields(fields: SchemaField[]): void {\n if (!fields || fields.length === 0) {\n throw new Error(\"Schema must have at least one field\");\n }\n\n const seenNames = new Set<string>();\n for (const field of fields) {\n validateFieldName(field.name);\n validateFieldType(field.type);\n\n if (seenNames.has(field.name)) {\n throw new Error(`Duplicate field name: ${field.name}`);\n }\n seenNames.add(field.name);\n }\n}\n\n/**\n * Builds an EAS schema string from an array of fields.\n * @param fields - The fields to include in the schema\n * @returns The EAS-compatible schema string\n * @throws Error if any field is invalid\n * @example\n * ```ts\n * import { buildSchemaString, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" },\n * { name: \"isActive\", type: \"bool\" }\n * ];\n *\n * const schemaString = buildSchemaString(fields);\n * // Result: \"address userAddress, uint8 age, bool isActive\"\n * ```\n */\nexport function buildSchemaString(fields: SchemaField[]): string {\n validateSchemaFields(fields);\n return fields.map((field) => `${field.type} ${field.name}`).join(\", \");\n}\n\n/**\n * Options for registering a schema.\n * @example\n * ```ts\n * import { RegisterSchemaOptions, SchemaField } from '@settlemint/sdk-eas';\n *\n * const options: RegisterSchemaOptions = {\n * fields: [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ],\n * resolverAddress: \"0x1234567890123456789012345678901234567890\",\n * revocable: true\n * };\n * ```\n */\nexport interface RegisterSchemaOptions {\n /** The fields that make up the schema */\n fields: SchemaField[];\n /** The Ethereum address of the resolver */\n resolverAddress: string;\n /** Whether attestations using this schema can be revoked */\n revocable: boolean;\n}\n\nimport { isAddress } from \"viem\";\n\n/**\n * Validates an Ethereum address.\n * @param address - The address to validate\n * @throws Error if the address is invalid\n * @example\n * ```ts\n * import { validateEthereumAddress } from '@settlemint/sdk-eas';\n *\n * // Valid address\n * validateEthereumAddress(\"0x1234567890123456789012345678901234567890\"); // OK\n *\n * // Invalid addresses\n * validateEthereumAddress(\"0x123\"); // Throws: \"Invalid Ethereum address format\"\n * validateEthereumAddress(\"\"); // Throws: \"Resolver address cannot be empty\"\n * ```\n */\nexport function validateEthereumAddress(address: string): void {\n if (!address) {\n throw new Error(\"Resolver address cannot be empty\");\n }\n if (!isAddress(address)) {\n throw new Error(\"Invalid Ethereum address format\");\n }\n}\n\n/**\n * Registers a new schema with EAS.\n * @param options - The schema registration options\n * @returns A promise that resolves to the schema UID\n * @throws Error if the schema registration fails\n * @example\n * ```ts\n * import { registerSchema, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ];\n *\n * const schemaUID = await registerSchema({\n * fields,\n * resolverAddress: \"0x1234567890123456789012345678901234567890\",\n * revocable: true\n * });\n *\n * console.log(`Schema registered with UID: ${schemaUID}`);\n * ```\n */\nexport async function registerSchema(options: RegisterSchemaOptions): Promise<string> {\n const { fields, resolverAddress, revocable } = options;\n\n // Validate the schema fields\n validateSchemaFields(fields);\n\n // Validate the resolver address\n validateEthereumAddress(resolverAddress);\n\n // Build the schema string\n const schemaString = buildSchemaString(fields);\n\n // TODO: Implement actual EAS SDK registration\n // This is a placeholder that will be replaced with actual EAS SDK integration\n console.log(`[EAS] Registering schema: ${schemaString}`);\n console.log(`[EAS] Resolver: ${resolverAddress}`);\n console.log(`[EAS] Revocable: ${revocable}`);\n\n // Return a mock UID for now\n return `0x${\"0\".repeat(64)}`;\n}\n","export * from \"./schema.js\";\n\nexport function createEASClient() {\n return {\n submitAttestation() {\n console.log(\"[EAS] Submitting attestation\");\n },\n\n parseAttestation() {\n console.log(\"[EAS] Parsing attestation\");\n },\n\n createSchema() {\n console.log(\"[EAS] Creating schema\");\n },\n\n getSchema() {\n console.log(\"[EAS] Getting schema\");\n },\n\n getAttestations() {\n console.log(\"[EAS] Getting attestations\");\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client-options.schema.ts","../src/ethers-adapter.ts","../src/types.ts","../src/validation.ts","../src/eas.ts"],"names":["ClientOptionsSchema","z","isAddress","AccessTokenSchema","UrlSchema","publicClientToProvider","client","chain","transport","network","providers","value","JsonRpcProvider","provider","walletClientToSigner","account","privateKey","Wallet","EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","createEASClient","options","validate","publicClient","getPublicClient","walletClient","getWalletClient","wallet","schemaRegistry","SchemaRegistry","registerSchema","schema","tx","error","getSchema","uid"],"mappings":"yOASO,IAAMA,CAAsBC,CAAAA,KAAAA,CAAE,OAAO,CAC1C,qBAAA,CAAuBA,KAAE,CAAA,MAAA,EAAS,CAAA,MAAA,CAAOC,cAAW,CAAA,iCAAiC,EACrF,kBAAoBD,CAAAA,KAAAA,CAAE,MAAO,EAAA,CAAE,MAAOC,CAAAA,cAAAA,CAAW,iCAAiC,CAAA,CAClF,GAAGD,KAAE,CAAA,MAAA,CAAO,CACV,WAAA,CAAaE,4BACb,CAAA,OAAA,CAASF,KAAE,CAAA,MAAA,GAAS,GAAI,CAAA,CAAC,CACzB,CAAA,SAAA,CAAWA,KAAE,CAAA,MAAA,EAAS,CAAA,GAAA,CAAI,CAAC,CAC3B,CAAA,MAAA,CAAQG,oBACV,CAAC,CAAE,CAAA,KACL,CAAC,CAAA,CCZM,SAASC,CAAuBC,CAAAA,CAAAA,CAAgC,CACrE,GAAM,CAAE,KAAAC,CAAAA,CAAAA,CAAO,SAAAC,CAAAA,CAAU,CAAIF,CAAAA,CAAAA,CAC7B,GAAI,CAACC,CAAAA,CAAO,MAAM,IAAI,KAAM,CAAA,mBAAmB,CAE/C,CAAA,IAAME,EAAU,CACd,OAAA,CAASF,CAAM,CAAA,EAAA,CACf,IAAMA,CAAAA,CAAAA,CAAM,IACZ,CAAA,UAAA,CAAYA,EAAM,SAAW,EAAA,WAAA,EAAa,OAC5C,CAAA,CAEA,GAAIC,CAAAA,CAAU,IAAS,GAAA,UAAA,CAAY,CACjC,IAAME,CAAAA,CAAaF,CAAU,CAAA,UAAA,CAC1B,GAAI,CAAA,CAAC,CAAE,KAAA,CAAA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AA,eAAA,CAAiBV,CAAQ,CAAA,eAAA,CACzB,SAAWA,CAAAA,CAAAA,CAAQ,SACrB,CAAC,EAED,OAAMW,MAAAA,CAAAA,CAAG,IAAK,EAAA,CACPA,CAAG,CAAA,QAAA,EACZ,CAAA,MAASC,EAAO,CACd,MAAM,IAAI,KAAA,CAAM,CAA+BA,2BAAAA,EAAAA,CAAAA,CAAgB,OAAO,CAAA,CAAA,CAAI,CAAE,KAAOA,CAAAA,CAAM,CAAC,CAC5F,CACF,CAEA,eAAeC,CAAAA,CAAUC,EAA8B,CACrD,GAAI,CAEF,OAAA,MAAM9B,CAAS,CAAA,UAAA,EAEA,CAAA,CAAA,MAAMuB,EAAe,SAAU,CAAA,CAAE,GAAAO,CAAAA,CAAI,CAAC,CAAA,EACvC,QAAS,EACzB,OAASF,CAAO,CAAA,CACd,MAAM,IAAI,KAAM,CAAA,CAAA,sBAAA,EAA0BA,CAAgB,CAAA,OAAO,EAAE,CACrE,CACF,CAEA,OAAO,CACL,cAAA,CAAAH,CACA,CAAA,SAAA,CAAAI,CACF,CACF","file":"eas.cjs","sourcesContent":["import { AccessTokenSchema, UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod\";\n\n/**\n * Schema for validating EAS client configuration options.\n * Extends the base Viem client options with EAS-specific requirements.\n */\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n attestationAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n ...z.object({\n accessToken: AccessTokenSchema,\n chainId: z.string().min(1),\n chainName: z.string().min(1),\n rpcUrl: UrlSchema,\n }).shape,\n});\n\n/**\n * Configuration options for creating an EAS client.\n * Combines EAS-specific options with base Viem client options.\n *\n * @property schemaRegistryAddress - The address of the EAS Schema Registry contract\n * @property attestationAddress - The address of the EAS Attestation contract\n * @property accessToken - Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_')\n * @property chainId - The chain ID to connect to\n * @property chainName - The name of the chain to connect to\n * @property rpcUrl - The RPC URL to connect to (must be a valid URL)\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema> &\n Pick<ViemClientOptions, \"accessToken\" | \"chainId\" | \"chainName\" | \"rpcUrl\">;\n","import { JsonRpcProvider, type Provider, Wallet } from \"ethers\";\nimport type { PublicClient, Transport, WalletClient } from \"viem\";\n\n/**\n * Converts a viem PublicClient to an ethers JsonRpcProvider\n */\nexport function publicClientToProvider(client: PublicClient): Provider {\n const { chain, transport } = client;\n if (!chain) throw new Error(\"Chain is required\");\n\n const network = {\n chainId: chain.id,\n name: chain.name,\n ensAddress: chain.contracts?.ensRegistry?.address,\n };\n\n if (transport.type === \"fallback\") {\n const providers = (transport.transports as ReturnType<Transport>[])\n .map(({ value }) => {\n if (!value?.url) return null;\n try {\n return new JsonRpcProvider(value.url, network);\n } catch {\n return null;\n }\n })\n .filter((provider): provider is JsonRpcProvider => provider != null);\n\n if (providers.length === 0) throw new Error(\"No valid RPC URLs found\");\n // We know providers[0] exists because we checked length > 0\n return providers[0] as Provider;\n }\n\n return new JsonRpcProvider(transport.url, network);\n}\n\n/**\n * Converts a viem WalletClient to an ethers Wallet\n */\nexport function walletClientToSigner(client: WalletClient): Wallet {\n const { account, chain, transport } = client;\n if (!chain) throw new Error(\"Chain is required\");\n if (!account) throw new Error(\"Account is required\");\n\n const network = {\n chainId: chain.id,\n name: chain.name,\n ensAddress: chain.contracts?.ensRegistry?.address,\n };\n\n const provider = new JsonRpcProvider(transport.url, network);\n\n // For viem, we need to get the private key from the account\n const privateKey = (account as { privateKey?: string }).privateKey;\n if (!privateKey || typeof privateKey !== \"string\") {\n throw new Error(\"Private key is required and must be a string\");\n }\n\n return new Wallet(privateKey, provider);\n}\n","/**\n * Supported field types for EAS schema fields.\n * Maps to the Solidity types that can be used in EAS schemas.\n */\nexport const EAS_FIELD_TYPES = {\n string: \"string\",\n address: \"address\",\n bool: \"bool\",\n bytes: \"bytes\",\n bytes32: \"bytes32\",\n uint256: \"uint256\",\n int256: \"int256\",\n uint8: \"uint8\",\n int8: \"int8\",\n} as const;\n\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Represents a single field in an EAS schema.\n *\n * @property name - The name of the field\n * @property type - The Solidity type of the field\n * @property description - Optional description of the field's purpose\n */\nexport interface SchemaField {\n name: string;\n type: EASFieldType;\n description?: string;\n}\n\n/**\n * Options for registering a new schema in the EAS Schema Registry.\n *\n * @property fields - Array of fields that make up the schema\n * @property resolverAddress - Address of the resolver contract that will handle attestations\n * @property revocable - Whether attestations using this schema can be revoked\n */\nexport interface RegisterSchemaOptions {\n fields: SchemaField[];\n resolverAddress: string;\n revocable: boolean;\n}\n","import { type EASFieldType, EAS_FIELD_TYPES, type SchemaField } from \"./types.js\";\n\nexport function validateFieldName(name: string): void {\n if (!name) {\n throw new Error(\"Field name cannot be empty\");\n }\n if (name.includes(\" \")) {\n throw new Error(\"Field name cannot contain spaces\");\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n throw new Error(\n \"Field name must start with a letter or underscore and contain only alphanumeric characters and underscores\",\n );\n }\n}\n\nexport function validateFieldType(type: string): asserts type is EASFieldType {\n if (!(type in EAS_FIELD_TYPES)) {\n throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(\", \")}`);\n }\n}\n\nexport function validateSchemaFields(fields: SchemaField[]): void {\n if (!fields || fields.length === 0) {\n throw new Error(\"Schema must have at least one field\");\n }\n\n const seenNames = new Set<string>();\n for (const field of fields) {\n validateFieldName(field.name);\n validateFieldType(field.type);\n\n if (seenNames.has(field.name)) {\n throw new Error(`Duplicate field name: ${field.name}`);\n }\n seenNames.add(field.name);\n }\n}\n\nexport function buildSchemaString(fields: SchemaField[]): string {\n validateSchemaFields(fields);\n return fields.map((field) => `${field.type} ${field.name}`).join(\", \");\n}\n","import { SchemaRegistry } from \"@ethereum-attestation-service/eas-sdk\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { getPublicClient, getWalletClient } from \"@settlemint/sdk-viem\";\nimport type { PublicClient } from \"viem\";\nimport { type ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nimport { publicClientToProvider, walletClientToSigner } from \"./ethers-adapter.js\";\nimport type { RegisterSchemaOptions } from \"./types.js\";\nimport { buildSchemaString, validateSchemaFields } from \"./validation.js\";\n\n// Re-export types and constants\nexport type { ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nexport type { RegisterSchemaOptions, SchemaField, EASFieldType } from \"./types.js\";\nexport { EAS_FIELD_TYPES } from \"./types.js\";\n\n/**\n * Creates an EAS client for interacting with the Ethereum Attestation Service.\n *\n * @param options - Configuration options for the client\n * @returns An object containing the EAS client instance\n * @throws Will throw an error if the options fail validation\n *\n * @example\n * ```ts\n * import { createEASClient } from '@settlemint/sdk-eas';\n *\n * const client = createEASClient({\n * schemaRegistryAddress: \"0x1234567890123456789012345678901234567890\",\n * attestationAddress: \"0x1234567890123456789012345678901234567890\",\n * accessToken: \"your-access-token\",\n * chainId: \"1\",\n * chainName: \"Ethereum\",\n * rpcUrl: \"http://localhost:8545\"\n * });\n * ```\n */\nexport function createEASClient(options: ClientOptions) {\n validate(ClientOptionsSchema, options);\n\n // Create viem clients\n const publicClient = getPublicClient({\n accessToken: options.accessToken,\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n }) as PublicClient;\n\n const walletClient = getWalletClient({\n accessToken: options.accessToken,\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n })();\n\n // Convert to ethers for EAS SDK\n const provider = publicClientToProvider(publicClient);\n const wallet = walletClientToSigner(walletClient);\n\n const schemaRegistry = new SchemaRegistry(options.schemaRegistryAddress);\n schemaRegistry.connect(wallet);\n\n async function registerSchema(options: RegisterSchemaOptions): Promise<string> {\n validateSchemaFields(options.fields);\n const schema = buildSchemaString(options.fields);\n\n try {\n // Check if the provider is available\n await provider.getNetwork();\n\n const tx = await schemaRegistry.register({\n schema,\n resolverAddress: options.resolverAddress,\n revocable: options.revocable,\n });\n\n await tx.wait();\n return tx.toString();\n } catch (error) {\n throw new Error(`Failed to register schema: ${(error as Error).message}`, { cause: error });\n }\n }\n\n async function getSchema(uid: string): Promise<string> {\n try {\n // Check if the provider is available\n await provider.getNetwork();\n\n const schema = await schemaRegistry.getSchema({ uid });\n return schema.toString();\n } catch (error) {\n throw new Error(`Failed to get schema: ${(error as Error).message}`);\n }\n }\n\n return {\n registerSchema,\n getSchema,\n };\n}\n"]}
|
package/dist/eas.d.cts
CHANGED
|
@@ -1,16 +1,48 @@
|
|
|
1
|
+
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
* Schema for validating EAS client configuration options.
|
|
6
|
+
* Extends the base Viem client options with EAS-specific requirements.
|
|
7
|
+
*/
|
|
8
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
9
|
+
accessToken: z.ZodString;
|
|
10
|
+
chainId: z.ZodString;
|
|
11
|
+
chainName: z.ZodString;
|
|
12
|
+
rpcUrl: z.ZodString;
|
|
13
|
+
schemaRegistryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
14
|
+
attestationAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
schemaRegistryAddress: `0x${string}`;
|
|
17
|
+
attestationAddress: `0x${string}`;
|
|
18
|
+
accessToken: string;
|
|
19
|
+
chainId: string;
|
|
20
|
+
chainName: string;
|
|
21
|
+
rpcUrl: string;
|
|
22
|
+
}, {
|
|
23
|
+
schemaRegistryAddress: string;
|
|
24
|
+
attestationAddress: string;
|
|
25
|
+
accessToken: string;
|
|
26
|
+
chainId: string;
|
|
27
|
+
chainName: string;
|
|
28
|
+
rpcUrl: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Configuration options for creating an EAS client.
|
|
32
|
+
* Combines EAS-specific options with base Viem client options.
|
|
33
|
+
*
|
|
34
|
+
* @property schemaRegistryAddress - The address of the EAS Schema Registry contract
|
|
35
|
+
* @property attestationAddress - The address of the EAS Attestation contract
|
|
36
|
+
* @property accessToken - Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_')
|
|
37
|
+
* @property chainId - The chain ID to connect to
|
|
38
|
+
* @property chainName - The name of the chain to connect to
|
|
39
|
+
* @property rpcUrl - The RPC URL to connect to (must be a valid URL)
|
|
40
|
+
*/
|
|
41
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema> & Pick<ClientOptions$1, "accessToken" | "chainId" | "chainName" | "rpcUrl">;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Supported field types for EAS schema fields.
|
|
45
|
+
* Maps to the Solidity types that can be used in EAS schemas.
|
|
14
46
|
*/
|
|
15
47
|
declare const EAS_FIELD_TYPES: {
|
|
16
48
|
readonly string: "string";
|
|
@@ -23,182 +55,56 @@ declare const EAS_FIELD_TYPES: {
|
|
|
23
55
|
readonly uint8: "uint8";
|
|
24
56
|
readonly int8: "int8";
|
|
25
57
|
};
|
|
26
|
-
/**
|
|
27
|
-
* Type representing all valid EAS field types.
|
|
28
|
-
*/
|
|
29
58
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
30
59
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* import { SchemaField } from '@settlemint/sdk-eas';
|
|
60
|
+
* Represents a single field in an EAS schema.
|
|
35
61
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* description: "The Ethereum address of the user"
|
|
40
|
-
* };
|
|
41
|
-
* ```
|
|
62
|
+
* @property name - The name of the field
|
|
63
|
+
* @property type - The Solidity type of the field
|
|
64
|
+
* @property description - Optional description of the field's purpose
|
|
42
65
|
*/
|
|
43
66
|
interface SchemaField {
|
|
44
|
-
/** The name of the field */
|
|
45
67
|
name: string;
|
|
46
|
-
/** The type of the field */
|
|
47
68
|
type: EASFieldType;
|
|
48
|
-
/** Optional description of the field */
|
|
49
69
|
description?: string;
|
|
50
70
|
}
|
|
51
71
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @param name - The field name to validate
|
|
54
|
-
* @throws Error if the name is invalid
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* import { validateFieldName } from '@settlemint/sdk-eas';
|
|
58
|
-
*
|
|
59
|
-
* // Valid names
|
|
60
|
-
* validateFieldName("userAddress"); // OK
|
|
61
|
-
* validateFieldName("user_address"); // OK
|
|
62
|
-
*
|
|
63
|
-
* // Invalid names
|
|
64
|
-
* validateFieldName("user address"); // Throws: "Field name cannot contain spaces"
|
|
65
|
-
* validateFieldName("123user"); // Throws: "Field name must start with a letter or underscore"
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function validateFieldName(name: string): void;
|
|
69
|
-
/**
|
|
70
|
-
* Validates a schema field type.
|
|
71
|
-
* @param type - The field type to validate
|
|
72
|
-
* @throws Error if the type is invalid
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* import { validateFieldType } from '@settlemint/sdk-eas';
|
|
76
|
-
*
|
|
77
|
-
* // Valid types
|
|
78
|
-
* validateFieldType("string"); // OK
|
|
79
|
-
* validateFieldType("address"); // OK
|
|
80
|
-
*
|
|
81
|
-
* // Invalid types
|
|
82
|
-
* validateFieldType("invalidType"); // Throws: "Invalid field type: invalidType"
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
declare function validateFieldType(type: string): asserts type is EASFieldType;
|
|
86
|
-
/**
|
|
87
|
-
* Validates an array of schema fields.
|
|
88
|
-
* @param fields - The fields to validate
|
|
89
|
-
* @throws Error if any field is invalid
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { validateSchemaFields, SchemaField } from '@settlemint/sdk-eas';
|
|
93
|
-
*
|
|
94
|
-
* const fields: SchemaField[] = [
|
|
95
|
-
* { name: "userAddress", type: "address" },
|
|
96
|
-
* { name: "age", type: "uint8" }
|
|
97
|
-
* ];
|
|
72
|
+
* Options for registering a new schema in the EAS Schema Registry.
|
|
98
73
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* validateSchemaFields([]); // Throws: "Schema must have at least one field"
|
|
103
|
-
* validateSchemaFields([
|
|
104
|
-
* { name: "userAddress", type: "address" },
|
|
105
|
-
* { name: "userAddress", type: "uint8" }
|
|
106
|
-
* ]); // Throws: "Duplicate field name: userAddress"
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
declare function validateSchemaFields(fields: SchemaField[]): void;
|
|
110
|
-
/**
|
|
111
|
-
* Builds an EAS schema string from an array of fields.
|
|
112
|
-
* @param fields - The fields to include in the schema
|
|
113
|
-
* @returns The EAS-compatible schema string
|
|
114
|
-
* @throws Error if any field is invalid
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* import { buildSchemaString, SchemaField } from '@settlemint/sdk-eas';
|
|
118
|
-
*
|
|
119
|
-
* const fields: SchemaField[] = [
|
|
120
|
-
* { name: "userAddress", type: "address" },
|
|
121
|
-
* { name: "age", type: "uint8" },
|
|
122
|
-
* { name: "isActive", type: "bool" }
|
|
123
|
-
* ];
|
|
124
|
-
*
|
|
125
|
-
* const schemaString = buildSchemaString(fields);
|
|
126
|
-
* // Result: "address userAddress, uint8 age, bool isActive"
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
declare function buildSchemaString(fields: SchemaField[]): string;
|
|
130
|
-
/**
|
|
131
|
-
* Options for registering a schema.
|
|
132
|
-
* @example
|
|
133
|
-
* ```ts
|
|
134
|
-
* import { RegisterSchemaOptions, SchemaField } from '@settlemint/sdk-eas';
|
|
135
|
-
*
|
|
136
|
-
* const options: RegisterSchemaOptions = {
|
|
137
|
-
* fields: [
|
|
138
|
-
* { name: "userAddress", type: "address" },
|
|
139
|
-
* { name: "age", type: "uint8" }
|
|
140
|
-
* ],
|
|
141
|
-
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
142
|
-
* revocable: true
|
|
143
|
-
* };
|
|
144
|
-
* ```
|
|
74
|
+
* @property fields - Array of fields that make up the schema
|
|
75
|
+
* @property resolverAddress - Address of the resolver contract that will handle attestations
|
|
76
|
+
* @property revocable - Whether attestations using this schema can be revoked
|
|
145
77
|
*/
|
|
146
78
|
interface RegisterSchemaOptions {
|
|
147
|
-
/** The fields that make up the schema */
|
|
148
79
|
fields: SchemaField[];
|
|
149
|
-
/** The Ethereum address of the resolver */
|
|
150
80
|
resolverAddress: string;
|
|
151
|
-
/** Whether attestations using this schema can be revoked */
|
|
152
81
|
revocable: boolean;
|
|
153
82
|
}
|
|
83
|
+
|
|
154
84
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @param address - The address to validate
|
|
157
|
-
* @throws Error if the address is invalid
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* import { validateEthereumAddress } from '@settlemint/sdk-eas';
|
|
85
|
+
* Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
161
86
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
87
|
+
* @param options - Configuration options for the client
|
|
88
|
+
* @returns An object containing the EAS client instance
|
|
89
|
+
* @throws Will throw an error if the options fail validation
|
|
164
90
|
*
|
|
165
|
-
* // Invalid addresses
|
|
166
|
-
* validateEthereumAddress("0x123"); // Throws: "Invalid Ethereum address format"
|
|
167
|
-
* validateEthereumAddress(""); // Throws: "Resolver address cannot be empty"
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
declare function validateEthereumAddress(address: string): void;
|
|
171
|
-
/**
|
|
172
|
-
* Registers a new schema with EAS.
|
|
173
|
-
* @param options - The schema registration options
|
|
174
|
-
* @returns A promise that resolves to the schema UID
|
|
175
|
-
* @throws Error if the schema registration fails
|
|
176
91
|
* @example
|
|
177
92
|
* ```ts
|
|
178
|
-
* import {
|
|
179
|
-
*
|
|
180
|
-
* const
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
188
|
-
* revocable: true
|
|
93
|
+
* import { createEASClient } from '@settlemint/sdk-eas';
|
|
94
|
+
*
|
|
95
|
+
* const client = createEASClient({
|
|
96
|
+
* schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
97
|
+
* attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
98
|
+
* accessToken: "your-access-token",
|
|
99
|
+
* chainId: "1",
|
|
100
|
+
* chainName: "Ethereum",
|
|
101
|
+
* rpcUrl: "http://localhost:8545"
|
|
189
102
|
* });
|
|
190
|
-
*
|
|
191
|
-
* console.log(`Schema registered with UID: ${schemaUID}`);
|
|
192
103
|
* ```
|
|
193
104
|
*/
|
|
194
|
-
declare function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
submitAttestation(): void;
|
|
198
|
-
parseAttestation(): void;
|
|
199
|
-
createSchema(): void;
|
|
200
|
-
getSchema(): void;
|
|
201
|
-
getAttestations(): void;
|
|
105
|
+
declare function createEASClient(options: ClientOptions): {
|
|
106
|
+
registerSchema: (options: RegisterSchemaOptions) => Promise<string>;
|
|
107
|
+
getSchema: (uid: string) => Promise<string>;
|
|
202
108
|
};
|
|
203
109
|
|
|
204
|
-
export { type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField,
|
|
110
|
+
export { type ClientOptions, ClientOptionsSchema, type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField, createEASClient };
|
package/dist/eas.d.ts
CHANGED
|
@@ -1,16 +1,48 @@
|
|
|
1
|
+
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
* Schema for validating EAS client configuration options.
|
|
6
|
+
* Extends the base Viem client options with EAS-specific requirements.
|
|
7
|
+
*/
|
|
8
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
9
|
+
accessToken: z.ZodString;
|
|
10
|
+
chainId: z.ZodString;
|
|
11
|
+
chainName: z.ZodString;
|
|
12
|
+
rpcUrl: z.ZodString;
|
|
13
|
+
schemaRegistryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
14
|
+
attestationAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
schemaRegistryAddress: `0x${string}`;
|
|
17
|
+
attestationAddress: `0x${string}`;
|
|
18
|
+
accessToken: string;
|
|
19
|
+
chainId: string;
|
|
20
|
+
chainName: string;
|
|
21
|
+
rpcUrl: string;
|
|
22
|
+
}, {
|
|
23
|
+
schemaRegistryAddress: string;
|
|
24
|
+
attestationAddress: string;
|
|
25
|
+
accessToken: string;
|
|
26
|
+
chainId: string;
|
|
27
|
+
chainName: string;
|
|
28
|
+
rpcUrl: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Configuration options for creating an EAS client.
|
|
32
|
+
* Combines EAS-specific options with base Viem client options.
|
|
33
|
+
*
|
|
34
|
+
* @property schemaRegistryAddress - The address of the EAS Schema Registry contract
|
|
35
|
+
* @property attestationAddress - The address of the EAS Attestation contract
|
|
36
|
+
* @property accessToken - Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_')
|
|
37
|
+
* @property chainId - The chain ID to connect to
|
|
38
|
+
* @property chainName - The name of the chain to connect to
|
|
39
|
+
* @property rpcUrl - The RPC URL to connect to (must be a valid URL)
|
|
40
|
+
*/
|
|
41
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema> & Pick<ClientOptions$1, "accessToken" | "chainId" | "chainName" | "rpcUrl">;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Supported field types for EAS schema fields.
|
|
45
|
+
* Maps to the Solidity types that can be used in EAS schemas.
|
|
14
46
|
*/
|
|
15
47
|
declare const EAS_FIELD_TYPES: {
|
|
16
48
|
readonly string: "string";
|
|
@@ -23,182 +55,56 @@ declare const EAS_FIELD_TYPES: {
|
|
|
23
55
|
readonly uint8: "uint8";
|
|
24
56
|
readonly int8: "int8";
|
|
25
57
|
};
|
|
26
|
-
/**
|
|
27
|
-
* Type representing all valid EAS field types.
|
|
28
|
-
*/
|
|
29
58
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
30
59
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* import { SchemaField } from '@settlemint/sdk-eas';
|
|
60
|
+
* Represents a single field in an EAS schema.
|
|
35
61
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* description: "The Ethereum address of the user"
|
|
40
|
-
* };
|
|
41
|
-
* ```
|
|
62
|
+
* @property name - The name of the field
|
|
63
|
+
* @property type - The Solidity type of the field
|
|
64
|
+
* @property description - Optional description of the field's purpose
|
|
42
65
|
*/
|
|
43
66
|
interface SchemaField {
|
|
44
|
-
/** The name of the field */
|
|
45
67
|
name: string;
|
|
46
|
-
/** The type of the field */
|
|
47
68
|
type: EASFieldType;
|
|
48
|
-
/** Optional description of the field */
|
|
49
69
|
description?: string;
|
|
50
70
|
}
|
|
51
71
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @param name - The field name to validate
|
|
54
|
-
* @throws Error if the name is invalid
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* import { validateFieldName } from '@settlemint/sdk-eas';
|
|
58
|
-
*
|
|
59
|
-
* // Valid names
|
|
60
|
-
* validateFieldName("userAddress"); // OK
|
|
61
|
-
* validateFieldName("user_address"); // OK
|
|
62
|
-
*
|
|
63
|
-
* // Invalid names
|
|
64
|
-
* validateFieldName("user address"); // Throws: "Field name cannot contain spaces"
|
|
65
|
-
* validateFieldName("123user"); // Throws: "Field name must start with a letter or underscore"
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function validateFieldName(name: string): void;
|
|
69
|
-
/**
|
|
70
|
-
* Validates a schema field type.
|
|
71
|
-
* @param type - The field type to validate
|
|
72
|
-
* @throws Error if the type is invalid
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* import { validateFieldType } from '@settlemint/sdk-eas';
|
|
76
|
-
*
|
|
77
|
-
* // Valid types
|
|
78
|
-
* validateFieldType("string"); // OK
|
|
79
|
-
* validateFieldType("address"); // OK
|
|
80
|
-
*
|
|
81
|
-
* // Invalid types
|
|
82
|
-
* validateFieldType("invalidType"); // Throws: "Invalid field type: invalidType"
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
declare function validateFieldType(type: string): asserts type is EASFieldType;
|
|
86
|
-
/**
|
|
87
|
-
* Validates an array of schema fields.
|
|
88
|
-
* @param fields - The fields to validate
|
|
89
|
-
* @throws Error if any field is invalid
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { validateSchemaFields, SchemaField } from '@settlemint/sdk-eas';
|
|
93
|
-
*
|
|
94
|
-
* const fields: SchemaField[] = [
|
|
95
|
-
* { name: "userAddress", type: "address" },
|
|
96
|
-
* { name: "age", type: "uint8" }
|
|
97
|
-
* ];
|
|
72
|
+
* Options for registering a new schema in the EAS Schema Registry.
|
|
98
73
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* validateSchemaFields([]); // Throws: "Schema must have at least one field"
|
|
103
|
-
* validateSchemaFields([
|
|
104
|
-
* { name: "userAddress", type: "address" },
|
|
105
|
-
* { name: "userAddress", type: "uint8" }
|
|
106
|
-
* ]); // Throws: "Duplicate field name: userAddress"
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
declare function validateSchemaFields(fields: SchemaField[]): void;
|
|
110
|
-
/**
|
|
111
|
-
* Builds an EAS schema string from an array of fields.
|
|
112
|
-
* @param fields - The fields to include in the schema
|
|
113
|
-
* @returns The EAS-compatible schema string
|
|
114
|
-
* @throws Error if any field is invalid
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* import { buildSchemaString, SchemaField } from '@settlemint/sdk-eas';
|
|
118
|
-
*
|
|
119
|
-
* const fields: SchemaField[] = [
|
|
120
|
-
* { name: "userAddress", type: "address" },
|
|
121
|
-
* { name: "age", type: "uint8" },
|
|
122
|
-
* { name: "isActive", type: "bool" }
|
|
123
|
-
* ];
|
|
124
|
-
*
|
|
125
|
-
* const schemaString = buildSchemaString(fields);
|
|
126
|
-
* // Result: "address userAddress, uint8 age, bool isActive"
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
declare function buildSchemaString(fields: SchemaField[]): string;
|
|
130
|
-
/**
|
|
131
|
-
* Options for registering a schema.
|
|
132
|
-
* @example
|
|
133
|
-
* ```ts
|
|
134
|
-
* import { RegisterSchemaOptions, SchemaField } from '@settlemint/sdk-eas';
|
|
135
|
-
*
|
|
136
|
-
* const options: RegisterSchemaOptions = {
|
|
137
|
-
* fields: [
|
|
138
|
-
* { name: "userAddress", type: "address" },
|
|
139
|
-
* { name: "age", type: "uint8" }
|
|
140
|
-
* ],
|
|
141
|
-
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
142
|
-
* revocable: true
|
|
143
|
-
* };
|
|
144
|
-
* ```
|
|
74
|
+
* @property fields - Array of fields that make up the schema
|
|
75
|
+
* @property resolverAddress - Address of the resolver contract that will handle attestations
|
|
76
|
+
* @property revocable - Whether attestations using this schema can be revoked
|
|
145
77
|
*/
|
|
146
78
|
interface RegisterSchemaOptions {
|
|
147
|
-
/** The fields that make up the schema */
|
|
148
79
|
fields: SchemaField[];
|
|
149
|
-
/** The Ethereum address of the resolver */
|
|
150
80
|
resolverAddress: string;
|
|
151
|
-
/** Whether attestations using this schema can be revoked */
|
|
152
81
|
revocable: boolean;
|
|
153
82
|
}
|
|
83
|
+
|
|
154
84
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @param address - The address to validate
|
|
157
|
-
* @throws Error if the address is invalid
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* import { validateEthereumAddress } from '@settlemint/sdk-eas';
|
|
85
|
+
* Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
161
86
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
87
|
+
* @param options - Configuration options for the client
|
|
88
|
+
* @returns An object containing the EAS client instance
|
|
89
|
+
* @throws Will throw an error if the options fail validation
|
|
164
90
|
*
|
|
165
|
-
* // Invalid addresses
|
|
166
|
-
* validateEthereumAddress("0x123"); // Throws: "Invalid Ethereum address format"
|
|
167
|
-
* validateEthereumAddress(""); // Throws: "Resolver address cannot be empty"
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
declare function validateEthereumAddress(address: string): void;
|
|
171
|
-
/**
|
|
172
|
-
* Registers a new schema with EAS.
|
|
173
|
-
* @param options - The schema registration options
|
|
174
|
-
* @returns A promise that resolves to the schema UID
|
|
175
|
-
* @throws Error if the schema registration fails
|
|
176
91
|
* @example
|
|
177
92
|
* ```ts
|
|
178
|
-
* import {
|
|
179
|
-
*
|
|
180
|
-
* const
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
188
|
-
* revocable: true
|
|
93
|
+
* import { createEASClient } from '@settlemint/sdk-eas';
|
|
94
|
+
*
|
|
95
|
+
* const client = createEASClient({
|
|
96
|
+
* schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
97
|
+
* attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
98
|
+
* accessToken: "your-access-token",
|
|
99
|
+
* chainId: "1",
|
|
100
|
+
* chainName: "Ethereum",
|
|
101
|
+
* rpcUrl: "http://localhost:8545"
|
|
189
102
|
* });
|
|
190
|
-
*
|
|
191
|
-
* console.log(`Schema registered with UID: ${schemaUID}`);
|
|
192
103
|
* ```
|
|
193
104
|
*/
|
|
194
|
-
declare function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
submitAttestation(): void;
|
|
198
|
-
parseAttestation(): void;
|
|
199
|
-
createSchema(): void;
|
|
200
|
-
getSchema(): void;
|
|
201
|
-
getAttestations(): void;
|
|
105
|
+
declare function createEASClient(options: ClientOptions): {
|
|
106
|
+
registerSchema: (options: RegisterSchemaOptions) => Promise<string>;
|
|
107
|
+
getSchema: (uid: string) => Promise<string>;
|
|
202
108
|
};
|
|
203
109
|
|
|
204
|
-
export { type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField,
|
|
110
|
+
export { type ClientOptions, ClientOptionsSchema, type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField, createEASClient };
|
package/dist/eas.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {isAddress}from'viem';var
|
|
1
|
+
import {SchemaRegistry}from'@ethereum-attestation-service/eas-sdk';import {UrlSchema,AccessTokenSchema,validate}from'@settlemint/sdk-utils/validation';import {getPublicClient,getWalletClient}from'@settlemint/sdk-viem';import {isAddress}from'viem';import {z}from'zod';import {JsonRpcProvider,Wallet}from'ethers';var u=z.object({schemaRegistryAddress:z.string().refine(isAddress,"Invalid Ethereum address format"),attestationAddress:z.string().refine(isAddress,"Invalid Ethereum address format"),...z.object({accessToken:AccessTokenSchema,chainId:z.string().min(1),chainName:z.string().min(1),rpcUrl:UrlSchema}).shape});function y(e){let{chain:t,transport:r}=e;if(!t)throw new Error("Chain is required");let n={chainId:t.id,name:t.name,ensAddress:t.contracts?.ensRegistry?.address};if(r.type==="fallback"){let s=r.transports.map(({value:i})=>{if(!i?.url)return null;try{return new JsonRpcProvider(i.url,n)}catch{return null}}).filter(i=>i!=null);if(s.length===0)throw new Error("No valid RPC URLs found");return s[0]}return new JsonRpcProvider(r.url,n)}function g(e){let{account:t,chain:r,transport:n}=e;if(!r)throw new Error("Chain is required");if(!t)throw new Error("Account is required");let s={chainId:r.id,name:r.name,ensAddress:r.contracts?.ensRegistry?.address},i=new JsonRpcProvider(n.url,s),c=t.privateKey;if(!c||typeof c!="string")throw new Error("Private key is required and must be a string");return new Wallet(c,i)}var d={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function b(e){if(!e)throw new Error("Field name cannot be empty");if(e.includes(" "))throw new Error("Field name cannot contain spaces");if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))throw new Error("Field name must start with a letter or underscore and contain only alphanumeric characters and underscores")}function F(e){if(!(e in d))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(d).join(", ")}`)}function h(e){if(!e||e.length===0)throw new Error("Schema must have at least one field");let t=new Set;for(let r of e){if(b(r.name),F(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function w(e){return h(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function K(e){validate(u,e);let t=getPublicClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl}),r=getWalletClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl})(),n=y(t),s=g(r),i=new SchemaRegistry(e.schemaRegistryAddress);i.connect(s);async function c(a){h(a.fields);let m=w(a.fields);try{await n.getNetwork();let l=await i.register({schema:m,resolverAddress:a.resolverAddress,revocable:a.revocable});return await l.wait(),l.toString()}catch(l){throw new Error(`Failed to register schema: ${l.message}`,{cause:l})}}async function S(a){try{return await n.getNetwork(),(await i.getSchema({uid:a})).toString()}catch(m){throw new Error(`Failed to get schema: ${m.message}`)}}return {registerSchema:c,getSchema:S}}export{d as EAS_FIELD_TYPES,K as createEASClient};//# sourceMappingURL=eas.mjs.map
|
|
2
2
|
//# sourceMappingURL=eas.mjs.map
|
package/dist/eas.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema.ts","../src/eas.ts"],"names":["EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","validateEthereumAddress","address","isAddress","registerSchema","options","resolverAddress","revocable","schemaString","createEASClient"],"mappings":"6BAcO,IAAMA,CAAkB,CAAA,CAC7B,MAAQ,CAAA,QAAA,CACR,OAAS,CAAA,SAAA,CACT,IAAM,CAAA,MAAA,CACN,MAAO,OACP,CAAA,OAAA,CAAS,SACT,CAAA,OAAA,CAAS,SACT,CAAA,MAAA,CAAQ,QACR,CAAA,KAAA,CAAO,OACP,CAAA,IAAA,CAAM,MACR,EA8CO,SAASC,CAAAA,CAAkBC,CAAoB,CAAA,CACpD,GAAI,CAACA,CAAAA,CACH,MAAM,IAAI,KAAM,CAAA,4BAA4B,CAE9C,CAAA,GAAIA,CAAK,CAAA,QAAA,CAAS,GAAG,CAAA,CACnB,MAAM,IAAI,KAAM,CAAA,kCAAkC,EAEpD,GAAI,CAAC,0BAA2B,CAAA,IAAA,CAAKA,CAAI,CAAA,CACvC,MAAM,IAAI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C,CAErD,CAyBA,eAAsBE,CAAAA,CAAeC,EAAiD,CACpF,GAAM,CAAE,MAAA,CAAAR,CAAQ,CAAA,eAAA,CAAAS,CAAiB,CAAA,SAAA,CAAAC,CAAU,CAAIF,CAAAA,CAAAA,CAG/CT,CAAqBC,CAAAA,CAAM,CAG3BI,CAAAA,CAAAA,CAAwBK,CAAe,CAAA,CAGvC,IAAME,CAAeR,CAAAA,CAAAA,CAAkBH,CAAM,CAAA,CAI7C,OAAQ,OAAA,CAAA,GAAA,CAAI,CAA6BW,0BAAAA,EAAAA,CAAY,CAAE,CAAA,CAAA,CACvD,OAAQ,CAAA,GAAA,CAAI,CAAmBF,gBAAAA,EAAAA,CAAe,CAAE,CAAA,CAAA,CAChD,QAAQ,GAAI,CAAA,CAAA,iBAAA,EAAoBC,CAAS,CAAA,CAAE,CAGpC,CAAA,CAAA,EAAA,EAAK,GAAI,CAAA,MAAA,CAAO,EAAE,CAAC,CAC5B,CAAA,CCvQO,SAASE,CAAAA,EAAkB,CAChC,OAAO,CACL,iBAAoB,EAAA,CAClB,OAAQ,CAAA,GAAA,CAAI,8BAA8B,EAC5C,CAEA,CAAA,gBAAA,EAAmB,CACjB,OAAA,CAAQ,GAAI,CAAA,2BAA2B,EACzC,CAAA,CAEA,YAAe,EAAA,CACb,QAAQ,GAAI,CAAA,uBAAuB,EACrC,CAAA,CAEA,SAAY,EAAA,CACV,OAAQ,CAAA,GAAA,CAAI,sBAAsB,EACpC,CAAA,CAEA,eAAkB,EAAA,CAChB,OAAQ,CAAA,GAAA,CAAI,4BAA4B,EAC1C,CACF,CACF","file":"eas.mjs","sourcesContent":["/**\n * Supported EAS schema field types.\n * Maps user-friendly type names to EAS-compatible type strings.\n * @example\n * ```ts\n * import { EAS_FIELD_TYPES } from '@settlemint/sdk-eas';\n *\n * // Use in type definitions\n * type MyFieldType = keyof typeof EAS_FIELD_TYPES;\n *\n * // Check if a type is supported\n * const isValidType = \"string\" in EAS_FIELD_TYPES;\n * ```\n */\nexport const EAS_FIELD_TYPES = {\n string: \"string\",\n address: \"address\",\n bool: \"bool\",\n bytes: \"bytes\",\n bytes32: \"bytes32\",\n uint256: \"uint256\",\n int256: \"int256\",\n uint8: \"uint8\",\n int8: \"int8\",\n} as const;\n\n/**\n * Type representing all valid EAS field types.\n */\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Interface for defining a schema field.\n * @example\n * ```ts\n * import { SchemaField } from '@settlemint/sdk-eas';\n *\n * const field: SchemaField = {\n * name: \"userAddress\",\n * type: \"address\",\n * description: \"The Ethereum address of the user\"\n * };\n * ```\n */\nexport interface SchemaField {\n /** The name of the field */\n name: string;\n /** The type of the field */\n type: EASFieldType;\n /** Optional description of the field */\n description?: string;\n}\n\n/**\n * Validates a schema field name.\n * @param name - The field name to validate\n * @throws Error if the name is invalid\n * @example\n * ```ts\n * import { validateFieldName } from '@settlemint/sdk-eas';\n *\n * // Valid names\n * validateFieldName(\"userAddress\"); // OK\n * validateFieldName(\"user_address\"); // OK\n *\n * // Invalid names\n * validateFieldName(\"user address\"); // Throws: \"Field name cannot contain spaces\"\n * validateFieldName(\"123user\"); // Throws: \"Field name must start with a letter or underscore\"\n * ```\n */\nexport function validateFieldName(name: string): void {\n if (!name) {\n throw new Error(\"Field name cannot be empty\");\n }\n if (name.includes(\" \")) {\n throw new Error(\"Field name cannot contain spaces\");\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n throw new Error(\n \"Field name must start with a letter or underscore and contain only alphanumeric characters and underscores\",\n );\n }\n}\n\n/**\n * Validates a schema field type.\n * @param type - The field type to validate\n * @throws Error if the type is invalid\n * @example\n * ```ts\n * import { validateFieldType } from '@settlemint/sdk-eas';\n *\n * // Valid types\n * validateFieldType(\"string\"); // OK\n * validateFieldType(\"address\"); // OK\n *\n * // Invalid types\n * validateFieldType(\"invalidType\"); // Throws: \"Invalid field type: invalidType\"\n * ```\n */\nexport function validateFieldType(type: string): asserts type is EASFieldType {\n if (!(type in EAS_FIELD_TYPES)) {\n throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(\", \")}`);\n }\n}\n\n/**\n * Validates an array of schema fields.\n * @param fields - The fields to validate\n * @throws Error if any field is invalid\n * @example\n * ```ts\n * import { validateSchemaFields, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ];\n *\n * validateSchemaFields(fields); // OK\n *\n * // Invalid fields\n * validateSchemaFields([]); // Throws: \"Schema must have at least one field\"\n * validateSchemaFields([\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"userAddress\", type: \"uint8\" }\n * ]); // Throws: \"Duplicate field name: userAddress\"\n * ```\n */\nexport function validateSchemaFields(fields: SchemaField[]): void {\n if (!fields || fields.length === 0) {\n throw new Error(\"Schema must have at least one field\");\n }\n\n const seenNames = new Set<string>();\n for (const field of fields) {\n validateFieldName(field.name);\n validateFieldType(field.type);\n\n if (seenNames.has(field.name)) {\n throw new Error(`Duplicate field name: ${field.name}`);\n }\n seenNames.add(field.name);\n }\n}\n\n/**\n * Builds an EAS schema string from an array of fields.\n * @param fields - The fields to include in the schema\n * @returns The EAS-compatible schema string\n * @throws Error if any field is invalid\n * @example\n * ```ts\n * import { buildSchemaString, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" },\n * { name: \"isActive\", type: \"bool\" }\n * ];\n *\n * const schemaString = buildSchemaString(fields);\n * // Result: \"address userAddress, uint8 age, bool isActive\"\n * ```\n */\nexport function buildSchemaString(fields: SchemaField[]): string {\n validateSchemaFields(fields);\n return fields.map((field) => `${field.type} ${field.name}`).join(\", \");\n}\n\n/**\n * Options for registering a schema.\n * @example\n * ```ts\n * import { RegisterSchemaOptions, SchemaField } from '@settlemint/sdk-eas';\n *\n * const options: RegisterSchemaOptions = {\n * fields: [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ],\n * resolverAddress: \"0x1234567890123456789012345678901234567890\",\n * revocable: true\n * };\n * ```\n */\nexport interface RegisterSchemaOptions {\n /** The fields that make up the schema */\n fields: SchemaField[];\n /** The Ethereum address of the resolver */\n resolverAddress: string;\n /** Whether attestations using this schema can be revoked */\n revocable: boolean;\n}\n\nimport { isAddress } from \"viem\";\n\n/**\n * Validates an Ethereum address.\n * @param address - The address to validate\n * @throws Error if the address is invalid\n * @example\n * ```ts\n * import { validateEthereumAddress } from '@settlemint/sdk-eas';\n *\n * // Valid address\n * validateEthereumAddress(\"0x1234567890123456789012345678901234567890\"); // OK\n *\n * // Invalid addresses\n * validateEthereumAddress(\"0x123\"); // Throws: \"Invalid Ethereum address format\"\n * validateEthereumAddress(\"\"); // Throws: \"Resolver address cannot be empty\"\n * ```\n */\nexport function validateEthereumAddress(address: string): void {\n if (!address) {\n throw new Error(\"Resolver address cannot be empty\");\n }\n if (!isAddress(address)) {\n throw new Error(\"Invalid Ethereum address format\");\n }\n}\n\n/**\n * Registers a new schema with EAS.\n * @param options - The schema registration options\n * @returns A promise that resolves to the schema UID\n * @throws Error if the schema registration fails\n * @example\n * ```ts\n * import { registerSchema, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ];\n *\n * const schemaUID = await registerSchema({\n * fields,\n * resolverAddress: \"0x1234567890123456789012345678901234567890\",\n * revocable: true\n * });\n *\n * console.log(`Schema registered with UID: ${schemaUID}`);\n * ```\n */\nexport async function registerSchema(options: RegisterSchemaOptions): Promise<string> {\n const { fields, resolverAddress, revocable } = options;\n\n // Validate the schema fields\n validateSchemaFields(fields);\n\n // Validate the resolver address\n validateEthereumAddress(resolverAddress);\n\n // Build the schema string\n const schemaString = buildSchemaString(fields);\n\n // TODO: Implement actual EAS SDK registration\n // This is a placeholder that will be replaced with actual EAS SDK integration\n console.log(`[EAS] Registering schema: ${schemaString}`);\n console.log(`[EAS] Resolver: ${resolverAddress}`);\n console.log(`[EAS] Revocable: ${revocable}`);\n\n // Return a mock UID for now\n return `0x${\"0\".repeat(64)}`;\n}\n","export * from \"./schema.js\";\n\nexport function createEASClient() {\n return {\n submitAttestation() {\n console.log(\"[EAS] Submitting attestation\");\n },\n\n parseAttestation() {\n console.log(\"[EAS] Parsing attestation\");\n },\n\n createSchema() {\n console.log(\"[EAS] Creating schema\");\n },\n\n getSchema() {\n console.log(\"[EAS] Getting schema\");\n },\n\n getAttestations() {\n console.log(\"[EAS] Getting attestations\");\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client-options.schema.ts","../src/ethers-adapter.ts","../src/types.ts","../src/validation.ts","../src/eas.ts"],"names":["ClientOptionsSchema","z","isAddress","AccessTokenSchema","UrlSchema","publicClientToProvider","client","chain","transport","network","providers","value","JsonRpcProvider","provider","walletClientToSigner","account","privateKey","Wallet","EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","createEASClient","options","validate","publicClient","getPublicClient","walletClient","getWalletClient","wallet","schemaRegistry","SchemaRegistry","registerSchema","schema","tx","error","getSchema","uid"],"mappings":"uTASO,IAAMA,CAAsBC,CAAAA,CAAAA,CAAE,OAAO,CAC1C,qBAAA,CAAuBA,CAAE,CAAA,MAAA,EAAS,CAAA,MAAA,CAAOC,SAAW,CAAA,iCAAiC,EACrF,kBAAoBD,CAAAA,CAAAA,CAAE,MAAO,EAAA,CAAE,MAAOC,CAAAA,SAAAA,CAAW,iCAAiC,CAAA,CAClF,GAAGD,CAAE,CAAA,MAAA,CAAO,CACV,WAAA,CAAaE,iBACb,CAAA,OAAA,CAASF,CAAE,CAAA,MAAA,GAAS,GAAI,CAAA,CAAC,CACzB,CAAA,SAAA,CAAWA,CAAE,CAAA,MAAA,EAAS,CAAA,GAAA,C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":"eas.mjs","sourcesContent":["import { AccessTokenSchema, UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod\";\n\n/**\n * Schema for validating EAS client configuration options.\n * Extends the base Viem client options with EAS-specific requirements.\n */\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n attestationAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n ...z.object({\n accessToken: AccessTokenSchema,\n chainId: z.string().min(1),\n chainName: z.string().min(1),\n rpcUrl: UrlSchema,\n }).shape,\n});\n\n/**\n * Configuration options for creating an EAS client.\n * Combines EAS-specific options with base Viem client options.\n *\n * @property schemaRegistryAddress - The address of the EAS Schema Registry contract\n * @property attestationAddress - The address of the EAS Attestation contract\n * @property accessToken - Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_')\n * @property chainId - The chain ID to connect to\n * @property chainName - The name of the chain to connect to\n * @property rpcUrl - The RPC URL to connect to (must be a valid URL)\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema> &\n Pick<ViemClientOptions, \"accessToken\" | \"chainId\" | \"chainName\" | \"rpcUrl\">;\n","import { JsonRpcProvider, type Provider, Wallet } from \"ethers\";\nimport type { PublicClient, Transport, WalletClient } from \"viem\";\n\n/**\n * Converts a viem PublicClient to an ethers JsonRpcProvider\n */\nexport function publicClientToProvider(client: PublicClient): Provider {\n const { chain, transport } = client;\n if (!chain) throw new Error(\"Chain is required\");\n\n const network = {\n chainId: chain.id,\n name: chain.name,\n ensAddress: chain.contracts?.ensRegistry?.address,\n };\n\n if (transport.type === \"fallback\") {\n const providers = (transport.transports as ReturnType<Transport>[])\n .map(({ value }) => {\n if (!value?.url) return null;\n try {\n return new JsonRpcProvider(value.url, network);\n } catch {\n return null;\n }\n })\n .filter((provider): provider is JsonRpcProvider => provider != null);\n\n if (providers.length === 0) throw new Error(\"No valid RPC URLs found\");\n // We know providers[0] exists because we checked length > 0\n return providers[0] as Provider;\n }\n\n return new JsonRpcProvider(transport.url, network);\n}\n\n/**\n * Converts a viem WalletClient to an ethers Wallet\n */\nexport function walletClientToSigner(client: WalletClient): Wallet {\n const { account, chain, transport } = client;\n if (!chain) throw new Error(\"Chain is required\");\n if (!account) throw new Error(\"Account is required\");\n\n const network = {\n chainId: chain.id,\n name: chain.name,\n ensAddress: chain.contracts?.ensRegistry?.address,\n };\n\n const provider = new JsonRpcProvider(transport.url, network);\n\n // For viem, we need to get the private key from the account\n const privateKey = (account as { privateKey?: string }).privateKey;\n if (!privateKey || typeof privateKey !== \"string\") {\n throw new Error(\"Private key is required and must be a string\");\n }\n\n return new Wallet(privateKey, provider);\n}\n","/**\n * Supported field types for EAS schema fields.\n * Maps to the Solidity types that can be used in EAS schemas.\n */\nexport const EAS_FIELD_TYPES = {\n string: \"string\",\n address: \"address\",\n bool: \"bool\",\n bytes: \"bytes\",\n bytes32: \"bytes32\",\n uint256: \"uint256\",\n int256: \"int256\",\n uint8: \"uint8\",\n int8: \"int8\",\n} as const;\n\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Represents a single field in an EAS schema.\n *\n * @property name - The name of the field\n * @property type - The Solidity type of the field\n * @property description - Optional description of the field's purpose\n */\nexport interface SchemaField {\n name: string;\n type: EASFieldType;\n description?: string;\n}\n\n/**\n * Options for registering a new schema in the EAS Schema Registry.\n *\n * @property fields - Array of fields that make up the schema\n * @property resolverAddress - Address of the resolver contract that will handle attestations\n * @property revocable - Whether attestations using this schema can be revoked\n */\nexport interface RegisterSchemaOptions {\n fields: SchemaField[];\n resolverAddress: string;\n revocable: boolean;\n}\n","import { type EASFieldType, EAS_FIELD_TYPES, type SchemaField } from \"./types.js\";\n\nexport function validateFieldName(name: string): void {\n if (!name) {\n throw new Error(\"Field name cannot be empty\");\n }\n if (name.includes(\" \")) {\n throw new Error(\"Field name cannot contain spaces\");\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n throw new Error(\n \"Field name must start with a letter or underscore and contain only alphanumeric characters and underscores\",\n );\n }\n}\n\nexport function validateFieldType(type: string): asserts type is EASFieldType {\n if (!(type in EAS_FIELD_TYPES)) {\n throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(\", \")}`);\n }\n}\n\nexport function validateSchemaFields(fields: SchemaField[]): void {\n if (!fields || fields.length === 0) {\n throw new Error(\"Schema must have at least one field\");\n }\n\n const seenNames = new Set<string>();\n for (const field of fields) {\n validateFieldName(field.name);\n validateFieldType(field.type);\n\n if (seenNames.has(field.name)) {\n throw new Error(`Duplicate field name: ${field.name}`);\n }\n seenNames.add(field.name);\n }\n}\n\nexport function buildSchemaString(fields: SchemaField[]): string {\n validateSchemaFields(fields);\n return fields.map((field) => `${field.type} ${field.name}`).join(\", \");\n}\n","import { SchemaRegistry } from \"@ethereum-attestation-service/eas-sdk\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { getPublicClient, getWalletClient } from \"@settlemint/sdk-viem\";\nimport type { PublicClient } from \"viem\";\nimport { type ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nimport { publicClientToProvider, walletClientToSigner } from \"./ethers-adapter.js\";\nimport type { RegisterSchemaOptions } from \"./types.js\";\nimport { buildSchemaString, validateSchemaFields } from \"./validation.js\";\n\n// Re-export types and constants\nexport type { ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nexport type { RegisterSchemaOptions, SchemaField, EASFieldType } from \"./types.js\";\nexport { EAS_FIELD_TYPES } from \"./types.js\";\n\n/**\n * Creates an EAS client for interacting with the Ethereum Attestation Service.\n *\n * @param options - Configuration options for the client\n * @returns An object containing the EAS client instance\n * @throws Will throw an error if the options fail validation\n *\n * @example\n * ```ts\n * import { createEASClient } from '@settlemint/sdk-eas';\n *\n * const client = createEASClient({\n * schemaRegistryAddress: \"0x1234567890123456789012345678901234567890\",\n * attestationAddress: \"0x1234567890123456789012345678901234567890\",\n * accessToken: \"your-access-token\",\n * chainId: \"1\",\n * chainName: \"Ethereum\",\n * rpcUrl: \"http://localhost:8545\"\n * });\n * ```\n */\nexport function createEASClient(options: ClientOptions) {\n validate(ClientOptionsSchema, options);\n\n // Create viem clients\n const publicClient = getPublicClient({\n accessToken: options.accessToken,\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n }) as PublicClient;\n\n const walletClient = getWalletClient({\n accessToken: options.accessToken,\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n })();\n\n // Convert to ethers for EAS SDK\n const provider = publicClientToProvider(publicClient);\n const wallet = walletClientToSigner(walletClient);\n\n const schemaRegistry = new SchemaRegistry(options.schemaRegistryAddress);\n schemaRegistry.connect(wallet);\n\n async function registerSchema(options: RegisterSchemaOptions): Promise<string> {\n validateSchemaFields(options.fields);\n const schema = buildSchemaString(options.fields);\n\n try {\n // Check if the provider is available\n await provider.getNetwork();\n\n const tx = await schemaRegistry.register({\n schema,\n resolverAddress: options.resolverAddress,\n revocable: options.revocable,\n });\n\n await tx.wait();\n return tx.toString();\n } catch (error) {\n throw new Error(`Failed to register schema: ${(error as Error).message}`, { cause: error });\n }\n }\n\n async function getSchema(uid: string): Promise<string> {\n try {\n // Check if the provider is available\n await provider.getNetwork();\n\n const schema = await schemaRegistry.getSchema({ uid });\n return schema.toString();\n } catch (error) {\n throw new Error(`Failed to get schema: ${(error as Error).message}`);\n }\n }\n\n return {\n registerSchema,\n getSchema,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlemint/sdk-eas",
|
|
3
3
|
"description": "Ethereum Attestation Service (EAS) integration for SettleMint SDK",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.3-main0f4b90ca",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -51,8 +51,11 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"
|
|
54
|
+
"@ethereum-attestation-service/eas-sdk": "^2",
|
|
55
|
+
"@settlemint/sdk-utils": "2.2.3-main0f4b90ca",
|
|
56
|
+
"@settlemint/sdk-viem": "2.2.3-main0f4b90ca",
|
|
57
|
+
"ethers": "^6",
|
|
58
|
+
"viem": "^2"
|
|
56
59
|
},
|
|
57
60
|
"peerDependencies": {},
|
|
58
61
|
"engines": {
|