@settlemint/sdk-eas 2.3.14 → 2.4.0-main1ce5f55f

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,9 +1,9 @@
1
+ /* SettleMint EAS SDK - Portal Optimized */
1
2
  import "node:module";
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";
3
+ import { createPortalClient, waitForTransactionReceipt } from "@settlemint/sdk-portal";
4
+ import { createLogger, requestLogger } from "@settlemint/sdk-utils/logging";
5
+ import { ApplicationAccessTokenSchema, UrlSchema, validate } from "@settlemint/sdk-utils/validation";
6
+ import { isAddress, zeroAddress } from "viem";
7
7
 
8
8
  //#region rolldown:runtime
9
9
  var __defProp = Object.defineProperty;
@@ -14,6 +14,79 @@ var __export = (target, all) => {
14
14
  });
15
15
  };
16
16
 
17
+ //#endregion
18
+ //#region src/portal/operations.ts
19
+ const GraphQLOperations = { mutations: {
20
+ deploySchemaRegistry: (graphql) => graphql(`
21
+ mutation DeployContractEASSchemaRegistry(
22
+ $from: String!
23
+ $constructorArguments: DeployContractEASSchemaRegistryInput!
24
+ $gasLimit: String!
25
+ ) {
26
+ DeployContractEASSchemaRegistry(from: $from, constructorArguments: $constructorArguments, gasLimit: $gasLimit) {
27
+ transactionHash
28
+ }
29
+ }`),
30
+ deployEAS: (graphql) => graphql(`
31
+ mutation DeployContractEAS($from: String!, $constructorArguments: DeployContractEASInput!, $gasLimit: String!) {
32
+ DeployContractEAS(from: $from, constructorArguments: $constructorArguments, gasLimit: $gasLimit) {
33
+ transactionHash
34
+ }
35
+ }`),
36
+ registerSchema: (graphql) => graphql(`
37
+ mutation EASSchemaRegistryRegister(
38
+ $address: String!
39
+ $from: String!
40
+ $input: EASSchemaRegistryRegisterInput!
41
+ $gasLimit: String!
42
+ ) {
43
+ EASSchemaRegistryRegister(address: $address, from: $from, input: $input, gasLimit: $gasLimit) {
44
+ transactionHash
45
+ }
46
+ }`),
47
+ attest: (graphql) => graphql(`
48
+ mutation EASAttest($address: String!, $from: String!, $input: EASAttestInput!, $gasLimit: String!) {
49
+ EASAttest(address: $address, from: $from, input: $input, gasLimit: $gasLimit) {
50
+ transactionHash
51
+ }
52
+ }`),
53
+ multiAttest: (graphql) => graphql(`
54
+ mutation EASMultiAttest($address: String!, $from: String!, $input: EASMultiAttestInput!, $gasLimit: String!) {
55
+ EASMultiAttest(address: $address, from: $from, input: $input, gasLimit: $gasLimit) {
56
+ transactionHash
57
+ }
58
+ }`),
59
+ revoke: (graphql) => graphql(`
60
+ mutation EASRevoke($address: String!, $from: String!, $input: EASRevokeInput!, $gasLimit: String!) {
61
+ EASRevoke(address: $address, from: $from, input: $input, gasLimit: $gasLimit) {
62
+ transactionHash
63
+ }
64
+ }`)
65
+ } };
66
+
67
+ //#endregion
68
+ //#region src/schema.ts
69
+ /**
70
+ * Common address constants
71
+ */
72
+ const ZERO_ADDRESS = zeroAddress;
73
+ const ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
74
+ /**
75
+ * Supported field types for EAS schema fields.
76
+ * Maps to the Solidity types that can be used in EAS schemas.
77
+ */
78
+ const EAS_FIELD_TYPES = {
79
+ string: "string",
80
+ address: "address",
81
+ bool: "bool",
82
+ bytes: "bytes",
83
+ bytes32: "bytes32",
84
+ uint256: "uint256",
85
+ int256: "int256",
86
+ uint8: "uint8",
87
+ int8: "int8"
88
+ };
89
+
17
90
  //#endregion
18
91
  //#region ../../node_modules/zod/dist/esm/v4/core/core.js
