@human-protocol/sdk 3.0.0 → 3.0.2

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 (64) hide show
  1. package/README.md +23 -80
  2. package/dist/constants.d.ts +1 -0
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +1 -0
  5. package/dist/enums.d.ts +4 -0
  6. package/dist/enums.d.ts.map +1 -1
  7. package/dist/enums.js +6 -1
  8. package/dist/error.d.ts +7 -0
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +8 -1
  11. package/dist/escrow.d.ts +90 -11
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +153 -43
  14. package/dist/graphql/queries/escrow.d.ts +1 -0
  15. package/dist/graphql/queries/escrow.d.ts.map +1 -1
  16. package/dist/graphql/queries/escrow.js +50 -12
  17. package/dist/graphql/queries/hmtoken.d.ts +1 -1
  18. package/dist/graphql/queries/hmtoken.d.ts.map +1 -1
  19. package/dist/graphql/queries/hmtoken.js +23 -7
  20. package/dist/graphql/queries/kvstore.d.ts +1 -0
  21. package/dist/graphql/queries/kvstore.d.ts.map +1 -1
  22. package/dist/graphql/queries/kvstore.js +12 -1
  23. package/dist/graphql/queries/operator.js +1 -1
  24. package/dist/graphql/queries/statistics.d.ts +2 -2
  25. package/dist/graphql/queries/statistics.d.ts.map +1 -1
  26. package/dist/graphql/queries/statistics.js +13 -7
  27. package/dist/graphql/queries/transaction.d.ts.map +1 -1
  28. package/dist/graphql/queries/transaction.js +12 -7
  29. package/dist/graphql/types.d.ts +11 -5
  30. package/dist/graphql/types.d.ts.map +1 -1
  31. package/dist/index.d.ts +3 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -1
  34. package/dist/interfaces.d.ts +16 -9
  35. package/dist/interfaces.d.ts.map +1 -1
  36. package/dist/kvstore.d.ts +69 -106
  37. package/dist/kvstore.d.ts.map +1 -1
  38. package/dist/kvstore.js +123 -159
  39. package/dist/operator.d.ts.map +1 -1
  40. package/dist/operator.js +64 -81
  41. package/dist/statistics.d.ts +91 -59
  42. package/dist/statistics.d.ts.map +1 -1
  43. package/dist/statistics.js +162 -85
  44. package/dist/transaction.d.ts +10 -4
  45. package/dist/transaction.d.ts.map +1 -1
  46. package/dist/transaction.js +36 -27
  47. package/package.json +5 -4
  48. package/src/constants.ts +1 -0
  49. package/src/enums.ts +5 -0
  50. package/src/error.ts +8 -0
  51. package/src/escrow.ts +197 -54
  52. package/src/graphql/queries/escrow.ts +53 -11
  53. package/src/graphql/queries/hmtoken.ts +23 -7
  54. package/src/graphql/queries/kvstore.ts +11 -0
  55. package/src/graphql/queries/operator.ts +1 -1
  56. package/src/graphql/queries/statistics.ts +15 -9
  57. package/src/graphql/queries/transaction.ts +12 -7
  58. package/src/graphql/types.ts +13 -5
  59. package/src/index.ts +4 -1
  60. package/src/interfaces.ts +18 -9
  61. package/src/kvstore.ts +145 -158
  62. package/src/operator.ts +79 -91
  63. package/src/statistics.ts +186 -96
  64. package/src/transaction.ts +40 -30
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { StakingClient } from './staking';
2
2
  import { StorageClient } from './storage';
3
- import { KVStoreClient } from './kvstore';
3
+ import { KVStoreClient, KVStoreUtils } from './kvstore';
4
4
  import { EscrowClient, EscrowUtils } from './escrow';
5
5
  import { StatisticsClient } from './statistics';
6
6
  import { Encryption, EncryptionUtils } from './encryption';
7
7
  import { OperatorUtils } from './operator';
