@show-karma/karma-gap-sdk 0.3.33 → 0.3.34

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.
@@ -1,12 +1,13 @@
1
1
  import { ethers } from "ethers";
2
- import pinataSDK from "@pinata/sdk";
3
2
  export declare class AlloBase {
4
3
  private signer;
5
4
  private contract;
6
- private static ipfsClient;
7
5
  private allo;
8
- constructor(signer: ethers.Signer, ipfsStorage: pinataSDK, chainId: number);
9
- saveAndGetCID(data: any): Promise<string>;
6
+ private pinataJWTToken;
7
+ constructor(signer: ethers.Signer, pinataJWTToken: string, chainId: number);
8
+ saveAndGetCID(data: any, pinataMetadata?: {
9
+ name: string;
10
+ }): Promise<any>;
10
11
  encodeStrategyInitData(applicationStart: number, applicationEnd: number, roundStart: number, roundEnd: number, payoutToken: string): Promise<string>;
11
12
  createGrant(args: any): Promise<{
12
13
  poolId: string;
@@ -9,20 +9,29 @@ const Allo_json_1 = __importDefault(require("../../abi/Allo.json"));
9
9
  const consts_1 = require("../../consts");
10
10
  const ethers_2 = require("ethers");
11
11
  const allo_v2_sdk_1 = require("@allo-team/allo-v2-sdk/");
12
+ const axios_1 = __importDefault(require("axios"));
12
13
  class AlloBase {
13
- constructor(signer, ipfsStorage, chainId) {
14
+ constructor(signer, pinataJWTToken, chainId) {
14
15
  this.signer = signer;
15
16
  this.contract = new ethers_1.ethers.Contract(consts_1.AlloContracts.alloProxy, Allo_json_1.default, signer);
16
17
  this.allo = new allo_v2_sdk_1.Allo({ chain: chainId });
17
- AlloBase.ipfsClient = ipfsStorage;
18
+ this.pinataJWTToken = pinataJWTToken;
18
19
  }
19
- async saveAndGetCID(data) {
20
+ async saveAndGetCID(data, pinataMetadata = { name: "via karma-gap-sdk" }) {
20
21
  try {
21
- const res = await AlloBase.ipfsClient.pinJSONToIPFS(data);
22
- return res.IpfsHash;
22
+ const res = await axios_1.default.post("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
23
+ pinataContent: data,
24
+ pinataMetadata: pinataMetadata,
25
+ }, {
26
+ headers: {
27
+ "Content-Type": "application/json",
28
+ Authorization: `Bearer ${this.pinataJWTToken}`,
29
+ },
30
+ });
31
+ return res.data.IpfsHash;
23
32
  }
24
33
  catch (error) {
25
- throw new Error(`Error adding data to IPFS: ${error}`);
34
+ console.log(error);
26
35
  }
27
36
  }
28
37
  async encodeStrategyInitData(applicationStart, applicationEnd, roundStart, roundEnd, payoutToken) {
@@ -1,11 +1,12 @@
1
1
  import { ethers } from "ethers";
2
2
  import { ProfileMetadata } from "../types/allo";
3
- import pinataSDK from "@pinata/sdk";
4
3
  export declare class AlloRegistry {
5
4
  private contract;
6
- private static ipfsClient;
7
- constructor(signer: ethers.Signer, ipfsStorage: pinataSDK);
8
- saveAndGetCID(data: any): Promise<string>;
5
+ private pinataJWTToken;
6
+ constructor(signer: ethers.Signer, pinataJWTToken: string);
7
+ saveAndGetCID(data: any, pinataMetadata?: {
8
+ name: string;
9
+ }): Promise<any>;
9
10
  createProgram(nonce: number, name: string, profileMetadata: ProfileMetadata, owner: string, members: string[]): Promise<{
10
11
  profileId: any;
11
12
  txHash: any;
@@ -7,18 +7,27 @@ exports.AlloRegistry = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const AlloRegistry_json_1 = __importDefault(require("../../abi/AlloRegistry.json"));
9
9
  const consts_1 = require("../../consts");
10
+ const axios_1 = __importDefault(require("axios"));
10
11
  class AlloRegistry {
11
- constructor(signer, ipfsStorage) {
12
+ constructor(signer, pinataJWTToken) {
12
13
  this.contract = new ethers_1.ethers.Contract(consts_1.AlloContracts.registry, AlloRegistry_json_1.default, signer);
13
- AlloRegistry.ipfsClient = ipfsStorage;
14
+ this.pinataJWTToken = pinataJWTToken;
14
15
  }
15
- async saveAndGetCID(data) {
16
+ async saveAndGetCID(data, pinataMetadata = { name: "via karma-gap-sdk" }) {
16
17
  try {
17
- const res = await AlloRegistry.ipfsClient.pinJSONToIPFS(data);
18
- return res.IpfsHash;
18
+ const res = await axios_1.default.post("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
19
+ pinataContent: data,
20
+ pinataMetadata: pinataMetadata,
21
+ }, {
22
+ headers: {
23
+ "Content-Type": "application/json",
24
+ Authorization: `Bearer ${this.pinataJWTToken}`,
25
+ },
26
+ });
27
+ return res.data.IpfsHash;
19
28
  }
20
29
  catch (error) {
21
- throw new Error(`Error adding data to IPFS: ${error}`);
30
+ console.log(error);
22
31
  }
23
32
  }
24
33
  async createProgram(nonce, name, profileMetadata, owner, members) {
@@ -1,10 +1,10 @@
1
- import pinataSDK from "@pinata/sdk";
2
1
  import { RemoteStorage } from "./RemoteStorage";
3
2
  import { TRemoteStorageOutput } from "core/types";
4
3
  export interface IpfsStorageOptions {
5
4
  token: string;
6
5
  }
7
- export declare class IpfsStorage extends RemoteStorage<pinataSDK> {
6
+ export declare class IpfsStorage extends RemoteStorage {
7
+ private pinataJWTToken;
8
8
  constructor(opts: IpfsStorageOptions,
9
9
  /**
10
10
  * If set, will send request to another server instead of
@@ -17,4 +17,7 @@ export declare class IpfsStorage extends RemoteStorage<pinataSDK> {
17
17
  get<T = unknown>(args: {
18
18
  cid: string;
19
19
  }): Promise<T>;
20
+ saveAndGetCID(data: any, pinataMetadata?: {
21
+ name: string;
22
+ }): Promise<any>;
20
23
  }
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.IpfsStorage = void 0;
7
- const sdk_1 = __importDefault(require("@pinata/sdk"));
8
7
  const RemoteStorage_1 = require("./RemoteStorage");
9
8
  const SchemaError_1 = require("../SchemaError");
10
9
  const utils_1 = require("../../utils");
10
+ const axios_1 = __importDefault(require("axios"));
11
11
  class IpfsStorage extends RemoteStorage_1.RemoteStorage {
12
12
  constructor(opts,
13
13
  /**
@@ -17,13 +17,13 @@ class IpfsStorage extends RemoteStorage_1.RemoteStorage {
17
17
  sponsor) {
18
18
  super(0 /* STORAGE_TYPE.IPFS */, sponsor);
19
19
  this.assert(opts);
20
- this.client = new sdk_1.default({ pinataJWTKey: opts.token });
20
+ this.pinataJWTToken = opts.token;
21
21
  }
22
22
  assert(opts) { }
23
23
  async save(data) {
24
24
  try {
25
- const res = await this.client.pinJSONToIPFS(data);
26
- return res.IpfsHash;
25
+ const cid = await this.saveAndGetCID(data);
26
+ return cid;
27
27
  }
28
28
  catch (error) {
29
29
  throw new SchemaError_1.RemoteStorageError("REMOTE_STORAGE_UPLOAD", `Error adding data to IPFS`);
@@ -35,5 +35,22 @@ class IpfsStorage extends RemoteStorage_1.RemoteStorage {
35
35
  async get(args) {
36
36
  return (0, utils_1.getIPFSData)(args.cid);
37
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
+ console.log(error);
53
+ }
54
+ }
38
55
  }
39
56
  exports.IpfsStorage = IpfsStorage;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.33",
6
+ "version": "0.3.34",
7
7
  "description": "Simple and easy interface between EAS and Karma GAP.",
8
8
  "main": "./index.js",
9
9
  "author": "KarmaHQ",
@@ -22,7 +22,6 @@
22
22
  "@allo-team/allo-v2-sdk": "^1.0.63",
23
23
  "@ethereum-attestation-service/eas-sdk": "1.4.2",
24
24
  "@gelatonetwork/relay-sdk": "^5.2.0",
25
- "@pinata/sdk": "^2.1.0",
26
25
  "@types/sha256": "^0.2.0",
27
26
  "axios": "^1.4.0",
28
27
  "ethers": "6.11.0",