@settlemint/sdk-eas 2.3.14-pr77cf5949 → 2.3.14-pr84e01ac3

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/dist/eas.cjs CHANGED
@@ -27,84 +27,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  }) : target, mod));
28
28
 
29
29
  //#endregion
30
- const __settlemint_sdk_portal = __toESM(require("@settlemint/sdk-portal"));
31
- const __settlemint_sdk_utils_logging = __toESM(require("@settlemint/sdk-utils/logging"));
30
+ const __ethereum_attestation_service_eas_sdk = __toESM(require("@ethereum-attestation-service/eas-sdk"));
32
31
  const __settlemint_sdk_utils_validation = __toESM(require("@settlemint/sdk-utils/validation"));
32
+ const __settlemint_sdk_viem = __toESM(require("@settlemint/sdk-viem"));
33
33
  const viem = __toESM(require("viem"));
34
+ const ethers = __toESM(require("ethers"));
34
35
 
35
- //#region src/portal/operations.ts
36
- const GraphQLOperations = { mutations: {
37
- deploySchemaRegistry: (graphql) => graphql(`
38
- mutation DeployContractEASSchemaRegistry(
39
- $from: String!
40
- $constructorArguments: DeployContractEASSchemaRegistryInput!
41
- $gasLimit: String!
42
- ) {
43
- DeployContractEASSchemaRegistry(from: $from, constructorArguments: $constructorArguments, gasLimit: $gasLimit) {
44
- transactionHash
45
- }
46
- }`),
47
- deployEAS: (graphql) => graphql(`
48
- mutation DeployContractEAS($from: String!, $constructorArguments: DeployContractEASInput!, $gasLimit: String!) {
49
- DeployContractEAS(from: $from, constructorArguments: $constructorArguments, gasLimit: $gasLimit) {
50
- transactionHash
51
- }
52
- }`),
53
- registerSchema: (graphql) => graphql(`
54
- mutation EASSchemaRegistryRegister(
55
- $address: String!
56
- $from: String!
57
- $input: EASSchemaRegistryRegisterInput!
58
- $gasLimit: String!
59
- ) {
60
- EASSchemaRegistryRegister(address: $address, from: $from, input: $input, gasLimit: $gasLimit) {
61
- transactionHash
62
- }
63
- }`),
64
- attest: (graphql) => graphql(`
65
- mutation EASAttest($address: String!, $from: String!, $input: EASAttestInput!, $gasLimit: String!) {
66
- EASAttest(address: $address, from: $from, input: $input, gasLimit: $gasLimit) {
67
- transactionHash
68
- }
69
- }`),
70
- multiAttest: (graphql) => graphql(`
71
- mutation EASMultiAttest($address: String!, $from: String!, $input: EASMultiAttestInput!, $gasLimit: String!) {
72
- EASMultiAttest(address: $address, from: $from, input: $input, gasLimit: $gasLimit) {
73
- transactionHash
74
- }
75
- }`),
76
- revoke: (graphql) => graphql(`
77
- mutation EASRevoke($address: String!, $from: String!, $input: EASRevokeInput!, $gasLimit: String!) {
78
- EASRevoke(address: $address, from: $from, input: $input, gasLimit: $gasLimit) {
79
- transactionHash
80
- }
81
- }`)
82
- } };
83
-
84
- //#endregion
85
- //#region src/schema.ts
86
- /**
87
- * Common address constants
88
- */
89
- const ZERO_ADDRESS = viem.zeroAddress;
90
- const ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
91
- /**
92
- * Supported field types for EAS schema fields.
93
- * Maps to the Solidity types that can be used in EAS schemas.
94
- */
95
- const EAS_FIELD_TYPES = {
96
- string: "string",
97
- address: "address",
98
- bool: "bool",
99
- bytes: "bytes",
100
- bytes32: "bytes32",
101
- uint256: "uint256",
102
- int256: "int256",
103
- uint8: "uint8",
104
- int8: "int8"
105
- };
106
-
107
- //#endregion
108
36
  //#region ../../node_modules/zod/dist/esm/v4/core/core.js
