@show-karma/karma-gap-sdk 0.1.29
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/core/abi/MultiAttester.json +676 -0
- package/core/class/Attestation.d.ts +169 -0
- package/core/class/Attestation.js +311 -0
- package/core/class/Fetcher.d.ts +132 -0
- package/core/class/Fetcher.js +7 -0
- package/core/class/GAP.d.ts +212 -0
- package/core/class/GAP.js +206 -0
- package/core/class/GapSchema.d.ts +33 -0
- package/core/class/GapSchema.js +61 -0
- package/core/class/Gelato/Gelato.d.ts +0 -0
- package/core/class/Gelato/Gelato.js +263 -0
- package/core/class/GraphQL/AxiosGQL.d.ts +6 -0
- package/core/class/GraphQL/AxiosGQL.js +25 -0
- package/core/class/GraphQL/EASClient.d.ts +16 -0
- package/core/class/GraphQL/EASClient.js +26 -0
- package/core/class/GraphQL/Fetcher.d.ts +132 -0
- package/core/class/GraphQL/Fetcher.js +7 -0
- package/core/class/GraphQL/GAPFetcher.d.ts +160 -0
- package/core/class/GraphQL/GAPFetcher.js +516 -0
- package/core/class/GraphQL/GapEasClient.d.ts +63 -0
- package/core/class/GraphQL/GapEasClient.js +420 -0
- package/core/class/GraphQL/index.d.ts +3 -0
- package/core/class/GraphQL/index.js +19 -0
- package/core/class/Schema.d.ts +213 -0
- package/core/class/Schema.js +434 -0
- package/core/class/SchemaError.d.ts +26 -0
- package/core/class/SchemaError.js +34 -0
- package/core/class/contract/GapContract.d.ts +55 -0
- package/core/class/contract/GapContract.js +176 -0
- package/core/class/contract/MultiAttest.d.ts +10 -0
- package/core/class/contract/MultiAttest.js +19 -0
- package/core/class/entities/Community.d.ts +36 -0
- package/core/class/entities/Community.js +88 -0
- package/core/class/entities/Grant.d.ts +53 -0
- package/core/class/entities/Grant.js +194 -0
- package/core/class/entities/MemberOf.d.ts +11 -0
- package/core/class/entities/MemberOf.js +31 -0
- package/core/class/entities/Milestone.d.ts +63 -0
- package/core/class/entities/Milestone.js +171 -0
- package/core/class/entities/Project.d.ts +73 -0
- package/core/class/entities/Project.js +243 -0
- package/core/class/entities/index.d.ts +5 -0
- package/core/class/entities/index.js +21 -0
- package/core/class/index.d.ts +7 -0
- package/core/class/index.js +23 -0
- package/core/class/karma-indexer/GapIndexerClient.d.ts +28 -0
- package/core/class/karma-indexer/GapIndexerClient.js +137 -0
- package/core/class/types/attestations.d.ts +108 -0
- package/core/class/types/attestations.js +55 -0
- package/core/consts.d.ts +19 -0
- package/core/consts.js +228 -0
- package/core/index.d.ts +7 -0
- package/core/index.js +23 -0
- package/core/types.d.ts +107 -0
- package/core/types.js +13 -0
- package/core/utils/gelato/index.d.ts +3 -0
- package/core/utils/gelato/index.js +19 -0
- package/core/utils/gelato/send-gelato-txn.d.ts +54 -0
- package/core/utils/gelato/send-gelato-txn.js +99 -0
- package/core/utils/gelato/sponsor-handler.d.ts +9 -0
- package/core/utils/gelato/sponsor-handler.js +60 -0
- package/core/utils/gelato/watch-gelato-txn.d.ts +7 -0
- package/core/utils/gelato/watch-gelato-txn.js +55 -0
- package/core/utils/get-date.d.ts +1 -0
- package/core/utils/get-date.js +7 -0
- package/core/utils/gql-queries.d.ts +12 -0
- package/core/utils/gql-queries.js +90 -0
- package/core/utils/index.d.ts +6 -0
- package/core/utils/index.js +22 -0
- package/core/utils/map-filter.d.ts +8 -0
- package/core/utils/map-filter.js +20 -0
- package/core/utils/serialize-bigint.d.ts +1 -0
- package/core/utils/serialize-bigint.js +8 -0
- package/core/utils/to-unix.d.ts +1 -0
- package/core/utils/to-unix.js +25 -0
- package/index.d.ts +1 -0
- package/index.js +17 -0
- package/package.json +37 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Hex, IAttestation, JSONStr, MultiAttestData, SignerOrProvider } from "../types";
|
|
2
|
+
import { Schema } from "./Schema";
|
|
3
|
+
import { SchemaItem, SchemaValue } from "@ethereum-attestation-service/eas-sdk";
|
|
4
|
+
import { GapSchema } from "./GapSchema";
|
|
5
|
+
export interface AttestationArgs<T = unknown, S extends Schema = Schema> {
|
|
6
|
+
data: T | string;
|
|
7
|
+
schema: S;
|
|
8
|
+
uid?: Hex;
|
|
9
|
+
refUID?: Hex;
|
|
10
|
+
attester?: Hex;
|
|
11
|
+
recipient: Hex;
|
|
12
|
+
revoked?: boolean;
|
|
13
|
+
revocationTime?: Date | number;
|
|
14
|
+
createdAt?: Date | number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Represents the EAS Attestation and provides methods to manage attestations.
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const grantee = new Attestation({
|
|
22
|
+
* schema: Schema.get("Grantee"), // Use GapSchema.find("SchemaName") if using default GAP schemas
|
|
23
|
+
* data: { grantee: true },
|
|
24
|
+
* uid: "0xabc123",
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const granteeDetails = new Attestation({
|
|
28
|
+
* schema: Schema.get("GranteeDetails"),
|
|
29
|
+
* data: {
|
|
30
|
+
* name: "John Doe",
|
|
31
|
+
* description: "A description",
|
|
32
|
+
* imageURL: "https://example.com/image.png",
|
|
33
|
+
* },
|
|
34
|
+
* uid: "0xab234"
|
|
35
|
+
* );
|
|
36
|
+
*
|
|
37
|
+
* // Return the refferenced attestation
|
|
38
|
+
* const ref = granteeDetails.reference<Grantee>();
|
|
39
|
+
*
|
|
40
|
+
* // Revoke attestation
|
|
41
|
+
* granteeDetails.revoke();
|
|
42
|
+
*
|
|
43
|
+
* // Get attestation data from a decoded JSON string.
|
|
44
|
+
* granteeDetails.fromDecodedSchema(granteeDetails.data);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare class Attestation<T = unknown, S extends Schema = GapSchema> implements AttestationArgs<T, S> {
|
|
48
|
+
readonly schema: S;
|
|
49
|
+
private _data;
|
|
50
|
+
protected _uid: Hex;
|
|
51
|
+
readonly refUID?: Hex;
|
|
52
|
+
readonly attester?: Hex;
|
|
53
|
+
readonly recipient: Hex;
|
|
54
|
+
readonly revoked?: boolean;
|
|
55
|
+
readonly revocationTime?: Date;
|
|
56
|
+
readonly createdAt: Date;
|
|
57
|
+
private _reference?;
|
|
58
|
+
constructor(args: AttestationArgs<T, S>);
|
|
59
|
+
/**
|
|
60
|
+
* Encodes the schema.
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
encodeSchema(schema: SchemaItem[]): string;
|
|
64
|
+
/**
|
|
65
|
+
* Sets a field in the schema.
|
|
66
|
+
*/
|
|
67
|
+
setValue<K extends keyof T>(key: K, value: SchemaValue): void;
|
|
68
|
+
/**
|
|
69
|
+
* Set attestation values to be uploaded.
|
|
70
|
+
* @param values
|
|
71
|
+
*/
|
|
72
|
+
setValues(values: T): void;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the referenced attestation
|
|
75
|
+
*/
|
|
76
|
+
reference<Ref = unknown, RefSchema extends Schema = Schema>(): Attestation<Ref, RefSchema>;
|
|
77
|
+
/**
|
|
78
|
+
* Returns the attestation data as a JSON string.
|
|
79
|
+
* @param data
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
fromDecodedSchema(data: T | JSONStr): T;
|
|
83
|
+
/**
|
|
84
|
+
* Revokes this attestation.
|
|
85
|
+
* @param eas
|
|
86
|
+
* @param signer
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
revoke(signer: SignerOrProvider): Promise<any>;
|
|
90
|
+
/**
|
|
91
|
+
* Attests the data using the specified signer and schema.
|
|
92
|
+
* @param signer - The signer or provider to use for attestation.
|
|
93
|
+
* @param args - Additional arguments to pass to the schema's `attest` method.
|
|
94
|
+
* @returns A Promise that resolves to the UID of the attestation.
|
|
95
|
+
* @throws An `AttestationError` if an error occurs during attestation.
|
|
96
|
+
*/
|
|
97
|
+
attest(signer: SignerOrProvider, ...args: unknown[]): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Validates the payload.
|
|
100
|
+
*
|
|
101
|
+
* If an attestation should have anything
|
|
102
|
+
* specifically explicit, it should be implemented in
|
|
103
|
+
* order to avoid errors.
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
protected assertPayload(): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Get the multi attestation payload for the referred index.
|
|
109
|
+
*
|
|
110
|
+
* The index should be the array position this payload wants
|
|
111
|
+
* to reference.
|
|
112
|
+
*
|
|
113
|
+
* E.g:
|
|
114
|
+
*
|
|
115
|
+
* 1. Project is index 0;
|
|
116
|
+
* 2. Project details is index 1;
|
|
117
|
+
* 3. Grant is index 2;
|
|
118
|
+
* 4. Grant details is index 3;
|
|
119
|
+
* 5. Milestone is index 4;
|
|
120
|
+
*
|
|
121
|
+
* `[Project, projectDetails, grant, grantDetails, milestone]`
|
|
122
|
+
*
|
|
123
|
+
* -> Project.payloadFor(0); // refs itself (no effect)
|
|
124
|
+
*
|
|
125
|
+
* -> project.details.payloadFor(0); // ref project
|
|
126
|
+
*
|
|
127
|
+
* -> grant.payloadFor(0); // ref project
|
|
128
|
+
*
|
|
129
|
+
* -> grant.details.payloadFor(2); // ref grant
|
|
130
|
+
*
|
|
131
|
+
* -> milestone.payloadFor(2); // ref grant
|
|
132
|
+
*
|
|
133
|
+
*
|
|
134
|
+
* @param refIdx
|
|
135
|
+
* @returns [Encoded payload, Raw payload]
|
|
136
|
+
*/
|
|
137
|
+
payloadFor(refIdx: number): {
|
|
138
|
+
payload: MultiAttestData;
|
|
139
|
+
raw: MultiAttestData;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Returns an Attestation instance from a JSON decoded schema.
|
|
143
|
+
* @param data
|
|
144
|
+
* @returns
|
|
145
|
+
*/
|
|
146
|
+
static fromDecodedSchema<T>(data: JSONStr): T;
|
|
147
|
+
/**
|
|
148
|
+
* Transform attestation interface-based into class-based.
|
|
149
|
+
*/
|
|
150
|
+
static fromInterface<T extends Attestation = Attestation>(attestations: IAttestation[]): T[];
|
|
151
|
+
/**
|
|
152
|
+
* Asserts if schema is valid.
|
|
153
|
+
* > Does not check refUID if `strict = false`. To check refUID use `Schema.validate()`
|
|
154
|
+
* @param args
|
|
155
|
+
*/
|
|
156
|
+
protected assert(args: AttestationArgs, strict?: boolean): void;
|
|
157
|
+
get data(): T;
|
|
158
|
+
get uid(): Hex;
|
|
159
|
+
set uid(uid: Hex);
|
|
160
|
+
/**
|
|
161
|
+
* Create attestation to serve as Attestation data.
|
|
162
|
+
* @param data Data to attest
|
|
163
|
+
* @param schema selected schema
|
|
164
|
+
* @param from attester
|
|
165
|
+
* @param to recipient
|
|
166
|
+
* @returns
|
|
167
|
+
*/
|
|
168
|
+
static factory<T = unknown>(data: T, schema: Schema, from: Hex, to: Hex): Attestation<T, Schema<string>>;
|
|
169
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
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"), // Use GapSchema.find("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"),
|
|
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());
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Encodes the schema.
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
encodeSchema(schema) {
|
|
58
|
+
return this.schema.encode(schema);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sets a field in the schema.
|
|
62
|
+
*/
|
|
63
|
+
setValue(key, value) {
|
|
64
|
+
this.schema.setValue(key, value);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Set attestation values to be uploaded.
|
|
68
|
+
* @param values
|
|
69
|
+
*/
|
|
70
|
+
setValues(values) {
|
|
71
|
+
const isJsonSchema = this.schema.isJsonSchema();
|
|
72
|
+
if (isJsonSchema)
|
|
73
|
+
this.schema.setValue("json", JSON.stringify(values));
|
|
74
|
+
this._data = values;
|
|
75
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
76
|
+
this[key] = value;
|
|
77
|
+
if (!isJsonSchema)
|
|
78
|
+
this.setValue(key, value.value || value);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the referenced attestation
|
|
83
|
+
*/
|
|
84
|
+
reference() {
|
|
85
|
+
return this._reference;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns the attestation data as a JSON string.
|
|
89
|
+
* @param data
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
fromDecodedSchema(data) {
|
|
93
|
+
return typeof data === "string"
|
|
94
|
+
? Attestation.fromDecodedSchema(data)
|
|
95
|
+
: data;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Revokes this attestation.
|
|
99
|
+
* @param eas
|
|
100
|
+
* @param signer
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
revoke(signer) {
|
|
104
|
+
try {
|
|
105
|
+
return GapContract_1.GapContract.multiRevoke(signer, [
|
|
106
|
+
{
|
|
107
|
+
data: [
|
|
108
|
+
{
|
|
109
|
+
uid: this.uid,
|
|
110
|
+
value: 0n,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
schema: this.schema.uid,
|
|
114
|
+
},
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.error(error);
|
|
119
|
+
throw new SchemaError_1.SchemaError("REVOKE_ERROR", "Error revoking attestation.");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Attests the data using the specified signer and schema.
|
|
124
|
+
* @param signer - The signer or provider to use for attestation.
|
|
125
|
+
* @param args - Additional arguments to pass to the schema's `attest` method.
|
|
126
|
+
* @returns A Promise that resolves to the UID of the attestation.
|
|
127
|
+
* @throws An `AttestationError` if an error occurs during attestation.
|
|
128
|
+
*/
|
|
129
|
+
async attest(signer, ...args) {
|
|
130
|
+
console.log(`Attesting ${this.schema.name}`);
|
|
131
|
+
try {
|
|
132
|
+
const uid = await this.schema.attest({
|
|
133
|
+
data: this.data,
|
|
134
|
+
to: this.recipient,
|
|
135
|
+
refUID: this.refUID,
|
|
136
|
+
signer,
|
|
137
|
+
});
|
|
138
|
+
this._uid = uid;
|
|
139
|
+
console.log(`Attested ${this.schema.name} with UID ${uid}`);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error(error);
|
|
143
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Error during attestation.");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Validates the payload.
|
|
148
|
+
*
|
|
149
|
+
* If an attestation should have anything
|
|
150
|
+
* specifically explicit, it should be implemented in
|
|
151
|
+
* order to avoid errors.
|
|
152
|
+
* @returns
|
|
153
|
+
*/
|
|
154
|
+
assertPayload() {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get the multi attestation payload for the referred index.
|
|
159
|
+
*
|
|
160
|
+
* The index should be the array position this payload wants
|
|
161
|
+
* to reference.
|
|
162
|
+
*
|
|
163
|
+
* E.g:
|
|
164
|
+
*
|
|
165
|
+
* 1. Project is index 0;
|
|
166
|
+
* 2. Project details is index 1;
|
|
167
|
+
* 3. Grant is index 2;
|
|
168
|
+
* 4. Grant details is index 3;
|
|
169
|
+
* 5. Milestone is index 4;
|
|
170
|
+
*
|
|
171
|
+
* `[Project, projectDetails, grant, grantDetails, milestone]`
|
|
172
|
+
*
|
|
173
|
+
* -> Project.payloadFor(0); // refs itself (no effect)
|
|
174
|
+
*
|
|
175
|
+
* -> project.details.payloadFor(0); // ref project
|
|
176
|
+
*
|
|
177
|
+
* -> grant.payloadFor(0); // ref project
|
|
178
|
+
*
|
|
179
|
+
* -> grant.details.payloadFor(2); // ref grant
|
|
180
|
+
*
|
|
181
|
+
* -> milestone.payloadFor(2); // ref grant
|
|
182
|
+
*
|
|
183
|
+
*
|
|
184
|
+
* @param refIdx
|
|
185
|
+
* @returns [Encoded payload, Raw payload]
|
|
186
|
+
*/
|
|
187
|
+
payloadFor(refIdx) {
|
|
188
|
+
this.assertPayload();
|
|
189
|
+
const payload = (encode = true) => ({
|
|
190
|
+
uid: consts_1.nullRef,
|
|
191
|
+
refIdx,
|
|
192
|
+
multiRequest: {
|
|
193
|
+
schema: this.schema.uid,
|
|
194
|
+
data: [
|
|
195
|
+
{
|
|
196
|
+
refUID: this.refUID,
|
|
197
|
+
expirationTime: 0n,
|
|
198
|
+
revocable: this.schema.revocable || true,
|
|
199
|
+
value: 0n,
|
|
200
|
+
data: (encode ? this.schema.encode() : this.schema.schema),
|
|
201
|
+
recipient: this.recipient,
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
payload: payload(),
|
|
208
|
+
raw: payload(false),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Returns an Attestation instance from a JSON decoded schema.
|
|
213
|
+
* @param data
|
|
214
|
+
* @returns
|
|
215
|
+
*/
|
|
216
|
+
static fromDecodedSchema(data) {
|
|
217
|
+
try {
|
|
218
|
+
const parsed = JSON.parse(data);
|
|
219
|
+
if (data.length < 2 && !/\{.*\}/gim.test(data))
|
|
220
|
+
return {};
|
|
221
|
+
if (parsed.length === 1 && parsed[0].name === "json") {
|
|
222
|
+
const { value } = parsed[0];
|
|
223
|
+
return (typeof value.value === "string"
|
|
224
|
+
? JSON.parse(value.value)
|
|
225
|
+
: value.value);
|
|
226
|
+
}
|
|
227
|
+
if (parsed && Array.isArray(parsed)) {
|
|
228
|
+
return parsed.reduce((acc, curr) => {
|
|
229
|
+
const { value } = curr.value;
|
|
230
|
+
if (curr.type.includes("uint")) {
|
|
231
|
+
acc[curr.name] = ["string", "bigint"].includes(typeof value)
|
|
232
|
+
? BigInt(value)
|
|
233
|
+
: Number(value);
|
|
234
|
+
}
|
|
235
|
+
else
|
|
236
|
+
acc[curr.name] = value;
|
|
237
|
+
return acc;
|
|
238
|
+
}, {});
|
|
239
|
+
}
|
|
240
|
+
throw new SchemaError_1.SchemaError("INVALID_DATA", "Data must be a valid JSON array string.");
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
console.error(error);
|
|
244
|
+
throw new SchemaError_1.SchemaError("INVALID_DATA", "Data must be a valid JSON string.");
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Transform attestation interface-based into class-based.
|
|
249
|
+
*/
|
|
250
|
+
static fromInterface(attestations) {
|
|
251
|
+
const result = [];
|
|
252
|
+
attestations.forEach((attestation) => {
|
|
253
|
+
try {
|
|
254
|
+
const schema = Schema_1.Schema.get(attestation.schemaId);
|
|
255
|
+
result.push(new Attestation({
|
|
256
|
+
...attestation,
|
|
257
|
+
schema,
|
|
258
|
+
data: attestation.decodedDataJson,
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
console.log(e);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Asserts if schema is valid.
|
|
269
|
+
* > Does not check refUID if `strict = false`. To check refUID use `Schema.validate()`
|
|
270
|
+
* @param args
|
|
271
|
+
*/
|
|
272
|
+
assert(args, strict = false) {
|
|
273
|
+
const { schema, uid } = args;
|
|
274
|
+
if (!schema || !(schema instanceof Schema_1.Schema)) {
|
|
275
|
+
throw new SchemaError_1.SchemaError("MISSING_FIELD", "Schema must be an array.");
|
|
276
|
+
}
|
|
277
|
+
if (!uid) {
|
|
278
|
+
throw new SchemaError_1.SchemaError("MISSING_FIELD", "Schema uid is required");
|
|
279
|
+
}
|
|
280
|
+
if (strict)
|
|
281
|
+
Schema_1.Schema.validate();
|
|
282
|
+
}
|
|
283
|
+
get data() {
|
|
284
|
+
return this._data;
|
|
285
|
+
}
|
|
286
|
+
get uid() {
|
|
287
|
+
return this._uid;
|
|
288
|
+
}
|
|
289
|
+
set uid(uid) {
|
|
290
|
+
this._uid = uid;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Create attestation to serve as Attestation data.
|
|
294
|
+
* @param data Data to attest
|
|
295
|
+
* @param schema selected schema
|
|
296
|
+
* @param from attester
|
|
297
|
+
* @param to recipient
|
|
298
|
+
* @returns
|
|
299
|
+
*/
|
|
300
|
+
static factory(data, schema, from, to) {
|
|
301
|
+
return new Attestation({
|
|
302
|
+
data: data,
|
|
303
|
+
recipient: to,
|
|
304
|
+
attester: from,
|
|
305
|
+
schema,
|
|
306
|
+
uid: "0x0",
|
|
307
|
+
createdAt: new Date(),
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
exports.Attestation = Attestation;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Hex, IAttestation, TSchemaName } from "core/types";
|
|
2
|
+
import { Attestation } from "./Attestation";
|
|
3
|
+
import { Community, Grant, MemberOf, Milestone, Project } from "./entities";
|
|
4
|
+
import { Grantee } from "./types/attestations";
|
|
5
|
+
import { AxiosGQL } from "./GraphQL/AxiosGQL";
|
|
6
|
+
export declare abstract class Fetcher extends AxiosGQL {
|
|
7
|
+
/**
|
|
8
|
+
* Fetch a single attestation by its UID.
|
|
9
|
+
* @param uid
|
|
10
|
+
*/
|
|
11
|
+
abstract attestation<T = unknown>(uid: Hex): Promise<Attestation<T>>;
|
|
12
|
+
/**
|
|
13
|
+
* Fetch attestations of a schema.
|
|
14
|
+
* @param schemaName
|
|
15
|
+
* @param search if set, will search decodedDataJson by the value.
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
abstract attestations(schemaName: TSchemaName, search?: string): Promise<IAttestation[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Fetch attestations of a schema.
|
|
21
|
+
* @param schemaName
|
|
22
|
+
* @param recipient
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
abstract attestationsOf(schemaName: TSchemaName, recipient: Hex): Promise<IAttestation[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Fetch attestations of a schema for a specific recipient.
|
|
28
|
+
* @param schemaName
|
|
29
|
+
* @param recipient
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
abstract attestationsTo(schemaName: TSchemaName, recipient: Hex): Promise<IAttestation[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Fetch all available communities with details and grantees uids.
|
|
35
|
+
*
|
|
36
|
+
* If search is defined, will try to find communities by the search string.
|
|
37
|
+
* @param search
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
abstract communities(search?: string): Promise<Community[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Fetch a set of communities by their ids.
|
|
43
|
+
* @param uids
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
abstract communitiesByIds(uids: Hex[]): Promise<Community[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Fetch a community by its name with details, grants and milestones.
|
|
49
|
+
*
|
|
50
|
+
* It is possible that the resulted community is not the one you are looking for.
|
|
51
|
+
* @param name
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
abstract communityBySlug(slug: string): Promise<Community>;
|
|
55
|
+
/**
|
|
56
|
+
* Fetch a community by its id. This method will also return the
|
|
57
|
+
* community details and projects.
|
|
58
|
+
*/
|
|
59
|
+
abstract communityById(uid: Hex): Promise<Community>;
|
|
60
|
+
/**
|
|
61
|
+
* Fetch a project by its id.
|
|
62
|
+
* @param uid
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
abstract projectById(uid: Hex): Promise<Project>;
|
|
66
|
+
/**
|
|
67
|
+
* Fetch a project by its slug.
|
|
68
|
+
* @param slug
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
abstract projectBySlug(slug: string): Promise<Project>;
|
|
72
|
+
/**
|
|
73
|
+
* Fetch projects with details and members.
|
|
74
|
+
* @param name if set, will search by the name.
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
abstract projects(name?: string): Promise<Project[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Fetch projects with details and members.
|
|
80
|
+
* @param grantee the public address of the grantee
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
abstract projectsOf(grantee: Hex): Promise<Project[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Fetch Grantee with details and projects.
|
|
86
|
+
* @param address
|
|
87
|
+
* @param withProjects if true, will get grantee project details.
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
abstract grantee(address: Hex): Promise<Grantee>;
|
|
91
|
+
/**
|
|
92
|
+
* Fetch all Grantees with details.
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
abstract grantees(): Promise<Grantee[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Fetches the grantes related to a grantee address (recipient).
|
|
98
|
+
* @param grantee grantee address
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
abstract grantsOf(grantee: Hex, withCommunity?: boolean): Promise<Grant[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Fetch grants for an array of projects with milestones.
|
|
104
|
+
* @param projects
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
abstract grantsFor(projects: Project[], withCommunity?: boolean): Promise<Grant[]>;
|
|
108
|
+
/**
|
|
109
|
+
* Fetch a grants that belongs to a community.
|
|
110
|
+
* @param uid community uid
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
abstract grantsByCommunity(uid: Hex): any;
|
|
114
|
+
/**
|
|
115
|
+
* Fetch all milestones related to an array of Grants.
|
|
116
|
+
* @param grants
|
|
117
|
+
* @returns
|
|
118
|
+
*/
|
|
119
|
+
abstract milestonesOf(grants: Grant[]): Promise<Milestone[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Bulk fetch members with details of an array of Projects.
|
|
122
|
+
* @param projects
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
abstract membersOf(projects: Project[]): Promise<MemberOf[]>;
|
|
126
|
+
/**
|
|
127
|
+
* Check if a name is already in use.
|
|
128
|
+
* @param slug
|
|
129
|
+
* @returns
|
|
130
|
+
*/
|
|
131
|
+
abstract slugExists(slug: string): Promise<boolean>;
|
|
132
|
+
}
|