@settlemint/sdk-eas 2.3.14 → 2.4.0-main005a9b57
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/README.md +1082 -63
- package/dist/browser/eas.d.ts +4327 -39
- package/dist/browser/eas.js +568 -167
- package/dist/browser/eas.js.map +1 -1
- package/dist/eas.cjs +570 -164
- package/dist/eas.cjs.map +1 -1
- package/dist/eas.d.cts +4327 -39
- package/dist/eas.d.ts +4327 -39
- package/dist/eas.js +568 -167
- package/dist/eas.js.map +1 -1
- package/package.json +5 -5
package/dist/browser/eas.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { isAddress } from "viem";
|
|
5
|
-
import { JsonRpcProvider, Wallet } from "ethers";
|
|
1
|
+
import { createPortalClient, waitForTransactionReceipt } from "@settlemint/sdk-portal";
|
|
2
|
+
import { createLogger, requestLogger } from "@settlemint/sdk-utils/logging";
|
|
3
|
+
import { ApplicationAccessTokenSchema, UrlSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
4
|
+
import { isAddress, zeroAddress } from "viem";
|
|
6
5
|
|
|
7
6
|
//#region rolldown:runtime
|
|
8
7
|
var __defProp = Object.defineProperty;
|
|
@@ -13,6 +12,79 @@ var __export = (target, all) => {
|
|
|
13
12
|
});
|
|
14
13
|
};
|
|
15
14
|
|
|
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
|
+
|
|
16
88
|
//#endregion
|
|
17
89
|
//#region ../../node_modules/zod/dist/esm/v4/core/core.js
|
|
18
90
|
function $constructor(name, initializer$2, params) {
|
|
@@ -10778,194 +10850,523 @@ var classic_default = external_exports;
|
|
|
10778
10850
|
var v4_default = classic_default;
|
|
10779
10851
|
|
|
10780
10852
|
//#endregion
|
|
10781
|
-
//#region src/
|
|
10853
|
+
//#region src/utils/validation.ts
|
|
10854
|
+
const ethAddressSchema = custom((val) => typeof val === "string" && isAddress(val), "Invalid Ethereum address");
|
|
10782
10855
|
/**
|
|
10783
|
-
*
|
|
10784
|
-
* Extends the base Viem client options with EAS-specific requirements.
|
|
10856
|
+
* Zod schema for EASClientOptions.
|
|
10785
10857
|
*/
|
|
10786
|
-
const
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
|
|
10790
|
-
|
|
10791
|
-
|
|
10792
|
-
rpcUrl: UrlSchema
|
|
10858
|
+
const EASClientOptionsSchema = object({
|
|
10859
|
+
instance: UrlSchema,
|
|
10860
|
+
accessToken: ApplicationAccessTokenSchema.optional(),
|
|
10861
|
+
easContractAddress: ethAddressSchema.optional(),
|
|
10862
|
+
schemaRegistryContractAddress: ethAddressSchema.optional(),
|
|
10863
|
+
debug: boolean$1().optional()
|
|
10793
10864
|
});
|
|
10794
10865
|
|
|
10795
10866
|
//#endregion
|
|
10796
|
-
//#region src/
|
|
10867
|
+
//#region src/eas.ts
|
|
10868
|
+
const LOGGER = createLogger();
|
|
10869
|
+
const DEFAULT_GAS_LIMIT = "0x3d0900";
|
|
10797
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
10886
|
*/
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10805
|
-
|
|
10806
|
-
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10887
|
+
var EASClient = class {
|
|
10888
|
+
options;
|
|
10889
|
+
portalClient;
|
|
10890
|
+
portalGraphql;
|
|
10891
|
+
deployedAddresses;
|
|
10892
|
+
/**
|
|
10893
|
+
* Create a new EAS client instance
|
|
10894
|
+
*
|
|
10895
|
+
* @param options - Configuration options for the EAS client
|
|
10896
|
+
*/
|
|
10897
|
+
constructor(options) {
|
|
10898
|
+
this.options = validate(EASClientOptionsSchema, options);
|
|
10899
|
+
const { client: portalClient, graphql: portalGraphql } = createPortalClient({
|
|
10900
|
+
instance: this.options.instance,
|
|
10901
|
+
accessToken: this.options.accessToken
|
|
10902
|
+
}, { fetch: requestLogger(LOGGER, "portal", fetch) });
|
|
10903
|
+
this.portalClient = portalClient;
|
|
10904
|
+
this.portalGraphql = portalGraphql;
|
|
10905
|
+
}
|
|
10906
|
+
/**
|
|
10907
|
+
* Deploy EAS contracts via Portal
|
|
10908
|
+
*
|
|
10909
|
+
* @param deployerAddress - The address that will deploy the contracts
|
|
10910
|
+
* @param forwarderAddress - Optional trusted forwarder address (defaults to zero address)
|
|
10911
|
+
* @param gasLimit - Optional gas limit for deployment transactions (defaults to "0x7a1200")
|
|
10912
|
+
* @returns Promise resolving to deployment result with contract addresses and transaction hashes
|
|
10913
|
+
*
|
|
10914
|
+
* @example
|
|
10915
|
+
* ```typescript
|
|
10916
|
+
* import { createEASClient } from "@settlemint/sdk-eas";
|
|
10917
|
+
*
|
|
10918
|
+
* const easClient = createEASClient({
|
|
10919
|
+
* instance: "https://your-portal-instance.settlemint.com",
|
|
10920
|
+
* accessToken: "your-access-token"
|
|
10921
|
+
* });
|
|
10922
|
+
*
|
|
10923
|
+
* const deployment = await easClient.deploy(
|
|
10924
|
+
* "0x1234567890123456789012345678901234567890", // deployer address
|
|
10925
|
+
* "0x0000000000000000000000000000000000000000", // forwarder (optional)
|
|
10926
|
+
* "0x7a1200" // gas limit (optional)
|
|
10927
|
+
* );
|
|
10928
|
+
*
|
|
10929
|
+
* console.log("Schema Registry:", deployment.schemaRegistryAddress);
|
|
10930
|
+
* console.log("EAS Contract:", deployment.easAddress);
|
|
10931
|
+
* ```
|
|
10932
|
+
*/
|
|
10933
|
+
async deploy(deployerAddress, forwarderAddress, gasLimit) {
|
|
10934
|
+
const defaultForwarder = forwarderAddress || ZERO_ADDRESS;
|
|
10935
|
+
const defaultGasLimit = gasLimit || "0x7a1200";
|
|
10936
|
+
try {
|
|
10937
|
+
const schemaRegistryResponse = await this.portalClient.request(GraphQLOperations.mutations.deploySchemaRegistry(this.portalGraphql), {
|
|
10938
|
+
from: deployerAddress,
|
|
10939
|
+
constructorArguments: { forwarder: defaultForwarder },
|
|
10940
|
+
gasLimit: defaultGasLimit
|
|
10941
|
+
});
|
|
10942
|
+
if (!schemaRegistryResponse.DeployContractEASSchemaRegistry?.transactionHash) {
|
|
10943
|
+
throw new Error("Schema Registry deployment failed - no transaction hash returned");
|
|
10944
|
+
}
|
|
10945
|
+
const schemaRegistryTxHash = schemaRegistryResponse.DeployContractEASSchemaRegistry.transactionHash;
|
|
10946
|
+
const schemaRegistryTransaction = await waitForTransactionReceipt(schemaRegistryTxHash, {
|
|
10947
|
+
portalGraphqlEndpoint: this.options.instance,
|
|
10948
|
+
accessToken: this.options.accessToken,
|
|
10949
|
+
timeout: 6e4
|
|
10950
|
+
});
|
|
10951
|
+
if (!schemaRegistryTransaction?.receipt?.contractAddress) {
|
|
10952
|
+
throw new Error("Schema Registry deployment failed - could not get contract address from transaction receipt.");
|
|
10953
|
+
}
|
|
10954
|
+
const schemaRegistryAddress = schemaRegistryTransaction.receipt.contractAddress;
|
|
10955
|
+
const easResponse = await this.portalClient.request(GraphQLOperations.mutations.deployEAS(this.portalGraphql), {
|
|
10956
|
+
from: deployerAddress,
|
|
10957
|
+
constructorArguments: {
|
|
10958
|
+
registry: schemaRegistryAddress,
|
|
10959
|
+
forwarder: defaultForwarder
|
|
10960
|
+
},
|
|
10961
|
+
gasLimit: defaultGasLimit
|
|
10962
|
+
});
|
|
10963
|
+
if (!easResponse.DeployContractEAS?.transactionHash) {
|
|
10964
|
+
throw new Error("EAS deployment failed - no transaction hash returned");
|
|
10965
|
+
}
|
|
10966
|
+
const easTxHash = easResponse.DeployContractEAS.transactionHash;
|
|
10967
|
+
const easTransaction = await waitForTransactionReceipt(easTxHash, {
|
|
10968
|
+
portalGraphqlEndpoint: this.options.instance,
|
|
10969
|
+
accessToken: this.options.accessToken,
|
|
10970
|
+
timeout: 6e4
|
|
10971
|
+
});
|
|
10972
|
+
if (!easTransaction?.receipt?.contractAddress) {
|
|
10973
|
+
throw new Error("EAS deployment failed - could not get contract address from transaction receipt.");
|
|
10974
|
+
}
|
|
10975
|
+
const easAddress = easTransaction.receipt.contractAddress;
|
|
10976
|
+
this.deployedAddresses = {
|
|
10977
|
+
easAddress,
|
|
10978
|
+
schemaRegistryAddress,
|
|
10979
|
+
easTransactionHash: easTxHash,
|
|
10980
|
+
schemaRegistryTransactionHash: schemaRegistryTxHash
|
|
10981
|
+
};
|
|
10982
|
+
return this.deployedAddresses;
|
|
10983
|
+
} catch (err) {
|
|
10984
|
+
const error$37 = err;
|
|
10985
|
+
throw new Error(`Failed to deploy EAS contracts: ${error$37.message}`);
|
|
10986
|
+
}
|
|
10987
|
+
}
|
|
10988
|
+
/**
|
|
10989
|
+
* Register a new schema in the EAS Schema Registry
|
|
10990
|
+
*
|
|
10991
|
+
* @param request - Schema registration request containing schema definition
|
|
10992
|
+
* @param fromAddress - Address that will register the schema
|
|
10993
|
+
* @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
|
|
10994
|
+
* @returns Promise resolving to transaction result
|
|
10995
|
+
*
|
|
10996
|
+
* @example
|
|
10997
|
+
* ```typescript
|
|
10998
|
+
* import { createEASClient } from "@settlemint/sdk-eas";
|
|
10999
|
+
*
|
|
11000
|
+
* const easClient = createEASClient({
|
|
11001
|
+
* instance: "https://your-portal-instance.settlemint.com",
|
|
11002
|
+
* accessToken: "your-access-token"
|
|
11003
|
+
* });
|
|
11004
|
+
*
|
|
11005
|
+
* const schemaResult = await easClient.registerSchema(
|
|
11006
|
+
* {
|
|
11007
|
+
* schema: "uint256 eventId, uint8 voteIndex",
|
|
11008
|
+
* resolver: "0x0000000000000000000000000000000000000000",
|
|
11009
|
+
* revocable: true
|
|
11010
|
+
* },
|
|
11011
|
+
* "0x1234567890123456789012345678901234567890" // from address
|
|
11012
|
+
* );
|
|
11013
|
+
*
|
|
11014
|
+
* console.log("Schema registered:", schemaResult.hash);
|
|
11015
|
+
* ```
|
|
11016
|
+
*/
|
|
11017
|
+
async registerSchema(request, fromAddress, gasLimit) {
|
|
11018
|
+
const schemaRegistryAddress = this.getSchemaRegistryAddress();
|
|
11019
|
+
let schemaString = request.schema;
|
|
11020
|
+
if (request.fields && !schemaString) {
|
|
11021
|
+
schemaString = this.buildSchemaString(request.fields);
|
|
11022
|
+
}
|
|
11023
|
+
if (!schemaString) {
|
|
11024
|
+
throw new Error("Schema string is required. Provide either 'schema' or 'fields'.");
|
|
11025
|
+
}
|
|
11026
|
+
try {
|
|
11027
|
+
const response = await this.portalClient.request(GraphQLOperations.mutations.registerSchema(this.portalGraphql), {
|
|
11028
|
+
address: schemaRegistryAddress,
|
|
11029
|
+
from: fromAddress,
|
|
11030
|
+
input: {
|
|
11031
|
+
schema: schemaString,
|
|
11032
|
+
resolver: request.resolver,
|
|
11033
|
+
revocable: request.revocable
|
|
11034
|
+
},
|
|
11035
|
+
gasLimit: gasLimit || DEFAULT_GAS_LIMIT
|
|
11036
|
+
});
|
|
11037
|
+
const transactionHash = response.EASSchemaRegistryRegister?.transactionHash;
|
|
11038
|
+
if (!transactionHash) {
|
|
11039
|
+
throw new Error("No transaction hash returned from Portal");
|
|
10815
11040
|
}
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
11041
|
+
return {
|
|
11042
|
+
hash: transactionHash,
|
|
11043
|
+
success: true
|
|
11044
|
+
};
|
|
11045
|
+
} catch (err) {
|
|
11046
|
+
const error$37 = err;
|
|
11047
|
+
throw new Error(`Failed to register schema: ${error$37.message}`);
|
|
11048
|
+
}
|
|
10819
11049
|
}
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
*
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
10845
|
-
*
|
|
10846
|
-
*
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
|
|
10854
|
-
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
10859
|
-
|
|
10860
|
-
|
|
10861
|
-
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
|
|
11050
|
+
/**
|
|
11051
|
+
* Create an attestation
|
|
11052
|
+
*
|
|
11053
|
+
* @param request - Attestation request containing schema and data
|
|
11054
|
+
* @param fromAddress - Address that will create the attestation
|
|
11055
|
+
* @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
|
|
11056
|
+
* @returns Promise resolving to transaction result
|
|
11057
|
+
*
|
|
11058
|
+
* @example
|
|
11059
|
+
* ```typescript
|
|
11060
|
+
* import { createEASClient } from "@settlemint/sdk-eas";
|
|
11061
|
+
*
|
|
11062
|
+
* const easClient = createEASClient({
|
|
11063
|
+
* instance: "https://your-portal-instance.settlemint.com",
|
|
11064
|
+
* accessToken: "your-access-token"
|
|
11065
|
+
* });
|
|
11066
|
+
*
|
|
11067
|
+
* const attestationResult = await easClient.attest(
|
|
11068
|
+
* {
|
|
11069
|
+
* schema: "0x1234567890123456789012345678901234567890123456789012345678901234",
|
|
11070
|
+
* data: {
|
|
11071
|
+
* recipient: "0x1234567890123456789012345678901234567890",
|
|
11072
|
+
* expirationTime: BigInt(0), // No expiration
|
|
11073
|
+
* revocable: true,
|
|
11074
|
+
* refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
11075
|
+
* data: "0x1234", // ABI-encoded data
|
|
11076
|
+
* value: BigInt(0)
|
|
11077
|
+
* }
|
|
11078
|
+
* },
|
|
11079
|
+
* "0x1234567890123456789012345678901234567890" // from address
|
|
11080
|
+
* );
|
|
11081
|
+
*
|
|
11082
|
+
* console.log("Attestation created:", attestationResult.hash);
|
|
11083
|
+
* ```
|
|
11084
|
+
*/
|
|
11085
|
+
async attest(request, fromAddress, gasLimit) {
|
|
11086
|
+
const easAddress = this.getEASAddress();
|
|
11087
|
+
try {
|
|
11088
|
+
const response = await this.portalClient.request(GraphQLOperations.mutations.attest(this.portalGraphql), {
|
|
11089
|
+
address: easAddress,
|
|
11090
|
+
from: fromAddress,
|
|
11091
|
+
input: { request: {
|
|
11092
|
+
schema: request.schema,
|
|
11093
|
+
data: {
|
|
11094
|
+
recipient: request.data.recipient,
|
|
11095
|
+
expirationTime: request.data.expirationTime.toString(),
|
|
11096
|
+
revocable: request.data.revocable,
|
|
11097
|
+
refUID: request.data.refUID,
|
|
11098
|
+
data: request.data.data,
|
|
11099
|
+
value: request.data.value?.toString() || "0"
|
|
11100
|
+
}
|
|
11101
|
+
} },
|
|
11102
|
+
gasLimit: gasLimit || DEFAULT_GAS_LIMIT
|
|
11103
|
+
});
|
|
11104
|
+
const transactionHash = response.EASAttest?.transactionHash;
|
|
11105
|
+
if (!transactionHash) {
|
|
11106
|
+
throw new Error("No transaction hash returned from Portal");
|
|
11107
|
+
}
|
|
11108
|
+
return {
|
|
11109
|
+
hash: transactionHash,
|
|
11110
|
+
success: true
|
|
11111
|
+
};
|
|
11112
|
+
} catch (err) {
|
|
11113
|
+
const error$37 = err;
|
|
11114
|
+
throw new Error(`Failed to create attestation: ${error$37.message}`);
|
|
11115
|
+
}
|
|
10865
11116
|
}
|
|
10866
|
-
|
|
10867
|
-
|
|
11117
|
+
/**
|
|
11118
|
+
* Create multiple attestations in a single transaction
|
|
11119
|
+
*
|
|
11120
|
+
* @param requests - Array of attestation requests
|
|
11121
|
+
* @param fromAddress - Address that will create the attestations
|
|
11122
|
+
* @param gasLimit - Optional gas limit for the transaction (defaults to "0x3d0900")
|
|
11123
|
+
* @returns Promise resolving to transaction result
|
|
11124
|
+
*
|
|
11125
|
+
* @example
|
|
11126
|
+
* ```typescript
|
|
11127
|
+
* import { createEASClient } from "@settlemint/sdk-eas";
|
|
11128
|
+
*
|
|
11129
|
+
* const easClient = createEASClient({
|
|
11130
|
+
* instance: "https://your-portal-instance.settlemint.com",
|
|
11131
|
+
* accessToken: "your-access-token"
|
|
11132
|
+
* });
|
|
11133
|
+
*
|
|
11134
|
+
* const multiAttestResult = await easClient.multiAttest(
|
|
11135
|
+
* [
|
|
11136
|
+
* {
|
|
11137
|
+
* schema: "0x1234567890123456789012345678901234567890123456789012345678901234",
|
|
11138
|
+
* data: {
|
|
11139
|
+
* recipient: "0x1234567890123456789012345678901234567890",
|
|
11140
|
+
* expirationTime: BigInt(0),
|
|
11141
|
+
* revocable: true,
|
|
11142
|
+
* refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
11143
|
+
* data: "0x1234",
|
|
11144
|
+
* value: BigInt(0)
|
|
11145
|
+
* }
|
|
11146
|
+
* },
|
|
11147
|
+
* {
|
|
11148
|
+
* schema: "0x5678901234567890123456789012345678901234567890123456789012345678",
|
|
11149
|
+
* data: {
|
|
11150
|
+
* recipient: "0x5678901234567890123456789012345678901234",
|
|
11151
|
+
* expirationTime: BigInt(0),
|
|
11152
|
+
* revocable: false,
|
|
11153
|
+
* refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
11154
|
+
* data: "0x5678",
|
|
11155
|
+
* value: BigInt(0)
|
|
11156
|
+
* }
|
|
11157
|
+
* }
|
|
11158
|
+
* ],
|
|
11159
|
+
* "0x1234567890123456789012345678901234567890" // from address
|
|
11160
|
+
* );
|
|
11161
|
+
*
|
|
11162
|
+
* console.log("Multiple attestations created:", multiAttestResult.hash);
|
|
11163
|
+
* ```
|
|
11164
|
+
*/
|
|
11165
|
+
async multiAttest(requests, fromAddress, gasLimit) {
|
|
11166
|
+
if (requests.length === 0) {
|
|
11167
|
+
throw new Error("At least one attestation request is required");
|
|
11168
|
+
}
|
|
11169
|
+
const easAddress = this.getEASAddress();
|
|
11170
|
+
try {
|
|
11171
|
+
const response = await this.portalClient.request(GraphQLOperations.mutations.multiAttest(this.portalGraphql), {
|
|
11172
|
+
address: easAddress,
|
|
11173
|
+
from: fromAddress,
|
|
11174
|
+
input: { multiRequests: requests.map((req) => ({
|
|
11175
|
+
schema: req.schema,
|
|
11176
|
+
data: [{
|
|
11177
|
+
recipient: req.data.recipient,
|
|
11178
|
+
expirationTime: req.data.expirationTime.toString(),
|
|
11179
|
+
revocable: req.data.revocable,
|
|
11180
|
+
refUID: req.data.refUID,
|
|
11181
|
+
data: req.data.data,
|
|
11182
|
+
value: req.data.value?.toString() || "0"
|
|
11183
|
+
}]
|
|
11184
|
+
})) },
|
|
11185
|
+
gasLimit: gasLimit || DEFAULT_GAS_LIMIT
|
|
11186
|
+
});
|
|
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
|
+
try {
|
|
11231
|
+
const response = 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 || DEFAULT_GAS_LIMIT
|
|
11242
|
+
});
|
|
11243
|
+
const transactionHash = response.EASRevoke?.transactionHash;
|
|
11244
|
+
if (!transactionHash) {
|
|
11245
|
+
throw new Error("No transaction hash returned from Portal");
|
|
11246
|
+
}
|
|
11247
|
+
return {
|
|
11248
|
+
hash: transactionHash,
|
|
11249
|
+
success: true
|
|
11250
|
+
};
|
|
11251
|
+
} catch (err) {
|
|
11252
|
+
const error$37 = err;
|
|
11253
|
+
throw new Error(`Failed to revoke attestation: ${error$37.message}`);
|
|
11254
|
+
}
|
|
10868
11255
|
}
|
|
10869
|
-
|
|
10870
|
-
|
|
11256
|
+
/**
|
|
11257
|
+
* Get a schema by UID
|
|
11258
|
+
*
|
|
11259
|
+
* TODO: Implement using The Graph subgraph for EAS data queries
|
|
11260
|
+
*/
|
|
11261
|
+
async getSchema(uid) {
|
|
11262
|
+
throw new Error(`Schema queries not implemented yet. Use The Graph subgraph for reading schema data. Schema UID: ${uid}`);
|
|
10871
11263
|
}
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
|
|
11264
|
+
/**
|
|
11265
|
+
* Get all schemas with pagination
|
|
11266
|
+
*
|
|
11267
|
+
* TODO: Implement using The Graph subgraph for EAS data queries
|
|
11268
|
+
*/
|
|
11269
|
+
async getSchemas(options) {
|
|
11270
|
+
throw new Error("Schema listing not implemented yet. Use The Graph subgraph for reading schema data.");
|
|
10876
11271
|
}
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
11272
|
+
/**
|
|
11273
|
+
* Get an attestation by UID
|
|
11274
|
+
*
|
|
11275
|
+
* TODO: Implement using The Graph subgraph for EAS data queries
|
|
11276
|
+
*/
|
|
11277
|
+
async getAttestation(uid) {
|
|
11278
|
+
throw new Error(`Attestation queries not implemented yet. Use The Graph subgraph for reading attestation data. Attestation UID: ${uid}`);
|
|
10881
11279
|
}
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
|
|
11280
|
+
/**
|
|
11281
|
+
* Get attestations with pagination and filtering
|
|
11282
|
+
*
|
|
11283
|
+
* TODO: Implement using The Graph subgraph for EAS data queries
|
|
11284
|
+
*/
|
|
11285
|
+
async getAttestations(options) {
|
|
11286
|
+
throw new Error("Attestation listing not implemented yet. Use The Graph subgraph for reading attestation data.");
|
|
11287
|
+
}
|
|
11288
|
+
/**
|
|
11289
|
+
* Check if an attestation is valid
|
|
11290
|
+
*
|
|
11291
|
+
* TODO: Implement using The Graph subgraph for EAS data queries
|
|
11292
|
+
*/
|
|
11293
|
+
async isValidAttestation(uid) {
|
|
11294
|
+
return false;
|
|
11295
|
+
}
|
|
11296
|
+
/**
|
|
11297
|
+
* Get the current timestamp from the contract
|
|
11298
|
+
*
|
|
11299
|
+
* TODO: Fix Portal GraphQL query parameter encoding or use The Graph subgraph
|
|
11300
|
+
*/
|
|
11301
|
+
async getTimestamp() {
|
|
11302
|
+
throw new Error("Timestamp query not implemented yet. Fix Portal query parameters or use The Graph subgraph.");
|
|
11303
|
+
}
|
|
11304
|
+
/**
|
|
11305
|
+
* Get client configuration
|
|
11306
|
+
*/
|
|
11307
|
+
getOptions() {
|
|
11308
|
+
return { ...this.options };
|
|
11309
|
+
}
|
|
11310
|
+
/**
|
|
11311
|
+
* Get the Portal client instance for advanced operations
|
|
11312
|
+
*/
|
|
11313
|
+
getPortalClient() {
|
|
11314
|
+
return this.portalClient;
|
|
11315
|
+
}
|
|
11316
|
+
/**
|
|
11317
|
+
* Get current contract addresses
|
|
11318
|
+
*/
|
|
11319
|
+
getContractAddresses() {
|
|
11320
|
+
return {
|
|
11321
|
+
easAddress: this.options.easContractAddress || this.deployedAddresses?.easAddress,
|
|
11322
|
+
schemaRegistryAddress: this.options.schemaRegistryContractAddress || this.deployedAddresses?.schemaRegistryAddress
|
|
11323
|
+
};
|
|
11324
|
+
}
|
|
11325
|
+
getEASAddress() {
|
|
11326
|
+
if (this.options.easContractAddress) {
|
|
11327
|
+
return this.options.easContractAddress;
|
|
11328
|
+
}
|
|
11329
|
+
if (this.deployedAddresses?.easAddress) {
|
|
11330
|
+
return this.deployedAddresses.easAddress;
|
|
10888
11331
|
}
|
|
10889
|
-
|
|
11332
|
+
throw new Error("EAS contract address not available. Please provide it in options or deploy contracts first.");
|
|
10890
11333
|
}
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
|
|
10898
|
-
|
|
11334
|
+
getSchemaRegistryAddress() {
|
|
11335
|
+
if (this.options.schemaRegistryContractAddress) {
|
|
11336
|
+
return this.options.schemaRegistryContractAddress;
|
|
11337
|
+
}
|
|
11338
|
+
if (this.deployedAddresses?.schemaRegistryAddress) {
|
|
11339
|
+
return this.deployedAddresses.schemaRegistryAddress;
|
|
11340
|
+
}
|
|
11341
|
+
throw new Error("Schema Registry contract address not available. Please provide it in options or deploy contracts first.");
|
|
11342
|
+
}
|
|
11343
|
+
buildSchemaString(fields) {
|
|
11344
|
+
return fields.map((field) => `${field.type} ${field.name}`).join(", ");
|
|
11345
|
+
}
|
|
11346
|
+
};
|
|
10899
11347
|
/**
|
|
10900
|
-
*
|
|
11348
|
+
* Create an EAS client instance
|
|
10901
11349
|
*
|
|
10902
|
-
* @param options - Configuration options for the client
|
|
10903
|
-
* @returns
|
|
10904
|
-
* @throws Will throw an error if the options fail validation
|
|
11350
|
+
* @param options - Configuration options for the EAS client
|
|
11351
|
+
* @returns EAS client instance
|
|
10905
11352
|
*
|
|
10906
11353
|
* @example
|
|
10907
|
-
* ```
|
|
10908
|
-
* import { createEASClient } from
|
|
11354
|
+
* ```typescript
|
|
11355
|
+
* import { createEASClient } from "@settlemint/sdk-eas";
|
|
10909
11356
|
*
|
|
10910
|
-
* const
|
|
10911
|
-
*
|
|
10912
|
-
*
|
|
10913
|
-
* accessToken: "your-access-token",
|
|
10914
|
-
* chainId: "1",
|
|
10915
|
-
* chainName: "Ethereum",
|
|
10916
|
-
* rpcUrl: "http://localhost:8545"
|
|
11357
|
+
* const easClient = createEASClient({
|
|
11358
|
+
* instance: "https://your-portal-instance.settlemint.com",
|
|
11359
|
+
* accessToken: "your-access-token"
|
|
10917
11360
|
* });
|
|
11361
|
+
*
|
|
11362
|
+
* // Use the client
|
|
11363
|
+
* const deployment = await easClient.deploy("0x1234...deployer-address");
|
|
10918
11364
|
* ```
|
|
10919
11365
|
*/
|
|
10920
11366
|
function createEASClient(options) {
|
|
10921
|
-
|
|
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
|
-
};
|
|
11367
|
+
return new EASClient(options);
|
|
10967
11368
|
}
|
|
10968
11369
|
|
|
10969
11370
|
//#endregion
|
|
10970
|
-
export { EAS_FIELD_TYPES, createEASClient };
|
|
11371
|
+
export { EASClient, EASClientOptionsSchema, EAS_FIELD_TYPES, GraphQLOperations, ZERO_ADDRESS, ZERO_BYTES32, createEASClient };
|
|
10971
11372
|
//# sourceMappingURL=eas.js.map
|