@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.
Files changed (63) hide show
  1. package/dist/base.d.ts +4 -5
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +4 -5
  4. package/dist/constants.js +6 -6
  5. package/dist/encryption.d.ts +68 -203
  6. package/dist/encryption.d.ts.map +1 -1
  7. package/dist/encryption.js +66 -202
  8. package/dist/error.d.ts +0 -24
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +2 -26
  11. package/dist/escrow.d.ts +427 -780
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +314 -684
  14. package/dist/graphql/queries/operator.d.ts.map +1 -1
  15. package/dist/graphql/queries/operator.js +3 -1
  16. package/dist/graphql/types.d.ts.map +1 -1
  17. package/dist/index.d.ts +3 -4
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -4
  20. package/dist/kvstore.d.ts +119 -181
  21. package/dist/kvstore.d.ts.map +1 -1
  22. package/dist/kvstore.js +119 -182
  23. package/dist/operator.d.ts +59 -30
  24. package/dist/operator.d.ts.map +1 -1
  25. package/dist/operator.js +59 -30
  26. package/dist/staking.d.ts +135 -134
  27. package/dist/staking.d.ts.map +1 -1
  28. package/dist/staking.js +135 -134
  29. package/dist/statistics.d.ts +104 -134
  30. package/dist/statistics.d.ts.map +1 -1
  31. package/dist/statistics.js +119 -144
  32. package/dist/transaction.d.ts +36 -15
  33. package/dist/transaction.d.ts.map +1 -1
  34. package/dist/transaction.js +36 -15
  35. package/dist/types.d.ts +0 -54
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/utils.d.ts +31 -17
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/utils.js +31 -17
  40. package/dist/worker.d.ts +35 -14
  41. package/dist/worker.d.ts.map +1 -1
  42. package/dist/worker.js +35 -14
  43. package/package.json +7 -24
  44. package/src/base.ts +4 -5
  45. package/src/constants.ts +6 -6
  46. package/src/encryption.ts +69 -203
  47. package/src/error.ts +0 -36
  48. package/src/escrow.ts +425 -780
  49. package/src/graphql/queries/operator.ts +3 -1
  50. package/src/graphql/types.ts +4 -2
  51. package/src/index.ts +4 -5
  52. package/src/kvstore.ts +120 -183
  53. package/src/operator.ts +59 -30
  54. package/src/staking.ts +135 -134
  55. package/src/statistics.ts +125 -146
  56. package/src/transaction.ts +36 -15
  57. package/src/types.ts +0 -57
  58. package/src/utils.ts +31 -17
  59. package/src/worker.ts +35 -14
  60. package/dist/storage.d.ts +0 -186
  61. package/dist/storage.d.ts.map +0 -1
  62. package/dist/storage.js +0 -319
  63. package/src/storage.ts +0 -313
package/dist/base.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { ContractRunner } from 'ethers';
2
2
  import { NetworkData } from './types';
3
3
  /**
4
- * ## Introduction
5
- *
6
- * This class is used as a base class for other clients making on-chain calls.
4
+ * Base class for clients making on-chain calls.
7
5
  *
6
+ * This class provides common functionality for interacting with Ethereum contracts.
8
7
  */