19
92
  function $constructor(name, initializer$2, params) {
@@ -10779,194 +10852,523 @@ var classic_default = external_exports;
10779
10852
  var v4_default = classic_default;
10780
10853
 
10781
10854
  //#endregion
10782
- //#region src/client-options.schema.ts
10855
+ //#region src/utils/validation.ts
10856
+ const ethAddressSchema = custom((val) => typeof val === "string" && isAddress(val), "Invalid Ethereum address");
10783
10857
  /**
10784
- * Schema for validating EAS client configuration options.
10785
- * Extends the base Viem client options with EAS-specific requirements.
10858
+ * Zod schema for EASClientOptions.
10786
10859
  */
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
10860
+ const EASClientOptionsSchema = object({
10861
+ instance: UrlSchema,
10862
+ accessToken: ApplicationAccessTokenSchema.optional(),
10863
+ easContractAddress: ethAddressSchema.optional(),
10864
+ schemaRegistryContractAddress: ethAddressSchema.optional(),
10865
+ debug: boolean$1().optional()
10794
10866
  });
10795
10867
 
10796
10868
  //#endregion
10797
- //#region src/ethers-adapter.ts
10869
+ //#region src/eas.ts
10870
+ const LOGGER = createLogger();
10871
+ const DEFAULT_GAS_LIMIT = "0x3d0900";
10798
10872
  /**
10799
- * Converts a viem PublicClient to an ethers JsonRpcProvider
10873
+ * Main EAS client class for interacting with Ethereum Attestation Service via Portal
10874
+ *
10875
+ * @example
10876
+ * ```typescript
10877
+ * import { createEASClient } from "@settlemint/sdk-eas";
10878
+ *
10879
+ * const easClient = createEASClient({
10880
+ * instance: "https://your-portal-instance.settlemint.com",
10881
+ * accessToken: "your-access-token"
10882
+ * });
10883
+ *
10884
+ * // Deploy EAS contracts
10885
+ * const deployment = await easClient.deploy("0x1234...deployer-address");
10886
+ * console.log("EAS deployed at:", deployment.easAddress);
10887
+ * ```
10800
10888
  */
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;
10889
+ var EASClient = class {
10890
+ options;
10891
+ portalClient;
10892
+ portalGraphql;
10893
+ deployedAddresses;
10894
+ /**
10895
+ * Create a new EAS client instance
10896
+ *
10897
+ * @param options - Configuration options for the EAS client
10898
+ */
10899
+ constructor(options) {
10900
+ this.options = validate(EASClientOptionsSchema, options);
10901
+ const { client: portalClient, graphql: portalGraphql } = createPortalClient({
10902
+ instance: this.options.instance,
10903
+ accessToken: this.options.accessToken
10904
+ }, { fetch: requestLogger(LOGGER, "portal", fetch) });
10905
+ this.portalClient = portalClient;
10906
+ this.portalGraphql = portalGraphql;
10907
+ }
10908
+ /**
10909
+ * Deploy EAS contracts via Portal
10910
+ *
10911
+ * @param deployerAddress - The address that will deploy the contracts
10912
+ * @param forwarderAddress - Optional trusted forwarder address (defaults to zero address)
10913
+ * @param gasLimit - Optional gas limit for deployment transactions (defaults to "0x7a1200")
10914
+ * @returns Promise resolving to deployment result with contract addresses and transaction hashes
10915
+ *
10916
+ * @example
10917
+ * ```typescript
10918
+ * import { createEASClient } from "@settlemint/sdk-eas";
10919
+ *
10920
+ * const easClient = createEASClient({
10921
+ * instance: "https://your-portal-instance.settlemint.com",
10922
+ * accessToken: "your-access-token"
10923
+ * });
10924
+ *
10925
+ * const deployment = await easClient.deploy(
10926
+ * "0x1234567890123456789012345678901234567890", // deployer address
10927
+ * "0x0000000000000000000000000000000000000000", // forwarder (optional)
10928
+ * "0x7a1200" // gas limit (optional)
10929
+ * );
10930
+ *
10931
+ * console.log("Schema Registry:", deployment.schemaRegistryAddress);
10932
+ * console.log("EAS Contract:", deployment.easAddress);
10933
+ * ```
10934
+ */
10935
+ async deploy(deployerAddress, forwarderAddress, gasLimit) {
10936
+ const defaultForwarder = forwarderAddress || ZERO_ADDRESS;
10937
+ const defaultGasLimit = gasLimit || "0x7a1200";
10938
+ try {
10939
+ const schemaRegistryResponse = await this.portalClient.request(GraphQLOperations.mutations.deploySchemaRegistry(this.portalGraphql), {
10940
+ from: deployerAddress,
10941
+ constructorArguments: { forwarder: defaultForwarder },
10942
+ gasLimit: defaultGasLimit
10943
+ });
10944
+ if (!schemaRegistryResponse.DeployContractEASSchemaRegistry?.transactionHash) {
10945
+ throw new Error("Schema Registry deployment failed - no transaction hash returned");
10946
+ }
10947
+ const schemaRegistryTxHash = schemaRegistryResponse.DeployContractEASSchemaRegistry.transactionHash;
10948
+ const schemaRegistryTransaction = await waitForTransactionReceipt(schemaRegistryTxHash, {
10949
+ portalGraphqlEndpoint: this.options.instance,
10950
+ accessToken: this.options.accessToken,
10951
+ timeout: 6e4
10952
+ });
10953
+ if (!schemaRegistryTransaction?.receipt?.contractAddress) {
10954
+ throw new Error("Schema Registry deployment failed - could not get contract address from transaction receipt.");
10955
+ }
10956
+ const schemaRegistryAddress = schemaRegistryTransaction.receipt.contractAddress;
10957
+ const easResponse = await this.portalClient.request(GraphQLOperations.mutations.deployEAS(this.portalGraphql), {
10958
+ from: deployerAddress,
10959
+ constructorArguments: {
10960
+ registry: schemaRegistryAddress,
10961
+ forwarder: defaultForwarder
10962
+ },
10963
+ gasLimit: defaultGasLimit
10964
+ });
10965
+ if (!easResponse.DeployContractEAS?.transactionHash) {
10966
+ throw new Error("EAS deployment failed - no transaction hash returned");
10967
+ }
10968
+ const easTxHash = easResponse.DeployContractEAS.transactionHash;
10969
+ const easTransaction = await waitForTransactionReceipt(easTxHash, {
10970
+ portalGraphqlEndpoint: this.options.instance,
10971
+ accessToken: this.options.accessToken,
10972
+ timeout: 6e4
10973
+ });
10974
+ if (!easTransaction?.receipt?.contractAddress) {
10975
+ throw new Error("EAS deployment failed - could not get contract address from transaction receipt.");
10976
+ }
10977
+ const easAddress = easTransaction.receipt.contractAddress;
10978
+ this.deployedAddresses = {
10979
+ easAddress,
10980
+ schemaRegistryAddress,
10981
+ easTransactionHash: easTxHash,
10982
+ schemaRegistryTransactionHash: schemaRegistryTxHash
10983
+ };
10984
+ return this.deployedAddresses;
10985
+ } catch (err) {
10986
+ const error$37 = err;
10987
+ throw new Error(`Failed to deploy EAS contracts: ${error$37.message}`);
10988
+ }
10989
+ }
10990
+ /**
10991
+ * Register a new schema in the EAS Schema Registry
10992
+ *
10993
+ * @param request - Schema registration request containing schema definition
10994
+ * @param fromAddress - Address that will register the schema
10995
+ * @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
10996
+ * @returns Promise resolving to transaction result
10997
+ *
10998
+ * @example
10999
+ * ```typescript
11000
+ * import { createEASClient } from "@settlemint/sdk-eas";
11001
+ *
11002
+ * const easClient = createEASClient({
11003
+ * instance: "https://your-portal-instance.settlemint.com",
11004
+ * accessToken: "your-access-token"
11005
+ * });
11006
+ *
11007
+ * const schemaResult = await easClient.registerSchema(
11008
+ * {
11009
+ * schema: "uint256 eventId, uint8 voteIndex",
11010
+ * resolver: "0x0000000000000000000000000000000000000000",
11011
+ * revocable: true
11012
+ * },
11013
+ * "0x1234567890123456789012345678901234567890" // from address
11014
+ * );
11015
+ *
11016
+ * console.log("Schema registered:", schemaResult.hash);
11017
+ * ```
11018
+ */
11019
+ async registerSchema(request, fromAddress, gasLimit) {
11020
+ const schemaRegistryAddress = this.getSchemaRegistryAddress();
11021
+ let schemaString = request.schema;
11022
+ if (request.fields && !schemaString) {
11023
+ schemaString = this.buildSchemaString(request.fields);
11024
+ }
11025
+ if (!schemaString) {
11026
+ throw new Error("Schema string is required. Provide either 'schema' or 'fields'.");
11027
+ }
11028
+ try {
11029
+ const response = await this.portalClient.request(GraphQLOperations.mutations.registerSchema(this.portalGraphql), {
11030
+ address: schemaRegistryAddress,
11031
+ from: fromAddress,
11032
+ input: {
11033
+ schema: schemaString,
11034
+ resolver: request.resolver,
11035
+ revocable: request.revocable
11036
+ },
11037
+ gasLimit: gasLimit || DEFAULT_GAS_LIMIT
11038
+ });
11039
+ const transactionHash = response.EASSchemaRegistryRegister?.transactionHash;
11040
+ if (!transactionHash) {
11041
+ throw new Error("No transaction hash returned from Portal");
10816
11042
  }
10817
- }).filter((provider) => provider != null);
10818
- if (providers.length === 0) throw new Error("No valid RPC URLs found");
10819
- return providers[0];
11043
+ return {
11044
+ hash: transactionHash,
11045
+ success: true
11046
+ };
11047
+ } catch (err) {
11048
+ const error$37 = err;
11049
+ throw new Error(`Failed to register schema: ${error$37.message}`);
11050
+ }
10820
11051
  }
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");
11052
+ /**
11053
+ * Create an attestation
11054
+ *
11055
+ * @param request - Attestation request containing schema and data
11056
+ * @param fromAddress - Address that will create the attestation
11057
+ * @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
11058
+ * @returns Promise resolving to transaction result
11059
+ *
11060
+ * @example
11061
+ * ```typescript
11062
+ * import { createEASClient } from "@settlemint/sdk-eas";
11063
+ *
11064
+ * const easClient = createEASClient({
11065
+ * instance: "https://your-portal-instance.settlemint.com",
11066
+ * accessToken: "your-access-token"
11067
+ * });
11068
+ *
11069
+ * const attestationResult = await easClient.attest(
11070
+ * {
11071
+ * schema: "0x1234567890123456789012345678901234567890123456789012345678901234",
11072
+ * data: {
11073
+ * recipient: "0x1234567890123456789012345678901234567890",
11074
+ * expirationTime: BigInt(0), // No expiration
11075
+ * revocable: true,
11076
+ * refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
11077
+ * data: "0x1234", // ABI-encoded data
11078
+ * value: BigInt(0)
11079
+ * }
11080
+ * },
11081
+ * "0x1234567890123456789012345678901234567890" // from address
11082
+ * );
11083
+ *
11084
+ * console.log("Attestation created:", attestationResult.hash);
11085
+ * ```
11086
+ */
11087
+ async attest(request, fromAddress, gasLimit) {
11088
+ const easAddress = this.getEASAddress();
11089
+ try {
11090
+ const response = await this.portalClient.request(GraphQLOperations.mutations.attest(this.portalGraphql), {
11091
+ address: easAddress,
11092
+ from: fromAddress,
11093
+ input: { request: {
11094
+ schema: request.schema,
11095
+ data: {
11096
+ recipient: request.data.recipient,
11097
+ expirationTime: request.data.expirationTime.toString(),
11098
+ revocable: request.data.revocable,
11099
+ refUID: request.data.refUID,
11100
+ data: request.data.data,
11101
+ value: request.data.value?.toString() || "0"
11102
+ }
11103
+ } },
11104
+ gasLimit: gasLimit || DEFAULT_GAS_LIMIT
11105
+ });
11106
+ const transactionHash = response.EASAttest?.transactionHash;
11107
+ if (!transactionHash) {
11108
+ throw new Error("No transaction hash returned from Portal");
11109
+ }
11110
+ return {
11111
+ hash: transactionHash,
11112
+ success: true
11113
+ };
11114
+ } catch (err) {
11115
+ const error$37 = err;
11116
+ throw new Error(`Failed to create attestation: ${error$37.message}`);
11117
+ }
10866
11118
  }
