@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
package/core/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Facade = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Generic GAP Facade interface.
|
|
6
|
+
* This supplies the GAP class with the necessary properties.
|
|
7
|
+
*/
|
|
8
|
+
class Facade {
|
|
9
|
+
static get eas() {
|
|
10
|
+
return this._eas;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Facade = Facade;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./send-gelato-txn"), exports);
|
|
18
|
+
__exportStar(require("./sponsor-handler"), exports);
|
|
19
|
+
__exportStar(require("./watch-gelato-txn"), exports);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { GelatoRelay } from "@gelatonetwork/relay-sdk";
|
|
2
|
+
import { Hex } from "../../types";
|
|
3
|
+
declare function sendByUrl(...params: Parameters<GelatoRelay["sponsoredCall"]>): Promise<string>;
|
|
4
|
+
/**
|
|
5
|
+
* Send gelato using an explicit api key.
|
|
6
|
+
*
|
|
7
|
+
* > __This is not safe in the frontend.__
|
|
8
|
+
*
|
|
9
|
+
* @param params
|
|
10
|
+
* @returns Gelato's task id and a wait function.
|
|
11
|
+
*/
|
|
12
|
+
declare function sendByApiKey(...params: Parameters<GelatoRelay["sponsoredCall"]>): Promise<{
|
|
13
|
+
taskId: string;
|
|
14
|
+
/**
|
|
15
|
+
* Waits for the transaction to be confirmed by Gelato.
|
|
16
|
+
* @returns Txn id
|
|
17
|
+
*/
|
|
18
|
+
wait: () => Promise<string>;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Sends a sponsored call using GelatoRelay
|
|
22
|
+
* @param payload
|
|
23
|
+
* @returns txn hash
|
|
24
|
+
*/
|
|
25
|
+
declare function sendGelatoTxn(...params: Parameters<GelatoRelay["sponsoredCall"]>): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Builds the arguments for a sponsored call using GelatoRelay
|
|
28
|
+
* @param data Populated contract call.
|
|
29
|
+
* @param chainId
|
|
30
|
+
* @param target target contract address (Hex)
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* const { data } = await contract.populateTransaction.transfer(
|
|
36
|
+
* recipient,
|
|
37
|
+
* amount
|
|
38
|
+
* );
|
|
39
|
+
* const args = buildArgs(data, chainId, target);
|
|
40
|
+
* const txn = sendGelatoTxn(...args);
|
|
41
|
+
* console.log(txn) // 0xabc..
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function buildArgs(
|
|
45
|
+
/**
|
|
46
|
+
* Populated transaction data.
|
|
47
|
+
*/
|
|
48
|
+
data: string, chainId: bigint, target: Hex): Parameters<GelatoRelay["sponsoredCall"]>;
|
|
49
|
+
declare const Gelato: {
|
|
50
|
+
sendByApiKey: typeof sendByApiKey;
|
|
51
|
+
sendByUrl: typeof sendByUrl;
|
|
52
|
+
buildArgs: typeof buildArgs;
|
|
53
|
+
};
|
|
54
|
+
export { sendGelatoTxn, Gelato };
|
|
@@ -0,0 +1,99 @@
|
|
|
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.Gelato = exports.sendGelatoTxn = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const relay_sdk_1 = require("@gelatonetwork/relay-sdk");
|
|
9
|
+
const watch_gelato_txn_1 = require("./watch-gelato-txn");
|
|
10
|
+
const GAP_1 = require("../../class/GAP");
|
|
11
|
+
async function sendByUrl(...params) {
|
|
12
|
+
const { data } = await axios_1.default.post(GAP_1.GAP.gelatoOpts.sponsorUrl, params);
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Send gelato using an explicit api key.
|
|
17
|
+
*
|
|
18
|
+
* > __This is not safe in the frontend.__
|
|
19
|
+
*
|
|
20
|
+
* @param params
|
|
21
|
+
* @returns Gelato's task id and a wait function.
|
|
22
|
+
*/
|
|
23
|
+
async function sendByApiKey(...params) {
|
|
24
|
+
const { apiKey } = GAP_1.GAP?.gelatoOpts || {};
|
|
25
|
+
if (!apiKey && params[1] === "{apiKey}")
|
|
26
|
+
throw new Error("No api key provided.");
|
|
27
|
+
if (apiKey && params[1] === "{apiKey}")
|
|
28
|
+
params[1] = apiKey;
|
|
29
|
+
const client = new relay_sdk_1.GelatoRelay();
|
|
30
|
+
const relayResponse = await client.sponsoredCall(...params);
|
|
31
|
+
return {
|
|
32
|
+
taskId: relayResponse.taskId,
|
|
33
|
+
/**
|
|
34
|
+
* Waits for the transaction to be confirmed by Gelato.
|
|
35
|
+
* @returns Txn id
|
|
36
|
+
*/
|
|
37
|
+
wait: () => (0, watch_gelato_txn_1.watchGelatoTxn)(relayResponse.taskId),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Sends a sponsored call using GelatoRelay
|
|
42
|
+
* @param payload
|
|
43
|
+
* @returns txn hash
|
|
44
|
+
*/
|
|
45
|
+
async function sendGelatoTxn(...params) {
|
|
46
|
+
if (!GAP_1.GAP.gelatoOpts)
|
|
47
|
+
throw new Error("Gelato opts not set.");
|
|
48
|
+
const { env_gelatoApiKey, sponsorUrl, useGasless, contained } = GAP_1.GAP.gelatoOpts;
|
|
49
|
+
if (!useGasless)
|
|
50
|
+
throw new Error("Gasless is not enabled.");
|
|
51
|
+
if ((sponsorUrl && contained && env_gelatoApiKey) ||
|
|
52
|
+
(sponsorUrl && !contained)) {
|
|
53
|
+
return sendByUrl(...params);
|
|
54
|
+
}
|
|
55
|
+
const { wait } = await sendByApiKey(...params);
|
|
56
|
+
return wait();
|
|
57
|
+
}
|
|
58
|
+
exports.sendGelatoTxn = sendGelatoTxn;
|
|
59
|
+
/**
|
|
60
|
+
* Builds the arguments for a sponsored call using GelatoRelay
|
|
61
|
+
* @param data Populated contract call.
|
|
62
|
+
* @param chainId
|
|
63
|
+
* @param target target contract address (Hex)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* const { data } = await contract.populateTransaction.transfer(
|
|
69
|
+
* recipient,
|
|
70
|
+
* amount
|
|
71
|
+
* );
|
|
72
|
+
* const args = buildArgs(data, chainId, target);
|
|
73
|
+
* const txn = sendGelatoTxn(...args);
|
|
74
|
+
* console.log(txn) // 0xabc..
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
function buildArgs(
|
|
78
|
+
/**
|
|
79
|
+
* Populated transaction data.
|
|
80
|
+
*/
|
|
81
|
+
data, chainId, target) {
|
|
82
|
+
return [
|
|
83
|
+
{
|
|
84
|
+
data,
|
|
85
|
+
chainId,
|
|
86
|
+
target,
|
|
87
|
+
},
|
|
88
|
+
"{apiKey}",
|
|
89
|
+
{
|
|
90
|
+
retries: 3,
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
const Gelato = {
|
|
95
|
+
sendByApiKey,
|
|
96
|
+
sendByUrl,
|
|
97
|
+
buildArgs,
|
|
98
|
+
};
|
|
99
|
+
exports.Gelato = Gelato;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ApiRequest {
|
|
2
|
+
method: string;
|
|
3
|
+
body: unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface ApiResponse {
|
|
6
|
+
statusCode: number;
|
|
7
|
+
send: (body: unknown) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function handler(req: ApiRequest, res: ApiResponse, env_gelatoApiKey: string): Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = void 0;
|
|
4
|
+
const send_gelato_txn_1 = require("./send-gelato-txn");
|
|
5
|
+
const assertionObj = [
|
|
6
|
+
{
|
|
7
|
+
data: /0x[a-fA-F0-9]+/gim,
|
|
8
|
+
chainId: /\d+/,
|
|
9
|
+
target: /0x[a-fA-F0-9]{40}/gim,
|
|
10
|
+
},
|
|
11
|
+
/\{apiKey\}/,
|
|
12
|
+
{
|
|
13
|
+
retries: /\d+/,
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
function assert(body) {
|
|
17
|
+
if (!Array.isArray(body) || body.length !== assertionObj.length)
|
|
18
|
+
throw new Error("Invalid request body");
|
|
19
|
+
assertionObj.forEach((item, index) => {
|
|
20
|
+
// check if objects from assertion Object are present in body
|
|
21
|
+
// and test them using the regexp from the assertion Object
|
|
22
|
+
if (typeof item === "object") {
|
|
23
|
+
Object.entries(item).forEach(([key, value]) => {
|
|
24
|
+
if (!body[index][key]?.toString().match(value))
|
|
25
|
+
throw new Error("Invalid request body");
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// test other items as strings
|
|
29
|
+
else if (!body[index]?.toString().match(item))
|
|
30
|
+
throw new Error("Invalid request body");
|
|
31
|
+
});
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
async function handler(req, res, env_gelatoApiKey) {
|
|
35
|
+
if (req.method !== "POST") {
|
|
36
|
+
res.statusCode = 405;
|
|
37
|
+
res.send("Method not allowed");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const body = req.body;
|
|
42
|
+
if (!assert(body))
|
|
43
|
+
return;
|
|
44
|
+
const { [env_gelatoApiKey]: apiKey } = process.env;
|
|
45
|
+
if (!apiKey)
|
|
46
|
+
throw new Error("Api key not provided.");
|
|
47
|
+
body[1] = apiKey;
|
|
48
|
+
const result = await send_gelato_txn_1.Gelato.sendByApiKey(...body);
|
|
49
|
+
const txId = await result.wait();
|
|
50
|
+
res.send(txId);
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.log(error);
|
|
56
|
+
res.statusCode = 400;
|
|
57
|
+
res.send(error.message);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.watchGelatoTxn = void 0;
|
|
4
|
+
const relay_sdk_1 = require("@gelatonetwork/relay-sdk");
|
|
5
|
+
var TaskState;
|
|
6
|
+
(function (TaskState) {
|
|
7
|
+
TaskState["CheckPending"] = "CheckPending";
|
|
8
|
+
TaskState["ExecPending"] = "ExecPending";
|
|
9
|
+
TaskState["ExecSuccess"] = "ExecSuccess";
|
|
10
|
+
TaskState["ExecReverted"] = "ExecReverted";
|
|
11
|
+
TaskState["WaitingForConfirmation"] = "WaitingForConfirmation";
|
|
12
|
+
TaskState["Blacklisted"] = "Blacklisted";
|
|
13
|
+
TaskState["Cancelled"] = "Cancelled";
|
|
14
|
+
TaskState["NotFound"] = "NotFound";
|
|
15
|
+
})(TaskState || (TaskState = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Waits for a transaction to be mined at Gelato Network
|
|
18
|
+
* @param taskId
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
async function watchGelatoTxn(taskId) {
|
|
22
|
+
const client = new relay_sdk_1.GelatoRelay();
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const loop = async () => {
|
|
25
|
+
const oneSecond = 1;
|
|
26
|
+
while (oneSecond) {
|
|
27
|
+
const status = await client.getTaskStatus(taskId);
|
|
28
|
+
// print status :D so we can debug this for now
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.log(status);
|
|
31
|
+
if (!status) {
|
|
32
|
+
reject(new Error("Transaction goes wrong."));
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
if (status && status.taskState === TaskState.ExecSuccess) {
|
|
36
|
+
resolve(status.transactionHash || "");
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
else if ([
|
|
40
|
+
TaskState.Cancelled,
|
|
41
|
+
TaskState.ExecReverted,
|
|
42
|
+
TaskState.Blacklisted,
|
|
43
|
+
].includes(status?.taskState)) {
|
|
44
|
+
reject(new Error(status.lastCheckMessage
|
|
45
|
+
?.split(/(RegisterDelegate)|(Execution error): /)
|
|
46
|
+
.at(-1) || ""));
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
loop();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.watchGelatoTxn = watchGelatoTxn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDate(date: Date | number): Date;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Hex } from "../types";
|
|
2
|
+
export declare const gqlQueries: {
|
|
3
|
+
attestation: (uid: Hex) => string;
|
|
4
|
+
attestations: (schemaId: Hex, uid: Hex) => string;
|
|
5
|
+
attestationsIn: (uids: Hex[], search?: string) => string;
|
|
6
|
+
attestationsFrom: (schemaId: Hex, attester: Hex) => string;
|
|
7
|
+
attestationsTo: (schemaId: Hex, recipient: Hex) => string;
|
|
8
|
+
attestationPairs: (schemaId: Hex, attester: Hex, recipient: Hex) => string;
|
|
9
|
+
attestationsOf: (schemaId: Hex, search?: string[] | string, refUids?: Hex[]) => string;
|
|
10
|
+
dependentsOf: (refs: Hex | Hex[], schemaIds: Hex[], attesters?: Hex[]) => string;
|
|
11
|
+
schemata: (creator: Hex) => string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gqlQueries = void 0;
|
|
4
|
+
const inStatement = (values) => `[${values.map((v) => `"${v}"`).join(",")}]`;
|
|
5
|
+
const attestationFields = `
|
|
6
|
+
uid: id
|
|
7
|
+
attester
|
|
8
|
+
data
|
|
9
|
+
decodedDataJson
|
|
10
|
+
recipient
|
|
11
|
+
revoked
|
|
12
|
+
createdAt: timeCreated
|
|
13
|
+
refUID
|
|
14
|
+
isOffchain
|
|
15
|
+
revocable
|
|
16
|
+
revocationTime
|
|
17
|
+
schemaId
|
|
18
|
+
`;
|
|
19
|
+
const schemaQuery = (schemaId, content) => `{schema(where: {id: "${schemaId}"}) {${content}}}`;
|
|
20
|
+
exports.gqlQueries = {
|
|
21
|
+
attestation: (uid) => `
|
|
22
|
+
{
|
|
23
|
+
attestation(where: {
|
|
24
|
+
id: "${uid}"
|
|
25
|
+
}) {${attestationFields}}
|
|
26
|
+
}`,
|
|
27
|
+
attestations: (schemaId, uid) => schemaQuery(schemaId, `attestations(where: {
|
|
28
|
+
revoked: {equals: false}
|
|
29
|
+
decodedDataJson: {contains: "${uid}"}
|
|
30
|
+
}) {${attestationFields}}`),
|
|
31
|
+
attestationsIn: (uids, search) => `
|
|
32
|
+
{
|
|
33
|
+
attestations(where: {
|
|
34
|
+
id:{in: ${inStatement(uids)}}
|
|
35
|
+
revoked:{equals:false}
|
|
36
|
+
${search
|
|
37
|
+
? `decodedDataJson:{contains:"${search}",mode:insensitive}`
|
|
38
|
+
: ""}
|
|
39
|
+
}) {${attestationFields}}
|
|
40
|
+
}`,
|
|
41
|
+
attestationsFrom: (schemaId, attester) => schemaQuery(schemaId, `attestations(orderBy:{timeCreated: desc},
|
|
42
|
+
where:{attester:{equals:"${attester}"}
|
|
43
|
+
revoked:{equals:false}
|
|
44
|
+
}){${attestationFields}}`),
|
|
45
|
+
attestationsTo: (schemaId, recipient) => schemaQuery(schemaId, `attestations(orderBy:{timeCreated: desc},
|
|
46
|
+
where:{
|
|
47
|
+
recipient:{equals:"${recipient}"}
|
|
48
|
+
revoked:{equals:false}
|
|
49
|
+
}){${attestationFields}}`),
|
|
50
|
+
attestationPairs: (schemaId, attester, recipient) => schemaQuery(schemaId, `attestations(where: {
|
|
51
|
+
attester: {equals: "${attester}"}
|
|
52
|
+
recipient: {equals: "${recipient}"}
|
|
53
|
+
revoked: {equals: false}
|
|
54
|
+
}) {${attestationFields}}`),
|
|
55
|
+
attestationsOf: (schemaId, search, refUids) => schemaQuery(schemaId, `attestations(orderBy:{timeCreated: desc},
|
|
56
|
+
where: {
|
|
57
|
+
revoked:{equals:false}
|
|
58
|
+
${refUids && refUids.length
|
|
59
|
+
? `refUID:{in: ${inStatement(refUids)}}`
|
|
60
|
+
: ""}
|
|
61
|
+
${search
|
|
62
|
+
? `OR: [
|
|
63
|
+
${[search]
|
|
64
|
+
.flat()
|
|
65
|
+
.map((s) => `{decodedDataJson:{contains:"${s}",mode:insensitive}}`)
|
|
66
|
+
.join(",")}
|
|
67
|
+
]`
|
|
68
|
+
: ""}
|
|
69
|
+
})
|
|
70
|
+
{${attestationFields}}`),
|
|
71
|
+
dependentsOf: (refs, schemaIds, attesters = []) => `
|
|
72
|
+
{
|
|
73
|
+
attestations(
|
|
74
|
+
orderBy:{timeCreated: desc},
|
|
75
|
+
where: {
|
|
76
|
+
refUID:{in: ${inStatement([refs].flat())}}
|
|
77
|
+
revoked:{equals: false}
|
|
78
|
+
schemaId:{in: ${inStatement(schemaIds)}}
|
|
79
|
+
${attesters.length ? `attester:{in:${inStatement(attesters)}}` : ""}
|
|
80
|
+
}){${attestationFields}}
|
|
81
|
+
}
|
|
82
|
+
`,
|
|
83
|
+
schemata: (creator) => `
|
|
84
|
+
{
|
|
85
|
+
schemata(where: {creator: {equals: "${creator}"}}) {
|
|
86
|
+
uid: id
|
|
87
|
+
schema
|
|
88
|
+
}
|
|
89
|
+
}`,
|
|
90
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./gelato"), exports);
|
|
18
|
+
__exportStar(require("./get-date"), exports);
|
|
19
|
+
__exportStar(require("./gql-queries"), exports);
|
|
20
|
+
__exportStar(require("./map-filter"), exports);
|
|
21
|
+
__exportStar(require("./serialize-bigint"), exports);
|
|
22
|
+
__exportStar(require("./to-unix"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters an array by its condition then maps it to the desired format.
|
|
3
|
+
* @param arr
|
|
4
|
+
* @param condition
|
|
5
|
+
* @param mapTo
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function mapFilter<T = unknown, U = unknown>(arr: U[], condition: (item: U) => boolean, mapTo: (item: U) => T): T[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapFilter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Filters an array by its condition then maps it to the desired format.
|
|
6
|
+
* @param arr
|
|
7
|
+
* @param condition
|
|
8
|
+
* @param mapTo
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
function mapFilter(arr, condition, mapTo) {
|
|
12
|
+
const newArray = [];
|
|
13
|
+
for (const item of arr) {
|
|
14
|
+
if (condition(item)) {
|
|
15
|
+
newArray.push(mapTo(item));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return newArray;
|
|
19
|
+
}
|
|
20
|
+
exports.mapFilter = mapFilter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function serializeWithBigint(value: unknown): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeWithBigint = void 0;
|
|
4
|
+
function serializeWithBigint(value) {
|
|
5
|
+
return JSON.stringify(value, (this,
|
|
6
|
+
(key, value) => (typeof value === "bigint" ? value.toString() : value)));
|
|
7
|
+
}
|
|
8
|
+
exports.serializeWithBigint = serializeWithBigint;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toUnix(value: number | Date | string): number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toUnix = void 0;
|
|
4
|
+
function toUnix(value) {
|
|
5
|
+
switch (typeof value) {
|
|
6
|
+
case "number":
|
|
7
|
+
value = Math.round(value);
|
|
8
|
+
if (value.toString().length > 13)
|
|
9
|
+
throw new Error("Invalid timestamp length");
|
|
10
|
+
if (value.toString().length === 10)
|
|
11
|
+
return value;
|
|
12
|
+
return Math.floor(value / 1000);
|
|
13
|
+
case "string":
|
|
14
|
+
if (/\D/.test(value))
|
|
15
|
+
return null;
|
|
16
|
+
return toUnix(+value);
|
|
17
|
+
case "object":
|
|
18
|
+
if (value instanceof Date)
|
|
19
|
+
return toUnix(value.getTime());
|
|
20
|
+
return null;
|
|
21
|
+
default:
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.toUnix = toUnix;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|
package/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./core"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@show-karma/karma-gap-sdk",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.1.29",
|
|
7
|
+
"description": "Simple and easy interface between EAS and Karma GAP.",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"author": "KarmaHQ",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"private": false,
|
|
12
|
+
"repository": {
|
|
13
|
+
"url": "https://github.com/show-karma/karma-gap-sdk",
|
|
14
|
+
"type": "git"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"deploy": "npx ts-node ./core/scripts/deploy.ts",
|
|
18
|
+
"csv-upload": "npx ts-node ./csv-upload/scripts/run.ts"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@ethereum-attestation-service/eas-sdk": "^1.1.0-beta.2",
|
|
22
|
+
"@gelatonetwork/relay-sdk": "^5.2.0",
|
|
23
|
+
"@types/sha256": "^0.2.0",
|
|
24
|
+
"axios": "^1.4.0",
|
|
25
|
+
"ethers": "5.7",
|
|
26
|
+
"sha256": "^0.2.0",
|
|
27
|
+
"simple-ts-job-runner": "^1.0.12"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^20.5.0",
|
|
31
|
+
"eslint": "^8.47.0",
|
|
32
|
+
"fast-csv": "^4.3.6",
|
|
33
|
+
"husky": "^8.0.3",
|
|
34
|
+
"prettier": "^3.0.1",
|
|
35
|
+
"typescript": "^5.1.6"
|
|
36
|
+
}
|
|
37
|
+
}
|