@human-protocol/sdk 5.2.0 → 6.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/base.d.ts +4 -5
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +4 -5
- package/dist/constants.js +6 -6
- 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 +427 -780
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +314 -684
- 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/kvstore.d.ts +119 -181
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +119 -182
- 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 +135 -134
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +135 -134
- 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 +36 -15
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +36 -15
- package/dist/types.d.ts +0 -54
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +31 -17
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -17
- package/dist/worker.d.ts +35 -14
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +35 -14
- package/package.json +7 -24
- package/src/base.ts +4 -5
- package/src/constants.ts +6 -6
- package/src/encryption.ts +69 -203
- package/src/error.ts +0 -36
- package/src/escrow.ts +425 -780
- package/src/graphql/queries/operator.ts +3 -1
- package/src/graphql/types.ts +4 -2
- package/src/index.ts +4 -5
- package/src/kvstore.ts +120 -183
- package/src/operator.ts +59 -30
- package/src/staking.ts +135 -134
- package/src/statistics.ts +125 -146
- package/src/transaction.ts +36 -15
- package/src/types.ts +0 -57
- package/src/utils.ts +31 -17
- 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/src/encryption.ts
CHANGED
|
@@ -4,8 +4,10 @@ import { IKeyPair } from './interfaces';
|
|
|
4
4
|
/**
|
|
5
5
|
* Type representing the data type of a message.
|
|
6
6
|
* It can be either a string or a Uint8Array.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
7
9
|
*/
|
|
8
|
-
type MessageDataType = string | Uint8Array;
|
|
10
|
+
export type MessageDataType = string | Uint8Array;
|
|
9
11
|
|
|
10
12
|
function makeMessageDataBinary(message: MessageDataType): Uint8Array {
|
|
11
13
|
if (typeof message === 'string') {
|
|
@@ -16,44 +18,11 @@ function makeMessageDataBinary(message: MessageDataType): Uint8Array {
|
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
|
-
* ## Introduction
|
|
20
|
-
*
|
|
21
21
|
* Class for signing and decrypting messages.
|
|
22
22
|
*
|
|
23
23
|
* 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).
|
|
24
24
|
*
|
|
25
|
-
* To get an instance of this class, initialization is recommended using the static `build` method.
|
|
26
|
-
*
|
|
27
|
-
* ```ts
|
|
28
|
-
* static async build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* ## Installation
|
|
32
|
-
*
|
|
33
|
-
* ### npm
|
|
34
|
-
* ```bash
|
|
35
|
-
* npm install @human-protocol/sdk
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* ### yarn
|
|
39
|
-
* ```bash
|
|
40
|
-
* yarn install @human-protocol/sdk
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* ## Input parameters
|
|
44
|
-
*
|
|
45
|
-
* - `privateKeyArmored` - The encrypted private key in armored format.
|
|
46
|
-
* - `passphrase` - The passphrase for the private key.
|
|
47
|
-
*
|
|
48
|
-
* ## Code example
|
|
49
|
-
*
|
|
50
|
-
* ```ts
|
|
51
|
-
* import { Encryption } from '@human-protocol/sdk';
|
|
52
|
-
*
|
|
53
|
-
* const privateKey = 'Armored_priv_key';
|
|
54
|
-
* const passphrase = 'example_passphrase';
|
|
55
|
-
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
56
|
-
* ```
|
|
25
|
+
* To get an instance of this class, initialization is recommended using the static [`build`](/ts/classes/Encryption/#build) method.
|
|
57
26
|
*/
|
|
58
27
|
export class Encryption {
|
|
59
28
|
private privateKey: openpgp.PrivateKey;
|
|
@@ -61,7 +30,7 @@ export class Encryption {
|
|
|
61
30
|
/**
|
|
62
31
|
* Constructor for the Encryption class.
|
|
63
32
|
*
|
|
64
|
-
* @param
|
|
33
|
+
* @param privateKey - The private key.
|
|
65
34
|
*/
|
|
66
35
|
constructor(privateKey: openpgp.PrivateKey) {
|
|
67
36
|
this.privateKey = privateKey;
|
|
@@ -70,9 +39,18 @@ export class Encryption {
|
|
|
70
39
|
/**
|
|
71
40
|
* Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase.
|
|
72
41
|
*
|
|
73
|
-
* @param
|
|
74
|
-
* @param
|
|
75
|
-
* @returns
|
|
42
|
+
* @param privateKeyArmored - The encrypted private key in armored format.
|
|
43
|
+
* @param passphrase - The passphrase for the private key (optional).
|
|
44
|
+
* @returns The Encryption instance.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
49
|
+
*
|
|
50
|
+
* const privateKey = 'Armored_priv_key';
|
|
51
|
+
* const passphrase = 'example_passphrase';
|
|
52
|
+
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
53
|
+
* ```
|
|
76
54
|
*/
|
|
77
55
|
public static async build(
|
|
78
56
|
privateKeyArmored: string,
|
|
@@ -98,45 +76,18 @@ export class Encryption {
|
|
|
98
76
|
/**
|
|
99
77
|
* This function signs and encrypts a message using the private key used to initialize the client and the specified public keys.
|
|
100
78
|
*
|
|
101
|
-
* @param
|
|
102
|
-
* @param
|
|
103
|
-
* @returns
|
|
104
|
-
*
|
|
105
|
-
* **Code example**
|
|
79
|
+
* @param message - Message to sign and encrypt.
|
|
80
|
+
* @param publicKeys - Array of public keys to use for encryption.
|
|
81
|
+
* @returns Message signed and encrypted.
|
|
106
82
|
*
|
|
83
|
+
* @example
|
|
107
84
|
* ```ts
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* const privateKey = 'Armored_priv_key';
|
|
112
|
-
* const passphrase = 'example_passphrase';
|
|
113
|
-
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
114
|
-
* const publicKey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
115
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
116
|
-
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
117
|
-
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
118
|
-
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
119
|
-
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
120
|
-
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
121
|
-
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
122
|
-
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
123
|
-
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
124
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
125
|
-
*
|
|
126
|
-
* const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
127
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
|
|
128
|
-
* FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
129
|
-
* CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
|
|
130
|
-
* bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
|
|
131
|
-
* ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
|
|
132
|
-
* CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
|
|
133
|
-
* bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
|
|
134
|
-
* bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
|
|
135
|
-
* s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
|
|
136
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
85
|
+
* const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
86
|
+
* const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
137
87
|
*
|
|
138
88
|
* const publicKeys = [publicKey1, publicKey2];
|
|
139
89
|
* const resultMessage = await encryption.signAndEncrypt('message', publicKeys);
|
|
90
|
+
* console.log('Encrypted message:', resultMessage);
|
|
140
91
|
* ```
|
|
141
92
|
*/
|
|
142
93
|
public async signAndEncrypt(
|
|
@@ -163,32 +114,17 @@ export class Encryption {
|
|
|
163
114
|
/**
|
|
164
115
|
* This function decrypts messages using the private key. In addition, the public key can be added for signature verification.
|
|
165
116
|
*
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
168
|
-
* @returns
|
|
169
|
-
*
|
|
170
|
-
* **Code example**
|
|
117
|
+
* @param message - Message to decrypt.
|
|
118
|
+
* @param publicKey - Public key used to verify signature if needed (optional).
|
|
119
|
+
* @returns Message decrypted.
|
|
120
|
+
* @throws Error If signature could not be verified when public key is provided
|
|
171
121
|
*
|
|
122
|
+
* @example
|
|
172
123
|
* ```ts
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* const privateKey = 'Armored_priv_key';
|
|
176
|
-
* const passphrase = 'example_passphrase';
|
|
177
|
-
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
178
|
-
*
|
|
179
|
-
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
180
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
181
|
-
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
182
|
-
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
183
|
-
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
184
|
-
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
185
|
-
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
186
|
-
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
187
|
-
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
188
|
-
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
189
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
124
|
+
* const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
190
125
|
*
|
|
191
|
-
* const resultMessage = await encryption.decrypt('message');
|
|
126
|
+
* const resultMessage = await encryption.decrypt('message', publicKey);
|
|
127
|
+
* console.log('Decrypted message:', resultMessage);
|
|
192
128
|
* ```
|
|
193
129
|
*/
|
|
194
130
|
public async decrypt(
|
|
@@ -233,19 +169,13 @@ export class Encryption {
|
|
|
233
169
|
/**
|
|
234
170
|
* This function signs a message using the private key used to initialize the client.
|
|
235
171
|
*
|
|
236
|
-
* @param
|
|
237
|
-
* @returns
|
|
238
|
-
*
|
|
239
|
-
* **Code example**
|
|
172
|
+
* @param message - Message to sign.
|
|
173
|
+
* @returns Message signed.
|
|
240
174
|
*
|
|
175
|
+
* @example
|
|
241
176
|
* ```ts
|
|
242
|
-
* import { Encryption } from '@human-protocol/sdk';
|
|
243
|
-
*
|
|
244
|
-
* const privateKey = 'Armored_priv_key';
|
|
245
|
-
* const passphrase = 'example_passphrase';
|
|
246
|
-
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
247
|
-
*
|
|
248
177
|
* const resultMessage = await encryption.sign('message');
|
|
178
|
+
* console.log('Signed message:', resultMessage);
|
|
249
179
|
* ```
|
|
250
180
|
*/
|
|
251
181
|
public async sign(message: string): Promise<string> {
|
|
@@ -263,56 +193,23 @@ export class Encryption {
|
|
|
263
193
|
}
|
|
264
194
|
|
|
265
195
|
/**
|
|
266
|
-
* ## Introduction
|
|
267
|
-
*
|
|
268
196
|
* Utility class for encryption-related operations.
|
|
269
|
-
*
|
|
270
|
-
* ## Installation
|
|
271
|
-
*
|
|
272
|
-
* ### npm
|
|
273
|
-
* ```bash
|
|
274
|
-
* npm install @human-protocol/sdk
|
|
275
|
-
* ```
|
|
276
|
-
*
|
|
277
|
-
* ### yarn
|
|
278
|
-
* ```bash
|
|
279
|
-
* yarn install @human-protocol/sdk
|
|
280
|
-
* ```
|
|
281
|
-
*
|
|
282
|
-
* ## Code example
|
|
283
|
-
*
|
|
284
|
-
* ```ts
|
|
285
|
-
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
286
|
-
*
|
|
287
|
-
* const keyPair = await EncryptionUtils.generateKeyPair('Human', 'human@hmt.ai');
|
|
288
|
-
* ```
|
|
289
197
|
*/
|
|
290
198
|
export class EncryptionUtils {
|
|
291
199
|
/**
|
|
292
200
|
* This function verifies the signature of a signed message using the public key.
|
|
293
201
|
*
|
|
294
|
-
* @param
|
|
295
|
-
* @param
|
|
296
|
-
* @returns
|
|
297
|
-
*
|
|
298
|
-
* **Code example**
|
|
202
|
+
* @param message - Message to verify.
|
|
203
|
+
* @param publicKey - Public key to verify that the message was signed by a specific source.
|
|
204
|
+
* @returns True if verified. False if not verified.
|
|
299
205
|
*
|
|
206
|
+
* @example
|
|
300
207
|
* ```ts
|
|
301
208
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
302
209
|
*
|
|
303
|
-
* const publicKey =
|
|
304
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
305
|
-
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
306
|
-
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
307
|
-
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
308
|
-
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
309
|
-
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
310
|
-
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
311
|
-
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
312
|
-
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
313
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
314
|
-
*
|
|
210
|
+
* const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
315
211
|
* const result = await EncryptionUtils.verify('message', publicKey);
|
|
212
|
+
* console.log('Verification result:', result);
|
|
316
213
|
* ```
|
|
317
214
|
*/
|
|
318
215
|
public static async verify(
|
|
@@ -337,15 +234,16 @@ export class EncryptionUtils {
|
|
|
337
234
|
/**
|
|
338
235
|
* This function gets signed data from a signed message.
|
|
339
236
|
*
|
|
340
|
-
* @param
|
|
341
|
-
* @returns
|
|
342
|
-
*
|
|
343
|
-
* **Code example**
|
|
237
|
+
* @param message - Message.
|
|
238
|
+
* @returns Signed data.
|
|
239
|
+
* @throws Error If data could not be extracted from the message
|
|
344
240
|
*
|
|
241
|
+
* @example
|
|
345
242
|
* ```ts
|
|
346
243
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
347
244
|
*
|
|
348
245
|
* const signedData = await EncryptionUtils.getSignedData('message');
|
|
246
|
+
* console.log('Signed data:', signedData);
|
|
349
247
|
* ```
|
|
350
248
|
*/
|
|
351
249
|
public static async getSignedData(message: string): Promise<string> {
|
|
@@ -363,20 +261,20 @@ export class EncryptionUtils {
|
|
|
363
261
|
/**
|
|
364
262
|
* This function generates a key pair for encryption and decryption.
|
|
365
263
|
*
|
|
366
|
-
* @param
|
|
367
|
-
* @param
|
|
368
|
-
* @param
|
|
369
|
-
* @returns
|
|
370
|
-
*
|
|
371
|
-
* **Code example**
|
|
264
|
+
* @param name - Name for the key pair.
|
|
265
|
+
* @param email - Email for the key pair.
|
|
266
|
+
* @param passphrase - Passphrase to encrypt the private key (optional, defaults to empty string).
|
|
267
|
+
* @returns Key pair generated.
|
|
372
268
|
*
|
|
269
|
+
* @example
|
|
373
270
|
* ```ts
|
|
374
271
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
375
272
|
*
|
|
376
273
|
* const name = 'YOUR_NAME';
|
|
377
274
|
* const email = 'YOUR_EMAIL';
|
|
378
275
|
* const passphrase = 'YOUR_PASSPHRASE';
|
|
379
|
-
* const
|
|
276
|
+
* const keyPair = await EncryptionUtils.generateKeyPair(name, email, passphrase);
|
|
277
|
+
* console.log('Public key:', keyPair.publicKey);
|
|
380
278
|
* ```
|
|
381
279
|
*/
|
|
382
280
|
public static async generateKeyPair(
|
|
@@ -404,41 +302,19 @@ export class EncryptionUtils {
|
|
|
404
302
|
/**
|
|
405
303
|
* This function encrypts a message using the specified public keys.
|
|
406
304
|
*
|
|
407
|
-
* @param
|
|
408
|
-
* @param
|
|
409
|
-
* @returns
|
|
410
|
-
*
|
|
411
|
-
* **Code example**
|
|
305
|
+
* @param message - Message to encrypt.
|
|
306
|
+
* @param publicKeys - Array of public keys to use for encryption.
|
|
307
|
+
* @returns Message encrypted.
|
|
412
308
|
*
|
|
309
|
+
* @example
|
|
413
310
|
* ```ts
|
|
414
311
|
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
415
312
|
*
|
|
416
|
-
* const publicKey1 =
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
422
|
-
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
423
|
-
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
424
|
-
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
425
|
-
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
426
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
427
|
-
*
|
|
428
|
-
* const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
429
|
-
* xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
|
|
430
|
-
* FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
431
|
-
* CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
|
|
432
|
-
* bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
|
|
433
|
-
* ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
|
|
434
|
-
* CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
|
|
435
|
-
* bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
|
|
436
|
-
* bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
|
|
437
|
-
* s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
|
|
438
|
-
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
439
|
-
*
|
|
440
|
-
* const publicKeys = [publicKey1, publicKey2]
|
|
441
|
-
* const result = await EncryptionUtils.encrypt('message', publicKeys);
|
|
313
|
+
* const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
314
|
+
* const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
315
|
+
* const publicKeys = [publicKey1, publicKey2];
|
|
316
|
+
* const encryptedMessage = await EncryptionUtils.encrypt('message', publicKeys);
|
|
317
|
+
* console.log('Encrypted message:', encryptedMessage);
|
|
442
318
|
* ```
|
|
443
319
|
*/
|
|
444
320
|
public static async encrypt(
|
|
@@ -464,25 +340,15 @@ export class EncryptionUtils {
|
|
|
464
340
|
/**
|
|
465
341
|
* Verifies if a message appears to be encrypted with OpenPGP.
|
|
466
342
|
*
|
|
467
|
-
* @param
|
|
468
|
-
* @returns
|
|
469
|
-
*
|
|
470
|
-
* **Code example:**
|
|
343
|
+
* @param message - Message to verify.
|
|
344
|
+
* @returns `true` if the message appears to be encrypted, `false` if not.
|
|
471
345
|
*
|
|
346
|
+
* @example
|
|
472
347
|
* ```ts
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
* wV4DqdeRpqH+jaISAQdAsvBFxikvjxRqC7ZlDe98cLd7/aeCEI/AcL8PpVKK
|
|
476
|
-
* mC0wKlwxNg/ADi55z9jcYFuMC4kKE+C/teM+JqiI8DO9AwassQUvKFtULnpx
|
|
477
|
-
* h2jaOjC/0sAQASjUsIFK8zbuDgk/P8T9Npn6px+GlJPg9K90iwtPWiIp0eyW
|
|
478
|
-
* 4zXamJZT51k2DyaUX/Rsc6P4PYhQRKjt0yxtH0jHPmKkLC/9eBeFf4GP0zlZ
|
|
479
|
-
* 18xMZ8uCpQCma708Gz0sJYxEz3u/eZdHD7Mc7tWQKyJG8MsTwM1P+fdK1X75
|
|
480
|
-
* L9UryJG2AY+6kKZhG4dqjNxiO4fWluiB2u7iMF+iLEyE3SQCEYorWMC+NDWi
|
|
481
|
-
* QIJZ7oQ2w7BaPo1a991gvTOSNm5v2x44KfqPI1uj859BjsQTCA==
|
|
482
|
-
* =tsmI
|
|
483
|
-
* -----END PGP MESSAGE-----`;
|
|
348
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
484
349
|
*
|
|
485
|
-
* const
|
|
350
|
+
* const message = '-----BEGIN PGP MESSAGE-----...';
|
|
351
|
+
* const isEncrypted = EncryptionUtils.isEncrypted(message);
|
|
486
352
|
*
|
|
487
353
|
* if (isEncrypted) {
|
|
488
354
|
* console.log('The message is encrypted with OpenPGP.');
|
package/src/error.ts
CHANGED
|
@@ -3,42 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const ErrorStakingMissing = new Error('Staking contract is missing');
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* @constant {Error} - The Storage client not initialized.
|
|
8
|
-
*/
|
|
9
|
-
export const ErrorStorageClientNotInitialized = new Error(
|
|
10
|
-
'Storage client not initialized'
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @constant {Error} - The Storage client does not exist.
|
|
15
|
-
*/
|
|
16
|
-
export const ErrorStorageClientNotExists = new Error(
|
|
17
|
-
'Storage client does not exist'
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @constant {Error} - The Storage credentials are missing.
|
|
22
|
-
*/
|
|
23
|
-
export const ErrorStorageCredentialsMissing = new Error(
|
|
24
|
-
'Storage credentials are missing'
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @constant {Error} - The Storage bucket not found.
|
|
29
|
-
*/
|
|
30
|
-
export const ErrorStorageBucketNotFound = new Error('Bucket not found');
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @constant {Error} - The Storage file not found.
|
|
34
|
-
*/
|
|
35
|
-
export const ErrorStorageFileNotFound = new Error('File not found');
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @constant {Error} - The Storage file not uploaded.
|
|
39
|
-
*/
|
|
40
|
-
export const ErrorStorageFileNotUploaded = new Error('File not uploaded');
|
|
41
|
-
|
|
42
6
|
/**
|
|
43
7
|
* @constant {Error} - The KVStore key cannot be empty.
|
|
44
8
|
*/
|