10867
- if (name.includes(" ")) {
10868
- throw new Error("Field name cannot contain spaces");
11119
+ /**
11120
+ * Create multiple attestations in a single transaction
11121
+ *
11122
+ * @param requests - Array of attestation requests
11123
+ * @param fromAddress - Address that will create the attestations
11124
+ * @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
11125
+ * @returns Promise resolving to transaction result
11126
+ *
11127
+ * @example
11128
+ * ```typescript
11129
+ * import { createEASClient } from "@settlemint/sdk-eas";
11130
+ *
11131
+ * const easClient = createEASClient({
11132
+ * instance: "https://your-portal-instance.settlemint.com",
11133
+ * accessToken: "your-access-token"
11134
+ * });
11135
+ *
11136
+ * const multiAttestResult = await easClient.multiAttest(
11137
+ * [
11138
+ * {
11139
+ * schema: "0x1234567890123456789012345678901234567890123456789012345678901234",
11140
+ * data: {
11141
+ * recipient: "0x1234567890123456789012345678901234567890",
11142
+ * expirationTime: BigInt(0),
11143
+ * revocable: true,
11144
+ * refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
11145
+ * data: "0x1234",
11146
+ * value: BigInt(0)
11147
+ * }
11148
+ * },
11149
+ * {
11150
+ * schema: "0x5678901234567890123456789012345678901234567890123456789012345678",
11151
+ * data: {
11152
+ * recipient: "0x5678901234567890123456789012345678901234",
11153
+ * expirationTime: BigInt(0),
11154
+ * revocable: false,
11155
+ * refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
11156
+ * data: "0x5678",
11157
+ * value: BigInt(0)
11158
+ * }
11159
+ * }
11160
+ * ],
11161
+ * "0x1234567890123456789012345678901234567890" // from address
11162
+ * );
11163
+ *
11164
+ * console.log("Multiple attestations created:", multiAttestResult.hash);
11165
+ * ```
11166
+ */
11167
+ async multiAttest(requests, fromAddress, gasLimit) {
11168
+ if (requests.length === 0) {
11169
+ throw new Error("At least one attestation request is required");
11170
+ }
11171
+ const easAddress = this.getEASAddress();
11172
+ try {
11173
+ const response = await this.portalClient.request(GraphQLOperations.mutations.multiAttest(this.portalGraphql), {
11174
+ address: easAddress,
11175
+ from: fromAddress,
11176
+ input: { multiRequests: requests.map((req) => ({
11177
+ schema: req.schema,
11178
+ data: [{
11179
+ recipient: req.data.recipient,
11180
+ expirationTime: req.data.expirationTime.toString(),
11181
+ revocable: req.data.revocable,
11182
+ refUID: req.data.refUID,
11183
+ data: req.data.data,
11184
+ value: req.data.value?.toString() || "0"
11185
+ }]
11186
+ })) },
11187
+ gasLimit: gasLimit || DEFAULT_GAS_LIMIT
11188
+ });
11189
+ const transactionHash = response.EASMultiAttest?.transactionHash;
11190
+ if (!transactionHash) {
11191
+ throw new Error("No transaction hash returned from Portal");
11192
+ }
11193
+ return {
11194
+ hash: transactionHash,
11195
+ success: true
11196
+ };
11197
+ } catch (err) {
11198
+ const error$37 = err;
11199
+ throw new Error(`Failed to create multiple attestations: ${error$37.message}`);
11200
+ }
11201
+ }
11202
+ /**
11203
+ * Revoke an existing attestation
11204
+ *
11205
+ * @param schemaUID - UID of the schema used for the attestation
11206
+ * @param attestationUID - UID of the attestation to revoke
11207
+ * @param fromAddress - Address that will revoke the attestation
11208
+ * @param value - Optional ETH value to send with the revocation
11209
+ * @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
11210
+ * @returns Promise resolving to transaction result
11211
+ *
11212
+ * @example
11213
+ * ```typescript
11214
+ * import { createEASClient } from "@settlemint/sdk-eas";
11215
+ *
11216
+ * const easClient = createEASClient({
11217
+ * instance: "https://your-portal-instance.settlemint.com",
11218
+ * accessToken: "your-access-token"
11219
+ * });
11220
+ *
11221
+ * const revokeResult = await easClient.revoke(
11222
+ * "0x1234567890123456789012345678901234567890123456789012345678901234", // schema UID
11223
+ * "0x5678901234567890123456789012345678901234567890123456789012345678", // attestation UID
11224
+ * "0x1234567890123456789012345678901234567890", // from address
11225
+ * BigInt(0) // value (optional)
11226
+ * );
11227
+ *
11228
+ * console.log("Attestation revoked:", revokeResult.hash);
11229
+ * ```
11230
+ */
11231
+ async revoke(schemaUID, attestationUID, fromAddress, value, gasLimit) {
11232
+ try {
11233
+ const response = await this.portalClient.request(GraphQLOperations.mutations.revoke(this.portalGraphql), {
11234
+ address: this.getEASAddress(),
11235
+ from: fromAddress,
11236
+ input: { request: {
11237
+ schema: schemaUID,
11238
+ data: {
11239
+ uid: attestationUID,
11240
+ value: value?.toString() || "0"
11241
+ }
11242
+ } },
11243
+ gasLimit: gasLimit || DEFAULT_GAS_LIMIT
11244
+ });
11245
+ const transactionHash = response.EASRevoke?.transactionHash;
11246
+ if (!transactionHash) {
11247
+ throw new Error("No transaction hash returned from Portal");
11248
+ }
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
+ }
10869
11257
  }
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");
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}`);
10872
11265
  }
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(", ")}`);
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.");
10877
11273
  }