9
8
  export declare abstract class BaseEthersClient {
10
9
  protected runner: ContractRunner;
@@ -12,8 +11,8 @@ export declare abstract class BaseEthersClient {
12
11
  /**
13
12
  * **BaseClient constructor**
14
13
  *
15
- * @param {ContractRunner} runner The Signer or Provider object to interact with the Ethereum network
16
- * @param {NetworkData} networkData The network information required to connect to the contracts
14
+ * @param runner - The Signer or Provider object to interact with the Ethereum network
15
+ * @param networkData - The network information required to connect to the contracts
17
16
  */
18
17
  constructor(runner: ContractRunner, networkData: NetworkData);
19
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;GAKG;AACH,8BAAsB,gBAAgB;IACpC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC;IAC1B,WAAW,EAAE,WAAW,CAAC;IAEhC;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;CAI7D"}
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;GAIG;AACH,8BAAsB,gBAAgB;IACpC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC;IAC1B,WAAW,EAAE,WAAW,CAAC;IAEhC;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;CAI7D"}
package/dist/base.js CHANGED
@@ -2,17 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseEthersClient = void 0;
4
4
  /**
5
- * ## Introduction
6
- *
7
- * This class is used as a base class for other clients making on-chain calls.
5
+ * Base class for clients making on-chain calls.
8
6
  *
7
+ * This class provides common functionality for interacting with Ethereum contracts.
9
8
  */
10
9
  class BaseEthersClient {
11
10
  /**
12
11
  * **BaseClient constructor**
13
12
  *
14
- * @param {ContractRunner} runner The Signer or Provider object to interact with the Ethereum network
15
- * @param {NetworkData} networkData The network information required to connect to the contracts
13
+ * @param runner - The Signer or Provider object to interact with the Ethereum network
14
+ * @param networkData - The network information required to connect to the contracts
16
15
  */
17
16
  constructor(runner, networkData) {
18
17
  this.networkData = networkData;
package/dist/constants.js CHANGED
@@ -28,7 +28,7 @@ exports.NETWORKS = {
28
28
  stakingAddress: '0xEf6Da3aB52c33925Be3F84038193a7e1331F51E6',
29
29
  kvstoreAddress: '0xB6d36B1CDaD50302BCB3DB43bAb0D349458e1b8D',
30
30
  subgraphUrl: 'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
31
- subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmXGmcjEtwwEgB83KE2ECjjYY38kLMqzaq4ip8GWY7A6zz',
31
+ subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmeCB3KX49nRAkzgqancc3yL3VMJvt65YtL1zrLCFgr2n5',
32
32
  oldSubgraphUrl: '',
33
33
  oldFactoryAddress: '',
34
34
  },
@@ -41,7 +41,7 @@ exports.NETWORKS = {
41
41
  stakingAddress: '0x2163e3A40032Af1C359ac731deaB48258b317890',
42
42
  kvstoreAddress: '0xCc0AF0635aa19fE799B6aFDBe28fcFAeA7f00a60',
43
43
  subgraphUrl: 'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
44
- subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmT4xNvZh8ymarrk1zdytjLhCW59iuTavsd4JgHS4LbCVB',
44
+ subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmcMntqZSTh8wJddxgp2hYcdw78wZFU86LHTHzJ1bTVUDc',
45
45
  oldSubgraphUrl: '',
46
46
  oldFactoryAddress: '',
47
47
  },
@@ -54,7 +54,7 @@ exports.NETWORKS = {
54
54
  stakingAddress: '0xE24e5C08E28331D24758b69A5E9f383D2bDD1c98',
55
55
  kvstoreAddress: '0x21A0C4CED7aE447fCf87D9FE3A29FA9B3AB20Ff1',
56
56
  subgraphUrl: 'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
57
- subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmdVdpm9NnFz5B8QyzhW1bW1nNfRWemTiFn2MrhYZGTSQD',
57
+ subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmRexbu8eLZ1iE7ZLMtKxAr9GJnQ1JVrXhybKq6JkJ9XLE',
58
58
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
59
59
  oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
60
60
  },
@@ -67,7 +67,7 @@ exports.NETWORKS = {
67
67
  stakingAddress: '0xD6D347ba6987519B4e42EcED43dF98eFf5465a23',
68
68
  kvstoreAddress: '0x32e27177BA6Ea91cf28dfd91a0Da9822A4b74EcF',
69
69
  subgraphUrl: 'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
70
- subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmZjYMktZe8RAz7W7qL33VZBV6AC57xsLyE1cEfv6NABdZ',
70
+ subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmfFBXsAP7nbckFx34XYcNq2hRnfoVNrfqCvuk7hmAtYJT',
71
71
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
72
72
  oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
73
73
  },
@@ -80,7 +80,7 @@ exports.NETWORKS = {
80
80
  stakingAddress: '0x01D115E9E8bF0C58318793624CC662a030D07F1D',
81
81
  kvstoreAddress: '0xbcB28672F826a50B03EE91B28145EAbddA73B2eD',
82
82
  subgraphUrl: 'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
83
- subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmUt9mmfNjtC5ZnQNiWHRbFG3k5zfngMuoTyky9jhXYqG2',
83
+ subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmUwHMDjnDHDB5cowGqd96SRJ1sZegoAPanjxBWUyLZghv',
84
84
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
85
85
  oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
86
86
  },
@@ -93,7 +93,7 @@ exports.NETWORKS = {
93
93
  stakingAddress: '0xffE496683F842a923110415b7278ded3F265f2C5',
94
94
  kvstoreAddress: '0x724AeFC243EdacCA27EAB86D3ec5a76Af4436Fc7',
95
95
  subgraphUrl: 'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
96
- subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmWRUFWpWoRRUh7Ec1HUJEwxc84DkP4iFTfLLsoVngJAPa',
96
+ subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmTJfcvVVmw8fe5CwRP6tZD5FzE2ESrm3ryygS1YZMYhM7',
97
97
  oldSubgraphUrl: '',
98
98
  oldFactoryAddress: '',
99
99
  },
@@ -3,313 +3,179 @@ import { IKeyPair } from './interfaces';
3
3
  /**
4
4
  * Type representing the data type of a message.
5
5
  * It can be either a string or a Uint8Array.
6
+ *
7
+ * @public
6
8
  */
7
- type MessageDataType = string | Uint8Array;
9
+ export type MessageDataType = string | Uint8Array;
8
10
  /**
9
- * ## Introduction
10
- *
11
11
  * Class for signing and decrypting messages.
12
12
  *
13
13
  * 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).
14
14
  *
15
- * To get an instance of this class, initialization is recommended using the static `build` method.
16
- *
17
- * ```ts
18
- * static async build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>
19
- * ```
20
- *
21
- * ## Installation
22
- *
23
- * ### npm
24
- * ```bash
25
- * npm install @human-protocol/sdk
26
- * ```
27
- *
28
- * ### yarn
29
- * ```bash
30
- * yarn install @human-protocol/sdk
31
- * ```
32
- *
33
- * ## Input parameters
34
- *
35
- * - `privateKeyArmored` - The encrypted private key in armored format.
36
- * - `passphrase` - The passphrase for the private key.
37
- *
38
- * ## Code example
39
- *
40
- * ```ts
41
- * import { Encryption } from '@human-protocol/sdk';
42
- *
43
- * const privateKey = 'Armored_priv_key';
44
- * const passphrase = 'example_passphrase';
45
- * const encryption = await Encryption.build(privateKey, passphrase);
46
- * ```
15
+ * To get an instance of this class, initialization is recommended using the static [`build`](/ts/classes/Encryption/#build) method.
47
16
  */
48
17
  export declare class Encryption {
49
18
  private privateKey;
50
19
  /**
51
20
  * Constructor for the Encryption class.
52
21
  *
53
- * @param {PrivateKey} privateKey - The private key.
22
+ * @param privateKey - The private key.
54
23
  */
55
24
  constructor(privateKey: openpgp.PrivateKey);
56
25
  /**
57
26
  * Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase.
58
27
  *
59
- * @param {string} privateKeyArmored - The encrypted private key in armored format.
60
- * @param {string} passphrase - Optional: The passphrase for the private key.
61
- * @returns {Promise<Encryption>} - The Encryption instance.
62
- */
63
- static build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>;
64
- /**
65
- * This function signs and encrypts a message using the private key used to initialize the client and the specified public keys.
66
- *
67
- * @param {MessageDataType} message Message to sign and encrypt.
68
- * @param {string[]} publicKeys Array of public keys to use for encryption.
69
- * @returns {Promise<string>} Message signed and encrypted.
70
- *
71
- * **Code example**
28
+ * @param privateKeyArmored - The encrypted private key in armored format.
29
+ * @param passphrase - The passphrase for the private key (optional).
30
+ * @returns The Encryption instance.
72
31
  *
32
+ * @example
73
33
  * ```ts
74
34
  * import { Encryption } from '@human-protocol/sdk';
75
- * import { EscrowClient } from '@human-protocol/sdk';
76
35
  *
77
36
  * const privateKey = 'Armored_priv_key';
78
37
  * const passphrase = 'example_passphrase';
79
38
  * const encryption = await Encryption.build(privateKey, passphrase);
80
- * const publicKey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
81
- * xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
82
- * WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
83
- * CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
84
- * XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
85
- * X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
86
- * CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
87
- * YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
88
- * XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
89
- * UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
90
- * -----END PGP PUBLIC KEY BLOCK-----`;
39
+ * ```
40
+ */
41
+ static build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>;
42
+ /**
43
+ * This function signs and encrypts a message using the private key used to initialize the client and the specified public keys.
44
+ *
45
+ * @param message - Message to sign and encrypt.
46
+ * @param publicKeys - Array of public keys to use for encryption.
47
+ * @returns Message signed and encrypted.
91
48
  *
92
- * const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
93
- * xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
94
- * FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
95
- * CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
96
- * bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
97
- * ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
98
- * CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
99
- * bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
100
- * bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
101
- * s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
102
- * -----END PGP PUBLIC KEY BLOCK-----`;
49
+ * @example
50
+ * ```ts
51
+ * const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
52
+ * const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
103
53
  *
104
54
  * const publicKeys = [publicKey1, publicKey2];
105
55
  * const resultMessage = await encryption.signAndEncrypt('message', publicKeys);
56
+ * console.log('Encrypted message:', resultMessage);
106
57
  * ```
107
58
  */
108
59
  signAndEncrypt(message: MessageDataType, publicKeys: string[]): Promise<string>;
109
60
  /**
110
61
  * This function decrypts messages using the private key. In addition, the public key can be added for signature verification.
111
62
  *
112
- * @param {string} message Message to decrypt.
113
- * @param {string} publicKey Public key used to verify signature if needed. This is optional.
114
- * @returns {Promise<Uint8Array>} Message decrypted.
115
- *
116
- * **Code example**
63
+ * @param message - Message to decrypt.
64
+ * @param publicKey - Public key used to verify signature if needed (optional).
65
+ * @returns Message decrypted.
66
+ * @throws Error If signature could not be verified when public key is provided
117
67
  *
68
+ * @example
118
69
  * ```ts
119
- * import { Encryption } from '@human-protocol/sdk';
120
- *
121
- * const privateKey = 'Armored_priv_key';
122
- * const passphrase = 'example_passphrase';
123
- * const encryption = await Encryption.build(privateKey, passphrase);
70
+ * const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
124
71
  *
125
- * const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
126
- * xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
127
- * WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
128
- * CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
129
- * XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
130
- * X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
131
- * CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
132
- * YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
133
- * XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
134
- * UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
135
- * -----END PGP PUBLIC KEY BLOCK-----`;
136
- *
137
- * const resultMessage = await encryption.decrypt('message');
72
+ * const resultMessage = await encryption.decrypt('message', publicKey);
73
+ * console.log('Decrypted message:', resultMessage);
138
74
  * ```
139
75
  */
140
76
  decrypt(message: string, publicKey?: string): Promise<Uint8Array>;
141
77
  /**
142
78
  * This function signs a message using the private key used to initialize the client.
143
79
  *
144
- * @param {string} message Message to sign.
145
- * @returns {Promise<string>} Message signed.
146
- *
147
- * **Code example**
80
+ * @param message - Message to sign.
81
+ * @returns Message signed.
148
82
  *
83
+ * @example
149
84
  * ```ts
150
- * import { Encryption } from '@human-protocol/sdk';
151
- *
152
- * const privateKey = 'Armored_priv_key';
153
- * const passphrase = 'example_passphrase';
154
- * const encryption = await Encryption.build(privateKey, passphrase);
155
- *
156
85
  * const resultMessage = await encryption.sign('message');
86
+ * console.log('Signed message:', resultMessage);
157
87
  * ```
158
88
  */
159
89
  sign(message: string): Promise<string>;
160
90
  }
161
91
  /**
162
- * ## Introduction
163
- *
164
92
  * Utility class for encryption-related operations.
165
- *
166
- * ## Installation
167
- *
168
- * ### npm
169
- * ```bash
170
- * npm install @human-protocol/sdk
171
- * ```
172
- *
173
- * ### yarn
174
- * ```bash
175
- * yarn install @human-protocol/sdk
176
- * ```
177
- *
178
- * ## Code example
179
- *
180
- * ```ts
181
- * import { EncryptionUtils } from '@human-protocol/sdk';
182
- *
183
- * const keyPair = await EncryptionUtils.generateKeyPair('Human', 'human@hmt.ai');
184
- * ```
185
93
  */
186
94
  export declare class EncryptionUtils {
187
95
  /**
188
96
  * This function verifies the signature of a signed message using the public key.
189
97
  *
190
- * @param {string} message Message to verify.
191
- * @param {string} publicKey Public key to verify that the message was signed by a specific source.
192
- * @returns {Promise<boolean>} True if verified. False if not verified.
193
- *
194
- * **Code example**
98
+ * @param message - Message to verify.
99
+ * @param publicKey - Public key to verify that the message was signed by a specific source.
100
+ * @returns True if verified. False if not verified.
195
101
  *
102
+ * @example
196
103
  * ```ts
197
104
  * import { EncryptionUtils } from '@human-protocol/sdk';
198
105
  *
199
- * const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
200
- * xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
201
- * WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
202
- * CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
203
- * XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
204
- * X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
205
- * CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
206
- * YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
207
- * XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
208
- * UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
209
- * -----END PGP PUBLIC KEY BLOCK-----`;
210
- *
106
+ * const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
211
107
  * const result = await EncryptionUtils.verify('message', publicKey);
108
+ * console.log('Verification result:', result);
212
109
  * ```
213
110
  */
214
111
  static verify(message: string, publicKey: string): Promise<boolean>;
215
112
  /**
216
113
  * This function gets signed data from a signed message.
217
114
  *
218
- * @param {string} message Message.
219
- * @returns {Promise<string>} Signed data.
220
- *
221
- * **Code example**
115
+ * @param message - Message.
116
+ * @returns Signed data.
117
+ * @throws Error If data could not be extracted from the message
222
118
  *
119
+ * @example
223
120
  * ```ts
224
121
  * import { EncryptionUtils } from '@human-protocol/sdk';
225
122
  *
226
123
  * const signedData = await EncryptionUtils.getSignedData('message');
124
+ * console.log('Signed data:', signedData);
227
125
  * ```
228
126
  */
229
127
  static getSignedData(message: string): Promise<string>;
230
128
  /**
231
129
  * This function generates a key pair for encryption and decryption.
232
130
  *
233
- * @param {string} name Name for the key pair.
234
- * @param {string} email Email for the key pair.
235
- * @param {string} passphrase Passphrase to encrypt the private key. Optional.
236
- * @returns {Promise<IKeyPair>} Key pair generated.
237
- *
238
- * **Code example**
131
+ * @param name - Name for the key pair.
132
+ * @param email - Email for the key pair.
133
+ * @param passphrase - Passphrase to encrypt the private key (optional, defaults to empty string).
134
+ * @returns Key pair generated.
239
135
  *
136
+ * @example
240
137
  * ```ts
241
138
  * import { EncryptionUtils } from '@human-protocol/sdk';
242
139
  *
243
140
  * const name = 'YOUR_NAME';
244
141
  * const email = 'YOUR_EMAIL';
245
142
  * const passphrase = 'YOUR_PASSPHRASE';
246
- * const result = await EncryptionUtils.generateKeyPair(name, email, passphrase);
143
+ * const keyPair = await EncryptionUtils.generateKeyPair(name, email, passphrase);
144
+ * console.log('Public key:', keyPair.publicKey);
247
145
  * ```
248
146
  */
249
147
  static generateKeyPair(name: string, email: string, passphrase?: string): Promise<IKeyPair>;
250
148
  /**
251
149
  * This function encrypts a message using the specified public keys.
252
150
  *
253
- * @param {MessageDataType} message Message to encrypt.
254
- * @param {string[]} publicKeys Array of public keys to use for encryption.
255
- * @returns {Promise<string>} Message encrypted.
256
- *
257
- * **Code example**
151
+ * @param message - Message to encrypt.
152
+ * @param publicKeys - Array of public keys to use for encryption.
153
+ * @returns Message encrypted.
258
154
  *
155
+ * @example
259
156
  * ```ts
260
157
  * import { EncryptionUtils } from '@human-protocol/sdk';
261
158
  *
262
- * const publicKey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
263
- * xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
264
- * WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
265
- * CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
266
- * XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
267
- * X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
268
- * CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
269
- * YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
270
- * XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
271
- * UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
272
- * -----END PGP PUBLIC KEY BLOCK-----`;
273
- *
274
- * const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
275
- * xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
276
- * FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
277
- * CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
278
- * bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
279
- * ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
280
- * CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
281
- * bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
282
- * bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
283
- * s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
284
- * -----END PGP PUBLIC KEY BLOCK-----`;
285
- *
286
- * const publicKeys = [publicKey1, publicKey2]
287
- * const result = await EncryptionUtils.encrypt('message', publicKeys);
159
+ * const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
160
+ * const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
161
+ * const publicKeys = [publicKey1, publicKey2];
162
+ * const encryptedMessage = await EncryptionUtils.encrypt('message', publicKeys);
163
+ * console.log('Encrypted message:', encryptedMessage);
288
164
  * ```
289
165
  */
290
166
  static encrypt(message: MessageDataType, publicKeys: string[]): Promise<string>;
291
167
  /**
292
168
  * Verifies if a message appears to be encrypted with OpenPGP.
293
169
  *
294
- * @param {string} message Message to verify.
295
- * @returns {Promise<boolean>} `true` if the message appears to be encrypted, `false` if not.
296
- *
297
- * **Code example:**
170
+ * @param message - Message to verify.
171
+ * @returns `true` if the message appears to be encrypted, `false` if not.
298
172
  *
173
+ * @example
299
174
  * ```ts
300
- * const message = `-----BEGIN PGP MESSAGE-----
301
- *
302
- * wV4DqdeRpqH+jaISAQdAsvBFxikvjxRqC7ZlDe98cLd7/aeCEI/AcL8PpVKK
303
- * mC0wKlwxNg/ADi55z9jcYFuMC4kKE+C/teM+JqiI8DO9AwassQUvKFtULnpx
304
- * h2jaOjC/0sAQASjUsIFK8zbuDgk/P8T9Npn6px+GlJPg9K90iwtPWiIp0eyW
305
- * 4zXamJZT51k2DyaUX/Rsc6P4PYhQRKjt0yxtH0jHPmKkLC/9eBeFf4GP0zlZ
306
- * 18xMZ8uCpQCma708Gz0sJYxEz3u/eZdHD7Mc7tWQKyJG8MsTwM1P+fdK1X75
307
- * L9UryJG2AY+6kKZhG4dqjNxiO4fWluiB2u7iMF+iLEyE3SQCEYorWMC+NDWi
308
- * QIJZ7oQ2w7BaPo1a991gvTOSNm5v2x44KfqPI1uj859BjsQTCA==
309
- * =tsmI
310
- * -----END PGP MESSAGE-----`;
175
+ * import { EncryptionUtils } from '@human-protocol/sdk';
311
176
  *
312
- * const isEncrypted = await EncryptionUtils.isEncrypted(message);
177
+ * const message = '-----BEGIN PGP MESSAGE-----...';
178
+ * const isEncrypted = EncryptionUtils.isEncrypted(message);
313
179
  *
314
180
  * if (isEncrypted) {
315
181
  * console.log('The message is encrypted with OpenPGP.');
@@ -320,5 +186,4 @@ export declare class EncryptionUtils {
320
186
  */
321
187
  static isEncrypted(message: string): boolean;
322
188
  }
323
- export {};
324
189
  //# sourceMappingURL=encryption.d.ts.map
@@ -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;AAExC;;;GAGG;AACH,KAAK,eAAe,GAAG,MAAM,GAAG,UAAU,CAAC;AAU3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;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,CAA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