@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
package/core/abi/index.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.abis = void 0;
7
- const AirdropNFT_json_1 = __importDefault(require("./AirdropNFT.json"));
8
- const Allo_json_1 = __importDefault(require("./Allo.json"));
9
- const AlloRegistry_json_1 = __importDefault(require("./AlloRegistry.json"));
10
- const CommunityResolverABI_json_1 = __importDefault(require("./CommunityResolverABI.json"));
11
- const Donations_json_1 = __importDefault(require("./Donations.json"));
12
- const EAS_json_1 = __importDefault(require("./EAS.json"));
13
- const MultiAttester_json_1 = __importDefault(require("./MultiAttester.json"));
14
- const ProjectResolver_json_1 = __importDefault(require("./ProjectResolver.json"));
15
- const SchemaRegistry_json_1 = __importDefault(require("./SchemaRegistry.json"));
16
- exports.abis = {
17
- AirdropNFT: AirdropNFT_json_1.default,
18
- Allo: Allo_json_1.default,
19
- AlloRegistry: AlloRegistry_json_1.default,
20
- CommunityResolverABI: CommunityResolverABI_json_1.default,
21
- Donations: Donations_json_1.default,
22
- EAS: EAS_json_1.default,
23
- MultiAttester: MultiAttester_json_1.default,
24
- ProjectResolver: ProjectResolver_json_1.default,
25
- SchemaRegistry: SchemaRegistry_json_1.default,
26
- };
@@ -1,9 +0,0 @@
1
- import { SchemaInterface, TNetwork, TSchemaName } from "../types";
2
- import { GapSchema } from "./GapSchema";
3
- export declare class AllGapSchemas {
4
- allSchemas: {
5
- [network: string]: SchemaInterface<TSchemaName>[];
6
- };
7
- constructor();
8
- findSchema(name: TSchemaName, network: TNetwork): GapSchema;
9
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AllGapSchemas = void 0;
4
- const consts_1 = require("../../core/consts");
5
- const GAP_1 = require("./GAP");
6
- const GapSchema_1 = require("./GapSchema");
7
- class AllGapSchemas {
8
- constructor() {
9
- this.allSchemas = {};
10
- Object.keys(consts_1.Networks).forEach((network) => {
11
- this.allSchemas[network] = Object.values((0, consts_1.MountEntities)(consts_1.Networks[network]));
12
- });
13
- }
14
- findSchema(name, network) {
15
- const schema = this.allSchemas[network].find((s) => s.name === name);
16
- return new GapSchema_1.GapSchema(schema, GAP_1.GAP.getInstance({ network }), false, false);
17
- }
18
- }
19
- exports.AllGapSchemas = AllGapSchemas;
@@ -1,173 +0,0 @@
1
- import { Hex, IAttestation, JSONStr, MultiAttestData, SignerOrProvider, TNetwork } from "../types";
2
- import { Schema } from "./Schema";
3
- import { SchemaItem, SchemaValue } from "@ethereum-attestation-service/eas-sdk";
4
- import { GapSchema } from "./GapSchema";
5
- import { AttestationWithTx } from "./types/attestations";
6
- export interface AttestationArgs<T = unknown, S extends Schema = Schema> {
7
- data: T | string;
8
- schema: S;
9
- uid?: Hex;
10
- refUID?: Hex;
11
- attester?: Hex;
12
- recipient: Hex;
13
- revoked?: boolean;
14
- revocationTime?: Date | number;
15
- createdAt?: Date | number;
16
- chainID?: number;
17
- }
18
- /**
19
- * Represents the EAS Attestation and provides methods to manage attestations.
20
- * @example
21
- *
22
- * ```ts
23
- * const grantee = new Attestation({
24
- * schema: Schema.get("Grantee", "network-name"), // Use this.schema.gap.findSchema("SchemaName") if using default GAP schemas
25
- * data: { grantee: true },
26
- * uid: "0xabc123",
27
- * });
28
- *
29
- * const granteeDetails = new Attestation({
30
- * schema: Schema.get("GranteeDetails", "optimism"),
31
- * data: {
32
- * name: "John Doe",
33
- * description: "A description",
34
- * imageURL: "https://example.com/image.png",
35
- * },
36
- * uid: "0xab234"
37
- * );
38
- *
39
- * // Return the refferenced attestation
40
- * const ref = granteeDetails.reference<Grantee>();
41
- *
42
- * // Revoke attestation
43
- * granteeDetails.revoke();
44
- *
45
- * // Get attestation data from a decoded JSON string.
46
- * granteeDetails.fromDecodedSchema(granteeDetails.data);
47
- * ```
48
- */
49
- export declare class Attestation<T = unknown, S extends Schema = GapSchema> implements AttestationArgs<T, S> {
50
- readonly schema: S;
51
- private _data;
52
- protected _uid: Hex;
53
- readonly refUID?: Hex;
54
- readonly attester?: Hex;
55
- readonly recipient: Hex;
56
- readonly revoked?: boolean;
57
- readonly revocationTime?: Date;
58
- readonly createdAt: Date;
59
- private _chainID;
60
- private _reference?;
61
- constructor(args: AttestationArgs<T, S>);
62
- /**
63
- * Encodes the schema.
64
- * @returns
65
- */
66
- encodeSchema(schema: SchemaItem[]): string;
67
- /**
68
- * Sets a field in the schema.
69
- */
70
- setValue<K extends keyof T>(key: K, value: SchemaValue): void;
71
- /**
72
- * Set attestation values to be uploaded.
73
- * @param values
74
- */
75
- setValues(values: T): void;
76
- /**
77
- * Returns the referenced attestation
78
- */
79
- reference<Ref = unknown, RefSchema extends Schema = Schema>(): Attestation<Ref, RefSchema>;
80
- /**
81
- * Returns the attestation data as a JSON string.
82
- * @param data
83
- * @returns
84
- */
85
- fromDecodedSchema(data: T | JSONStr): T;
86
- /**
87
- * Revokes this attestation.
88
- * @param eas
89
- * @param signer
90
- * @returns
91
- */
92
- revoke(signer: SignerOrProvider, callback?: Function): Promise<AttestationWithTx>;
93
- /**
94
- * Attests the data using the specified signer and schema.
95
- * @param signer - The signer or provider to use for attestation.
96
- * @param args - Additional arguments to pass to the schema's `attest` method.
97
- * @returns A Promise that resolves to the UID of the attestation.
98
- * @throws An `AttestationError` if an error occurs during attestation.
99
- */
100
- attest(signer: SignerOrProvider, ...args: unknown[]): Promise<AttestationWithTx>;
101
- /**
102
- * Validates the payload.
103
- *
104
- * If an attestation should have anything
105
- * specifically explicit, it should be implemented in
106
- * order to avoid errors.
107
- * @returns
108
- */
109
- protected assertPayload(): boolean;
110
- /**
111
- * Get the multi attestation payload for the referred index.
112
- *
113
- * The index should be the array position this payload wants
114
- * to reference.
115
- *
116
- * E.g:
117
- *
118
- * 1. Project is index 0;
119
- * 2. Project details is index 1;
120
- * 3. Grant is index 2;
121
- * 4. Grant details is index 3;
122
- * 5. Milestone is index 4;
123
- *
124
- * `[Project, projectDetails, grant, grantDetails, milestone]`
125
- *
126
- * -> Project.payloadFor(0); // refs itself (no effect)
127
- *
128
- * -> project.details.payloadFor(0); // ref project
129
- *
130
- * -> grant.payloadFor(0); // ref project
131
- *
132
- * -> grant.details.payloadFor(2); // ref grant
133
- *
134
- * -> milestone.payloadFor(2); // ref grant
135
- *
136
- *
137
- * @param refIdx
138
- * @returns [Encoded payload, Raw payload]
139
- */
140
- payloadFor(refIdx: number): Promise<{
141
- payload: MultiAttestData;
142
- raw: MultiAttestData;
143
- }>;
144
- /**
145
- * Returns an Attestation instance from a JSON decoded schema.
146
- * @param data
147
- * @returns
148
- */
149
- static fromDecodedSchema<T>(data: JSONStr): T;
150
- /**
151
- * Transform attestation interface-based into class-based.
152
- */
153
- static fromInterface<T extends Attestation = Attestation>(attestations: IAttestation[], network: TNetwork): T[];
154
- /**
155
- * Asserts if schema is valid.
156
- * > Does not check refUID if `strict = false`. To check refUID use `Schema.validate()`
157
- * @param args
158
- */
159
- protected assert(args: AttestationArgs, strict?: boolean): void;
160
- get chainID(): number;
161
- get data(): T;
162
- get uid(): Hex;
163
- set uid(uid: Hex);
164
- /**
165
- * Create attestation to serve as Attestation data.
166
- * @param data Data to attest
167
- * @param schema selected schema
168
- * @param from attester
169
- * @param to recipient
170
- * @returns
171
- */
172
- static factory<T = unknown>(data: T, schema: Schema, from: Hex, to: Hex): Attestation<T, Schema<string>>;
173
- }
@@ -1,333 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Attestation = void 0;
4
- const Schema_1 = require("./Schema");
5
- const SchemaError_1 = require("./SchemaError");
6
- const get_date_1 = require("../utils/get-date");
7
- const consts_1 = require("../consts");
8
- const GapContract_1 = require("./contract/GapContract");
9
- /**
10
- * Represents the EAS Attestation and provides methods to manage attestations.
11
- * @example
12
- *
13
- * ```ts
14
- * const grantee = new Attestation({
15
- * schema: Schema.get("Grantee", "network-name"), // Use this.schema.gap.findSchema("SchemaName") if using default GAP schemas
16
- * data: { grantee: true },
17
- * uid: "0xabc123",
18
- * });
19
- *
20
- * const granteeDetails = new Attestation({
21
- * schema: Schema.get("GranteeDetails", "optimism"),
22
- * data: {
23
- * name: "John Doe",
24
- * description: "A description",
25
- * imageURL: "https://example.com/image.png",
26
- * },
27
- * uid: "0xab234"
28
- * );
29
- *
30
- * // Return the refferenced attestation
31
- * const ref = granteeDetails.reference<Grantee>();
32
- *
33
- * // Revoke attestation
34
- * granteeDetails.revoke();
35
- *
36
- * // Get attestation data from a decoded JSON string.
37
- * granteeDetails.fromDecodedSchema(granteeDetails.data);
38
- * ```
39
- */
40
- class Attestation {
41
- constructor(args) {
42
- this.schema = args.schema;
43
- this._data = this.fromDecodedSchema(args.data);
44
- this.setValues(this._data);
45
- this._uid = args.uid || consts_1.nullRef;
46
- this.refUID = args.refUID || consts_1.nullRef;
47
- this.attester = args.attester;
48
- this.recipient = args.recipient;
49
- this.revoked = args.revoked;
50
- this.revocationTime = (0, get_date_1.getDate)(args.revocationTime);
51
- this.createdAt = (0, get_date_1.getDate)(args.createdAt || Date.now() / 1000);
52
- this._chainID = args.chainID || consts_1.Networks[this.schema.gap.network].chainId;
53
- }
54
- /**
55
- * Encodes the schema.
56
- * @returns
57
- */
58
- encodeSchema(schema) {
59
- return this.schema.encode(schema);
60
- }
61
- /**
62
- * Sets a field in the schema.
63
- */
64
- setValue(key, value) {
65
- this.schema.setValue(key, value);
66
- }
67
- /**
68
- * Set attestation values to be uploaded.
69
- * @param values
70
- */
71
- setValues(values) {
72
- const isJsonSchema = this.schema.isJsonSchema();
73
- if (isJsonSchema)
74
- this.schema.setValue("json", JSON.stringify(values));
75
- this._data = values;
76
- Object.entries(values).forEach(([key, value]) => {
77
- this[key] = value;
78
- if (!isJsonSchema)
79
- this.setValue(key, value.value || value);
80
- });
81
- }
82
- /**
83
- * Returns the referenced attestation
84
- */
85
- reference() {
86
- return this._reference;
87
- }
88
- /**
89
- * Returns the attestation data as a JSON string.
90
- * @param data
91
- * @returns
92
- */
93
- fromDecodedSchema(data) {
94
- return typeof data === "string"
95
- ? Attestation.fromDecodedSchema(data)
96
- : data;
97
- }
98
- /**
99
- * Revokes this attestation.
100
- * @param eas
101
- * @param signer
102
- * @returns
103
- */
104
- async revoke(signer, callback) {
105
- try {
106
- callback?.("preparing");
107
- const { tx } = await GapContract_1.GapContract.multiRevoke(signer, [
108
- {
109
- data: [
110
- {
111
- uid: this.uid,
112
- value: 0n,
113
- },
114
- ],
115
- schema: this.schema.uid,
116
- },
117
- ]).then((res) => {
118
- callback?.("confirmed");
119
- return res;
120
- });
121
- return { tx, uids: [this.uid] };
122
- }
123
- catch (error) {
124
- console.error(error);
125
- throw new SchemaError_1.SchemaError("REVOKE_ERROR", "Error revoking attestation.", error);
126
- }
127
- }
128
- /**
129
- * Attests the data using the specified signer and schema.
130
- * @param signer - The signer or provider to use for attestation.
131
- * @param args - Additional arguments to pass to the schema's `attest` method.
132
- * @returns A Promise that resolves to the UID of the attestation.
133
- * @throws An `AttestationError` if an error occurs during attestation.
134
- */
135
- async attest(signer, ...args) {
136
- const callback = typeof args[args.length - 1] === "function"
137
- ? args.pop()
138
- : null;
139
- console.log(`Attesting ${this.schema.name}`);
140
- try {
141
- const { tx, uids } = await this.schema.attest({
142
- data: this.data,
143
- to: this.recipient,
144
- refUID: this.refUID,
145
- signer,
146
- callback: callback,
147
- });
148
- this._uid = uids[0];
149
- console.log(`Attested ${this.schema.name} with UID ${this.uid}`);
150
- return { tx, uids };
151
- }
152
- catch (error) {
153
- console.error(error);
154
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Error during attestation.", error);
155
- }
156
- }
157
- /**
158
- * Validates the payload.
159
- *
160
- * If an attestation should have anything
161
- * specifically explicit, it should be implemented in
162
- * order to avoid errors.
163
- * @returns
164
- */
165
- assertPayload() {
166
- return true;
167
- }
168
- /**
169
- * Get the multi attestation payload for the referred index.
170
- *
171
- * The index should be the array position this payload wants
172
- * to reference.
173
- *
174
- * E.g:
175
- *
176
- * 1. Project is index 0;
177
- * 2. Project details is index 1;
178
- * 3. Grant is index 2;
179
- * 4. Grant details is index 3;
180
- * 5. Milestone is index 4;
181
- *
182
- * `[Project, projectDetails, grant, grantDetails, milestone]`
183
- *
184
- * -> Project.payloadFor(0); // refs itself (no effect)
185
- *
186
- * -> project.details.payloadFor(0); // ref project
187
- *
188
- * -> grant.payloadFor(0); // ref project
189
- *
190
- * -> grant.details.payloadFor(2); // ref grant
191
- *
192
- * -> milestone.payloadFor(2); // ref grant
193
- *
194
- *
195
- * @param refIdx
196
- * @returns [Encoded payload, Raw payload]
197
- */
198
- async payloadFor(refIdx) {
199
- this.assertPayload();
200
- if (this.schema.isJsonSchema()) {
201
- if (this.type) {
202
- this._data.type = this.type;
203
- this.schema.setValue("json", JSON.stringify(this._data));
204
- }
205
- }
206
- const payload = (encode = true) => ({
207
- uid: consts_1.nullRef,
208
- refIdx,
209
- multiRequest: {
210
- schema: this.schema.uid,
211
- data: [
212
- {
213
- refUID: this.refUID,
214
- expirationTime: 0n,
215
- revocable: this.schema.revocable || true,
216
- value: 0n,
217
- data: (encode ? this.schema.encode() : this.schema.schema),
218
- recipient: this.recipient,
219
- },
220
- ],
221
- },
222
- });
223
- return {
224
- payload: payload(),
225
- raw: payload(false),
226
- };
227
- }
228
- /**
229
- * Returns an Attestation instance from a JSON decoded schema.
230
- * @param data
231
- * @returns
232
- */
233
- static fromDecodedSchema(data) {
234
- try {
235
- const parsed = JSON.parse(data);
236
- if (data.length < 2 && !/\{.*\}/gim.test(data))
237
- return {};
238
- if (parsed.length === 1 && parsed[0].name === "json") {
239
- const { value } = parsed[0];
240
- return (typeof value.value === "string"
241
- ? JSON.parse(value.value)
242
- : value.value);
243
- }
244
- if (parsed && Array.isArray(parsed)) {
245
- return parsed.reduce((acc, curr) => {
246
- const { value } = curr.value;
247
- if (curr.type.includes("uint")) {
248
- acc[curr.name] = ["string", "bigint"].includes(typeof value)
249
- ? BigInt(value)
250
- : Number(value);
251
- }
252
- else
253
- acc[curr.name] = value;
254
- return acc;
255
- }, {});
256
- }
257
- throw new SchemaError_1.SchemaError("INVALID_DATA", "Data must be a valid JSON array string.");
258
- }
259
- catch (error) {
260
- console.error(error);
261
- throw new SchemaError_1.SchemaError("INVALID_DATA", "Data must be a valid JSON string.", error);
262
- }
263
- }
264
- /**
265
- * Transform attestation interface-based into class-based.
266
- */
267
- static fromInterface(attestations, network) {
268
- const result = [];
269
- attestations.forEach((attestation) => {
270
- try {
271
- const schema = Schema_1.Schema.get(attestation.schemaId, network);
272
- result.push(new Attestation({
273
- ...attestation,
274
- schema,
275
- chainID: consts_1.Networks[network].chainId,
276
- data: attestation.decodedDataJson,
277
- }));
278
- }
279
- catch (e) {
280
- console.log(e);
281
- }
282
- });
283
- return result;
284
- }
285
- /**
286
- * Asserts if schema is valid.
287
- * > Does not check refUID if `strict = false`. To check refUID use `Schema.validate()`
288
- * @param args
289
- */
290
- assert(args, strict = false) {
291
- const { schema, uid } = args;
292
- if (!schema || !(schema instanceof Schema_1.Schema)) {
293
- throw new SchemaError_1.SchemaError("MISSING_FIELD", "Schema must be an array.");
294
- }
295
- if (!uid) {
296
- throw new SchemaError_1.SchemaError("MISSING_FIELD", "Schema uid is required");
297
- }
298
- if (strict)
299
- Schema_1.Schema.validate(this.schema.gap.network);
300
- }
301
- get chainID() {
302
- return this._chainID;
303
- }
304
- get data() {
305
- return this._data;
306
- }
307
- get uid() {
308
- return this._uid;
309
- }
310
- set uid(uid) {
311
- this._uid = uid;
312
- }
313
- /**
314
- * Create attestation to serve as Attestation data.
315
- * @param data Data to attest
316
- * @param schema selected schema
317
- * @param from attester
318
- * @param to recipient
319
- * @returns
320
- */
321
- static factory(data, schema, from, to) {
322
- return new Attestation({
323
- data: data,
324
- recipient: to,
325
- attester: from,
326
- schema,
327
- uid: "0x0",
328
- createdAt: new Date(),
329
- chainID: consts_1.Networks[schema.gap.network].chainId,
330
- });
331
- }
332
- }
333
- exports.Attestation = Attestation;