@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.
Files changed (56) hide show
  1. package/README.md +80 -1
  2. package/dist/constants.d.ts +52 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +222 -0
  5. package/dist/decorators.d.ts +2 -0
  6. package/dist/decorators.d.ts.map +1 -0
  7. package/dist/decorators.js +17 -0
  8. package/dist/encryption.d.ts +84 -0
  9. package/dist/encryption.d.ts.map +1 -0
  10. package/dist/encryption.js +202 -0
  11. package/dist/enums.d.ts +17 -0
  12. package/dist/enums.d.ts.map +1 -0
  13. package/dist/enums.js +20 -0
  14. package/dist/error.d.ts +196 -0
  15. package/dist/error.d.ts.map +1 -0
  16. package/dist/error.js +229 -0
  17. package/dist/escrow.d.ts +201 -0
  18. package/dist/escrow.d.ts.map +1 -0
  19. package/dist/escrow.js +651 -0
  20. package/dist/index.d.ts +10 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +29 -0
  23. package/dist/interfaces.d.ts +42 -0
  24. package/dist/interfaces.d.ts.map +1 -0
  25. package/dist/interfaces.js +2 -0
  26. package/dist/kvstore.d.ts +51 -0
  27. package/dist/kvstore.d.ts.map +1 -0
  28. package/dist/kvstore.js +135 -0
  29. package/dist/queries.d.ts +5 -0
  30. package/dist/queries.d.ts.map +1 -0
  31. package/dist/queries.js +19 -0
  32. package/dist/staking.d.ts +130 -0
  33. package/dist/staking.d.ts.map +1 -0
  34. package/dist/staking.js +409 -0
  35. package/dist/storage.d.ts +49 -0
  36. package/dist/storage.d.ts.map +1 -0
  37. package/dist/storage.js +171 -0
  38. package/dist/types.d.ts +131 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +35 -0
  41. package/dist/utils.d.ts +32 -0
  42. package/dist/utils.d.ts.map +1 -0
  43. package/dist/utils.js +99 -0
  44. package/package.json +4 -1
  45. package/src/constants.ts +25 -6
  46. package/src/encryption.ts +223 -0
  47. package/src/error.ts +2 -4
  48. package/src/escrow.ts +120 -74
  49. package/src/index.ts +6 -12
  50. package/src/interfaces.ts +10 -13
  51. package/src/kvstore.ts +51 -14
  52. package/src/queries.ts +15 -7
  53. package/src/staking.ts +61 -24
  54. package/src/storage.ts +15 -3
  55. package/src/types.ts +8 -0
  56. package/src/init.ts +0 -45
