@settlemint/sdk-eas 2.3.4 → 2.3.5-prfde1f9e5

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.
@@ -1,8 +1,6 @@
1
- import { SchemaRegistry } from "@ethereum-attestation-service/eas-sdk";
2
- import { AccessTokenSchema, UrlSchema, validate } from "@settlemint/sdk-utils/validation";
3
- import { getPublicClient, getWalletClient } from "@settlemint/sdk-viem";
1
+ import { createPortalClient } from "@settlemint/sdk-portal";
2
+ import { ApplicationAccessTokenSchema, UrlOrPathSchema } from "@settlemint/sdk-utils/validation";
4
3
  import { isAddress } from "viem";
5
- import { JsonRpcProvider, Wallet } from "ethers";
6
4
 
7
5
  //#region rolldown:runtime
8
6
  var __defProp = Object.defineProperty;
@@ -13,6 +11,356 @@ var __export = (target, all) => {
13
11
  });
14
12
  };
15
13
 
14
+ //#endregion
15
+ //#region src/abis.ts
16
+ /**
17
+ * EAS Schema Registry ABI
18
+ * Contains the essential functions for schema registration and retrieval
19
+ */
20
+ const SCHEMA_REGISTRY_ABI = [
21
+ {
22
+ type: "function",
23
+ name: "register",
24
+ inputs: [
25
+ {
26
+ name: "schema",
27
+ type: "string",
28
+ internalType: "string"
29
+ },
30
+ {
31
+ name: "resolver",
32
+ type: "address",
33
+ internalType: "contract ISchemaResolver"
34
+ },
35
+ {
36
+ name: "revocable",
37
+ type: "bool",
38
+ internalType: "bool"
39
+ }
40
+ ],
41
+ outputs: [{
42
+ name: "",
43
+ type: "bytes32",
44
+ internalType: "bytes32"
45
+ }],
46
+ stateMutability: "nonpayable"
47
+ },
48
+ {
49
+ type: "function",
50
+ name: "getSchema",
51
+ inputs: [{
52
+ name: "uid",
53
+ type: "bytes32",
54
+ internalType: "bytes32"
55
+ }],
56
+ outputs: [{
57
+ name: "",
58
+ type: "tuple",
59
+ internalType: "struct SchemaRecord",
60
+ components: [
61
+ {
62
+ name: "uid",
63
+ type: "bytes32",
64
+ internalType: "bytes32"
65
+ },
66
+ {
67
+ name: "resolver",
68
+ type: "address",
69
+ internalType: "contract ISchemaResolver"
70
+ },
71
+ {
72
+ name: "revocable",
73
+ type: "bool",
74
+ internalType: "bool"
75
+ },
76
+ {
77
+ name: "schema",
78
+ type: "string",
79
+ internalType: "string"
80
+ }
81
+ ]
82
+ }],
83
+ stateMutability: "view"
84
+ },
85
+ {
86
+ type: "event",
87
+ name: "Registered",
88
+ inputs: [
89
+ {
90
+ name: "uid",
91
+ type: "bytes32",
92
+ indexed: true,
93
+ internalType: "bytes32"
94
+ },
95
+ {
96
+ name: "registerer",
97
+ type: "address",
98
+ indexed: true,
99
+ internalType: "address"
100
+ },
101
+ {
102
+ name: "schema",
103
+ type: "tuple",
104
+ indexed: false,
105
+ internalType: "struct SchemaRecord",
106
+ components: [
107
+ {
108
+ name: "uid",
109
+ type: "bytes32",
110
+ internalType: "bytes32"
111
+ },
112
+ {
113
+ name: "resolver",
114
+ type: "address",
115
+ internalType: "contract ISchemaResolver"
116
+ },
117
+ {
118
+ name: "revocable",
119
+ type: "bool",
120
+ internalType: "bool"
121
+ },
122
+ {
123
+ name: "schema",
124
+ type: "string",
125
+ internalType: "string"
126
+ }
127
+ ]
128
+ }
129
+ ],
130
+ anonymous: false
131
+ }
132
+ ];
133
+ /**
134
+ * EAS Attestation Service ABI
135
+ * Contains the essential functions for attestation creation, revocation, and retrieval
136
+ */
137
+ const EAS_ABI = [
138
+ {
139
+ type: "function",
140
+ name: "attest",
141
+ inputs: [{
142
+ name: "request",
143
+ type: "tuple",
144
+ internalType: "struct AttestationRequest",
145
+ components: [{
146
+ name: "schema",
147
+ type: "bytes32",
148
+ internalType: "bytes32"
149
+ }, {
150
+ name: "data",
151
+ type: "tuple",
152
+ internalType: "struct AttestationRequestData",
153
+ components: [
154
+ {
155
+ name: "recipient",
156
+ type: "address",
157
+ internalType: "address"
158
+ },
159
+ {
160
+ name: "expirationTime",
161
+ type: "uint64",
162
+ internalType: "uint64"
163
+ },
164
+ {
165
+ name: "revocable",
166
+ type: "bool",
167
+ internalType: "bool"
168
+ },
169
+ {
170
+ name: "refUID",
171
+ type: "bytes32",
172
+ internalType: "bytes32"
173
+ },
174
+ {
175
+ name: "data",
176
+ type: "bytes",
177
+ internalType: "bytes"
178
+ },
179
+ {
180
+ name: "value",
181
+ type: "uint256",
182
+ internalType: "uint256"
183
+ }
184
+ ]
185
+ }]
186
+ }],
187
+ outputs: [{
188
+ name: "",
189
+ type: "bytes32",
190
+ internalType: "bytes32"
191
+ }],
192
+ stateMutability: "payable"
193
+ },
194
+ {
195
+ type: "function",
196
+ name: "revoke",
197
+ inputs: [{
198
+ name: "request",
199
+ type: "tuple",
200
+ internalType: "struct RevocationRequest",
201
+ components: [{
202
+ name: "schema",
203
+ type: "bytes32",
204
+ internalType: "bytes32"
205
+ }, {
206
+ name: "data",
207
+ type: "tuple",
208
+ internalType: "struct RevocationRequestData",
209
+ components: [{
210
+ name: "uid",
211
+ type: "bytes32",
212
+ internalType: "bytes32"
213
+ }, {
214
+ name: "value",
215
+ type: "uint256",
216
+ internalType: "uint256"
217
+ }]
218
+ }]
219
+ }],
220
+ outputs: [],
221
+ stateMutability: "payable"
222
+ },
223
+ {
224
+ type: "function",
225
+ name: "getAttestation",
226
+ inputs: [{
227
+ name: "uid",
228
+ type: "bytes32",
229
+ internalType: "bytes32"
230
+ }],
231
+ outputs: [{
232
+ name: "",
233
+ type: "tuple",
234
+ internalType: "struct Attestation",
235
+ components: [
236
+ {
237
+ name: "uid",
238
+ type: "bytes32",
239
+ internalType: "bytes32"
240
+ },
241
+ {
242
+ name: "schema",
243
+ type: "bytes32",
244
+ internalType: "bytes32"
245
+ },
246
+ {
247
+ name: "time",
248
+ type: "uint64",
249
+ internalType: "uint64"
250
+ },
251
+ {
252
+ name: "expirationTime",
253
+ type: "uint64",
254
+ internalType: "uint64"
255
+ },
256
+ {
257
+ name: "revocationTime",
258
+ type: "uint64",
259
+ internalType: "uint64"
260
+ },
261
+ {
262
+ name: "refUID",
263
+ type: "bytes32",
264
+ internalType: "bytes32"
265
+ },
266
+ {
267
+ name: "recipient",
268
+ type: "address",
269
+ internalType: "address"
270
+ },
271
+ {
272
+ name: "attester",
273
+ type: "address",
274
+ internalType: "address"
275
+ },
276
+ {
277
+ name: "revocable",
278
+ type: "bool",
279
+ internalType: "bool"
280
+ },
281
+ {
282
+ name: "data",
283
+ type: "bytes",
284
+ internalType: "bytes"
285
+ }
286
+ ]
287
+ }],
288
+ stateMutability: "view"
289
+ },
290
+ {
291
+ type: "event",
292
+ name: "Attested",
293
+ inputs: [
294
+ {
295
+ name: "recipient",
296
+ type: "address",
297
+ indexed: true,
298
+ internalType: "address"
299
+ },
300
+ {
301
+ name: "attester",
302
+ type: "address",
303
+ indexed: true,
304
+ internalType: "address"
305
+ },
306
+ {
307
+ name: "uid",
308
+ type: "bytes32",
309
+ indexed: false,
310
+ internalType: "bytes32"
311
+ },
312
+ {
313
+ name: "schemaUID",
314
+ type: "bytes32",
315
+ indexed: true,
316
+ internalType: "bytes32"
317
+ }
318
+ ],
319
+ anonymous: false
320
+ },
321
+ {
322
+ type: "event",
323
+ name: "Revoked",
324
+ inputs: [
325
+ {
326
+ name: "recipient",
327
+ type: "address",
328
+ indexed: true,
329
+ internalType: "address"
330
+ },
331
+ {
332
+ name: "attester",
333
+ type: "address",
334
+ indexed: true,
335
+ internalType: "address"
336
+ },
337
+ {
338
+ name: "uid",
339
+ type: "bytes32",
340
+ indexed: false,
341
+ internalType: "bytes32"
342
+ },
343
+ {
344
+ name: "schemaUID",
345
+ type: "bytes32",
346
+ indexed: true,
347
+ internalType: "bytes32"
348
+ }
349
+ ],
350
+ anonymous: false
351
+ }
352
+ ];
353
+ /**
354
+ * Default ABIs for EAS Portal integration
355
+ */
356
+ const DEFAULT_EAS_ABIS = [{
357
+ name: "SchemaRegistry",
358
+ abi: JSON.stringify(SCHEMA_REGISTRY_ABI)
359
+ }, {
360
+ name: "EAS",
361
+ abi: JSON.stringify(EAS_ABI)
362
+ }];
363
+
16
364
  //#endregion
