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