@human-protocol/sdk 6.1.0 → 7.1.0

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 (129) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/constants.js +26 -14
  4. package/dist/encryption/encryption.d.ts +84 -0
  5. package/dist/encryption/encryption.d.ts.map +1 -0
  6. package/dist/{encryption.js → encryption/encryption.js} +3 -161
  7. package/dist/encryption/encryption_utils.d.ts +101 -0
  8. package/dist/encryption/encryption_utils.d.ts.map +1 -0
  9. package/dist/encryption/encryption_utils.js +191 -0
  10. package/dist/encryption/index.d.ts +4 -0
  11. package/dist/encryption/index.d.ts.map +1 -0
  12. package/dist/encryption/index.js +7 -0
  13. package/dist/encryption/types.d.ts +9 -0
  14. package/dist/encryption/types.d.ts.map +1 -0
  15. package/dist/encryption/types.js +9 -0
  16. package/dist/error.d.ts +6 -10
  17. package/dist/error.d.ts.map +1 -1
  18. package/dist/error.js +12 -14
  19. package/dist/{escrow.d.ts → escrow/escrow_client.d.ts} +4 -184
  20. package/dist/{escrow.d.ts.map → escrow/escrow_client.d.ts.map} +1 -1
  21. package/dist/{escrow.js → escrow/escrow_client.js} +35 -411
  22. package/dist/escrow/escrow_utils.d.ts +172 -0
  23. package/dist/escrow/escrow_utils.d.ts.map +1 -0
  24. package/dist/escrow/escrow_utils.js +394 -0
  25. package/dist/escrow/index.d.ts +3 -0
  26. package/dist/escrow/index.d.ts.map +1 -0
  27. package/dist/escrow/index.js +7 -0
  28. package/dist/graphql/queries/escrow.d.ts +1 -1
  29. package/dist/graphql/queries/escrow.d.ts.map +1 -1
  30. package/dist/graphql/queries/escrow.js +5 -1
  31. package/dist/graphql/queries/statistics.d.ts +1 -0
  32. package/dist/graphql/queries/statistics.d.ts.map +1 -1
  33. package/dist/graphql/queries/statistics.js +36 -2
  34. package/dist/graphql/queries/worker.d.ts.map +1 -1
  35. package/dist/graphql/queries/worker.js +0 -2
  36. package/dist/graphql/types.d.ts +5 -2
  37. package/dist/graphql/types.d.ts.map +1 -1
  38. package/dist/index.d.ts +10 -10
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +23 -22
  41. package/dist/interfaces.d.ts +4 -7
  42. package/dist/interfaces.d.ts.map +1 -1
  43. package/dist/kvstore/index.d.ts +3 -0
  44. package/dist/kvstore/index.d.ts.map +1 -0
  45. package/dist/kvstore/index.js +7 -0
  46. package/dist/{kvstore.d.ts → kvstore/kvstore_client.d.ts} +3 -108
  47. package/dist/kvstore/kvstore_client.d.ts.map +1 -0
  48. package/dist/{kvstore.js → kvstore/kvstore_client.js} +22 -184
  49. package/dist/kvstore/kvstore_utils.d.ts +105 -0
  50. package/dist/kvstore/kvstore_utils.d.ts.map +1 -0
  51. package/dist/kvstore/kvstore_utils.js +184 -0
  52. package/dist/operator/index.d.ts +2 -0
  53. package/dist/operator/index.d.ts.map +1 -0
  54. package/dist/operator/index.js +5 -0
  55. package/dist/{operator.d.ts → operator/operator_utils.d.ts} +3 -3
  56. package/dist/operator/operator_utils.d.ts.map +1 -0
  57. package/dist/{operator.js → operator/operator_utils.js} +6 -6
  58. package/dist/staking/index.d.ts +3 -0
  59. package/dist/staking/index.d.ts.map +1 -0
  60. package/dist/staking/index.js +7 -0
  61. package/dist/{staking.d.ts → staking/staking_client.d.ts} +4 -65
  62. package/dist/staking/staking_client.d.ts.map +1 -0
  63. package/dist/{staking.js → staking/staking_client.js} +6 -136
  64. package/dist/staking/staking_utils.d.ts +63 -0
  65. package/dist/staking/staking_utils.d.ts.map +1 -0
  66. package/dist/staking/staking_utils.js +137 -0
  67. package/dist/statistics/index.d.ts +2 -0
  68. package/dist/statistics/index.d.ts.map +1 -0
  69. package/dist/statistics/index.js +5 -0
  70. package/dist/{statistics.d.ts → statistics/statistics_utils.d.ts} +4 -13
  71. package/dist/statistics/statistics_utils.d.ts.map +1 -0
  72. package/dist/{statistics.js → statistics/statistics_utils.js} +8 -22
  73. package/dist/transaction/index.d.ts +2 -0
  74. package/dist/transaction/index.d.ts.map +1 -0
  75. package/dist/transaction/index.js +5 -0
  76. package/dist/{transaction.d.ts → transaction/transaction_utils.d.ts} +3 -3
  77. package/dist/transaction/transaction_utils.d.ts.map +1 -0
  78. package/dist/{transaction.js → transaction/transaction_utils.js} +5 -5
  79. package/dist/types.d.ts +8 -0
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/utils.d.ts +15 -0
  82. package/dist/utils.d.ts.map +1 -1
  83. package/dist/utils.js +71 -4
  84. package/dist/worker/index.d.ts +2 -0
  85. package/dist/worker/index.d.ts.map +1 -0
  86. package/dist/worker/index.js +5 -0
  87. package/dist/{worker.d.ts → worker/worker_utils.d.ts} +3 -4
  88. package/dist/worker/worker_utils.d.ts.map +1 -0
  89. package/dist/{worker.js → worker/worker_utils.js} +5 -7
  90. package/package.json +12 -8
  91. package/src/constants.ts +38 -14
  92. package/src/{encryption.ts → encryption/encryption.ts} +1 -193
  93. package/src/encryption/encryption_utils.ts +179 -0
  94. package/src/encryption/index.ts +3 -0
  95. package/src/encryption/types.ts +15 -0
  96. package/src/error.ts +11 -17
  97. package/src/{escrow.ts → escrow/escrow_client.ts} +36 -556
  98. package/src/escrow/escrow_utils.ts +518 -0
  99. package/src/escrow/index.ts +2 -0
  100. package/src/graphql/queries/escrow.ts +6 -1
  101. package/src/graphql/queries/statistics.ts +37 -1
  102. package/src/graphql/queries/worker.ts +0 -2
  103. package/src/graphql/types.ts +6 -2
  104. package/src/index.ts +11 -25
  105. package/src/interfaces.ts +4 -7
  106. package/src/kvstore/index.ts +2 -0
  107. package/src/{kvstore.ts → kvstore/kvstore_client.ts} +27 -241
  108. package/src/kvstore/kvstore_utils.ts +244 -0
  109. package/src/operator/index.ts +1 -0
  110. package/src/{operator.ts → operator/operator_utils.ts} +8 -8
  111. package/src/staking/index.ts +2 -0
  112. package/src/{staking.ts → staking/staking_client.ts} +8 -174
  113. package/src/staking/staking_utils.ts +170 -0
  114. package/src/statistics/index.ts +1 -0
  115. package/src/{statistics.ts → statistics/statistics_utils.ts} +14 -26
  116. package/src/transaction/index.ts +1 -0
  117. package/src/{transaction.ts → transaction/transaction_utils.ts} +7 -7
  118. package/src/types.ts +8 -0
  119. package/src/utils.ts +80 -3
  120. package/src/worker/index.ts +1 -0
  121. package/src/{worker.ts → worker/worker_utils.ts} +7 -9
  122. package/dist/encryption.d.ts +0 -189
  123. package/dist/encryption.d.ts.map +0 -1
  124. package/dist/kvstore.d.ts.map +0 -1
  125. package/dist/operator.d.ts.map +0 -1
  126. package/dist/staking.d.ts.map +0 -1
  127. package/dist/statistics.d.ts.map +0 -1
  128. package/dist/transaction.d.ts.map +0 -1
  129. package/dist/worker.d.ts.map +0 -1
