@show-karma/karma-gap-sdk 0.4.15 → 0.4.16

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.
Files changed (188) hide show
  1. package/.cursorrules +43 -0
  2. package/core/abi/AirdropNFT.json +1 -1
  3. package/core/abi/Allo.json +860 -860
  4. package/core/abi/AlloRegistry.json +578 -578
  5. package/core/abi/CommunityResolverABI.json +506 -506
  6. package/core/abi/Donations.json +251 -251
  7. package/core/abi/EAS.json +1 -1
  8. package/core/abi/MultiAttester.json +746 -746
  9. package/core/abi/ProjectResolver.json +574 -574
  10. package/core/abi/SchemaRegistry.json +1 -1
  11. package/core/abi/index.ts +21 -0
  12. package/core/class/AllGapSchemas.ts +21 -0
  13. package/core/class/Attestation.ts +429 -0
  14. package/core/class/Fetcher.ts +224 -0
  15. package/core/class/GAP.ts +481 -0
  16. package/core/class/GapSchema.ts +93 -0
  17. package/core/class/Gelato/{Gelato.js → Gelato.ts} +23 -0
  18. package/core/class/GrantProgramRegistry/Allo.ts +188 -0
  19. package/core/class/GrantProgramRegistry/AlloRegistry.ts +101 -0
  20. package/core/class/GraphQL/AxiosGQL.ts +29 -0
  21. package/core/class/GraphQL/EASClient.ts +34 -0
  22. package/core/class/GraphQL/GapEasClient.ts +869 -0
  23. package/core/class/Schema.ts +659 -0
  24. package/core/class/SchemaError.ts +42 -0
  25. package/core/class/contract/GapContract.ts +457 -0
  26. package/core/class/entities/Community.ts +148 -0
  27. package/core/class/entities/ContributorProfile.ts +108 -0
  28. package/core/class/entities/Grant.ts +321 -0
  29. package/core/class/entities/GrantUpdate.ts +187 -0
  30. package/core/class/entities/MemberOf.ts +52 -0
  31. package/core/class/entities/Milestone.ts +898 -0
  32. package/core/class/entities/Project.ts +672 -0
  33. package/core/class/entities/ProjectImpact.ts +170 -0
  34. package/core/class/entities/ProjectMilestone.ts +254 -0
  35. package/core/class/entities/ProjectPointer.ts +39 -0
  36. package/core/class/entities/ProjectUpdate.ts +176 -0
  37. package/core/class/entities/Track.ts +32 -0
  38. package/core/class/karma-indexer/GapIndexerClient.ts +383 -0
  39. package/core/class/karma-indexer/api/GapIndexerApi.ts +446 -0
  40. package/core/class/karma-indexer/api/types.ts +313 -0
  41. package/core/class/remote-storage/IpfsStorage.ts +76 -0
  42. package/core/class/remote-storage/RemoteStorage.ts +65 -0
  43. package/core/class/types/allo.ts +93 -0
  44. package/core/class/types/attestations.ts +223 -0
  45. package/core/consts.ts +775 -0
  46. package/core/scripts/create-grant.ts +102 -0
  47. package/core/scripts/create-program.ts +43 -0
  48. package/core/scripts/create-schemas.ts +65 -0
  49. package/core/scripts/deploy.ts +65 -0
  50. package/core/scripts/index.ts +1 -0
  51. package/core/scripts/milestone-multi-grants.ts +125 -0
  52. package/core/shared/types.ts +13 -0
  53. package/core/types.ts +224 -0
  54. package/core/utils/gelato/send-gelato-txn.ts +114 -0
  55. package/core/utils/gelato/sponsor-handler.ts +77 -0
  56. package/core/utils/gelato/watch-gelato-txn.ts +67 -0
  57. package/core/utils/get-date.ts +3 -0
  58. package/core/utils/get-ipfs-data.ts +13 -0
  59. package/core/utils/get-web3-provider.ts +18 -0
  60. package/core/utils/gql-queries.ts +133 -0
  61. package/core/utils/map-filter.ts +21 -0
  62. package/core/utils/serialize-bigint.ts +7 -0
  63. package/core/utils/to-unix.ts +18 -0
  64. package/create-community-example.ts +119 -0
  65. package/csv-upload/README.md +74 -0
  66. package/csv-upload/config.ts +41 -0
  67. package/csv-upload/example.csv +2 -0
  68. package/csv-upload/keys.example.json +8 -0
  69. package/csv-upload/scripts/run.ts +417 -0
  70. package/csv-upload/types.ts +39 -0
  71. package/docs/.gitkeep +0 -0
  72. package/docs/images/attestation-architecture.png +0 -0
  73. package/docs/images/dfd-get-projects.png +0 -0
  74. package/gap-schema.yaml +155 -0
  75. package/milestone-workflow-example.ts +353 -0
  76. package/package.json +45 -39
  77. package/readme.md +872 -0
  78. package/schemas/.gitkeep +0 -0
  79. package/schemas/GAP-schemas-1692135812877.json +33 -0
  80. package/test-file-indexer-api.ts +25 -0
  81. package/tsconfig.json +26 -0
  82. package/core/abi/index.d.ts +0 -1114
  83. package/core/abi/index.js +0 -26
  84. package/core/class/AllGapSchemas.d.ts +0 -9
  85. package/core/class/AllGapSchemas.js +0 -19
  86. package/core/class/Attestation.d.ts +0 -173
  87. package/core/class/Attestation.js +0 -333
  88. package/core/class/Fetcher.d.ts +0 -175
  89. package/core/class/Fetcher.js +0 -13
  90. package/core/class/GAP.d.ts +0 -254
  91. package/core/class/GAP.js +0 -289
  92. package/core/class/GapSchema.d.ts +0 -34
  93. package/core/class/GapSchema.js +0 -62
  94. package/core/class/GrantProgramRegistry/Allo.d.ts +0 -17
  95. package/core/class/GrantProgramRegistry/Allo.js +0 -137
  96. package/core/class/GrantProgramRegistry/AlloRegistry.d.ts +0 -15
  97. package/core/class/GrantProgramRegistry/AlloRegistry.js +0 -70
  98. package/core/class/GraphQL/AxiosGQL.d.ts +0 -6
  99. package/core/class/GraphQL/AxiosGQL.js +0 -25
  100. package/core/class/GraphQL/EASClient.d.ts +0 -16
  101. package/core/class/GraphQL/EASClient.js +0 -26
  102. package/core/class/GraphQL/GapEasClient.d.ts +0 -71
  103. package/core/class/GraphQL/GapEasClient.js +0 -451
  104. package/core/class/GraphQL/index.js +0 -19
  105. package/core/class/Schema.d.ts +0 -233
  106. package/core/class/Schema.js +0 -488
  107. package/core/class/SchemaError.d.ts +0 -30
  108. package/core/class/SchemaError.js +0 -39
  109. package/core/class/contract/GapContract.d.ts +0 -102
  110. package/core/class/contract/GapContract.js +0 -285
  111. package/core/class/entities/Community.d.ts +0 -34
  112. package/core/class/entities/Community.js +0 -109
  113. package/core/class/entities/ContributorProfile.d.ts +0 -41
  114. package/core/class/entities/ContributorProfile.js +0 -69
  115. package/core/class/entities/Grant.d.ts +0 -54
  116. package/core/class/entities/Grant.js +0 -223
  117. package/core/class/entities/GrantUpdate.d.ts +0 -40
  118. package/core/class/entities/GrantUpdate.js +0 -114
  119. package/core/class/entities/MemberOf.d.ts +0 -11
  120. package/core/class/entities/MemberOf.js +0 -33
  121. package/core/class/entities/Milestone.d.ts +0 -168
  122. package/core/class/entities/Milestone.js +0 -657
  123. package/core/class/entities/Project.d.ts +0 -92
  124. package/core/class/entities/Project.js +0 -418
  125. package/core/class/entities/ProjectImpact.d.ts +0 -50
  126. package/core/class/entities/ProjectImpact.js +0 -112
  127. package/core/class/entities/ProjectMilestone.d.ts +0 -60
  128. package/core/class/entities/ProjectMilestone.js +0 -174
  129. package/core/class/entities/ProjectPointer.d.ts +0 -12
  130. package/core/class/entities/ProjectPointer.js +0 -22
  131. package/core/class/entities/ProjectUpdate.d.ts +0 -50
  132. package/core/class/entities/ProjectUpdate.js +0 -110
  133. package/core/class/entities/Track.d.ts +0 -16
  134. package/core/class/entities/Track.js +0 -21
  135. package/core/class/entities/index.js +0 -26
  136. package/core/class/index.js +0 -26
  137. package/core/class/karma-indexer/GapIndexerClient.d.ts +0 -66
  138. package/core/class/karma-indexer/GapIndexerClient.js +0 -207
  139. package/core/class/karma-indexer/api/GapIndexerApi.d.ts +0 -73
  140. package/core/class/karma-indexer/api/GapIndexerApi.js +0 -256
  141. package/core/class/karma-indexer/api/types.d.ts +0 -295
  142. package/core/class/karma-indexer/api/types.js +0 -2
  143. package/core/class/remote-storage/IpfsStorage.d.ts +0 -23
  144. package/core/class/remote-storage/IpfsStorage.js +0 -56
  145. package/core/class/remote-storage/RemoteStorage.d.ts +0 -41
  146. package/core/class/remote-storage/RemoteStorage.js +0 -38
  147. package/core/class/types/allo.d.ts +0 -78
  148. package/core/class/types/allo.js +0 -2
  149. package/core/class/types/attestations.d.ts +0 -168
  150. package/core/class/types/attestations.js +0 -66
  151. package/core/consts.d.ts +0 -48
  152. package/core/consts.js +0 -641
  153. package/core/index.js +0 -24
  154. package/core/shared/types.d.ts +0 -6
  155. package/core/shared/types.js +0 -2
  156. package/core/types.d.ts +0 -131
  157. package/core/types.js +0 -13
  158. package/core/utils/gelato/index.js +0 -19
  159. package/core/utils/gelato/send-gelato-txn.d.ts +0 -55
  160. package/core/utils/gelato/send-gelato-txn.js +0 -100
  161. package/core/utils/gelato/sponsor-handler.d.ts +0 -9
  162. package/core/utils/gelato/sponsor-handler.js +0 -60
  163. package/core/utils/gelato/watch-gelato-txn.d.ts +0 -7
  164. package/core/utils/gelato/watch-gelato-txn.js +0 -63
  165. package/core/utils/get-date.d.ts +0 -1
  166. package/core/utils/get-date.js +0 -7
  167. package/core/utils/get-ipfs-data.d.ts +0 -1
  168. package/core/utils/get-ipfs-data.js +0 -20
  169. package/core/utils/get-web3-provider.d.ts +0 -2
  170. package/core/utils/get-web3-provider.js +0 -18
  171. package/core/utils/gql-queries.d.ts +0 -12
  172. package/core/utils/gql-queries.js +0 -90
  173. package/core/utils/index.js +0 -23
  174. package/core/utils/map-filter.d.ts +0 -8
  175. package/core/utils/map-filter.js +0 -20
  176. package/core/utils/serialize-bigint.d.ts +0 -1
  177. package/core/utils/serialize-bigint.js +0 -8
  178. package/core/utils/to-unix.d.ts +0 -1
  179. package/core/utils/to-unix.js +0 -25
  180. package/index.js +0 -17
  181. /package/core/class/GraphQL/{index.d.ts → index.ts} +0 -0
  182. /package/core/class/entities/{index.d.ts → index.ts} +0 -0
  183. /package/core/class/{index.d.ts → index.ts} +0 -0
  184. /package/core/{index.d.ts → index.ts} +0 -0
  185. /package/core/utils/gelato/{index.d.ts → index.ts} +0 -0
  186. /package/core/utils/{index.d.ts → index.ts} +0 -0
  187. /package/{core/class/Gelato/Gelato.d.ts → csv-upload/.gitkeep} +0 -0
  188. /package/{index.d.ts → index.ts} +0 -0
