@human-protocol/sdk 1.1.14 → 1.1.16
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/encryption.d.ts +245 -29
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +245 -29
- package/dist/escrow.d.ts +731 -117
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +739 -121
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/kvstore.d.ts +138 -15
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +138 -15
- package/dist/staking.d.ts +324 -54
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +326 -56
- package/dist/statistics.d.ts +266 -16
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +266 -16
- package/dist/storage.d.ts +155 -16
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +155 -16
- package/package.json +18 -1
- package/src/encryption.ts +246 -29
- package/src/escrow.ts +739 -121
- package/src/index.ts +3 -0
- package/src/kvstore.ts +138 -15
- package/src/staking.ts +326 -56
- package/src/statistics.ts +266 -16
- package/src/storage.ts +156 -17
package/dist/encryption.d.ts
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
import * as openpgp from 'openpgp';
|
|
2
2
|
import { IKeyPair } from './interfaces';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* ## Introduction
|
|
5
|
+
*
|
|
6
|
+
* Class for sign and decrypt messages.
|
|
7
|
+
*
|
|
8
|
+
* The algorithm includes the implementation of the [PGP encryption algorithm](https://github.com/openpgpjs/openpgpjs) multi-public key encryption on typescript.
|
|
9
|
+
* Using the vanilla [ed25519](https://en.wikipedia.org/wiki/EdDSA#Ed25519) implementation Schnorr signatures for signature and [curve25519](https://en.wikipedia.org/wiki/Curve25519) for encryption. [Learn more](https://wiki.polkadot.network/docs/learn-cryptography).
|
|
10
|
+
*
|
|
11
|
+
* To get an instance of this class, is recommended to initialize it using the static `build` method.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* static async build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* ## Installation
|
|
18
|
+
*
|
|
19
|
+
* ### npm
|
|
20
|
+
* ```bash
|
|
21
|
+
* npm install @human-protocol/sdk
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ### yarn
|
|
25
|
+
* ```bash
|
|
26
|
+
* yarn install @human-protocol/sdk
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ## Input parameters
|
|
30
|
+
*
|
|
31
|
+
* - `privateKeyArmored` - The encrypted private key in armored format.
|
|
32
|
+
* - `passphrase` - The passphrase for the private key.
|
|
33
|
+
*
|
|
34
|
+
* ## Code example
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
38
|
+
*
|
|
39
|
+
* const privateKey = 'Armored_priv_key';
|
|
40
|
+
* const passphrase = 'example_passphrase';
|
|
41
|
+
* const encription = await Encryption.build(privateKey, passphrase);
|
|
42
|
+
* ```
|
|
5
43
|
*/
|
|
6
44
|
export declare class Encryption {
|
|
7
45
|
private privateKey;
|
|
@@ -20,64 +58,242 @@ export declare class Encryption {
|
|
|
20
58
|
*/
|
|
21
59
|
static build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>;
|
|
22
60
|
/**
|
|
23
|
-
*
|
|
61
|
+
* This function signs and encrypts a message using the private key used to initialize the client and the specified public keys.
|
|
24
62
|
*
|
|
25
|
-
* @param {string} message
|
|
26
|
-
* @param {string[]} publicKeys
|
|
27
|
-
* @returns {Promise<string>}
|
|
63
|
+
* @param {string} message Message to sign and encrypt.
|
|
64
|
+
* @param {string[]} publicKeys Array of public keys to use for encryption.
|
|
65
|
+
* @returns {Promise<string>} Message signed and encrypted.
|
|
66
|
+
*
|
|
67
|
+
* **Code example**
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
71
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
72
|
+
*
|
|
73
|
+
* const privateKey = 'Armored_priv_key';
|
|
74
|
+
* const passphrase = 'example_passphrase';
|
|
75
|
+
* const encription = await Encryption.build(privateKey, passphrase);
|
|
76
|
+
* const publicKey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
77
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
78
|
+
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
79
|
+
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
80
|
+
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
81
|
+
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
82
|
+
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
83
|
+
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
84
|
+
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
85
|
+
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
86
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
87
|
+
*
|
|
88
|
+
* const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
89
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
|
|
90
|
+
* FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
91
|
+
* CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
|
|
92
|
+
* bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
|
|
93
|
+
* ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
|
|
94
|
+
* CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
|
|
95
|
+
* bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
|
|
96
|
+
* bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
|
|
97
|
+
* s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
|
|
98
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
99
|
+
*
|
|
100
|
+
* const publicKeys = [publicKey1, publicKey2];
|
|
101
|
+
* const resultMessage = await encription.signAndEncrypt('message', publicKeys);
|
|
102
|
+
* ```
|
|
28
103
|
*/
|
|
29
104
|
signAndEncrypt(message: string, publicKeys: string[]): Promise<string>;
|
|
30
105
|
/**
|
|
31
|
-
*
|
|
106
|
+
* This function decrypt message message using the private key. In addition, the public key can be added for signature verification.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} message Message to decrypt.
|
|
109
|
+
* @param {string} publicKey Public key used to verify signature if needed. Optional.
|
|
110
|
+
* @returns {Promise<string>} Message decrypted.
|
|
111
|
+
*
|
|
112
|
+
* **Code example**
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
32
116
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
117
|
+
* const privateKey = 'Armored_priv_key';
|
|
118
|
+
* const passphrase = 'example_passphrase';
|
|
119
|
+
* const encription = await Encryption.build(privateKey, passphrase);
|
|
120
|
+
*
|
|
121
|
+
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
122
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
123
|
+
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
124
|
+
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
125
|
+
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
126
|
+
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
127
|
+
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
128
|
+
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
129
|
+
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
130
|
+
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
131
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
132
|
+
*
|
|
133
|
+
* const resultMessage = await encription.decrypt('message');
|
|
134
|
+
* ```
|
|
36
135
|
*/
|
|
37
136
|
decrypt(message: string, publicKey?: string): Promise<string>;
|
|
38
137
|
/**
|
|
39
|
-
*
|
|
138
|
+
* This function signs a message using the private key used to initialize the client.
|
|
139
|
+
*
|
|
140
|
+
* @param {string} message Message to sign.
|
|
141
|
+
* @returns {Promise<string>} Message signed.
|
|
142
|
+
*
|
|
143
|
+
* **Code example**
|
|
40
144
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
147
|
+
*
|
|
148
|
+
* const privateKey = 'Armored_priv_key';
|
|
149
|
+
* const passphrase = 'example_passphrase';
|
|
150
|
+
* const encription = await Encryption.build(privateKey, passphrase);
|
|
151
|
+
*
|
|
152
|
+
* const resultMessage = await encription.sign('message');
|
|
153
|
+
* ```
|
|
43
154
|
*/
|
|
44
155
|
sign(message: string): Promise<string>;
|
|
45
156
|
}
|
|
46
157
|
/**
|
|
158
|
+
* ## Introduction
|
|
159
|
+
*
|
|
47
160
|
* Utility class for encryption-related operations.
|
|
161
|
+
*
|
|
162
|
+
* ## Installation
|
|
163
|
+
*
|
|
164
|
+
* ### npm
|
|
165
|
+
* ```bash
|
|
166
|
+
* npm install @human-protocol/sdk
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* ### yarn
|
|
170
|
+
* ```bash
|
|
171
|
+
* yarn install @human-protocol/sdk
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* ## Code example
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
178
|
+
*
|
|
179
|
+
* const keyPair = await EncryptionUtils.generateKeyPair('Human', 'human@hmt.ai');
|
|
180
|
+
* ```
|
|
48
181
|
*/
|
|
49
182
|
export declare class EncryptionUtils {
|
|
50
183
|
/**
|
|
51
|
-
*
|
|
184
|
+
* This function verifies the signature of a signed message using the public key.
|
|
185
|
+
*
|
|
186
|
+
* @param {string} message Message to verify.
|
|
187
|
+
* @param {string} publicKey Public key to verify that the message was sign by a specific source.
|
|
188
|
+
* @returns {Promise<boolean>} True if verified. False if not verified.
|
|
52
189
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
190
|
+
* **Code example**
|
|
191
|
+
*
|
|
192
|
+
* ```ts
|
|
193
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
194
|
+
*
|
|
195
|
+
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
196
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
197
|
+
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
198
|
+
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
199
|
+
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
200
|
+
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
201
|
+
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
202
|
+
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
203
|
+
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
204
|
+
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
205
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
206
|
+
*
|
|
207
|
+
* const result = await EncriptionUtils.verify('message', publicKey);
|
|
208
|
+
* ```
|
|
56
209
|
*/
|
|
57
210
|
static verify(message: string, publicKey: string): Promise<boolean>;
|
|
58
211
|
/**
|
|
59
|
-
*
|
|
212
|
+
* This function gets signed data from a signed message.
|
|
213
|
+
*
|
|
214
|
+
* @param {string} message Message.
|
|
215
|
+
* @returns {Promise<string>} Signed data.
|
|
60
216
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
217
|
+
* **Code example**
|
|
218
|
+
*
|
|
219
|
+
* ```ts
|
|
220
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
221
|
+
*
|
|
222
|
+
* const signedData = await EncriptionUtils.getSignedData('message');
|
|
223
|
+
* ```
|
|
64
224
|
*/
|
|
65
225
|
static getSignedData(message: string): Promise<string>;
|
|
66
226
|
/**
|
|
67
|
-
*
|
|
227
|
+
* This function generates a key pair for encryption and decryption.
|
|
228
|
+
*
|
|
229
|
+
* @param {string} name Name for the key pair.
|
|
230
|
+
* @param {string} email Email for the key pair.
|
|
231
|
+
* @param {string} passphrase Passphrase to encrypt the private key. Optional.
|
|
232
|
+
* @returns {Promise<IKeyPair>} Key pair generated.
|
|
233
|
+
*
|
|
234
|
+
* **Code example**
|
|
68
235
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
238
|
+
*
|
|
239
|
+
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
240
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
241
|
+
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
242
|
+
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
243
|
+
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
244
|
+
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
245
|
+
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
246
|
+
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
247
|
+
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
248
|
+
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
249
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
250
|
+
*
|
|
251
|
+
* const name = 'YOUR_NAME';
|
|
252
|
+
* const email = 'YOUR_EMAIL';
|
|
253
|
+
* const passphrase = 'YOUR_PASSPHRASE';
|
|
254
|
+
* const result = await EncriptionUtils.generateKeyPair(name, email, passphrase);
|
|
255
|
+
* ```
|
|
73
256
|
*/
|
|
74
257
|
static generateKeyPair(name: string, email: string, passphrase?: string): Promise<IKeyPair>;
|
|
75
258
|
/**
|
|
76
|
-
*
|
|
259
|
+
* This function encrypts a message using the specified public keys.
|
|
260
|
+
*
|
|
261
|
+
* @param {string} message Message to encrypt.
|
|
262
|
+
* @param {string} publicKey Array of public keys to use for encryption.
|
|
263
|
+
* @returns {Promise<string>} Message encrypted.
|
|
264
|
+
*
|
|
265
|
+
* **Code example**
|
|
266
|
+
*
|
|
267
|
+
* ```ts
|
|
268
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
269
|
+
*
|
|
270
|
+
* const publicKey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
271
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
272
|
+
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
273
|
+
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
274
|
+
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
275
|
+
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
276
|
+
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
277
|
+
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
278
|
+
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
279
|
+
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
280
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
281
|
+
*
|
|
282
|
+
* const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
283
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
|
|
284
|
+
* FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
285
|
+
* CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
|
|
286
|
+
* bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
|
|
287
|
+
* ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
|
|
288
|
+
* CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
|
|
289
|
+
* bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
|
|
290
|
+
* bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
|
|
291
|
+
* s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
|
|
292
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
77
293
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
294
|
+
* const publicKeys = [publicKey1, publicKey2]
|
|
295
|
+
* const result = await EncriptionUtils.encrypt('message', publicKeys);
|
|
296
|
+
* ```
|
|
81
297
|
*/
|
|
82
298
|
static encrypt(message: string, publicKeys: string[]): Promise<string>;
|
|
83
299
|
}
|
package/dist/encryption.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;IACU,cAAc,CACzB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,CAAC;IAiBlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB1E;;;;;;;;;;;;;;;;;OAiBG;IACU,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,eAAe;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;WACiB,MAAM,CACxB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IAgBnB;;;;;;;;;;;;;OAaG;WACiB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAYnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;WACiB,eAAe,CACjC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,SAAK,GACd,OAAO,CAAC,QAAQ,CAAC;IAkBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;WACiB,OAAO,CACzB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,CAAC;CAenB"}
|
package/dist/encryption.js
CHANGED
|
@@ -26,7 +26,45 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.EncryptionUtils = exports.Encryption = void 0;
|
|
27
27
|
const openpgp = __importStar(require("openpgp"));
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* ## Introduction
|
|
30
|
+
*
|
|
31
|
+
* Class for sign and decrypt messages.
|
|
32
|
+
*
|
|
33
|
+
* The algorithm includes the implementation of the [PGP encryption algorithm](https://github.com/openpgpjs/openpgpjs) multi-public key encryption on typescript.
|
|
34
|
+
* Using the vanilla [ed25519](https://en.wikipedia.org/wiki/EdDSA#Ed25519) implementation Schnorr signatures for signature and [curve25519](https://en.wikipedia.org/wiki/Curve25519) for encryption. [Learn more](https://wiki.polkadot.network/docs/learn-cryptography).
|
|
35
|
+
*
|
|
36
|
+
* To get an instance of this class, is recommended to initialize it using the static `build` method.
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* static async build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ## Installation
|
|
43
|
+
*
|
|
44
|
+
* ### npm
|
|
45
|
+
* ```bash
|
|
46
|
+
* npm install @human-protocol/sdk
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* ### yarn
|
|
50
|
+
* ```bash
|
|
51
|
+
* yarn install @human-protocol/sdk
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* ## Input parameters
|
|
55
|
+
*
|
|
56
|
+
* - `privateKeyArmored` - The encrypted private key in armored format.
|
|
57
|
+
* - `passphrase` - The passphrase for the private key.
|
|
58
|
+
*
|
|
59
|
+
* ## Code example
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
63
|
+
*
|
|
64
|
+
* const privateKey = 'Armored_priv_key';
|
|
65
|
+
* const passphrase = 'example_passphrase';
|
|
66
|
+
* const encription = await Encryption.build(privateKey, passphrase);
|
|
67
|
+
* ```
|
|
30
68
|
*/
|
|
31
69
|
class Encryption {
|
|
32
70
|
/**
|
|
@@ -58,11 +96,48 @@ class Encryption {
|
|
|
58
96
|
}));
|
|
59
97
|
}
|
|
60
98
|
/**
|
|
61
|
-
*
|
|
99
|
+
* This function signs and encrypts a message using the private key used to initialize the client and the specified public keys.
|
|
62
100
|
*
|
|
63
|
-
* @param {string} message
|
|
64
|
-
* @param {string[]} publicKeys
|
|
65
|
-
* @returns {Promise<string>}
|
|
101
|
+
* @param {string} message Message to sign and encrypt.
|
|
102
|
+
* @param {string[]} publicKeys Array of public keys to use for encryption.
|
|
103
|
+
* @returns {Promise<string>} Message signed and encrypted.
|
|
104
|
+
*
|
|
105
|
+
* **Code example**
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
109
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
110
|
+
*
|
|
111
|
+
* const privateKey = 'Armored_priv_key';
|
|
112
|
+
* const passphrase = 'example_passphrase';
|
|
113
|
+
* const encription = 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-----`;
|
|
137
|
+
*
|
|
138
|
+
* const publicKeys = [publicKey1, publicKey2];
|
|
139
|
+
* const resultMessage = await encription.signAndEncrypt('message', publicKeys);
|
|
140
|
+
* ```
|
|
66
141
|
*/
|
|
67
142
|
async signAndEncrypt(message, publicKeys) {
|
|
68
143
|
const plaintext = message;
|
|
@@ -76,11 +151,35 @@ class Encryption {
|
|
|
76
151
|
return encrypted;
|
|
77
152
|
}
|
|
78
153
|
/**
|
|
79
|
-
*
|
|
154
|
+
* This function decrypt message message using the private key. In addition, the public key can be added for signature verification.
|
|
155
|
+
*
|
|
156
|
+
* @param {string} message Message to decrypt.
|
|
157
|
+
* @param {string} publicKey Public key used to verify signature if needed. Optional.
|
|
158
|
+
* @returns {Promise<string>} Message decrypted.
|
|
159
|
+
*
|
|
160
|
+
* **Code example**
|
|
161
|
+
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
80
164
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
165
|
+
* const privateKey = 'Armored_priv_key';
|
|
166
|
+
* const passphrase = 'example_passphrase';
|
|
167
|
+
* const encription = await Encryption.build(privateKey, passphrase);
|
|
168
|
+
*
|
|
169
|
+
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
170
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
171
|
+
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
172
|
+
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
173
|
+
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
174
|
+
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
175
|
+
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
176
|
+
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
177
|
+
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
178
|
+
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
179
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
180
|
+
*
|
|
181
|
+
* const resultMessage = await encription.decrypt('message');
|
|
182
|
+
* ```
|
|
84
183
|
*/
|
|
85
184
|
async decrypt(message, publicKey) {
|
|
86
185
|
const pgpMessage = await openpgp.readMessage({ armoredMessage: message });
|
|
@@ -97,10 +196,22 @@ class Encryption {
|
|
|
97
196
|
return decrypted;
|
|
98
197
|
}
|
|
99
198
|
/**
|
|
100
|
-
*
|
|
199
|
+
* This function signs a message using the private key used to initialize the client.
|
|
200
|
+
*
|
|
201
|
+
* @param {string} message Message to sign.
|
|
202
|
+
* @returns {Promise<string>} Message signed.
|
|
203
|
+
*
|
|
204
|
+
* **Code example**
|
|
101
205
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
206
|
+
* ```ts
|
|
207
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
208
|
+
*
|
|
209
|
+
* const privateKey = 'Armored_priv_key';
|
|
210
|
+
* const passphrase = 'example_passphrase';
|
|
211
|
+
* const encription = await Encryption.build(privateKey, passphrase);
|
|
212
|
+
*
|
|
213
|
+
* const resultMessage = await encription.sign('message');
|
|
214
|
+
* ```
|
|
104
215
|
*/
|
|
105
216
|
async sign(message) {
|
|
106
217
|
const unsignedMessage = await openpgp.createCleartextMessage({
|
|
@@ -116,15 +227,57 @@ class Encryption {
|
|
|
116
227
|
}
|
|
117
228
|
exports.Encryption = Encryption;
|
|
118
229
|
/**
|
|
230
|
+
* ## Introduction
|
|
231
|
+
*
|
|
119
232
|
* Utility class for encryption-related operations.
|
|
233
|
+
*
|
|
234
|
+
* ## Installation
|
|
235
|
+
*
|
|
236
|
+
* ### npm
|
|
237
|
+
* ```bash
|
|
238
|
+
* npm install @human-protocol/sdk
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* ### yarn
|
|
242
|
+
* ```bash
|
|
243
|
+
* yarn install @human-protocol/sdk
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* ## Code example
|
|
247
|
+
*
|
|
248
|
+
* ```ts
|
|
249
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
250
|
+
*
|
|
251
|
+
* const keyPair = await EncryptionUtils.generateKeyPair('Human', 'human@hmt.ai');
|
|
252
|
+
* ```
|
|
120
253
|
*/
|
|
121
254
|
class EncryptionUtils {
|
|
122
255
|
/**
|
|
123
|
-
*
|
|
256
|
+
* This function verifies the signature of a signed message using the public key.
|
|
257
|
+
*
|
|
258
|
+
* @param {string} message Message to verify.
|
|
259
|
+
* @param {string} publicKey Public key to verify that the message was sign by a specific source.
|
|
260
|
+
* @returns {Promise<boolean>} True if verified. False if not verified.
|
|
124
261
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
262
|
+
* **Code example**
|
|
263
|
+
*
|
|
264
|
+
* ```ts
|
|
265
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
266
|
+
*
|
|
267
|
+
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
268
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
269
|
+
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
270
|
+
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
271
|
+
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
272
|
+
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
273
|
+
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
274
|
+
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
275
|
+
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
276
|
+
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
277
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
278
|
+
*
|
|
279
|
+
* const result = await EncriptionUtils.verify('message', publicKey);
|
|
280
|
+
* ```
|
|
128
281
|
*/
|
|
129
282
|
static async verify(message, publicKey) {
|
|
130
283
|
const pgpPublicKey = await openpgp.readKey({ armoredKey: publicKey });
|
|
@@ -141,11 +294,18 @@ class EncryptionUtils {
|
|
|
141
294
|
}
|
|
142
295
|
}
|
|
143
296
|
/**
|
|
144
|
-
*
|
|
297
|
+
* This function gets signed data from a signed message.
|
|
298
|
+
*
|
|
299
|
+
* @param {string} message Message.
|
|
300
|
+
* @returns {Promise<string>} Signed data.
|
|
145
301
|
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
302
|
+
* **Code example**
|
|
303
|
+
*
|
|
304
|
+
* ```ts
|
|
305
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
306
|
+
*
|
|
307
|
+
* const signedData = await EncriptionUtils.getSignedData('message');
|
|
308
|
+
* ```
|
|
149
309
|
*/
|
|
150
310
|
static async getSignedData(message) {
|
|
151
311
|
const signedMessage = await openpgp.readCleartextMessage({
|
|
@@ -159,12 +319,35 @@ class EncryptionUtils {
|
|
|
159
319
|
}
|
|
160
320
|
}
|
|
161
321
|
/**
|
|
162
|
-
*
|
|
322
|
+
* This function generates a key pair for encryption and decryption.
|
|
323
|
+
*
|
|
324
|
+
* @param {string} name Name for the key pair.
|
|
325
|
+
* @param {string} email Email for the key pair.
|
|
326
|
+
* @param {string} passphrase Passphrase to encrypt the private key. Optional.
|
|
327
|
+
* @returns {Promise<IKeyPair>} Key pair generated.
|
|
328
|
+
*
|
|
329
|
+
* **Code example**
|
|
163
330
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
331
|
+
* ```ts
|
|
332
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
333
|
+
*
|
|
334
|
+
* const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
335
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
336
|
+
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
337
|
+
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
338
|
+
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
339
|
+
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
340
|
+
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
341
|
+
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
342
|
+
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
343
|
+
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
344
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
345
|
+
*
|
|
346
|
+
* const name = 'YOUR_NAME';
|
|
347
|
+
* const email = 'YOUR_EMAIL';
|
|
348
|
+
* const passphrase = 'YOUR_PASSPHRASE';
|
|
349
|
+
* const result = await EncriptionUtils.generateKeyPair(name, email, passphrase);
|
|
350
|
+
* ```
|
|
168
351
|
*/
|
|
169
352
|
static async generateKeyPair(name, email, passphrase = '') {
|
|
170
353
|
const { privateKey, publicKey, revocationCertificate } = await openpgp.generateKey({
|
|
@@ -182,11 +365,44 @@ class EncryptionUtils {
|
|
|
182
365
|
};
|
|
183
366
|
}
|
|
184
367
|
/**
|
|
185
|
-
*
|
|
368
|
+
* This function encrypts a message using the specified public keys.
|
|
369
|
+
*
|
|
370
|
+
* @param {string} message Message to encrypt.
|
|
371
|
+
* @param {string} publicKey Array of public keys to use for encryption.
|
|
372
|
+
* @returns {Promise<string>} Message encrypted.
|
|
373
|
+
*
|
|
374
|
+
* **Code example**
|
|
375
|
+
*
|
|
376
|
+
* ```ts
|
|
377
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
378
|
+
*
|
|
379
|
+
* const publicKey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
380
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
|
|
381
|
+
* WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
382
|
+
* CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
|
|
383
|
+
* XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
|
|
384
|
+
* X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
|
|
385
|
+
* CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
|
|
386
|
+
* YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
|
|
387
|
+
* XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
|
|
388
|
+
* UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
|
|
389
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
390
|
+
*
|
|
391
|
+
* const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
392
|
+
* xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
|
|
393
|
+
* FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
|
|
394
|
+
* CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
|
|
395
|
+
* bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
|
|
396
|
+
* ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
|
|
397
|
+
* CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
|
|
398
|
+
* bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
|
|
399
|
+
* bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
|
|
400
|
+
* s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
|
|
401
|
+
* -----END PGP PUBLIC KEY BLOCK-----`;
|
|
186
402
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
403
|
+
* const publicKeys = [publicKey1, publicKey2]
|
|
404
|
+
* const result = await EncriptionUtils.encrypt('message', publicKeys);
|
|
405
|
+
* ```
|
|
190
406
|
*/
|
|
191
407
|
static async encrypt(message, publicKeys) {
|
|
192
408
|
const plaintext = message;
|