@settlemint/sdk-eas 2.2.2-main5d81cd7d → 2.2.2-main7ac23329
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 +298 -43
- package/dist/eas.cjs +1 -1
- package/dist/eas.cjs.map +1 -1
- package/dist/eas.d.cts +164 -70
- package/dist/eas.d.ts +164 -70
- package/dist/eas.mjs +1 -1
- package/dist/eas.mjs.map +1 -1
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -29,12 +29,17 @@
|
|
|
29
29
|
- [About](#about)
|
|
30
30
|
- [API Reference](#api-reference)
|
|
31
31
|
- [Functions](#functions)
|
|
32
|
-
- [
|
|
32
|
+
- [buildSchemaString()](#buildschemastring)
|
|
33
|
+
- [registerSchema()](#registerschema)
|
|
34
|
+
- [validateEthereumAddress()](#validateethereumaddress)
|
|
35
|
+
- [validateFieldName()](#validatefieldname)
|
|
36
|
+
- [validateFieldType()](#validatefieldtype)
|
|
37
|
+
- [validateSchemaFields()](#validateschemafields)
|
|
33
38
|
- [Interfaces](#interfaces)
|
|
34
39
|
- [RegisterSchemaOptions](#registerschemaoptions)
|
|
35
40
|
- [SchemaField](#schemafield)
|
|
36
41
|
- [Type Aliases](#type-aliases)
|
|
37
|
-
- [
|
|
42
|
+
- [EASFieldType](#easfieldtype)
|
|
38
43
|
- [Variables](#variables)
|
|
39
44
|
- [EAS\_FIELD\_TYPES](#eas_field_types)
|
|
40
45
|
- [Contributing](#contributing)
|
|
@@ -48,76 +53,314 @@ The SettleMint EAS SDK provides a lightweight wrapper for the Ethereum Attestati
|
|
|
48
53
|
|
|
49
54
|
### Functions
|
|
50
55
|
|
|
51
|
-
####
|
|
56
|
+
#### buildSchemaString()
|
|
52
57
|
|
|
53
|
-
> **
|
|
58
|
+
> **buildSchemaString**(`fields`): `string`
|
|
54
59
|
|
|
55
|
-
Defined in: [
|
|
60
|
+
Defined in: [schema.ts:166](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L166)
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
Builds an EAS schema string from an array of fields.
|
|
58
63
|
|
|
59
64
|
##### Parameters
|
|
60
65
|
|
|
61
66
|
| Parameter | Type | Description |
|
|
62
67
|
| ------ | ------ | ------ |
|
|
63
|
-
| `
|
|
68
|
+
| `fields` | [`SchemaField`](#schemafield)[] | The fields to include in the schema |
|
|
64
69
|
|
|
65
70
|
##### Returns
|
|
66
71
|
|
|
67
|
-
`
|
|
72
|
+
`string`
|
|
68
73
|
|
|
69
|
-
|
|
74
|
+
The EAS-compatible schema string
|
|
70
75
|
|
|
71
|
-
|
|
76
|
+
##### Throws
|
|
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
108
|
| ------ | ------ | ------ |
|
|
73
|
-
| `
|
|
74
|
-
|
|
109
|
+
| `options` | [`RegisterSchemaOptions`](#registerschemaoptions) | The schema registration options |
|
|
110
|
+
|
|
111
|
+
##### Returns
|
|
112
|
+
|
|
113
|
+
`Promise`\<`string`\>
|
|
114
|
+
|
|
115
|
+
A promise that resolves to the schema UID
|
|
75
116
|
|
|
76
117
|
##### Throws
|
|
77
118
|
|
|
78
|
-
|
|
119
|
+
Error if the schema registration fails
|
|
79
120
|
|
|
80
121
|
##### Example
|
|
81
122
|
|
|
82
123
|
```ts
|
|
83
|
-
import {
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
124
|
+
import { registerSchema, SchemaField } from '@settlemint/sdk-eas';
|
|
125
|
+
|
|
126
|
+
const fields: SchemaField[] = [
|
|
127
|
+
{ name: "userAddress", type: "address" },
|
|
128
|
+
{ name: "age", type: "uint8" }
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
const schemaUID = await registerSchema({
|
|
132
|
+
fields,
|
|
133
|
+
resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
134
|
+
revocable: true
|
|
92
135
|
});
|
|
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"
|
|
93
294
|
```
|
|
94
295
|
|
|
95
296
|
### Interfaces
|
|
96
297
|
|
|
97
298
|
#### RegisterSchemaOptions
|
|
98
299
|
|
|
99
|
-
Defined in: [
|
|
300
|
+
Defined in: [schema.ts:187](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L187)
|
|
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
320
|
|
|
101
|
-
|
|
321
|
+
| Property | Type | Description | Defined in |
|
|
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
326
|
|
|
103
327
|
***
|
|
104
328
|
|
|
105
329
|
#### SchemaField
|
|
106
330
|
|
|
107
|
-
Defined in: [
|
|
331
|
+
Defined in: [schema.ts:45](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L45)
|
|
332
|
+
|
|
333
|
+
Interface for defining a schema field.
|
|
334
|
+
|
|
335
|
+
##### Example
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
import { SchemaField } from '@settlemint/sdk-eas';
|
|
339
|
+
|
|
340
|
+
const field: SchemaField = {
|
|
341
|
+
name: "userAddress",
|
|
342
|
+
type: "address",
|
|
343
|
+
description: "The Ethereum address of the user"
|
|
344
|
+
};
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
##### Properties
|
|
108
348
|
|
|
109
|
-
|
|
349
|
+
| Property | Type | Description | Defined in |
|
|
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) |
|
|
110
354
|
|
|
111
355
|
### Type Aliases
|
|
112
356
|
|
|
113
|
-
####
|
|
357
|
+
#### EASFieldType
|
|
114
358
|
|
|
115
|
-
> **
|
|
359
|
+
> **EASFieldType** = keyof *typeof* [`EAS_FIELD_TYPES`](#eas_field_types)
|
|
116
360
|
|
|
117
|
-
Defined in: [
|
|
361
|
+
Defined in: [schema.ts:30](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L30)
|
|
118
362
|
|
|
119
|
-
|
|
120
|
-
Combines EAS-specific options with base Viem client options.
|
|
363
|
+
Type representing all valid EAS field types.
|
|
121
364
|
|
|
122
365
|
### Variables
|
|
123
366
|
|
|
@@ -125,24 +368,36 @@ Combines EAS-specific options with base Viem client options.
|
|
|
125
368
|
|
|
126
369
|
> `const` **EAS\_FIELD\_TYPES**: `object`
|
|
127
370
|
|
|
128
|
-
Defined in: [
|
|
371
|
+
Defined in: [schema.ts:15](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L15)
|
|
129
372
|
|
|
130
|
-
Supported
|
|
131
|
-
Maps
|
|
373
|
+
Supported EAS schema field types.
|
|
374
|
+
Maps user-friendly type names to EAS-compatible type strings.
|
|
132
375
|
|
|
133
376
|
##### Type declaration
|
|
134
377
|
|
|
135
378
|
| Name | Type | Default value | Defined in |
|
|
136
379
|
| ------ | ------ | ------ | ------ |
|
|
137
|
-
| <a id="address"></a> `address` | `"address"` | `"address"` | [
|
|
138
|
-
| <a id="bool"></a> `bool` | `"bool"` | `"bool"` | [
|
|
139
|
-
| <a id="bytes"></a> `bytes` | `"bytes"` | `"bytes"` | [
|
|
140
|
-
| <a id="bytes32"></a> `bytes32` | `"bytes32"` | `"bytes32"` | [
|
|
141
|
-
| <a id="int256"></a> `int256` | `"int256"` | `"int256"` | [
|
|
142
|
-
| <a id="int8"></a> `int8` | `"int8"` | `"int8"` | [
|
|
143
|
-
| <a id="string"></a> `string` | `"string"` | `"string"` | [
|
|
144
|
-
| <a id="uint256"></a> `uint256` | `"uint256"` | `"uint256"` | [
|
|
145
|
-
| <a id="uint8"></a> `uint8` | `"uint8"` | `"uint8"` | [
|
|
380
|
+
| <a id="address"></a> `address` | `"address"` | `"address"` | [schema.ts:17](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L17) |
|
|
381
|
+
| <a id="bool"></a> `bool` | `"bool"` | `"bool"` | [schema.ts:18](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L18) |
|
|
382
|
+
| <a id="bytes"></a> `bytes` | `"bytes"` | `"bytes"` | [schema.ts:19](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L19) |
|
|
383
|
+
| <a id="bytes32"></a> `bytes32` | `"bytes32"` | `"bytes32"` | [schema.ts:20](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L20) |
|
|
384
|
+
| <a id="int256"></a> `int256` | `"int256"` | `"int256"` | [schema.ts:22](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L22) |
|
|
385
|
+
| <a id="int8"></a> `int8` | `"int8"` | `"int8"` | [schema.ts:24](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L24) |
|
|
386
|
+
| <a id="string"></a> `string` | `"string"` | `"string"` | [schema.ts:16](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L16) |
|
|
387
|
+
| <a id="uint256"></a> `uint256` | `"uint256"` | `"uint256"` | [schema.ts:21](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L21) |
|
|
388
|
+
| <a id="uint8"></a> `uint8` | `"uint8"` | `"uint8"` | [schema.ts:23](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L23) |
|
|
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
|
+
```
|
|
146
401
|
|
|
147
402
|
## Contributing
|
|
148
403
|
|
package/dist/eas.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var viem=require('viem');var o={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function a(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 c(e){if(!(e in o))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(o).join(", ")}`)}function r(e){if(!e||e.length===0)throw new Error("Schema must have at least one field");let t=new Set;for(let n of e){if(a(n.name),c(n.type),t.has(n.name))throw new Error(`Duplicate field name: ${n.name}`);t.add(n.name);}}function l(e){return r(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function m(e){if(!e)throw new Error("Resolver address cannot be empty");if(!viem.isAddress(e))throw new Error("Invalid Ethereum address format")}async function p(e){let{fields:t,resolverAddress:n,revocable:i}=e;r(t),m(n);let s=l(t);return console.log(`[EAS] Registering schema: ${s}`),console.log(`[EAS] Resolver: ${n}`),console.log(`[EAS] Revocable: ${i}`),`0x${"0".repeat(64)}`}function S(){return {submitAttestation(){console.log("[EAS] Submitting attestation");},parseAttestation(){console.log("[EAS] Parsing attestation");},createSchema(){console.log("[EAS] Creating schema");},getSchema(){console.log("[EAS] Getting schema");},getAttestations(){console.log("[EAS] Getting attestations");}}}exports.EAS_FIELD_TYPES=o;exports.buildSchemaString=l;exports.createEASClient=S;exports.registerSchema=p;exports.validateEthereumAddress=m;exports.validateFieldName=a;exports.validateFieldType=c;exports.validateSchemaFields=r;//# sourceMappingURL=eas.cjs.map
|
|
2
2
|
//# sourceMappingURL=eas.cjs.map
|
package/dist/eas.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CA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H,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 } 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"]}
|
|
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,CA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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"]}
|
package/dist/eas.d.cts
CHANGED
|
@@ -1,48 +1,16 @@
|
|
|
1
|
-
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
/**
|
|
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
1
|
/**
|
|
44
|
-
* Supported
|
|
45
|
-
* Maps
|
|
2
|
+
* Supported EAS schema field types.
|
|
3
|
+
* Maps user-friendly type names to EAS-compatible type strings.
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { EAS_FIELD_TYPES } from '@settlemint/sdk-eas';
|
|
7
|
+
*
|
|
8
|
+
* // Use in type definitions
|
|
9
|
+
* type MyFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
10
|
+
*
|
|
11
|
+
* // Check if a type is supported
|
|
12
|
+
* const isValidType = "string" in EAS_FIELD_TYPES;
|
|
13
|
+
* ```
|
|
46
14
|
*/
|
|
47
15
|
declare const EAS_FIELD_TYPES: {
|
|
48
16
|
readonly string: "string";
|
|
@@ -55,56 +23,182 @@ declare const EAS_FIELD_TYPES: {
|
|
|
55
23
|
readonly uint8: "uint8";
|
|
56
24
|
readonly int8: "int8";
|
|
57
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Type representing all valid EAS field types.
|
|
28
|
+
*/
|
|
58
29
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
59
30
|
/**
|
|
60
|
-
*
|
|
31
|
+
* Interface for defining a schema field.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { SchemaField } from '@settlemint/sdk-eas';
|
|
61
35
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
36
|
+
* const field: SchemaField = {
|
|
37
|
+
* name: "userAddress",
|
|
38
|
+
* type: "address",
|
|
39
|
+
* description: "The Ethereum address of the user"
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
65
42
|
*/
|
|
66
43
|
interface SchemaField {
|
|
44
|
+
/** The name of the field */
|
|
67
45
|
name: string;
|
|
46
|
+
/** The type of the field */
|
|
68
47
|
type: EASFieldType;
|
|
48
|
+
/** Optional description of the field */
|
|
69
49
|
description?: string;
|
|
70
50
|
}
|
|
71
51
|
/**
|
|
72
|
-
*
|
|
52
|
+
* Validates a schema field name.
|
|
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
|
+
* ];
|
|
73
98
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
99
|
+
* validateSchemaFields(fields); // OK
|
|
100
|
+
*
|
|
101
|
+
* // Invalid fields
|
|
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
|
+
* ```
|
|
77
145
|
*/
|
|
78
146
|
interface RegisterSchemaOptions {
|
|
147
|
+
/** The fields that make up the schema */
|
|
79
148
|
fields: SchemaField[];
|
|
149
|
+
/** The Ethereum address of the resolver */
|
|
80
150
|
resolverAddress: string;
|
|
151
|
+
/** Whether attestations using this schema can be revoked */
|
|
81
152
|
revocable: boolean;
|
|
82
153
|
}
|
|
83
|
-
|
|
84
154
|
/**
|
|
85
|
-
*
|
|
155
|
+
* Validates an Ethereum address.
|
|
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';
|
|
86
161
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @throws Will throw an error if the options fail validation
|
|
162
|
+
* // Valid address
|
|
163
|
+
* validateEthereumAddress("0x1234567890123456789012345678901234567890"); // OK
|
|
90
164
|
*
|
|
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
|
|
91
176
|
* @example
|
|
92
177
|
* ```ts
|
|
93
|
-
* import {
|
|
94
|
-
*
|
|
95
|
-
* const
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
178
|
+
* import { registerSchema, SchemaField } from '@settlemint/sdk-eas';
|
|
179
|
+
*
|
|
180
|
+
* const fields: SchemaField[] = [
|
|
181
|
+
* { name: "userAddress", type: "address" },
|
|
182
|
+
* { name: "age", type: "uint8" }
|
|
183
|
+
* ];
|
|
184
|
+
*
|
|
185
|
+
* const schemaUID = await registerSchema({
|
|
186
|
+
* fields,
|
|
187
|
+
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
188
|
+
* revocable: true
|
|
102
189
|
* });
|
|
190
|
+
*
|
|
191
|
+
* console.log(`Schema registered with UID: ${schemaUID}`);
|
|
103
192
|
* ```
|
|
104
193
|
*/
|
|
105
|
-
declare function
|
|
106
|
-
|
|
107
|
-
|
|
194
|
+
declare function registerSchema(options: RegisterSchemaOptions): Promise<string>;
|
|
195
|
+
|
|
196
|
+
declare function createEASClient(): {
|
|
197
|
+
submitAttestation(): void;
|
|
198
|
+
parseAttestation(): void;
|
|
199
|
+
createSchema(): void;
|
|
200
|
+
getSchema(): void;
|
|
201
|
+
getAttestations(): void;
|
|
108
202
|
};
|
|
109
203
|
|
|
110
|
-
export { type
|
|
204
|
+
export { type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField, buildSchemaString, createEASClient, registerSchema, validateEthereumAddress, validateFieldName, validateFieldType, validateSchemaFields };
|
package/dist/eas.d.ts
CHANGED
|
@@ -1,48 +1,16 @@
|
|
|
1
|
-
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
/**
|
|
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
1
|
/**
|
|
44
|
-
* Supported
|
|
45
|
-
* Maps
|
|
2
|
+
* Supported EAS schema field types.
|
|
3
|
+
* Maps user-friendly type names to EAS-compatible type strings.
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { EAS_FIELD_TYPES } from '@settlemint/sdk-eas';
|
|
7
|
+
*
|
|
8
|
+
* // Use in type definitions
|
|
9
|
+
* type MyFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
10
|
+
*
|
|
11
|
+
* // Check if a type is supported
|
|
12
|
+
* const isValidType = "string" in EAS_FIELD_TYPES;
|
|
13
|
+
* ```
|
|
46
14
|
*/
|
|
47
15
|
declare const EAS_FIELD_TYPES: {
|
|
48
16
|
readonly string: "string";
|
|
@@ -55,56 +23,182 @@ declare const EAS_FIELD_TYPES: {
|
|
|
55
23
|
readonly uint8: "uint8";
|
|
56
24
|
readonly int8: "int8";
|
|
57
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Type representing all valid EAS field types.
|
|
28
|
+
*/
|
|
58
29
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
59
30
|
/**
|
|
60
|
-
*
|
|
31
|
+
* Interface for defining a schema field.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { SchemaField } from '@settlemint/sdk-eas';
|
|
61
35
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
36
|
+
* const field: SchemaField = {
|
|
37
|
+
* name: "userAddress",
|
|
38
|
+
* type: "address",
|
|
39
|
+
* description: "The Ethereum address of the user"
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
65
42
|
*/
|
|
66
43
|
interface SchemaField {
|
|
44
|
+
/** The name of the field */
|
|
67
45
|
name: string;
|
|
46
|
+
/** The type of the field */
|
|
68
47
|
type: EASFieldType;
|
|
48
|
+
/** Optional description of the field */
|
|
69
49
|
description?: string;
|
|
70
50
|
}
|
|
71
51
|
/**
|
|
72
|
-
*
|
|
52
|
+
* Validates a schema field name.
|
|
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
|
+
* ];
|
|
73
98
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
99
|
+
* validateSchemaFields(fields); // OK
|
|
100
|
+
*
|
|
101
|
+
* // Invalid fields
|
|
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
|
+
* ```
|
|
77
145
|
*/
|
|
78
146
|
interface RegisterSchemaOptions {
|
|
147
|
+
/** The fields that make up the schema */
|
|
79
148
|
fields: SchemaField[];
|
|
149
|
+
/** The Ethereum address of the resolver */
|
|
80
150
|
resolverAddress: string;
|
|
151
|
+
/** Whether attestations using this schema can be revoked */
|
|
81
152
|
revocable: boolean;
|
|
82
153
|
}
|
|
83
|
-
|
|
84
154
|
/**
|
|
85
|
-
*
|
|
155
|
+
* Validates an Ethereum address.
|
|
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';
|
|
86
161
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @throws Will throw an error if the options fail validation
|
|
162
|
+
* // Valid address
|
|
163
|
+
* validateEthereumAddress("0x1234567890123456789012345678901234567890"); // OK
|
|
90
164
|
*
|
|
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
|
|
91
176
|
* @example
|
|
92
177
|
* ```ts
|
|
93
|
-
* import {
|
|
94
|
-
*
|
|
95
|
-
* const
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
178
|
+
* import { registerSchema, SchemaField } from '@settlemint/sdk-eas';
|
|
179
|
+
*
|
|
180
|
+
* const fields: SchemaField[] = [
|
|
181
|
+
* { name: "userAddress", type: "address" },
|
|
182
|
+
* { name: "age", type: "uint8" }
|
|
183
|
+
* ];
|
|
184
|
+
*
|
|
185
|
+
* const schemaUID = await registerSchema({
|
|
186
|
+
* fields,
|
|
187
|
+
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
188
|
+
* revocable: true
|
|
102
189
|
* });
|
|
190
|
+
*
|
|
191
|
+
* console.log(`Schema registered with UID: ${schemaUID}`);
|
|
103
192
|
* ```
|
|
104
193
|
*/
|
|
105
|
-
declare function
|
|
106
|
-
|
|
107
|
-
|
|
194
|
+
declare function registerSchema(options: RegisterSchemaOptions): Promise<string>;
|
|
195
|
+
|
|
196
|
+
declare function createEASClient(): {
|
|
197
|
+
submitAttestation(): void;
|
|
198
|
+
parseAttestation(): void;
|
|
199
|
+
createSchema(): void;
|
|
200
|
+
getSchema(): void;
|
|
201
|
+
getAttestations(): void;
|
|
108
202
|
};
|
|
109
203
|
|
|
110
|
-
export { type
|
|
204
|
+
export { type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField, buildSchemaString, createEASClient, registerSchema, validateEthereumAddress, validateFieldName, validateFieldType, validateSchemaFields };
|
package/dist/eas.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {isAddress}from'viem';var o={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function a(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 c(e){if(!(e in o))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(o).join(", ")}`)}function r(e){if(!e||e.length===0)throw new Error("Schema must have at least one field");let t=new Set;for(let n of e){if(a(n.name),c(n.type),t.has(n.name))throw new Error(`Duplicate field name: ${n.name}`);t.add(n.name);}}function l(e){return r(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function m(e){if(!e)throw new Error("Resolver address cannot be empty");if(!isAddress(e))throw new Error("Invalid Ethereum address format")}async function p(e){let{fields:t,resolverAddress:n,revocable:i}=e;r(t),m(n);let s=l(t);return console.log(`[EAS] Registering schema: ${s}`),console.log(`[EAS] Resolver: ${n}`),console.log(`[EAS] Revocable: ${i}`),`0x${"0".repeat(64)}`}function S(){return {submitAttestation(){console.log("[EAS] Submitting attestation");},parseAttestation(){console.log("[EAS] Parsing attestation");},createSchema(){console.log("[EAS] Creating schema");},getSchema(){console.log("[EAS] Getting schema");},getAttestations(){console.log("[EAS] Getting attestations");}}}export{o as EAS_FIELD_TYPES,l as buildSchemaString,S as createEASClient,p as registerSchema,m as validateEthereumAddress,a as validateFieldName,c as validateFieldType,r as validateSchemaFields};//# sourceMappingURL=eas.mjs.map
|
|
2
2
|
//# sourceMappingURL=eas.mjs.map
|
package/dist/eas.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CAAI,CAAC,CAC3B,CAAA,MAAA,CAAQG,SACV,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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eG,CAAAA,CAAeT,CAAiD,CAAA,CAC7EN,CAAqBM,CAAAA,CAAAA,CAAQ,MAAM,CAAA,CACnC,IAAMU,CAASZ,CAAAA,CAAAA,CAAkBE,CAAQ,CAAA,MAAM,CAE/C,CAAA,GAAI,CAEF,MAAMhB,EAAS,UAAW,EAAA,CAE1B,IAAM2B,CAAAA,CAAK,MAAMJ,CAAAA,CAAe,QAAS,CAAA,CACvC,OAAAG,CACA,CAAA,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.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 } 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"]}
|
|
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,GA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AAA,CAC7D,GAAI,CAACA,CACH,CAAA,MAAM,IAAI,KAAM,CAAA,kCAAkC,CAEpD,CAAA,GAAI,CAACC,SAAAA,CAAUD,CAAO,CAAA,CACpB,MAAM,IAAI,KAAM,CAAA,iCAAiC,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"]}
|
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.2-
|
|
4
|
+
"version": "2.2.2-main7ac23329",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -51,11 +51,8 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"
|
|
56
|
-
"@settlemint/sdk-viem": "2.2.2-main5d81cd7d",
|
|
57
|
-
"ethers": "^6",
|
|
58
|
-
"viem": "^2"
|
|
54
|
+
"@settlemint/sdk-utils": "2.2.2-main7ac23329",
|
|
55
|
+
"viem": "^2.7.9"
|
|
59
56
|
},
|
|
60
57
|
"peerDependencies": {},
|
|
61
58
|
"engines": {
|