@human-protocol/sdk 1.1.5 → 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 (48) hide show
  1. package/README.md +80 -1
  2. package/dist/constants.d.ts +6 -0
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +24 -5
  5. package/dist/encryption.d.ts +84 -0
  6. package/dist/encryption.d.ts.map +1 -0
  7. package/dist/encryption.js +202 -0
  8. package/dist/error.d.ts +2 -2
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +3 -3
  11. package/dist/escrow.d.ts +32 -15
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +74 -37
  14. package/dist/index.d.ts +6 -6
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +10 -14
  17. package/dist/interfaces.d.ts +10 -12
  18. package/dist/interfaces.d.ts.map +1 -1
  19. package/dist/kvstore.d.ts +19 -8
  20. package/dist/kvstore.d.ts.map +1 -1
  21. package/dist/kvstore.js +38 -9
  22. package/dist/queries.d.ts +3 -2
  23. package/dist/queries.d.ts.map +1 -1
  24. package/dist/queries.js +4 -7
  25. package/dist/staking.d.ts +16 -7
  26. package/dist/staking.d.ts.map +1 -1
  27. package/dist/staking.js +40 -12
  28. package/dist/storage.d.ts +2 -1
  29. package/dist/storage.d.ts.map +1 -1
  30. package/dist/storage.js +9 -3
  31. package/dist/types.d.ts +8 -0
  32. package/dist/types.d.ts.map +1 -1
  33. package/package.json +2 -1
  34. package/src/constants.ts +24 -5
  35. package/src/encryption.ts +223 -0
  36. package/src/error.ts +2 -4
  37. package/src/escrow.ts +112 -70
  38. package/src/index.ts +6 -12
  39. package/src/interfaces.ts +10 -13
  40. package/src/kvstore.ts +51 -14
  41. package/src/queries.ts +15 -7
  42. package/src/staking.ts +60 -24
  43. package/src/storage.ts +14 -3
  44. package/src/types.ts +8 -0
  45. package/dist/init.d.ts +0 -13
  46. package/dist/init.d.ts.map +0 -1
  47. package/dist/init.js +0 -35
  48. 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