package/README.md CHANGED
@@ -6,4 +6,83 @@ Node.js SDK to launch/manage escrows on [Human Protocol](https://www.humanprotoc
6
6
 
7
7
  This SDK is available on [NPM](https://www.npmjs.com/package/@human-protocol/sdk).
8
8
 
9
- yarn @human-protocol/sdk
9
+ yarn add @human-protocol/sdk
10
+
11
+ ## Components
12
+
13
+ - InitClient
14
+
15
+ **InitClient** has one static function that returns a `Signer` or `Provider` (depending on the passed parameter), as well as a chainId associated with this parameter in an asynchronous way. Used for further passing as a constructor parameter to Web3 dependent modules.
16
+
17
+ - StorageClient
18
+
19
+ **StorageClient** is used to upload/download files to the cloud storage with given credentials and params. If credentials are not provided, anonymous access will be used (for downloading files).
20
+
21
+ - EscrowClient
22
+
23
+ **EscrowClient** enables to perform actions on Escrow contracts and obtain information from both the contracts and subgraph. Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
24
+
25
+ - KVStoreClient
26
+
27
+ **KVStoreClient** enables to perform actions on KVStore contract and obtain information from both the contracts and subgraph. Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
28
+
29
+ - StakingClient
30
+
31
+ **StakingClient** enables to perform actions on staking contracts and obtain staking information from both the contracts and subgraph. Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
32
+
33
+ ## Example
34
+
35
+ ```typescript
36
+ const {
37
+ EscrowClient,
38
+ StakingClient,
39
+ NETWORKS,
40
+ ChainId,
41
+ } = require('@human-protocol/sdk');
42
+ const { ethers } = require('ethers');
43
+
44
+ (async () => {
45
+ // Hardhat Provider
46
+ const provider = new ethers.providers.JsonRpcProvider(
47
+ 'http://127.0.0.1:8545/'
48
+ );
49
+
50
+ // Load localhost configuration
51
+ const network = NETWORKS[ChainId.LOCALHOST];
52
+
53
+ const signer = new ethers.Wallet(
54
+ '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a',
55
+ provider
56
+ );
57
+
58
+ // Initialize StakingClient
59
+ const stakingClient = new StakingClient({
60
+ signerOrProvider: signer,
61
+ network,
62
+ });
63
+
64
+ // Stake 10 HMT
65
+ await stakingClient.approveStake(ethers.BigNumber.from(10));
66
+ await stakingClient.stake(ethers.BigNumber.from(10));
67
+
68
+ // Initialize EscrowClient
69
+ const escrowClient = new EscrowClient({
70
+ signerOrProvider: signer,
71
+ network,
72
+ });
73
+
74
+ // Create a new escrow, and setup
75
+ const escrowAddress = await escrowClient.createEscrow(network.hmtAddress, [
76
+ signer.address,
77
+ ]);
78
+
79
+ await escrowClient.setup(escrowAddress, {
80
+ recordingOracle: '0x90F79bf6EB2c4f870365E785982E1f101E93b906',
81
+ reputationOracle: '0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65',
82
+ recordingOracleFee: ethers.BigNumber.from(1),
83
+ reputationOracleFee: ethers.BigNumber.from(1),
84
+ manifestUrl: 'http://example.com',
85
+ hash: 'test',
86
+ });
87
+ })();
88
+ ```
@@ -0,0 +1,52 @@
1
+ import { ChainId } from './enums';
2
+ import { NetworkData } from './types';
3
+ /**
4
+ * @constant Default public bucket name
5
+ */
6
+ export declare const DEFAULT_PUBLIC_BUCKET = "escrow-public-results";
7
+ /**
8
+ * @constant Default storage endpoint
9
+ */
10
+ export declare const DEFAULT_ENDPOINT = "localhost";
11
+ /**
12
+ * @constant Default storage region
13
+ */
14
+ export declare const DEFAULT_REGION = "eu";
15
+ /**
16
+ * @constant Default storage port
17
+ */
18
+ export declare const DEFAULT_PORT = 9000;
19
+ /**
20
+ * @constant Default storage port
21
+ */
22
+ export declare const DEFAULT_USE_SSL = false;
23
+ /**
24
+ * @constant Default tx Id
25
+ */
26
+ export declare const DEFAULT_TX_ID = 1;
27
+ /**
28
+ * @constant Default Enum for escrow statuses.
29
+ */
30
+ export declare enum HttpStatus {
31
+ OK = 200,
32
+ CREATED = 201,
33
+ BAD_REQUEST = 400,
34
+ UNAUTHORIZED = 401,
35
+ PAYMENT_REQUIRED = 402,
36
+ FORBIDDEN = 403,
37
+ NOT_FOUND = 404,
38
+ INTERNAL_SERVER_ERROR = 500
39
+ }
40
+ /**
41
+ * @constant Default network parameters
42
+ */
43
+ export declare const NETWORKS: {
44
+ [chainId in ChainId]?: NetworkData;
45
+ };
46
+ export declare const KVStoreKeys: {
47
+ role: string;
48
+ webhook_url: string;
49
+ fee: string;
50
+ public_key: string;
51
+ };
52
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;GAEG;AACH,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC;;GAEG;AACH,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B;;GAEG;AACH,oBAAY,UAAU;IACpB,EAAE,MAAM;IACR,OAAO,MAAM;IACb,WAAW,MAAM;IACjB,YAAY,MAAM;IAClB,gBAAgB,MAAM;IACtB,SAAS,MAAM;IACf,SAAS,MAAM;IACf,qBAAqB,MAAM;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE;KACpB,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,WAAW;CA0LnC,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;CAKvB,CAAC"}
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KVStoreKeys = exports.NETWORKS = exports.HttpStatus = exports.DEFAULT_TX_ID = exports.DEFAULT_USE_SSL = exports.DEFAULT_PORT = exports.DEFAULT_REGION = exports.DEFAULT_ENDPOINT = exports.DEFAULT_PUBLIC_BUCKET = void 0;
4
+ const enums_1 = require("./enums");
5
+ /**
6
+ * @constant Default public bucket name
7
+ */
8
+ exports.DEFAULT_PUBLIC_BUCKET = 'escrow-public-results';
9
+ /**
10
+ * @constant Default storage endpoint
11
+ */
12
+ exports.DEFAULT_ENDPOINT = 'localhost';
13
+ /**
14
+ * @constant Default storage region
15
+ */
16
+ exports.DEFAULT_REGION = 'eu';
17
+ /**
18
+ * @constant Default storage port
19
+ */
20
+ exports.DEFAULT_PORT = 9000;
21
+ /**
22
+ * @constant Default storage port
23
+ */
24
+ exports.DEFAULT_USE_SSL = false;
25
+ /**
26
+ * @constant Default tx Id
27
+ */
28
+ exports.DEFAULT_TX_ID = 1;
29
+ /**
30
+ * @constant Default Enum for escrow statuses.
31
+ */
32
+ var HttpStatus;
33
+ (function (HttpStatus) {
34
+ HttpStatus[HttpStatus["OK"] = 200] = "OK";
35
+ HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
36
+ HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
37
+ HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
38
+ HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
39
+ HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
40
+ HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
41
+ HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
42
+ })(HttpStatus = exports.HttpStatus || (exports.HttpStatus = {}));
43
+ /**
44
+ * @constant Default network parameters
45
+ */
46
+ exports.NETWORKS = {
47
+ [enums_1.ChainId.MAINNET]: {
48
+ chainId: enums_1.ChainId.MAINNET,
49
+ title: 'Ethereum',
50
+ scanUrl: 'https://etherscan.io',
51
+ factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
52
+ hmtAddress: '0xd1ba9BAC957322D6e8c07a160a3A8dA11A0d2867',
53
+ stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
54
+ rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
55
+ kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
56
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v1',
57
+ oldSubgraphUrl: '',
58
+ oldFactoryAddress: '',
59
+ },
60
+ [enums_1.ChainId.RINKEBY]: {
61
+ chainId: enums_1.ChainId.RINKEBY,
62
+ title: 'Ethereum Rinkeby',
63
+ scanUrl: 'https://rinkeby.etherscan.io',
64
+ factoryAddress: '0x925B24444511c86F4d4E63141D8Be0A025E2dca4',
65
+ hmtAddress: '0x4dCf5ac4509888714dd43A5cCc46d7ab389D9c23',
66
+ stakingAddress: '',
67
+ rewardPoolAddress: '',
68
+ kvstoreAddress: '',
69
+ subgraphUrl: '',
70
+ oldSubgraphUrl: '',
71
+ oldFactoryAddress: '',
72
+ },
73
+ [enums_1.ChainId.GOERLI]: {
74
+ chainId: enums_1.ChainId.GOERLI,
75
+ title: 'Ethereum Goerli',
76
+ scanUrl: 'https://goerli.etherscan.io',
77
+ factoryAddress: '0x87469B4f2Fcf37cBd34E54244c0BD4Fa0603664c',
78
+ hmtAddress: '0xd3A31D57FDD790725d0F6B78095F62E8CD4ab317',
79
+ stakingAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
80
+ rewardPoolAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
81
+ kvstoreAddress: '0xc9Fe39c4b6e1d7A2991355Af159956982DADf842',
82
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v1',
83
+ oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli',
84
+ oldFactoryAddress: '0xaAe6a2646C1F88763E62e0cD08aD050Ea66AC46F',
85
+ },
86
+ [enums_1.ChainId.BSC_MAINNET]: {
87
+ chainId: enums_1.ChainId.BSC_MAINNET,
88
+ title: 'Binance Smart Chain',
89
+ scanUrl: 'https://bscscan.com',
90
+ factoryAddress: '0x92FD968AcBd521c232f5fB8c33b342923cC72714',
91
+ hmtAddress: '0x711Fd6ab6d65A98904522d4e3586F492B989c527',
92
+ stakingAddress: '0xdFbB79dC35a3A53741be54a2C9b587d6BafAbd1C',
93
+ rewardPoolAddress: '0xf376443BCc6d4d4D63eeC086bc4A9E4a83878e0e',
94
+ kvstoreAddress: '0x2B95bEcb6EBC4589f64CB000dFCF716b4aeF8aA6',
95
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v1',
96
+ oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
97
+ oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
98
+ },
99
+ [enums_1.ChainId.BSC_TESTNET]: {
100
+ chainId: enums_1.ChainId.BSC_TESTNET,
101
+ title: 'Binance Smart Chain (Testnet)',
102
+ scanUrl: 'https://testnet.bscscan.com',
103
+ factoryAddress: '0x2bfA592DBDaF434DDcbb893B1916120d181DAD18',
104
+ hmtAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
105
+ stakingAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18',
106
+ rewardPoolAddress: '0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29',
107
+ kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4',
108
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v1',
109
+ oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
110
+ oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
111
+ },
112
+ [enums_1.ChainId.POLYGON]: {
113
+ chainId: enums_1.ChainId.POLYGON,
114
+ title: 'Polygon',
115
+ scanUrl: 'https://polygonscan.com',
116
+ factoryAddress: '0xBDBfD2cC708199C5640C6ECdf3B0F4A4C67AdfcB',
117
+ hmtAddress: '0xc748B2A084F8eFc47E086ccdDD9b7e67aEb571BF',
118
+ stakingAddress: '0xcbAd56bE3f504E98bd70875823d3CC0242B7bB29',
119
+ rewardPoolAddress: '0xa8e32d777a3839440cc7c24D591A64B9481753B3',
120
+ kvstoreAddress: '0x35Cf4beBD58F9C8D75B9eA2599479b6C173d406F',
121
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v1',
122
+ oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
123
+ oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
124
+ },
125
+ [enums_1.ChainId.POLYGON_MUMBAI]: {
126
+ chainId: enums_1.ChainId.POLYGON_MUMBAI,
127
+ title: 'Polygon Mumbai',
128
+ scanUrl: 'https://mumbai.polygonscan.com',
129
+ factoryAddress: '0xA8D927C4DA17A6b71675d2D49dFda4E9eBE58f2d',
130
+ hmtAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
131
+ stakingAddress: '0x7Fd3dF914E7b6Bd96B4c744Df32183b51368Bfac',
132
+ rewardPoolAddress: '0xf0145eD99AC3c4f877aDa7dA4D1E059ec9116BAE',
133
+ kvstoreAddress: '0xD7F61E812e139a5a02eDae9Dfec146E1b8eA3807',
134
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v1',
135
+ oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai',
136
+ oldFactoryAddress: '0x558cd800f9F0B02f3B149667bDe003284c867E94',
137
+ },
138
+ [enums_1.ChainId.MOONBEAM]: {
139
+ chainId: enums_1.ChainId.MOONBEAM,
140
+ title: 'Moonbeam',
141
+ scanUrl: 'https://moonbeam.moonscan.io',
142
+ factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
143
+ hmtAddress: '0x3b25BC1dC591D24d60560d0135D6750A561D4764',
144
+ stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
145
+ rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
146
+ kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
147
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v1',
148
+ oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam',
149
+ oldFactoryAddress: '0x98108c28B7767a52BE38B4860832dd4e11A7ecad',
150
+ },
151
+ [enums_1.ChainId.MOONBASE_ALPHA]: {
152
+ chainId: enums_1.ChainId.MOONBASE_ALPHA,
153
+ title: 'Moonbase Alpha',
154
+ scanUrl: 'https://moonbase.moonscan.io/',
155
+ factoryAddress: '0x5e622FF522D81aa426f082bDD95210BC25fCA7Ed',
156
+ hmtAddress: '0x2dd72db2bBA65cE663e476bA8b84A1aAF802A8e3',
157
+ stakingAddress: '0xBFC7009F3371F93F3B54DdC8caCd02914a37495c',
158
+ rewardPoolAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
159
+ kvstoreAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
160
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v1',
161
+ oldSubgraphUrl: '',
162
+ oldFactoryAddress: '',
163
+ },
164
+ [enums_1.ChainId.AVALANCHE_TESTNET]: {
165
+ chainId: enums_1.ChainId.AVALANCHE_TESTNET,
166
+ title: 'Fuji C-Chain',
167
+ scanUrl: 'https://testnet.snowtrace.io',
168
+ factoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88',
169
+ hmtAddress: '0x9406d5c635AD22b0d76c75E52De57A2177919ca3',
170
+ stakingAddress: '',
171
+ rewardPoolAddress: '',
172
+ kvstoreAddress: '0xd232c1426CF0653cE8a71DC98bCfDf10c471c114',
173
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji',
174
+ oldSubgraphUrl: '',
175
+ oldFactoryAddress: '',
176
+ },
177
+ [enums_1.ChainId.AVALANCHE]: {
178
+ chainId: enums_1.ChainId.AVALANCHE,
179
+ title: 'Avalanche C-Chain Mainnet',
180
+ scanUrl: 'https://snowtrace.io',
181
+ factoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4',
182
+ hmtAddress: '0x12365293cb6477d4fc2686e46BB97E3Fb64f1550',
183
+ stakingAddress: '',
184
+ rewardPoolAddress: '',
185
+ kvstoreAddress: '0x4B79eaD28F52eD5686bf0e379717e85fc7aD10Df',
186
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche',
187
+ oldSubgraphUrl: '',
188
+ oldFactoryAddress: '',
189
+ },
190
+ [enums_1.ChainId.SKALE]: {
191
+ chainId: enums_1.ChainId.SKALE,
192
+ title: 'SKALE Human Protocol Chain',
193
+ scanUrl: 'https://wan-red-ain.explorer.mainnet.skalenodes.com/',
194
+ factoryAddress: '0x319070b49C8d1cC015915D1E7Eb5fd8e22833885',
195
+ hmtAddress: '0x6E5FF61Ea88270F6142E0E0eC8cbe9d67476CbCd',
196
+ stakingAddress: '0x79F37FB9C210910733c16228AC4D14a8e32C11BD',
197
+ rewardPoolAddress: '0x881218246c25C6898aE96145259584340153aDA2',
198
+ kvstoreAddress: '0xE1055607327b1be2080D31211dCDC4D9338CaF4A',
199
+ subgraphUrl: 'https://graph-skale.humanprotocol.org/subgraphs/name/skale-human',
200
+ oldSubgraphUrl: '',
201
+ oldFactoryAddress: '0x27B423cE73d1dBdB48d2dd351398b5Ce8223117c',
202
+ },
203
+ [enums_1.ChainId.LOCALHOST]: {
204
+ chainId: enums_1.ChainId.LOCALHOST,
205
+ title: 'Localhost',
206
+ scanUrl: '',
207
+ factoryAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
208
+ hmtAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
209
+ stakingAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
210
+ rewardPoolAddress: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853',
211
+ kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
212
+ subgraphUrl: '',
213
+ oldSubgraphUrl: '',
214
+ oldFactoryAddress: '',
215
+ },
216
+ };
217
+ exports.KVStoreKeys = {
218
+ role: 'role',
219
+ webhook_url: 'webhook_url',
220
+ fee: 'fee',
221
+ public_key: 'public_key',
222
+ };
@@ -0,0 +1,2 @@
1
+ export declare function requiresSigner(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
2
+ //# sourceMappingURL=decorators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAIA,wBAAgB,cAAc,CAC5B,MAAM,EAAE,GAAG,EACX,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,sBAa/B"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requiresSigner = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const ethers_1 = require("ethers");
6
+ const error_1 = require("./error");
7
+ function requiresSigner(target, propertyKey, descriptor) {
8
+ const originalMethod = descriptor.value;
9
+ descriptor.value = async function (...args) {
10
+ if (!ethers_1.Signer.isSigner(this.signerOrProvider)) {
11
+ throw error_1.ErrorSigner;
12
+ }
13
+ return originalMethod.apply(this, args);
14
+ };
15
+ return descriptor;
16
+ }
17
+ exports.requiresSigner = requiresSigner;
@@ -0,0 +1,84 @@
1
+ import * as openpgp from 'openpgp';
2
+ import { IKeyPair } from './interfaces';
3
+ /**
4
+ * Class for encryption and decryption operations.
5
+ */
6
+ export declare class Encryption {
7
+ private privateKey;
8
+ /**
9
+ * Constructor for the Encryption class.
10
+ *
11
+ * @param {PrivateKey} privateKey - The private key.
12
+ */
13
+ constructor(privateKey: openpgp.PrivateKey);
14
+ /**
15
+ * Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase.
16
+ *
17
+ * @param {string} privateKeyArmored - The encrypted private key in armored format.
18
+ * @param {string} passphrase - Optional: The passphrase for the private key.
19
+ * @returns {Promise<Encryption>} - The Encryption instance.
20
+ */
21
+ static build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>;
22
+ /**
23
+ * Signs and encrypts a message using the specified public keys.
24
+ *
25
+ * @param {string} message - The message to encrypt.
26
+ * @param {string[]} publicKeys - The public keys in armored format.
27
+ * @returns {Promise<string>} - The encrypted message.
28
+ */
29
+ signAndEncrypt(message: string, publicKeys: string[]): Promise<string>;
30
+ /**
31
+ * Decrypts an encrypted message using the private key.
32
+ *
33
+ * @param {string} message - The encrypted message.
34
+ * @param {string} publicKey - Optional: The public key in armored format for signature verification.
35
+ * @returns {Promise<string>} - The decrypted message.
36
+ */
37
+ decrypt(message: string, publicKey?: string): Promise<string>;
38
+ /**
39
+ * Signs a message using the private key.
40
+ *
41
+ * @param {string} message - The message to sign.
42
+ * @returns {Promise<string>} - The signed message.
43
+ */
44
+ sign(message: string): Promise<string>;
45
+ }
46
+ /**
47
+ * Utility class for encryption-related operations.
48
+ */
49
+ export declare class EncryptionUtils {
50
+ /**
51
+ * Verifies the signature of a signed message using the public key.
52
+ *
53
+ * @param {string} message - The signed message.
54
+ * @param {string} publicKey - The public key in armored format.
55
+ * @returns {Promise<boolean>} - A boolean indicating if the signature is valid.
56
+ */
57
+ static verify(message: string, publicKey: string): Promise<boolean>;
58
+ /**
59
+ * Gets the signed data from a signed message.
60
+ *
61
+ * @param {string} message - The signed message.
62
+ * @returns {Promise<string>} - The signed data.
63
+ * @throws {Error} - An error object if an error occurred.
64
+ */
65
+ static getSignedData(message: string): Promise<string>;
66
+ /**
67
+ * Generates a key pair for encryption and decryption.
68
+ *
69
+ * @param {string} name - The name for the key pair.
70
+ * @param {string} email - The email for the key pair.
71
+ * @param {string} passphrase - The passphrase used to encrypt the private key.
72
+ * @returns {Promise<IKeyPair>} - The generated key pair.
73
+ */
74
+ static generateKeyPair(name: string, email: string, passphrase?: string): Promise<IKeyPair>;
75
+ /**
76
+ * Encrypts a message using the specified public keys.
77
+ *
78
+ * @param {string} message - The message to encrypt.
79
+ * @param {string[]} publicKeys - The public keys in armored format.
80
+ * @returns {Promise<string>} - The encrypted message.
81
+ */
82
+ static encrypt(message: string, publicKeys: string[]): Promise<string>;
83
+ }
84
+ //# sourceMappingURL=encryption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../src/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAqB;IAEvC;;;;OAIG;gBACS,UAAU,EAAE,OAAO,CAAC,UAAU;IAI1C;;;;;;OAMG;WACiB,KAAK,CACvB,iBAAiB,EAAE,MAAM,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC;IAkBtB;;;;;;OAMG;IACU,cAAc,CACzB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,CAAC;IAiBlB;;;;;;OAMG;IACU,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB1E;;;;;OAKG;IACU,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYpD;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B;;;;;;OAMG;WACiB,MAAM,CACxB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IAgBnB;;;;;;OAMG;WACiB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAYnE;;;;;;;OAOG;WACiB,eAAe,CACjC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,SAAK,GACd,OAAO,CAAC,QAAQ,CAAC;IAkBpB;;;;;;OAMG;WACiB,OAAO,CACzB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,CAAC;CAenB"}
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.EncryptionUtils = exports.Encryption = void 0;
27
+ const openpgp = __importStar(require("openpgp"));
28
+ /**
29
+ * Class for encryption and decryption operations.
30
+ */
31
+ class Encryption {
32
+ /**
33
+ * Constructor for the Encryption class.
34
+ *
35
+ * @param {PrivateKey} privateKey - The private key.
36
+ */
37
+ constructor(privateKey) {
38
+ this.privateKey = privateKey;
39
+ }
40
+ /**
41
+ * Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase.
42
+ *
43
+ * @param {string} privateKeyArmored - The encrypted private key in armored format.
44
+ * @param {string} passphrase - Optional: The passphrase for the private key.
45
+ * @returns {Promise<Encryption>} - The Encryption instance.
46
+ */
47
+ static async build(privateKeyArmored, passphrase) {
48
+ const options = {
49
+ armoredKey: privateKeyArmored,
50
+ };
51
+ if (!passphrase) {
52
+ return new Encryption(await openpgp.readPrivateKey(options));
53
+ }
54
+ const privateKey = await openpgp.readPrivateKey(options);
55
+ return new Encryption(await openpgp.decryptKey({
56
+ privateKey,
57
+ passphrase,
58
+ }));
59
+ }
60
+ /**
61
+ * Signs and encrypts a message using the specified public keys.
62
+ *
63
+ * @param {string} message - The message to encrypt.
64
+ * @param {string[]} publicKeys - The public keys in armored format.
65
+ * @returns {Promise<string>} - The encrypted message.
66
+ */
67
+ async signAndEncrypt(message, publicKeys) {
68
+ const plaintext = message;
69
+ const pgpPublicKeys = await Promise.all(publicKeys.map((armoredKey) => openpgp.readKey({ armoredKey })));
70
+ const pgpMessage = await openpgp.createMessage({ text: plaintext });
71
+ const encrypted = await openpgp.encrypt({
72
+ message: pgpMessage,
73
+ encryptionKeys: pgpPublicKeys,
74
+ signingKeys: this.privateKey,
75
+ });
76
+ return encrypted;
77
+ }
78
+ /**
79
+ * Decrypts an encrypted message using the private key.
80
+ *
81
+ * @param {string} message - The encrypted message.
82
+ * @param {string} publicKey - Optional: The public key in armored format for signature verification.
83
+ * @returns {Promise<string>} - The decrypted message.
84
+ */
85
+ async decrypt(message, publicKey) {
86
+ const pgpMessage = await openpgp.readMessage({ armoredMessage: message });
87
+ const decryptionOptions = {
88
+ message: pgpMessage,
89
+ decryptionKeys: this.privateKey,
90
+ expectSigned: !!publicKey,
91
+ };
92
+ if (publicKey) {
93
+ const pgpPublicKey = await openpgp.readKey({ armoredKey: publicKey });
94
+ decryptionOptions.verificationKeys = pgpPublicKey;
95
+ }
96
+ const { data: decrypted } = await openpgp.decrypt(decryptionOptions);
97
+ return decrypted;
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
+ async sign(message) {
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
+ return cleartextMessage;
115
+ }
116
+ }
117
+ exports.Encryption = Encryption;
118
+ /**
119
+ * Utility class for encryption-related operations.
120
+ */
121
+ class EncryptionUtils {
122
+ /**
123
+ * Verifies the signature of a signed message using the public key.
124
+ *
125
+ * @param {string} message - The signed message.
126
+ * @param {string} publicKey - The public key in armored format.
127
+ * @returns {Promise<boolean>} - A boolean indicating if the signature is valid.
128
+ */
129
+ static async verify(message, publicKey) {
130
+ const pgpPublicKey = await openpgp.readKey({ armoredKey: publicKey });
131
+ const signedMessage = await openpgp.readCleartextMessage({
132
+ cleartextMessage: message,
133
+ });
134
+ const verificationResult = await signedMessage.verify([pgpPublicKey]);
135
+ const { verified } = verificationResult[0];
136
+ try {
137
+ return await verified;
138
+ }
139
+ catch {
140
+ return false;
141
+ }
142
+ }
143
+ /**
144
+ * Gets the signed data from a signed message.
145
+ *
146
+ * @param {string} message - The signed message.
147
+ * @returns {Promise<string>} - The signed data.
148
+ * @throws {Error} - An error object if an error occurred.
149
+ */
150
+ static async getSignedData(message) {
151
+ const signedMessage = await openpgp.readCleartextMessage({
152
+ cleartextMessage: message,
153
+ });
154
+ try {
155
+ return signedMessage.getText();
156
+ }
157
+ catch (e) {
158
+ throw new Error('Could not get data: ' + e.message);
159
+ }
160
+ }
161
+ /**
162
+ * Generates a key pair for encryption and decryption.
163
+ *
164
+ * @param {string} name - The name for the key pair.
165
+ * @param {string} email - The email for the key pair.
166
+ * @param {string} passphrase - The passphrase used to encrypt the private key.
167
+ * @returns {Promise<IKeyPair>} - The generated key pair.
168
+ */
169
+ static async generateKeyPair(name, email, passphrase = '') {
170
+ const { privateKey, publicKey, revocationCertificate } = await openpgp.generateKey({
171
+ type: 'ecc',
172
+ curve: 'ed25519',
173
+ userIDs: [{ name: name, email: email }],
174
+ passphrase: passphrase,
175
+ format: 'armored',
176
+ });
177
+ return {
178
+ passphrase: passphrase,
179
+ privateKey,
180
+ publicKey,
181
+ revocationCertificate,
182
+ };
183
+ }
184
+ /**
185
+ * Encrypts a message using the specified public keys.
186
+ *
187
+ * @param {string} message - The message to encrypt.
188
+ * @param {string[]} publicKeys - The public keys in armored format.
189
+ * @returns {Promise<string>} - The encrypted message.
190
+ */
191
+ static async encrypt(message, publicKeys) {
192
+ const plaintext = message;
193
+ const pgpPublicKeys = await Promise.all(publicKeys.map((armoredKey) => openpgp.readKey({ armoredKey })));
194
+ const pgpMessage = await openpgp.createMessage({ text: plaintext });
195
+ const encrypted = await openpgp.encrypt({
196
+ message: pgpMessage,
197
+ encryptionKeys: pgpPublicKeys,
198
+ });
199
+ return encrypted;
200
+ }
201
+ }
202
+ exports.EncryptionUtils = EncryptionUtils;