10878
- }
10879
- function validateSchemaFields(fields) {
10880
- if (!fields || fields.length === 0) {
10881
- throw new Error("Schema must have at least one field");
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}`);
10882
11281
  }
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}`);
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.");
11305
+ }
11306
+ /**
11307
+ * Get client configuration
11308
+ */
11309
+ getOptions() {
11310
+ return { ...this.options };
11311
+ }
11312
+ /**
11313
+ * Get the Portal client instance for advanced operations
11314
+ */
11315
+ getPortalClient() {
11316
+ return this.portalClient;
11317
+ }
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
+ };
11326
+ }
11327
+ getEASAddress() {
11328
+ if (this.options.easContractAddress) {
11329
+ return this.options.easContractAddress;
11330
+ }
11331
+ if (this.deployedAddresses?.easAddress) {
11332
+ return this.deployedAddresses.easAddress;
10889
11333
  }
10890
- seenNames.add(field.name);
11334
+ throw new Error("EAS contract address not available. Please provide it in options or deploy contracts first.");
10891
11335
  }
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
11336
+ getSchemaRegistryAddress() {
11337
+ if (this.options.schemaRegistryContractAddress) {
11338
+ return this.options.schemaRegistryContractAddress;
11339
+ }
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(", ");
11347
+ }
11348
+ };
10900
11349
  /**
10901
- * Creates an EAS client for interacting with the Ethereum Attestation Service.
11350
+ * Create an EAS client instance
10902
11351
  *
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
11352
+ * @param options - Configuration options for the EAS client
11353
+ * @returns EAS client instance
10906
11354
  *
10907
11355
  * @example
10908
- * ```ts
10909
- * import { createEASClient } from '@settlemint/sdk-eas';
11356
+ * ```typescript
11357
+ * import { createEASClient } from "@settlemint/sdk-eas";
10910
11358
  *
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"
11359
+ * const easClient = createEASClient({
11360
+ * instance: "https://your-portal-instance.settlemint.com",
11361
+ * accessToken: "your-access-token"
10918
11362
  * });
11363
+ *
11364
+ * // Use the client
11365
+ * const deployment = await easClient.deploy("0x1234...deployer-address");
10919
11366
  * ```
10920
11367
  */
10921
11368
  function createEASClient(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
- };
11369
+ return new EASClient(options);
10968
11370
  }
10969
11371
 
10970
11372
  //#endregion
10971
- export { EAS_FIELD_TYPES, createEASClient };
11373
+ export { EASClient, EASClientOptionsSchema, EAS_FIELD_TYPES, GraphQLOperations, ZERO_ADDRESS, ZERO_BYTES32, createEASClient };
10972
11374
  //# sourceMappingURL=eas.js.map