@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.
@@ -1,7 +1,45 @@
1
1
  import * as openpgp from 'openpgp';
2
2
  import { IKeyPair } from './interfaces';
3
3
  /**
4
- * Class for encryption and decryption operations.
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
- * Signs and encrypts a message using the specified public keys.
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 - The message to encrypt.
26
- * @param {string[]} publicKeys - The public keys in armored format.
27
- * @returns {Promise<string>} - The encrypted message.
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
- * Decrypts an encrypted message using the private key.
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
- * @param {string} message - The encrypted message.
34
- * @param {string} publicKey - Optional: The public key in armored format for signature verification.
35
- * @returns {Promise<string>} - The decrypted message.
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
- * Signs a message using the private key.
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
- * @param {string} message - The message to sign.
42
- * @returns {Promise<string>} - The signed message.
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
- * Verifies the signature of a signed message using the public key.
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
- * @param {string} message - The signed message.
54
- * @param {string} publicKey - The public key in armored format.
55
- * @returns {Promise<boolean>} - A boolean indicating if the signature is valid.
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
- * Gets the signed data from a signed message.
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
- * @param {string} message - The signed message.
62
- * @returns {Promise<string>} - The signed data.
63
- * @throws {Error} - An error object if an error occurred.
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
- * Generates a key pair for encryption and decryption.
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
- * @param {string} name - The name for the key pair.
70
- * @param {string} email - The email for the key pair.
71
- * @param {string} passphrase - The passphrase used to encrypt the private key.
72
- * @returns {Promise<IKeyPair>} - The generated key pair.
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
- * Encrypts a message using the specified public keys.
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
- * @param {string} message - The message to encrypt.
79
- * @param {string[]} publicKeys - The public keys in armored format.
80
- * @returns {Promise<string>} - The encrypted message.
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
  }
@@ -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;AACxC;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAqB;IAEvC;;;;OAIG;gBACS,UAAU,EAAE,OAAO,CAAC,UAAU;IAI1C;;;;;;OAMG;WACiB,KAAK,CACvB,iBAAiB,EAAE,MAAM,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC;IAkBtB;;;;;;OAMG;IACU,cAAc,CACzB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,CAAC;IAiBlB;;;;;;OAMG;IACU,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB1E;;;;;OAKG;IACU,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYpD;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B;;;;;;OAMG;WACiB,MAAM,CACxB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IAgBnB;;;;;;OAMG;WACiB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAYnE;;;;;;;OAOG;WACiB,eAAe,CACjC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,SAAK,GACd,OAAO,CAAC,QAAQ,CAAC;IAkBpB;;;;;;OAMG;WACiB,OAAO,CACzB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,CAAC;CAenB"}
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"}
@@ -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
- * Class for encryption and decryption operations.
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
- * Signs and encrypts a message using the specified public keys.
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 - The message to encrypt.
64
- * @param {string[]} publicKeys - The public keys in armored format.
65
- * @returns {Promise<string>} - The encrypted message.
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
- * Decrypts an encrypted message using the private key.
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
- * @param {string} message - The encrypted message.
82
- * @param {string} publicKey - Optional: The public key in armored format for signature verification.
83
- * @returns {Promise<string>} - The decrypted message.
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
- * Signs a message using the private key.
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
- * @param {string} message - The message to sign.
103
- * @returns {Promise<string>} - The signed message.
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
- * Verifies the signature of a signed message using the public key.
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
- * @param {string} message - The signed message.
126
- * @param {string} publicKey - The public key in armored format.
127
- * @returns {Promise<boolean>} - A boolean indicating if the signature is valid.
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
- * Gets the signed data from a signed message.
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
- * @param {string} message - The signed message.
147
- * @returns {Promise<string>} - The signed data.
148
- * @throws {Error} - An error object if an error occurred.
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
- * Generates a key pair for encryption and decryption.
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
- * @param {string} name - The name for the key pair.
165
- * @param {string} email - The email for the key pair.
166
- * @param {string} passphrase - The passphrase used to encrypt the private key.
167
- * @returns {Promise<IKeyPair>} - The generated key pair.
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
- * Encrypts a message using the specified public keys.
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
- * @param {string} message - The message to encrypt.
188
- * @param {string[]} publicKeys - The public keys in armored format.
189
- * @returns {Promise<string>} - The encrypted message.
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;