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