package/dist/utils.d.ts CHANGED
@@ -27,6 +27,13 @@ export declare const isValidUrl: (url: string) => boolean;
27
27
  * @returns True if the string is valid JSON, false otherwise
28
28
  */
29
29
  export declare const isValidJson: (input: string) => boolean;
30
+ /**
31
+ * Extracts a readable message from unknown error values.
32
+ *
33
+ * @param error - Unknown error value
34
+ * @returns Human-readable error message
35
+ */
36
+ export declare const getErrorMessage: (error: unknown) => string;
30
37
  /**
31
38
  * Gets the subgraph URL for the given network, using API key if available.
32
39
  *
@@ -34,6 +41,14 @@ export declare const isValidJson: (input: string) => boolean;
34
41
  * @returns The subgraph URL with API key if available
35
42
  */
36
43
  export declare const getSubgraphUrl: (networkData: NetworkData) => string;
44
+ /**
45
+ * Gets the HMT statistics subgraph URL for the given network.
46
+ * Falls back to the default subgraph URL when a dedicated HMT endpoint is not configured.
47
+ *
48
+ * @param networkData - The network data containing subgraph URLs
49
+ * @returns The HMT statistics subgraph URL with API key if available
50
+ */
51
+ export declare const getHMTSubgraphUrl: (networkData: NetworkData) => string;
37
52
  /**
38
53
  * Converts a Date object to Unix timestamp (seconds since epoch).
39
54
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAMxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,OAO3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,WAAW,WAUtD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAE7C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,OAS3C,CAAC;AAaF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,GAAG,GAAG,EAC1C,KAAK,MAAM,EACX,OAAO,GAAG,EACV,YAAY,GAAG,EACf,UAAU,eAAe,KACxB,OAAO,CAAC,CAAC,CA4CX,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAMxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,OAO3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,MAUhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,WAAW,WAUtD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,aAAa,WAAW,WAWzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAE7C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,OAS3C,CAAC;AA6CF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,GAAG,GAAG,EAC1C,KAAK,MAAM,EACX,OAAO,GAAG,EACV,YAAY,GAAG,EACf,UAAU,eAAe,KACxB,OAAO,CAAC,CAAC,CAiDX,CAAC"}
package/dist/utils.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.customGqlFetch = exports.isIndexerError = exports.getUnixTimestamp = exports.getSubgraphUrl = exports.isValidJson = exports.isValidUrl = exports.throwError = void 0;
6
+ exports.customGqlFetch = exports.isIndexerError = exports.getUnixTimestamp = exports.getHMTSubgraphUrl = exports.getSubgraphUrl = exports.getErrorMessage = exports.isValidJson = exports.isValidUrl = exports.throwError = void 0;
7
7
  /* eslint-disable @typescript-eslint/no-explicit-any */