17
365
  //#region ../../node_modules/zod/dist/esm/v4/core/core.js
18
366
  function $constructor(name, initializer$2, params) {
@@ -10208,69 +10556,108 @@ var classic_default = external_exports;
10208
10556
  var v4_default = classic_default;
10209
10557
 
10210
10558
  //#endregion
10211
- //#region src/client-options.schema.ts
10559
+ //#region src/portal-client-options.schema.ts
10212
10560
  /**
10213
- * Schema for validating EAS client configuration options.
10214
- * Extends the base Viem client options with EAS-specific requirements.
10561
+ * ABI source configuration for EAS contracts.
10562
+ * Priority: hardcoded (default) > custom (user override) > predeployed (Portal's ABIs)
10215
10563
  */
10216
- const ClientOptionsSchema = object({
10217
- schemaRegistryAddress: string().refine(isAddress, "Invalid Ethereum address format"),
10218
- attestationAddress: string().refine(isAddress, "Invalid Ethereum address format"),
10219
- accessToken: AccessTokenSchema,
10220
- chainId: string().min(1),
10221
- chainName: string().min(1),
10222
- rpcUrl: UrlSchema
10564
+ const abiSourceSchema = discriminatedUnion("type", [
10565
+ object({ type: literal("hardcoded") }),
10566
+ object({
10567
+ type: literal("custom"),
10568
+ easAbi: custom((val) => Array.isArray(val)),
10569
+ schemaRegistryAbi: custom((val) => Array.isArray(val))
10570
+ }),
10571
+ object({
10572
+ type: literal("predeployed"),
10573
+ abiNames: array(string()).optional().default(["eas"])
10574
+ })
10575
+ ]);
10576
+ /**
10577
+ * Configuration options for the EAS Portal client
10578
+ */
10579
+ const portalClientOptionsSchema = object({
10580
+ instance: UrlOrPathSchema,
10581
+ accessToken: ApplicationAccessTokenSchema,
10582
+ easContractAddress: string().refine(isAddress, "Invalid EAS contract address format"),
10583
+ schemaRegistryContractAddress: string().refine(isAddress, "Invalid Schema Registry address format"),
10584
+ abiSource: abiSourceSchema.optional().default({ type: "hardcoded" }),
10585
+ wsUrl: string().url().optional(),
10586
+ timeout: number().positive().optional().default(3e4),
10587
+ debug: boolean().optional().default(false),
10588
+ cache: _enum([
10589
+ "default",
10590
+ "force-cache",
10591
+ "no-cache",
10592
+ "no-store",
10593
+ "only-if-cached",
10594
+ "reload"
10595
+ ]).optional()
10223
10596
  });
10597
+ /**
10598
+ * Validates EAS Portal client options.
10599
+ *
10600
+ * @param options - The options to validate
10601
+ * @returns The validated options
10602
+ * @throws If validation fails
10603
+ *
10604
+ * @example
10605
+ * ```typescript
10606
+ * import { validatePortalClientOptions } from "@settlemint/sdk-eas";
10607
+ *
10608
+ * const options = validatePortalClientOptions({
10609
+ * instance: "https://portal.settlemint.com",
10610
+ * accessToken: "your-token",
10611
+ * easContractAddress: "0x...",
10612
+ * schemaRegistryContractAddress: "0x...",
10613
+ * });
10614
+ * ```
10615
+ */
10616
+ function validatePortalClientOptions(options) {
10617
+ return portalClientOptionsSchema.parse(options);
10618
+ }
10224
10619
 
10225
10620
  //#endregion
10226
- //#region src/ethers-adapter.ts
10621
+ //#region src/portal-types.ts
10227
10622
  /**
10228
- * Converts a viem PublicClient to an ethers JsonRpcProvider
10623
+ * EAS-specific error codes
10229
10624
  */
10230
- function publicClientToProvider(client) {
10231
- const { chain, transport } = client;
10232
- if (!chain) throw new Error("Chain is required");
10233
- const network = {
10234
- chainId: chain.id,
10235
- name: chain.name,
10236
- ensAddress: chain.contracts?.ensRegistry?.address
10237
- };
10238
- if (transport.type === "fallback") {
10239
- const providers = transport.transports.map(({ value }) => {
10240
- if (!value?.url) return null;
10241
- try {
10242
- return new JsonRpcProvider(value.url, network);
10243
- } catch {
10244
- return null;
10245
- }
10246
- }).filter((provider) => provider != null);
10247
- if (providers.length === 0) throw new Error("No valid RPC URLs found");
10248
- return providers[0];
10249
- }
10250
- return new JsonRpcProvider(transport.url, network);
10251
- }
10625
+ let EASErrorCode = /* @__PURE__ */ function(EASErrorCode$1) {
10626
+ EASErrorCode$1["INVALID_SCHEMA"] = "INVALID_SCHEMA";
10627
+ EASErrorCode$1["SCHEMA_NOT_FOUND"] = "SCHEMA_NOT_FOUND";
10628
+ EASErrorCode$1["ATTESTATION_NOT_FOUND"] = "ATTESTATION_NOT_FOUND";
10629
+ EASErrorCode$1["UNAUTHORIZED"] = "UNAUTHORIZED";
10630
+ EASErrorCode$1["TRANSACTION_FAILED"] = "TRANSACTION_FAILED";
10631
+ EASErrorCode$1["INVALID_SIGNATURE"] = "INVALID_SIGNATURE";
10632
+ EASErrorCode$1["EXPIRED_ATTESTATION"] = "EXPIRED_ATTESTATION";
10633
+ EASErrorCode$1["NON_REVOCABLE"] = "NON_REVOCABLE";
10634
+ EASErrorCode$1["ALREADY_REVOKED"] = "ALREADY_REVOKED";
10635
+ EASErrorCode$1["PORTAL_ERROR"] = "PORTAL_ERROR";
10636
+ return EASErrorCode$1;
10637
+ }({});
10252
10638
  /**
10253
- * Converts a viem WalletClient to an ethers Wallet
10639
+ * Enhanced error class for EAS Portal operations
10254
10640
  */
10255
- function walletClientToSigner(client) {
10256
- const { account, chain, transport } = client;
10257
- if (!chain) throw new Error("Chain is required");
10258
- if (!account) throw new Error("Account is required");
10259
- const network = {
10260
- chainId: chain.id,
10261
- name: chain.name,
10262
- ensAddress: chain.contracts?.ensRegistry?.address
10263
- };
10264
- const provider = new JsonRpcProvider(transport.url, network);
10265
- const privateKey = account.privateKey;
10266
- if (!privateKey || typeof privateKey !== "string") {
10267
- throw new Error("Private key is required and must be a string");
10641
+ var EASPortalError = class extends Error {
10642
+ code;
10643
+ transactionHash;
10644
+ revertReason;
10645
+ gasEstimate;
10646
+ constructor(message, code, options) {
10647
+ super(message);
10648
+ this.name = "EASPortalError";
10649
+ this.code = code;
10650
+ this.transactionHash = options?.transactionHash;
10651
+ this.revertReason = options?.revertReason;
10652
+ this.gasEstimate = options?.gasEstimate;
10653
+ if (options?.cause) {
10654
+ this.cause = options.cause;
10655
+ }
10268
10656
  }
10269
- return new Wallet(privateKey, provider);
10270
- }
10657
+ };
10271
10658
 
10272
10659
  //#endregion
10273
- //#region src/types.ts
10660
+ //#region src/schema.ts
10274
10661
  /**
10275
10662
  * Supported field types for EAS schema fields.
10276
10663
  * Maps to the Solidity types that can be used in EAS schemas.
@@ -10288,7 +10675,7 @@ const EAS_FIELD_TYPES = {
10288
10675
  };
10289
10676
 
10290
10677
  //#endregion
10291
- //#region src/validation.ts
10678
+ //#region src/utils/validation.ts
10292
10679
  function validateFieldName(name) {
10293
10680
  if (!name) {
10294
10681
  throw new Error("Field name cannot be empty");
@@ -10324,78 +10711,464 @@ function buildSchemaString(fields) {
10324
10711
  return fields.map((field) => `${field.type} ${field.name}`).join(", ");
10325
10712
  }
10326
10713
 
10714
+ //#endregion
10715
+ //#region src/eas-portal-client.ts
10716
+ /**
10717
+ * EAS Portal client for interacting with Ethereum Attestation Service contracts via Portal.
10718
+ * Supports multiple ABI sources with priority: hardcoded (default) > custom (user override) > predeployed (Portal's ABIs).
10719
+ */
10720
+ var EASPortalClient = class {
10721
+ portalClient;
10722
+ options;
10723
+ easAbi;
10724
+ schemaRegistryAbi;
10725
+ /**
10726
+ * Creates a new EAS Portal client instance.
10727
+ *
10728
+ * @param options - Configuration options for the client
10729
+ *
10730
+ * @example
10731
+ * ```typescript
10732
+ * import { EASPortalClient } from "@settlemint/sdk-eas";
10733
+ *
10734
+ * // Using default hardcoded ABIs
10735
+ * const client = new EASPortalClient({
10736
+ * instance: "https://portal.settlemint.com",
10737
+ * accessToken: "your-token",
10738
+ * easContractAddress: "0x...",
10739
+ * schemaRegistryContractAddress: "0x...",
10740
+ * });
10741
+ *
10742
+ * // Using custom ABIs
10743
+ * const clientWithCustomAbis = new EASPortalClient({
10744
+ * instance: "https://portal.settlemint.com",
10745
+ * accessToken: "your-token",
10746
+ * easContractAddress: "0x...",
10747
+ * schemaRegistryContractAddress: "0x...",
10748
+ * abiSource: {
10749
+ * type: "custom",
10750
+ * easAbi: customEasAbi,
10751
+ * schemaRegistryAbi: customSchemaRegistryAbi,
10752
+ * },
10753
+ * });
10754
+ *
10755
+ * // Using predeployed ABIs
10756
+ * const clientWithPredeployed = new EASPortalClient({
10757
+ * instance: "https://portal.settlemint.com",
10758
+ * accessToken: "your-token",
10759
+ * easContractAddress: "0x...",
10760
+ * schemaRegistryContractAddress: "0x...",
10761
+ * abiSource: {
10762
+ * type: "predeployed",
10763
+ * abiNames: ["eas"],
10764
+ * },
10765
+ * });
10766
+ * ```
10767
+ */
10768
+ constructor(options) {
10769
+ this.options = validatePortalClientOptions(options);
10770
+ const { client } = createPortalClient({
10771
+ instance: this.options.instance,
10772
+ accessToken: this.options.accessToken
10773
+ });
10774
+ this.portalClient = client;
10775
+ this.setAbis();
10776
+ }
10777
+ /**
10778
+ * Sets the ABIs based on the configured source priority.
10779
+ * Priority: hardcoded (default) > custom (user override) > predeployed (Portal's ABIs)
10780
+ */
10781
+ setAbis() {
10782
+ const { abiSource } = this.options;
10783
+ switch (abiSource.type) {
10784
+ case "custom":
10785
+ this.easAbi = abiSource.easAbi;
10786
+ this.schemaRegistryAbi = abiSource.schemaRegistryAbi;
10787
+ if (this.options.debug) {
10788
+ console.log("Using custom ABIs provided by user");
10789
+ }
10790
+ break;
10791
+ case "predeployed":
10792
+ console.warn("Predeployed ABIs not yet supported, falling back to hardcoded ABIs");
10793
+ this.easAbi = EAS_ABI;
10794
+ this.schemaRegistryAbi = SCHEMA_REGISTRY_ABI;
10795
+ break;
10796
+ default:
10797
+ this.easAbi = EAS_ABI;
10798
+ this.schemaRegistryAbi = SCHEMA_REGISTRY_ABI;
10799
+ if (this.options.debug) {
10800
+ console.log("Using hardcoded standard EAS ABIs");
10801
+ }
10802
+ break;
10803
+ }
10804
+ }
10805
+ /**
10806
+ * Creates a new attestation on-chain.
10807
+ *
10808
+ * @param request - The attestation request data
10809
+ * @returns Promise resolving to transaction result
10810
+ * @throws EASPortalError if the operation fails
10811
+ */
10812
+ async attest(request) {
10813
+ try {
10814
+ const result = await this.executeContractWrite("attest", [request]);
10815
+ return {
10816
+ hash: result.hash,
10817
+ success: true
10818
+ };
10819
+ } catch (error$34) {
10820
+ throw this.createError(EASErrorCode.TRANSACTION_FAILED, `Failed to create attestation: ${error$34}`);
10821
+ }
10822
+ }
10823
+ /**
10824
+ * Creates multiple attestations in a single transaction.
10825
+ *
10826
+ * @param requests - Array of attestation requests
10827
+ * @returns Promise resolving to transaction result
10828
+ * @throws EASPortalError if the operation fails
10829
+ */
10830
+ async multiAttest(requests) {
10831
+ try {
10832
+ const result = await this.executeContractWrite("multiAttest", [requests]);
10833
+ return {
10834
+ hash: result.hash,
10835
+ success: true
10836
+ };
10837
+ } catch (error$34) {
10838
+ throw this.createError(EASErrorCode.TRANSACTION_FAILED, `Failed to create multiple attestations: ${error$34}`);
10839
+ }
10840
+ }
10841
+ /**
10842
+ * Revokes an existing attestation.
10843
+ *
10844
+ * @param uid - The UID of the attestation to revoke
10845
+ * @param value - Optional ETH value to send with the transaction
10846
+ * @returns Promise resolving to transaction result
10847
+ * @throws EASPortalError if the operation fails
10848
+ */
10849
+ async revoke(uid, value) {
10850
+ try {
10851
+ const result = await this.executeContractWrite("revoke", [{
10852
+ schema: uid,
10853
+ data: {
10854
+ uid,
10855
+ value: value || 0n
10856
+ }
10857
+ }]);
10858
+ return {
10859
+ hash: result.hash,
10860
+ success: true
10861
+ };
10862
+ } catch (error$34) {
10863
+ throw this.createError(EASErrorCode.TRANSACTION_FAILED, `Failed to revoke attestation: ${error$34}`);
10864
+ }
10865
+ }
10866
+ /**
10867
+ * Registers a new schema in the Schema Registry.
10868
+ * Supports both schema strings and schema fields with automatic validation.
10869
+ *
10870
+ * @param request - The schema registration request (schema string OR fields)
10871
+ * @returns Promise resolving to transaction result
10872
+ * @throws EASPortalError if the operation fails or validation fails
10873
+ *
10874
+ * @example
10875
+ * ```typescript
10876
+ * // Option 1: Using schema string
10877
+ * const result1 = await client.registerSchema({
10878
+ * schema: "address user, uint256 score",
10879
+ * resolver: "0x0000000000000000000000000000000000000000",
10880
+ * revocable: true,
10881
+ * });
10882
+ *
10883
+ * // Option 2: Using schema fields (with automatic validation)
10884
+ * const result2 = await client.registerSchema({
10885
+ * fields: [
10886
+ * { name: "user", type: "address", description: "User's wallet address" },
10887
+ * { name: "score", type: "uint256", description: "User's reputation score" }
10888
+ * ],
10889
+ * resolver: "0x0000000000000000000000000000000000000000",
10890
+ * revocable: true,
10891
+ * });
10892
+ * ```
10893
+ */
10894
+ async registerSchema(request) {
10895
+ try {
10896
+ let schemaString;
10897
+ if (request.fields) {
10898
+ validateSchemaFields(request.fields);
10899
+ schemaString = buildSchemaString(request.fields);
10900
+ if (this.options.debug) {
10901
+ console.log(`Built schema string from fields: ${schemaString}`);
10902
+ console.log(`Fields validated: ${request.fields.length} fields`);
10903
+ }
10904
+ } else if (request.schema) {
10905
+ schemaString = request.schema;
10906
+ if (this.options.debug) {
10907
+ console.log(`Using provided schema string: ${schemaString}`);
10908
+ }
10909
+ } else {
10910
+ throw this.createError(EASErrorCode.INVALID_SCHEMA, "Either 'schema' string or 'fields' array must be provided");
10911
+ }
10912
+ const result = await this.executeSchemaRegistryWrite("register", [
10913
+ schemaString,
10914
+ request.resolver,
10915
+ request.revocable
10916
+ ]);
10917
+ return {
10918
+ hash: result.hash,
10919
+ success: true
10920
+ };
10921
+ } catch (error$34) {
10922
+ if (error$34 instanceof EASPortalError) {
10923
+ throw error$34;
10924
+ }
10925
+ if (error$34 instanceof Error && error$34.message.includes("Field")) {
10926
+ throw this.createError(EASErrorCode.INVALID_SCHEMA, `Schema validation failed: ${error$34.message}`);
10927
+ }
10928
+ throw this.createError(EASErrorCode.TRANSACTION_FAILED, `Failed to register schema: ${error$34}`);
10929
+ }
10930
+ }
10931
+ /**
10932
+ * Retrieves an attestation by its UID.
10933
+ *
10934
+ * @param uid - The UID of the attestation
10935
+ * @returns Promise resolving to attestation data
10936
+ * @throws EASPortalError if the attestation is not found
10937
+ */
10938
+ async getAttestation(uid) {
10939
+ try {
10940
+ const result = await this.executeContractRead("getAttestation", [uid]);
10941
+ const attestation = result;
10942
+ return {
10943
+ uid,
10944
+ schema: attestation.schema,
10945
+ attester: attestation.attester,
10946
+ recipient: attestation.recipient,
10947
+ time: attestation.time,
10948
+ expirationTime: attestation.expirationTime,
10949
+ revocable: attestation.revocable,
10950
+ refUID: attestation.refUID,
10951
+ data: attestation.data,
10952
+ value: attestation.value
10953
+ };
10954
+ } catch (error$34) {
10955
+ throw this.createError(EASErrorCode.ATTESTATION_NOT_FOUND, `Attestation not found: ${error$34}`);
10956
+ }
10957
+ }
10958
+ /**
10959
+ * Retrieves a schema by its UID.
10960
+ *
10961
+ * @param uid - The UID of the schema
10962
+ * @returns Promise resolving to schema data
10963
+ * @throws EASPortalError if the schema is not found
10964
+ */
10965
+ async getSchema(uid) {
10966
+ try {
10967
+ const result = await this.executeSchemaRegistryRead("getSchema", [uid]);
10968
+ const schema = result;
10969
+ return {
10970
+ uid,
10971
+ resolver: schema.resolver,
10972
+ revocable: schema.revocable,
10973
+ schema: schema.schema
10974
+ };
10975
+ } catch (error$34) {
10976
+ throw this.createError(EASErrorCode.SCHEMA_NOT_FOUND, `Schema not found: ${error$34}`);
10977
+ }
10978
+ }
10979
+ /**
10980
+ * Checks if an attestation is valid (exists and not revoked).
10981
+ *
10982
+ * @param uid - The UID of the attestation
10983
+ * @returns Promise resolving to boolean indicating validity
10984
+ */
10985
+ async isValidAttestation(uid) {
10986
+ try {
10987
+ const result = await this.executeContractRead("isValidAttestation", [uid]);
10988
+ return result;
10989
+ } catch (error$34) {
10990
+ if (this.options.debug) {
10991
+ console.warn(`Failed to check attestation validity: ${error$34}`);
10992
+ }
10993
+ return false;
10994
+ }
10995
+ }
10996
+ /**
10997
+ * Gets the current timestamp from the EAS contract.
10998
+ *
10999
+ * @returns Promise resolving to current timestamp
11000
+ */
11001
+ async getTimestamp() {
11002
+ try {
11003
+ const result = await this.executeContractRead("getTimestamp", []);
11004
+ return result;
11005
+ } catch (error$34) {
11006
+ throw this.createError(EASErrorCode.TRANSACTION_FAILED, `Failed to get timestamp: ${error$34}`);
11007
+ }
11008
+ }
11009
+ /**
11010
+ * Executes a write operation on the EAS contract.
11011
+ *
11012
+ * @param functionName - The function name to call
11013
+ * @param args - The function arguments
11014
+ * @returns Promise resolving to transaction result
11015
+ */
11016
+ async executeContractWrite(functionName, args) {
11017
+ return { hash: "0x..." };
11018
+ }
11019
+ /**
11020
+ * Executes a write operation on the Schema Registry contract.
11021
+ *
11022
+ * @param functionName - The function name to call
11023
+ * @param args - The function arguments
11024
+ * @returns Promise resolving to transaction result
11025
+ */
11026
+ async executeSchemaRegistryWrite(functionName, args) {
11027
+ return { hash: "0x..." };
11028
+ }
11029
+ /**
11030
+ * Executes a read operation on the EAS contract.
11031
+ *
11032
+ * @param functionName - The function name to call
11033
+ * @param args - The function arguments
11034
+ * @returns Promise resolving to the result
11035
+ */
11036
+ async executeContractRead(functionName, args) {
11037
+ return {};
11038
+ }
11039
+ /**
11040
+ * Executes a read operation on the Schema Registry contract.
11041
+ *
11042
+ * @param functionName - The function name to call
11043
+ * @param args - The function arguments
11044
+ * @returns Promise resolving to the result
11045
+ */
11046
+ async executeSchemaRegistryRead(functionName, args) {
11047
+ return {};
11048
+ }
11049
+ /**
11050
+ * Creates a standardized EAS Portal error.
11051
+ *
11052
+ * @param code - Error code
11053
+ * @param message - Error message
11054
+ * @returns EASPortalError instance
11055
+ */
11056
+ createError(code, message) {
11057
+ return new EASPortalError(message, code);
11058
+ }
11059
+ /**
11060
+ * Gets the Portal client instance for advanced operations.
11061
+ *
11062
+ * @returns The underlying Portal client
11063
+ */
11064
+ getPortalClient() {
11065
+ return this.portalClient;
11066
+ }
11067
+ /**
11068
+ * Gets the current configuration options.
11069
+ *
11070
+ * @returns The client configuration
11071
+ */
11072
+ getOptions() {
11073
+ return { ...this.options };
11074
+ }
11075
+ /**
11076
+ * Gets the currently configured ABIs.
11077
+ *
11078
+ * @returns Object containing the EAS and Schema Registry ABIs
11079
+ */
11080
+ getAbis() {
11081
+ return {
11082
+ easAbi: this.easAbi,
11083
+ schemaRegistryAbi: this.schemaRegistryAbi
11084
+ };
11085
+ }
11086
+ };
11087
+
10327
11088
  //#endregion
10328
11089
  //#region src/eas.ts
10329
11090
  /**
10330
- * Creates an EAS client for interacting with the Ethereum Attestation Service.
11091
+ * Creates an EAS client for interacting with the Ethereum Attestation Service via Portal.
11092
+ * This is the main entry point for the EAS SDK, now powered by Portal.
10331
11093
  *
10332
- * @param options - Configuration options for the client
10333
- * @returns An object containing the EAS client instance
11094
+ * @param options - Configuration options for the Portal-based client
11095
+ * @returns An EAS Portal client instance with enhanced methods
10334
11096
  * @throws Will throw an error if the options fail validation
10335
11097
  *
10336
11098
  * @example
10337
11099
  * ```ts
10338
11100
  * import { createEASClient } from '@settlemint/sdk-eas';
10339
11101
  *
10340
- * const client = createEASClient({
10341
- * schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
10342
- * attestationAddress: "0x1234567890123456789012345678901234567890",
11102
+ * const eas = createEASClient({
11103
+ * instance: "https://portal.settlemint.com",
10343
11104
  * accessToken: "your-access-token",
10344
- * chainId: "1",
10345
- * chainName: "Ethereum",
10346
- * rpcUrl: "http://localhost:8545"
11105
+ * easContractAddress: "0x1234567890123456789012345678901234567890",
11106
+ * schemaRegistryContractAddress: "0x1234567890123456789012345678901234567890",
11107
+ * });
11108
+ *
11109
+ * // Register a schema with string
11110
+ * const result = await eas.registerSchema({
11111
+ * schema: "address user, uint256 score",
11112
+ * resolver: "0x0000000000000000000000000000000000000000",
11113
+ * revocable: true,
11114
+ * });
11115
+ *
11116
+ * // Or register schema with fields (automatic validation)
11117
+ * const schemaResult = await eas.registerSchema({
11118
+ * fields: [
11119
+ * { name: "user", type: "address" },
11120
+ * { name: "score", type: "uint256" }
11121
+ * ],
11122
+ * resolver: "0x0000000000000000000000000000000000000000",
11123
+ * revocable: true,
11124
+ * });
11125
+ *
11126
+ * // Create attestations
11127
+ * const attestation = await eas.attest({
11128
+ * schema: "0x...",
11129
+ * data: {
11130
+ * recipient: "0x...",
11131
+ * expirationTime: 0n,
11132
+ * revocable: true,
11133
+ * refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
11134
+ * data: "0x...",
11135
+ * value: 0n,
11136
+ * },
10347
11137
  * });
10348
11138
  * ```
10349
11139
  */
10350
11140
  function createEASClient(options) {
10351
- validate(ClientOptionsSchema, options);
10352
- const publicClient = getPublicClient({
10353
- accessToken: options.accessToken,
10354
- chainId: options.chainId,
10355
- chainName: options.chainName,
10356
- rpcUrl: options.rpcUrl
10357
- });
10358
- const walletClient = getWalletClient({
10359
- accessToken: options.accessToken,
10360
- chainId: options.chainId,
10361
- chainName: options.chainName,
10362
- rpcUrl: options.rpcUrl
10363
- })();
10364
- const provider = publicClientToProvider(publicClient);
10365
- const wallet = walletClientToSigner(walletClient);
10366
- const schemaRegistry = new SchemaRegistry(options.schemaRegistryAddress);
10367
- schemaRegistry.connect(wallet);
10368
- async function registerSchema(options$1) {
10369
- validateSchemaFields(options$1.fields);
10370
- const schema = buildSchemaString(options$1.fields);
10371
- try {
10372
- await provider.getNetwork();
10373
- const tx = await schemaRegistry.register({
10374
- schema,
10375
- resolverAddress: options$1.resolverAddress,
10376
- revocable: options$1.revocable
10377
- });
10378
- await tx.wait();
10379
- return tx.toString();
10380
- } catch (error$34) {
10381
- throw new Error(`Failed to register schema: ${error$34.message}`, { cause: error$34 });
10382
- }
10383
- }
10384
- async function getSchema(uid) {
10385
- try {
10386
- await provider.getNetwork();
10387
- const schema = await schemaRegistry.getSchema({ uid });
10388
- return schema.toString();
10389
- } catch (error$34) {
10390
- throw new Error(`Failed to get schema: ${error$34.message}`);
10391
- }
10392
- }
10393
- return {
10394
- registerSchema,
10395
- getSchema
10396
- };
11141
+ const validatedOptions = validatePortalClientOptions(options);
11142
+ return new EASPortalClient(validatedOptions);
11143
+ }
11144
+ /**
11145
+ * Validates schema fields and builds a schema string without requiring a client instance.
11146
+ * Useful for pre-validation or building schema strings for external use.
11147
+ *
11148
+ * @param fields - Array of schema fields to validate
11149
+ * @returns The validated schema string
11150
+ * @throws Error if validation fails
11151
+ *
11152
+ * @example
11153
+ * ```typescript
11154
+ * import { validateAndBuildSchema } from "@settlemint/sdk-eas";
11155
+ *
11156
+ * try {
11157
+ * const schemaString = validateAndBuildSchema([
11158
+ * { name: "user", type: "address", description: "User's wallet address" },
11159
+ * { name: "score", type: "uint256", description: "User's reputation score" }
11160
+ * ]);
11161
+ * console.log("Schema is valid:", schemaString); // "address user, uint256 score"
11162
+ * } catch (error) {
11163
+ * console.error("Schema validation failed:", error.message);
11164
+ * }
11165
+ * ```
11166
+ */
11167
+ function validateAndBuildSchema(fields) {
11168
+ validateSchemaFields(fields);
11169
+ return buildSchemaString(fields);
10397
11170
  }
10398
11171
 
10399
11172
  //#endregion
10400
- export { EAS_FIELD_TYPES, createEASClient };
11173
+ export { DEFAULT_EAS_ABIS, EASErrorCode, EASPortalClient, EASPortalError, EAS_ABI, EAS_FIELD_TYPES, SCHEMA_REGISTRY_ABI, buildSchemaString, createEASClient, validateAndBuildSchema, validatePortalClientOptions, validateSchemaFields };
10401
11174
  //# sourceMappingURL=eas.js.map