@human-protocol/sdk 5.2.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/base.d.ts +8 -7
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +18 -5
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +7 -8
- package/dist/encryption.d.ts +68 -203
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +66 -202
- package/dist/error.d.ts +0 -24
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -26
- package/dist/escrow.d.ts +438 -791
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +331 -705
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +3 -1
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/interfaces.d.ts +2 -2
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +124 -186
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +122 -185
- package/dist/operator.d.ts +59 -30
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +59 -30
- package/dist/staking.d.ts +142 -141
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +140 -139
- package/dist/statistics.d.ts +104 -134
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +119 -144
- package/dist/transaction.d.ts +38 -17
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +40 -19
- package/dist/types.d.ts +14 -55
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +32 -18
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +32 -19
- package/dist/worker.d.ts +35 -14
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +35 -14
- package/package.json +8 -25
- package/src/base.ts +42 -7
- package/src/constants.ts +6 -8
- package/src/encryption.ts +69 -203
- package/src/error.ts +0 -36
- package/src/escrow.ts +548 -891
- package/src/graphql/queries/operator.ts +3 -1
- package/src/graphql/types.ts +4 -2
- package/src/index.ts +4 -5
- package/src/interfaces.ts +2 -2
- package/src/kvstore.ts +142 -197
- package/src/operator.ts +59 -30
- package/src/staking.ts +177 -160
- package/src/statistics.ts +125 -146
- package/src/transaction.ts +40 -19
- package/src/types.ts +16 -58
- package/src/utils.ts +33 -23
- package/src/worker.ts +35 -14
- package/dist/storage.d.ts +0 -186
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -319
- package/src/storage.ts +0 -313
package/dist/encryption.js
CHANGED
|
@@ -42,50 +42,17 @@ function makeMessageDataBinary(message) {
|
|
|
42
42
|
return message;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
* ## Introduction
|
|
46
|
-
*
|
|
47
45
|
* Class for signing and decrypting messages.
|
|
48
46
|
*
|
|
49
47
|
* The algorithm includes the implementation of the [PGP encryption algorithm](https://github.com/openpgpjs/openpgpjs) multi-public key encryption on typescript, and uses the vanilla [ed25519](https://en.wikipedia.org/wiki/EdDSA#Ed25519) implementation Schnorr signature for signatures and [curve25519](https://en.wikipedia.org/wiki/Curve25519) for encryption. [Learn more](https://wiki.polkadot.network/docs/learn-cryptography).
|
|
50
48
|
*
|
|
51
|
-
* To get an instance of this class, initialization is recommended using the static `build` method.
|
|
52
|
-
*
|
|
53
|
-
* ```ts
|
|
54
|
-
* static async build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* ## Installation
|
|
58
|
-
*
|
|
59
|
-
* ### npm
|
|
60
|
-
* ```bash
|
|
61
|
-
* npm install @human-protocol/sdk
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* ### yarn
|
|
65
|
-
* ```bash
|
|
66
|
-
* yarn install @human-protocol/sdk
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* ## Input parameters
|
|
70
|
-
*
|
|
71
|
-
* - `privateKeyArmored` - The encrypted private key in armored format.
|
|
72
|
-
* - `passphrase` - The passphrase for the private key.
|
|
73
|
-
*
|
|
74
|
-
* ## Code example
|
|
75
|
-
*
|
|
76
|
-
* ```ts
|
|
77
|
-
* import { Encryption } from '@human-protocol/sdk';
|
|
78
|
-
*
|
|
79
|
-
* const privateKey = 'Armored_priv_key';
|
|
80
|
-
* const passphrase = 'example_passphrase';
|
|
81
|
-
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
82
|
-
* ```
|
|
49
|
+
* To get an instance of this class, initialization is recommended using the static [`build`](/ts/classes/Encryption/#build) method.
|
|
83
50
|
*/
|
|
84
51
|
class Encryption {
|
|
85
52
|
/**
|
|
86
53
|
* Constructor for the Encryption class.
|
|
87
54
|
*
|
|
88
|
-
* @param
|
|
55
|
+
* @param privateKey - The private key.
|
|
89
56
|
*/
|
|
90
57
|
constructor(privateKey) {
|
|
91
58
|
this.privateKey = privateKey;
|
|
@@ -93,9 +60,18 @@ class Encryption {
|
|
|
93
60
|
/**
|
|
94
61
|
* Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase.
|
|
95
62
|
*
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
98
|
-
* @returns
|
|
63
|
+
* @param privateKeyArmored - The encrypted private key in armored format.
|
|
64
|
+
* @param passphrase - The passphrase for the private key (optional).
|
|
65
|
+
* @returns The Encryption instance.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
70
|
+
*
|
|
71
|
+
* const privateKey = 'Armored_priv_key';
|
|
72
|
+
* const passphrase = 'example_passphrase';
|
|
73
|
+
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
74
|
+
* ```
|
|
99
75
|
*/
|
|
100
76
|
static async build(privateKeyArmored, passphrase) {
|
|
101
77
|
const options = {
|
|
@@ -113,45 +89,18 @@ class Encryption {
|
|
|
113
89
|
/**
|
|
114
90
|
* This function signs and encrypts a message using the private key used to initialize the client and the specified public keys.
|
|
115
91
|
*
|
|
116
|
-
* @param
|
|
117
|
-
* @param
|
|
118
|
-
* @returns
|
|
119
|
-
*
|
|
120
|
-
* **Code example**
|
|
92
|
+
* @param message - Message to sign and encrypt.
|
|
93
|
+
* @param publicKeys - Array of public keys to use for encryption.
|
|
94
|
+
* @returns Message signed and encrypted.
|
|
121
95
|
*
|
|
96
|
+
* @example
|
|
122
97
|
* ```ts
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* const privateKey = 'Armored_priv_key';
|
|
127
|
-
* const passphrase = 'example_passphrase';
|
|
128
|
-
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
129
|
-
* const publicKey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
130
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
131
|
-
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
132
|
-
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
133
|
-
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
134
|
-
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
135
|
-
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
136
|
-
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
137
|
-
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
138
|
-
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
139
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
140
|
-
*
|
|
141
|
-
* const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
142
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
|
|
143
|
-
* FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
144
|
-
* CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
|
|
145
|
-
* bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
|
|
146
|
-
* ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
|
|
147
|
-
* CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
|
|
148
|
-
* bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
|
|
149
|
-
* bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
|
|
150
|
-
* s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
|
|
151
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
98
|
+
* const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
99
|
+
* const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
152
100
|
*
|
|
153
101
|
* const publicKeys = [publicKey1, publicKey2];
|
|
154
102
|
* const resultMessage = await encryption.signAndEncrypt('message', publicKeys);
|
|
103
|
+
* console.log('Encrypted message:', resultMessage);
|
|
155
104
|
* ```
|
|
156
105
|
*/
|
|
157
106
|
async signAndEncrypt(message, publicKeys) {
|
|
@@ -170,32 +119,17 @@ class Encryption {
|
|
|
170
119
|
/**
|
|
171
120
|
* This function decrypts messages using the private key. In addition, the public key can be added for signature verification.
|
|
172
121
|
*
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
175
|
-
* @returns
|
|
176
|
-
*
|
|
177
|
-
* **Code example**
|
|
122
|
+
* @param message - Message to decrypt.
|
|
123
|
+
* @param publicKey - Public key used to verify signature if needed (optional).
|
|
124
|
+
* @returns Message decrypted.
|
|
125
|
+
* @throws Error If signature could not be verified when public key is provided
|
|
178
126
|
*
|
|
127
|
+
* @example
|
|
179
128
|
* ```ts
|
|
180
|
-
*
|
|
129
|
+
* const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
181
130
|
*
|
|
182
|
-
* const
|
|
183
|
-
*
|
|
184
|
-
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
185
|
-
*
|
|
186
|
-
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
187
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
188
|
-
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
189
|
-
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
190
|
-
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
191
|
-
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
192
|
-
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
193
|
-
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
194
|
-
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
195
|
-
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
196
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
197
|
-
*
|
|
198
|
-
* const resultMessage = await encryption.decrypt('message');
|
|
131
|
+
* const resultMessage = await encryption.decrypt('message', publicKey);
|
|
132
|
+
* console.log('Decrypted message:', resultMessage);
|
|
199
133
|
* ```
|
|
200
134
|
*/
|
|
201
135
|
async decrypt(message, publicKey) {
|
|
@@ -231,19 +165,13 @@ class Encryption {
|
|
|
231
165
|
/**
|
|
232
166
|
* This function signs a message using the private key used to initialize the client.
|
|
233
167
|
*
|
|
234
|
-
* @param
|
|
235
|
-
* @returns
|
|
236
|
-
*
|
|
237
|
-
* **Code example**
|
|
168
|
+
* @param message - Message to sign.
|
|
169
|
+
* @returns Message signed.
|
|
238
170
|
*
|
|
171
|
+
* @example
|
|
239
172
|
* ```ts
|
|
240
|
-
* import { Encryption } from '@human-protocol/sdk';
|
|
241
|
-
*
|
|
242
|
-
* const privateKey = 'Armored_priv_key';
|
|
243
|
-
* const passphrase = 'example_passphrase';
|
|
244
|
-
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
245
|
-
*
|
|
246
173
|
* const resultMessage = await encryption.sign('message');
|
|
174
|
+
* console.log('Signed message:', resultMessage);
|
|
247
175
|
* ```
|
|
248
176
|
*/
|
|
249
177
|
async sign(message) {
|
|
@@ -260,56 +188,23 @@ class Encryption {
|
|
|
260
188
|
}
|
|
261
189
|
exports.Encryption = Encryption;
|
|
262
190
|
/**
|
|
263
|
-
* ## Introduction
|
|
264
|
-
*
|
|
265
191
|
* Utility class for encryption-related operations.
|
|
266
|
-
*
|
|
267
|
-
* ## Installation
|
|
268
|
-
*
|
|
269
|
-
* ### npm
|
|
270
|
-
* ```bash
|
|
271
|
-
* npm install @human-protocol/sdk
|
|
272
|
-
* ```
|
|
273
|
-
*
|
|
274
|
-
* ### yarn
|
|
275
|
-
* ```bash
|
|
276
|
-
* yarn install @human-protocol/sdk
|
|
277
|
-
* ```
|
|
278
|
-
*
|
|
279
|
-
* ## Code example
|
|
280
|
-
*
|
|
281
|
-
* ```ts
|
|
282
|
-
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
283
|
-
*
|
|
284
|
-
* const keyPair = await EncryptionUtils.generateKeyPair('Human', 'human@hmt.ai');
|
|
285
|
-
* ```
|
|
286
192
|
*/
|
|
287
193
|
class EncryptionUtils {
|
|
288
194
|
/**
|
|
289
195
|
* This function verifies the signature of a signed message using the public key.
|
|
290
196
|
*
|
|
291
|
-
* @param
|
|
292
|
-
* @param
|
|
293
|
-
* @returns
|
|
294
|
-
*
|
|
295
|
-
* **Code example**
|
|
197
|
+
* @param message - Message to verify.
|
|
198
|
+
* @param publicKey - Public key to verify that the message was signed by a specific source.
|
|
199
|
+
* @returns True if verified. False if not verified.
|
|
296
200
|
*
|
|
201
|
+
* @example
|
|
297
202
|
* ```ts
|
|
298
203
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
299
204
|
*
|
|
300
|
-
* const publicKey =
|
|
301
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
302
|
-
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
303
|
-
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
304
|
-
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
305
|
-
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
306
|
-
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
307
|
-
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
308
|
-
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
309
|
-
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
310
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
311
|
-
*
|
|
205
|
+
* const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
312
206
|
* const result = await EncryptionUtils.verify('message', publicKey);
|
|
207
|
+
* console.log('Verification result:', result);
|
|
313
208
|
* ```
|
|
314
209
|
*/
|
|
315
210
|
static async verify(message, publicKey) {
|
|
@@ -329,15 +224,16 @@ class EncryptionUtils {
|
|
|
329
224
|
/**
|
|
330
225
|
* This function gets signed data from a signed message.
|
|
331
226
|
*
|
|
332
|
-
* @param
|
|
333
|
-
* @returns
|
|
334
|
-
*
|
|
335
|
-
* **Code example**
|
|
227
|
+
* @param message - Message.
|
|
228
|
+
* @returns Signed data.
|
|
229
|
+
* @throws Error If data could not be extracted from the message
|
|
336
230
|
*
|
|
231
|
+
* @example
|
|
337
232
|
* ```ts
|
|
338
233
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
339
234
|
*
|
|
340
235
|
* const signedData = await EncryptionUtils.getSignedData('message');
|
|
236
|
+
* console.log('Signed data:', signedData);
|
|
341
237
|
* ```
|
|
342
238
|
*/
|
|
343
239
|
static async getSignedData(message) {
|
|
@@ -354,20 +250,20 @@ class EncryptionUtils {
|
|
|
354
250
|
/**
|
|
355
251
|
* This function generates a key pair for encryption and decryption.
|
|
356
252
|
*
|
|
357
|
-
* @param
|
|
358
|
-
* @param
|
|
359
|
-
* @param
|
|
360
|
-
* @returns
|
|
361
|
-
*
|
|
362
|
-
* **Code example**
|
|
253
|
+
* @param name - Name for the key pair.
|
|
254
|
+
* @param email - Email for the key pair.
|
|
255
|
+
* @param passphrase - Passphrase to encrypt the private key (optional, defaults to empty string).
|
|
256
|
+
* @returns Key pair generated.
|
|
363
257
|
*
|
|
258
|
+
* @example
|
|
364
259
|
* ```ts
|
|
365
260
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
366
261
|
*
|
|
367
262
|
* const name = 'YOUR_NAME';
|
|
368
263
|
* const email = 'YOUR_EMAIL';
|
|
369
264
|
* const passphrase = 'YOUR_PASSPHRASE';
|
|
370
|
-
* const
|
|
265
|
+
* const keyPair = await EncryptionUtils.generateKeyPair(name, email, passphrase);
|
|
266
|
+
* console.log('Public key:', keyPair.publicKey);
|
|
371
267
|
* ```
|
|
372
268
|
*/
|
|
373
269
|
static async generateKeyPair(name, email, passphrase = '') {
|
|
@@ -388,41 +284,19 @@ class EncryptionUtils {
|
|
|
388
284
|
/**
|
|
389
285
|
* This function encrypts a message using the specified public keys.
|
|
390
286
|
*
|
|
391
|
-
* @param
|
|
392
|
-
* @param
|
|
393
|
-
* @returns
|
|
394
|
-
*
|
|
395
|
-
* **Code example**
|
|
287
|
+
* @param message - Message to encrypt.
|
|
288
|
+
* @param publicKeys - Array of public keys to use for encryption.
|
|
289
|
+
* @returns Message encrypted.
|
|
396
290
|
*
|
|
291
|
+
* @example
|
|
397
292
|
* ```ts
|
|
398
293
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
399
294
|
*
|
|
400
|
-
* const publicKey1 =
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
406
|
-
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
407
|
-
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
408
|
-
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
409
|
-
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
410
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
411
|
-
*
|
|
412
|
-
* const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
413
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
|
|
414
|
-
* FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
415
|
-
* CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
|
|
416
|
-
* bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
|
|
417
|
-
* ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
|
|
418
|
-
* CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
|
|
419
|
-
* bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
|
|
420
|
-
* bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
|
|
421
|
-
* s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
|
|
422
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
423
|
-
*
|
|
424
|
-
* const publicKeys = [publicKey1, publicKey2]
|
|
425
|
-
* const result = await EncryptionUtils.encrypt('message', publicKeys);
|
|
295
|
+
* const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
296
|
+
* const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
297
|
+
* const publicKeys = [publicKey1, publicKey2];
|
|
298
|
+
* const encryptedMessage = await EncryptionUtils.encrypt('message', publicKeys);
|
|
299
|
+
* console.log('Encrypted message:', encryptedMessage);
|
|
426
300
|
* ```
|
|
427
301
|
*/
|
|
428
302
|
static async encrypt(message, publicKeys) {
|
|
@@ -440,25 +314,15 @@ class EncryptionUtils {
|
|
|
440
314
|
/**
|
|
441
315
|
* Verifies if a message appears to be encrypted with OpenPGP.
|
|
442
316
|
*
|
|
443
|
-
* @param
|
|
444
|
-
* @returns
|
|
445
|
-
*
|
|
446
|
-
* **Code example:**
|
|
317
|
+
* @param message - Message to verify.
|
|
318
|
+
* @returns `true` if the message appears to be encrypted, `false` if not.
|
|
447
319
|
*
|
|
320
|
+
* @example
|
|
448
321
|
* ```ts
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
* wV4DqdeRpqH+jaISAQdAsvBFxikvjxRqC7ZlDe98cLd7/aeCEI/AcL8PpVKK
|
|
452
|
-
* mC0wKlwxNg/ADi55z9jcYFuMC4kKE+C/teM+JqiI8DO9AwassQUvKFtULnpx
|
|
453
|
-
* h2jaOjC/0sAQASjUsIFK8zbuDgk/P8T9Npn6px+GlJPg9K90iwtPWiIp0eyW
|
|
454
|
-
* 4zXamJZT51k2DyaUX/Rsc6P4PYhQRKjt0yxtH0jHPmKkLC/9eBeFf4GP0zlZ
|
|
455
|
-
* 18xMZ8uCpQCma708Gz0sJYxEz3u/eZdHD7Mc7tWQKyJG8MsTwM1P+fdK1X75
|
|
456
|
-
* L9UryJG2AY+6kKZhG4dqjNxiO4fWluiB2u7iMF+iLEyE3SQCEYorWMC+NDWi
|
|
457
|
-
* QIJZ7oQ2w7BaPo1a991gvTOSNm5v2x44KfqPI1uj859BjsQTCA==
|
|
458
|
-
* =tsmI
|
|
459
|
-
* -----END PGP MESSAGE-----`;
|
|
322
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
460
323
|
*
|
|
461
|
-
* const
|
|
324
|
+
* const message = '-----BEGIN PGP MESSAGE-----...';
|
|
325
|
+
* const isEncrypted = EncryptionUtils.isEncrypted(message);
|
|
462
326
|
*
|
|
463
327
|
* if (isEncrypted) {
|
|
464
328
|
* console.log('The message is encrypted with OpenPGP.');
|
package/dist/error.d.ts
CHANGED
|
@@ -2,30 +2,6 @@
|
|
|
2
2
|
* @constant {Error} - The Staking contract is missing.
|
|
3
3
|
*/
|
|
4
4
|
export declare const ErrorStakingMissing: Error;
|
|
5
|
-
/**
|
|
6
|
-
* @constant {Error} - The Storage client not initialized.
|
|
7
|
-
*/
|
|
8
|
-
export declare const ErrorStorageClientNotInitialized: Error;
|
|
9
|
-
/**
|
|
10
|
-
* @constant {Error} - The Storage client does not exist.
|
|
11
|
-
*/
|
|
12
|
-
export declare const ErrorStorageClientNotExists: Error;
|
|
13
|
-
/**
|
|
14
|
-
* @constant {Error} - The Storage credentials are missing.
|
|
15
|
-
*/
|
|
16
|
-
export declare const ErrorStorageCredentialsMissing: Error;
|
|
17
|
-
/**
|
|
18
|
-
* @constant {Error} - The Storage bucket not found.
|
|
19
|
-
*/
|
|
20
|
-
export declare const ErrorStorageBucketNotFound: Error;
|
|
21
|
-
/**
|
|
22
|
-
* @constant {Error} - The Storage file not found.
|
|
23
|
-
*/
|
|
24
|
-
export declare const ErrorStorageFileNotFound: Error;
|
|
25
|
-
/**
|
|
26
|
-
* @constant {Error} - The Storage file not uploaded.
|
|
27
|
-
*/
|
|
28
|
-
export declare const ErrorStorageFileNotUploaded: Error;
|
|
29
5
|
/**
|
|
30
6
|
* @constant {Error} - The KVStore key cannot be empty.
|
|
31
7
|
*/
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],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EG;AACH,eAAO,MAAM,2BAA2B,OAEvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2CAA2C,OAEvD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,qHACoF,CAAC;AAErH;;GAEG;AACH,eAAO,MAAM,6BAA6B,yFAC4C,CAAC;AAEvF,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,oBAAqB,SAAQ,aAAa;gBACzC,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;AAED,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAGzC"}
|
package/dist/error.js
CHANGED
|
@@ -1,35 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ErrorBulkPayOutVersion = exports.ErrorStoreResultsVersion = exports.ErrorUnsupportedStatus = exports.ErrorInvalidHash = exports.ErrorHashIsEmptyString = exports.ErrorLaunchedEventIsNotEmitted = exports.ErrorRecipientAndAmountsMustBeSameLength = exports.ErrorAmountsCannotBeEmptyArray = exports.ErrorEscrowDoesNotHaveEnoughBalance = exports.ErrorAmountMustBeGreaterThanZero = exports.ErrorTooManyRecipients = exports.ErrorRecipientCannotBeEmptyArray = exports.ErrorTotalFeeMustBeLessThanHundred = exports.ErrorFeeMustBeBetweenZeroAndHundred = exports.ErrorNoURLprovided = exports.ErrorInvalidManifest = exports.ErrorInvalidUrl = exports.ErrorManifestFileDoesNotExist = exports.ErrorTransferEventNotFoundInTransactionLogs = exports.ErrorEscrowAddressIsNotProvidedByFactory = exports.ErrorSigner = exports.ErrorStakerNotFound = exports.ErrorUnsupportedChainID = exports.ErrorProviderDoesNotExist = exports.ErrorHMTokenAmountNotApproved = exports.ErrorFailedToCheckAllowance = exports.ErrorFailedToApproveStakingAmountSignerDoesNotExist = exports.ErrorStakingGetStakers = exports.ErrorInvalidEscrowAddressProvided = exports.ErrorCannotUseDateAndBlockSimultaneously = exports.ErrorInvalidHashProvided = exports.ErrorInvalidStakerAddressProvided = exports.ErrorInvalidSlasherAddressProvided = exports.ErrorInvalidStakingValueSign = exports.ErrorInvalidStakingValueType = exports.ErrorStakingValueMustBePositive = exports.ErrorInvalidExchangeOracleAddressProvided = exports.ErrorInvalidReputationOracleAddressProvided = exports.ErrorInvalidRecordingOracleAddressProvided = exports.ErrorInvalidTokenAddress = exports.ErrorInvalidAddress = exports.ErrorKVStoreArrayLength = exports.ErrorKVStoreEmptyKey = exports.
|
|
4
|
-
exports.InvalidKeyError = exports.InvalidEthereumAddressError = exports.ContractExecutionError = exports.TransactionReplaced = exports.NonceExpired = exports.NumericFault = exports.ReplacementUnderpriced =
|
|
3
|
+
exports.InvalidArgumentError = exports.EthereumError = exports.WarnSubgraphApiKeyNotProvided = exports.WarnVersionMismatch = exports.ErrorRoutingRequestsToIndexerRequiresApiKey = exports.ErrorRetryParametersMissing = exports.ErrorBulkPayOutVersion = exports.ErrorStoreResultsVersion = exports.ErrorUnsupportedStatus = exports.ErrorInvalidHash = exports.ErrorHashIsEmptyString = exports.ErrorLaunchedEventIsNotEmitted = exports.ErrorRecipientAndAmountsMustBeSameLength = exports.ErrorAmountsCannotBeEmptyArray = exports.ErrorEscrowDoesNotHaveEnoughBalance = exports.ErrorAmountMustBeGreaterThanZero = exports.ErrorTooManyRecipients = exports.ErrorRecipientCannotBeEmptyArray = exports.ErrorTotalFeeMustBeLessThanHundred = exports.ErrorFeeMustBeBetweenZeroAndHundred = exports.ErrorNoURLprovided = exports.ErrorInvalidManifest = exports.ErrorInvalidUrl = exports.ErrorManifestFileDoesNotExist = exports.ErrorTransferEventNotFoundInTransactionLogs = exports.ErrorEscrowAddressIsNotProvidedByFactory = exports.ErrorSigner = exports.ErrorStakerNotFound = exports.ErrorUnsupportedChainID = exports.ErrorProviderDoesNotExist = exports.ErrorHMTokenAmountNotApproved = exports.ErrorFailedToCheckAllowance = exports.ErrorFailedToApproveStakingAmountSignerDoesNotExist = exports.ErrorStakingGetStakers = exports.ErrorInvalidEscrowAddressProvided = exports.ErrorCannotUseDateAndBlockSimultaneously = exports.ErrorInvalidHashProvided = exports.ErrorInvalidStakerAddressProvided = exports.ErrorInvalidSlasherAddressProvided = exports.ErrorInvalidStakingValueSign = exports.ErrorInvalidStakingValueType = exports.ErrorStakingValueMustBePositive = exports.ErrorInvalidExchangeOracleAddressProvided = exports.ErrorInvalidReputationOracleAddressProvided = exports.ErrorInvalidRecordingOracleAddressProvided = exports.ErrorInvalidTokenAddress = exports.ErrorInvalidAddress = exports.ErrorKVStoreArrayLength = exports.ErrorKVStoreEmptyKey = exports.ErrorStakingMissing = void 0;
|
|
4
|
+
exports.InvalidKeyError = exports.InvalidEthereumAddressError = exports.ContractExecutionError = exports.TransactionReplaced = exports.NonceExpired = exports.NumericFault = exports.ReplacementUnderpriced = void 0;
|
|
5
5
|
/**
|
|
6
6
|
* @constant {Error} - The Staking contract is missing.
|
|
7
7
|
*/
|
|
8
8
|
exports.ErrorStakingMissing = new Error('Staking contract is missing');
|
|
9
|
-
/**
|
|
10
|
-
* @constant {Error} - The Storage client not initialized.
|
|
11
|
-
*/
|
|
12
|
-
exports.ErrorStorageClientNotInitialized = new Error('Storage client not initialized');
|
|
13
|
-
/**
|
|
14
|
-
* @constant {Error} - The Storage client does not exist.
|
|
15
|
-
*/
|
|
16
|
-
exports.ErrorStorageClientNotExists = new Error('Storage client does not exist');
|
|
17
|
-
/**
|
|
18
|
-
* @constant {Error} - The Storage credentials are missing.
|
|
19
|
-
*/
|
|
20
|
-
exports.ErrorStorageCredentialsMissing = new Error('Storage credentials are missing');
|
|
21
|
-
/**
|
|
22
|
-
* @constant {Error} - The Storage bucket not found.
|
|
23
|
-
*/
|
|
24
|
-
exports.ErrorStorageBucketNotFound = new Error('Bucket not found');
|
|
25
|
-
/**
|
|
26
|
-
* @constant {Error} - The Storage file not found.
|
|
27
|
-
*/
|
|
28
|
-
exports.ErrorStorageFileNotFound = new Error('File not found');
|
|
29
|
-
/**
|
|
30
|
-
* @constant {Error} - The Storage file not uploaded.
|
|
31
|
-
*/
|
|
32
|
-
exports.ErrorStorageFileNotUploaded = new Error('File not uploaded');
|
|
33
9
|
/**
|
|
34
10
|
* @constant {Error} - The KVStore key cannot be empty.
|
|
35
11
|
*/
|