8
8
  const ethers_1 = require("ethers");
9
9
  const graphql_request_1 = __importDefault(require("graphql-request"));
@@ -76,6 +76,24 @@ const isValidJson = (input) => {
76
76
  }
77
77
  };
78
78
  exports.isValidJson = isValidJson;
79
+ /**
80
+ * Extracts a readable message from unknown error values.
81
+ *
82
+ * @param error - Unknown error value
83
+ * @returns Human-readable error message
84
+ */
85
+ const getErrorMessage = (error) => {
86
+ if (error instanceof Error) {
87
+ return error.message;
88
+ }
89
+ try {
90
+ return JSON.stringify(error);
91
+ }
92
+ catch {
93
+ return String(error);
94
+ }
95
+ };
96
+ exports.getErrorMessage = getErrorMessage;
79
97
  /**
80
98
  * Gets the subgraph URL for the given network, using API key if available.
81
99
  *
@@ -94,6 +112,26 @@ const getSubgraphUrl = (networkData) => {
94
112
  return subgraphUrl;
95
113
  };
96
114
  exports.getSubgraphUrl = getSubgraphUrl;
115
+ /**
116
+ * Gets the HMT statistics subgraph URL for the given network.
117
+ * Falls back to the default subgraph URL when a dedicated HMT endpoint is not configured.
118
+ *
119
+ * @param networkData - The network data containing subgraph URLs
120
+ * @returns The HMT statistics subgraph URL with API key if available
121
+ */
122
+ const getHMTSubgraphUrl = (networkData) => {
123
+ let subgraphUrl = networkData.hmtSubgraphUrl || networkData.subgraphUrl;
124
+ if (process.env.SUBGRAPH_API_KEY) {
125
+ subgraphUrl =
126
+ networkData.hmtSubgraphUrlApiKey || networkData.subgraphUrlApiKey;
127
+ }
128
+ else if (networkData.chainId !== enums_1.ChainId.LOCALHOST) {
129
+ // eslint-disable-next-line no-console
130
+ console.warn(error_1.WarnSubgraphApiKeyNotProvided);
131
+ }
132
+ return subgraphUrl;
133
+ };
134
+ exports.getHMTSubgraphUrl = getHMTSubgraphUrl;
97
135
  /**
98
136
  * Converts a Date object to Unix timestamp (seconds since epoch).
99
137
  *
@@ -114,6 +152,29 @@ const isIndexerError = (error) => {
114
152
  return errorMessage.toLowerCase().includes('bad indexers');
115
153
  };
116
154
  exports.isIndexerError = isIndexerError;
155
+ const getSubgraphErrorMessage = (error) => {
156
+ return (error?.response?.errors?.[0]?.message ||
157
+ error?.message ||
158
+ error?.toString?.() ||
159
+ 'Subgraph request failed');
160
+ };
161
+ const getSubgraphStatusCode = (error) => {
162
+ if (typeof error?.response?.status === 'number') {
163
+ return error.response.status;
164
+ }
165
+ if (typeof error?.status === 'number') {
166
+ return error.status;
167
+ }
168
+ return undefined;
169
+ };
170
+ const toSubgraphError = (error, url) => {
171
+ const message = getSubgraphErrorMessage(error);
172
+ const statusCode = getSubgraphStatusCode(error);
173
+ if ((0, exports.isIndexerError)(error)) {
174
+ return new error_1.SubgraphBadIndexerError(message, url, statusCode);
175
+ }
176
+ return new error_1.SubgraphRequestError(message, url, statusCode);
177
+ };
117
178
  const sleep = (ms) => {
118
179
  return new Promise((resolve) => setTimeout(resolve, ms));
119
180
  };
@@ -143,7 +204,12 @@ const customGqlFetch = async (url, query, variables, options) => {
143
204
  }
144
205
  : undefined;
145
206
  if (!options) {
146
- return await (0, graphql_request_1.default)(url, query, variables, headers);
207
+ try {
208
+ return await (0, graphql_request_1.default)(url, query, variables, headers);
209
+ }
210
+ catch (error) {
211
+ throw toSubgraphError(error, url);
212
+ }
147
213
  }
148
214
  const hasMaxRetries = options.maxRetries !== undefined;
149
215
  const hasBaseDelay = options.baseDelay !== undefined;
@@ -162,9 +228,10 @@ const customGqlFetch = async (url, query, variables, options) => {
162
228
  return await (0, graphql_request_1.default)(targetUrl, query, variables, headers);
163
229
  }
164
230
  catch (error) {
165
- lastError = error;
231
+ const wrappedError = toSubgraphError(error, targetUrl);
232
+ lastError = wrappedError;
166
233
  if (attempt === maxRetries || !(0, exports.isIndexerError)(error)) {
167
- throw error;
234
+ throw wrappedError;
168
235
  }
169
236
  const delay = baseDelay * attempt;
170
237
  await sleep(delay);
@@ -0,0 +1,2 @@
1
+ export { WorkerUtils } from './worker_utils';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkerUtils = void 0;
4
+ var worker_utils_1 = require("./worker_utils");
5
+ Object.defineProperty(exports, "WorkerUtils", { enumerable: true, get: function () { return worker_utils_1.WorkerUtils; } });
@@ -1,5 +1,5 @@
1
- import { ChainId } from './enums';
2
- import { IWorker, IWorkersFilter, SubgraphOptions } from './interfaces';
1
+ import { ChainId } from '../enums';
2
+ import { IWorker, IWorkersFilter, SubgraphOptions } from '../interfaces';
3
3
  /**
4
4
  * Utility class for worker-related operations.
5
5
  *
@@ -57,7 +57,6 @@ export declare class WorkerUtils {
57
57
  * type IWorker = {
58
58
  * id: string;
59
59
  * address: string;
60
- * totalHMTAmountReceived: bigint;
61
60
  * payoutCount: number;
62
61
  * };
63
62
  * ```
@@ -83,4 +82,4 @@ export declare class WorkerUtils {
83
82
  */
