@human-protocol/sdk 3.0.7 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +2 -25
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +25 -66
- package/dist/decorators.js +1 -1
- package/dist/encryption.d.ts +21 -29
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +34 -36
- package/dist/error.d.ts +31 -28
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +36 -33
- package/dist/escrow.d.ts +118 -112
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +254 -180
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +15 -7
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +0 -2
- package/dist/graphql/queries/transaction.d.ts.map +1 -1
- package/dist/graphql/queries/transaction.js +23 -10
- package/dist/graphql/types.d.ts +0 -2
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/interfaces.d.ts +29 -12
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +16 -16
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +16 -16
- package/dist/operator.d.ts +11 -10
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +36 -11
- package/dist/staking.d.ts +26 -118
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +46 -173
- package/dist/statistics.d.ts +10 -29
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +13 -30
- package/dist/storage.d.ts +13 -18
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +30 -25
- package/dist/transaction.js +1 -1
- package/dist/types.d.ts +23 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -1
- package/package.json +8 -4
- package/src/constants.ts +25 -66
- package/src/decorators.ts +1 -1
- package/src/encryption.ts +21 -29
- package/src/error.ts +39 -37
- package/src/escrow.ts +360 -216
- package/src/graphql/queries/operator.ts +15 -7
- package/src/graphql/queries/statistics.ts +0 -2
- package/src/graphql/queries/transaction.ts +23 -13
- package/src/graphql/types.ts +0 -2
- package/src/interfaces.ts +30 -13
- package/src/kvstore.ts +17 -17
- package/src/operator.ts +47 -12
- package/src/staking.ts +53 -187
- package/src/statistics.ts +13 -30
- package/src/storage.ts +13 -18
- package/src/transaction.ts +2 -2
- package/src/types.ts +24 -6
- package/src/utils.ts +0 -1
package/src/decorators.ts
CHANGED
package/src/encryption.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as openpgp from 'openpgp';
|
|
2
2
|
import { IKeyPair } from './interfaces';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Type representing the data type of a message.
|
|
6
|
+
* It can be either a string or a Uint8Array.
|
|
7
|
+
*/
|
|
4
8
|
type MessageDataType = string | Uint8Array;
|
|
5
9
|
|
|
6
10
|
function makeMessageDataBinary(message: MessageDataType): Uint8Array {
|
|
@@ -48,7 +52,7 @@ function makeMessageDataBinary(message: MessageDataType): Uint8Array {
|
|
|
48
52
|
*
|
|
49
53
|
* const privateKey = 'Armored_priv_key';
|
|
50
54
|
* const passphrase = 'example_passphrase';
|
|
51
|
-
* const
|
|
55
|
+
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
52
56
|
* ```
|
|
53
57
|
*/
|
|
54
58
|
export class Encryption {
|
|
@@ -94,7 +98,7 @@ export class Encryption {
|
|
|
94
98
|
/**
|
|
95
99
|
* This function signs and encrypts a message using the private key used to initialize the client and the specified public keys.
|
|
96
100
|
*
|
|
97
|
-
* @param {
|
|
101
|
+
* @param {MessageDataType} message Message to sign and encrypt.
|
|
98
102
|
* @param {string[]} publicKeys Array of public keys to use for encryption.
|
|
99
103
|
* @returns {Promise<string>} Message signed and encrypted.
|
|
100
104
|
*
|
|
@@ -106,7 +110,7 @@ export class Encryption {
|
|
|
106
110
|
*
|
|
107
111
|
* const privateKey = 'Armored_priv_key';
|
|
108
112
|
* const passphrase = 'example_passphrase';
|
|
109
|
-
* const
|
|
113
|
+
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
110
114
|
* const publicKey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
111
115
|
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
112
116
|
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
@@ -132,7 +136,7 @@ export class Encryption {
|
|
|
132
136
|
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
133
137
|
*
|
|
134
138
|
* const publicKeys = [publicKey1, publicKey2];
|
|
135
|
-
* const resultMessage = await
|
|
139
|
+
* const resultMessage = await encryption.signAndEncrypt('message', publicKeys);
|
|
136
140
|
* ```
|
|
137
141
|
*/
|
|
138
142
|
public async signAndEncrypt(
|
|
@@ -161,7 +165,7 @@ export class Encryption {
|
|
|
161
165
|
*
|
|
162
166
|
* @param {string} message Message to decrypt.
|
|
163
167
|
* @param {string} publicKey Public key used to verify signature if needed. This is optional.
|
|
164
|
-
* @returns {Promise<
|
|
168
|
+
* @returns {Promise<Uint8Array>} Message decrypted.
|
|
165
169
|
*
|
|
166
170
|
* **Code example**
|
|
167
171
|
*
|
|
@@ -170,7 +174,7 @@ export class Encryption {
|
|
|
170
174
|
*
|
|
171
175
|
* const privateKey = 'Armored_priv_key';
|
|
172
176
|
* const passphrase = 'example_passphrase';
|
|
173
|
-
* const
|
|
177
|
+
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
174
178
|
*
|
|
175
179
|
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
176
180
|
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
@@ -184,7 +188,7 @@ export class Encryption {
|
|
|
184
188
|
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
185
189
|
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
186
190
|
*
|
|
187
|
-
* const resultMessage = await
|
|
191
|
+
* const resultMessage = await encryption.decrypt('message');
|
|
188
192
|
* ```
|
|
189
193
|
*/
|
|
190
194
|
public async decrypt(
|
|
@@ -239,9 +243,9 @@ export class Encryption {
|
|
|
239
243
|
*
|
|
240
244
|
* const privateKey = 'Armored_priv_key';
|
|
241
245
|
* const passphrase = 'example_passphrase';
|
|
242
|
-
* const
|
|
246
|
+
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
243
247
|
*
|
|
244
|
-
* const resultMessage = await
|
|
248
|
+
* const resultMessage = await encryption.sign('message');
|
|
245
249
|
* ```
|
|
246
250
|
*/
|
|
247
251
|
public async sign(message: string): Promise<string> {
|
|
@@ -288,7 +292,7 @@ export class EncryptionUtils {
|
|
|
288
292
|
* This function verifies the signature of a signed message using the public key.
|
|
289
293
|
*
|
|
290
294
|
* @param {string} message Message to verify.
|
|
291
|
-
* @param {string} publicKey Public key to verify that the message was
|
|
295
|
+
* @param {string} publicKey Public key to verify that the message was signed by a specific source.
|
|
292
296
|
* @returns {Promise<boolean>} True if verified. False if not verified.
|
|
293
297
|
*
|
|
294
298
|
* **Code example**
|
|
@@ -308,7 +312,7 @@ export class EncryptionUtils {
|
|
|
308
312
|
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
309
313
|
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
310
314
|
*
|
|
311
|
-
* const result = await
|
|
315
|
+
* const result = await EncryptionUtils.verify('message', publicKey);
|
|
312
316
|
* ```
|
|
313
317
|
*/
|
|
314
318
|
public static async verify(
|
|
@@ -341,7 +345,7 @@ export class EncryptionUtils {
|
|
|
341
345
|
* ```ts
|
|
342
346
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
343
347
|
*
|
|
344
|
-
* const signedData = await
|
|
348
|
+
* const signedData = await EncryptionUtils.getSignedData('message');
|
|
345
349
|
* ```
|
|
346
350
|
*/
|
|
347
351
|
public static async getSignedData(message: string): Promise<string> {
|
|
@@ -369,22 +373,10 @@ export class EncryptionUtils {
|
|
|
369
373
|
* ```ts
|
|
370
374
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
371
375
|
*
|
|
372
|
-
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
373
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
374
|
-
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
375
|
-
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
376
|
-
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
377
|
-
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
378
|
-
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
379
|
-
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
380
|
-
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
381
|
-
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
382
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
383
|
-
*
|
|
384
376
|
* const name = 'YOUR_NAME';
|
|
385
377
|
* const email = 'YOUR_EMAIL';
|
|
386
378
|
* const passphrase = 'YOUR_PASSPHRASE';
|
|
387
|
-
* const result = await
|
|
379
|
+
* const result = await EncryptionUtils.generateKeyPair(name, email, passphrase);
|
|
388
380
|
* ```
|
|
389
381
|
*/
|
|
390
382
|
public static async generateKeyPair(
|
|
@@ -412,8 +404,8 @@ export class EncryptionUtils {
|
|
|
412
404
|
/**
|
|
413
405
|
* This function encrypts a message using the specified public keys.
|
|
414
406
|
*
|
|
415
|
-
* @param {
|
|
416
|
-
* @param {string}
|
|
407
|
+
* @param {MessageDataType} message Message to encrypt.
|
|
408
|
+
* @param {string[]} publicKeys Array of public keys to use for encryption.
|
|
417
409
|
* @returns {Promise<string>} Message encrypted.
|
|
418
410
|
*
|
|
419
411
|
* **Code example**
|
|
@@ -446,7 +438,7 @@ export class EncryptionUtils {
|
|
|
446
438
|
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
447
439
|
*
|
|
448
440
|
* const publicKeys = [publicKey1, publicKey2]
|
|
449
|
-
* const result = await
|
|
441
|
+
* const result = await EncryptionUtils.encrypt('message', publicKeys);
|
|
450
442
|
* ```
|
|
451
443
|
*/
|
|
452
444
|
public static async encrypt(
|
|
@@ -490,7 +482,7 @@ export class EncryptionUtils {
|
|
|
490
482
|
* =tsmI
|
|
491
483
|
* -----END PGP MESSAGE-----`;
|
|
492
484
|
*
|
|
493
|
-
* const isEncrypted = await
|
|
485
|
+
* const isEncrypted = await EncryptionUtils.isEncrypted(message);
|
|
494
486
|
*
|
|
495
487
|
* if (isEncrypted) {
|
|
496
488
|
* console.log('The message is encrypted with OpenPGP.');
|
package/src/error.ts
CHANGED
|
@@ -4,24 +4,24 @@
|
|
|
4
4
|
export const ErrorStakingMissing = new Error('Staking contract is missing');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @constant {Error} - The Storage client not
|
|
7
|
+
* @constant {Error} - The Storage client not initialized.
|
|
8
8
|
*/
|
|
9
9
|
export const ErrorStorageClientNotInitialized = new Error(
|
|
10
10
|
'Storage client not initialized'
|
|
11
11
|
);
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* @constant {Error} - The Storage does not
|
|
14
|
+
* @constant {Error} - The Storage client does not exist.
|
|
15
15
|
*/
|
|
16
16
|
export const ErrorStorageClientNotExists = new Error(
|
|
17
|
-
'Storage client does not
|
|
17
|
+
'Storage client does not exist'
|
|
18
18
|
);
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* @constant {Error} - The Storage credentials
|
|
21
|
+
* @constant {Error} - The Storage credentials are missing.
|
|
22
22
|
*/
|
|
23
23
|
export const ErrorStorageCredentialsMissing = new Error(
|
|
24
|
-
'Storage credentials
|
|
24
|
+
'Storage credentials are missing'
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -40,9 +40,9 @@ export const ErrorStorageFileNotFound = new Error('File not found');
|
|
|
40
40
|
export const ErrorStorageFileNotUploaded = new Error('File not uploaded');
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* @constant {Error} - The KVStore key
|
|
43
|
+
* @constant {Error} - The KVStore key cannot be empty.
|
|
44
44
|
*/
|
|
45
|
-
export const ErrorKVStoreEmptyKey = new Error('Key
|
|
45
|
+
export const ErrorKVStoreEmptyKey = new Error('Key cannot be empty');
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* @constant {Error} - The KVStore arrays must have the same length.
|
|
@@ -52,12 +52,12 @@ export const ErrorKVStoreArrayLength = new Error(
|
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* @constant {Error} - The
|
|
55
|
+
* @constant {Error} - The address provided is invalid.
|
|
56
56
|
*/
|
|
57
57
|
export const ErrorInvalidAddress = new Error('Invalid address');
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
* @constant {Error} - The token address
|
|
60
|
+
* @constant {Error} - The token address provided is invalid.
|
|
61
61
|
*/
|
|
62
62
|
export const ErrorInvalidTokenAddress = new Error('Invalid token address');
|
|
63
63
|
|
|
@@ -76,14 +76,14 @@ export const ErrorInvalidReputationOracleAddressProvided = new Error(
|
|
|
76
76
|
);
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* @constant {Error} - Invalid
|
|
79
|
+
* @constant {Error} - Invalid exchange oracle address provided.
|
|
80
80
|
*/
|
|
81
81
|
export const ErrorInvalidExchangeOracleAddressProvided = new Error(
|
|
82
82
|
'Invalid exchange oracle address provided'
|
|
83
83
|
);
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* @constant {Error} - The
|
|
86
|
+
* @constant {Error} - The staking value must be positive.
|
|
87
87
|
*/
|
|
88
88
|
export const ErrorStakingValueMustBePositive = new Error(
|
|
89
89
|
'Value must be positive'
|
|
@@ -120,7 +120,7 @@ export const ErrorInvalidStakerAddressProvided = new Error(
|
|
|
120
120
|
/**
|
|
121
121
|
* @constant {Error} - Invalid hash provided.
|
|
122
122
|
*/
|
|
123
|
-
export const
|
|
123
|
+
export const ErrorInvalidHashProvided = new Error('Invalid hash provided');
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* @constant {Error} - Cannot use both date and block filters simultaneously.
|
|
@@ -148,6 +148,9 @@ export const ErrorFailedToApproveStakingAmountSignerDoesNotExist = new Error(
|
|
|
148
148
|
'Failed to approve staking amount: signerOrProvider is not a Signer instance'
|
|
149
149
|
);
|
|
150
150
|
|
|
151
|
+
/**
|
|
152
|
+
* @constant {Error} - Failed to check allowance.
|
|
153
|
+
*/
|
|
151
154
|
export const ErrorFailedToCheckAllowance = new Error(
|
|
152
155
|
'Failed to check allowance'
|
|
153
156
|
);
|
|
@@ -158,12 +161,12 @@ export const ErrorFailedToCheckAllowance = new Error(
|
|
|
158
161
|
export const ErrorHMTokenAmountNotApproved = new Error('Amount not approved');
|
|
159
162
|
|
|
160
163
|
/**
|
|
161
|
-
* @constant {Error} -
|
|
164
|
+
* @constant {Error} - Provider does not exist.
|
|
162
165
|
*/
|
|
163
166
|
export const ErrorProviderDoesNotExist = new Error('Provider does not exist');
|
|
164
167
|
|
|
165
168
|
/**
|
|
166
|
-
* @constant {Error} -
|
|
169
|
+
* @constant {Error} - Unsupported chain ID.
|
|
167
170
|
*/
|
|
168
171
|
export const ErrorUnsupportedChainID = new Error('Unsupported chain ID');
|
|
169
172
|
|
|
@@ -193,13 +196,6 @@ export const ErrorManifestFileDoesNotExist = new Error(
|
|
|
193
196
|
'Manifest file does not exist'
|
|
194
197
|
);
|
|
195
198
|
|
|
196
|
-
/**
|
|
197
|
-
* @constant {Error} - Storage client does not exist.
|
|
198
|
-
*/
|
|
199
|
-
export const ErrorStorageClientDoesNotExist = new Error(
|
|
200
|
-
'Storage client does not exist'
|
|
201
|
-
);
|
|
202
|
-
|
|
203
199
|
/**
|
|
204
200
|
* @constant {Error} - Invalid URL string.
|
|
205
201
|
*/
|
|
@@ -244,7 +240,12 @@ export const ErrorRecipientCannotBeEmptyArray = new Error(
|
|
|
244
240
|
);
|
|
245
241
|
|
|
246
242
|
/**
|
|
247
|
-
* @constant {Error} -
|
|
243
|
+
* @constant {Error} - Too many recipients.
|
|
244
|
+
*/
|
|
245
|
+
export const ErrorTooManyRecipients = new Error('Too many recipients');
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @constant {Error} - Amount must be greater than zero.
|
|
248
249
|
*/
|
|
249
250
|
export const ErrorAmountMustBeGreaterThanZero = new Error(
|
|
250
251
|
'Amount must be greater than zero'
|
|
@@ -283,6 +284,22 @@ export const ErrorLaunchedEventIsNotEmitted = new Error(
|
|
|
283
284
|
*/
|
|
284
285
|
export const ErrorHashIsEmptyString = new Error('Hash is an empty string');
|
|
285
286
|
|
|
287
|
+
/**
|
|
288
|
+
* @constant {Error} - The hash does not match.
|
|
289
|
+
*/
|
|
290
|
+
export const ErrorInvalidHash = new Error('Invalid hash');
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @constant {Error} - The status is not supported.
|
|
294
|
+
*/
|
|
295
|
+
export const ErrorUnsupportedStatus = new Error('Unsupported status for query');
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @constant {Warning} - The SUBGRAPH_API_KEY is not being provided.
|
|
299
|
+
*/
|
|
300
|
+
export const WarnSubgraphApiKeyNotProvided =
|
|
301
|
+
'"SUBGRAPH_API_KEY" is not being provided. It might cause issues with the subgraph.';
|
|
302
|
+
|
|
286
303
|
export class EthereumError extends Error {
|
|
287
304
|
constructor(message: string) {
|
|
288
305
|
super(`An error occurred while interacting with Ethereum: ${message}`);
|
|
@@ -330,21 +347,6 @@ export class InvalidEthereumAddressError extends Error {
|
|
|
330
347
|
super(`Invalid ethereum address error: ${address}`);
|
|
331
348
|
}
|
|
332
349
|
}
|
|
333
|
-
/**
|
|
334
|
-
* @constant {Error} - The Hash does not match
|
|
335
|
-
*/
|
|
336
|
-
export const ErrorInvalidHash = new Error('Invalid hash');
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* @constant {Error} - The Status is not supported
|
|
340
|
-
*/
|
|
341
|
-
export const ErrorUnsupportedStatus = new Error('Unsupported status for query');
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* @constant {Error} - The SUBGRAPH_API_KEY is not being provided
|
|
345
|
-
*/
|
|
346
|
-
export const WarnSubgraphApiKeyNotProvided =
|
|
347
|
-
'"SUBGRAPH_API_KEY" is not being provided. It might cause issues with the subgraph.';
|
|
348
350
|
|
|
349
351
|
export class InvalidKeyError extends Error {
|
|
350
352
|
constructor(key: string, address: string) {
|