8
+ import { TransactionUtils } from './transaction';
8
9
  export * from './constants';
9
10
  export * from './types';
10
11
  export * from './enums';
11
12
  export * from './interfaces';
12
- export { StakingClient, StorageClient, KVStoreClient, EscrowClient, EscrowUtils, StatisticsClient, Encryption, EncryptionUtils, OperatorUtils, };
13
+ export { StakingClient, StorageClient, KVStoreClient, KVStoreUtils, EscrowClient, EscrowUtils, StatisticsClient, Encryption, EncryptionUtils, OperatorUtils, TransactionUtils, };
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAE7B,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,aAAa,GACd,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAE7B,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,aAAa,EACb,gBAAgB,GACjB,CAAC"}
package/dist/index.js CHANGED
@@ -14,13 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.OperatorUtils = exports.EncryptionUtils = exports.Encryption = exports.StatisticsClient = exports.EscrowUtils = exports.EscrowClient = exports.KVStoreClient = exports.StorageClient = exports.StakingClient = void 0;
17
+ exports.TransactionUtils = exports.OperatorUtils = exports.EncryptionUtils = exports.Encryption = exports.StatisticsClient = exports.EscrowUtils = exports.EscrowClient = exports.KVStoreUtils = exports.KVStoreClient = exports.StorageClient = exports.StakingClient = void 0;
18
18
  const staking_1 = require("./staking");
19
19
  Object.defineProperty(exports, "StakingClient", { enumerable: true, get: function () { return staking_1.StakingClient; } });
20
20
  const storage_1 = require("./storage");
21
21
  Object.defineProperty(exports, "StorageClient", { enumerable: true, get: function () { return storage_1.StorageClient; } });
22
22
  const kvstore_1 = require("./kvstore");
23
23
  Object.defineProperty(exports, "KVStoreClient", { enumerable: true, get: function () { return kvstore_1.KVStoreClient; } });
24
+ Object.defineProperty(exports, "KVStoreUtils", { enumerable: true, get: function () { return kvstore_1.KVStoreUtils; } });
24
25
  const escrow_1 = require("./escrow");
25
26
  Object.defineProperty(exports, "EscrowClient", { enumerable: true, get: function () { return escrow_1.EscrowClient; } });
26
27
  Object.defineProperty(exports, "EscrowUtils", { enumerable: true, get: function () { return escrow_1.EscrowUtils; } });