84
83
  static getWorkers(filter: IWorkersFilter, options?: SubgraphOptions): Promise<IWorker[]>;
85
84
  }
86
- //# sourceMappingURL=worker.d.ts.map
85
+ //# sourceMappingURL=worker_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker_utils.d.ts","sourceRoot":"","sources":["../../src/worker/worker_utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,UAAU,CAAC;AAInD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGzE;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAW;IACtB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IA0B1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0CG;WACiB,UAAU,CAC5B,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,EAAE,CAAC;CAoCtB"}
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WorkerUtils = void 0;
4
4
  const ethers_1 = require("ethers");
5
- const constants_1 = require("./constants");
6
- const enums_1 = require("./enums");
7
- const error_1 = require("./error");
8
- const worker_1 = require("./graphql/queries/worker");
9
- const utils_1 = require("./utils");
5
+ const constants_1 = require("../constants");
6
+ const enums_1 = require("../enums");
7
+ const error_1 = require("../error");
8
+ const worker_1 = require("../graphql/queries/worker");
9
+ const utils_1 = require("../utils");
10
10
  /**
11
11
  * Utility class for worker-related operations.
12
12
  *
@@ -78,7 +78,6 @@ class WorkerUtils {
78
78
  * type IWorker = {
79
79
  * id: string;
80
80
  * address: string;
81
- * totalHMTAmountReceived: bigint;
82
81
  * payoutCount: number;
83
82
  * };
84
83
  * ```
@@ -132,7 +131,6 @@ function mapWorker(w) {
132
131
  return {
133
132
  id: w.id,
134
133
  address: w.address,
135
- totalHMTAmountReceived: BigInt(w.totalHMTAmountReceived || 0),
136
134
  payoutCount: Number(w.payoutCount || 0),
137
135
  };
138
136
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "6.1.0",
4
+ "version": "7.1.0",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -38,27 +38,31 @@
38
38
  ]
39
39
  },
40
40
  "dependencies": {
41
- "@human-protocol/core": "5.0.1",
41
+ "@human-protocol/core": "6.0.0",
42
42
  "axios": "^1.4.0",
43
- "ethers": "~6.15.0",
43
+ "ethers": "~6.16.0",
44
44
  "graphql": "^16.8.1",
45
45
  "graphql-request": "^7.3.4",
46
46
  "graphql-tag": "^2.12.6",
47
47
  "openpgp": "^6.2.2",
48
48
  "secp256k1": "^5.0.1",
49
49
  "validator": "^13.12.0",
50
- "vitest": "^3.0.9"
50
+ "vitest": "^4.0.18"
51
51
  },
52
52
  "devDependencies": {
53
+ "@eslint/js": "^10.0.1",
53
54
  "@types/validator": "^13.15.4",
54
- "eslint": "^9.39.1",
55
- "eslint-plugin-jest": "^28.9.0",
55
+ "eslint": "^10.0.3",
56
+ "eslint-config-prettier": "^10.1.8",
57
+ "eslint-plugin-jest": "^29.15.0",
56
58
  "eslint-plugin-prettier": "^5.5.5",
57
59
  "glob": "^13.0.0",
58
- "prettier": "^3.7.4",
60
+ "globals": "^16.3.0",
61
+ "prettier": "^3.8.1",
59
62
  "ts-node": "^10.9.2",
60
63
  "typedoc": "^0.28.15",
61
64
  "typedoc-plugin-markdown": "^4.9.0",
62
- "typescript": "^5.8.3"
65
+ "typescript": "^5.8.3",
66
+ "typescript-eslint": "^8.57.0"
63
67
  }
64
68
  }
package/src/constants.ts CHANGED
@@ -34,11 +34,15 @@ export const NETWORKS: {
34
34
  stakingAddress: '0xEf6Da3aB52c33925Be3F84038193a7e1331F51E6',
35
35
  kvstoreAddress: '0xB6d36B1CDaD50302BCB3DB43bAb0D349458e1b8D',
36
36
  subgraphUrl:
37
- 'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
37
+ 'https://api.studio.thegraph.com/query/74256/human-ethereum/version/latest',
38
38
  subgraphUrlApiKey:
39
- 'https://gateway.thegraph.com/api/deployments/id/QmNhLQEfBJQ46fngBh4YCttk8kNkveFy5uvAeUmyAdX1kD',
39
+ 'https://gateway.thegraph.com/api/deployments/id/QmQZ3yL1FzydDwaB56ozgTiBESciTNFsMLyTBfHXzNd1gg',
40
40
  oldSubgraphUrl: '',
41
41
  oldFactoryAddress: '',
42
+ hmtSubgraphUrl:
43
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-ethereum/version/latest',
44
+ hmtSubgraphUrlApiKey:
45
+ 'https://gateway.thegraph.com/api/deployments/id/QmdcTW7XhgULq5yJZGA65mjTwQogdyzLJaZ69ttDJz5JeE',
42
46
  },
43
47
  [ChainId.SEPOLIA]: {
44
48
  chainId: ChainId.SEPOLIA,
@@ -49,11 +53,15 @@ export const NETWORKS: {
49
53
  stakingAddress: '0x2163e3A40032Af1C359ac731deaB48258b317890',
50
54
  kvstoreAddress: '0xCc0AF0635aa19fE799B6aFDBe28fcFAeA7f00a60',
51
55
  subgraphUrl:
52
- 'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
56
+ 'https://api.studio.thegraph.com/query/74256/human-sepolia/version/latest',
53
57
  subgraphUrlApiKey:
54
- 'https://gateway.thegraph.com/api/deployments/id/QmQghdr7hxqrjFde8DN15TzfrJLCfwvzmUH9RzWwH1mKzk',
58
+ 'https://gateway.thegraph.com/api/deployments/id/QmQEbyGSf8VG9pdskowsK6C977wkcyJSxw9q6EDctKEkUw',
55
59
  oldSubgraphUrl: '',
56
60
  oldFactoryAddress: '',
61
+ hmtSubgraphUrl:
62
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-sepolia/version/latest',
63
+ hmtSubgraphUrlApiKey:
64
+ 'https://gateway.thegraph.com/api/deployments/id/QmYkPnYxbZ5ZTtKz7PTyxh6x5sK2H6yzx6vXDCrErpa9gB',
57
65
  },
58
66
  [ChainId.BSC_MAINNET]: {
59
67
  chainId: ChainId.BSC_MAINNET,
@@ -64,11 +72,15 @@ export const NETWORKS: {
64
72
  stakingAddress: '0xE24e5C08E28331D24758b69A5E9f383D2bDD1c98',
65
73
  kvstoreAddress: '0x21A0C4CED7aE447fCf87D9FE3A29FA9B3AB20Ff1',
66
74
  subgraphUrl:
67
- 'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
75
+ 'https://api.studio.thegraph.com/query/74256/human-bsc/version/latest',
68
76
  subgraphUrlApiKey:
69
- 'https://gateway.thegraph.com/api/deployments/id/QmTioC9Z1HzKSCnEKL3BP9iHqbgZt1ceLU2VE4Mv6sxNkd',
77
+ 'https://gateway.thegraph.com/api/deployments/id/QmV3nZUM51NGt7F8RpZP9GxKPpKox3F24iJ8H1ekPb6ha4',
70
78
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
71
79
  oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
80
+ hmtSubgraphUrl:
81
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-bsc/version/latest',
82
+ hmtSubgraphUrlApiKey:
83
+ 'https://gateway.thegraph.com/api/deployments/id/QmUnHgNShyv45S2dQ21W9jLvRA8xWT6XfeuP25fXJoNoEa',
72
84
  },
73
85
  [ChainId.BSC_TESTNET]: {
74
86
  chainId: ChainId.BSC_TESTNET,
@@ -79,12 +91,16 @@ export const NETWORKS: {
79
91
  stakingAddress: '0xD6D347ba6987519B4e42EcED43dF98eFf5465a23',
80
92
  kvstoreAddress: '0x32e27177BA6Ea91cf28dfd91a0Da9822A4b74EcF',
81
93
  subgraphUrl:
82
- 'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
94
+ 'https://api.studio.thegraph.com/query/74256/human-bsc-testnet/version/latest',
83
95
  subgraphUrlApiKey:
84
- 'https://gateway.thegraph.com/api/deployments/id/QmPyUYRjAvzDdeenXMGHcCRD2v4qwZbKMEkVkY3Jq6VLwn',
96
+ 'https://gateway.thegraph.com/api/deployments/id/QmdQJog9vMghK2o39U9YJL8vpU9VZnkJa7jGg7wnsod7qV',
85
97
  oldSubgraphUrl:
86
98
  'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
87
99
  oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
100
+ hmtSubgraphUrl:
101
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-bsc-testnet/version/latest',
102
+ hmtSubgraphUrlApiKey:
103
+ 'https://gateway.thegraph.com/api/deployments/id/QmPMRbrXKp7a1i5x27dzBHbomxqKYDg5eU3djv1DXB5heq',
88
104
  },
89
105
  [ChainId.POLYGON]: {
90
106
  chainId: ChainId.POLYGON,
@@ -95,12 +111,16 @@ export const NETWORKS: {
95
111
  stakingAddress: '0x01D115E9E8bF0C58318793624CC662a030D07F1D',
96
112
  kvstoreAddress: '0xbcB28672F826a50B03EE91B28145EAbddA73B2eD',
97
113
  subgraphUrl:
98
- 'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
114
+ 'https://api.studio.thegraph.com/query/74256/human-polygon/version/latest',
99
115
  subgraphUrlApiKey:
100
- 'https://gateway.thegraph.com/api/deployments/id/QmQNkWNE5FPtqbtSkdtR6AEBJz9N7WDz1X7pfvQqYAcUZJ',
116
+ 'https://gateway.thegraph.com/api/deployments/id/QmSu7B48kgGgMgXaD6Yb4fXjbnsJNmobKAU9qZgescZXid',
101
117
  oldSubgraphUrl:
102
118
  'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
103
119
  oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
120
+ hmtSubgraphUrl:
121
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-polygon/version/latest',
122
+ hmtSubgraphUrlApiKey:
123
+ 'https://gateway.thegraph.com/api/deployments/id/QmcTTTq2reYDBP5j5P2eToc5FmYbJ5ZSMhPaRB6NLriNjR',
104
124
  },
105
125
  [ChainId.POLYGON_AMOY]: {
106
126
  chainId: ChainId.POLYGON_AMOY,
@@ -111,20 +131,24 @@ export const NETWORKS: {
111
131
  stakingAddress: '0xffE496683F842a923110415b7278ded3F265f2C5',
112
132
  kvstoreAddress: '0x724AeFC243EdacCA27EAB86D3ec5a76Af4436Fc7',
113
133
  subgraphUrl:
114
- 'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
134
+ 'https://api.studio.thegraph.com/query/74256/human-amoy/version/latest',
115
135
  subgraphUrlApiKey:
116
- 'https://gateway.thegraph.com/api/deployments/id/QmcLwLMw3UzCSbNbjegrpNu6PB3kAd67xquuyaVWvc5Q7Q',
136
+ 'https://gateway.thegraph.com/api/deployments/id/QmRx5WSi7o9FtENWnE5eEz8Dr7kYUazk4TNPRt65UZkKkB',
117
137
  oldSubgraphUrl: '',
118
138
  oldFactoryAddress: '',
139
+ hmtSubgraphUrl:
140
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-amoy/version/latest',
141
+ hmtSubgraphUrlApiKey:
142
+ 'https://gateway.thegraph.com/api/deployments/id/QmZze6UWMJna8dQ183TVounSfGwc9C36RgQCGWhFzgrW3y',
119
143
  },
120
144
  [ChainId.LOCALHOST]: {
121
145
  chainId: ChainId.LOCALHOST,
122
146
  title: 'Localhost',
123
147
  scanUrl: '',
124
- factoryAddress: '0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9',
148
+ factoryAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
125
149
  hmtAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
126
150
  stakingAddress: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
127
- kvstoreAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
151
+ kvstoreAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
128
152
  subgraphUrl: 'http://localhost:8000/subgraphs/name/humanprotocol/localhost',
129
153
  subgraphUrlApiKey: '',
130
154
  oldSubgraphUrl: '',
@@ -1,21 +1,5 @@
1
1
  import * as openpgp from 'openpgp';
2
- import { IKeyPair } from './interfaces';
3
-
4
- /**
5
- * Type representing the data type of a message.
6
- * It can be either a string or a Uint8Array.
7
- *
8
- * @public
9
- */
10
- export type MessageDataType = string | Uint8Array;
11
-
12
- function makeMessageDataBinary(message: MessageDataType): Uint8Array {
13
- if (typeof message === 'string') {
14
- return Buffer.from(message);
15
- }
16
-
17
- return message;
18
- }
2
+ import { makeMessageDataBinary, MessageDataType } from './types';
19
3
 
