@human-protocol/sdk 6.1.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +26 -14
- package/dist/encryption/encryption.d.ts +84 -0
- package/dist/encryption/encryption.d.ts.map +1 -0
- package/dist/{encryption.js → encryption/encryption.js} +3 -161
- package/dist/encryption/encryption_utils.d.ts +101 -0
- package/dist/encryption/encryption_utils.d.ts.map +1 -0
- package/dist/encryption/encryption_utils.js +191 -0
- package/dist/encryption/index.d.ts +4 -0
- package/dist/encryption/index.d.ts.map +1 -0
- package/dist/encryption/index.js +7 -0
- package/dist/encryption/types.d.ts +9 -0
- package/dist/encryption/types.d.ts.map +1 -0
- package/dist/encryption/types.js +9 -0
- package/dist/error.d.ts +6 -10
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +12 -14
- package/dist/{escrow.d.ts → escrow/escrow_client.d.ts} +4 -184
- package/dist/{escrow.d.ts.map → escrow/escrow_client.d.ts.map} +1 -1
- package/dist/{escrow.js → escrow/escrow_client.js} +35 -411
- package/dist/escrow/escrow_utils.d.ts +172 -0
- package/dist/escrow/escrow_utils.d.ts.map +1 -0
- package/dist/escrow/escrow_utils.js +388 -0
- package/dist/escrow/index.d.ts +3 -0
- package/dist/escrow/index.d.ts.map +1 -0
- package/dist/escrow/index.js +7 -0
- package/dist/graphql/queries/statistics.d.ts +1 -0
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +36 -2
- package/dist/graphql/types.d.ts +3 -1
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -22
- package/dist/interfaces.d.ts +0 -5
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore/index.d.ts +3 -0
- package/dist/kvstore/index.d.ts.map +1 -0
- package/dist/kvstore/index.js +7 -0
- package/dist/{kvstore.d.ts → kvstore/kvstore_client.d.ts} +3 -108
- package/dist/kvstore/kvstore_client.d.ts.map +1 -0
- package/dist/{kvstore.js → kvstore/kvstore_client.js} +22 -184
- package/dist/kvstore/kvstore_utils.d.ts +105 -0
- package/dist/kvstore/kvstore_utils.d.ts.map +1 -0
- package/dist/kvstore/kvstore_utils.js +184 -0
- package/dist/operator/index.d.ts +2 -0
- package/dist/operator/index.d.ts.map +1 -0
- package/dist/operator/index.js +5 -0
- package/dist/{operator.d.ts → operator/operator_utils.d.ts} +3 -3
- package/dist/operator/operator_utils.d.ts.map +1 -0
- package/dist/{operator.js → operator/operator_utils.js} +6 -6
- package/dist/staking/index.d.ts +3 -0
- package/dist/staking/index.d.ts.map +1 -0
- package/dist/staking/index.js +7 -0
- package/dist/{staking.d.ts → staking/staking_client.d.ts} +4 -65
- package/dist/staking/staking_client.d.ts.map +1 -0
- package/dist/{staking.js → staking/staking_client.js} +6 -136
- package/dist/staking/staking_utils.d.ts +63 -0
- package/dist/staking/staking_utils.d.ts.map +1 -0
- package/dist/staking/staking_utils.js +137 -0
- package/dist/statistics/index.d.ts +2 -0
- package/dist/statistics/index.d.ts.map +1 -0
- package/dist/statistics/index.js +5 -0
- package/dist/{statistics.d.ts → statistics/statistics_utils.d.ts} +4 -13
- package/dist/statistics/statistics_utils.d.ts.map +1 -0
- package/dist/{statistics.js → statistics/statistics_utils.js} +8 -22
- package/dist/transaction/index.d.ts +2 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/index.js +5 -0
- package/dist/{transaction.d.ts → transaction/transaction_utils.d.ts} +3 -3
- package/dist/transaction/transaction_utils.d.ts.map +1 -0
- package/dist/{transaction.js → transaction/transaction_utils.js} +5 -5
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +15 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +71 -4
- package/dist/worker/index.d.ts +2 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +5 -0
- package/dist/{worker.d.ts → worker/worker_utils.d.ts} +3 -3
- package/dist/worker/worker_utils.d.ts.map +1 -0
- package/dist/{worker.js → worker/worker_utils.js} +5 -5
- package/package.json +4 -4
- package/src/constants.ts +38 -14
- package/src/{encryption.ts → encryption/encryption.ts} +1 -193
- package/src/encryption/encryption_utils.ts +179 -0
- package/src/encryption/index.ts +3 -0
- package/src/encryption/types.ts +15 -0
- package/src/error.ts +11 -17
- package/src/{escrow.ts → escrow/escrow_client.ts} +36 -556
- package/src/escrow/escrow_utils.ts +510 -0
- package/src/escrow/index.ts +2 -0
- package/src/graphql/queries/statistics.ts +37 -1
- package/src/graphql/types.ts +4 -1
- package/src/index.ts +11 -25
- package/src/interfaces.ts +0 -5
- package/src/kvstore/index.ts +2 -0
- package/src/{kvstore.ts → kvstore/kvstore_client.ts} +27 -241
- package/src/kvstore/kvstore_utils.ts +244 -0
- package/src/operator/index.ts +1 -0
- package/src/{operator.ts → operator/operator_utils.ts} +8 -8
- package/src/staking/index.ts +2 -0
- package/src/{staking.ts → staking/staking_client.ts} +8 -174
- package/src/staking/staking_utils.ts +170 -0
- package/src/statistics/index.ts +1 -0
- package/src/{statistics.ts → statistics/statistics_utils.ts} +14 -26
- package/src/transaction/index.ts +1 -0
- package/src/{transaction.ts → transaction/transaction_utils.ts} +7 -7
- package/src/types.ts +8 -0
- package/src/utils.ts +80 -3
- package/src/worker/index.ts +1 -0
- package/src/{worker.ts → worker/worker_utils.ts} +7 -7
- package/dist/encryption.d.ts +0 -189
- package/dist/encryption.d.ts.map +0 -1
- package/dist/kvstore.d.ts.map +0 -1
- package/dist/operator.d.ts.map +0 -1
- package/dist/staking.d.ts.map +0 -1
- package/dist/statistics.d.ts.map +0 -1
- package/dist/transaction.d.ts.map +0 -1
- package/dist/worker.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @human-protocol/sdk
|
|
2
2
|
|
|
3
|
+
## 7.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- a7ab394: Updated KV Store utils in sdk to return empty string in case no value in subgraph instead of throwing and error
|
|
8
|
+
- a7ab394: Updated escrow contracts and SDKs to fetch oracle fees from `KVStore` instead of passing fee values during escrow setup. `Escrow.setup(...)` and factory setup flows no longer accept fee arguments, escrow deployments now require a `KVStore` address, and fee validation is enforced on-chain from `KVStore` values, including per-oracle and total fee limits. Added upgrade-safe `EscrowFactory` support for storing and updating the `KVStore` address.
|
|
9
|
+
|
|
10
|
+
Updated TypeScript and Python SDK escrow setup APIs to match the new contract signatures by removing fee arguments from `setup(...)` and create-and-setup helpers. Existing config fee fields remain optional for backward compatibility but are ignored by setup calls.
|
|
11
|
+
|
|
12
|
+
Updated SDKs to use a dedicated HMT stats subgraph endpoint for HMT statistics methods and removed `totalAmountPaid` and `averageAmountPerWorker` from `IDailyPayment`.
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- a31cfc8: Added typed subgraph errors (SubgraphRequestError, SubgraphBadIndexerError) and wrapped subgraph request failures with these classes
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- c50fc7e: Split combined domain files into module folders with explicit files per responsibility.
|
|
21
|
+
- Updated dependencies [a7ab394]
|
|
22
|
+
- @human-protocol/core@6.0.0
|
|
23
|
+
|
|
3
24
|
## 6.1.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAE7D,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAE5C,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,oBAAY,UAAU;IACpB,EAAE,MAAM;IACR,OAAO,MAAM;IACb,WAAW,MAAM;IACjB,YAAY,MAAM;IAClB,gBAAgB,MAAM;IACtB,SAAS,MAAM;IACf,SAAS,MAAM;IACf,qBAAqB,MAAM;CAC5B;AAED,eAAO,MAAM,QAAQ,EAAE;KACpB,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,WAAW;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAE7D,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAE5C,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,oBAAY,UAAU;IACpB,EAAE,MAAM;IACR,OAAO,MAAM;IACb,WAAW,MAAM;IACjB,YAAY,MAAM;IAClB,gBAAgB,MAAM;IACtB,SAAS,MAAM;IACf,SAAS,MAAM;IACf,qBAAqB,MAAM;CAC5B;AAED,eAAO,MAAM,QAAQ,EAAE;KACpB,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,WAAW;CAmInC,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;CAavB,CAAC;AAEF,eAAO,MAAM,IAAI;;;;;CAKhB,CAAC;AAEF,eAAO,MAAM,4BAA4B,KAAK,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -27,10 +27,12 @@ exports.NETWORKS = {
|
|
|
27
27
|
hmtAddress: '0xd1ba9BAC957322D6e8c07a160a3A8dA11A0d2867',
|
|
28
28
|
stakingAddress: '0xEf6Da3aB52c33925Be3F84038193a7e1331F51E6',
|
|
29
29
|
kvstoreAddress: '0xB6d36B1CDaD50302BCB3DB43bAb0D349458e1b8D',
|
|
30
|
-
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
|
|
31
|
-
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/
|
|
30
|
+
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/human-ethereum/version/latest',
|
|
31
|
+
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmQZ3yL1FzydDwaB56ozgTiBESciTNFsMLyTBfHXzNd1gg',
|
|
32
32
|
oldSubgraphUrl: '',
|
|
33
33
|
oldFactoryAddress: '',
|
|
34
|
+
hmtSubgraphUrl: 'https://api.studio.thegraph.com/query/74256/hmt-stats-ethereum/version/latest',
|
|
35
|
+
hmtSubgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmdcTW7XhgULq5yJZGA65mjTwQogdyzLJaZ69ttDJz5JeE',
|
|
34
36
|
},
|
|
35
37
|
[enums_1.ChainId.SEPOLIA]: {
|
|
36
38
|
chainId: enums_1.ChainId.SEPOLIA,
|
|
@@ -40,10 +42,12 @@ exports.NETWORKS = {
|
|
|
40
42
|
hmtAddress: '0x792abbcC99c01dbDec49c9fa9A828a186Da45C33',
|
|
41
43
|
stakingAddress: '0x2163e3A40032Af1C359ac731deaB48258b317890',
|
|
42
44
|
kvstoreAddress: '0xCc0AF0635aa19fE799B6aFDBe28fcFAeA7f00a60',
|
|
43
|
-
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
|
|
44
|
-
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/
|
|
45
|
+
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/human-sepolia/version/latest',
|
|
46
|
+
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmQEbyGSf8VG9pdskowsK6C977wkcyJSxw9q6EDctKEkUw',
|
|
45
47
|
oldSubgraphUrl: '',
|
|
46
48
|
oldFactoryAddress: '',
|
|
49
|
+
hmtSubgraphUrl: 'https://api.studio.thegraph.com/query/74256/hmt-stats-sepolia/version/latest',
|
|
50
|
+
hmtSubgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmYkPnYxbZ5ZTtKz7PTyxh6x5sK2H6yzx6vXDCrErpa9gB',
|
|
47
51
|
},
|
|
48
52
|
[enums_1.ChainId.BSC_MAINNET]: {
|
|
49
53
|
chainId: enums_1.ChainId.BSC_MAINNET,
|
|
@@ -53,10 +57,12 @@ exports.NETWORKS = {
|
|
|
53
57
|
hmtAddress: '0x711Fd6ab6d65A98904522d4e3586F492B989c527',
|
|
54
58
|
stakingAddress: '0xE24e5C08E28331D24758b69A5E9f383D2bDD1c98',
|
|
55
59
|
kvstoreAddress: '0x21A0C4CED7aE447fCf87D9FE3A29FA9B3AB20Ff1',
|
|
56
|
-
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
|
|
57
|
-
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/
|
|
60
|
+
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/human-bsc/version/latest',
|
|
61
|
+
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmV3nZUM51NGt7F8RpZP9GxKPpKox3F24iJ8H1ekPb6ha4',
|
|
58
62
|
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
|
|
59
63
|
oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
|
|
64
|
+
hmtSubgraphUrl: 'https://api.studio.thegraph.com/query/74256/hmt-stats-bsc/version/latest',
|
|
65
|
+
hmtSubgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmUnHgNShyv45S2dQ21W9jLvRA8xWT6XfeuP25fXJoNoEa',
|
|
60
66
|
},
|
|
61
67
|
[enums_1.ChainId.BSC_TESTNET]: {
|
|
62
68
|
chainId: enums_1.ChainId.BSC_TESTNET,
|
|
@@ -66,10 +72,12 @@ exports.NETWORKS = {
|
|
|
66
72
|
hmtAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
|
|
67
73
|
stakingAddress: '0xD6D347ba6987519B4e42EcED43dF98eFf5465a23',
|
|
68
74
|
kvstoreAddress: '0x32e27177BA6Ea91cf28dfd91a0Da9822A4b74EcF',
|
|
69
|
-
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
|
|
70
|
-
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/
|
|
75
|
+
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/human-bsc-testnet/version/latest',
|
|
76
|
+
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmdQJog9vMghK2o39U9YJL8vpU9VZnkJa7jGg7wnsod7qV',
|
|
71
77
|
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
|
|
72
78
|
oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
|
|
79
|
+
hmtSubgraphUrl: 'https://api.studio.thegraph.com/query/74256/hmt-stats-bsc-testnet/version/latest',
|
|
80
|
+
hmtSubgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmPMRbrXKp7a1i5x27dzBHbomxqKYDg5eU3djv1DXB5heq',
|
|
73
81
|
},
|
|
74
82
|
[enums_1.ChainId.POLYGON]: {
|
|
75
83
|
chainId: enums_1.ChainId.POLYGON,
|
|
@@ -79,10 +87,12 @@ exports.NETWORKS = {
|
|
|
79
87
|
hmtAddress: '0xc748B2A084F8eFc47E086ccdDD9b7e67aEb571BF',
|
|
80
88
|
stakingAddress: '0x01D115E9E8bF0C58318793624CC662a030D07F1D',
|
|
81
89
|
kvstoreAddress: '0xbcB28672F826a50B03EE91B28145EAbddA73B2eD',
|
|
82
|
-
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
|
|
83
|
-
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/
|
|
90
|
+
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/human-polygon/version/latest',
|
|
91
|
+
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmSu7B48kgGgMgXaD6Yb4fXjbnsJNmobKAU9qZgescZXid',
|
|
84
92
|
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
|
|
85
93
|
oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
|
|
94
|
+
hmtSubgraphUrl: 'https://api.studio.thegraph.com/query/74256/hmt-stats-polygon/version/latest',
|
|
95
|
+
hmtSubgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmcTTTq2reYDBP5j5P2eToc5FmYbJ5ZSMhPaRB6NLriNjR',
|
|
86
96
|
},
|
|
87
97
|
[enums_1.ChainId.POLYGON_AMOY]: {
|
|
88
98
|
chainId: enums_1.ChainId.POLYGON_AMOY,
|
|
@@ -92,19 +102,21 @@ exports.NETWORKS = {
|
|
|
92
102
|
hmtAddress: '0x792abbcC99c01dbDec49c9fa9A828a186Da45C33',
|
|
93
103
|
stakingAddress: '0xffE496683F842a923110415b7278ded3F265f2C5',
|
|
94
104
|
kvstoreAddress: '0x724AeFC243EdacCA27EAB86D3ec5a76Af4436Fc7',
|
|
95
|
-
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
|
|
96
|
-
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/
|
|
105
|
+
subgraphUrl: 'https://api.studio.thegraph.com/query/74256/human-amoy/version/latest',
|
|
106
|
+
subgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmRx5WSi7o9FtENWnE5eEz8Dr7kYUazk4TNPRt65UZkKkB',
|
|
97
107
|
oldSubgraphUrl: '',
|
|
98
108
|
oldFactoryAddress: '',
|
|
109
|
+
hmtSubgraphUrl: 'https://api.studio.thegraph.com/query/74256/hmt-stats-amoy/version/latest',
|
|
110
|
+
hmtSubgraphUrlApiKey: 'https://gateway.thegraph.com/api/deployments/id/QmZze6UWMJna8dQ183TVounSfGwc9C36RgQCGWhFzgrW3y',
|
|
99
111
|
},
|
|
100
112
|
[enums_1.ChainId.LOCALHOST]: {
|
|
101
113
|
chainId: enums_1.ChainId.LOCALHOST,
|
|
102
114
|
title: 'Localhost',
|
|
103
115
|
scanUrl: '',
|
|
104
|
-
factoryAddress: '
|
|
116
|
+
factoryAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
|
|
105
117
|
hmtAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
|
|
106
118
|
stakingAddress: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
|
|
107
|
-
kvstoreAddress: '
|
|
119
|
+
kvstoreAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
|
|
108
120
|
subgraphUrl: 'http://localhost:8000/subgraphs/name/humanprotocol/localhost',
|
|
109
121
|
subgraphUrlApiKey: '',
|
|
110
122
|
oldSubgraphUrl: '',
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as openpgp from 'openpgp';
|
|
2
|
+
import { MessageDataType } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Class for signing and decrypting messages.
|
|
5
|
+
*
|
|
6
|
+
* 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).
|
|
7
|
+
*
|
|
8
|
+
* To get an instance of this class, initialization is recommended using the static [`build`](/ts/classes/Encryption/#build) method.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Encryption {
|
|
11
|
+
private privateKey;
|
|
12
|
+
/**
|
|
13
|
+
* Constructor for the Encryption class.
|
|
14
|
+
*
|
|
15
|
+
* @param privateKey - The private key.
|
|
16
|
+
*/
|
|
17
|
+
constructor(privateKey: openpgp.PrivateKey);
|
|
18
|
+
/**
|
|
19
|
+
* Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase.
|
|
20
|
+
*
|
|
21
|
+
* @param privateKeyArmored - The encrypted private key in armored format.
|
|
22
|
+
* @param passphrase - The passphrase for the private key (optional).
|
|
23
|
+
* @returns The Encryption instance.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { Encryption } from '@human-protocol/sdk';
|
|
28
|
+
*
|
|
29
|
+
* const privateKey = 'Armored_priv_key';
|
|
30
|
+
* const passphrase = 'example_passphrase';
|
|
31
|
+
* const encryption = await Encryption.build(privateKey, passphrase);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
static build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>;
|
|
35
|
+
/**
|
|
36
|
+
* This function signs and encrypts a message using the private key used to initialize the client and the specified public keys.
|
|
37
|
+
*
|
|
38
|
+
* @param message - Message to sign and encrypt.
|
|
39
|
+
* @param publicKeys - Array of public keys to use for encryption.
|
|
40
|
+
* @returns Message signed and encrypted.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
45
|
+
* const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
46
|
+
*
|
|
47
|
+
* const publicKeys = [publicKey1, publicKey2];
|
|
48
|
+
* const resultMessage = await encryption.signAndEncrypt('message', publicKeys);
|
|
49
|
+
* console.log('Encrypted message:', resultMessage);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
signAndEncrypt(message: MessageDataType, publicKeys: string[]): Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* This function decrypts messages using the private key. In addition, the public key can be added for signature verification.
|
|
55
|
+
*
|
|
56
|
+
* @param message - Message to decrypt.
|
|
57
|
+
* @param publicKey - Public key used to verify signature if needed (optional).
|
|
58
|
+
* @returns Message decrypted.
|
|
59
|
+
* @throws Error If signature could not be verified when public key is provided
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
64
|
+
*
|
|
65
|
+
* const resultMessage = await encryption.decrypt('message', publicKey);
|
|
66
|
+
* console.log('Decrypted message:', resultMessage);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
decrypt(message: string, publicKey?: string): Promise<Uint8Array>;
|
|
70
|
+
/**
|
|
71
|
+
* This function signs a message using the private key used to initialize the client.
|
|
72
|
+
*
|
|
73
|
+
* @param message - Message to sign.
|
|
74
|
+
* @returns Message signed.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const resultMessage = await encryption.sign('message');
|
|
79
|
+
* console.log('Signed message:', resultMessage);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
sign(message: string): Promise<string>;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../src/encryption/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAyB,eAAe,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;;;GAMG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAqB;IAEvC;;;;OAIG;gBACS,UAAU,EAAE,OAAO,CAAC,UAAU;IAI1C;;;;;;;;;;;;;;;OAeG;WACiB,KAAK,CACvB,iBAAiB,EAAE,MAAM,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC;IAkBtB;;;;;;;;;;;;;;;;OAgBG;IACU,cAAc,CACzB,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,CAAC;IAkBlB;;;;;;;;;;;;;;;OAeG;IACU,OAAO,CAClB,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC;IAoCtB;;;;;;;;;;;OAWG;IACU,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYpD"}
|
|
@@ -33,14 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
36
|
+
exports.Encryption = void 0;
|
|
37
37
|
const openpgp = __importStar(require("openpgp"));
|
|
38
|
-
|
|
39
|
-
if (typeof message === 'string') {
|
|
40
|
-
return Buffer.from(message);
|
|
41
|
-
}
|
|
42
|
-
return message;
|
|
43
|
-
}
|
|
38
|
+
const types_1 = require("./types");
|
|
44
39
|
/**
|
|
45
40
|
* Class for signing and decrypting messages.
|
|
46
41
|
*
|
|
@@ -106,7 +101,7 @@ class Encryption {
|
|
|
106
101
|
async signAndEncrypt(message, publicKeys) {
|
|
107
102
|
const pgpPublicKeys = await Promise.all(publicKeys.map((armoredKey) => openpgp.readKey({ armoredKey })));
|
|
108
103
|
const pgpMessage = await openpgp.createMessage({
|
|
109
|
-
binary: makeMessageDataBinary(message),
|
|
104
|
+
binary: (0, types_1.makeMessageDataBinary)(message),
|
|
110
105
|
});
|
|
111
106
|
const encrypted = await openpgp.encrypt({
|
|
112
107
|
message: pgpMessage,
|
|
@@ -187,156 +182,3 @@ class Encryption {
|
|
|
187
182
|
}
|
|
188
183
|
}
|
|
189
184
|
exports.Encryption = Encryption;
|
|
190
|
-
/**
|
|
191
|
-
* Utility class for encryption-related operations.
|
|
192
|
-
*/
|
|
193
|
-
class EncryptionUtils {
|
|
194
|
-
/**
|
|
195
|
-
* This function verifies the signature of a signed message using the public key.
|
|
196
|
-
*
|
|
197
|
-
* @param message - Message to verify.
|
|
198
|
-
* @param publicKey - Public key to verify that the message was signed by a specific source.
|
|
199
|
-
* @returns True if verified. False if not verified.
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* ```ts
|
|
203
|
-
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
204
|
-
*
|
|
205
|
-
* const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
206
|
-
* const result = await EncryptionUtils.verify('message', publicKey);
|
|
207
|
-
* console.log('Verification result:', result);
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
static async verify(message, publicKey) {
|
|
211
|
-
const pgpPublicKey = await openpgp.readKey({ armoredKey: publicKey });
|
|
212
|
-
const signedMessage = await openpgp.readCleartextMessage({
|
|
213
|
-
cleartextMessage: message,
|
|
214
|
-
});
|
|
215
|
-
const verificationResult = await signedMessage.verify([pgpPublicKey]);
|
|
216
|
-
const { verified } = verificationResult[0];
|
|
217
|
-
try {
|
|
218
|
-
return await verified;
|
|
219
|
-
}
|
|
220
|
-
catch {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* This function gets signed data from a signed message.
|
|
226
|
-
*
|
|
227
|
-
* @param message - Message.
|
|
228
|
-
* @returns Signed data.
|
|
229
|
-
* @throws Error If data could not be extracted from the message
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* ```ts
|
|
233
|
-
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
234
|
-
*
|
|
235
|
-
* const signedData = await EncryptionUtils.getSignedData('message');
|
|
236
|
-
* console.log('Signed data:', signedData);
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
static async getSignedData(message) {
|
|
240
|
-
const signedMessage = await openpgp.readCleartextMessage({
|
|
241
|
-
cleartextMessage: message,
|
|
242
|
-
});
|
|
243
|
-
try {
|
|
244
|
-
return signedMessage.getText();
|
|
245
|
-
}
|
|
246
|
-
catch (e) {
|
|
247
|
-
throw new Error('Could not get data: ' + e.message);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* This function generates a key pair for encryption and decryption.
|
|
252
|
-
*
|
|
253
|
-
* @param name - Name for the key pair.
|
|
254
|
-
* @param email - Email for the key pair.
|
|
255
|
-
* @param passphrase - Passphrase to encrypt the private key (optional, defaults to empty string).
|
|
256
|
-
* @returns Key pair generated.
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* ```ts
|
|
260
|
-
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
261
|
-
*
|
|
262
|
-
* const name = 'YOUR_NAME';
|
|
263
|
-
* const email = 'YOUR_EMAIL';
|
|
264
|
-
* const passphrase = 'YOUR_PASSPHRASE';
|
|
265
|
-
* const keyPair = await EncryptionUtils.generateKeyPair(name, email, passphrase);
|
|
266
|
-
* console.log('Public key:', keyPair.publicKey);
|
|
267
|
-
* ```
|
|
268
|
-
*/
|
|
269
|
-
static async generateKeyPair(name, email, passphrase = '') {
|
|
270
|
-
const { privateKey, publicKey, revocationCertificate } = await openpgp.generateKey({
|
|
271
|
-
type: 'ecc',
|
|
272
|
-
curve: 'ed25519Legacy',
|
|
273
|
-
userIDs: [{ name: name, email: email }],
|
|
274
|
-
passphrase: passphrase,
|
|
275
|
-
format: 'armored',
|
|
276
|
-
});
|
|
277
|
-
return {
|
|
278
|
-
passphrase: passphrase,
|
|
279
|
-
privateKey,
|
|
280
|
-
publicKey,
|
|
281
|
-
revocationCertificate,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* This function encrypts a message using the specified public keys.
|
|
286
|
-
*
|
|
287
|
-
* @param message - Message to encrypt.
|
|
288
|
-
* @param publicKeys - Array of public keys to use for encryption.
|
|
289
|
-
* @returns Message encrypted.
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* ```ts
|
|
293
|
-
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
294
|
-
*
|
|
295
|
-
* const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
296
|
-
* const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
297
|
-
* const publicKeys = [publicKey1, publicKey2];
|
|
298
|
-
* const encryptedMessage = await EncryptionUtils.encrypt('message', publicKeys);
|
|
299
|
-
* console.log('Encrypted message:', encryptedMessage);
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
static async encrypt(message, publicKeys) {
|
|
303
|
-
const pgpPublicKeys = await Promise.all(publicKeys.map((armoredKey) => openpgp.readKey({ armoredKey })));
|
|
304
|
-
const pgpMessage = await openpgp.createMessage({
|
|
305
|
-
binary: makeMessageDataBinary(message),
|
|
306
|
-
});
|
|
307
|
-
const encrypted = await openpgp.encrypt({
|
|
308
|
-
message: pgpMessage,
|
|
309
|
-
encryptionKeys: pgpPublicKeys,
|
|
310
|
-
format: 'armored',
|
|
311
|
-
});
|
|
312
|
-
return encrypted;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Verifies if a message appears to be encrypted with OpenPGP.
|
|
316
|
-
*
|
|
317
|
-
* @param message - Message to verify.
|
|
318
|
-
* @returns `true` if the message appears to be encrypted, `false` if not.
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* ```ts
|
|
322
|
-
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
323
|
-
*
|
|
324
|
-
* const message = '-----BEGIN PGP MESSAGE-----...';
|
|
325
|
-
* const isEncrypted = EncryptionUtils.isEncrypted(message);
|
|
326
|
-
*
|
|
327
|
-
* if (isEncrypted) {
|
|
328
|
-
* console.log('The message is encrypted with OpenPGP.');
|
|
329
|
-
* } else {
|
|
330
|
-
* console.log('The message is not encrypted with OpenPGP.');
|
|
331
|
-
* }
|
|
332
|
-
* ```
|
|
333
|
-
*/
|
|
334
|
-
static isEncrypted(message) {
|
|
335
|
-
const startMarker = '-----BEGIN PGP MESSAGE-----';
|
|
336
|
-
const endMarker = '-----END PGP MESSAGE-----';
|
|
337
|
-
const hasStartMarker = message.includes(startMarker);
|
|
338
|
-
const hasEndMarker = message.includes(endMarker);
|
|
339
|
-
return hasStartMarker && hasEndMarker;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
exports.EncryptionUtils = EncryptionUtils;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { IKeyPair } from '../interfaces';
|
|
2
|
+
import { MessageDataType } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Utility class for encryption-related operations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EncryptionUtils {
|
|
7
|
+
/**
|
|
8
|
+
* This function verifies the signature of a signed message using the public key.
|
|
9
|
+
*
|
|
10
|
+
* @param message - Message to verify.
|
|
11
|
+
* @param publicKey - Public key to verify that the message was signed by a specific source.
|
|
12
|
+
* @returns True if verified. False if not verified.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
17
|
+
*
|
|
18
|
+
* const publicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
19
|
+
* const result = await EncryptionUtils.verify('message', publicKey);
|
|
20
|
+
* console.log('Verification result:', result);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
static verify(message: string, publicKey: string): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* This function gets signed data from a signed message.
|
|
26
|
+
*
|
|
27
|
+
* @param message - Message.
|
|
28
|
+
* @returns Signed data.
|
|
29
|
+
* @throws Error If data could not be extracted from the message
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
34
|
+
*
|
|
35
|
+
* const signedData = await EncryptionUtils.getSignedData('message');
|
|
36
|
+
* console.log('Signed data:', signedData);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
static getSignedData(message: string): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* This function generates a key pair for encryption and decryption.
|
|
42
|
+
*
|
|
43
|
+
* @param name - Name for the key pair.
|
|
44
|
+
* @param email - Email for the key pair.
|
|
45
|
+
* @param passphrase - Passphrase to encrypt the private key (optional, defaults to empty string).
|
|
46
|
+
* @returns Key pair generated.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
51
|
+
*
|
|
52
|
+
* const name = 'YOUR_NAME';
|
|
53
|
+
* const email = 'YOUR_EMAIL';
|
|
54
|
+
* const passphrase = 'YOUR_PASSPHRASE';
|
|
55
|
+
* const keyPair = await EncryptionUtils.generateKeyPair(name, email, passphrase);
|
|
56
|
+
* console.log('Public key:', keyPair.publicKey);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
static generateKeyPair(name: string, email: string, passphrase?: string): Promise<IKeyPair>;
|
|
60
|
+
/**
|
|
61
|
+
* This function encrypts a message using the specified public keys.
|
|
62
|
+
*
|
|
63
|
+
* @param message - Message to encrypt.
|
|
64
|
+
* @param publicKeys - Array of public keys to use for encryption.
|
|
65
|
+
* @returns Message encrypted.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
70
|
+
*
|
|
71
|
+
* const publicKey1 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
72
|
+
* const publicKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----...';
|
|
73
|
+
* const publicKeys = [publicKey1, publicKey2];
|
|
74
|
+
* const encryptedMessage = await EncryptionUtils.encrypt('message', publicKeys);
|
|
75
|
+
* console.log('Encrypted message:', encryptedMessage);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
static encrypt(message: MessageDataType, publicKeys: string[]): Promise<string>;
|
|
79
|
+
/**
|
|
80
|
+
* Verifies if a message appears to be encrypted with OpenPGP.
|
|
81
|
+
*
|
|
82
|
+
* @param message - Message to verify.
|
|
83
|
+
* @returns `true` if the message appears to be encrypted, `false` if not.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import { EncryptionUtils } from '@human-protocol/sdk';
|
|
88
|
+
*
|
|
89
|
+
* const message = '-----BEGIN PGP MESSAGE-----...';
|
|
90
|
+
* const isEncrypted = EncryptionUtils.isEncrypted(message);
|
|
91
|
+
*
|
|
92
|
+
* if (isEncrypted) {
|
|
93
|
+
* console.log('The message is encrypted with OpenPGP.');
|
|
94
|
+
* } else {
|
|
95
|
+
* console.log('The message is not encrypted with OpenPGP.');
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
static isEncrypted(message: string): boolean;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=encryption_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption_utils.d.ts","sourceRoot":"","sources":["../../src/encryption/encryption_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAyB,eAAe,EAAE,MAAM,SAAS,CAAC;AAEjE;;GAEG;AACH,qBAAa,eAAe;IAC1B;;;;;;;;;;;;;;;OAeG;WACiB,MAAM,CACxB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IAgBnB;;;;;;;;;;;;;;OAcG;WACiB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAYnE;;;;;;;;;;;;;;;;;;OAkBG;WACiB,eAAe,CACjC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,SAAK,GACd,OAAO,CAAC,QAAQ,CAAC;IAkBpB;;;;;;;;;;;;;;;;;OAiBG;WACiB,OAAO,CACzB,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,CAAC;IAiBlB;;;;;;;;;;;;;;;;;;;OAmBG;WACW,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CASpD"}
|