@human-protocol/sdk 1.1.3 → 1.1.6
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/README.md +80 -1
- package/dist/constants.d.ts +52 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +222 -0
- package/dist/decorators.d.ts +2 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +17 -0
- package/dist/encryption.d.ts +84 -0
- package/dist/encryption.d.ts.map +1 -0
- package/dist/encryption.js +202 -0
- package/dist/enums.d.ts +17 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +20 -0
- package/dist/error.d.ts +196 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +229 -0
- package/dist/escrow.d.ts +201 -0
- package/dist/escrow.d.ts.map +1 -0
- package/dist/escrow.js +651 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/interfaces.d.ts +42 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/interfaces.js +2 -0
- package/dist/kvstore.d.ts +51 -0
- package/dist/kvstore.d.ts.map +1 -0
- package/dist/kvstore.js +135 -0
- package/dist/queries.d.ts +5 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +19 -0
- package/dist/staking.d.ts +130 -0
- package/dist/staking.d.ts.map +1 -0
- package/dist/staking.js +409 -0
- package/dist/storage.d.ts +49 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +171 -0
- package/dist/types.d.ts +131 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +35 -0
- package/dist/utils.d.ts +32 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +99 -0
- package/package.json +4 -1
- package/src/constants.ts +25 -6
- package/src/encryption.ts +223 -0
- package/src/error.ts +2 -4
- package/src/escrow.ts +120 -74
- package/src/index.ts +6 -12
- package/src/interfaces.ts +10 -13
- package/src/kvstore.ts +51 -14
- package/src/queries.ts +15 -7
- package/src/staking.ts +61 -24
- package/src/storage.ts +15 -3
- package/src/types.ts +8 -0
- package/src/init.ts +0 -45
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum for escrow statuses.
|
|
3
|
+
* @readonly
|
|
4
|
+
* @enum {number}
|
|
5
|
+
*/
|
|
6
|
+
export declare enum EscrowStatus {
|
|
7
|
+
/**
|
|
8
|
+
* Escrow is launched.
|
|
9
|
+
*/
|
|
10
|
+
Launched = 0,
|
|
11
|
+
/**
|
|
12
|
+
* Escrow is funded, and waiting for the results to be submitted.
|
|
13
|
+
*/
|
|
14
|
+
Pending = 1,
|
|
15
|
+
/**
|
|
16
|
+
* Escrow is partially paid out.
|
|
17
|
+
*/
|
|
18
|
+
Partial = 2,
|
|
19
|
+
/**
|
|
20
|
+
* Escrow is fully paid.
|
|
21
|
+
*/
|
|
22
|
+
Paid = 3,
|
|
23
|
+
/**
|
|
24
|
+
* Escrow is finished..
|
|
25
|
+
*/
|
|
26
|
+
Complete = 4,
|
|
27
|
+
/**
|
|
28
|
+
* Escrow is cancelled.
|
|
29
|
+
*/
|
|
30
|
+
Cancelled = 5
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* AWS/GCP cloud storage access data
|
|
34
|
+
* @readonly
|
|
35
|
+
*/
|
|
36
|
+
export type StorageCredentials = {
|
|
37
|
+
/**
|
|
38
|
+
* Access Key
|
|
39
|
+
*/
|
|
40
|
+
accessKey: string;
|
|
41
|
+
/**
|
|
42
|
+
* Secret Key
|
|
43
|
+
*/
|
|
44
|
+
secretKey: string;
|
|
45
|
+
};
|
|
46
|
+
export type StorageParams = {
|
|
47
|
+
/**
|
|
48
|
+
* Request endPoint
|
|
49
|
+
*/
|
|
50
|
+
endPoint: string;
|
|
51
|
+
/**
|
|
52
|
+
* Enable secure (HTTPS) access. Default value set to false
|
|
53
|
+
*/
|
|
54
|
+
useSSL: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Region
|
|
57
|
+
*/
|
|
58
|
+
region?: string;
|
|
59
|
+
/**
|
|
60
|
+
* TCP/IP port number. Default value set to 80 for HTTP and 443 for HTTPs
|
|
61
|
+
*/
|
|
62
|
+
port?: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Upload file data
|
|
66
|
+
* @readonly
|
|
67
|
+
*/
|
|
68
|
+
export type UploadFile = {
|
|
69
|
+
/**
|
|
70
|
+
* Uploaded object key
|
|
71
|
+
*/
|
|
72
|
+
key: string;
|
|
73
|
+
/**
|
|
74
|
+
* Uploaded object URL
|
|
75
|
+
*/
|
|
76
|
+
url: string;
|
|
77
|
+
/**
|
|
78
|
+
* Hash of uploaded object key
|
|
79
|
+
*/
|
|
80
|
+
hash: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Network data
|
|
84
|
+
*/
|
|
85
|
+
export type NetworkData = {
|
|
86
|
+
/**
|
|
87
|
+
* Network chain id
|
|
88
|
+
*/
|
|
89
|
+
chainId: number;
|
|
90
|
+
/**
|
|
91
|
+
* Network title
|
|
92
|
+
*/
|
|
93
|
+
title: string;
|
|
94
|
+
/**
|
|
95
|
+
* Network scanner URL
|
|
96
|
+
*/
|
|
97
|
+
scanUrl: string;
|
|
98
|
+
/**
|
|
99
|
+
* HMT Token contract address
|
|
100
|
+
*/
|
|
101
|
+
hmtAddress: string;
|
|
102
|
+
/**
|
|
103
|
+
* Escrow Factory contract address
|
|
104
|
+
*/
|
|
105
|
+
factoryAddress: string;
|
|
106
|
+
/**
|
|
107
|
+
* Staking contract address
|
|
108
|
+
*/
|
|
109
|
+
stakingAddress: string;
|
|
110
|
+
/**
|
|
111
|
+
* RewardPool contract address
|
|
112
|
+
*/
|
|
113
|
+
rewardPoolAddress: string;
|
|
114
|
+
/**
|
|
115
|
+
* KVStore contract address
|
|
116
|
+
*/
|
|
117
|
+
kvstoreAddress: string;
|
|
118
|
+
/**
|
|
119
|
+
* Subgraph URL
|
|
120
|
+
*/
|
|
121
|
+
subgraphUrl: string;
|
|
122
|
+
/**
|
|
123
|
+
* Old subgraph URL
|
|
124
|
+
*/
|
|
125
|
+
oldSubgraphUrl: string;
|
|
126
|
+
/**
|
|
127
|
+
* Old Escrow Factory contract address
|
|
128
|
+
*/
|
|
129
|
+
oldFactoryAddress: string;
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;CACV;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EscrowStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum for escrow statuses.
|
|
6
|
+
* @readonly
|
|
7
|
+
* @enum {number}
|
|
8
|
+
*/
|
|
9
|
+
var EscrowStatus;
|
|
10
|
+
(function (EscrowStatus) {
|
|
11
|
+
/**
|
|
12
|
+
* Escrow is launched.
|
|
13
|
+
*/
|
|
14
|
+
EscrowStatus[EscrowStatus["Launched"] = 0] = "Launched";
|
|
15
|
+
/**
|
|
16
|
+
* Escrow is funded, and waiting for the results to be submitted.
|
|
17
|
+
*/
|
|
18
|
+
EscrowStatus[EscrowStatus["Pending"] = 1] = "Pending";
|
|
19
|
+
/**
|
|
20
|
+
* Escrow is partially paid out.
|
|
21
|
+
*/
|
|
22
|
+
EscrowStatus[EscrowStatus["Partial"] = 2] = "Partial";
|
|
23
|
+
/**
|
|
24
|
+
* Escrow is fully paid.
|
|
25
|
+
*/
|
|
26
|
+
EscrowStatus[EscrowStatus["Paid"] = 3] = "Paid";
|
|
27
|
+
/**
|
|
28
|
+
* Escrow is finished..
|
|
29
|
+
*/
|
|
30
|
+
EscrowStatus[EscrowStatus["Complete"] = 4] = "Complete";
|
|
31
|
+
/**
|
|
32
|
+
* Escrow is cancelled.
|
|
33
|
+
*/
|
|
34
|
+
EscrowStatus[EscrowStatus["Cancelled"] = 5] = "Cancelled";
|
|
35
|
+
})(EscrowStatus = exports.EscrowStatus || (exports.EscrowStatus = {}));
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **Get specific error text.*
|
|
3
|
+
*
|
|
4
|
+
* @param {any} error - An error message.
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const getRevertReason: (error: any) => string;
|
|
8
|
+
/**
|
|
9
|
+
* **Handle and throw the error.*
|
|
10
|
+
*
|
|
11
|
+
* @param {any} e
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare const throwError: (e: any) => never;
|
|
15
|
+
/**
|
|
16
|
+
* **URL validation.*
|
|
17
|
+
*
|
|
18
|
+
* @param {string} url
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare const isValidUrl: (url: string) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* **Fetching data with queries.*
|
|
24
|
+
*
|
|
25
|
+
* @param {string} url
|
|
26
|
+
* @param {string} query
|
|
27
|
+
* @param {any} variables
|
|
28
|
+
* @param {any} headers
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare const gqlFetch: (url: string, query: string, variables?: any, headers?: any) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
32
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAiBA;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,GAAG,KAAG,MAO5C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,MAAO,GAAG,UAqBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,YAOrC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,QACd,MAAM,SACJ,MAAM,cACD,GAAG,YACL,GAAG,qDAYd,CAAC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.gqlFetch = exports.isValidUrl = exports.throwError = exports.getRevertReason = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const ethers_1 = require("ethers");
|
|
10
|
+
const error_1 = require("./error");
|
|
11
|
+
/**
|
|
12
|
+
* **Get specific error text.*
|
|
13
|
+
*
|
|
14
|
+
* @param {any} error - An error message.
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
const getRevertReason = (error) => {
|
|
18
|
+
const prefix = "reverted with reason string '";
|
|
19
|
+
const suffix = "'";
|
|
20
|
+
const message = error.data.substring(error.data.indexOf(prefix) + prefix.length);
|
|
21
|
+
return message.substring(0, message.indexOf(suffix));
|
|
22
|
+
};
|
|
23
|
+
exports.getRevertReason = getRevertReason;
|
|
24
|
+
/**
|
|
25
|
+
* **Handle and throw the error.*
|
|
26
|
+
*
|
|
27
|
+
* @param {any} e
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
const throwError = (e) => {
|
|
31
|
+
if (e.code === ethers_1.ethers.utils.Logger.errors.INVALID_ARGUMENT) {
|
|
32
|
+
throw new error_1.InvalidArgumentError(e.message);
|
|
33
|
+
}
|
|
34
|
+
else if (e.code === 'OUT_OF_GAS') {
|
|
35
|
+
throw new error_1.OutOfGasError(e.message);
|
|
36
|
+
}
|
|
37
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.CALL_EXCEPTION) {
|
|
38
|
+
const reason = (0, exports.getRevertReason)(e.data);
|
|
39
|
+
throw new error_1.ContractExecutionError(reason);
|
|
40
|
+
}
|
|
41
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.UNPREDICTABLE_GAS_LIMIT) {
|
|
42
|
+
throw new error_1.UnpredictableGasLimit(e.message);
|
|
43
|
+
}
|
|
44
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.TRANSACTION_REPLACED) {
|
|
45
|
+
throw new error_1.TransactionReplaced(e.message);
|
|
46
|
+
}
|
|
47
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.REPLACEMENT_UNDERPRICED) {
|
|
48
|
+
throw new error_1.ReplacementUnderpriced(e.message);
|
|
49
|
+
}
|
|
50
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.NUMERIC_FAULT) {
|
|
51
|
+
throw new error_1.NumericFault(e.message);
|
|
52
|
+
}
|
|
53
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.NONCE_EXPIRED) {
|
|
54
|
+
throw new error_1.NonceExpired(e.message);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw new error_1.EthereumError(e.message);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.throwError = throwError;
|
|
61
|
+
/**
|
|
62
|
+
* **URL validation.*
|
|
63
|
+
*
|
|
64
|
+
* @param {string} url
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
const isValidUrl = (url) => {
|
|
68
|
+
try {
|
|
69
|
+
new URL(url);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.isValidUrl = isValidUrl;
|
|
77
|
+
/**
|
|
78
|
+
* **Fetching data with queries.*
|
|
79
|
+
*
|
|
80
|
+
* @param {string} url
|
|
81
|
+
* @param {string} query
|
|
82
|
+
* @param {any} variables
|
|
83
|
+
* @param {any} headers
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
const gqlFetch = (url, query, variables, headers) => {
|
|
87
|
+
if (url && url.length) {
|
|
88
|
+
return axios_1.default.post(url, JSON.stringify({ query, variables }), {
|
|
89
|
+
headers: {
|
|
90
|
+
'Content-Type': 'application/json',
|
|
91
|
+
...headers,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return Promise.reject(error_1.ErrorNoURLprovided);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.gqlFetch = gqlFetch;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@human-protocol/sdk",
|
|
3
3
|
"description": "Human Protocol SDK",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.6",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
7
7
|
"dist"
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"types": "dist/index.d.ts",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"clean": "rm -rf ./dist",
|
|
13
|
+
"prebuild": "yarn workspace @human-protocol/core build",
|
|
13
14
|
"build": "npm run clean && tsc",
|
|
14
15
|
"prepublish": "npm run build",
|
|
15
16
|
"test": "vitest -u",
|
|
@@ -38,8 +39,10 @@
|
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@human-protocol/core": "*",
|
|
40
41
|
"aws-sdk": "^2.1255.0",
|
|
42
|
+
"axios": "^1.4.0",
|
|
41
43
|
"crypto": "^1.0.1",
|
|
42
44
|
"ethers": "^5.7.2",
|
|
45
|
+
"minio": "^7.0.32",
|
|
43
46
|
"secp256k1": "^4.0.3",
|
|
44
47
|
"vitest": "^0.30.1",
|
|
45
48
|
"winston": "^3.8.2"
|
package/src/constants.ts
CHANGED
|
@@ -58,6 +58,7 @@ export const NETWORKS: {
|
|
|
58
58
|
factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
|
|
59
59
|
hmtAddress: '0xd1ba9BAC957322D6e8c07a160a3A8dA11A0d2867',
|
|
60
60
|
stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
|
|
61
|
+
rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
|
|
61
62
|
kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
|
|
62
63
|
subgraphUrl:
|
|
63
64
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v1',
|
|
@@ -71,6 +72,7 @@ export const NETWORKS: {
|
|
|
71
72
|
factoryAddress: '0x925B24444511c86F4d4E63141D8Be0A025E2dca4',
|
|
72
73
|
hmtAddress: '0x4dCf5ac4509888714dd43A5cCc46d7ab389D9c23',
|
|
73
74
|
stakingAddress: '',
|
|
75
|
+
rewardPoolAddress: '',
|
|
74
76
|
kvstoreAddress: '',
|
|
75
77
|
subgraphUrl: '',
|
|
76
78
|
oldSubgraphUrl: '',
|
|
@@ -83,6 +85,7 @@ export const NETWORKS: {
|
|
|
83
85
|
factoryAddress: '0x87469B4f2Fcf37cBd34E54244c0BD4Fa0603664c',
|
|
84
86
|
hmtAddress: '0xd3A31D57FDD790725d0F6B78095F62E8CD4ab317',
|
|
85
87
|
stakingAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
|
|
88
|
+
rewardPoolAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
|
|
86
89
|
kvstoreAddress: '0xc9Fe39c4b6e1d7A2991355Af159956982DADf842',
|
|
87
90
|
subgraphUrl:
|
|
88
91
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v1',
|
|
@@ -94,11 +97,11 @@ export const NETWORKS: {
|
|
|
94
97
|
chainId: ChainId.BSC_MAINNET,
|
|
95
98
|
title: 'Binance Smart Chain',
|
|
96
99
|
scanUrl: 'https://bscscan.com',
|
|
97
|
-
factoryAddress: '
|
|
98
|
-
hmtAddress: '
|
|
99
|
-
stakingAddress: '
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
factoryAddress: '0x92FD968AcBd521c232f5fB8c33b342923cC72714',
|
|
101
|
+
hmtAddress: '0x711Fd6ab6d65A98904522d4e3586F492B989c527',
|
|
102
|
+
stakingAddress: '0xdFbB79dC35a3A53741be54a2C9b587d6BafAbd1C',
|
|
103
|
+
rewardPoolAddress: '0xf376443BCc6d4d4D63eeC086bc4A9E4a83878e0e',
|
|
104
|
+
kvstoreAddress: '0x2B95bEcb6EBC4589f64CB000dFCF716b4aeF8aA6',
|
|
102
105
|
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v1',
|
|
103
106
|
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
|
|
104
107
|
oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
|
|
@@ -110,6 +113,7 @@ export const NETWORKS: {
|
|
|
110
113
|
factoryAddress: '0x2bfA592DBDaF434DDcbb893B1916120d181DAD18',
|
|
111
114
|
hmtAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
|
|
112
115
|
stakingAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18',
|
|
116
|
+
rewardPoolAddress: '0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29',
|
|
113
117
|
kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4',
|
|
114
118
|
subgraphUrl:
|
|
115
119
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v1',
|
|
@@ -124,6 +128,7 @@ export const NETWORKS: {
|
|
|
124
128
|
factoryAddress: '0xBDBfD2cC708199C5640C6ECdf3B0F4A4C67AdfcB',
|
|
125
129
|
hmtAddress: '0xc748B2A084F8eFc47E086ccdDD9b7e67aEb571BF',
|
|
126
130
|
stakingAddress: '0xcbAd56bE3f504E98bd70875823d3CC0242B7bB29',
|
|
131
|
+
rewardPoolAddress: '0xa8e32d777a3839440cc7c24D591A64B9481753B3',
|
|
127
132
|
kvstoreAddress: '0x35Cf4beBD58F9C8D75B9eA2599479b6C173d406F',
|
|
128
133
|
subgraphUrl:
|
|
129
134
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v1',
|
|
@@ -138,6 +143,7 @@ export const NETWORKS: {
|
|
|
138
143
|
factoryAddress: '0xA8D927C4DA17A6b71675d2D49dFda4E9eBE58f2d',
|
|
139
144
|
hmtAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
|
|
140
145
|
stakingAddress: '0x7Fd3dF914E7b6Bd96B4c744Df32183b51368Bfac',
|
|
146
|
+
rewardPoolAddress: '0xf0145eD99AC3c4f877aDa7dA4D1E059ec9116BAE',
|
|
141
147
|
kvstoreAddress: '0xD7F61E812e139a5a02eDae9Dfec146E1b8eA3807',
|
|
142
148
|
subgraphUrl:
|
|
143
149
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v1',
|
|
@@ -152,6 +158,7 @@ export const NETWORKS: {
|
|
|
152
158
|
factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
|
|
153
159
|
hmtAddress: '0x3b25BC1dC591D24d60560d0135D6750A561D4764',
|
|
154
160
|
stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
|
|
161
|
+
rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
|
|
155
162
|
kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
|
|
156
163
|
subgraphUrl:
|
|
157
164
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v1',
|
|
@@ -166,6 +173,7 @@ export const NETWORKS: {
|
|
|
166
173
|
factoryAddress: '0x5e622FF522D81aa426f082bDD95210BC25fCA7Ed',
|
|
167
174
|
hmtAddress: '0x2dd72db2bBA65cE663e476bA8b84A1aAF802A8e3',
|
|
168
175
|
stakingAddress: '0xBFC7009F3371F93F3B54DdC8caCd02914a37495c',
|
|
176
|
+
rewardPoolAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
|
|
169
177
|
kvstoreAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
|
|
170
178
|
subgraphUrl:
|
|
171
179
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v1',
|
|
@@ -179,6 +187,7 @@ export const NETWORKS: {
|
|
|
179
187
|
factoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88',
|
|
180
188
|
hmtAddress: '0x9406d5c635AD22b0d76c75E52De57A2177919ca3',
|
|
181
189
|
stakingAddress: '',
|
|
190
|
+
rewardPoolAddress: '',
|
|
182
191
|
kvstoreAddress: '0xd232c1426CF0653cE8a71DC98bCfDf10c471c114',
|
|
183
192
|
|
|
184
193
|
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji',
|
|
@@ -192,6 +201,7 @@ export const NETWORKS: {
|
|
|
192
201
|
factoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4',
|
|
193
202
|
hmtAddress: '0x12365293cb6477d4fc2686e46BB97E3Fb64f1550',
|
|
194
203
|
stakingAddress: '',
|
|
204
|
+
rewardPoolAddress: '',
|
|
195
205
|
kvstoreAddress: '0x4B79eaD28F52eD5686bf0e379717e85fc7aD10Df',
|
|
196
206
|
subgraphUrl:
|
|
197
207
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche',
|
|
@@ -205,6 +215,7 @@ export const NETWORKS: {
|
|
|
205
215
|
factoryAddress: '0x319070b49C8d1cC015915D1E7Eb5fd8e22833885',
|
|
206
216
|
hmtAddress: '0x6E5FF61Ea88270F6142E0E0eC8cbe9d67476CbCd',
|
|
207
217
|
stakingAddress: '0x79F37FB9C210910733c16228AC4D14a8e32C11BD',
|
|
218
|
+
rewardPoolAddress: '0x881218246c25C6898aE96145259584340153aDA2',
|
|
208
219
|
kvstoreAddress: '0xE1055607327b1be2080D31211dCDC4D9338CaF4A',
|
|
209
220
|
subgraphUrl:
|
|
210
221
|
'https://graph-skale.humanprotocol.org/subgraphs/name/skale-human',
|
|
@@ -217,10 +228,18 @@ export const NETWORKS: {
|
|
|
217
228
|
scanUrl: '',
|
|
218
229
|
factoryAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
|
|
219
230
|
hmtAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
|
|
220
|
-
stakingAddress: '
|
|
231
|
+
stakingAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
|
|
232
|
+
rewardPoolAddress: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853',
|
|
221
233
|
kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
|
|
222
234
|
subgraphUrl: '',
|
|
223
235
|
oldSubgraphUrl: '',
|
|
224
236
|
oldFactoryAddress: '',
|
|
225
237
|
},
|
|
226
238
|
};
|
|
239
|
+
|
|
240
|
+
export const KVStoreKeys = {
|
|
241
|
+
role: 'role',
|
|
242
|
+
webhook_url: 'webhook_url',
|
|
243
|
+
fee: 'fee',
|
|
244
|
+
public_key: 'public_key',
|
|
245
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import * as openpgp from 'openpgp';
|
|
2
|
+
import { IKeyPair } from './interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Class for encryption and decryption operations.
|
|
5
|
+
*/
|
|
6
|
+
export class Encryption {
|
|
7
|
+
private privateKey: openpgp.PrivateKey;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constructor for the Encryption class.
|
|
11
|
+
*
|
|
12
|
+
* @param {PrivateKey} privateKey - The private key.
|
|
13
|
+
*/
|
|
14
|
+
constructor(privateKey: openpgp.PrivateKey) {
|
|
15
|
+
this.privateKey = privateKey;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} privateKeyArmored - The encrypted private key in armored format.
|
|
22
|
+
* @param {string} passphrase - Optional: The passphrase for the private key.
|
|
23
|
+
* @returns {Promise<Encryption>} - The Encryption instance.
|
|
24
|
+
*/
|
|
25
|
+
public static async build(
|
|
26
|
+
privateKeyArmored: string,
|
|
27
|
+
passphrase?: string
|
|
28
|
+
): Promise<Encryption> {
|
|
29
|
+
const options = {
|
|
30
|
+
armoredKey: privateKeyArmored,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (!passphrase) {
|
|
34
|
+
return new Encryption(await openpgp.readPrivateKey(options));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const privateKey = await openpgp.readPrivateKey(options);
|
|
38
|
+
return new Encryption(
|
|
39
|
+
await openpgp.decryptKey({
|
|
40
|
+
privateKey,
|
|
41
|
+
passphrase,
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Signs and encrypts a message using the specified public keys.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} message - The message to encrypt.
|
|
50
|
+
* @param {string[]} publicKeys - The public keys in armored format.
|
|
51
|
+
* @returns {Promise<string>} - The encrypted message.
|
|
52
|
+
*/
|
|
53
|
+
public async signAndEncrypt(
|
|
54
|
+
message: string,
|
|
55
|
+
publicKeys: string[]
|
|
56
|
+
): Promise<string> {
|
|
57
|
+
const plaintext = message;
|
|
58
|
+
|
|
59
|
+
const pgpPublicKeys = await Promise.all(
|
|
60
|
+
publicKeys.map((armoredKey) => openpgp.readKey({ armoredKey }))
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const pgpMessage = await openpgp.createMessage({ text: plaintext });
|
|
64
|
+
const encrypted = await openpgp.encrypt({
|
|
65
|
+
message: pgpMessage,
|
|
66
|
+
encryptionKeys: pgpPublicKeys,
|
|
67
|
+
signingKeys: this.privateKey,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return encrypted as string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Decrypts an encrypted message using the private key.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} message - The encrypted message.
|
|
77
|
+
* @param {string} publicKey - Optional: The public key in armored format for signature verification.
|
|
78
|
+
* @returns {Promise<string>} - The decrypted message.
|
|
79
|
+
*/
|
|
80
|
+
public async decrypt(message: string, publicKey?: string): Promise<string> {
|
|
81
|
+
const pgpMessage = await openpgp.readMessage({ armoredMessage: message });
|
|
82
|
+
|
|
83
|
+
const decryptionOptions: openpgp.DecryptOptions = {
|
|
84
|
+
message: pgpMessage,
|
|
85
|
+
decryptionKeys: this.privateKey,
|
|
86
|
+
expectSigned: !!publicKey,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
if (publicKey) {
|
|
90
|
+
const pgpPublicKey = await openpgp.readKey({ armoredKey: publicKey });
|
|
91
|
+
decryptionOptions.verificationKeys = pgpPublicKey;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const { data: decrypted } = await openpgp.decrypt(decryptionOptions);
|
|
95
|
+
|
|
96
|
+
return decrypted as string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Signs a message using the private key.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} message - The message to sign.
|
|
103
|
+
* @returns {Promise<string>} - The signed message.
|
|
104
|
+
*/
|
|
105
|
+
public async sign(message: string): Promise<string> {
|
|
106
|
+
const unsignedMessage = await openpgp.createCleartextMessage({
|
|
107
|
+
text: message,
|
|
108
|
+
});
|
|
109
|
+
const cleartextMessage = await openpgp.sign({
|
|
110
|
+
message: unsignedMessage,
|
|
111
|
+
signingKeys: this.privateKey,
|
|
112
|
+
format: 'armored',
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return cleartextMessage;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Utility class for encryption-related operations.
|
|
121
|
+
*/
|
|
122
|
+
export class EncryptionUtils {
|
|
123
|
+
/**
|
|
124
|
+
* Verifies the signature of a signed message using the public key.
|
|
125
|
+
*
|
|
126
|
+
* @param {string} message - The signed message.
|
|
127
|
+
* @param {string} publicKey - The public key in armored format.
|
|
128
|
+
* @returns {Promise<boolean>} - A boolean indicating if the signature is valid.
|
|
129
|
+
*/
|
|
130
|
+
public static async verify(
|
|
131
|
+
message: string,
|
|
132
|
+
publicKey: string
|
|
133
|
+
): Promise<boolean> {
|
|
134
|
+
const pgpPublicKey = await openpgp.readKey({ armoredKey: publicKey });
|
|
135
|
+
const signedMessage = await openpgp.readCleartextMessage({
|
|
136
|
+
cleartextMessage: message,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const verificationResult = await signedMessage.verify([pgpPublicKey]);
|
|
140
|
+
const { verified } = verificationResult[0];
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
return await verified;
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Gets the signed data from a signed message.
|
|
151
|
+
*
|
|
152
|
+
* @param {string} message - The signed message.
|
|
153
|
+
* @returns {Promise<string>} - The signed data.
|
|
154
|
+
* @throws {Error} - An error object if an error occurred.
|
|
155
|
+
*/
|
|
156
|
+
public static async getSignedData(message: string): Promise<string> {
|
|
157
|
+
const signedMessage = await openpgp.readCleartextMessage({
|
|
158
|
+
cleartextMessage: message,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
return signedMessage.getText();
|
|
163
|
+
} catch (e) {
|
|
164
|
+
throw new Error('Could not get data: ' + e.message);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Generates a key pair for encryption and decryption.
|
|
170
|
+
*
|
|
171
|
+
* @param {string} name - The name for the key pair.
|
|
172
|
+
* @param {string} email - The email for the key pair.
|
|
173
|
+
* @param {string} passphrase - The passphrase used to encrypt the private key.
|
|
174
|
+
* @returns {Promise<IKeyPair>} - The generated key pair.
|
|
175
|
+
*/
|
|
176
|
+
public static async generateKeyPair(
|
|
177
|
+
name: string,
|
|
178
|
+
email: string,
|
|
179
|
+
passphrase = ''
|
|
180
|
+
): Promise<IKeyPair> {
|
|
181
|
+
const { privateKey, publicKey, revocationCertificate } =
|
|
182
|
+
await openpgp.generateKey({
|
|
183
|
+
type: 'ecc',
|
|
184
|
+
curve: 'ed25519',
|
|
185
|
+
userIDs: [{ name: name, email: email }],
|
|
186
|
+
passphrase: passphrase,
|
|
187
|
+
format: 'armored',
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
passphrase: passphrase,
|
|
192
|
+
privateKey,
|
|
193
|
+
publicKey,
|
|
194
|
+
revocationCertificate,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Encrypts a message using the specified public keys.
|
|
200
|
+
*
|
|
201
|
+
* @param {string} message - The message to encrypt.
|
|
202
|
+
* @param {string[]} publicKeys - The public keys in armored format.
|
|
203
|
+
* @returns {Promise<string>} - The encrypted message.
|
|
204
|
+
*/
|
|
205
|
+
public static async encrypt(
|
|
206
|
+
message: string,
|
|
207
|
+
publicKeys: string[]
|
|
208
|
+
): Promise<string> {
|
|
209
|
+
const plaintext = message;
|
|
210
|
+
|
|
211
|
+
const pgpPublicKeys = await Promise.all(
|
|
212
|
+
publicKeys.map((armoredKey) => openpgp.readKey({ armoredKey }))
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const pgpMessage = await openpgp.createMessage({ text: plaintext });
|
|
216
|
+
const encrypted = await openpgp.encrypt({
|
|
217
|
+
message: pgpMessage,
|
|
218
|
+
encryptionKeys: pgpPublicKeys,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
return encrypted as string;
|
|
222
|
+
}
|
|
223
|
+
}
|
package/src/error.ts
CHANGED
|
@@ -141,14 +141,12 @@ export const ErrorHMTokenAmountNotApproved = new Error('Amount not approved');
|
|
|
141
141
|
/**
|
|
142
142
|
* @constant {Error} - Init provider does not exists.
|
|
143
143
|
*/
|
|
144
|
-
export const
|
|
145
|
-
'Provider does not exist'
|
|
146
|
-
);
|
|
144
|
+
export const ErrorProviderDoesNotExist = new Error('Provider does not exist');
|
|
147
145
|
|
|
148
146
|
/**
|
|
149
147
|
* @constant {Error} - Init with unsupported chain ID.
|
|
150
148
|
*/
|
|
151
|
-
export const
|
|
149
|
+
export const ErrorUnsupportedChainID = new Error('Unsupported chain ID');
|
|
152
150
|
|
|
153
151
|
/**
|
|
154
152
|
* @constant {Error} - Sending a transaction requires a signer.
|