@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/browser/eas.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { isAddress
|
|
1
|
+
import { SchemaRegistry } from "@ethereum-attestation-service/eas-sdk";
|
|
2
|
+
import { AccessTokenSchema, UrlSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
3
|
+
import { getPublicClient, getWalletClient } from "@settlemint/sdk-viem";
|
|
4
|
+
import { isAddress } from "viem";
|
|
5
|
+
import { JsonRpcProvider, Wallet } from "ethers";
|
|
5
6
|
|
|
6
7
|
//#region rolldown:runtime
|
|
7
8
|
var __defProp = Object.defineProperty;
|
|
@@ -12,79 +13,6 @@ var __export = (target, all) => {
|
|
|
12
13
|
});
|
|
13
14
|
};
|
|
14
15
|
|
|
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
|
-
|
|
88
16
|
//#endregion
|
|
89
17
|
//#region ../../node_modules/zod/dist/esm/v4/core/core.js
|
|
90
18
|
function $constructor(name, initializer$2, params) {
|
|
@@ -10850,523 +10778,194 @@ var classic_default = external_exports;
|
|
|
10850
10778
|
var v4_default = classic_default;
|
|
10851
10779
|
|
|
10852
10780
|
//#endregion
|
|
10853
|
-
//#region src/
|
|
10854
|
-
const ethAddressSchema = custom((val) => typeof val === "string" && isAddress(val), "Invalid Ethereum address");
|
|
10781
|
+
//#region src/client-options.schema.ts
|
|
10855
10782
|
/**
|
|
10856
|
-
*
|
|
10783
|
+
* Schema for validating EAS client configuration options.
|
|
10784
|
+
* Extends the base Viem client options with EAS-specific requirements.
|
|
10857
10785
|
*/
|
|
10858
|
-
const
|
|
10859
|
-
|
|
10860
|
-
|
|
10861
|
-
|
|
10862
|
-
|
|
10863
|
-
|
|
10786
|
+
const ClientOptionsSchema = object({
|
|
10787
|
+
schemaRegistryAddress: string$1().refine(isAddress, "Invalid Ethereum address format"),
|
|
10788
|
+
attestationAddress: string$1().refine(isAddress, "Invalid Ethereum address format"),
|
|
10789
|
+
accessToken: AccessTokenSchema,
|
|
10790
|
+
chainId: string$1().min(1),
|
|
10791
|
+
chainName: string$1().min(1),
|
|
10792
|
+
rpcUrl: UrlSchema
|
|
10864
10793
|
});
|
|
10865
10794
|
|
|
10866
10795
|
//#endregion
|
|
10867
|
-
//#region src/
|
|
10868
|
-
const LOGGER = createLogger();
|
|
10869
|
-
const DEFAULT_GAS_LIMIT = "0x3d0900";
|
|
10796
|
+
//#region src/ethers-adapter.ts
|
|
10870
10797
|
/**
|
|
10871
|
-
*
|
|
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
|
-
* ```
|
|
10798
|
+
* Converts a viem PublicClient to an ethers JsonRpcProvider
|
|
10886
10799
|
*/
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
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");
|
|
11040
|
-
}
|
|
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
|
-
}
|
|
11049
|
-
}
|
|
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
|
-
}
|
|
11116
|
-
}
|
|
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");
|
|
10800
|
+
function publicClientToProvider(client) {
|
|
10801
|
+
const { chain, transport } = client;
|
|
10802
|
+
if (!chain) throw new Error("Chain is required");
|
|
10803
|
+
const network = {
|
|
10804
|
+
chainId: chain.id,
|
|
10805
|
+
name: chain.name,
|
|
10806
|
+
ensAddress: chain.contracts?.ensRegistry?.address
|
|
10807
|
+
};
|
|
10808
|
+
if (transport.type === "fallback") {
|
|
10809
|
+
const providers = transport.transports.map(({ value }) => {
|
|
10810
|
+
if (!value?.url) return null;
|
|
10811
|
+
try {
|
|
10812
|
+
return new JsonRpcProvider(value.url, network);
|
|
10813
|
+
} catch {
|
|
10814
|
+
return null;
|
|
11246
10815
|
}
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11250
|
-
};
|
|
11251
|
-
} catch (err) {
|
|
11252
|
-
const error$37 = err;
|
|
11253
|
-
throw new Error(`Failed to revoke attestation: ${error$37.message}`);
|
|
11254
|
-
}
|
|
11255
|
-
}
|
|
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}`);
|
|
11263
|
-
}
|
|
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.");
|
|
11271
|
-
}
|
|
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}`);
|
|
10816
|
+
}).filter((provider) => provider != null);
|
|
10817
|
+
if (providers.length === 0) throw new Error("No valid RPC URLs found");
|
|
10818
|
+
return providers[0];
|
|
11279
10819
|
}
|
|
11280
|
-
|
|
11281
|
-
|
|
11282
|
-
|
|
11283
|
-
|
|
11284
|
-
|
|
11285
|
-
|
|
11286
|
-
|
|
11287
|
-
|
|
11288
|
-
|
|
11289
|
-
|
|
11290
|
-
|
|
11291
|
-
|
|
11292
|
-
|
|
11293
|
-
|
|
11294
|
-
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
|
|
11298
|
-
|
|
11299
|
-
|
|
11300
|
-
|
|
11301
|
-
|
|
11302
|
-
|
|
10820
|
+
return new JsonRpcProvider(transport.url, network);
|
|
10821
|
+
}
|
|
10822
|
+
/**
|
|
10823
|
+
* Converts a viem WalletClient to an ethers Wallet
|
|
10824
|
+
*/
|
|
10825
|
+
function walletClientToSigner(client) {
|
|
10826
|
+
const { account, chain, transport } = client;
|
|
10827
|
+
if (!chain) throw new Error("Chain is required");
|
|
10828
|
+
if (!account) throw new Error("Account is required");
|
|
10829
|
+
const network = {
|
|
10830
|
+
chainId: chain.id,
|
|
10831
|
+
name: chain.name,
|
|
10832
|
+
ensAddress: chain.contracts?.ensRegistry?.address
|
|
10833
|
+
};
|
|
10834
|
+
const provider = new JsonRpcProvider(transport.url, network);
|
|
10835
|
+
const privateKey = account.privateKey;
|
|
10836
|
+
if (!privateKey || typeof privateKey !== "string") {
|
|
10837
|
+
throw new Error("Private key is required and must be a string");
|
|
10838
|
+
}
|
|
10839
|
+
return new Wallet(privateKey, provider);
|
|
10840
|
+
}
|
|
10841
|
+
|
|
10842
|
+
//#endregion
|
|
10843
|
+
//#region src/types.ts
|
|
10844
|
+
/**
|
|
10845
|
+
* Supported field types for EAS schema fields.
|
|
10846
|
+
* Maps to the Solidity types that can be used in EAS schemas.
|
|
10847
|
+
*/
|
|
10848
|
+
const EAS_FIELD_TYPES = {
|
|
10849
|
+
string: "string",
|
|
10850
|
+
address: "address",
|
|
10851
|
+
bool: "bool",
|
|
10852
|
+
bytes: "bytes",
|
|
10853
|
+
bytes32: "bytes32",
|
|
10854
|
+
uint256: "uint256",
|
|
10855
|
+
int256: "int256",
|
|
10856
|
+
uint8: "uint8",
|
|
10857
|
+
int8: "int8"
|
|
10858
|
+
};
|
|
10859
|
+
|
|
10860
|
+
//#endregion
|
|
10861
|
+
//#region src/validation.ts
|
|
10862
|
+
function validateFieldName(name) {
|
|
10863
|
+
if (!name) {
|
|
10864
|
+
throw new Error("Field name cannot be empty");
|
|
11303
10865
|
}
|
|
11304
|
-
|
|
11305
|
-
|
|
11306
|
-
*/
|
|
11307
|
-
getOptions() {
|
|
11308
|
-
return { ...this.options };
|
|
10866
|
+
if (name.includes(" ")) {
|
|
10867
|
+
throw new Error("Field name cannot contain spaces");
|
|
11309
10868
|
}
|
|
11310
|
-
|
|
11311
|
-
|
|
11312
|
-
*/
|
|
11313
|
-
getPortalClient() {
|
|
11314
|
-
return this.portalClient;
|
|
10869
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
|
|
10870
|
+
throw new Error("Field name must start with a letter or underscore and contain only alphanumeric characters and underscores");
|
|
11315
10871
|
}
|
|
11316
|
-
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
return {
|
|
11321
|
-
easAddress: this.options.easContractAddress || this.deployedAddresses?.easAddress,
|
|
11322
|
-
schemaRegistryAddress: this.options.schemaRegistryContractAddress || this.deployedAddresses?.schemaRegistryAddress
|
|
11323
|
-
};
|
|
10872
|
+
}
|
|
10873
|
+
function validateFieldType(type) {
|
|
10874
|
+
if (!(type in EAS_FIELD_TYPES)) {
|
|
10875
|
+
throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(", ")}`);
|
|
11324
10876
|
}
|
|
11325
|
-
|
|
11326
|
-
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
if (this.deployedAddresses?.easAddress) {
|
|
11330
|
-
return this.deployedAddresses.easAddress;
|
|
11331
|
-
}
|
|
11332
|
-
throw new Error("EAS contract address not available. Please provide it in options or deploy contracts first.");
|
|
10877
|
+
}
|
|
10878
|
+
function validateSchemaFields(fields) {
|
|
10879
|
+
if (!fields || fields.length === 0) {
|
|
10880
|
+
throw new Error("Schema must have at least one field");
|
|
11333
10881
|
}
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
10882
|
+
const seenNames = new Set();
|
|
10883
|
+
for (const field of fields) {
|
|
10884
|
+
validateFieldName(field.name);
|
|
10885
|
+
validateFieldType(field.type);
|
|
10886
|
+
if (seenNames.has(field.name)) {
|
|
10887
|
+
throw new Error(`Duplicate field name: ${field.name}`);
|
|
11337
10888
|
}
|
|
11338
|
-
|
|
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(", ");
|
|
10889
|
+
seenNames.add(field.name);
|
|
11345
10890
|
}
|
|
11346
|
-
}
|
|
10891
|
+
}
|
|
10892
|
+
function buildSchemaString(fields) {
|
|
10893
|
+
validateSchemaFields(fields);
|
|
10894
|
+
return fields.map((field) => `${field.type} ${field.name}`).join(", ");
|
|
10895
|
+
}
|
|
10896
|
+
|
|
10897
|
+
//#endregion
|
|
10898
|
+
//#region src/eas.ts
|
|
11347
10899
|
/**
|
|
11348
|
-
*
|
|
10900
|
+
* Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
11349
10901
|
*
|
|
11350
|
-
* @param options - Configuration options for the
|
|
11351
|
-
* @returns EAS client instance
|
|
10902
|
+
* @param options - Configuration options for the client
|
|
10903
|
+
* @returns An object containing the EAS client instance
|
|
10904
|
+
* @throws Will throw an error if the options fail validation
|
|
11352
10905
|
*
|
|
11353
10906
|
* @example
|
|
11354
|
-
* ```
|
|
11355
|
-
* import { createEASClient } from
|
|
10907
|
+
* ```ts
|
|
10908
|
+
* import { createEASClient } from '@settlemint/sdk-eas';
|
|
11356
10909
|
*
|
|
11357
|
-
* const
|
|
11358
|
-
*
|
|
11359
|
-
*
|
|
10910
|
+
* const client = createEASClient({
|
|
10911
|
+
* schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
10912
|
+
* attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
10913
|
+
* accessToken: "your-access-token",
|
|
10914
|
+
* chainId: "1",
|
|
10915
|
+
* chainName: "Ethereum",
|
|
10916
|
+
* rpcUrl: "http://localhost:8545"
|
|
11360
10917
|
* });
|
|
11361
|
-
*
|
|
11362
|
-
* // Use the client
|
|
11363
|
-
* const deployment = await easClient.deploy("0x1234...deployer-address");
|
|
11364
10918
|
* ```
|
|
11365
10919
|
*/
|
|
11366
10920
|
function createEASClient(options) {
|
|
11367
|
-
|
|
10921
|
+
validate(ClientOptionsSchema, options);
|
|
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
10967
|
}
|
|
11369
10968
|
|
|
11370
10969
|
//#endregion
|
|
11371
|
-
export {
|
|
10970
|
+
export { EAS_FIELD_TYPES, createEASClient };
|
|
11372
10971
|
//# sourceMappingURL=eas.js.map
|