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