20
4
  /**
21
5
  * Class for signing and decrypting messages.
@@ -191,179 +175,3 @@ export class Encryption {
191
175
  return cleartextMessage;
192
176
  }
193
177
  }
194
-
195
- /**
196
- * Utility class for encryption-related operations.
197
- */
198
- export class EncryptionUtils {
199
- /**
200
- * This function verifies the signature of a signed message using the public key.
201
- *
202
- * @param message - Message to verify.
203
- * @param publicKey - Public key to verify that the message was signed by a specific source.
204
- * @returns True if verified. False if not verified.
205
- *
206
- * @example
207
- * ```ts
208
- * import { EncryptionUtils } from '@human-protocol/sdk';
209
- *
210
- * const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
211
- * const result = await EncryptionUtils.verify('message', publicKey);
212
- * console.log('Verification result:', result);
213
- * ```
214
- */
215
- public static async verify(
216
- message: string,
217
- publicKey: string
218
- ): Promise<boolean> {
219
- const pgpPublicKey = await openpgp.readKey({ armoredKey: publicKey });
220
- const signedMessage = await openpgp.readCleartextMessage({
221
- cleartextMessage: message,
222
- });
223
-
224
- const verificationResult = await signedMessage.verify([pgpPublicKey]);
225
- const { verified } = verificationResult[0];
226
-
227
- try {
228
- return await verified;
229
- } catch {
230
- return false;
231
- }
232
- }
233
-
234
- /**
235
- * This function gets signed data from a signed message.
236
- *
237
- * @param message - Message.
238
- * @returns Signed data.
239
- * @throws Error If data could not be extracted from the message
240
- *
241
- * @example
242
- * ```ts
243
- * import { EncryptionUtils } from '@human-protocol/sdk';
244
- *
245
- * const signedData = await EncryptionUtils.getSignedData('message');
246
- * console.log('Signed data:', signedData);
247
- * ```
248
- */
249
- public static async getSignedData(message: string): Promise<string> {
250
- const signedMessage = await openpgp.readCleartextMessage({
251
- cleartextMessage: message,
252
- });
253
-
254
- try {
255
- return signedMessage.getText();
256
- } catch (e) {
257
- throw new Error('Could not get data: ' + e.message);
258
- }
259
- }
260
-
261
- /**
262
- * This function generates a key pair for encryption and decryption.
263
- *
264
- * @param name - Name for the key pair.
265
- * @param email - Email for the key pair.
266
- * @param passphrase - Passphrase to encrypt the private key (optional, defaults to empty string).
267
- * @returns Key pair generated.
268
- *
269
- * @example
270
- * ```ts
271
- * import { EncryptionUtils } from '@human-protocol/sdk';
272
- *
273
- * const name = 'YOUR_NAME';
274
- * const email = 'YOUR_EMAIL';
275
- * const passphrase = 'YOUR_PASSPHRASE';
276
- * const keyPair = await EncryptionUtils.generateKeyPair(name, email, passphrase);
277
- * console.log('Public key:', keyPair.publicKey);
278
- * ```
279
- */
280
- public static async generateKeyPair(
281
- name: string,
282
- email: string,
283
- passphrase = ''
284
- ): Promise<IKeyPair> {
285
- const { privateKey, publicKey, revocationCertificate } =
286
- await openpgp.generateKey({
287
- type: 'ecc',
288
- curve: 'ed25519Legacy',
289
- userIDs: [{ name: name, email: email }],
290
- passphrase: passphrase,
291
- format: 'armored',
292
- });
293
-
294
- return {
295
- passphrase: passphrase,
296
- privateKey,
297
- publicKey,
298
- revocationCertificate,
299
- };
300
- }
301
-
302
- /**
303
- * This function encrypts a message using the specified public keys.
304
- *
305
- * @param message - Message to encrypt.
306
- * @param publicKeys - Array of public keys to use for encryption.
307
- * @returns Message encrypted.
308
- *
309
- * @example
310
- * ```ts
311
- * import { EncryptionUtils } from '@human-protocol/sdk';
312
- *
313
- * const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
314
- * const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
315
- * const publicKeys = [publicKey1, publicKey2];
316
- * const encryptedMessage = await EncryptionUtils.encrypt('message', publicKeys);
317
- * console.log('Encrypted message:', encryptedMessage);
318
- * ```
319
- */
320
- public static async encrypt(
321
- message: MessageDataType,
322
- publicKeys: string[]
323
- ): Promise<string> {
324
- const pgpPublicKeys = await Promise.all(
325
- publicKeys.map((armoredKey) => openpgp.readKey({ armoredKey }))
326
- );
327
-
328
- const pgpMessage = await openpgp.createMessage({
329
- binary: makeMessageDataBinary(message),
330
- });
331
- const encrypted = await openpgp.encrypt({
332
- message: pgpMessage,
333
- encryptionKeys: pgpPublicKeys,
334
- format: 'armored',
335
- });
336
-
337
- return encrypted as string;
338
- }
339
-
340
- /**
341
- * Verifies if a message appears to be encrypted with OpenPGP.
342
- *
343
- * @param message - Message to verify.
344
- * @returns `true` if the message appears to be encrypted, `false` if not.
345
- *
346
- * @example
347
- * ```ts
348
- * import { EncryptionUtils } from '@human-protocol/sdk';
349
- *
350
- * const message = '-----BEGIN PGP MESSAGE-----...';
351
- * const isEncrypted = EncryptionUtils.isEncrypted(message);
352
- *
353
- * if (isEncrypted) {
354
- * console.log('The message is encrypted with OpenPGP.');
355
- * } else {
356
- * console.log('The message is not encrypted with OpenPGP.');
357
- * }
358
- * ```
359
- */
360
- public static isEncrypted(message: string): boolean {
361
- const startMarker = '-----BEGIN PGP MESSAGE-----';
362
- const endMarker = '-----END PGP MESSAGE-----';
363
-
364
- const hasStartMarker = message.includes(startMarker);
365
- const hasEndMarker = message.includes(endMarker);
366
-
367
- return hasStartMarker && hasEndMarker;
368
- }
369
- }