@settlemint/sdk-eas 2.2.2-pr2dca8a07 → 2.2.2-pr40a5ad4c
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 +366 -0
- package/dist/eas.cjs +1 -1
- package/dist/eas.cjs.map +1 -1
- package/dist/eas.d.cts +39 -169
- package/dist/eas.d.ts +39 -169
- package/dist/eas.mjs +1 -1
- package/dist/eas.mjs.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -27,12 +27,378 @@
|
|
|
27
27
|
## Table of Contents
|
|
28
28
|
|
|
29
29
|
- [About](#about)
|
|
30
|
+
- [API Reference](#api-reference)
|
|
31
|
+
- [Functions](#functions)
|
|
32
|
+
- [buildSchemaString()](#buildschemastring)
|
|
33
|
+
- [registerSchema()](#registerschema)
|
|
34
|
+
- [validateEthereumAddress()](#validateethereumaddress)
|
|
35
|
+
- [validateFieldName()](#validatefieldname)
|
|
36
|
+
- [validateFieldType()](#validatefieldtype)
|
|
37
|
+
- [validateSchemaFields()](#validateschemafields)
|
|
38
|
+
- [Interfaces](#interfaces)
|
|
39
|
+
- [RegisterSchemaOptions](#registerschemaoptions)
|
|
40
|
+
- [SchemaField](#schemafield)
|
|
41
|
+
- [Type Aliases](#type-aliases)
|
|
42
|
+
- [EASFieldType](#easfieldtype)
|
|
43
|
+
- [Variables](#variables)
|
|
44
|
+
- [EAS\_FIELD\_TYPES](#eas_field_types)
|
|
30
45
|
- [Contributing](#contributing)
|
|
31
46
|
- [License](#license)
|
|
32
47
|
|
|
33
48
|
## About
|
|
34
49
|
|
|
35
50
|
The SettleMint EAS SDK provides a lightweight wrapper for the Ethereum Attestation Service (EAS), enabling developers to easily create, manage, and verify attestations within their applications. It simplifies the process of working with EAS by handling contract interactions, schema management, and The Graph integration, while ensuring proper integration with the SettleMint platform. This allows developers to quickly implement document verification, identity attestation, and other EAS-based features without manual setup.
|
|
51
|
+
|
|
52
|
+
## API Reference
|
|
53
|
+
|
|
54
|
+
### Functions
|
|
55
|
+
|
|
56
|
+
#### buildSchemaString()
|
|
57
|
+
|
|
58
|
+
> **buildSchemaString**(`fields`): `string`
|
|
59
|
+
|
|
60
|
+
Defined in: [schema.ts:166](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L166)
|
|
61
|
+
|
|
62
|
+
Builds an EAS schema string from an array of fields.
|
|
63
|
+
|
|
64
|
+
##### Parameters
|
|
65
|
+
|
|
66
|
+
| Parameter | Type | Description |
|
|
67
|
+
| ------ | ------ | ------ |
|
|
68
|
+
| `fields` | [`SchemaField`](#schemafield)[] | The fields to include in the schema |
|
|
69
|
+
|
|
70
|
+
##### Returns
|
|
71
|
+
|
|
72
|
+
`string`
|
|
73
|
+
|
|
74
|
+
The EAS-compatible schema string
|
|
75
|
+
|
|
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 |
|
|
108
|
+
| ------ | ------ | ------ |
|
|
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
|
|
116
|
+
|
|
117
|
+
##### Throws
|
|
118
|
+
|
|
119
|
+
Error if the schema registration fails
|
|
120
|
+
|
|
121
|
+
##### Example
|
|
122
|
+
|
|
123
|
+
```ts
|
|
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
|
|
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"
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Interfaces
|
|
297
|
+
|
|
298
|
+
#### RegisterSchemaOptions
|
|
299
|
+
|
|
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
|
|
320
|
+
|
|
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) |
|
|
326
|
+
|
|
327
|
+
***
|
|
328
|
+
|
|
329
|
+
#### SchemaField
|
|
330
|
+
|
|
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
|
|
348
|
+
|
|
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) |
|
|
354
|
+
|
|
355
|
+
### Type Aliases
|
|
356
|
+
|
|
357
|
+
#### EASFieldType
|
|
358
|
+
|
|
359
|
+
> **EASFieldType** = keyof *typeof* [`EAS_FIELD_TYPES`](#eas_field_types)
|
|
360
|
+
|
|
361
|
+
Defined in: [schema.ts:30](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L30)
|
|
362
|
+
|
|
363
|
+
Type representing all valid EAS field types.
|
|
364
|
+
|
|
365
|
+
### Variables
|
|
366
|
+
|
|
367
|
+
#### EAS\_FIELD\_TYPES
|
|
368
|
+
|
|
369
|
+
> `const` **EAS\_FIELD\_TYPES**: `object`
|
|
370
|
+
|
|
371
|
+
Defined in: [schema.ts:15](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L15)
|
|
372
|
+
|
|
373
|
+
Supported EAS schema field types.
|
|
374
|
+
Maps user-friendly type names to EAS-compatible type strings.
|
|
375
|
+
|
|
376
|
+
##### Type declaration
|
|
377
|
+
|
|
378
|
+
| Name | Type | Default value | Defined in |
|
|
379
|
+
| ------ | ------ | ------ | ------ |
|
|
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
|
+
```
|
|
401
|
+
|
|
36
402
|
## Contributing
|
|
37
403
|
|
|
38
404
|
We welcome contributions from the community! Please check out our [Contributing](https://github.com/settlemint/sdk/blob/main/.github/CONTRIBUTING.md) guide to learn how you can help improve the SettleMint SDK through bug reports, feature requests, documentation updates, or code contributions.
|
package/dist/eas.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var easSdk=require('@ethereum-attestation-service/eas-sdk'),validation=require('@settlemint/sdk-utils/validation'),ethers=require('ethers'),zod=require('zod');var d=zod.z.object({schemaRegistryAddress:zod.z.string().min(1),attestationAddress:zod.z.string().min(1),blockchainNode:zod.z.string().min(1)});var c={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function g(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 S(e){if(!(e in c))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(c).join(", ")}`)}function m(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(g(r.name),S(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function l(e){return m(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function $(e){validation.validate(d,e);let t=new ethers.JsonRpcProvider(e.blockchainNode),r=ethers.Wallet.createRandom().connect(t),s=new easSdk.SchemaRegistry(e.schemaRegistryAddress);s.connect(r);async function p(i){m(i.fields);let n=l(i.fields);try{await t.getNetwork();let o=await s.register({schema:n,resolverAddress:i.resolverAddress,revocable:i.revocable});return await o.wait(),o.toString()}catch(o){throw new Error(`Failed to register schema: ${o.message}`)}}async function h(i){try{return await t.getNetwork(),(await s.getSchema({uid:i})).toString()}catch(n){throw new Error(`Failed to get schema: ${n.message}`)}}return {registerSchema:p,getSchema:h}}exports.createEASClient=$;//# 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","registerSchema","options","resolverAddress","revocable","schemaString","createEASClient"],"mappings":"aAcO,IAAMA,CAAkB,CAAA,CAC7B,MAAQ,CAAA,QAAA,CACR,OAAS,CAAA,SAAA,CACT,IAAM,CAAA,MAAA,CACN,KAAO,CAAA,OAAA,CACP,OAAS,CAAA,SAAA,CACT,QAAS,SACT,CAAA,MAAA,CAAQ,QACR,CAAA,KAAA,CAAO,OACP,CAAA,IAAA,CAAM,MACR,EA8CO,SAASC,CAAAA,CAAkBC,CAAoB,CAAA,CACpD,GAAI,CAACA,CACH,CAAA,MAAM,IAAI,KAAM,CAAA,4BAA4B,CAE9C,CAAA,GAAIA,CAAK,CAAA,QAAA,CAAS,GAAG,CAAA,CACnB,MAAM,IAAI,KAAM,CAAA,kCAAkC,CAEpD,CAAA,GAAI,CAAC,0BAAA,CAA2B,KAAKA,CAAI,CAAA,CACvC,MAAM,IAAI,KACR,CAAA,4GACF,CAEJ,CAkBO,SAASC,CAAAA,CAAkBC,CAA4C,CAAA,CAC5E,GAAI,EAAEA,CAAQJ,IAAAA,CAAAA,CAAAA,CACZ,MAAM,IAAI,KAAA,CAAM,CAAuBI,oBAAAA,EAAAA,CAAI,CAAqB,kBAAA,EAAA,MAAA,CAAO,IAAKJ,CAAAA,CAAe,CAAE,CAAA,IAAA,CAAK,IAAI,CAAC,CAAE,CAAA,CAE7G,CAyBO,SAASK,EAAqBC,CAA6B,CAAA,CAChE,GAAI,CAACA,CAAUA,EAAAA,CAAAA,CAAO,MAAW,GAAA,CAAA,CAC/B,MAAM,IAAI,KAAM,CAAA,qCAAqC,CAGvD,CAAA,IAAMC,CAAY,CAAA,IAAI,IACtB,IAAWC,IAAAA,CAAAA,IAASF,CAAQ,CAAA,CAI1B,GAHAL,CAAAA,CAAkBO,CAAM,CAAA,IAAI,CAC5BL,CAAAA,CAAAA,CAAkBK,CAAM,CAAA,IAAI,CAExBD,CAAAA,CAAAA,CAAU,GAAIC,CAAAA,CAAAA,CAAM,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AkB,EAAA,CAChC,OAAO,CACL,mBAAoB,CAClB,OAAA,CAAQ,GAAI,CAAA,8BAA8B,EAC5C,CAAA,CAEA,gBAAmB,EAAA,CACjB,OAAQ,CAAA,GAAA,CAAI,2BAA2B,EACzC,CAEA,CAAA,YAAA,EAAe,CACb,OAAA,CAAQ,IAAI,uBAAuB,EACrC,CAEA,CAAA,SAAA,EAAY,CACV,OAAA,CAAQ,GAAI,CAAA,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\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 (!/^0x[a-fA-F0-9]{40}$/.test(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/types.ts","../src/validation.ts","../src/eas.ts"],"names":["ClientOptionsSchema","z","EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","createEASClient","options","validate","provider","Json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rB,CAAC,CAAA,CAED,aAAMU,CAAG,CAAA,IAAA,EACFA,CAAAA,CAAAA,CAAG,UACZ,CAAA,MAASC,CAAO,CAAA,CACd,MAAM,IAAI,KAAA,CAAM,8BAA+BA,CAAgB,CAAA,OAAO,EAAE,CAC1E,CACF,CAEA,eAAeC,EAAUC,CAA8B,CAAA,CACrD,GAAI,CAEF,aAAMX,CAAS,CAAA,UAAA,EAEA,CAAA,CAAA,MAAMI,EAAe,SAAU,CAAA,CAAE,IAAAO,CAAI,CAAC,GACvC,QAAS,EACzB,CAASF,MAAAA,CAAAA,CAAO,CACd,MAAM,IAAI,KAAM,CAAA,CAAA,sBAAA,EAA0BA,EAAgB,OAAO,CAAA,CAAE,CACrE,CACF,CAEA,OAAO,CACL,eAAAH,CACA,CAAA,SAAA,CAAAI,CACF,CACF","file":"eas.cjs","sourcesContent":["import { z } from \"zod\";\n\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().min(1),\n attestationAddress: z.string().min(1),\n blockchainNode: z.string().min(1),\n});\n\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n","export 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\nexport interface SchemaField {\n name: string;\n type: EASFieldType;\n description?: string;\n}\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 { JsonRpcProvider, Wallet } from \"ethers\";\nimport { type ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nimport type { RegisterSchemaOptions } from \"./types.js\";\nimport { buildSchemaString, validateSchemaFields } from \"./validation.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 * blockchainNode: \"http://localhost:8545\"\n * });\n *\n * // Register a schema\n * const schema = await client.registerSchema({\n * fields: [\n * { name: \"eventId\", type: \"uint256\" },\n * { name: \"voteIndex\", type: \"uint8\" }\n * ],\n * resolverAddress: \"0x0000000000000000000000000000000000000000\",\n * revocable: true\n * });\n * ```\n */\nexport function createEASClient(options: ClientOptions) {\n validate(ClientOptionsSchema, options);\n\n const provider = new JsonRpcProvider(options.blockchainNode);\n const wallet = Wallet.createRandom().connect(provider);\n const schemaRegistry = new SchemaRegistry(options.schemaRegistryAddress);\n\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}`);\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,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
4
|
+
schemaRegistryAddress: z.ZodString;
|
|
5
|
+
attestationAddress: z.ZodString;
|
|
6
|
+
blockchainNode: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
schemaRegistryAddress: string;
|
|
9
|
+
attestationAddress: string;
|
|
10
|
+
blockchainNode: string;
|
|
11
|
+
}, {
|
|
12
|
+
schemaRegistryAddress: string;
|
|
13
|
+
attestationAddress: string;
|
|
14
|
+
blockchainNode: string;
|
|
15
|
+
}>;
|
|
16
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
17
|
+
|
|
15
18
|
declare const EAS_FIELD_TYPES: {
|
|
16
19
|
readonly string: "string";
|
|
17
20
|
readonly address: "address";
|
|
@@ -23,182 +26,49 @@ declare const EAS_FIELD_TYPES: {
|
|
|
23
26
|
readonly uint8: "uint8";
|
|
24
27
|
readonly int8: "int8";
|
|
25
28
|
};
|
|
26
|
-
/**
|
|
27
|
-
* Type representing all valid EAS field types.
|
|
28
|
-
*/
|
|
29
29
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
30
|
-
/**
|
|
31
|
-
* Interface for defining a schema field.
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* import { SchemaField } from '@settlemint/sdk-eas';
|
|
35
|
-
*
|
|
36
|
-
* const field: SchemaField = {
|
|
37
|
-
* name: "userAddress",
|
|
38
|
-
* type: "address",
|
|
39
|
-
* description: "The Ethereum address of the user"
|
|
40
|
-
* };
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
30
|
interface SchemaField {
|
|
44
|
-
/** The name of the field */
|
|
45
31
|
name: string;
|
|
46
|
-
/** The type of the field */
|
|
47
32
|
type: EASFieldType;
|
|
48
|
-
/** Optional description of the field */
|
|
49
33
|
description?: string;
|
|
50
34
|
}
|
|
51
|
-
/**
|
|
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
|
-
* ];
|
|
98
|
-
*
|
|
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
|
-
* ```
|
|
145
|
-
*/
|
|
146
35
|
interface RegisterSchemaOptions {
|
|
147
|
-
/** The fields that make up the schema */
|
|
148
36
|
fields: SchemaField[];
|
|
149
|
-
/** The Ethereum address of the resolver */
|
|
150
37
|
resolverAddress: string;
|
|
151
|
-
/** Whether attestations using this schema can be revoked */
|
|
152
38
|
revocable: boolean;
|
|
153
39
|
}
|
|
40
|
+
|
|
154
41
|
/**
|
|
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';
|
|
42
|
+
* Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
161
43
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
44
|
+
* @param options - Configuration options for the client
|
|
45
|
+
* @returns An object containing the EAS client instance
|
|
46
|
+
* @throws Will throw an error if the options fail validation
|
|
164
47
|
*
|
|
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
48
|
* @example
|
|
177
49
|
* ```ts
|
|
178
|
-
* import {
|
|
50
|
+
* import { createEASClient } from '@settlemint/sdk-eas';
|
|
179
51
|
*
|
|
180
|
-
* const
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
52
|
+
* const client = createEASClient({
|
|
53
|
+
* schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
54
|
+
* attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
55
|
+
* blockchainNode: "http://localhost:8545"
|
|
56
|
+
* });
|
|
184
57
|
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
58
|
+
* // Register a schema
|
|
59
|
+
* const schema = await client.registerSchema({
|
|
60
|
+
* fields: [
|
|
61
|
+
* { name: "eventId", type: "uint256" },
|
|
62
|
+
* { name: "voteIndex", type: "uint8" }
|
|
63
|
+
* ],
|
|
64
|
+
* resolverAddress: "0x0000000000000000000000000000000000000000",
|
|
188
65
|
* revocable: true
|
|
189
66
|
* });
|
|
190
|
-
*
|
|
191
|
-
* console.log(`Schema registered with UID: ${schemaUID}`);
|
|
192
67
|
* ```
|
|
193
68
|
*/
|
|
194
|
-
declare function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
submitAttestation(): void;
|
|
198
|
-
parseAttestation(): void;
|
|
199
|
-
createSchema(): void;
|
|
200
|
-
getSchema(): void;
|
|
201
|
-
getAttestations(): void;
|
|
69
|
+
declare function createEASClient(options: ClientOptions): {
|
|
70
|
+
registerSchema: (options: RegisterSchemaOptions) => Promise<string>;
|
|
71
|
+
getSchema: (uid: string) => Promise<string>;
|
|
202
72
|
};
|
|
203
73
|
|
|
204
|
-
export {
|
|
74
|
+
export { createEASClient };
|
package/dist/eas.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
4
|
+
schemaRegistryAddress: z.ZodString;
|
|
5
|
+
attestationAddress: z.ZodString;
|
|
6
|
+
blockchainNode: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
schemaRegistryAddress: string;
|
|
9
|
+
attestationAddress: string;
|
|
10
|
+
blockchainNode: string;
|
|
11
|
+
}, {
|
|
12
|
+
schemaRegistryAddress: string;
|
|
13
|
+
attestationAddress: string;
|
|
14
|
+
blockchainNode: string;
|
|
15
|
+
}>;
|
|
16
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
17
|
+
|
|
15
18
|
declare const EAS_FIELD_TYPES: {
|
|
16
19
|
readonly string: "string";
|
|
17
20
|
readonly address: "address";
|
|
@@ -23,182 +26,49 @@ declare const EAS_FIELD_TYPES: {
|
|
|
23
26
|
readonly uint8: "uint8";
|
|
24
27
|
readonly int8: "int8";
|
|
25
28
|
};
|
|
26
|
-
/**
|
|
27
|
-
* Type representing all valid EAS field types.
|
|
28
|
-
*/
|
|
29
29
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
30
|
-
/**
|
|
31
|
-
* Interface for defining a schema field.
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* import { SchemaField } from '@settlemint/sdk-eas';
|
|
35
|
-
*
|
|
36
|
-
* const field: SchemaField = {
|
|
37
|
-
* name: "userAddress",
|
|
38
|
-
* type: "address",
|
|
39
|
-
* description: "The Ethereum address of the user"
|
|
40
|
-
* };
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
30
|
interface SchemaField {
|
|
44
|
-
/** The name of the field */
|
|
45
31
|
name: string;
|
|
46
|
-
/** The type of the field */
|
|
47
32
|
type: EASFieldType;
|
|
48
|
-
/** Optional description of the field */
|
|
49
33
|
description?: string;
|
|
50
34
|
}
|
|
51
|
-
/**
|
|
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
|
-
* ];
|
|
98
|
-
*
|
|
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
|
-
* ```
|
|
145
|
-
*/
|
|
146
35
|
interface RegisterSchemaOptions {
|
|
147
|
-
/** The fields that make up the schema */
|
|
148
36
|
fields: SchemaField[];
|
|
149
|
-
/** The Ethereum address of the resolver */
|
|
150
37
|
resolverAddress: string;
|
|
151
|
-
/** Whether attestations using this schema can be revoked */
|
|
152
38
|
revocable: boolean;
|
|
153
39
|
}
|
|
40
|
+
|
|
154
41
|
/**
|
|
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';
|
|
42
|
+
* Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
161
43
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
44
|
+
* @param options - Configuration options for the client
|
|
45
|
+
* @returns An object containing the EAS client instance
|
|
46
|
+
* @throws Will throw an error if the options fail validation
|
|
164
47
|
*
|
|
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
48
|
* @example
|
|
177
49
|
* ```ts
|
|
178
|
-
* import {
|
|
50
|
+
* import { createEASClient } from '@settlemint/sdk-eas';
|
|
179
51
|
*
|
|
180
|
-
* const
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
52
|
+
* const client = createEASClient({
|
|
53
|
+
* schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
54
|
+
* attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
55
|
+
* blockchainNode: "http://localhost:8545"
|
|
56
|
+
* });
|
|
184
57
|
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
58
|
+
* // Register a schema
|
|
59
|
+
* const schema = await client.registerSchema({
|
|
60
|
+
* fields: [
|
|
61
|
+
* { name: "eventId", type: "uint256" },
|
|
62
|
+
* { name: "voteIndex", type: "uint8" }
|
|
63
|
+
* ],
|
|
64
|
+
* resolverAddress: "0x0000000000000000000000000000000000000000",
|
|
188
65
|
* revocable: true
|
|
189
66
|
* });
|
|
190
|
-
*
|
|
191
|
-
* console.log(`Schema registered with UID: ${schemaUID}`);
|
|
192
67
|
* ```
|
|
193
68
|
*/
|
|
194
|
-
declare function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
submitAttestation(): void;
|
|
198
|
-
parseAttestation(): void;
|
|
199
|
-
createSchema(): void;
|
|
200
|
-
getSchema(): void;
|
|
201
|
-
getAttestations(): void;
|
|
69
|
+
declare function createEASClient(options: ClientOptions): {
|
|
70
|
+
registerSchema: (options: RegisterSchemaOptions) => Promise<string>;
|
|
71
|
+
getSchema: (uid: string) => Promise<string>;
|
|
202
72
|
};
|
|
203
73
|
|
|
204
|
-
export {
|
|
74
|
+
export { createEASClient };
|
package/dist/eas.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
import {SchemaRegistry}from'@ethereum-attestation-service/eas-sdk';import {validate}from'@settlemint/sdk-utils/validation';import {JsonRpcProvider,Wallet}from'ethers';import {z}from'zod';var d=z.object({schemaRegistryAddress:z.string().min(1),attestationAddress:z.string().min(1),blockchainNode:z.string().min(1)});var c={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function g(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 S(e){if(!(e in c))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(c).join(", ")}`)}function m(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(g(r.name),S(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function l(e){return m(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function $(e){validate(d,e);let t=new JsonRpcProvider(e.blockchainNode),r=Wallet.createRandom().connect(t),s=new SchemaRegistry(e.schemaRegistryAddress);s.connect(r);async function p(i){m(i.fields);let n=l(i.fields);try{await t.getNetwork();let o=await s.register({schema:n,resolverAddress:i.resolverAddress,revocable:i.revocable});return await o.wait(),o.toString()}catch(o){throw new Error(`Failed to register schema: ${o.message}`)}}async function h(i){try{return await t.getNetwork(),(await s.getSchema({uid:i})).toString()}catch(n){throw new Error(`Failed to get schema: ${n.message}`)}}return {registerSchema:p,getSchema:h}}export{$ 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","registerSchema","options","resolverAddress","revocable","schemaString","createEASClient"],"mappings":"AAcO,IAAMA,CAAkB,CAAA,CAC7B,MAAQ,CAAA,QAAA,CACR,OAAS,CAAA,SAAA,CACT,IAAM,CAAA,MAAA,CACN,KAAO,CAAA,OAAA,CACP,OAAS,CAAA,SAAA,CACT,QAAS,SACT,CAAA,MAAA,CAAQ,QACR,CAAA,KAAA,CAAO,OACP,CAAA,IAAA,CAAM,MACR,EA8CO,SAASC,CAAAA,CAAkBC,CAAoB,CAAA,CACpD,GAAI,CAACA,CACH,CAAA,MAAM,IAAI,KAAM,CAAA,4BAA4B,CAE9C,CAAA,GAAIA,CAAK,CAAA,QAAA,CAAS,GAAG,CAAA,CACnB,MAAM,IAAI,KAAM,CAAA,kCAAkC,CAEpD,CAAA,GAAI,CAAC,0BAAA,CAA2B,KAAKA,CAAI,CAAA,CACvC,MAAM,IAAI,KACR,CAAA,4GACF,CAEJ,CAkBO,SAASC,CAAAA,CAAkBC,CAA4C,CAAA,CAC5E,GAAI,EAAEA,CAAQJ,IAAAA,CAAAA,CAAAA,CACZ,MAAM,IAAI,KAAA,CAAM,CAAuBI,oBAAAA,EAAAA,CAAI,CAAqB,kBAAA,EAAA,MAAA,CAAO,IAAKJ,CAAAA,CAAe,CAAE,CAAA,IAAA,CAAK,IAAI,CAAC,CAAE,CAAA,CAE7G,CAyBO,SAASK,EAAqBC,CAA6B,CAAA,CAChE,GAAI,CAACA,CAAUA,EAAAA,CAAAA,CAAO,MAAW,GAAA,CAAA,CAC/B,MAAM,IAAI,KAAM,CAAA,qCAAqC,CAGvD,CAAA,IAAMC,CAAY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AA,CAAA,gBAAA,EAAmBF,CAAe,CAAA,CAAE,CAChD,CAAA,OAAA,CAAQ,IAAI,CAAoBC,iBAAAA,EAAAA,CAAS,CAAE,CAAA,CAAA,CAGpC,CAAK,EAAA,EAAA,GAAA,CAAI,MAAO,CAAA,EAAE,CAAC,CAAA,CAC5B,CCrQO,SAASE,CAAkB,EAAA,CAChC,OAAO,CACL,mBAAoB,CAClB,OAAA,CAAQ,GAAI,CAAA,8BAA8B,EAC5C,CAAA,CAEA,gBAAmB,EAAA,CACjB,OAAQ,CAAA,GAAA,CAAI,2BAA2B,EACzC,CAEA,CAAA,YAAA,EAAe,CACb,OAAA,CAAQ,IAAI,uBAAuB,EACrC,CAEA,CAAA,SAAA,EAAY,CACV,OAAA,CAAQ,GAAI,CAAA,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\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 (!/^0x[a-fA-F0-9]{40}$/.test(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/types.ts","../src/validation.ts","../src/eas.ts"],"names":["ClientOptionsSchema","z","EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","createEASClient","options","validate","provider","JsonRpcProvider","wallet","Wallet","schemaRegistry","SchemaRegistry","registerSchema","schema","tx","error","getSchema","uid"],"mappings":"2LAEO,IAAMA,CAAsBC,CAAAA,CAAAA,CAAE,OAAO,CAC1C,qBAAA,CAAuBA,CAAE,CAAA,MAAA,GAAS,GAAI,CAAA,CAAC,CACvC,CAAA,kBAAA,CAAoBA,EAAE,MAAO,EAAA,CAAE,IAAI,CAAC,CAAA,CACpC,eAAgBA,CAAE,CAAA,MAAA,EAAS,CAAA,GAAA,CAAI,CAAC,CAClC,CAAC,CCNM,CAAA,IAAMC,EAAkB,CAC7B,MAAA,CAAQ,QACR,CAAA,OAAA,CAAS,UACT,IAAM,CAAA,MAAA,CACN,KAAO,CAAA,OAAA,CACP,QAAS,SACT,CAAA,OAAA,CAAS,SACT,CAAA,MAAA,CAAQ,SACR,KAAO,CAAA,OAAA,CACP,IAAM,CAAA,MACR,ECRO,SAASC,CAAAA,CAAkBC,CAAoB,CAAA,CACpD,GAAI,CAACA,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,4BAA4B,CAE9C,CAAA,GAAIA,CAAK,CAAA,QAAA,CAAS,GAAG,CACnB,CAAA,MAAM,IAAI,KAAA,CAAM,kCAAkC,CAEpD,CAAA,GAAI,CAAC,0BAAA,CAA2B,KAAKA,CAAI,CAAA,CACvC,MAAM,IAAI,MACR,4GACF,CAEJ,CAEO,SAASC,EAAkBC,CAA4C,CAAA,CAC5E,GAAI,EAAEA,KAAQJ,CACZ,CAAA,CAAA,MAAM,IAAI,KAAA,CAAM,uBAAuBI,CAAI,CAAA,kBAAA,EAAqB,OAAO,IAAKJ,CAAAA,CAAe,EAAE,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,EAAQ,MAAM,CAAA,CAE/C,GAAI,CAEF,MAAME,CAAS,CAAA,UAAA,EAEf,CAAA,IAAMQ,EAAK,MAAMJ,CAAAA,CAAe,QAAS,CAAA,CACvC,OAAAG,CACA,CAAA,eAAA,CAAiBT,CAAQ,CAAA,eAAA,CACzB,UAAWA,CAAQ,CAAA,SACrB,CAAC,CAAA,CAED,aAAMU,CAAG,CAAA,IAAA,EACFA,CAAAA,CAAAA,CAAG,UACZ,CAAA,MAASC,CAAO,CAAA,CACd,MAAM,IAAI,KAAA,CAAM,8BAA+BA,CAAgB,CAAA,OAAO,EAAE,CAC1E,CACF,CAEA,eAAeC,EAAUC,CAA8B,CAAA,CACrD,GAAI,CAEF,aAAMX,CAAS,CAAA,UAAA,EAEA,CAAA,CAAA,MAAMI,EAAe,SAAU,CAAA,CAAE,IAAAO,CAAI,CAAC,GACvC,QAAS,EACzB,CAASF,MAAAA,CAAAA,CAAO,CACd,MAAM,IAAI,KAAM,CAAA,CAAA,sBAAA,EAA0BA,EAAgB,OAAO,CAAA,CAAE,CACrE,CACF,CAEA,OAAO,CACL,eAAAH,CACA,CAAA,SAAA,CAAAI,CACF,CACF","file":"eas.mjs","sourcesContent":["import { z } from \"zod\";\n\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().min(1),\n attestationAddress: z.string().min(1),\n blockchainNode: z.string().min(1),\n});\n\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n","export 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\nexport interface SchemaField {\n name: string;\n type: EASFieldType;\n description?: string;\n}\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 { JsonRpcProvider, Wallet } from \"ethers\";\nimport { type ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nimport type { RegisterSchemaOptions } from \"./types.js\";\nimport { buildSchemaString, validateSchemaFields } from \"./validation.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 * blockchainNode: \"http://localhost:8545\"\n * });\n *\n * // Register a schema\n * const schema = await client.registerSchema({\n * fields: [\n * { name: \"eventId\", type: \"uint256\" },\n * { name: \"voteIndex\", type: \"uint8\" }\n * ],\n * resolverAddress: \"0x0000000000000000000000000000000000000000\",\n * revocable: true\n * });\n * ```\n */\nexport function createEASClient(options: ClientOptions) {\n validate(ClientOptionsSchema, options);\n\n const provider = new JsonRpcProvider(options.blockchainNode);\n const wallet = Wallet.createRandom().connect(provider);\n const schemaRegistry = new SchemaRegistry(options.schemaRegistryAddress);\n\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}`);\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.2-
|
|
4
|
+
"version": "2.2.2-pr40a5ad4c",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@
|
|
54
|
+
"@ethereum-attestation-service/eas-sdk": "2.7.0",
|
|
55
|
+
"@settlemint/sdk-utils": "2.2.2-pr40a5ad4c",
|
|
55
56
|
"viem": "^2.7.9"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {},
|