@@ -31,6 +32,8 @@ Object.defineProperty(exports, "Encryption", { enumerable: true, get: function (
31
32
  Object.defineProperty(exports, "EncryptionUtils", { enumerable: true, get: function () { return encryption_1.EncryptionUtils; } });
32
33
  const operator_1 = require("./operator");
33
34
  Object.defineProperty(exports, "OperatorUtils", { enumerable: true, get: function () { return operator_1.OperatorUtils; } });
35
+ const transaction_1 = require("./transaction");
36
+ Object.defineProperty(exports, "TransactionUtils", { enumerable: true, get: function () { return transaction_1.TransactionUtils; } });
34
37
  __exportStar(require("./constants"), exports);
35
38
  __exportStar(require("./types"), exports);
36
39
  __exportStar(require("./enums"), exports);
@@ -1,5 +1,5 @@
1
1
  import { EscrowStatus } from './types';
2
- import { ChainId } from './enums';
2
+ import { ChainId, OrderDirection } from './enums';
3
3
  export interface IAllocation {
4
4
  escrowAddress: string;
5
5
  staker: string;
@@ -23,7 +23,7 @@ export interface ILeader {
23
23
  amountSlashed: bigint;
24
24
  reputation: bigint;
25
25
  reward: bigint;
26
- amountJobsLaunched: bigint;
26
+ amountJobsProcessed: bigint;
27
27
  role?: string;
28
28
  fee?: bigint;
29
29
  publicKey?: string;
@@ -55,7 +55,7 @@ export interface IOperator {
55
55
  export interface IOperatorSubgraph extends Omit<IOperator, 'jobTypes'> {
56
56
  jobTypes?: string;
57
57
  }
58
- export interface IEscrowsFilter {
58
+ export interface IEscrowsFilter extends IPagination {
59
59
  launcher?: string;
60
60
  reputationOracle?: string;
61
61
  recordingOracle?: string;
@@ -64,7 +64,7 @@ export interface IEscrowsFilter {
64
64
  status?: EscrowStatus;
65
65
  from?: Date;
66
66
  to?: Date;
67
- networks: ChainId[];
67
+ chainId: ChainId;
68
68
  }
69
69
  export interface IEscrowConfig {
70
70
  recordingOracle: string;
@@ -82,10 +82,12 @@ export interface IKeyPair {
82
82
  passphrase: string;
83
83
  revocationCertificate?: string;
84
84
  }
85
- export interface IStatisticsParams {
85
+ export interface IStatisticsFilter extends IPagination {
86
86
  from?: Date;
87
87
  to?: Date;
88
- limit?: number;
88
+ }
89
+ export interface IHMTHoldersParams extends IPagination {
90
+ address?: string;
89
91
  }
90
92
  export interface IPayoutFilter {
91
93
  escrowAddress?: string;
@@ -99,15 +101,15 @@ export interface IKVStore {
99
101
  }
100
102
  export interface ITransaction {
101
103
  block: bigint;
102
- hash: string;
104
+ txHash: string;
103
105
  from: string;
104
106
  to: string;
105
107
  timestamp: bigint;
106
108
  value: string;
107
109
  method: string;
108
110
  }
109
- export interface ITransactionsFilter {
110
- networks: ChainId[];
111
+ export interface ITransactionsFilter extends IPagination {
112
+ chainId: ChainId;
111
113
  startBlock?: number;
112
114
  endBlock?: number;
113
115
  startDate?: Date;
@@ -115,4 +117,9 @@ export interface ITransactionsFilter {
115
117
  fromAddress?: string;
116
118
  toAddress?: string;
117
119
  }
120
+ export interface IPagination {
121
+ first?: number;
122
+ skip?: number;
123
+ orderDirection?: OrderDirection;
124
+ }
118
125
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MA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EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC"}
package/dist/kvstore.d.ts CHANGED
@@ -176,80 +176,6 @@ export declare class KVStoreClient extends BaseEthersClient {
176
176
  * ```
177
177
  */
178
178
  setFileUrlAndHash(url: string, urlKey?: string, txOptions?: Overrides): Promise<void>;
179
- /**
180
- * Gets the value of a key-value pair in the contract.
181
- *
182
- * @param {string} address Address from which to get the key value.
183
- * @param {string} key Key to obtain the value.
184
- * @returns {string} Value of the key.
185
- *
186
- *
187
- * **Code example**
188
- *
189
- * > Need to have available stake.
190
- *
191
- * ```ts
192
- * import { providers } from 'ethers';
193
- * import { KVStoreClient } from '@human-protocol/sdk';
194
- *
195
- * const rpcUrl = 'YOUR_RPC_URL';
196
- *
197
- * const provider = new providers.JsonRpcProvider(rpcUrl);
198
- * const kvstoreClient = await KVStoreClient.build(provider);
199
- *
200
- * const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
201
- * ```
202
- */
203
- get(address: string, key: string): Promise<string>;
204
- /**
205
- * Gets the URL value of the given entity, and verify its hash.
206
- *
207
- * @param {string} address Address from which to get the URL value.
208
- * @param {string} urlKey Configurable URL key. `url` by default.
209
- * @returns {string} URL value for the given address if exists, and the content is valid
210
- *
211
- *
212
- * **Code example**
213
- *
214
- * ```ts
215
- * import { providers } from 'ethers';
216
- * import { KVStoreClient } from '@human-protocol/sdk';
217
- *
218
- * const rpcUrl = 'YOUR_RPC_URL';
219
- *
220
- * const provider = new providers.JsonRpcProvider(rpcUrl);
221
- * const kvstoreClient = await KVStoreClient.build(provider);
222
- *
223
- * const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
224
- * const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
225
- * '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
226
- * 'linkedin_url'
227
- * );
228
- * ```
229
- */
230
- getFileUrlAndVerifyHash(address: string, urlKey?: string): Promise<string>;
231
- /**
232
- * Gets the public key of the given entity, and verify its hash.
233
- *
234
- * @param {string} address Address from which to get the public key.
235
- * @returns {string} Public key for the given address if exists, and the content is valid
236
- *
237
- *
238
- * **Code example**
239
- *
240
- * ```ts
241
- * import { providers } from 'ethers';
242
- * import { KVStoreClient } from '@human-protocol/sdk';
243
- *
244
- * const rpcUrl = 'YOUR_RPC_URL';
245
- *
246
- * const provider = new providers.JsonRpcProvider(rpcUrl);
247
- * const kvstoreClient = await KVStoreClient.build(provider);
248
- *
249
- * const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
250
- * ```
251
- */
252
- getPublicKey(address: string): Promise<string>;
253
179
  }
254
180
  /**
255
181
  * ## Introduction
@@ -277,60 +203,97 @@ export declare class KVStoreClient extends BaseEthersClient {
277
203
  * ```ts
278
204
  * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
279
205
  *
280
- * const KVStoreAddresses = new KVStoreUtils.getData({
281
- * networks: [ChainId.POLYGON_AMOY]
282
- * });
206
+ * const KVStoreAddresses = new KVStoreUtils.getKVStoreData({
207
+ * ChainId.POLYGON_AMOY,
208
+ * "0x1234567890123456789012345678901234567890",
209
+ * );
283
210
  * ```
284
211
  */
285
212
  export declare class KVStoreUtils {
286
213
  /**
287
214
  * This function returns the KVStore data for a given address.
288
215
  *
289
- * > This uses Subgraph
216
+ * @param {ChainId} chainId Network in which the KVStore is deployed
217
+ * @param {string} address Address of the KVStore
218
+ * @returns {Promise<IKVStore[]>} KVStore data
219
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
220
+ * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
290
221
  *
291
- * **Input parameters**
222
+ * **Code example**
292
223
  *
293
224
  * ```ts
294
- * enum ChainId {
295
- * ALL = -1,
296
- * MAINNET = 1,
297
- * RINKEBY = 4,
298
- * GOERLI = 5,
299
- * BSC_MAINNET = 56,
300
- * BSC_TESTNET = 97,
301
- * POLYGON = 137,
302
- * POLYGON_MUMBAI = 80001,
303
- * POLYGON_AMOY = 80002,
304
- * MOONBEAM = 1284,
305
- * MOONBASE_ALPHA = 1287,
306
- * AVALANCHE = 43114,
307
- * AVALANCHE_TESTNET = 43113,
308
- * CELO = 42220,
309
- * CELO_ALFAJORES = 44787,
310
- * LOCALHOST = 1338,
311
- * }
225
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
226
+ *
227
+ * const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
228
+ * console.log(kvStoreData);
312
229
  * ```
230
+ */
231
+ static getKVStoreData(chainId: ChainId, address: string): Promise<IKVStore[]>;
232
+ /**
233
+ * Gets the value of a key-value pair in the KVStore using the subgraph.
234
+ *
235
+ * @param {ChainId} chainId Network in which the KVStore is deployed
236
+ * @param {string} address Address from which to get the key value.
237
+ * @param {string} key Key to obtain the value.
238
+ * @returns {Promise<string>} Value of the key.
239
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
240
+ * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
241
+ * @throws {ErrorKVStoreEmptyKey} - Thrown if the key is empty
242
+ *
243
+ * **Code example**
313
244
  *
314
245
  * ```ts
315
- * interface IKVStore {
316
- * key: string;
317
- * value: string;
318
- * }
246
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
247
+ *
248
+ * const chainId = ChainId.POLYGON_AMOY;
249
+ * const address = '0x1234567890123456789012345678901234567890';
250
+ * const key = 'role';
251
+ *
252
+ * const value = await KVStoreUtils.get(chainId, address, key);
253
+ * console.log(value);
319
254
  * ```
255
+ */
256
+ static get(chainId: ChainId, address: string, key: string): Promise<string>;
257
+ /**
258
+ * Gets the URL value of the given entity, and verifies its hash.
320
259
  *
321
260
  * @param {ChainId} chainId Network in which the KVStore is deployed
322
- * @param {string} address Address of the KVStore
323
- * @returns {Promise<IKVStore[]>} KVStore data
261
+ * @param {string} address Address from which to get the URL value.
262
+ * @param {string} urlKey Configurable URL key. `url` by default.
263
+ * @returns {Promise<string>} URL value for the given address if it exists, and the content is valid
324
264
  *
325
265
  * **Code example**
326
266
  *
327
267
  * ```ts
328
268
  * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
329
269
  *
330
- * const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
331
- * console.log(kvStoreData);
270
+ * const chainId = ChainId.POLYGON_AMOY;
271
+ * const address = '0x1234567890123456789012345678901234567890';
272
+ *
273
+ * const url = await KVStoreUtils.getFileUrlAndVerifyHash(chainId, address);
274
+ * console.log(url);
332
275
  * ```
333
276
  */
334
- static getKVStoreData(chainId: ChainId, address: string): Promise<IKVStore[]>;
277
+ static getFileUrlAndVerifyHash(chainId: ChainId, address: string, urlKey?: string): Promise<string>;
278
+ /**
279
+ * Gets the public key of the given entity, and verifies its hash.
280
+ *
281
+ * @param {ChainId} chainId Network in which the KVStore is deployed
282
+ * @param {string} address Address from which to get the public key.
283
+ * @returns {Promise<string>} Public key for the given address if it exists, and the content is valid
284
+ *
285
+ * **Code example**
286
+ *
287
+ * ```ts
288
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
289
+ *
290
+ * const chainId = ChainId.POLYGON_AMOY;
291
+ * const address = '0x1234567890123456789012345678901234567890';
292
+ *
293
+ * const publicKey = await KVStoreUtils.getPublicKey(chainId, address);
294
+ * console.log(publicKey);
295
+ * ```
296
+ */
297
+ static getPublicKey(chainId: ChainId, address: string): Promise<string>;
335
298
  }
336
299
  //# sourceMappingURL=kvstore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAWlC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AAEH,qBAAa,aAAc,SAAQ,gBAAgB;IACjD,OAAO,CAAC,QAAQ,CAAU;IAE1B;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;IAS5D;;;;;;;;OAQG;WACiB,KAAK,CAAC,MAAM,EAAE,cAAc;IAiBhD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IAEU,GAAG,CACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAShB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IAEU,OAAO,CAClB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IAEU,iBAAiB,CAC5B,GAAG,EAAE,MAAM,EACX,MAAM,SAAQ,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CA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EAAE,cAAc;IAiBhD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IAEU,GAAG,CACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAShB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IAEU,OAAO,CAClB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IAEU,iBAAiB,CAC5B,GAAG,EAAE,MAAM,EACX,MAAM,SAAQ,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;CAuBjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,YAAY;IACvB;;;;;;;;;;;;;;;;;OAiBG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,QAAQ,EAAE,CAAC;IAyBtB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;WACiB,GAAG,CACrB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC;IAyBlB;;;;;;;;;;;;;;;;;;;OAmBG;WACiB,uBAAuB,CACzC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,SAAQ,GACb,OAAO,CAAC,MAAM,CAAC;IAkClB;;;;;;;;;;;;;;;;;;OAkBG;WACiB,YAAY,CAC9B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;CAenB"}
package/dist/kvstore.js CHANGED
@@ -244,130 +244,6 @@ class KVStoreClient extends base_1.BaseEthersClient {
244
244
  throw Error(`Failed to set URL and hash: ${e.message}`);
245
245
  }
246
246
  }
247
- /**
248
- * Gets the value of a key-value pair in the contract.
249
- *
250
- * @param {string} address Address from which to get the key value.
251
- * @param {string} key Key to obtain the value.
252
- * @returns {string} Value of the key.
253
- *
254
- *
255
- * **Code example**
256
- *
257
- * > Need to have available stake.
258
- *
259
- * ```ts
260
- * import { providers } from 'ethers';
261
- * import { KVStoreClient } from '@human-protocol/sdk';
262
- *
263
- * const rpcUrl = 'YOUR_RPC_URL';
264
- *
265
- * const provider = new providers.JsonRpcProvider(rpcUrl);
266
- * const kvstoreClient = await KVStoreClient.build(provider);
267
- *
268
- * const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
269
- * ```
270
- */
271
- async get(address, key) {
272
- if (key === '')
273
- throw error_1.ErrorKVStoreEmptyKey;
274
- if (!ethers_1.ethers.isAddress(address))
275
- throw error_1.ErrorInvalidAddress;
276
- try {
277
- const result = await this.contract?.get(address, key);
278
- return result;
279
- }
280
- catch (e) {
281
- if (e instanceof Error)
282
- throw Error(`Failed to get value: ${e.message}`);
283
- return e;
284
- }
285
- }
286
- /**
287
- * Gets the URL value of the given entity, and verify its hash.
288
- *
289
- * @param {string} address Address from which to get the URL value.
290
- * @param {string} urlKey Configurable URL key. `url` by default.
291
- * @returns {string} URL value for the given address if exists, and the content is valid
292
- *
293
- *
294
- * **Code example**
295
- *
296
- * ```ts
297
- * import { providers } from 'ethers';
298
- * import { KVStoreClient } from '@human-protocol/sdk';
299
- *
300
- * const rpcUrl = 'YOUR_RPC_URL';
301
- *
302
- * const provider = new providers.JsonRpcProvider(rpcUrl);
303
- * const kvstoreClient = await KVStoreClient.build(provider);
304
- *
305
- * const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
306
- * const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
307
- * '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
308
- * 'linkedin_url'
309
- * );
310
- * ```
311
- */
312
- async getFileUrlAndVerifyHash(address, urlKey = 'url') {
313
- if (!ethers_1.ethers.isAddress(address))
314
- throw error_1.ErrorInvalidAddress;
315
- const hashKey = urlKey + '_hash';
316
- let url = '', hash = '';
317
- try {
318
- url = await this.contract?.get(address, urlKey);
319
- }
320
- catch (e) {
321
- if (e instanceof Error)
322
- throw Error(`Failed to get URL: ${e.message}`);
323
- }
324
- // Return empty string
325
- if (!url?.length) {
326
- return '';
327
- }
328
- try {
329
- hash = await this.contract?.get(address, hashKey);
330
- }
331
- catch (e) {
332
- if (e instanceof Error)
333
- throw Error(`Failed to get Hash: ${e.message}`);
334
- }
335
- const content = await fetch(url).then((res) => res.text());
336
- const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
337
- if (hash !== contentHash) {
338
- throw error_1.ErrorInvalidHash;
339
- }
340
- return url;
341
- }
342
- /**
343
- * Gets the public key of the given entity, and verify its hash.
344
- *
345
- * @param {string} address Address from which to get the public key.
346
- * @returns {string} Public key for the given address if exists, and the content is valid
347
- *
348
- *
349
- * **Code example**
350
- *
351
- * ```ts
352
- * import { providers } from 'ethers';
353
- * import { KVStoreClient } from '@human-protocol/sdk';
354
- *
355
- * const rpcUrl = 'YOUR_RPC_URL';
356
- *
357
- * const provider = new providers.JsonRpcProvider(rpcUrl);
358
- * const kvstoreClient = await KVStoreClient.build(provider);
359
- *
360
- * const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
361
- * ```
362
- */
363
- async getPublicKey(address) {
364
- const publicKeyUrl = await this.getFileUrlAndVerifyHash(address, constants_1.KVStoreKeys.publicKey);
365
- if (publicKeyUrl === '') {
366
- return '';
367
- }
368
- const publicKey = await fetch(publicKeyUrl).then((res) => res.text());
369
- return publicKey;
370
- }
371
247
  }
372
248
  __decorate([
373
249
  decorators_1.requiresSigner,
@@ -414,50 +290,21 @@ exports.KVStoreClient = KVStoreClient;
414
290
  * ```ts
415
291
  * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
416
292
  *
417
- * const KVStoreAddresses = new KVStoreUtils.getData({
418
- * networks: [ChainId.POLYGON_AMOY]
419
- * });
293
+ * const KVStoreAddresses = new KVStoreUtils.getKVStoreData({
294
+ * ChainId.POLYGON_AMOY,
295
+ * "0x1234567890123456789012345678901234567890",
296
+ * );
420
297
  * ```
421
298
  */
422
299
  class KVStoreUtils {
423
300
  /**
424
301
  * This function returns the KVStore data for a given address.
425
302
  *
426
- * > This uses Subgraph
427
- *
428
- * **Input parameters**
429
- *
430
- * ```ts
431
- * enum ChainId {
432
- * ALL = -1,
433
- * MAINNET = 1,
434
- * RINKEBY = 4,
435
- * GOERLI = 5,
436
- * BSC_MAINNET = 56,
437
- * BSC_TESTNET = 97,
438
- * POLYGON = 137,
439
- * POLYGON_MUMBAI = 80001,
440
- * POLYGON_AMOY = 80002,
441
- * MOONBEAM = 1284,
442
- * MOONBASE_ALPHA = 1287,
443
- * AVALANCHE = 43114,
444
- * AVALANCHE_TESTNET = 43113,
445
- * CELO = 42220,
446
- * CELO_ALFAJORES = 44787,
447
- * LOCALHOST = 1338,
448
- * }
449
- * ```
450
- *
451
- * ```ts
452
- * interface IKVStore {
453
- * key: string;
454
- * value: string;
455
- * }
456
- * ```
457
- *
458
303
  * @param {ChainId} chainId Network in which the KVStore is deployed
459
304
  * @param {string} address Address of the KVStore
460
305
  * @returns {Promise<IKVStore[]>} KVStore data
306
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
307
+ * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
461
308
  *
462
309
  * **Code example**
463
310
  *
@@ -483,5 +330,122 @@ class KVStoreUtils {
483
330
  }));
484
331
  return kvStoreData || [];
485
332
  }
333
+ /**
334
+ * Gets the value of a key-value pair in the KVStore using the subgraph.
335
+ *
336
+ * @param {ChainId} chainId Network in which the KVStore is deployed
337
+ * @param {string} address Address from which to get the key value.
338
+ * @param {string} key Key to obtain the value.
339
+ * @returns {Promise<string>} Value of the key.
340
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
341
+ * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
342
+ * @throws {ErrorKVStoreEmptyKey} - Thrown if the key is empty
343
+ *
344
+ * **Code example**
345
+ *
346
+ * ```ts
347
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
348
+ *
349
+ * const chainId = ChainId.POLYGON_AMOY;
350
+ * const address = '0x1234567890123456789012345678901234567890';
351
+ * const key = 'role';
352
+ *
353
+ * const value = await KVStoreUtils.get(chainId, address, key);
354
+ * console.log(value);
355
+ * ```
356
+ */
357
+ static async get(chainId, address, key) {
358
+ if (key === '')
359
+ throw error_1.ErrorKVStoreEmptyKey;
360
+ if (!ethers_1.ethers.isAddress(address))
361
+ throw error_1.ErrorInvalidAddress;
362
+ const networkData = constants_1.NETWORKS[chainId];
363
+ if (!networkData) {
364
+ throw error_1.ErrorUnsupportedChainID;
365
+ }
366
+ const { kvstores } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, kvstore_1.GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY)(), { address: address.toLowerCase(), key });
367
+ if (!kvstores || kvstores.length === 0) {
368
+ throw new Error(`Key "${key}" not found for address ${address}`);
369
+ }
370
+ const value = kvstores[0].value;
371
+ return value;
372
+ }
373
+ /**
374
+ * Gets the URL value of the given entity, and verifies its hash.
375
+ *
376
+ * @param {ChainId} chainId Network in which the KVStore is deployed
377
+ * @param {string} address Address from which to get the URL value.
378
+ * @param {string} urlKey Configurable URL key. `url` by default.
379
+ * @returns {Promise<string>} URL value for the given address if it exists, and the content is valid
380
+ *
381
+ * **Code example**
382
+ *
383
+ * ```ts
384
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
385
+ *
386
+ * const chainId = ChainId.POLYGON_AMOY;
387
+ * const address = '0x1234567890123456789012345678901234567890';
388
+ *
389
+ * const url = await KVStoreUtils.getFileUrlAndVerifyHash(chainId, address);
390
+ * console.log(url);
391
+ * ```
392
+ */
393
+ static async getFileUrlAndVerifyHash(chainId, address, urlKey = 'url') {
394
+ if (!ethers_1.ethers.isAddress(address))
395
+ throw error_1.ErrorInvalidAddress;
396
+ const hashKey = urlKey + '_hash';
397
+ let url = '', hash = '';
398
+ try {
399
+ url = await this.get(chainId, address, urlKey);
400
+ }
401
+ catch (e) {
402
+ if (e instanceof Error)
403
+ throw Error(`Failed to get URL: ${e.message}`);
404
+ }
405
+ // Return empty string
406
+ if (!url?.length) {
407
+ return '';
408
+ }
409
+ try {
410
+ hash = await this.get(chainId, address, hashKey);
411
+ }
412
+ catch (e) {
413
+ if (e instanceof Error)
414
+ throw Error(`Failed to get Hash: ${e.message}`);
415
+ }
416
+ const content = await fetch(url).then((res) => res.text());
417
+ const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
418
+ if (hash !== contentHash) {
419
+ throw error_1.ErrorInvalidHash;
420
+ }
421
+ return url;
422
+ }
423
+ /**
424
+ * Gets the public key of the given entity, and verifies its hash.
425
+ *
426
+ * @param {ChainId} chainId Network in which the KVStore is deployed
427
+ * @param {string} address Address from which to get the public key.
428
+ * @returns {Promise<string>} Public key for the given address if it exists, and the content is valid
429
+ *
430
+ * **Code example**
431
+ *
432
+ * ```ts
433
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
434
+ *
435
+ * const chainId = ChainId.POLYGON_AMOY;
436
+ * const address = '0x1234567890123456789012345678901234567890';
437
+ *
438
+ * const publicKey = await KVStoreUtils.getPublicKey(chainId, address);
439
+ * console.log(publicKey);
440
+ * ```
441
+ */
442
+ static async getPublicKey(chainId, address) {
443
+ const publicKeyUrl = await this.getFileUrlAndVerifyHash(chainId, address, constants_1.KVStoreKeys.publicKey);
444
+ if (publicKeyUrl === '') {
445
+ return '';
446
+ }
447
+ const publicKey = await fetch(publicKeyUrl).then((res) => res.text());
448
+ return publicKey;
449
+ }
486
450
  }
487
451
  exports.KVStoreUtils = KVStoreUtils;