@show-karma/karma-gap-sdk 0.4.21 → 0.4.22
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/class/GAP.js +8 -0
- package/core/class/remote-storage/IpfsStorage.d.ts +23 -0
- package/core/class/remote-storage/IpfsStorage.js +56 -0
- package/core/class/remote-storage/RemoteStorage.d.ts +41 -0
- package/core/class/remote-storage/RemoteStorage.js +38 -0
- package/core/consts.js +99 -18
- package/core/utils/get-ipfs-data.d.ts +1 -0
- package/core/utils/get-ipfs-data.js +19 -0
- package/package.json +1 -1
package/core/class/GAP.js
CHANGED
|
@@ -233,6 +233,10 @@ class GAP extends types_1.Facade {
|
|
|
233
233
|
const currentChainId = chainId ||
|
|
234
234
|
Number((await signer.provider.getNetwork())?.chainId ||
|
|
235
235
|
(await signer.getChainId()));
|
|
236
|
+
if (chainId && !rpcConfig) {
|
|
237
|
+
throw new Error(`rpcConfig is required when specifying chainId for cross-chain operations. ` +
|
|
238
|
+
`Either provide rpcConfig or omit chainId to use the signer's chain.`);
|
|
239
|
+
}
|
|
236
240
|
const provider = chainId && rpcConfig
|
|
237
241
|
? (0, get_web3_provider_1.getWeb3Provider)(chainId, rpcConfig)
|
|
238
242
|
: signer;
|
|
@@ -254,6 +258,10 @@ class GAP extends types_1.Facade {
|
|
|
254
258
|
const currentChainId = chainId ||
|
|
255
259
|
Number((await signer.provider.getNetwork())?.chainId ||
|
|
256
260
|
(await signer.getChainId()));
|
|
261
|
+
if (chainId && !rpcConfig) {
|
|
262
|
+
throw new Error(`rpcConfig is required when specifying chainId for cross-chain operations. ` +
|
|
263
|
+
`Either provide rpcConfig or omit chainId to use the signer's chain.`);
|
|
264
|
+
}
|
|
257
265
|
const provider = chainId && rpcConfig
|
|
258
266
|
? (0, get_web3_provider_1.getWeb3Provider)(chainId, rpcConfig)
|
|
259
267
|
: signer;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RemoteStorage } from "./RemoteStorage";
|
|
2
|
+
import { TRemoteStorageOutput } from "core/types";
|
|
3
|
+
export interface IpfsStorageOptions {
|
|
4
|
+
token: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class IpfsStorage extends RemoteStorage {
|
|
7
|
+
private pinataJWTToken;
|
|
8
|
+
constructor(opts: IpfsStorageOptions,
|
|
9
|
+
/**
|
|
10
|
+
* If set, will send request to another server instead of
|
|
11
|
+
* using the local instance
|
|
12
|
+
*/
|
|
13
|
+
sponsor?: RemoteStorage["sponsor"]);
|
|
14
|
+
private assert;
|
|
15
|
+
save<T = unknown>(data: T): Promise<string>;
|
|
16
|
+
encode(data: string): TRemoteStorageOutput<string>;
|
|
17
|
+
get<T = unknown>(args: {
|
|
18
|
+
cid: string;
|
|
19
|
+
}): Promise<T>;
|
|
20
|
+
saveAndGetCID(data: any, pinataMetadata?: {
|
|
21
|
+
name: string;
|
|
22
|
+
}): Promise<any>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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.IpfsStorage = void 0;
|
|
7
|
+
const RemoteStorage_1 = require("./RemoteStorage");
|
|
8
|
+
const SchemaError_1 = require("../SchemaError");
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
class IpfsStorage extends RemoteStorage_1.RemoteStorage {
|
|
12
|
+
constructor(opts,
|
|
13
|
+
/**
|
|
14
|
+
* If set, will send request to another server instead of
|
|
15
|
+
* using the local instance
|
|
16
|
+
*/
|
|
17
|
+
sponsor) {
|
|
18
|
+
super(0 /* STORAGE_TYPE.IPFS */, sponsor);
|
|
19
|
+
this.assert(opts);
|
|
20
|
+
this.pinataJWTToken = opts.token;
|
|
21
|
+
}
|
|
22
|
+
assert(opts) { }
|
|
23
|
+
async save(data) {
|
|
24
|
+
try {
|
|
25
|
+
const cid = await this.saveAndGetCID(data);
|
|
26
|
+
return cid;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new SchemaError_1.RemoteStorageError("REMOTE_STORAGE_UPLOAD", `Error adding data to IPFS`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
encode(data) {
|
|
33
|
+
return { hash: data, storageType: this.storageType };
|
|
34
|
+
}
|
|
35
|
+
async get(args) {
|
|
36
|
+
return (0, utils_1.getIPFSData)(args.cid);
|
|
37
|
+
}
|
|
38
|
+
async saveAndGetCID(data, pinataMetadata = { name: "via karma-gap-sdk" }) {
|
|
39
|
+
try {
|
|
40
|
+
const res = await axios_1.default.post("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
|
|
41
|
+
pinataContent: data,
|
|
42
|
+
pinataMetadata: pinataMetadata,
|
|
43
|
+
}, {
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
Authorization: `Bearer ${this.pinataJWTToken}`,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return res.data.IpfsHash;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new SchemaError_1.RemoteStorageError("REMOTE_STORAGE_UPLOAD", `Error adding data to IPFS`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.IpfsStorage = IpfsStorage;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { STORAGE_TYPE, TRemoteStorageOutput } from 'core/types';
|
|
2
|
+
interface SponsoredRemote {
|
|
3
|
+
url: string;
|
|
4
|
+
responseParser: (response: any) => string;
|
|
5
|
+
}
|
|
6
|
+
export declare abstract class RemoteStorage<C = unknown> {
|
|
7
|
+
protected client: C;
|
|
8
|
+
readonly storageType: number;
|
|
9
|
+
readonly sponsor?: SponsoredRemote;
|
|
10
|
+
constructor(storageType: STORAGE_TYPE,
|
|
11
|
+
/**
|
|
12
|
+
* If set, will try to POST request to another server instead of
|
|
13
|
+
* using the local instance.
|
|
14
|
+
*
|
|
15
|
+
* > If a response parser is not set, it will try to get { cid: string }.
|
|
16
|
+
*/
|
|
17
|
+
sponsor: SponsoredRemote);
|
|
18
|
+
/**
|
|
19
|
+
* Try to save data to remote storage and return the CID.
|
|
20
|
+
* IF sponsorUrl is set, this method will be automatically
|
|
21
|
+
* intercepted and will send a POST request to the sponsorUrl
|
|
22
|
+
* with the contents: `{ data: T, type: "<AttestationType>" }`
|
|
23
|
+
*/
|
|
24
|
+
abstract save<T = unknown>(data: T, schemaName: string): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Encodes the data according to the remote storage type parameters
|
|
27
|
+
* OR returns the data as is if no encoding is required
|
|
28
|
+
*/
|
|
29
|
+
abstract encode(data: unknown): TRemoteStorageOutput;
|
|
30
|
+
/**
|
|
31
|
+
* Get data from Remote Storage
|
|
32
|
+
*/
|
|
33
|
+
abstract get<T = unknown>(args: unknown): Promise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* If sponsorUrl is set, intercept the save method and send a POST request
|
|
36
|
+
* to the sponsorUrl instead of using the local instance.
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
private interceptRemoteStorage;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
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.RemoteStorage = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class RemoteStorage {
|
|
9
|
+
constructor(storageType,
|
|
10
|
+
/**
|
|
11
|
+
* If set, will try to POST request to another server instead of
|
|
12
|
+
* using the local instance.
|
|
13
|
+
*
|
|
14
|
+
* > If a response parser is not set, it will try to get { cid: string }.
|
|
15
|
+
*/
|
|
16
|
+
sponsor) {
|
|
17
|
+
this.storageType = storageType;
|
|
18
|
+
this.sponsor = sponsor;
|
|
19
|
+
this.interceptRemoteStorage();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* If sponsorUrl is set, intercept the save method and send a POST request
|
|
23
|
+
* to the sponsorUrl instead of using the local instance.
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
interceptRemoteStorage() {
|
|
27
|
+
if (!this.sponsor?.url)
|
|
28
|
+
return;
|
|
29
|
+
this.save = async (data, schemaName) => {
|
|
30
|
+
const { data: response } = await axios_1.default.post(this.sponsor.url, {
|
|
31
|
+
data: data,
|
|
32
|
+
type: schemaName,
|
|
33
|
+
});
|
|
34
|
+
return this.sponsor.responseParser?.(response) || response.cid;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.RemoteStorage = RemoteStorage;
|
package/core/consts.js
CHANGED
|
@@ -435,16 +435,43 @@ exports.Networks = {
|
|
|
435
435
|
Community: "0x3c2231024f4f17f3718b5bd9ed9ff29cc323dea5449f9ceba11a9888bfbdd0e1",
|
|
436
436
|
Details: "0x9895e82115987d8e3e02b35ced92e6a0509293890333f58f50ec291b34853dac",
|
|
437
437
|
Grant: "0x7afa603a89cee2d8f93d30007e2c64efddc6509fd76aa95d2ccd97b6e34acc71",
|
|
438
|
-
GrantVerified: "
|
|
438
|
+
GrantVerified: "0x837ae97827bdec74d0c8d755331634f730bb8ad00702099e9a6a2bbe193b1511",
|
|
439
439
|
MemberOf: "0xb4186a2401f40a4c78768941ef9140e1fbe5fe595053a65d44f31d6df180b712",
|
|
440
|
-
MilestoneApproved: "
|
|
441
|
-
MilestoneCompleted: "
|
|
442
|
-
GrantUpdateStatus: "
|
|
440
|
+
MilestoneApproved: "0x837ae97827bdec74d0c8d755331634f730bb8ad00702099e9a6a2bbe193b1511",
|
|
441
|
+
MilestoneCompleted: "0x837ae97827bdec74d0c8d755331634f730bb8ad00702099e9a6a2bbe193b1511",
|
|
442
|
+
GrantUpdateStatus: "0x837ae97827bdec74d0c8d755331634f730bb8ad00702099e9a6a2bbe193b1511",
|
|
443
443
|
Project: "0x672fbaa8a1fb6e1f73a89c84a8e97a808da0750003a9d1d18aba3d39fa165945",
|
|
444
|
-
ProjectUpdateStatus: "
|
|
445
|
-
ProjectMilestoneStatus: "
|
|
444
|
+
ProjectUpdateStatus: "0x837ae97827bdec74d0c8d755331634f730bb8ad00702099e9a6a2bbe193b1511",
|
|
445
|
+
ProjectMilestoneStatus: "0x837ae97827bdec74d0c8d755331634f730bb8ad00702099e9a6a2bbe193b1511",
|
|
446
446
|
ContributorProfile: null
|
|
447
447
|
},
|
|
448
|
+
oldSchemas: [
|
|
449
|
+
{
|
|
450
|
+
name: "GrantVerified",
|
|
451
|
+
uid: "0xf45fdf2c064073f0623416571c2746085d785cde5a57fd0696ff88bdf78bcbdc",
|
|
452
|
+
raw: oldStatusSchema
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
name: "MilestoneApproved",
|
|
456
|
+
uid: "0xf45fdf2c064073f0623416571c2746085d785cde5a57fd0696ff88bdf78bcbdc",
|
|
457
|
+
raw: oldStatusSchema
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
name: "MilestoneCompleted",
|
|
461
|
+
uid: "0xf45fdf2c064073f0623416571c2746085d785cde5a57fd0696ff88bdf78bcbdc",
|
|
462
|
+
raw: oldStatusSchema
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
name: "GrantUpdateStatus",
|
|
466
|
+
uid: "0xf45fdf2c064073f0623416571c2746085d785cde5a57fd0696ff88bdf78bcbdc",
|
|
467
|
+
raw: oldStatusSchema
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: "ProjectUpdateStatus",
|
|
471
|
+
uid: "0xf45fdf2c064073f0623416571c2746085d785cde5a57fd0696ff88bdf78bcbdc",
|
|
472
|
+
raw: oldStatusSchema
|
|
473
|
+
},
|
|
474
|
+
]
|
|
448
475
|
},
|
|
449
476
|
"base": {
|
|
450
477
|
chainId: 8453,
|
|
@@ -462,16 +489,43 @@ exports.Networks = {
|
|
|
462
489
|
Community: "0x721c17b065dccc5c916e0c2708d0ef50f1810591b76d0402ff6fe5accbd8488f",
|
|
463
490
|
Details: "0x70a3f615f738fc6a4f56100692ada93d947c028b840940d97af7e7d6f0fa0577",
|
|
464
491
|
Grant: "0x12837231f48acbca4e1e7f4416f684f3353bd4d71d4f03a09d29e5ffa6f21a50",
|
|
465
|
-
GrantVerified: "
|
|
492
|
+
GrantVerified: "0x535417d864b95c33fc0289082617b4004737a12c276ee27effd9f54491942934",
|
|
466
493
|
MemberOf: "0x7fbb8a65924d8ad2ae12356e04b1418043e8361ba3b1b6c917de2e23df3ec81c",
|
|
467
|
-
MilestoneApproved: "
|
|
468
|
-
MilestoneCompleted: "
|
|
469
|
-
GrantUpdateStatus: "
|
|
494
|
+
MilestoneApproved: "0x535417d864b95c33fc0289082617b4004737a12c276ee27effd9f54491942934",
|
|
495
|
+
MilestoneCompleted: "0x535417d864b95c33fc0289082617b4004737a12c276ee27effd9f54491942934",
|
|
496
|
+
GrantUpdateStatus: "0x535417d864b95c33fc0289082617b4004737a12c276ee27effd9f54491942934",
|
|
470
497
|
Project: "0x5a6b36ac106c74541efad39f8430751dd843bb78729bf7ffc296eca4cbb8d8f3",
|
|
471
|
-
ProjectUpdateStatus: "
|
|
472
|
-
ProjectMilestoneStatus: "
|
|
498
|
+
ProjectUpdateStatus: "0x535417d864b95c33fc0289082617b4004737a12c276ee27effd9f54491942934",
|
|
499
|
+
ProjectMilestoneStatus: "0x535417d864b95c33fc0289082617b4004737a12c276ee27effd9f54491942934",
|
|
473
500
|
ContributorProfile: "0xdfb8ad353dd144235bd45ae38803db6ffe066081770370f603709b9dec9ba8ff"
|
|
474
501
|
},
|
|
502
|
+
oldSchemas: [
|
|
503
|
+
{
|
|
504
|
+
name: "GrantVerified",
|
|
505
|
+
uid: "0xb7eab95609c821624edc3c3a5a6c787bdc9da6c91393a967fb22b0e274c619dd",
|
|
506
|
+
raw: oldStatusSchema
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
name: "MilestoneApproved",
|
|
510
|
+
uid: "0xb7eab95609c821624edc3c3a5a6c787bdc9da6c91393a967fb22b0e274c619dd",
|
|
511
|
+
raw: oldStatusSchema
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
name: "MilestoneCompleted",
|
|
515
|
+
uid: "0xb7eab95609c821624edc3c3a5a6c787bdc9da6c91393a967fb22b0e274c619dd",
|
|
516
|
+
raw: oldStatusSchema
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
name: "GrantUpdateStatus",
|
|
520
|
+
uid: "0xb7eab95609c821624edc3c3a5a6c787bdc9da6c91393a967fb22b0e274c619dd",
|
|
521
|
+
raw: oldStatusSchema
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
name: "ProjectUpdateStatus",
|
|
525
|
+
uid: "0xb7eab95609c821624edc3c3a5a6c787bdc9da6c91393a967fb22b0e274c619dd",
|
|
526
|
+
raw: oldStatusSchema
|
|
527
|
+
},
|
|
528
|
+
]
|
|
475
529
|
},
|
|
476
530
|
"polygon": {
|
|
477
531
|
chainId: 137,
|
|
@@ -489,16 +543,43 @@ exports.Networks = {
|
|
|
489
543
|
Community: "0x884bd33b1d7fce5c637e85aef538e83a8a87157d7df2d357e6cc8d4c59b89400",
|
|
490
544
|
Details: "0x2038ec9d8d0ab60324065aa0b4961d3f93d725f1c71f67b9f1ef209114c75f7f",
|
|
491
545
|
Grant: "0x2cedad5cda259c921f3380eedd5920be86a7dfe9496848cc8afc7f01159dfd65",
|
|
492
|
-
GrantVerified: "
|
|
546
|
+
GrantVerified: "0xefa705f5baaf91745bb4706fa4aa55156c5d9c3cd6834fcc4912bcb51ad5bea3",
|
|
493
547
|
MemberOf: "0x2cfa4adacb1efcd0ff408d749fd12bb36cd5f88aa0822f633962d4bd5c8023aa",
|
|
494
|
-
MilestoneApproved: "
|
|
495
|
-
MilestoneCompleted: "
|
|
496
|
-
GrantUpdateStatus: "
|
|
548
|
+
MilestoneApproved: "0xefa705f5baaf91745bb4706fa4aa55156c5d9c3cd6834fcc4912bcb51ad5bea3",
|
|
549
|
+
MilestoneCompleted: "0xefa705f5baaf91745bb4706fa4aa55156c5d9c3cd6834fcc4912bcb51ad5bea3",
|
|
550
|
+
GrantUpdateStatus: "0xefa705f5baaf91745bb4706fa4aa55156c5d9c3cd6834fcc4912bcb51ad5bea3",
|
|
497
551
|
Project: "0x7f0e4ac5f7cbe2a39af317b46bad7e86b053f76109c364d197447d9da34e821a",
|
|
498
|
-
ProjectUpdateStatus: "
|
|
499
|
-
ProjectMilestoneStatus: "
|
|
552
|
+
ProjectUpdateStatus: "0xefa705f5baaf91745bb4706fa4aa55156c5d9c3cd6834fcc4912bcb51ad5bea3",
|
|
553
|
+
ProjectMilestoneStatus: "0xefa705f5baaf91745bb4706fa4aa55156c5d9c3cd6834fcc4912bcb51ad5bea3",
|
|
500
554
|
ContributorProfile: "0x281f0afbb0313c6ff851400c4ed317fe9741be75e7e20c337dfd403059523bea"
|
|
501
555
|
},
|
|
556
|
+
oldSchemas: [
|
|
557
|
+
{
|
|
558
|
+
name: "GrantVerified",
|
|
559
|
+
uid: "0xe4b229d7051c27bb64cca0d29d92377143e6d5b9e076416e997c38d4cb40a399",
|
|
560
|
+
raw: oldStatusSchema
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
name: "MilestoneApproved",
|
|
564
|
+
uid: "0xe4b229d7051c27bb64cca0d29d92377143e6d5b9e076416e997c38d4cb40a399",
|
|
565
|
+
raw: oldStatusSchema
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
name: "MilestoneCompleted",
|
|
569
|
+
uid: "0xe4b229d7051c27bb64cca0d29d92377143e6d5b9e076416e997c38d4cb40a399",
|
|
570
|
+
raw: oldStatusSchema
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
name: "GrantUpdateStatus",
|
|
574
|
+
uid: "0xe4b229d7051c27bb64cca0d29d92377143e6d5b9e076416e997c38d4cb40a399",
|
|
575
|
+
raw: oldStatusSchema
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
name: "ProjectUpdateStatus",
|
|
579
|
+
uid: "0xe4b229d7051c27bb64cca0d29d92377143e6d5b9e076416e997c38d4cb40a399",
|
|
580
|
+
raw: oldStatusSchema
|
|
581
|
+
},
|
|
582
|
+
]
|
|
502
583
|
},
|
|
503
584
|
};
|
|
504
585
|
const DetailsSchema = [{ type: "string", name: "json", value: null }];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getIPFSData<T>(cid: string): Promise<T>;
|
|
@@ -0,0 +1,19 @@
|
|
|
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.getIPFSData = getIPFSData;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
async function getIPFSData(cid) {
|
|
9
|
+
try {
|
|
10
|
+
const { data } = await axios_1.default.get(`https://ipfs.io/ipfs/${cid}`, {
|
|
11
|
+
timeout: 5000,
|
|
12
|
+
});
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.error(err);
|
|
17
|
+
throw new Error(`Error to retrive data for CID: ${cid}`);
|
|
18
|
+
}
|
|
19
|
+
}
|