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