@human-protocol/sdk 2.0.0 → 2.1.1

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/dist/constants.js CHANGED
@@ -235,7 +235,7 @@ exports.NETWORKS = {
235
235
  stakingAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
236
236
  rewardPoolAddress: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853',
237
237
  kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
238
- subgraphUrl: '',
238
+ subgraphUrl: 'http://localhost:8000/subgraphs/name/humanprotocol/localhost',
239
239
  oldSubgraphUrl: '',
240
240
  oldFactoryAddress: '',
241
241
  },
@@ -243,8 +243,8 @@ exports.NETWORKS = {
243
243
  exports.KVStoreKeys = {
244
244
  role: 'role',
245
245
  fee: 'fee',
246
- publicKey: 'publicKey',
247
- webhookUrl: 'webhookUrl',
246
+ publicKey: 'public_key',
247
+ webhookUrl: 'webhook_url',
248
248
  url: 'url',
249
249
  };
250
250
  exports.Role = {
package/dist/kvstore.d.ts CHANGED
@@ -141,14 +141,14 @@ export declare class KVStoreClient extends BaseEthersClient {
141
141
  * const signer = new Wallet(privateKey, provider);
142
142
  * const kvstoreClient = await KVStoreClient.build(signer);
143
143
  *
144
- * const keys = ['role', 'webhookUrl'];
144
+ * const keys = ['role', 'webhook_url'];
145
145
  * const values = ['RecordingOracle', 'http://localhost'];
146
146
  * await kvstoreClient.set(keys, values);
147
147
  * ```
148
148
  */
149
149
  setBulk(keys: string[], values: string[], txOptions?: Overrides): Promise<void>;
150
150
  /**
151
- * This function sets a URL value for the address that submits the transaction.
151
+ * Sets a URL value for the address that submits the transaction, and its hash.
152
152
  *
153
153
  * @param {string} url URL to set
154
154
  * @param {string | undefined} urlKey Configurable URL key. `url` by default.
@@ -169,13 +169,13 @@ export declare class KVStoreClient extends BaseEthersClient {
169
169
  * const signer = new Wallet(privateKey, provider);
170
170
  * const kvstoreClient = await KVStoreClient.build(signer);
171
171
  *
172
- * await kvstoreClient.setURL('example.com');
173
- * await kvstoreClient.setURL('linkedin.com/example', 'linkedinUrl);
172
+ * await kvstoreClient.setFileUrlAndHash('example.com');
173
+ * await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url);
174
174
  * ```
175
175
  */
176
- setURL(url: string, urlKey?: string, txOptions?: Overrides): Promise<void>;
176
+ setFileUrlAndHash(url: string, urlKey?: string, txOptions?: Overrides): Promise<void>;
177
177
  /**
178
- * This function returns the value for a specified key and address.
178
+ * Gets the value of a key-value pair in the contract.
179
179
  *
180
180
  * @param {string} address Address from which to get the key value.
181
181
  * @param {string} key Key to obtain the value.
@@ -200,7 +200,7 @@ export declare class KVStoreClient extends BaseEthersClient {
200
200
  */
201
201
  get(address: string, key: string): Promise<string>;
202
202
  /**
203
- * This function returns the URL value for the given entity.
203
+ * Gets the URL value of the given entity, and verify its hash.
204
204
  *
205
205
  * @param {string} address Address from which to get the URL value.
206
206
  * @param {string} urlKey Configurable URL key. `url` by default.
@@ -218,13 +218,35 @@ export declare class KVStoreClient extends BaseEthersClient {
218
218
  * const provider = new providers.JsonRpcProvider(rpcUrl);
219
219
  * const kvstoreClient = await KVStoreClient.build(provider);
220
220
  *
221
- * const url = await kvstoreClient.getURL('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
222
- * const linkedinUrl = await kvstoreClient.getURL(
221
+ * const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
222
+ * const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
223
223
  * '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
224
- * 'linkedinUrl'
224
+ * 'linkedin_url'
225
225
  * );
226
226
  * ```
227
227
  */
228
- getURL(address: string, urlKey?: string): Promise<string>;
228
+ getFileUrlAndVerifyHash(address: string, urlKey?: string): Promise<string>;
229
+ /**
230
+ * Gets the public key of the given entity, and verify its hash.
231
+ *
232
+ * @param {string} address Address from which to get the public key.
233
+ * @returns {string} Public key for the given address if exists, and the content is valid
234
+ *
235
+ *
236
+ * **Code example**
237
+ *
238
+ * ```ts
239
+ * import { providers } from 'ethers';
240
+ * import { KVStoreClient } from '@human-protocol/sdk';
241
+ *
242
+ * const rpcUrl = 'YOUR_RPC_URL';
243
+ *
244
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
245
+ * const kvstoreClient = await KVStoreClient.build(provider);
246
+ *
247
+ * const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
248
+ * ```
249
+ */
250
+ getPublicKey(address: string): Promise<string>;
229
251
  }
230
252
  //# 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;AAa1C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,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,MAAM,CACjB,GAAG,EAAE,MAAM,EACX,MAAM,SAAQ,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAwBhB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAa/D;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CAiCtE"}
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;AAa1C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,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,CAAC,IAAI,CAAC;IAwBhB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAa/D;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,uBAAuB,CAClC,OAAO,EAAE,MAAM,EACf,MAAM,SAAQ,GACb,OAAO,CAAC,MAAM,CAAC;IAkClB;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAc5D"}
package/dist/kvstore.js CHANGED
@@ -180,7 +180,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
180
180
  * const signer = new Wallet(privateKey, provider);
181
181
  * const kvstoreClient = await KVStoreClient.build(signer);
182
182
  *
183
- * const keys = ['role', 'webhookUrl'];
183
+ * const keys = ['role', 'webhook_url'];
184
184
  * const values = ['RecordingOracle', 'http://localhost'];
185
185
  * await kvstoreClient.set(keys, values);
186
186
  * ```
@@ -199,7 +199,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
199
199
  }
200
200
  }
201
201
  /**
202
- * This function sets a URL value for the address that submits the transaction.
202
+ * Sets a URL value for the address that submits the transaction, and its hash.
203
203
  *
204
204
  * @param {string} url URL to set
205
205
  * @param {string | undefined} urlKey Configurable URL key. `url` by default.
@@ -220,17 +220,17 @@ class KVStoreClient extends base_1.BaseEthersClient {
220
220
  * const signer = new Wallet(privateKey, provider);
221
221
  * const kvstoreClient = await KVStoreClient.build(signer);
222
222
  *
223
- * await kvstoreClient.setURL('example.com');
224
- * await kvstoreClient.setURL('linkedin.com/example', 'linkedinUrl);
223
+ * await kvstoreClient.setFileUrlAndHash('example.com');
224
+ * await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url);
225
225
  * ```
226
226
  */
227
- async setURL(url, urlKey = 'url', txOptions = {}) {
227
+ async setFileUrlAndHash(url, urlKey = 'url', txOptions = {}) {
228
228
  if (!(0, utils_1.isValidUrl)(url)) {
229
229
  throw error_1.ErrorInvalidUrl;
230
230
  }
231
231
  const content = await fetch(url).then((res) => res.text());
232
232
  const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
233
- const hashKey = urlKey + 'Hash';
233
+ const hashKey = urlKey + '_hash';
234
234
  try {
235
235
  await (await this.contract.setBulk([urlKey, hashKey], [url, contentHash], txOptions)).wait();
236
236
  }
@@ -240,7 +240,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
240
240
  }
241
241
  }
242
242
  /**
243
- * This function returns the value for a specified key and address.
243
+ * Gets the value of a key-value pair in the contract.
244
244
  *
245
245
  * @param {string} address Address from which to get the key value.
246
246
  * @param {string} key Key to obtain the value.
@@ -279,7 +279,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
279
279
  }
280
280
  }
281
281
  /**
282
- * This function returns the URL value for the given entity.
282
+ * Gets the URL value of the given entity, and verify its hash.
283
283
  *
284
284
  * @param {string} address Address from which to get the URL value.
285
285
  * @param {string} urlKey Configurable URL key. `url` by default.
@@ -297,17 +297,17 @@ class KVStoreClient extends base_1.BaseEthersClient {
297
297
  * const provider = new providers.JsonRpcProvider(rpcUrl);
298
298
  * const kvstoreClient = await KVStoreClient.build(provider);
299
299
  *
300
- * const url = await kvstoreClient.getURL('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
301
- * const linkedinUrl = await kvstoreClient.getURL(
300
+ * const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
301
+ * const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
302
302
  * '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
303
- * 'linkedinUrl'
303
+ * 'linkedin_url'
304
304
  * );
305
305
  * ```
306
306
  */
307
- async getURL(address, urlKey = 'url') {
307
+ async getFileUrlAndVerifyHash(address, urlKey = 'url') {
308
308
  if (!ethers_1.ethers.isAddress(address))
309
309
  throw error_1.ErrorInvalidAddress;
310
- const hashKey = urlKey + 'Hash';
310
+ const hashKey = urlKey + '_hash';
311
311
  let url = '', hash = '';
312
312
  try {
313
313
  url = await this.contract?.get(address, urlKey);
@@ -334,6 +334,35 @@ class KVStoreClient extends base_1.BaseEthersClient {
334
334
  }
335
335
  return url;
336
336
  }
337
+ /**
338
+ * Gets the public key of the given entity, and verify its hash.
339
+ *
340
+ * @param {string} address Address from which to get the public key.
341
+ * @returns {string} Public key for the given address if exists, and the content is valid
342
+ *
343
+ *
344
+ * **Code example**
345
+ *
346
+ * ```ts
347
+ * import { providers } from 'ethers';
348
+ * import { KVStoreClient } from '@human-protocol/sdk';
349
+ *
350
+ * const rpcUrl = 'YOUR_RPC_URL';
351
+ *
352
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
353
+ * const kvstoreClient = await KVStoreClient.build(provider);
354
+ *
355
+ * const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
356
+ * ```
357
+ */
358
+ async getPublicKey(address) {
359
+ const publicKeyUrl = await this.getFileUrlAndVerifyHash(address, constants_1.KVStoreKeys.publicKey);
360
+ if (publicKeyUrl === '') {
361
+ return '';
362
+ }
363
+ const publicKey = await fetch(publicKeyUrl).then((res) => res.text());
364
+ return publicKey;
365
+ }
337
366
  }
338
367
  __decorate([
339
368
  decorators_1.requiresSigner,
@@ -352,5 +381,5 @@ __decorate([
352
381
  __metadata("design:type", Function),
353
382
  __metadata("design:paramtypes", [String, Object, Object]),
354
383
  __metadata("design:returntype", Promise)
355
- ], KVStoreClient.prototype, "setURL", null);
384
+ ], KVStoreClient.prototype, "setFileUrlAndHash", null);
356
385
  exports.KVStoreClient = KVStoreClient;
package/dist/operator.js CHANGED
@@ -102,7 +102,7 @@ class OperatorUtils {
102
102
  }
103
103
  try {
104
104
  const { reputationNetwork } = await (0, graphql_request_1.default)(networkData.subgraphUrl, (0, operator_1.GET_REPUTATION_NETWORK_QUERY)(role), {
105
- address: address,
105
+ address: address.toLowerCase(),
106
106
  role: role,
107
107
  });
108
108
  return reputationNetwork.operators;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "2.0.0",
4
+ "version": "2.1.1",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -12,9 +12,9 @@
12
12
  "clean": "rm -rf ./dist",
13
13
  "clean:doc": "rm -rf ../../../../docs/sdk/typescript/",
14
14
  "prebuild": "yarn workspace @human-protocol/core build",
15
- "build": "npm run clean && tsc",
16
- "build:doc": "npm run clean:doc && npx typedoc --plugin typedoc-plugin-markdown --out ../../../../docs/sdk/typescript/",
17
- "prepublish": "npm run build",
15
+ "build": "yarn clean && tsc",
16
+ "build:doc": "yarn clean:doc && npx typedoc --plugin typedoc-plugin-markdown --out ../../../../docs/sdk/typescript/",
17
+ "prepublish": "yarn build",
18
18
  "test": "vitest -u",
19
19
  "lint": "eslint .",
20
20
  "lint:fix": "eslint . --fix",
@@ -42,7 +42,6 @@
42
42
  "@human-protocol/core": "*",
43
43
  "aws-sdk": "^2.1528.0",
44
44
  "axios": "^1.4.0",
45
- "crypto": "^1.0.1",
46
45
  "graphql": "^16.8.1",
47
46
  "graphql-request": "^6.1.0",
48
47
  "graphql-tag": "^2.12.6",
@@ -50,7 +49,7 @@
50
49
  "openpgp": "^5.10.2",
51
50
  "secp256k1": "^4.0.3",
52
51
  "vitest": "^0.30.1",
53
- "winston": "^3.8.2"
52
+ "winston": "^3.13.0"
54
53
  },
55
54
  "devDependencies": {
56
55
  "typedoc": "^0.25.1",
package/src/constants.ts CHANGED
@@ -260,7 +260,7 @@ export const NETWORKS: {
260
260
  stakingAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
261
261
  rewardPoolAddress: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853',
262
262
  kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
263
- subgraphUrl: '',
263
+ subgraphUrl: 'http://localhost:8000/subgraphs/name/humanprotocol/localhost',
264
264
  oldSubgraphUrl: '',
265
265
  oldFactoryAddress: '',
266
266
  },
@@ -269,8 +269,8 @@ export const NETWORKS: {
269
269
  export const KVStoreKeys = {
270
270
  role: 'role',
271
271
  fee: 'fee',
272
- publicKey: 'publicKey',
273
- webhookUrl: 'webhookUrl',
272
+ publicKey: 'public_key',
273
+ webhookUrl: 'webhook_url',
274
274
  url: 'url',
275
275
  };
276
276
 
package/src/kvstore.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from '@human-protocol/core/typechain-types';
5
5
  import { ContractRunner, Overrides, ethers } from 'ethers';
6
6
  import { BaseEthersClient } from './base';
7
- import { NETWORKS } from './constants';
7
+ import { KVStoreKeys, NETWORKS } from './constants';
8
8
  import { requiresSigner } from './decorators';
9
9
  import { ChainId } from './enums';
10
10
  import {
@@ -197,7 +197,7 @@ export class KVStoreClient extends BaseEthersClient {
197
197
  * const signer = new Wallet(privateKey, provider);
198
198
  * const kvstoreClient = await KVStoreClient.build(signer);
199
199
  *
200
- * const keys = ['role', 'webhookUrl'];
200
+ * const keys = ['role', 'webhook_url'];
201
201
  * const values = ['RecordingOracle', 'http://localhost'];
202
202
  * await kvstoreClient.set(keys, values);
203
203
  * ```
@@ -220,7 +220,7 @@ export class KVStoreClient extends BaseEthersClient {
220
220
  }
221
221
 
222
222
  /**
223
- * This function sets a URL value for the address that submits the transaction.
223
+ * Sets a URL value for the address that submits the transaction, and its hash.
224
224
  *
225
225
  * @param {string} url URL to set
226
226
  * @param {string | undefined} urlKey Configurable URL key. `url` by default.
@@ -241,12 +241,12 @@ export class KVStoreClient extends BaseEthersClient {
241
241
  * const signer = new Wallet(privateKey, provider);
242
242
  * const kvstoreClient = await KVStoreClient.build(signer);
243
243
  *
244
- * await kvstoreClient.setURL('example.com');
245
- * await kvstoreClient.setURL('linkedin.com/example', 'linkedinUrl);
244
+ * await kvstoreClient.setFileUrlAndHash('example.com');
245
+ * await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url);
246
246
  * ```
247
247
  */
248
248
  @requiresSigner
249
- public async setURL(
249
+ public async setFileUrlAndHash(
250
250
  url: string,
251
251
  urlKey = 'url',
252
252
  txOptions: Overrides = {}
@@ -258,7 +258,7 @@ export class KVStoreClient extends BaseEthersClient {
258
258
  const content = await fetch(url).then((res) => res.text());
259
259
  const contentHash = ethers.keccak256(ethers.toUtf8Bytes(content));
260
260
 
261
- const hashKey = urlKey + 'Hash';
261
+ const hashKey = urlKey + '_hash';
262
262
 
263
263
  try {
264
264
  await (
@@ -275,7 +275,7 @@ export class KVStoreClient extends BaseEthersClient {
275
275
  }
276
276
 
277
277
  /**
278
- * This function returns the value for a specified key and address.
278
+ * Gets the value of a key-value pair in the contract.
279
279
  *
280
280
  * @param {string} address Address from which to get the key value.
281
281
  * @param {string} key Key to obtain the value.
@@ -312,7 +312,7 @@ export class KVStoreClient extends BaseEthersClient {
312
312
  }
313
313
 
314
314
  /**
315
- * This function returns the URL value for the given entity.
315
+ * Gets the URL value of the given entity, and verify its hash.
316
316
  *
317
317
  * @param {string} address Address from which to get the URL value.
318
318
  * @param {string} urlKey Configurable URL key. `url` by default.
@@ -330,16 +330,19 @@ export class KVStoreClient extends BaseEthersClient {
330
330
  * const provider = new providers.JsonRpcProvider(rpcUrl);
331
331
  * const kvstoreClient = await KVStoreClient.build(provider);
332
332
  *
333
- * const url = await kvstoreClient.getURL('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
334
- * const linkedinUrl = await kvstoreClient.getURL(
333
+ * const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
334
+ * const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
335
335
  * '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
336
- * 'linkedinUrl'
336
+ * 'linkedin_url'
337
337
  * );
338
338
  * ```
339
339
  */
340
- public async getURL(address: string, urlKey = 'url'): Promise<string> {
340
+ public async getFileUrlAndVerifyHash(
341
+ address: string,
342
+ urlKey = 'url'
343
+ ): Promise<string> {
341
344
  if (!ethers.isAddress(address)) throw ErrorInvalidAddress;
342
- const hashKey = urlKey + 'Hash';
345
+ const hashKey = urlKey + '_hash';
343
346
 
344
347
  let url = '',
345
348
  hash = '';
@@ -370,4 +373,40 @@ export class KVStoreClient extends BaseEthersClient {
370
373
 
371
374
  return url;
372
375
  }
376
+
377
+ /**
378
+ * Gets the public key of the given entity, and verify its hash.
379
+ *
380
+ * @param {string} address Address from which to get the public key.
381
+ * @returns {string} Public key for the given address if exists, and the content is valid
382
+ *
383
+ *
384
+ * **Code example**
385
+ *
386
+ * ```ts
387
+ * import { providers } from 'ethers';
388
+ * import { KVStoreClient } from '@human-protocol/sdk';
389
+ *
390
+ * const rpcUrl = 'YOUR_RPC_URL';
391
+ *
392
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
393
+ * const kvstoreClient = await KVStoreClient.build(provider);
394
+ *
395
+ * const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
396
+ * ```
397
+ */
398
+ public async getPublicKey(address: string): Promise<string> {
399
+ const publicKeyUrl = await this.getFileUrlAndVerifyHash(
400
+ address,
401
+ KVStoreKeys.publicKey
402
+ );
403
+
404
+ if (publicKeyUrl === '') {
405
+ return '';
406
+ }
407
+
408
+ const publicKey = await fetch(publicKeyUrl).then((res) => res.text());
409
+
410
+ return publicKey;
411
+ }
373
412
  }
package/src/operator.ts CHANGED
@@ -134,7 +134,7 @@ export class OperatorUtils {
134
134
  const { reputationNetwork } = await gqlFetch<{
135
135
  reputationNetwork: IReputationNetwork;
136
136
  }>(networkData.subgraphUrl, GET_REPUTATION_NETWORK_QUERY(role), {
137
- address: address,
137
+ address: address.toLowerCase(),
138
138
  role: role,
139
139
  });
140
140