+ ```
@@ -43,4 +43,10 @@ export declare enum HttpStatus {
43
43
  export declare const NETWORKS: {
44
44
  [chainId in ChainId]?: NetworkData;
45
45
  };
46
+ export declare const KVStoreKeys: {
47
+ role: string;
48
+ webhook_url: string;
49
+ fee: string;
50
+ public_key: string;
51
+ };
46
52
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +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;CA8KnC,CAAC"}
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"}
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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;
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
4
  const enums_1 = require("./enums");
5
5
  /**
6
6
  * @constant Default public bucket name
@@ -51,6 +51,7 @@ exports.NETWORKS = {
51
51
  factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
52
52
  hmtAddress: '0xd1ba9BAC957322D6e8c07a160a3A8dA11A0d2867',
53
53
  stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
54
+ rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
54
55
  kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
55
56
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v1',
56
57
  oldSubgraphUrl: '',
@@ -63,6 +64,7 @@ exports.NETWORKS = {
63
64
  factoryAddress: '0x925B24444511c86F4d4E63141D8Be0A025E2dca4',
64
65
  hmtAddress: '0x4dCf5ac4509888714dd43A5cCc46d7ab389D9c23',
65
66
  stakingAddress: '',
67
+ rewardPoolAddress: '',
66
68
  kvstoreAddress: '',
67
69
  subgraphUrl: '',
68
70
  oldSubgraphUrl: '',
@@ -75,6 +77,7 @@ exports.NETWORKS = {
75
77
  factoryAddress: '0x87469B4f2Fcf37cBd34E54244c0BD4Fa0603664c',
76
78
  hmtAddress: '0xd3A31D57FDD790725d0F6B78095F62E8CD4ab317',
77
79
  stakingAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
80
+ rewardPoolAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
78
81
  kvstoreAddress: '0xc9Fe39c4b6e1d7A2991355Af159956982DADf842',
79
82
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v1',
80
83
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli',
@@ -84,10 +87,11 @@ exports.NETWORKS = {
84
87
  chainId: enums_1.ChainId.BSC_MAINNET,
85
88
  title: 'Binance Smart Chain',
86
89
  scanUrl: 'https://bscscan.com',
87
- factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
88
- hmtAddress: '0x0d501B743F22b641B8C8dfe00F1AAb881D57DDC7',
89
- stakingAddress: '0xC2163A0928034e020f0d31e1171Ba0D6d9AfFB6c',
90
- kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
90
+ factoryAddress: '0x92FD968AcBd521c232f5fB8c33b342923cC72714',
91
+ hmtAddress: '0x711Fd6ab6d65A98904522d4e3586F492B989c527',
92
+ stakingAddress: '0xdFbB79dC35a3A53741be54a2C9b587d6BafAbd1C',
93
+ rewardPoolAddress: '0xf376443BCc6d4d4D63eeC086bc4A9E4a83878e0e',
94
+ kvstoreAddress: '0x2B95bEcb6EBC4589f64CB000dFCF716b4aeF8aA6',
91
95
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v1',
92
96
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
93
97
  oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
@@ -99,6 +103,7 @@ exports.NETWORKS = {
99
103
  factoryAddress: '0x2bfA592DBDaF434DDcbb893B1916120d181DAD18',
100
104
  hmtAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
101
105
  stakingAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18',
106
+ rewardPoolAddress: '0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29',
102
107
  kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4',
103
108
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v1',
104
109
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
@@ -111,6 +116,7 @@ exports.NETWORKS = {
111
116
  factoryAddress: '0xBDBfD2cC708199C5640C6ECdf3B0F4A4C67AdfcB',
112
117
  hmtAddress: '0xc748B2A084F8eFc47E086ccdDD9b7e67aEb571BF',
113
118
  stakingAddress: '0xcbAd56bE3f504E98bd70875823d3CC0242B7bB29',
119
+ rewardPoolAddress: '0xa8e32d777a3839440cc7c24D591A64B9481753B3',
114
120
  kvstoreAddress: '0x35Cf4beBD58F9C8D75B9eA2599479b6C173d406F',
115
121
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v1',
116
122
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
@@ -123,6 +129,7 @@ exports.NETWORKS = {
123
129
  factoryAddress: '0xA8D927C4DA17A6b71675d2D49dFda4E9eBE58f2d',
124
130
  hmtAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
125
131
  stakingAddress: '0x7Fd3dF914E7b6Bd96B4c744Df32183b51368Bfac',
132
+ rewardPoolAddress: '0xf0145eD99AC3c4f877aDa7dA4D1E059ec9116BAE',
126
133
  kvstoreAddress: '0xD7F61E812e139a5a02eDae9Dfec146E1b8eA3807',
127
134
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v1',
128
135
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai',
@@ -135,6 +142,7 @@ exports.NETWORKS = {
135
142
  factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
136
143
  hmtAddress: '0x3b25BC1dC591D24d60560d0135D6750A561D4764',
137
144
  stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
145
+ rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
138
146
  kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
139
147
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v1',
140
148
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam',
@@ -147,6 +155,7 @@ exports.NETWORKS = {
147
155
  factoryAddress: '0x5e622FF522D81aa426f082bDD95210BC25fCA7Ed',
148
156
  hmtAddress: '0x2dd72db2bBA65cE663e476bA8b84A1aAF802A8e3',
149
157
  stakingAddress: '0xBFC7009F3371F93F3B54DdC8caCd02914a37495c',
158
+ rewardPoolAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
150
159
  kvstoreAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
151
160
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v1',
152
161
  oldSubgraphUrl: '',
@@ -159,6 +168,7 @@ exports.NETWORKS = {
159
168
  factoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88',
160
169
  hmtAddress: '0x9406d5c635AD22b0d76c75E52De57A2177919ca3',
161
170
  stakingAddress: '',
171
+ rewardPoolAddress: '',
162
172
  kvstoreAddress: '0xd232c1426CF0653cE8a71DC98bCfDf10c471c114',
163
173
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji',
164
174
  oldSubgraphUrl: '',
@@ -171,6 +181,7 @@ exports.NETWORKS = {
171
181
  factoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4',
172
182
  hmtAddress: '0x12365293cb6477d4fc2686e46BB97E3Fb64f1550',
173
183
  stakingAddress: '',
184
+ rewardPoolAddress: '',
174
185
  kvstoreAddress: '0x4B79eaD28F52eD5686bf0e379717e85fc7aD10Df',
175
186
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche',
176
187
  oldSubgraphUrl: '',
@@ -183,6 +194,7 @@ exports.NETWORKS = {
183
194
  factoryAddress: '0x319070b49C8d1cC015915D1E7Eb5fd8e22833885',
184
195
  hmtAddress: '0x6E5FF61Ea88270F6142E0E0eC8cbe9d67476CbCd',
185
196
  stakingAddress: '0x79F37FB9C210910733c16228AC4D14a8e32C11BD',
197
+ rewardPoolAddress: '0x881218246c25C6898aE96145259584340153aDA2',
186
198
  kvstoreAddress: '0xE1055607327b1be2080D31211dCDC4D9338CaF4A',
187
199
  subgraphUrl: 'https://graph-skale.humanprotocol.org/subgraphs/name/skale-human',
188
200
  oldSubgraphUrl: '',
@@ -195,9 +207,16 @@ exports.NETWORKS = {
195
207
  factoryAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
196
208
  hmtAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
197
209
  stakingAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
210
+ rewardPoolAddress: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853',
198
211
  kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
199
212
  subgraphUrl: '',
200
213
  oldSubgraphUrl: '',
201
214
  oldFactoryAddress: '',
202
215
  },
203
216
  };
217
+ exports.KVStoreKeys = {
218
+ role: 'role',
219
+ webhook_url: 'webhook_url',
220
+ fee: 'fee',
221
+ public_key: 'public_key',
222
+ };
@@ -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;
package/dist/error.d.ts CHANGED
@@ -90,11 +90,11 @@ export declare const ErrorHMTokenAmountNotApproved: Error;
90
90
  /**
91
91
  * @constant {Error} - Init provider does not exists.
92
92
  */
93
- export declare const ErrorInitProviderDoesNotExist: Error;
93
+ export declare const ErrorProviderDoesNotExist: Error;
94
94
  /**
95
95
  * @constant {Error} - Init with unsupported chain ID.
96
96
  */
97
- export declare const ErrorInitUnsupportedChainID: Error;
97
+ export declare const ErrorUnsupportedChainID: Error;
98
98
  /**
99
99
  * @constant {Error} - Sending a transaction requires a signer.
100
100
  */
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,mBAAmB,OAA2C,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,gCAAgC,OAE5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,OAEvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8B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,MAAM;CAG5B;AAED,qBAAa,oBAAqB,SAAQ,aAAa;gBACzC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,aAAc,SAAQ,aAAa;gBAClC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;gBAC1C,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,sBAAuB,SAAQ,aAAa;gBAC3C,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,YAAa,SAAQ,aAAa;gBACjC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,YAAa,SAAQ,aAAa;gBACjC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,sBAAuB,SAAQ,aAAa;gBAC3C,MAAM,EAAE,MAAM;CAG3B;AAED,qBAAa,2BAA4B,SAAQ,KAAK;gBACxC,OAAO,EAAE,MAAM;CAG5B"}
package/dist/error.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransactionReplaced = exports.NonceExpired = exports.NumericFault = exports.ReplacementUnderpriced = exports.UnpredictableGasLimit = exports.OutOfGasError = exports.InvalidArgumentError = exports.EthereumError = exports.ErrorHashIsEmptyString = exports.ErrorLaunchedEventIsNotEmitted = exports.ErrorRecipientAndAmountsMustBeSameLength = exports.ErrorAmountsCannotBeEmptyArray = exports.ErrorEscrowDoesNotHaveEnoughBalance = exports.ErrorAmountMustBeGreaterThanZero = exports.ErrorRecipientCannotBeEmptyArray = exports.ErrorTotalFeeMustBeLessThanHundred = exports.ErrorFeeMustBeBetweenZeroAndHundred = exports.ErrorNoURLprovided = exports.ErrorListOfHandlersCannotBeEmpty = exports.ErrorUrlIsEmptyString = exports.ErrorInvalidUrl = exports.ErrorStorageClientDoesNotExist = exports.ErrorManifestFileDoesNotExist = exports.ErrorEscrowAddressIsNotProvidedByFactory = exports.ErrorSigner = exports.ErrorInitUnsupportedChainID = exports.ErrorInitProviderDoesNotExist = exports.ErrorHMTokenAmountNotApproved = exports.ErrorFailedToCheckAllowance = exports.ErrorFailedToApproveStakingAmountSignerDoesNotExist = exports.ErrorStakingGetStakers = exports.ErrorInvalidEscrowAddressProvided = exports.ErrorInvalidStakerAddressProvided = exports.ErrorInvalidSlasherAddressProvided = exports.ErrorInvalidStakingValueSign = exports.ErrorInvalidStakingValueType = exports.ErrorStakingValueMustBePositive = exports.ErrorInvalidReputationOracleAddressProvided = exports.ErrorInvalidRecordingOracleAddressProvided = exports.ErrorInvalidTokenAddress = exports.ErrorInvalidAddress = exports.ErrorKVStoreArrayLength = exports.ErrorKVStoreEmptyKey = exports.ErrorStorageFileNotUploaded = exports.ErrorStorageFileNotFound = exports.ErrorStorageBucketNotFound = exports.ErrorStorageCredentialsMissing = exports.ErrorStorageClientNotExists = exports.ErrorStorageClientNotInitialized = exports.ErrorStakingMissing = void 0;
3
+ exports.TransactionReplaced = exports.NonceExpired = exports.NumericFault = exports.ReplacementUnderpriced = exports.UnpredictableGasLimit = exports.OutOfGasError = exports.InvalidArgumentError = exports.EthereumError = exports.ErrorHashIsEmptyString = exports.ErrorLaunchedEventIsNotEmitted = exports.ErrorRecipientAndAmountsMustBeSameLength = exports.ErrorAmountsCannotBeEmptyArray = exports.ErrorEscrowDoesNotHaveEnoughBalance = exports.ErrorAmountMustBeGreaterThanZero = exports.ErrorRecipientCannotBeEmptyArray = exports.ErrorTotalFeeMustBeLessThanHundred = exports.ErrorFeeMustBeBetweenZeroAndHundred = exports.ErrorNoURLprovided = exports.ErrorListOfHandlersCannotBeEmpty = exports.ErrorUrlIsEmptyString = exports.ErrorInvalidUrl = exports.ErrorStorageClientDoesNotExist = exports.ErrorManifestFileDoesNotExist = exports.ErrorEscrowAddressIsNotProvidedByFactory = exports.ErrorSigner = exports.ErrorUnsupportedChainID = exports.ErrorProviderDoesNotExist = exports.ErrorHMTokenAmountNotApproved = exports.ErrorFailedToCheckAllowance = exports.ErrorFailedToApproveStakingAmountSignerDoesNotExist = exports.ErrorStakingGetStakers = exports.ErrorInvalidEscrowAddressProvided = exports.ErrorInvalidStakerAddressProvided = exports.ErrorInvalidSlasherAddressProvided = exports.ErrorInvalidStakingValueSign = exports.ErrorInvalidStakingValueType = exports.ErrorStakingValueMustBePositive = exports.ErrorInvalidReputationOracleAddressProvided = exports.ErrorInvalidRecordingOracleAddressProvided = exports.ErrorInvalidTokenAddress = exports.ErrorInvalidAddress = exports.ErrorKVStoreArrayLength = exports.ErrorKVStoreEmptyKey = exports.ErrorStorageFileNotUploaded = exports.ErrorStorageFileNotFound = exports.ErrorStorageBucketNotFound = exports.ErrorStorageCredentialsMissing = exports.ErrorStorageClientNotExists = exports.ErrorStorageClientNotInitialized = exports.ErrorStakingMissing = void 0;
4
4
  exports.InvalidEthereumAddressError = exports.ContractExecutionError = void 0;
5
5
  /**
6
6
  * @constant {Error} - The Staking contract is missing.
@@ -94,11 +94,11 @@ exports.ErrorHMTokenAmountNotApproved = new Error('Amount not approved');
94
94
  /**
95
95
  * @constant {Error} - Init provider does not exists.
96
96
  */
97
- exports.ErrorInitProviderDoesNotExist = new Error('Provider does not exist');
97
+ exports.ErrorProviderDoesNotExist = new Error('Provider does not exist');
98
98
  /**
99
99
  * @constant {Error} - Init with unsupported chain ID.
100
100
  */
101
- exports.ErrorInitUnsupportedChainID = new Error('Unsupported chain ID');
101
+ exports.ErrorUnsupportedChainID = new Error('Unsupported chain ID');
102
102
  /**
103
103
  * @constant {Error} - Sending a transaction requires a signer.
104
104
  */
package/dist/escrow.d.ts CHANGED
@@ -1,18 +1,28 @@
1
- import { BigNumber } from 'ethers';
2
- import { IClientParams, IEscrowConfig, IEscrowsFilter, ILauncherEscrowsResult } from './interfaces';
1
+ import { Provider } from '@ethersproject/abstract-provider';
2
+ import { BigNumber, Signer } from 'ethers';
3
+ import { IEscrowConfig, IEscrowsFilter } from './interfaces';
3
4
  import { EscrowStatus, NetworkData } from './types';
4
- export default class EscrowClient {
5
- readonly clientParams: IClientParams;
5
+ export declare class EscrowClient {
6
6
  private escrowFactoryContract;
7
7
  private escrowContract?;
8
8
  private signerOrProvider;
9
9
  network: NetworkData;
10
10
  /**
11
- * **Escrow constructor**
11
+ * **EscrowClient constructor**
12
12
  *
13
- * * @param {IClientParams} clientParams - Init client parameters
13
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
14
+ * @param {NetworkData} network - The network information required to connect to the Escrow contract
14
15
  */
15
- constructor(clientParams: IClientParams);
16
+ constructor(signerOrProvider: Signer | Provider, network: NetworkData);
17
+ /**
18
+ * Creates an instance of EscrowClient from a Signer or Provider.
19
+ *
20
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
21
+ * @returns {Promise<EscrowClient>} - An instance of EscrowClient
22
+ * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
23
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
24
+ */
25
+ static build(signerOrProvider: Signer | Provider): Promise<EscrowClient>;
16
26
  /**
17
27
  * Creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
18
28
  *
@@ -131,6 +141,14 @@ export default class EscrowClient {
131
141
  * @throws {Error} - An error object if an error occurred.
132
142
  */
133
143
  getResultsUrl(escrowAddress: string): Promise<string>;
144
+ /**
145
+ * Returns the intermediate results file URL.
146
+ *
147
+ * @param {string} escrowAddress - Address of the escrow.
148
+ * @returns {Promise<void>}
149
+ * @throws {Error} - An error object if an error occurred.
150
+ */
151
+ getIntermediateResultsUrl(escrowAddress: string): Promise<string>;
134
152
  /**
135
153
  * Returns the value for a specified key and address
136
154
  *
@@ -148,22 +166,21 @@ export default class EscrowClient {
148
166
  */
149
167
  getStatus(escrowAddress: string): Promise<EscrowStatus>;
150
168
  /**
151
- * Returns the current status of the escrow.
169
+ * Returns the escrow addresses created by a job requester.
152
170
  *
153
171
  * @param {IEscrowsFilter} requesterAddress - Address of the requester.
154
- * @returns {Promise<void>}
172
+ * @returns {Promise<string[]>}
155
173
  * @throws {Error} - An error object if an error occurred.
156
174
  */
157
- getLaunchedEscrows(requesterAddress: string): Promise<ILauncherEscrowsResult[]>;
175
+ getLaunchedEscrows(requesterAddress: string): Promise<string[]>;
158
176
  /**
159
- * Returns the escrows addresses created by a job requester.
177
+ * Returns the escrow addresses based on a specified filter.
160
178
  *
161
- * @param {string} escrowAddress - Address of the escrow.
162
- * @param {IEscrowsFilter} filer - Filter parameters.
163
- * @returns {Promise<void>}
179
+ * @param {IEscrowsFilter} filter - Filter parameters.
180
+ * @returns {Promise<string[]>}
164
181
  * @throws {Error} - An error object if an error occurred.
165
182
  */
166
- getEscrowsFiltered(escrowAddress: string, filter: IEscrowsFilter): Promise<ILauncherEscrowsResult[]>;
183
+ getEscrowsFiltered(filter: IEscrowsFilter): Promise<string[]>;
167
184
  /**
168
185
  * Returns the recording oracle address of given escrow
169
186
  *