109
37
  function $constructor(name, initializer$2, params) {
110
38
  function init(inst, def) {
@@ -10869,530 +10797,195 @@ var classic_default = external_exports;
10869
10797
  var v4_default = classic_default;
10870
10798
 
10871
10799
  //#endregion
10872
- //#region src/utils/validation.ts
10873
- const ethAddressSchema = custom((val) => typeof val === "string" && (0, viem.isAddress)(val), "Invalid Ethereum address");
10800
+ //#region src/client-options.schema.ts
10874
10801
  /**
10875
- * @description Zod schema for EASClientOptions.
10802
+ * Schema for validating EAS client configuration options.
10803
+ * Extends the base Viem client options with EAS-specific requirements.
10876
10804
  */
10877
- const EASClientOptionsSchema = object({
10878
- instance: string$1().url("Invalid instance URL"),
10879
- accessToken: __settlemint_sdk_utils_validation.ApplicationAccessTokenSchema.optional(),
10880
- easContractAddress: ethAddressSchema.optional(),
10881
- schemaRegistryContractAddress: ethAddressSchema.optional(),
10882
- debug: boolean$1().optional()
10805
+ const ClientOptionsSchema = object({
10806
+ schemaRegistryAddress: string$1().refine(viem.isAddress, "Invalid Ethereum address format"),
10807
+ attestationAddress: string$1().refine(viem.isAddress, "Invalid Ethereum address format"),
10808
+ accessToken: __settlemint_sdk_utils_validation.AccessTokenSchema,
10809
+ chainId: string$1().min(1),
10810
+ chainName: string$1().min(1),
10811
+ rpcUrl: __settlemint_sdk_utils_validation.UrlSchema
10883
10812
  });
10884
10813
 
10885
10814
  //#endregion
10886
- //#region src/eas.ts
10887
- const LOGGER = (0, __settlemint_sdk_utils_logging.createLogger)();
10815
+ //#region src/ethers-adapter.ts
10888
10816
  /**
10889
- * Main EAS client class for interacting with Ethereum Attestation Service via Portal
10890
- *
10891
- * @example
10892
- * ```typescript
10893
- * import { createEASClient } from "@settlemint/sdk-eas";
10894
- *
10895
- * const easClient = createEASClient({
10896
- * instance: "https://your-portal-instance.settlemint.com",
10897
- * accessToken: "your-access-token"
10898
- * });
10899
- *
10900
- * // Deploy EAS contracts
10901
- * const deployment = await easClient.deploy("0x1234...deployer-address");
10902
- * console.log("EAS deployed at:", deployment.easAddress);
10903
- * ```
10817
+ * Converts a viem PublicClient to an ethers JsonRpcProvider
10904
10818
  */
10905
- var EASClient = class {
10906
- options;
10907
- portalClient;
10908
- portalGraphql;
10909
- deployedAddresses;
10910
- constructor(options) {
10911
- this.options = (0, __settlemint_sdk_utils_validation.validate)(EASClientOptionsSchema, options);
10912
- const { client: portalClient, graphql: portalGraphql } = (0, __settlemint_sdk_portal.createPortalClient)({
10913
- instance: this.options.instance,
10914
- accessToken: this.options.accessToken
10915
- }, { fetch: (0, __settlemint_sdk_utils_logging.requestLogger)(LOGGER, "portal", fetch) });
10916
- this.portalClient = portalClient;
10917
- this.portalGraphql = portalGraphql;
10918
- }
10919
- /**
10920
- * Deploy EAS contracts via Portal
10921
- *
10922
- * @param deployerAddress - The address that will deploy the contracts
10923
- * @param forwarderAddress - Optional trusted forwarder address (defaults to zero address)
10924
- * @param gasLimit - Optional gas limit for deployment transactions (defaults to "0x7a1200")
10925
- * @returns Promise resolving to deployment result with contract addresses and transaction hashes
10926
- *
10927
- * @example
10928
- * ```typescript
10929
- * import { createEASClient } from "@settlemint/sdk-eas";
10930
- *
10931
- * const easClient = createEASClient({
10932
- * instance: "https://your-portal-instance.settlemint.com",
10933
- * accessToken: "your-access-token"
10934
- * });
10935
- *
10936
- * const deployment = await easClient.deploy(
10937
- * "0x1234567890123456789012345678901234567890", // deployer address
10938
- * "0x0000000000000000000000000000000000000000", // forwarder (optional)
10939
- * "0x7a1200" // gas limit (optional)
10940
- * );
10941
- *
10942
- * console.log("Schema Registry:", deployment.schemaRegistryAddress);
10943
- * console.log("EAS Contract:", deployment.easAddress);
10944
- * ```
10945
- */
10946
- async deploy(deployerAddress, forwarderAddress, gasLimit) {
10947
- const defaultForwarder = forwarderAddress || ZERO_ADDRESS;
10948
- const defaultGasLimit = gasLimit || "0x7a1200";
10949
- try {
10950
- const schemaRegistryResult = await this.portalClient.request(GraphQLOperations.mutations.deploySchemaRegistry(this.portalGraphql), {
10951
- from: deployerAddress,
10952
- constructorArguments: { forwarder: defaultForwarder },
10953
- gasLimit: defaultGasLimit
10954
- });
10955
- const schemaRegistryResponse = schemaRegistryResult;
10956
- if (!schemaRegistryResponse.DeployContractEASSchemaRegistry?.transactionHash) {
10957
- throw new Error("Schema Registry deployment failed - no transaction hash returned");
10958
- }
10959
- const schemaRegistryTxHash = schemaRegistryResponse.DeployContractEASSchemaRegistry.transactionHash;
10960
- const schemaRegistryTransaction = await (0, __settlemint_sdk_portal.waitForTransactionReceipt)(schemaRegistryTxHash, {
10961
- portalGraphqlEndpoint: this.options.instance,
10962
- accessToken: this.options.accessToken,
10963
- timeout: 6e4
10964
- });
10965
- if (!schemaRegistryTransaction?.receipt?.contractAddress) {
10966
- throw new Error("Schema Registry deployment failed - could not get contract address from transaction receipt.");
10967
- }
10968
- const schemaRegistryAddress = schemaRegistryTransaction.receipt.contractAddress;
10969
- const easResponse = await this.portalClient.request(GraphQLOperations.mutations.deployEAS(this.portalGraphql), {
10970
- from: deployerAddress,
10971
- constructorArguments: {
10972
- registry: schemaRegistryAddress,
10973
- forwarder: defaultForwarder
10974
- },
10975
- gasLimit: defaultGasLimit
10976
- });
10977
- const easResult = easResponse;
10978
- if (!easResult.DeployContractEAS?.transactionHash) {
10979
- throw new Error("EAS deployment failed - no transaction hash returned");
10980
- }
10981
- const easTxHash = easResult.DeployContractEAS.transactionHash;
10982
- const easTransaction = await (0, __settlemint_sdk_portal.waitForTransactionReceipt)(easTxHash, {
10983
- portalGraphqlEndpoint: this.options.instance,
10984
- accessToken: this.options.accessToken,
10985
- timeout: 6e4
10986
- });
10987
- if (!easTransaction?.receipt?.contractAddress) {
10988
- throw new Error("EAS deployment failed - could not get contract address from transaction receipt.");
10989
- }
10990
- const easAddress = easTransaction.receipt.contractAddress;
10991
- this.deployedAddresses = {
10992
- easAddress,
10993
- schemaRegistryAddress,
10994
- easTransactionHash: easTxHash,
10995
- schemaRegistryTransactionHash: schemaRegistryTxHash
10996
- };
10997
- return this.deployedAddresses;
10998
- } catch (err) {
10999
- const error$37 = err;
11000
- throw new Error(`Failed to deploy EAS contracts: ${error$37.message}`);
11001
- }
11002
- }
11003
- /**
11004
- * Register a new schema in the EAS Schema Registry
11005
- *
11006
- * @param request - Schema registration request containing schema definition
11007
- * @param fromAddress - Address that will register the schema
11008
- * @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
11009
- * @returns Promise resolving to transaction result
11010
- *
11011
- * @example
11012
- * ```typescript
11013
- * import { createEASClient } from "@settlemint/sdk-eas";
11014
- *
11015
- * const easClient = createEASClient({
11016
- * instance: "https://your-portal-instance.settlemint.com",
11017
- * accessToken: "your-access-token"
11018
- * });
11019
- *
11020
- * const schemaResult = await easClient.registerSchema(
11021
- * {
11022
- * schema: "uint256 eventId, uint8 voteIndex",
11023
- * resolver: "0x0000000000000000000000000000000000000000",
11024
- * revocable: true
11025
- * },
11026
- * "0x1234567890123456789012345678901234567890" // from address
11027
- * );
11028
- *
11029
- * console.log("Schema registered:", schemaResult.hash);
11030
- * ```
11031
- */
11032
- async registerSchema(request, fromAddress, gasLimit) {
11033
- const schemaRegistryAddress = this.getSchemaRegistryAddress();
11034
- let schemaString = request.schema;
11035
- if (request.fields && !schemaString) {
11036
- schemaString = this.buildSchemaString(request.fields);
11037
- }
11038
- if (!schemaString) {
11039
- throw new Error("Schema string is required. Provide either 'schema' or 'fields'.");
11040
- }
11041
- try {
11042
- const result = await this.portalClient.request(GraphQLOperations.mutations.registerSchema(this.portalGraphql), {
11043
- address: schemaRegistryAddress,
11044
- from: fromAddress,
11045
- input: {
11046
- schema: schemaString,
11047
- resolver: request.resolver,
11048
- revocable: request.revocable
11049
- },
11050
- gasLimit: gasLimit || "0x3d0900"
11051
- });
11052
- const response = result;
11053
- const transactionHash = response.EASSchemaRegistryRegister?.transactionHash;
11054
- if (!transactionHash) {
11055
- throw new Error("No transaction hash returned from Portal");
11056
- }
11057
- return {
11058
- hash: transactionHash,
11059
- success: true
11060
- };
11061
- } catch (err) {
11062
- const error$37 = err;
11063
- throw new Error(`Failed to register schema: ${error$37.message}`);
11064
- }
11065
- }
11066
- /**
11067
- * Create an attestation
11068
- *
11069
- * @param request - Attestation request containing schema and data
11070
- * @param fromAddress - Address that will create the attestation
11071
- * @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
11072
- * @returns Promise resolving to transaction result
11073
- *
11074
- * @example
11075
- * ```typescript
11076
- * import { createEASClient } from "@settlemint/sdk-eas";
11077
- *
11078
- * const easClient = createEASClient({
11079
- * instance: "https://your-portal-instance.settlemint.com",
11080
- * accessToken: "your-access-token"
11081
- * });
11082
- *
11083
- * const attestationResult = await easClient.attest(
11084
- * {
11085
- * schema: "0x1234567890123456789012345678901234567890123456789012345678901234",
11086
- * data: {
11087
- * recipient: "0x1234567890123456789012345678901234567890",
11088
- * expirationTime: BigInt(0), // No expiration
11089
- * revocable: true,
11090
- * refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
11091
- * data: "0x1234", // ABI-encoded data
11092
- * value: BigInt(0)
11093
- * }
11094
- * },
11095
- * "0x1234567890123456789012345678901234567890" // from address
11096
- * );
11097
- *
11098
- * console.log("Attestation created:", attestationResult.hash);
11099
- * ```
11100
- */
11101
- async attest(request, fromAddress, gasLimit) {
11102
- const easAddress = this.getEASAddress();
11103
- try {
11104
- const result = await this.portalClient.request(GraphQLOperations.mutations.attest(this.portalGraphql), {
11105
- address: easAddress,
11106
- from: fromAddress,
11107
- input: { request: {
11108
- schema: request.schema,
11109
- data: {
11110
- recipient: request.data.recipient,
11111
- expirationTime: request.data.expirationTime.toString(),
11112
- revocable: request.data.revocable,
11113
- refUID: request.data.refUID,
11114
- data: request.data.data,
11115
- value: request.data.value?.toString() || "0"
11116
- }
11117
- } },
11118
- gasLimit: gasLimit || "0x3d0900"
11119
- });
11120
- const response = result;
11121
- const transactionHash = response.EASAttest?.transactionHash;
11122
- if (!transactionHash) {
11123
- throw new Error("No transaction hash returned from Portal");
11124
- }
11125
- return {
11126
- hash: transactionHash,
11127
- success: true
11128
- };
11129
- } catch (err) {
11130
- const error$37 = err;
11131
- throw new Error(`Failed to create attestation: ${error$37.message}`);
11132
- }
11133
- }
11134
- /**
11135
- * Create multiple attestations in a single transaction
11136
- *
11137
- * @param requests - Array of attestation requests
11138
- * @param fromAddress - Address that will create the attestations
11139
- * @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
11140
- * @returns Promise resolving to transaction result
11141
- *
11142
- * @example
11143
- * ```typescript
11144
- * import { createEASClient } from "@settlemint/sdk-eas";
11145
- *
11146
- * const easClient = createEASClient({
11147
- * instance: "https://your-portal-instance.settlemint.com",
11148
- * accessToken: "your-access-token"
11149
- * });
11150
- *
11151
- * const multiAttestResult = await easClient.multiAttest(
11152
- * [
11153
- * {
11154
- * schema: "0x1234567890123456789012345678901234567890123456789012345678901234",
11155
- * data: {
11156
- * recipient: "0x1234567890123456789012345678901234567890",
11157
- * expirationTime: BigInt(0),
11158
- * revocable: true,
11159
- * refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
11160
- * data: "0x1234",
11161
- * value: BigInt(0)
11162
- * }
11163
- * },
11164
- * {
11165
- * schema: "0x5678901234567890123456789012345678901234567890123456789012345678",
11166
- * data: {
11167
- * recipient: "0x5678901234567890123456789012345678901234",
11168
- * expirationTime: BigInt(0),
11169
- * revocable: false,
11170
- * refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
11171
- * data: "0x5678",
11172
- * value: BigInt(0)
11173
- * }
11174
- * }
11175
- * ],
11176
- * "0x1234567890123456789012345678901234567890" // from address
11177
- * );
11178
- *
11179
- * console.log("Multiple attestations created:", multiAttestResult.hash);
11180
- * ```
11181
- */
11182
- async multiAttest(requests, fromAddress, gasLimit) {
11183
- if (requests.length === 0) {
11184
- throw new Error("At least one attestation request is required");
11185
- }
11186
- const easAddress = this.getEASAddress();
11187
- try {
11188
- const result = await this.portalClient.request(GraphQLOperations.mutations.multiAttest(this.portalGraphql), {
11189
- address: easAddress,
11190
- from: fromAddress,
11191
- input: { multiRequests: requests.map((req) => ({
11192
- schema: req.schema,
11193
- data: [{
11194
- recipient: req.data.recipient,
11195
- expirationTime: req.data.expirationTime.toString(),
11196
- revocable: req.data.revocable,
11197
- refUID: req.data.refUID,
11198
- data: req.data.data,
11199
- value: req.data.value?.toString() || "0"
11200
- }]
11201
- })) },
11202
- gasLimit: gasLimit || "0x3d0900"
11203
- });
11204
- const response = result;
11205
- const transactionHash = response.EASMultiAttest?.transactionHash;
11206
- if (!transactionHash) {
11207
- throw new Error("No transaction hash returned from Portal");
11208
- }
11209
- return {
11210
- hash: transactionHash,
11211
- success: true
11212
- };
11213
- } catch (err) {
11214
- const error$37 = err;
11215
- throw new Error(`Failed to create multiple attestations: ${error$37.message}`);
11216
- }
11217
- }
11218
- /**
11219
- * Revoke an existing attestation
11220
- *
11221
- * @param schemaUID - UID of the schema used for the attestation
11222
- * @param attestationUID - UID of the attestation to revoke
11223
- * @param fromAddress - Address that will revoke the attestation
11224
- * @param value - Optional ETH value to send with the revocation
11225
- * @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
11226
- * @returns Promise resolving to transaction result
11227
- *
11228
- * @example
11229
- * ```typescript
11230
- * import { createEASClient } from "@settlemint/sdk-eas";
11231
- *
11232
- * const easClient = createEASClient({
11233
- * instance: "https://your-portal-instance.settlemint.com",
11234
- * accessToken: "your-access-token"
11235
- * });
11236
- *
11237
- * const revokeResult = await easClient.revoke(
11238
- * "0x1234567890123456789012345678901234567890123456789012345678901234", // schema UID
11239
- * "0x5678901234567890123456789012345678901234567890123456789012345678", // attestation UID
11240
- * "0x1234567890123456789012345678901234567890", // from address
11241
- * BigInt(0) // value (optional)
11242
- * );
11243
- *
11244
- * console.log("Attestation revoked:", revokeResult.hash);
11245
- * ```
11246
- */
11247
- async revoke(schemaUID, attestationUID, fromAddress, value, gasLimit) {
11248
- const easAddress = this.getEASAddress();
11249
- try {
11250
- const result = await this.portalClient.request(GraphQLOperations.mutations.revoke(this.portalGraphql), {
11251
- address: this.getEASAddress(),
11252
- from: fromAddress,
11253
- input: { request: {
11254
- schema: schemaUID,
11255
- data: {
11256
- uid: attestationUID,
11257
- value: value?.toString() || "0"
11258
- }
11259
- } },
11260
- gasLimit: gasLimit || "0x3d0900"
11261
- });
11262
- const response = result;
11263
- const transactionHash = response.EASRevoke?.transactionHash;
11264
- if (!transactionHash) {
11265
- throw new Error("No transaction hash returned from Portal");
10819
+ function publicClientToProvider(client) {
10820
+ const { chain, transport } = client;
10821
+ if (!chain) throw new Error("Chain is required");
10822
+ const network = {
10823
+ chainId: chain.id,
10824
+ name: chain.name,
10825
+ ensAddress: chain.contracts?.ensRegistry?.address
10826
+ };
10827
+ if (transport.type === "fallback") {
10828
+ const providers = transport.transports.map(({ value }) => {
10829
+ if (!value?.url) return null;
10830
+ try {
10831
+ return new ethers.JsonRpcProvider(value.url, network);
10832
+ } catch {
10833
+ return null;
11266
10834
  }
11267
- return {
11268
- hash: transactionHash,
11269
- success: true
11270
- };
11271
- } catch (err) {
11272
- const error$37 = err;
11273
- throw new Error(`Failed to revoke attestation: ${error$37.message}`);
11274
- }
11275
- }
11276
- /**
11277
- * Get a schema by UID
11278
- *
11279
- * TODO: Implement using The Graph subgraph for EAS data queries
11280
- */
11281
- async getSchema(uid) {
11282
- throw new Error(`Schema queries not implemented yet. Use The Graph subgraph for reading schema data. Schema UID: ${uid}`);
11283
- }
11284
- /**
11285
- * Get all schemas with pagination
11286
- *
11287
- * TODO: Implement using The Graph subgraph for EAS data queries
11288
- */
11289
- async getSchemas(options) {
11290
- throw new Error("Schema listing not implemented yet. Use The Graph subgraph for reading schema data.");
11291
- }
11292
- /**
11293
- * Get an attestation by UID
11294
- *
11295
- * TODO: Implement using The Graph subgraph for EAS data queries
11296
- */
11297
- async getAttestation(uid) {
11298
- throw new Error(`Attestation queries not implemented yet. Use The Graph subgraph for reading attestation data. Attestation UID: ${uid}`);
10835
+ }).filter((provider) => provider != null);
10836
+ if (providers.length === 0) throw new Error("No valid RPC URLs found");
10837
+ return providers[0];
11299
10838
  }
11300
- /**
11301
- * Get attestations with pagination and filtering
11302
- *
11303
- * TODO: Implement using The Graph subgraph for EAS data queries
11304
- */
11305
- async getAttestations(options) {
11306
- throw new Error("Attestation listing not implemented yet. Use The Graph subgraph for reading attestation data.");
11307
- }
11308
- /**
11309
- * Check if an attestation is valid
11310
- *
11311
- * TODO: Implement using The Graph subgraph for EAS data queries
11312
- */
11313
- async isValidAttestation(uid) {
11314
- return false;
11315
- }
11316
- /**
11317
- * Get the current timestamp from the contract
11318
- *
11319
- * TODO: Fix Portal GraphQL query parameter encoding or use The Graph subgraph
11320
- */
11321
- async getTimestamp() {
11322
- throw new Error("Timestamp query not implemented yet. Fix Portal query parameters or use The Graph subgraph.");
10839
+ return new ethers.JsonRpcProvider(transport.url, network);
10840
+ }
10841
+ /**
10842
+ * Converts a viem WalletClient to an ethers Wallet
10843
+ */
10844
+ function walletClientToSigner(client) {
10845
+ const { account, chain, transport } = client;
10846
+ if (!chain) throw new Error("Chain is required");
10847
+ if (!account) throw new Error("Account is required");
10848
+ const network = {
10849
+ chainId: chain.id,
10850
+ name: chain.name,
10851
+ ensAddress: chain.contracts?.ensRegistry?.address
10852
+ };
10853
+ const provider = new ethers.JsonRpcProvider(transport.url, network);
10854
+ const privateKey = account.privateKey;
10855
+ if (!privateKey || typeof privateKey !== "string") {
10856
+ throw new Error("Private key is required and must be a string");
10857
+ }
10858
+ return new ethers.Wallet(privateKey, provider);
10859
+ }
10860
+
10861
+ //#endregion
10862
+ //#region src/types.ts
10863
+ /**
10864
+ * Supported field types for EAS schema fields.
10865
+ * Maps to the Solidity types that can be used in EAS schemas.
10866
+ */
10867
+ const EAS_FIELD_TYPES = {
10868
+ string: "string",
10869
+ address: "address",
10870
+ bool: "bool",
10871
+ bytes: "bytes",
10872
+ bytes32: "bytes32",
10873
+ uint256: "uint256",
10874
+ int256: "int256",
10875
+ uint8: "uint8",
10876
+ int8: "int8"
10877
+ };
10878
+
10879
+ //#endregion
10880
+ //#region src/validation.ts
10881
+ function validateFieldName(name) {
10882
+ if (!name) {
10883
+ throw new Error("Field name cannot be empty");
11323
10884
  }
11324
- /**
11325
- * Get client configuration
11326
- */
11327
- getOptions() {
11328
- return { ...this.options };
10885
+ if (name.includes(" ")) {
10886
+ throw new Error("Field name cannot contain spaces");
11329
10887
  }
11330
- /**
11331
- * Get the Portal client instance for advanced operations
11332
- */
11333
- getPortalClient() {
11334
- return this.portalClient;
10888
+ if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
10889
+ throw new Error("Field name must start with a letter or underscore and contain only alphanumeric characters and underscores");
11335
10890
  }
11336
- /**
11337
- * Get current contract addresses
11338
- */
11339
- getContractAddresses() {
11340
- return {
11341
- easAddress: this.options.easContractAddress || this.deployedAddresses?.easAddress,
11342
- schemaRegistryAddress: this.options.schemaRegistryContractAddress || this.deployedAddresses?.schemaRegistryAddress
11343
- };
10891
+ }
10892
+ function validateFieldType(type) {
10893
+ if (!(type in EAS_FIELD_TYPES)) {
10894
+ throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(", ")}`);
11344
10895
  }
11345
- getEASAddress() {
11346
- if (this.options.easContractAddress) {
11347
- return this.options.easContractAddress;
11348
- }
11349
- if (this.deployedAddresses?.easAddress) {
11350
- return this.deployedAddresses.easAddress;
11351
- }
11352
- throw new Error("EAS contract address not available. Please provide it in options or deploy contracts first.");
10896
+ }
10897
+ function validateSchemaFields(fields) {
10898
+ if (!fields || fields.length === 0) {
10899
+ throw new Error("Schema must have at least one field");
11353
10900
  }
11354
- getSchemaRegistryAddress() {
11355
- if (this.options.schemaRegistryContractAddress) {
11356
- return this.options.schemaRegistryContractAddress;
10901
+ const seenNames = new Set();
10902
+ for (const field of fields) {
10903
+ validateFieldName(field.name);
10904
+ validateFieldType(field.type);
10905
+ if (seenNames.has(field.name)) {
10906
+ throw new Error(`Duplicate field name: ${field.name}`);
11357
10907
  }
11358
- if (this.deployedAddresses?.schemaRegistryAddress) {
11359
- return this.deployedAddresses.schemaRegistryAddress;
11360
- }
11361
- throw new Error("Schema Registry contract address not available. Please provide it in options or deploy contracts first.");
11362
- }
11363
- buildSchemaString(fields) {
11364
- return fields.map((field) => `${field.type} ${field.name}`).join(", ");
10908
+ seenNames.add(field.name);
11365
10909
  }
11366
- };
10910
+ }
10911
+ function buildSchemaString(fields) {
10912
+ validateSchemaFields(fields);
10913
+ return fields.map((field) => `${field.type} ${field.name}`).join(", ");
10914
+ }
10915
+
10916
+ //#endregion
10917
+ //#region src/eas.ts
11367
10918
  /**
11368
- * Create an EAS client instance
10919
+ * Creates an EAS client for interacting with the Ethereum Attestation Service.
11369
10920
  *
11370
- * @param options - Configuration options for the EAS client
11371
- * @returns EAS client instance
10921
+ * @param options - Configuration options for the client
10922
+ * @returns An object containing the EAS client instance
10923
+ * @throws Will throw an error if the options fail validation
11372
10924
  *
11373
10925
  * @example
11374
- * ```typescript
11375
- * import { createEASClient } from "@settlemint/sdk-eas";
10926
+ * ```ts
10927
+ * import { createEASClient } from '@settlemint/sdk-eas';
11376
10928
  *
11377
- * const easClient = createEASClient({
11378
- * instance: "https://your-portal-instance.settlemint.com",
11379
- * accessToken: "your-access-token"
10929
+ * const client = createEASClient({
10930
+ * schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
10931
+ * attestationAddress: "0x1234567890123456789012345678901234567890",
10932
+ * accessToken: "your-access-token",
10933
+ * chainId: "1",
10934
+ * chainName: "Ethereum",
10935
+ * rpcUrl: "http://localhost:8545"
11380
10936
  * });
11381
- *
11382
- * // Use the client
11383
- * const deployment = await easClient.deploy("0x1234...deployer-address");
11384
10937
  * ```
11385
10938
  */
11386
10939
  function createEASClient(options) {
11387
- return new EASClient(options);
10940
+ (0, __settlemint_sdk_utils_validation.validate)(ClientOptionsSchema, options);
10941
+ const publicClient = (0, __settlemint_sdk_viem.getPublicClient)({
10942
+ accessToken: options.accessToken,
10943
+ chainId: options.chainId,
10944
+ chainName: options.chainName,
10945
+ rpcUrl: options.rpcUrl
10946
+ });
10947
+ const walletClient = (0, __settlemint_sdk_viem.getWalletClient)({
10948
+ accessToken: options.accessToken,
10949
+ chainId: options.chainId,
10950
+ chainName: options.chainName,
10951
+ rpcUrl: options.rpcUrl
10952
+ })();
10953
+ const provider = publicClientToProvider(publicClient);
10954
+ const wallet = walletClientToSigner(walletClient);
10955
+ const schemaRegistry = new __ethereum_attestation_service_eas_sdk.SchemaRegistry(options.schemaRegistryAddress);
10956
+ schemaRegistry.connect(wallet);
10957
+ async function registerSchema(options$1) {
10958
+ validateSchemaFields(options$1.fields);
10959
+ const schema = buildSchemaString(options$1.fields);
10960
+ try {
10961
+ await provider.getNetwork();
10962
+ const tx = await schemaRegistry.register({
10963
+ schema,
10964
+ resolverAddress: options$1.resolverAddress,
10965
+ revocable: options$1.revocable
10966
+ });
10967
+ await tx.wait();
10968
+ return tx.toString();
10969
+ } catch (error$37) {
10970
+ throw new Error(`Failed to register schema: ${error$37.message}`, { cause: error$37 });
10971
+ }
10972
+ }
10973
+ async function getSchema(uid) {
10974
+ try {
10975
+ await provider.getNetwork();
10976
+ const schema = await schemaRegistry.getSchema({ uid });
10977
+ return schema.toString();
10978
+ } catch (error$37) {
10979
+ throw new Error(`Failed to get schema: ${error$37.message}`);
10980
+ }
10981
+ }
10982
+ return {
10983
+ registerSchema,
10984
+ getSchema
10985
+ };
11388
10986
  }
11389
10987
 
11390
10988
  //#endregion
11391
- exports.EASClient = EASClient;
11392
- exports.EASClientOptionsSchema = EASClientOptionsSchema;
11393
10989
  exports.EAS_FIELD_TYPES = EAS_FIELD_TYPES;
11394
- exports.GraphQLOperations = GraphQLOperations;
11395
- exports.ZERO_ADDRESS = ZERO_ADDRESS;
11396
- exports.ZERO_BYTES32 = ZERO_BYTES32;
11397
10990
  exports.createEASClient = createEASClient;
11398
10991
  //# sourceMappingURL=eas.cjs.map