@@ -1,488 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Schema = void 0;
4
- const eas_sdk_1 = require("@ethereum-attestation-service/eas-sdk");
5
- const SchemaError_1 = require("./SchemaError");
6
- const consts_1 = require("../consts");
7
- const GapContract_1 = require("./contract/GapContract");
8
- const ethers_1 = require("ethers");
9
- /**
10
- * Represents the EAS Schema and provides methods to encode and decode the schema,
11
- * and validate the schema references.
12
- *
13
- * Also provides a set of static methods to manage the schema list.
14
- *
15
- * @example
16
- * ```
17
- * // You may or not attribute a schema to a variable.
18
- * new Schema({
19
- * name: "Grantee",
20
- * schema: [{ type: "bool", name: "grantee", value: true }],
21
- * uid: "0x000000000
22
- * });
23
- *
24
- * const granteeDetails = new Schema({
25
- * name: "GranteeDetails",
26
- * schema: [
27
- * { type: "bool", name: "name", value: null }
28
- * { type: "bool", name: "description", value: null }
29
- * { type: "bool", name: "imageURL", value: null }
30
- * ],
31
- * uid: "0x000000000,
32
- * references: "Grantee"
33
- * });
34
- *
35
- * // Validate if references are correct and all of them exist.
36
- * Schema.validate();
37
- *
38
- * // Gets the schema by name.
39
- * const grantee = Schema.get("Grantee");
40
- *
41
- * // Sets a single schema value.
42
- * grantee.setValue("grantee", true);
43
- *
44
- * // Sets multiple schema values.
45
- * granteeDetails.setValues({ name: "John Doe", description: "A description", imageURL: "https://example.com/image.png" });
46
- *
47
- * // Gets the schema encoded data, used to create an attestation.
48
- * const encodedGrantee = grantee.encode();
49
- *
50
- * // Verify if schema exists
51
- * Schema.exists("Grantee"); // true
52
- * Schema.exists("GranteeDetails"); // true
53
- * Schema.exists("GranteeDetails2"); // false
54
- *
55
- * // Get all schemas.
56
- * Schema.getAll(); // [grantee, granteeDetails]
57
- *
58
- * // Get all schema names.
59
- * Schema.getNames(); // ["Grantee", "GranteeDetails"]
60
- *
61
- * // Get many schemas by name. Throws an error if schema does not exist.
62
- * Schema.getMany(["Grantee", "GranteeDetails"]); // [grantee, granteeDetails]
63
- *
64
- * // Replace all schemas. Throws an error if schema does not exist.
65
- * Schema.replaceAll([grantee, granteeDetails]);
66
- *
67
- * // Replace one schema. This will replace a schema using the inbound schema name.. Throws an error if schema does not exist.
68
- * Schema.replaceOne(grantee);
69
- *
70
- * // Converts a raw schema string (e.g. "uint256 id, string name") to a SchemaItem[].
71
- * const schema = Schema.rawToObject("uint256 id, string name");
72
- * ```
73
- */
74
- class Schema {
75
- /**
76
- * Creates a new schema instance
77
- * @param args
78
- * @param strict If true, will throw an error if schema reference is not valid. With this option, user should add schemas
79
- * in a strict order.
80
- */
81
- constructor(args, gap, strict = false, ignoreSchema = false) {
82
- this._schema = [];
83
- this.assert(args, strict);
84
- this.gap = gap;
85
- this._schema = args.schema;
86
- this.uid = args.uid;
87
- this.name = args.name;
88
- this.references = args.references;
89
- this.revocable = args.revocable || true;
90
- this.oldSchemas = args.oldSchemas || null;
91
- this.encoder = new eas_sdk_1.SchemaEncoder(this.raw);
92
- }
93
- /**
94
- * Encode the schema to be used as payload in the attestation
95
- * @returns
96
- */
97
- encode(schema) {
98
- return this.encoder.encodeData(schema || this.schema);
99
- }
100
- /**
101
- * Set a schema field value.
102
- * @param key
103
- * @param value
104
- */
105
- setValue(key, value) {
106
- const idx = this._schema.findIndex((item) => item.name === key);
107
- if (!~idx)
108
- throw new SchemaError_1.SchemaError("INVALID_SCHEMA_FIELD", `Field ${key} not found in schema ${this.name}`);
109
- this.assertField(this._schema[idx], value);
110
- this._schema[idx].value = value;
111
- }
112
- /**
113
- * Tests if the current schema is a JSON Schema.
114
- *
115
- * @returns boolean
116
- */
117
- isJsonSchema() {
118
- return !!this.schema.find((s) => s.name === "json" && s.type === "string");
119
- }
120
- assertField(item, value) {
121
- const { type, name } = item;
122
- if (type.includes("uint") && /\D/.test(value)) {
123
- throw new SchemaError_1.SchemaError("INVALID_SCHEMA_FIELD", `Field ${name} is of type ${type} but value is not a number.`);
124
- }
125
- if (type.includes("address") &&
126
- !(0, ethers_1.isAddress)(value) &&
127
- value !== consts_1.zeroAddress) {
128
- throw new SchemaError_1.SchemaError("INVALID_SCHEMA_FIELD", `Field ${name} is of type ${type} but value is not a valid address.`);
129
- }
130
- if (type.includes("bytes") && !value.startsWith("0x")) {
131
- throw new SchemaError_1.SchemaError("INVALID_SCHEMA_FIELD", `Field ${name} is of type ${type} but value is not a valid hex string.`);
132
- }
133
- if (type.includes("bool") &&
134
- (!["true", "false", true, false].includes(value) ||
135
- typeof value !== "boolean")) {
136
- throw new SchemaError_1.SchemaError("INVALID_SCHEMA_FIELD", `Field ${name} is of type ${type} but value is not a valid boolean.`);
137
- }
138
- if (type.includes("tuple") && !Array.isArray(value)) {
139
- throw new SchemaError_1.SchemaError("INVALID_SCHEMA_FIELD", `Field ${name} is of type ${type} but value is not a valid array.`);
140
- }
141
- if (type === "string" && name === "json") {
142
- try {
143
- JSON.parse(value);
144
- }
145
- catch (error) {
146
- throw new SchemaError_1.SchemaError("INVALID_SCHEMA_FIELD", `Field ${name} is of type ${type} but value is not a valid JSON string.`, error);
147
- }
148
- }
149
- }
150
- /**
151
- * Asserts if schema is valid.
152
- * > Does not check references if `strict = false`. To check references use `Schema.validate()`
153
- * @param args
154
- */
155
- assert(args, strict = false) {
156
- const { name, schema, uid, references } = args;
157
- if (!name) {
158
- throw new SchemaError_1.SchemaError("MISSING_FIELD", "Schema name is required");
159
- }
160
- if (!schema && !Array.isArray(schema)) {
161
- throw new SchemaError_1.SchemaError("MISSING_FIELD", "Schema must be an array.");
162
- }
163
- // if (!uid) {
164
- // throw new SchemaError("MISSING_FIELD", "Schema uid is required");
165
- // }
166
- if (strict && references && !Schema.exists(references, this.gap.network)) {
167
- throw new SchemaError_1.SchemaError("INVALID_REFERENCE", `Schema ${name} references ${references} but it does not exist.`);
168
- }
169
- }
170
- /**
171
- * Attest off chain data
172
- * @returns
173
- */
174
- async attestOffchain({ data, signer, to, refUID }) {
175
- const eas = await this.gap.eas.getOffchain();
176
- const payload = {
177
- data,
178
- version: eas.version,
179
- revocable: this.revocable,
180
- expirationTime: 0n,
181
- recipient: to,
182
- refUID,
183
- schema: this.raw,
184
- time: BigInt((Date.now() / 1000).toFixed(0)),
185
- };
186
- return eas.signOffchainAttestation(payload, signer);
187
- }
188
- /**
189
- * Revokes one off chain attestation by its UID.
190
- * @param uid
191
- * @param signer
192
- * @returns
193
- */
194
- async revokeOffchain(uid, signer) {
195
- const eas = this.gap.eas.connect(signer);
196
- return eas.revokeOffchain(uid);
197
- }
198
- /**
199
- * Revokes multiple off chain attestations by their UIDs.
200
- * @param uids
201
- * @param signer
202
- * @returns
203
- */
204
- async multiRevokeOffchain(uids, signer) {
205
- const eas = this.gap.eas.connect(signer);
206
- return eas.multiRevokeOffchain(uids);
207
- }
208
- /**
209
- * Validates and attests a given schema.
210
- *
211
- * This function checks a schema against predefined standards or rules. If the 'ipfsKey' parameter is enabled,
212
- * it uploads the data to the IPFS (InterPlanetary File System). Upon successful upload, the function
213
- * returns the CID (Content Identifier) within the Attestation Body, providing a reference to the data on IPFS.
214
- *
215
- * Usage:
216
- * - Ensure that the schema to be attested conforms to the required format.
217
- * - Enable 'ipfsKey' if you wish to store the data on IPFS and retrieve its CID.
218
- *
219
- * @param {Object} param0 - An object containing the schema and other optional settings.
220
- * @returns {Object} An object containing the attestation results, including the CID if 'ipfsKey' is enabled.
221
- */
222
- async attest({ data, to, signer, refUID, callback, }) {
223
- const eas = this.gap.eas.connect(signer);
224
- if (this.references && !refUID)
225
- throw new SchemaError_1.AttestationError("INVALID_REFERENCE", "Attestation schema references another schema but no reference UID was provided.");
226
- if (this.isJsonSchema()) {
227
- this.setValue("json", JSON.stringify(data));
228
- }
229
- else {
230
- Object.entries(data).forEach(([key, value]) => {
231
- this.setValue(key, value);
232
- });
233
- }
234
- const payload = {
235
- schema: this.uid,
236
- data: {
237
- raw: {
238
- recipient: to,
239
- expirationTime: 0n,
240
- revocable: true,
241
- data: this.schema,
242
- refUID,
243
- value: 0n,
244
- },
245
- payload: {
246
- recipient: to,
247
- expirationTime: 0n,
248
- revocable: true,
249
- data: this.encode(this.schema),
250
- refUID,
251
- value: 0n,
252
- },
253
- },
254
- };
255
- callback?.("preparing");
256
- if (consts_1.useDefaultAttestation.includes(this.name)) {
257
- const uid = await eas.attest({
258
- schema: this.uid,
259
- data: payload.data.payload,
260
- });
261
- callback?.("pending");
262
- const uidResult = await uid.wait();
263
- callback?.("confirmed");
264
- return {
265
- tx: [
266
- {
267
- hash: uidResult,
268
- },
269
- ],
270
- uids: [uidResult],
271
- };
272
- }
273
- const { tx, uids } = await GapContract_1.GapContract.attest(signer, payload, callback);
274
- return {
275
- tx,
276
- uids,
277
- };
278
- }
279
- /**
280
- * Bulk attest a set of attestations.
281
- * @param signer
282
- * @param entities
283
- * @returns
284
- */
285
- async multiAttest(signer, entities = [], callback) {
286
- entities.forEach((entity) => {
287
- if (this.references && !entity.refUID)
288
- throw new SchemaError_1.SchemaError("INVALID_REF_UID", `Entity ${entity.schema.name} references another schema but no reference UID was provided.`);
289
- });
290
- const eas = this.gap.eas.connect(signer);
291
- const entityBySchema = entities.reduce((acc, entity) => {
292
- const schema = entity.schema.uid;
293
- if (!acc[schema])
294
- acc[schema] = [];
295
- acc[schema].push(entity);
296
- return acc;
297
- }, {});
298
- const payload = Object.entries(entityBySchema).map(([schema, ents]) => ({
299
- schema,
300
- data: ents.map((e) => ({
301
- data: e.schema.encode(),
302
- refUID: e.refUID,
303
- recipient: e.recipient,
304
- expirationTime: 0n,
305
- })),
306
- }));
307
- if (callback)
308
- callback("preparing");
309
- const attestation = await eas.multiAttest(payload, {
310
- gasLimit: 5000000n,
311
- });
312
- if (callback)
313
- callback("pending");
314
- const txResult = await attestation.wait().then((res) => {
315
- if (callback)
316
- callback("confirmed");
317
- return res;
318
- });
319
- const tx = txResult.map((item) => ({ hash: item }));
320
- return {
321
- tx,
322
- uids: txResult,
323
- };
324
- }
325
- /**
326
- * Revokes a set of attestations by their UIDs.
327
- * @param signer
328
- * @param uids
329
- * @returns
330
- */
331
- async multiRevoke(signer, toRevoke, callback) {
332
- callback?.("preparing");
333
- const groupBySchema = toRevoke.reduce((acc, { uid, schemaId }) => {
334
- if (!acc[schemaId])
335
- acc[schemaId] = [];
336
- acc[schemaId].push(uid);
337
- return acc;
338
- }, {});
339
- const eas = this.gap.eas.connect(signer);
340
- const payload = Object.entries(groupBySchema).map(([schema, uids]) => ({
341
- schema,
342
- data: uids.map((uid) => ({ uid })),
343
- }));
344
- const tx = await eas.multiRevoke(payload, {
345
- gasLimit: 5000000n,
346
- });
347
- callback?.("pending");
348
- await tx.wait();
349
- callback?.("confirmed");
350
- return {
351
- tx: [{ hash: tx.tx.hash }],
352
- uids: payload.map((p) => p.data.map((d) => d.uid)).flat(),
353
- };
354
- }
355
- static exists(name, network) {
356
- return this.schemas[network].find((schema) => schema.name === name);
357
- }
358
- /**
359
- * Adds the schema signature to a shares list. Use Schema.get("SchemaName") to get the schema.
360
- *
361
- * __Note that this will make the schema available to all instances
362
- * of the class AND its data can be overriden by any changes.__
363
- * @param schemas
364
- */
365
- static add(network, ...schemas) {
366
- schemas.forEach((schema) => {
367
- if (!this.exists(schema.name, network))
368
- this.schemas[network].push(schema);
369
- });
370
- }
371
- static getAll(network) {
372
- return this.schemas[network];
373
- }
374
- static get(name, network) {
375
- const schema = this.schemas[network].find((schema) => schema.name === name || schema.uid === name);
376
- if (!schema)
377
- throw new SchemaError_1.SchemaError("SCHEMA_NOT_FOUND", `Schema ${name} not found. Available schemas: ${Schema.getNames(network)}`);
378
- return schema;
379
- }
380
- /**
381
- * Find many schemas by name and return them as an array in the same order.
382
- * @param names
383
- * @returns
384
- */
385
- static getMany(names, network) {
386
- return names.map((name) => this.get(name, network));
387
- }
388
- static getNames(network) {
389
- return Schema.schemas[network].map((schema) => schema.name);
390
- }
391
- /**
392
- * Validade references
393
- * @throws {SchemaError} if any reference is not valid
394
- * @returns {true} if references are valid
395
- */
396
- static validate(network) {
397
- const errors = [];
398
- this.schemas[network].forEach((schema) => {
399
- if (!schema.references || Schema.exists(schema.references, network))
400
- return;
401
- else
402
- errors.push(new SchemaError_1.SchemaError("INVALID_REFERENCE", `Schema ${schema.name} references ${schema.references} but it does not exist.`));
403
- });
404
- if (errors.length)
405
- throw errors;
406
- return true;
407
- }
408
- /**
409
- * Replaces the schema list with a new list.
410
- * @param schemas
411
- */
412
- static replaceAll(schemas, network) {
413
- this.schemas[network] = schemas;
414
- }
415
- /**
416
- * Replaces a schema from the schema list.
417
- * @throws {SchemaError} if desired schema name does not exist.
418
- */
419
- static replaceOne(schema, network) {
420
- const idx = this.schemas[network].findIndex((item) => schema.name === item.name);
421
- if (!~idx)
422
- throw new SchemaError_1.SchemaError("SCHEMA_NOT_FOUND", `Schema ${schema.name} not found.`);
423
- this.schemas[idx] = schema;
424
- }
425
- /**
426
- * Transforms the given raw schema to SchemaItem[]
427
- *
428
- * @example
429
- * ```
430
- * const schema = Schema.rawToObject("uint256 id, string name");
431
- * // schema = [{ type: "uint256", name: "id", value: null }, { type: "string", name: "name", value: null }]
432
- * ```
433
- * @param abi
434
- * @returns
435
- */
436
- static rawToObject(abi) {
437
- const items = abi.trim().replace(/,\s+/gim, ",").split(",");
438
- const schema = items.map((item) => {
439
- const [type, name] = item.split(" ");
440
- return { type, name, value: null };
441
- });
442
- return schema;
443
- }
444
- /**
445
- * Returns the raw schema string.
446
- * @example
447
- * ```ts
448
- * const schema = new Schema({ name: "Grantee", schema: [{ type: "bool", name: "grantee", value: true }], uid: "0x000000000" });
449
- * schema.raw; // "bool grantee"
450
- * ```
451
- */
452
- get raw() {
453
- return this.schema.map((item) => `${item.type} ${item.name}`).join(",");
454
- }
455
- get schema() {
456
- return this._schema;
457
- }
458
- /**
459
- * Get all schemas that references this schema. Note that this
460
- * will return a reference to the original schema and all
461
- * the changes made to it will reflect the original instance.
462
- */
463
- get children() {
464
- return Schema.schemas[this.gap.network].filter((schema) => schema.references === this.name || schema.references === this.uid);
465
- }
466
- /**
467
- * Asserts and sets the schema value.
468
- */
469
- set schema(schema) {
470
- schema.forEach((item) => {
471
- this.setValue(item.name, item.value);
472
- });
473
- }
474
- }
475
- exports.Schema = Schema;
476
- Schema.schemas = {
477
- "optimism-sepolia": [],
478
- // "optimism-goerli": [],
479
- optimism: [],
480
- sepolia: [],
481
- arbitrum: [],
482
- celo: [],
483
- sei: [],
484
- "sei-testnet": [],
485
- "base-sepolia": [],
486
- lisk: [],
487
- scroll: [],
488
- };
@@ -1,30 +0,0 @@
1
- declare const SchemaErrorCodes: {
2
- INVALID_SCHEMA: number;
3
- INVALID_SCHEMA_NAME: number;
4
- INVALID_SCHEMA_TYPE: number;
5
- SCHEMA_ALREADY_EXISTS: number;
6
- SCHEMA_NOT_FOUND: number;
7
- SCHEMA_NOT_CREATED: number;
8
- MISSING_FIELD: number;
9
- INVALID_REFERENCE: number;
10
- INVALID_SCHEMA_FIELD: number;
11
- INVALID_DATA: number;
12
- REVOKE_ERROR: number;
13
- ATTEST_ERROR: number;
14
- INVALID_REF_UID: number;
15
- REVOKATION_ERROR: number;
16
- NOT_REVOCABLE: number;
17
- REMOTE_STORAGE_UPLOAD: number;
18
- };
19
- export declare class SchemaError extends Error {
20
- readonly code: number;
21
- private readonly _message;
22
- readonly originalError: any;
23
- constructor(code: keyof typeof SchemaErrorCodes, append?: string, originalError?: any);
24
- get message(): string;
25
- }
26
- export declare class AttestationError extends SchemaError {
27
- }
28
- export declare class RemoteStorageError extends SchemaError {
29
- }
30
- export {};
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RemoteStorageError = exports.AttestationError = exports.SchemaError = void 0;
4
- const SchemaErrorCodes = {
5
- INVALID_SCHEMA: 50001,
6
- INVALID_SCHEMA_NAME: 50002,
7
- INVALID_SCHEMA_TYPE: 50003,
8
- SCHEMA_ALREADY_EXISTS: 50004,
9
- SCHEMA_NOT_FOUND: 50005,
10
- SCHEMA_NOT_CREATED: 50006,
11
- MISSING_FIELD: 50007,
12
- INVALID_REFERENCE: 50008,
13
- INVALID_SCHEMA_FIELD: 50009,
14
- INVALID_DATA: 50010,
15
- REVOKE_ERROR: 50011,
16
- ATTEST_ERROR: 50012,
17
- INVALID_REF_UID: 50013,
18
- REVOKATION_ERROR: 50014,
19
- NOT_REVOCABLE: 50015,
20
- REMOTE_STORAGE_UPLOAD: 50016,
21
- };
22
- class SchemaError extends Error {
23
- constructor(code, append, originalError) {
24
- super(`${code}${append ? `: ${append}` : ""}`);
25
- this._message = append || code.replace(/_/g, " ");
26
- this.code = SchemaErrorCodes[code];
27
- this.originalError = originalError;
28
- }
29
- get message() {
30
- return this._message;
31
- }
32
- }
33
- exports.SchemaError = SchemaError;
34
- class AttestationError extends SchemaError {
35
- }
36
- exports.AttestationError = AttestationError;
37
- class RemoteStorageError extends SchemaError {
38
- }
39
- exports.RemoteStorageError = RemoteStorageError;
@@ -1,102 +0,0 @@
1
- import { MultiRevocationRequest } from "@ethereum-attestation-service/eas-sdk";
2
- import { CallbackStatus, Hex, RawAttestationPayload, RawMultiAttestPayload, SignerOrProvider } from "core/types";
3
- import { Transaction } from "ethers";
4
- import { AttestationWithTx } from "../types/attestations";
5
- export declare class GapContract {
6
- static nonces: {
7
- [key: string]: number;
8
- };
9
- /**
10
- * Signs a message for the delegated attestation.
11
- * @param signer
12
- * @param payload
13
- * @returns r,s,v signature
14
- */
15
- private static signAttestation;
16
- /**
17
- * Returns the r, s, v values of a signature
18
- * @param signature
19
- * @returns
20
- */
21
- private static getRSV;
22
- static getSignerAddress(signer: SignerOrProvider): Promise<any>;
23
- /**
24
- * Get nonce for the transaction
25
- * @param address
26
- * @returns
27
- */
28
- private static getNonce;
29
- /**
30
- * Send a single attestation
31
- * @param signer
32
- * @param payload
33
- * @returns
34
- */
35
- static attest(signer: SignerOrProvider, payload: RawAttestationPayload, callback?: ((status: CallbackStatus) => void) & ((status: string) => void)): Promise<AttestationWithTx>;
36
- static attestBySig(signer: SignerOrProvider, payload: RawAttestationPayload): Promise<{
37
- tx: Transaction[];
38
- uids: `0x${string}`[];
39
- }>;
40
- /**
41
- * Performs a referenced multi attestation.
42
- *
43
- * @returns an array with the attestation UIDs.
44
- */
45
- static multiAttest(signer: SignerOrProvider, payload: RawMultiAttestPayload[], callback?: Function): Promise<AttestationWithTx>;
46
- /**
47
- * Performs a referenced multi attestation.
48
- *
49
- * @returns an array with the attestation UIDs.
50
- */
51
- static multiAttestBySig(signer: SignerOrProvider, payload: RawMultiAttestPayload[]): Promise<AttestationWithTx>;
52
- static multiRevoke(signer: SignerOrProvider, payload: MultiRevocationRequest[]): Promise<AttestationWithTx>;
53
- /**
54
- * Performs a referenced multi attestation.
55
- *
56
- * @returns an array with the attestation UIDs.
57
- */
58
- static multiRevokeBySig(signer: SignerOrProvider, payload: MultiRevocationRequest[]): Promise<AttestationWithTx>;
59
- /**
60
- * Transfer the ownership of an attestation
61
- * @param signer
62
- * @param projectUID
63
- * @param newOwner
64
- * @returns
65
- */
66
- static transferProjectOwnership(signer: SignerOrProvider, projectUID: Hex, newOwner: Hex): Promise<any>;
67
- /**
68
- * Check if the signer is the owner of the project
69
- * @param signer
70
- * @param projectUID
71
- * @param projectChainId
72
- * @param publicAddress
73
- * @returns
74
- */
75
- static isProjectOwner(signer: SignerOrProvider, projectUID: Hex, projectChainId: number, publicAddress?: string): Promise<boolean>;
76
- /**
77
- * Check if the signer is admin of the project
78
- * @param signer
79
- * @param projectUID
80
- * @param projectChainId
81
- * @param publicAddress
82
- * @returns
83
- */
84
- static isProjectAdmin(signer: SignerOrProvider, projectUID: Hex, projectChainId: number, publicAddress?: string): Promise<boolean>;
85
- private static getTransactionLogs;
86
- /**
87
- * Add Project Admin
88
- * @param signer
89
- * @param projectUID
90
- * @param newAdmin
91
- * @returns
92
- */
93
- static addProjectAdmin(signer: SignerOrProvider, projectUID: Hex, newAdmin: Hex): Promise<any>;
94
- /**
95
- * RemoveProject Admin
96
- * @param signer
97
- * @param projectUID
98
- * @param newAdmin
99
- * @returns
100
- */
101
- static removeProjectAdmin(signer: SignerOrProvider, projectUID: Hex, oldAdmin: Hex): Promise<any>;
102
- }