@settlemint/sdk-eas 2.2.2-prd773eb0f → 2.2.2-prdc6e1d84
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 +389 -38
- package/dist/eas.cjs +2 -0
- package/dist/eas.cjs.map +1 -0
- package/dist/eas.d.cts +77 -0
- package/dist/eas.d.ts +77 -0
- package/dist/eas.mjs +2 -0
- package/dist/eas.mjs.map +1 -0
- package/package.json +13 -10
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -9
- package/dist/index.d.ts +0 -9
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,57 +1,408 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://github.com/settlemint/sdk/blob/main/logo.svg" width="200px" align="center" alt="SettleMint logo" />
|
|
3
|
+
<h1 align="center">SettleMint SDK</h1>
|
|
4
|
+
<p align="center">
|
|
5
|
+
✨ <a href="https://settlemint.com">https://settlemint.com</a> ✨
|
|
6
|
+
<br/>
|
|
7
|
+
Integrate SettleMint into your application with ease.
|
|
8
|
+
</p>
|
|
9
|
+
</p>
|
|
2
10
|
|
|
3
|
-
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://github.com/settlemint/sdk/actions?query=branch%3Amain"><img src="https://github.com/settlemint/sdk/actions/workflows/build.yml/badge.svg?event=push&branch=main" alt="CI status" /></a>
|
|
13
|
+
<a href="https://fsl.software" rel="nofollow"><img src="https://img.shields.io/npm/l/@settlemint/sdk-eas" alt="License"></a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/@settlemint/sdk-eas" rel="nofollow"><img src="https://img.shields.io/npm/dw/@settlemint/sdk-eas" alt="npm"></a>
|
|
15
|
+
<a href="https://github.com/settlemint/sdk" rel="nofollow"><img src="https://img.shields.io/github/stars/settlemint/sdk" alt="stars"></a>
|
|
16
|
+
</p>
|
|
4
17
|
|
|
5
|
-
|
|
18
|
+
<div align="center">
|
|
19
|
+
<a href="https://console.settlemint.com/documentation">Documentation</a>
|
|
20
|
+
<span> • </span>
|
|
21
|
+
<a href="https://www.npmjs.com/package/@settlemint/sdk-eas">NPM</a>
|
|
22
|
+
<span> • </span>
|
|
23
|
+
<a href="https://github.com/settlemint/sdk/issues">Issues</a>
|
|
24
|
+
<br />
|
|
25
|
+
</div>
|
|
6
26
|
|
|
7
|
-
|
|
8
|
-
- [ ] Graph query helpers
|
|
9
|
-
- [ ] Schema creation utils
|
|
27
|
+
## Table of Contents
|
|
10
28
|
|
|
11
|
-
|
|
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)
|
|
45
|
+
- [Contributing](#contributing)
|
|
46
|
+
- [License](#license)
|
|
12
47
|
|
|
13
|
-
|
|
14
|
-
|
|
48
|
+
## About
|
|
49
|
+
|
|
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"
|
|
15
93
|
```
|
|
16
94
|
|
|
17
|
-
|
|
95
|
+
***
|
|
18
96
|
|
|
19
|
-
|
|
20
|
-
import { createEASClient } from '@settlemint/sdk-eas';
|
|
21
|
-
import { getPublicClient, getWalletClient } from '@settlemint/sdk-viem';
|
|
97
|
+
#### registerSchema()
|
|
22
98
|
|
|
23
|
-
|
|
24
|
-
const walletClient = getWalletClient({ ... });
|
|
99
|
+
> **registerSchema**(`options`): `Promise`\<`string`\>
|
|
25
100
|
|
|
26
|
-
|
|
27
|
-
publicClient,
|
|
28
|
-
walletClient,
|
|
29
|
-
schemaRegistryAddress: '0x...',
|
|
30
|
-
attestationContractAddress: '0x...',
|
|
31
|
-
});
|
|
101
|
+
Defined in: [schema.ts:246](https://github.com/settlemint/sdk/blob/v2.2.2/sdk/eas/src/schema.ts#L246)
|
|
32
102
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
39
118
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
46
135
|
});
|
|
47
136
|
|
|
48
|
-
|
|
49
|
-
|
|
137
|
+
console.log(`Schema registered with UID: ${schemaUID}`);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
***
|
|
141
|
+
|
|
142
|
+
#### validateEthereumAddress()
|
|
143
|
+
|
|
144
|
+
> **validateEthereumAddress**(`address`): `void`
|
|
50
145
|
|
|
51
|
-
|
|
52
|
-
|
|
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"
|
|
53
175
|
```
|
|
54
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
|
+
|
|
402
|
+
## Contributing
|
|
403
|
+
|
|
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.
|
|
405
|
+
|
|
55
406
|
## License
|
|
56
407
|
|
|
57
|
-
FSL
|
|
408
|
+
The SettleMint SDK is released under the [FSL Software License](https://fsl.software). See the [LICENSE](https://github.com/settlemint/sdk/blob/main/LICENSE) file for more details.
|
package/dist/eas.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var easSdk=require('@ethereum-attestation-service/eas-sdk'),validation=require('@settlemint/sdk-utils/validation'),sdkViem=require('@settlemint/sdk-viem'),zod=require('zod'),ethers=require('ethers');var u=zod.z.object({schemaRegistryAddress:zod.z.string().min(1),attestationAddress:zod.z.string().min(1),...zod.z.object({accessToken:zod.z.string().min(1),chainId:zod.z.string().min(1),chainName:zod.z.string().min(1),rpcUrl:zod.z.string().min(1)}).shape});function f(e){let{chain:t,transport:r}=e;if(!t)throw new Error("Chain is required");let a={chainId:t.id,name:t.name,ensAddress:t.contracts?.ensRegistry?.address};if(r.type==="fallback"){let s=r.transports.map(({value:i})=>{if(!i?.url)return null;try{return new ethers.JsonRpcProvider(i.url,a)}catch{return null}}).filter(i=>i!=null);if(s.length===0)throw new Error("No valid RPC URLs found");return s[0]}return new ethers.JsonRpcProvider(r.url,a)}function g(e){let{account:t,chain:r,transport:a}=e;if(!r)throw new Error("Chain is required");if(!t)throw new Error("Account is required");let s={chainId:r.id,name:r.name,ensAddress:r.contracts?.ensRegistry?.address},i=new ethers.JsonRpcProvider(a.url,s),c=t.privateKey;if(!c||typeof c!="string")throw new Error("Private key is required and must be a string");return new ethers.Wallet(c,i)}var p={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function v(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 E(e){if(!(e in p))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(p).join(", ")}`)}function h(e){if(!e||e.length===0)throw new Error("Schema must have at least one field");let t=new Set;for(let r of e){if(v(r.name),E(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function y(e){return h(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function q(e){validation.validate(u,e);let t=sdkViem.getPublicClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl}),r=sdkViem.getWalletClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl})(),a=f(t),s=g(r),i=new easSdk.SchemaRegistry(e.schemaRegistryAddress);i.connect(s);async function c(o){h(o.fields);let l=y(o.fields);try{await a.getNetwork();let m=await i.register({schema:l,resolverAddress:o.resolverAddress,revocable:o.revocable});return await m.wait(),m.toString()}catch(m){throw new Error(`Failed to register schema: ${m.message}`)}}async function w(o){try{return await a.getNetwork(),(await i.getSchema({uid:o})).toString()}catch(l){throw new Error(`Failed to get schema: ${l.message}`)}}return {registerSchema:c,getSchema:w}}exports.createEASClient=q;//# sourceMappingURL=eas.cjs.map
|
|
2
|
+
//# sourceMappingURL=eas.cjs.map
|
package/dist/eas.cjs.map
ADDED
|
@@ -0,0 +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","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":"oNAGO,IAAMA,CAAAA,CAAsBC,KAAE,CAAA,MAAA,CAAO,CAC1C,qBAAuBA,CAAAA,KAAAA,CAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,CACvC,CAAA,kBAAA,CAAoBA,MAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,CACpC,CAAA,GAAGA,KAAE,CAAA,MAAA,CAAO,CACV,WAAaA,CAAAA,KAAAA,CAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,CAC7B,CAAA,OAAA,CAASA,MAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,CACzB,CAAA,SAAA,CAAWA,KAAE,CAAA,MAAA,GAAS,GAAI,CAAA,CAAC,CAC3B,CAAA,MAAA,CAAQA,KAAE,CAAA,MAAA,EAAS,CAAA,GAAA,CAAI,CAAC,CAC1B,CAAC,CAAE,CAAA,KACL,CAAC,CAAA,CCNM,SAASC,CAAAA,CAAuBC,CAAgC,CAAA,CACrE,GAAM,CAAE,KAAA,CAAAC,CAAO,CAAA,SAAA,CAAAC,CAAU,CAAA,CAAIF,CAC7B,CAAA,GAAI,CAACC,CAAO,CAAA,MAAM,IAAI,KAAA,CAAM,mBAAmB,CAAA,CAE/C,IAAME,CAAAA,CAAU,CACd,OAASF,CAAAA,CAAAA,CAAM,EACf,CAAA,IAAA,CAAMA,CAAM,CAAA,IAAA,CACZ,UAAYA,CAAAA,CAAAA,CAAM,WAAW,WA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Q,MAAM,CAAA,CACnC,IAAMU,CAAAA,CAASZ,CAAkBE,CAAAA,CAAAA,CAAQ,MAAM,CAAA,CAE/C,GAAI,CAEF,MAAMhB,CAAS,CAAA,UAAA,EAEf,CAAA,IAAM2B,CAAK,CAAA,MAAMJ,EAAe,QAAS,CAAA,CACvC,MAAAG,CAAAA,CAAAA,CACA,eAAiBV,CAAAA,CAAAA,CAAQ,eACzB,CAAA,SAAA,CAAWA,CAAQ,CAAA,SACrB,CAAC,CAAA,CAED,OAAMW,MAAAA,CAAAA,CAAG,IAAK,EAAA,CACPA,EAAG,QAAS,EACrB,CAASC,MAAAA,CAAAA,CAAO,CACd,MAAM,IAAI,KAAA,CAAM,8BAA+BA,CAAgB,CAAA,OAAO,CAAE,CAAA,CAC1E,CACF,CAEA,eAAeC,CAAAA,CAAUC,EAA8B,CACrD,GAAI,CAEF,OAAA,MAAM9B,CAAS,CAAA,UAAA,EAEA,CAAA,CAAA,MAAMuB,EAAe,SAAU,CAAA,CAAE,GAAAO,CAAAA,CAAI,CAAC,CAAA,EACvC,QAAS,EACzB,OAASF,CAAO,CAAA,CACd,MAAM,IAAI,KAAM,CAAA,CAAA,sBAAA,EAA0BA,CAAgB,CAAA,OAAO,EAAE,CACrE,CACF,CAEA,OAAO,CACL,cAAA,CAAAH,CACA,CAAA,SAAA,CAAAI,CACF,CACF","file":"eas.cjs","sourcesContent":["import type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { z } from \"zod\";\n\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().min(1),\n attestationAddress: z.string().min(1),\n ...z.object({\n accessToken: z.string().min(1),\n chainId: z.string().min(1),\n chainName: z.string().min(1),\n rpcUrl: z.string().min(1),\n }).shape,\n});\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","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 { 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/**\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}`);\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
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
5
|
+
accessToken: z.ZodString;
|
|
6
|
+
chainId: z.ZodString;
|
|
7
|
+
chainName: z.ZodString;
|
|
8
|
+
rpcUrl: z.ZodString;
|
|
9
|
+
schemaRegistryAddress: z.ZodString;
|
|
10
|
+
attestationAddress: z.ZodString;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
schemaRegistryAddress: string;
|
|
13
|
+
attestationAddress: string;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
chainId: string;
|
|
16
|
+
chainName: string;
|
|
17
|
+
rpcUrl: string;
|
|
18
|
+
}, {
|
|
19
|
+
schemaRegistryAddress: string;
|
|
20
|
+
attestationAddress: string;
|
|
21
|
+
accessToken: string;
|
|
22
|
+
chainId: string;
|
|
23
|
+
chainName: string;
|
|
24
|
+
rpcUrl: string;
|
|
25
|
+
}>;
|
|
26
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema> & Pick<ClientOptions$1, "accessToken" | "chainId" | "chainName" | "rpcUrl">;
|
|
27
|
+
|
|
28
|
+
declare const EAS_FIELD_TYPES: {
|
|
29
|
+
readonly string: "string";
|
|
30
|
+
readonly address: "address";
|
|
31
|
+
readonly bool: "bool";
|
|
32
|
+
readonly bytes: "bytes";
|
|
33
|
+
readonly bytes32: "bytes32";
|
|
34
|
+
readonly uint256: "uint256";
|
|
35
|
+
readonly int256: "int256";
|
|
36
|
+
readonly uint8: "uint8";
|
|
37
|
+
readonly int8: "int8";
|
|
38
|
+
};
|
|
39
|
+
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
40
|
+
interface SchemaField {
|
|
41
|
+
name: string;
|
|
42
|
+
type: EASFieldType;
|
|
43
|
+
description?: string;
|
|
44
|
+
}
|
|
45
|
+
interface RegisterSchemaOptions {
|
|
46
|
+
fields: SchemaField[];
|
|
47
|
+
resolverAddress: string;
|
|
48
|
+
revocable: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Configuration options for the client
|
|
55
|
+
* @returns An object containing the EAS client instance
|
|
56
|
+
* @throws Will throw an error if the options fail validation
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { createEASClient } from '@settlemint/sdk-eas';
|
|
61
|
+
*
|
|
62
|
+
* const client = createEASClient({
|
|
63
|
+
* schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
64
|
+
* attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
65
|
+
* accessToken: "your-access-token",
|
|
66
|
+
* chainId: "1",
|
|
67
|
+
* chainName: "Ethereum",
|
|
68
|
+
* rpcUrl: "http://localhost:8545"
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function createEASClient(options: ClientOptions): {
|
|
73
|
+
registerSchema: (options: RegisterSchemaOptions) => Promise<string>;
|
|
74
|
+
getSchema: (uid: string) => Promise<string>;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { createEASClient };
|
package/dist/eas.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
5
|
+
accessToken: z.ZodString;
|
|
6
|
+
chainId: z.ZodString;
|
|
7
|
+
chainName: z.ZodString;
|
|
8
|
+
rpcUrl: z.ZodString;
|
|
9
|
+
schemaRegistryAddress: z.ZodString;
|
|
10
|
+
attestationAddress: z.ZodString;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
schemaRegistryAddress: string;
|
|
13
|
+
attestationAddress: string;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
chainId: string;
|
|
16
|
+
chainName: string;
|
|
17
|
+
rpcUrl: string;
|
|
18
|
+
}, {
|
|
19
|
+
schemaRegistryAddress: string;
|
|
20
|
+
attestationAddress: string;
|
|
21
|
+
accessToken: string;
|
|
22
|
+
chainId: string;
|
|
23
|
+
chainName: string;
|
|
24
|
+
rpcUrl: string;
|
|
25
|
+
}>;
|
|
26
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema> & Pick<ClientOptions$1, "accessToken" | "chainId" | "chainName" | "rpcUrl">;
|
|
27
|
+
|
|
28
|
+
declare const EAS_FIELD_TYPES: {
|
|
29
|
+
readonly string: "string";
|
|
30
|
+
readonly address: "address";
|
|
31
|
+
readonly bool: "bool";
|
|
32
|
+
readonly bytes: "bytes";
|
|
33
|
+
readonly bytes32: "bytes32";
|
|
34
|
+
readonly uint256: "uint256";
|
|
35
|
+
readonly int256: "int256";
|
|
36
|
+
readonly uint8: "uint8";
|
|
37
|
+
readonly int8: "int8";
|
|
38
|
+
};
|
|
39
|
+
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
40
|
+
interface SchemaField {
|
|
41
|
+
name: string;
|
|
42
|
+
type: EASFieldType;
|
|
43
|
+
description?: string;
|
|
44
|
+
}
|
|
45
|
+
interface RegisterSchemaOptions {
|
|
46
|
+
fields: SchemaField[];
|
|
47
|
+
resolverAddress: string;
|
|
48
|
+
revocable: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Configuration options for the client
|
|
55
|
+
* @returns An object containing the EAS client instance
|
|
56
|
+
* @throws Will throw an error if the options fail validation
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { createEASClient } from '@settlemint/sdk-eas';
|
|
61
|
+
*
|
|
62
|
+
* const client = createEASClient({
|
|
63
|
+
* schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
64
|
+
* attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
65
|
+
* accessToken: "your-access-token",
|
|
66
|
+
* chainId: "1",
|
|
67
|
+
* chainName: "Ethereum",
|
|
68
|
+
* rpcUrl: "http://localhost:8545"
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function createEASClient(options: ClientOptions): {
|
|
73
|
+
registerSchema: (options: RegisterSchemaOptions) => Promise<string>;
|
|
74
|
+
getSchema: (uid: string) => Promise<string>;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { createEASClient };
|
package/dist/eas.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {SchemaRegistry}from'@ethereum-attestation-service/eas-sdk';import {validate}from'@settlemint/sdk-utils/validation';import {getPublicClient,getWalletClient}from'@settlemint/sdk-viem';import {z}from'zod';import {JsonRpcProvider,Wallet}from'ethers';var u=z.object({schemaRegistryAddress:z.string().min(1),attestationAddress:z.string().min(1),...z.object({accessToken:z.string().min(1),chainId:z.string().min(1),chainName:z.string().min(1),rpcUrl:z.string().min(1)}).shape});function f(e){let{chain:t,transport:r}=e;if(!t)throw new Error("Chain is required");let a={chainId:t.id,name:t.name,ensAddress:t.contracts?.ensRegistry?.address};if(r.type==="fallback"){let s=r.transports.map(({value:i})=>{if(!i?.url)return null;try{return new JsonRpcProvider(i.url,a)}catch{return null}}).filter(i=>i!=null);if(s.length===0)throw new Error("No valid RPC URLs found");return s[0]}return new JsonRpcProvider(r.url,a)}function g(e){let{account:t,chain:r,transport:a}=e;if(!r)throw new Error("Chain is required");if(!t)throw new Error("Account is required");let s={chainId:r.id,name:r.name,ensAddress:r.contracts?.ensRegistry?.address},i=new JsonRpcProvider(a.url,s),c=t.privateKey;if(!c||typeof c!="string")throw new Error("Private key is required and must be a string");return new Wallet(c,i)}var p={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function v(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 E(e){if(!(e in p))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(p).join(", ")}`)}function h(e){if(!e||e.length===0)throw new Error("Schema must have at least one field");let t=new Set;for(let r of e){if(v(r.name),E(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function y(e){return h(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function q(e){validate(u,e);let t=getPublicClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl}),r=getWalletClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl})(),a=f(t),s=g(r),i=new SchemaRegistry(e.schemaRegistryAddress);i.connect(s);async function c(o){h(o.fields);let l=y(o.fields);try{await a.getNetwork();let m=await i.register({schema:l,resolverAddress:o.resolverAddress,revocable:o.revocable});return await m.wait(),m.toString()}catch(m){throw new Error(`Failed to register schema: ${m.message}`)}}async function w(o){try{return await a.getNetwork(),(await i.getSchema({uid:o})).toString()}catch(l){throw new Error(`Failed to get schema: ${l.message}`)}}return {registerSchema:c,getSchema:w}}export{q as createEASClient};//# sourceMappingURL=eas.mjs.map
|
|
2
|
+
//# sourceMappingURL=eas.mjs.map
|
package/dist/eas.mjs.map
ADDED
|
@@ -0,0 +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","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":"8PAGO,IAAMA,CAAAA,CAAsBC,CAAE,CAAA,MAAA,CA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A,CAAO,CACd,MAAM,IAAI,KAAA,CAAM,8BAA+BA,CAAgB,CAAA,OAAO,CAAE,CAAA,CAC1E,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 type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { z } from \"zod\";\n\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().min(1),\n attestationAddress: z.string().min(1),\n ...z.object({\n accessToken: z.string().min(1),\n chainId: z.string().min(1),\n chainName: z.string().min(1),\n rpcUrl: z.string().min(1),\n }).shape,\n});\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","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 { 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/**\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}`);\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-prdc6e1d84",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
"email": "support@settlemint.com"
|
|
22
22
|
},
|
|
23
23
|
"files": ["dist"],
|
|
24
|
-
"main": "./dist/
|
|
25
|
-
"module": "./dist/
|
|
26
|
-
"types": "./dist/
|
|
24
|
+
"main": "./dist/eas.cjs",
|
|
25
|
+
"module": "./dist/eas.mjs",
|
|
26
|
+
"types": "./dist/eas.d.ts",
|
|
27
27
|
"exports": {
|
|
28
28
|
"./package.json": "./package.json",
|
|
29
29
|
".": {
|
|
30
30
|
"import": {
|
|
31
|
-
"types": "./dist/
|
|
32
|
-
"default": "./dist/
|
|
31
|
+
"types": "./dist/eas.d.ts",
|
|
32
|
+
"default": "./dist/eas.mjs"
|
|
33
33
|
},
|
|
34
34
|
"require": {
|
|
35
|
-
"types": "./dist/
|
|
36
|
-
"default": "./dist/
|
|
35
|
+
"types": "./dist/eas.d.cts",
|
|
36
|
+
"default": "./dist/eas.cjs"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
},
|
|
@@ -47,11 +47,14 @@
|
|
|
47
47
|
"typecheck": "tsc --noEmit",
|
|
48
48
|
"publish-npm": "bun publish --tag ${TAG} --access public || exit 0",
|
|
49
49
|
"prepack": "cp ../../LICENSE .",
|
|
50
|
-
"docs": "typedoc --options '../../typedoc.config.mjs' --entryPoints src/
|
|
50
|
+
"docs": "typedoc --options '../../typedoc.config.mjs' --entryPoints src/eas.ts --out ./docs"
|
|
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-prdc6e1d84",
|
|
56
|
+
"@settlemint/sdk-viem": "2.2.2-prdc6e1d84",
|
|
57
|
+
"ethers": "^6.11.1",
|
|
55
58
|
"viem": "^2.7.9"
|
|
56
59
|
},
|
|
57
60
|
"peerDependencies": {},
|
package/dist/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';function t(){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.createEASClient=t;//# sourceMappingURL=index.cjs.map
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["createEASClient"],"mappings":"aAAO,SAASA,GAAkB,CAChC,OAAO,CACL,iBAAA,EAAoB,CAClB,OAAQ,CAAA,GAAA,CAAI,8BAA8B,EAC5C,EAEA,gBAAmB,EAAA,CACjB,QAAQ,GAAI,CAAA,2BAA2B,EACzC,CAEA,CAAA,YAAA,EAAe,CACb,OAAA,CAAQ,IAAI,uBAAuB,EACrC,EAEA,SAAY,EAAA,CACV,QAAQ,GAAI,CAAA,sBAAsB,EACpC,CAAA,CAEA,iBAAkB,CAChB,OAAA,CAAQ,IAAI,4BAA4B,EAC1C,CACF,CACF","file":"index.cjs","sourcesContent":["export 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/index.d.cts
DELETED
package/dist/index.d.ts
DELETED
package/dist/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function t(){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{t as createEASClient};//# sourceMappingURL=index.mjs.map
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["createEASClient"],"mappings":"AAAO,SAASA,GAAkB,CAChC,OAAO,CACL,iBAAA,EAAoB,CAClB,OAAQ,CAAA,GAAA,CAAI,8BAA8B,EAC5C,EAEA,gBAAmB,EAAA,CACjB,QAAQ,GAAI,CAAA,2BAA2B,EACzC,CAEA,CAAA,YAAA,EAAe,CACb,OAAA,CAAQ,IAAI,uBAAuB,EACrC,EAEA,SAAY,EAAA,CACV,QAAQ,GAAI,CAAA,sBAAsB,EACpC,CAAA,CAEA,iBAAkB,CAChB,OAAA,CAAQ,IAAI,4BAA4B,EAC1C,CACF,CACF","file":"index.mjs","sourcesContent":["export 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"]}
|