@alephium/web3 0.2.0-rc.1 → 0.2.0-rc.10
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/.eslintignore +2 -2
- package/README.md +2 -135
- package/contracts/greeter/greeter.ral +2 -2
- package/contracts/greeter/greeter_interface.ral +1 -0
- package/contracts/greeter_main.ral +0 -2
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/scripts/create-project.js +3 -2
- package/dist/src/api/api-alephium.d.ts +44 -11
- package/dist/src/api/api-alephium.js +16 -0
- package/dist/src/api/api-explorer.d.ts +16 -16
- package/dist/src/api/index.d.ts +2 -2
- package/dist/src/api/index.js +18 -3
- package/dist/src/contract/contract.d.ts +101 -52
- package/dist/src/contract/contract.js +353 -219
- package/dist/src/contract/index.js +5 -1
- package/dist/src/global.d.ts +4 -0
- package/dist/src/global.js +38 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +20 -1
- package/dist/src/signer/index.d.ts +0 -1
- package/dist/src/signer/index.js +5 -2
- package/dist/src/signer/signer.d.ts +1 -1
- package/dist/src/signer/signer.js +8 -3
- package/dist/src/transaction/index.d.ts +0 -1
- package/dist/src/transaction/index.js +5 -2
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/index.js +5 -2
- package/dist/src/utils/subscription.d.ts +0 -1
- package/dist/src/utils/subscription.js +2 -1
- package/dist/src/utils/utils.d.ts +5 -4
- package/dist/src/utils/utils.js +17 -16
- package/jest-config.json +11 -0
- package/package.json +6 -34
- package/scripts/create-project.ts +3 -2
- package/src/api/api-alephium.ts +53 -5
- package/src/api/index.ts +13 -3
- package/src/contract/contract.ts +505 -318
- package/src/contract/events.ts +2 -2
- package/src/{transaction/sign-verify.ts → global.ts} +14 -15
- package/src/index.ts +3 -0
- package/src/signer/index.ts +0 -1
- package/src/signer/signer.ts +3 -2
- package/src/transaction/index.ts +0 -1
- package/src/transaction/status.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/subscription.ts +3 -3
- package/src/utils/utils.ts +10 -10
- package/templates/base/package.json +2 -2
- package/templates/base/src/greeter.ts +8 -7
- package/templates/react/package.json +2 -2
- package/templates/react/src/App.tsx +2 -2
- package/.eslintrc.json +0 -21
- package/LICENSE +0 -165
- package/contracts/add/add.ral +0 -16
- package/contracts/main.ral +0 -6
- package/contracts/sub/sub.ral +0 -9
- package/dist/src/signer/node-wallet.d.ts +0 -13
- package/dist/src/signer/node-wallet.js +0 -60
- package/dist/src/test/index.d.ts +0 -7
- package/dist/src/test/index.js +0 -41
- package/dist/src/test/privatekey-wallet.d.ts +0 -12
- package/dist/src/test/privatekey-wallet.js +0 -68
- package/dist/src/transaction/sign-verify.d.ts +0 -2
- package/dist/src/transaction/sign-verify.js +0 -58
- package/dist/src/utils/password-crypto.d.ts +0 -2
- package/dist/src/utils/password-crypto.js +0 -69
- package/gitignore +0 -10
- package/src/contract/ralph.test.ts +0 -178
- package/src/fixtures/address.json +0 -36
- package/src/fixtures/balance.json +0 -9
- package/src/fixtures/self-clique.json +0 -19
- package/src/fixtures/transaction.json +0 -13
- package/src/fixtures/transactions.json +0 -179
- package/src/signer/fixtures/genesis.json +0 -26
- package/src/signer/fixtures/wallets.json +0 -26
- package/src/signer/node-wallet.ts +0 -74
- package/src/test/index.ts +0 -32
- package/src/test/privatekey-wallet.ts +0 -58
- package/src/transaction/sign-verify.test.ts +0 -50
- package/src/utils/address.test.ts +0 -47
- package/src/utils/djb2.test.ts +0 -35
- package/src/utils/password-crypto.test.ts +0 -27
- package/src/utils/password-crypto.ts +0 -77
- package/src/utils/utils.test.ts +0 -161
- package/test/contract.test.ts +0 -178
- package/test/events.test.ts +0 -138
- package/test/transaction.test.ts +0 -72
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"oneInputOneOutput": {
|
|
3
|
-
"hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
|
|
4
|
-
"blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
|
|
5
|
-
"timestamp": 1639679587756,
|
|
6
|
-
"inputs": [
|
|
7
|
-
{
|
|
8
|
-
"outputRef": {
|
|
9
|
-
"hint": 269352581,
|
|
10
|
-
"key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
|
|
11
|
-
},
|
|
12
|
-
"unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
|
|
13
|
-
"txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
|
|
14
|
-
"address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
|
|
15
|
-
"amount": "100000000000000000000"
|
|
16
|
-
}
|
|
17
|
-
],
|
|
18
|
-
"outputs": [
|
|
19
|
-
{
|
|
20
|
-
"hint": 1770492891,
|
|
21
|
-
"key": "685eedf4a7eef2cccd55dfcc0d7d72c2aef788b118236d2dc8b27d924206da9d",
|
|
22
|
-
"amount": "409200570768056060",
|
|
23
|
-
"address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA2",
|
|
24
|
-
"spent": "4d8e564e1731ecc09e167211c25da7b91a3fab8096a951a0df3b7ce1549d6cd9"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"hint": 269352581,
|
|
28
|
-
"key": "162784ca82a5dfc796bc6514658453e51aacdb48ed7bec716850152a61b55b82",
|
|
29
|
-
"amount": "50000000000000000000",
|
|
30
|
-
"address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
|
|
31
|
-
"spent": "f823bcb78fbbc6c18dea882fe697cb8be9c5e2cb020e65670041dbe39b80c3d8"
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
"gasAmount": 68060,
|
|
35
|
-
"gasPrice": "100000000000"
|
|
36
|
-
},
|
|
37
|
-
"twoInputsOneOutput": {
|
|
38
|
-
"hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
|
|
39
|
-
"blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
|
|
40
|
-
"timestamp": 1639679587756,
|
|
41
|
-
"inputs": [
|
|
42
|
-
{
|
|
43
|
-
"outputRef": {
|
|
44
|
-
"hint": 269352581,
|
|
45
|
-
"key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
|
|
46
|
-
},
|
|
47
|
-
"unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
|
|
48
|
-
"txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
|
|
49
|
-
"address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
|
|
50
|
-
"amount": "100000000000000000000"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
"outputRef": {
|
|
54
|
-
"hint": 269352581,
|
|
55
|
-
"key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
|
|
56
|
-
},
|
|
57
|
-
"unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
|
|
58
|
-
"txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
|
|
59
|
-
"address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
|
|
60
|
-
"amount": "100000000000000000000"
|
|
61
|
-
}
|
|
62
|
-
],
|
|
63
|
-
"outputs": [
|
|
64
|
-
{
|
|
65
|
-
"hint": 1770492891,
|
|
66
|
-
"key": "685eedf4a7eef2cccd55dfcc0d7d72c2aef788b118236d2dc8b27d924206da9d",
|
|
67
|
-
"amount": "150000000000000000000",
|
|
68
|
-
"address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA2",
|
|
69
|
-
"spent": "4d8e564e1731ecc09e167211c25da7b91a3fab8096a951a0df3b7ce1549d6cd9"
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"hint": 269352581,
|
|
73
|
-
"key": "162784ca82a5dfc796bc6514658453e51aacdb48ed7bec716850152a61b55b82",
|
|
74
|
-
"amount": "50000000000000000000",
|
|
75
|
-
"address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
|
|
76
|
-
"spent": "f823bcb78fbbc6c18dea882fe697cb8be9c5e2cb020e65670041dbe39b80c3d8"
|
|
77
|
-
}
|
|
78
|
-
],
|
|
79
|
-
"gasAmount": 68060,
|
|
80
|
-
"gasPrice": "100000000000"
|
|
81
|
-
},
|
|
82
|
-
"twoInputsZeroOutput": {
|
|
83
|
-
"hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
|
|
84
|
-
"blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
|
|
85
|
-
"timestamp": 1639679587756,
|
|
86
|
-
"inputs": [
|
|
87
|
-
{
|
|
88
|
-
"outputRef": {
|
|
89
|
-
"hint": 269352581,
|
|
90
|
-
"key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
|
|
91
|
-
},
|
|
92
|
-
"unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
|
|
93
|
-
"txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
|
|
94
|
-
"address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
|
|
95
|
-
"amount": "100000000000000000000"
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
"outputRef": {
|
|
99
|
-
"hint": 269352581,
|
|
100
|
-
"key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
|
|
101
|
-
},
|
|
102
|
-
"unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
|
|
103
|
-
"txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
|
|
104
|
-
"address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
|
|
105
|
-
"amount": "100000000000000000000"
|
|
106
|
-
}
|
|
107
|
-
],
|
|
108
|
-
"outputs": [
|
|
109
|
-
{
|
|
110
|
-
"hint": 1770492891,
|
|
111
|
-
"key": "685eedf4a7eef2cccd55dfcc0d7d72c2aef788b118236d2dc8b27d924206da9d",
|
|
112
|
-
"amount": "150000000000000000000",
|
|
113
|
-
"address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA2",
|
|
114
|
-
"spent": "4d8e564e1731ecc09e167211c25da7b91a3fab8096a951a0df3b7ce1549d6cd9"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"hint": 269352581,
|
|
118
|
-
"key": "162784ca82a5dfc796bc6514658453e51aacdb48ed7bec716850152a61b55b82",
|
|
119
|
-
"amount": "50000000000000000000",
|
|
120
|
-
"address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA3",
|
|
121
|
-
"spent": "f823bcb78fbbc6c18dea882fe697cb8be9c5e2cb020e65670041dbe39b80c3d8"
|
|
122
|
-
}
|
|
123
|
-
],
|
|
124
|
-
"gasAmount": 68060,
|
|
125
|
-
"gasPrice": "100000000000"
|
|
126
|
-
},
|
|
127
|
-
"missingInputs": {
|
|
128
|
-
"hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
|
|
129
|
-
"blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
|
|
130
|
-
"timestamp": 1639679587756,
|
|
131
|
-
"outputs": [
|
|
132
|
-
{
|
|
133
|
-
"hint": 1770492891,
|
|
134
|
-
"key": "685eedf4a7eef2cccd55dfcc0d7d72c2aef788b118236d2dc8b27d924206da9d",
|
|
135
|
-
"amount": "150000000000000000000",
|
|
136
|
-
"address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA2",
|
|
137
|
-
"spent": "4d8e564e1731ecc09e167211c25da7b91a3fab8096a951a0df3b7ce1549d6cd9"
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
"hint": 269352581,
|
|
141
|
-
"key": "162784ca82a5dfc796bc6514658453e51aacdb48ed7bec716850152a61b55b82",
|
|
142
|
-
"amount": "50000000000000000000",
|
|
143
|
-
"address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA3",
|
|
144
|
-
"spent": "f823bcb78fbbc6c18dea882fe697cb8be9c5e2cb020e65670041dbe39b80c3d8"
|
|
145
|
-
}
|
|
146
|
-
],
|
|
147
|
-
"gasAmount": 68060,
|
|
148
|
-
"gasPrice": "100000000000"
|
|
149
|
-
},
|
|
150
|
-
"missingOutputs": {
|
|
151
|
-
"hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
|
|
152
|
-
"blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
|
|
153
|
-
"timestamp": 1639679587756,
|
|
154
|
-
"inputs": [
|
|
155
|
-
{
|
|
156
|
-
"outputRef": {
|
|
157
|
-
"hint": 269352581,
|
|
158
|
-
"key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
|
|
159
|
-
},
|
|
160
|
-
"unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
|
|
161
|
-
"txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
|
|
162
|
-
"address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
|
|
163
|
-
"amount": "100000000000000000000"
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
"outputRef": {
|
|
167
|
-
"hint": 269352581,
|
|
168
|
-
"key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
|
|
169
|
-
},
|
|
170
|
-
"unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
|
|
171
|
-
"txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
|
|
172
|
-
"address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
|
|
173
|
-
"amount": "100000000000000000000"
|
|
174
|
-
}
|
|
175
|
-
],
|
|
176
|
-
"gasAmount": 68060,
|
|
177
|
-
"gasPrice": "100000000000"
|
|
178
|
-
}
|
|
179
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"address": "19XWyoWy6DjrRp7erWqPfBnh7HL1Sb2Ub8SVjux2d71Eb",
|
|
4
|
-
"pubKey": "03d3400977a9dabf737714ce672dd60e3e74afc7f9d61fa6a6d74f3e2909f7dc00",
|
|
5
|
-
"priKey": "fff733a4e95a5366625610e30d942587168130f82785c3609d92ae84c149e05e",
|
|
6
|
-
"mnemonic": "space window beach above tiger attract barrel noodle autumn grain update either twelve security shoe teach quote flip reflect maple bike polar ivory gadget"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"address": "1CsutTzw8WVhqr1PB6F1tYinuLihAsAm9FxE7rVkC3Z2u",
|
|
10
|
-
"pubKey": "02b3a0175856c1ac653720cc05eeb84263ec2036e9eeced748e8d643a8607901ae",
|
|
11
|
-
"priKey": "f004e2a5b9435531adef0954ce4106a494731379ee626365907d4e3ac639e9c6",
|
|
12
|
-
"mnemonic": "length hazard scene rabbit tiny soup page almost argue helmet cliff soap then bean artist teach guess sense dose near topic dinner option isolate"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"address": "1CwD52BrUj9e4WDJSZ7RXLU2A8us4ZFSmYBDKu98p7szi",
|
|
16
|
-
"pubKey": "03372b642615c8f32a4af2ca318bc5fc471828428dbc11e29d1a816d0d208d217d",
|
|
17
|
-
"priKey": "7ed7be6e1ba50c217b06f70a0b1e26e844907b3dec2e479ff5d206ad62a073e9",
|
|
18
|
-
"mnemonic": "head add industry horn prepare green budget divide attack reason finish purse flip congress book allow message salute turkey video quote pulse present private"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"address": "1BHSQ8JMeYHZe2kj3KmLjuQCSM3mvzYjNutz14uRPbxZM",
|
|
22
|
-
"pubKey": "02ea6e8cf78e57d4ab758ded570e1a6cd721e6586f34a1200f55a3d3c2a1b0374f",
|
|
23
|
-
"priKey": "7ced95c635863187db397d1b6406497654d27202e9b69edf9ae7f23ab346984b",
|
|
24
|
-
"mnemonic": "lottery mystery chase fatal rural snake moral cricket cash south pitch enlist loyal point turkey rally journey earth rifle deputy metal arm hospital tree"
|
|
25
|
-
}
|
|
26
|
-
]
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"wallets": [
|
|
3
|
-
{
|
|
4
|
-
"mnemonic": "scan pause slender around cube flavor neck shrug gadget ramp rude lend capable tone nose unhappy gift across cluster minor tragic fever detail script",
|
|
5
|
-
"seed": "f585d130dd79d3b5bd63aa99d9bc6e6107cfbbe393b86d70e865f6e75c60a37496afc1b25cd4d1ab3b82d9b41f469c6c112a9f310e441814147ff27a5d65882b",
|
|
6
|
-
"password": "36ae0b75ef06d2e902e473c879c6e853193760ffa5dc29dc8da76133149e0892",
|
|
7
|
-
"file": {
|
|
8
|
-
"encrypted": "b686b4fff0c97e7fcacfd47babccf3ebac60c65035ed1370741424b3de5dbb75d87ac7f7bc0a2309725ec3370c53cd0bc705e3d1e919cdbad539d334398498d29b97689b37c9447b4aaeef3b99d11cadb85028ece6baa62fe74750a26d02f06a71b8e2ff69e112d78999c7f787a7029120bc25ad28e2acfaf4f088b30fea2973e30bd3ced24880a610c121ceddab4e271c17d6dcd0bcec7e6aff921c9409a0bb2e478a5028f1aacc70c72ee7fc64ebc58b4e63db",
|
|
9
|
-
"salt": "fd90b530931ad2fc9a195b719c7f1ecea8519e49a5e9b96d527c87549445c587dd34385f28446b570062286e79600430d190a885198b224e1b10678a0cd6648b",
|
|
10
|
-
"iv": "620bec5b5c612ac5f1f82b529dbdb818ba78c0d5e298a08d4ed9ea63a0bf762ca54414d12bd312e101d16ef95350c46b5ea18cf78d83ed025d5a400406bcdf70",
|
|
11
|
-
"version": 1
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"mnemonic": "fence motor uncle pass zero curve garlic match palm kingdom quality keep undo scissors host lend ginger human loop mad sting horse swap track",
|
|
16
|
-
"seed": "f346de0a6cb3c8f50eb651ed4f17d572f7184813d3366215b4a1a61d7c776bedca41373d9008176bac8cb2ff8216d5cc3542f37fd520b4938295ca85013dbb3c",
|
|
17
|
-
"password": "36ae0b75ef06d2e902e473c879c6e853193760ffa5dc29dc8da76133149e0892",
|
|
18
|
-
"file": {
|
|
19
|
-
"encrypted": "d908a9e2816be754f17b4e80789546783d9e4538240e6585fda17c16343569d03aaac0a10c61122e23d9aa1c988f55d9e88b4d7b271e1f631e8aee02d5dc9e077e6150732381ec06c6f18d4fdde7ed3e09494762d002232a12fbcb5d1f0ca9ac3e6d964d3eb06ed530b10b8b151a66e2ea1eb4e60241b24c631edb31aa7ae99cf5c7f74692f39c534e7deee4e168375da2e6b93b7236fdfcafaade2d2e641498e61888b16d05147a43bb8024",
|
|
20
|
-
"salt": "e30c12732903502d8257cec78c3a1d25b29cd77a45378c43d4c9aed0386fd3c278149354221bdcf18e156d6384f1cb20c120975957f37fa433526f516528d597",
|
|
21
|
-
"iv": "d28a2821343d525a5afc8a17167e0e7f52a7dbc36dcbfbc95819c7f33afd5c6a1cc97a65a2b2bc95387b220a2e9fda7237bd897dfd59ab98e9a7add0c5eeab30",
|
|
22
|
-
"version": 1
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { NodeProvider } from '../api'
|
|
20
|
-
import { Account, SignerWithNodeProvider } from '../signer'
|
|
21
|
-
|
|
22
|
-
export class NodeWallet extends SignerWithNodeProvider {
|
|
23
|
-
public walletName: string
|
|
24
|
-
public accounts: Account[] | undefined
|
|
25
|
-
|
|
26
|
-
constructor(provider: NodeProvider, walletName: string, alwaysSubmitTx = true) {
|
|
27
|
-
super(provider, alwaysSubmitTx)
|
|
28
|
-
this.walletName = walletName
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async getAccounts(): Promise<Account[]> {
|
|
32
|
-
if (typeof this.accounts === 'undefined') {
|
|
33
|
-
this.accounts = await this.getAllAccounts()
|
|
34
|
-
}
|
|
35
|
-
return this.accounts
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private async getAllAccounts(): Promise<Account[]> {
|
|
39
|
-
const walletAddresses = await this.provider.wallets.getWalletsWalletNameAddresses(this.walletName)
|
|
40
|
-
const accounts: Account[] = walletAddresses.addresses.map<Account>((acc) => ({
|
|
41
|
-
publicKey: acc.publicKey,
|
|
42
|
-
address: acc.address,
|
|
43
|
-
group: acc.group
|
|
44
|
-
}))
|
|
45
|
-
return accounts
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static async FromCliqueClient(
|
|
49
|
-
provider: NodeProvider,
|
|
50
|
-
walletName: string,
|
|
51
|
-
alwaysSubmitTx = true
|
|
52
|
-
): Promise<NodeWallet> {
|
|
53
|
-
return new NodeWallet(provider, walletName, alwaysSubmitTx)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async signRaw(signerAddress: string, hexString: string): Promise<string> {
|
|
57
|
-
const currentActiveAddressResponse = await this.provider.wallets.getWalletsWalletNameAddresses(this.walletName)
|
|
58
|
-
const { activeAddress } = currentActiveAddressResponse
|
|
59
|
-
await this.provider.wallets.postWalletsWalletNameChangeActiveAddress(this.walletName, { address: signerAddress })
|
|
60
|
-
const { signature } = await this.provider.wallets.postWalletsWalletNameSign(this.walletName, { data: hexString })
|
|
61
|
-
|
|
62
|
-
await this.provider.wallets.postWalletsWalletNameChangeActiveAddress(this.walletName, { address: activeAddress }) // set the address that's active back to previous state
|
|
63
|
-
|
|
64
|
-
return signature
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async unlock(password: string): Promise<void> {
|
|
68
|
-
return await this.provider.wallets.postWalletsWalletNameUnlock(this.walletName, { password })
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async lock(): Promise<void> {
|
|
72
|
-
return await this.provider.wallets.postWalletsWalletNameLock(this.walletName)
|
|
73
|
-
}
|
|
74
|
-
}
|
package/src/test/index.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { NodeProvider } from '../api'
|
|
20
|
-
import { NodeWallet } from '../signer'
|
|
21
|
-
|
|
22
|
-
export const testWalletName = 'alephium-web3-test-only-wallet'
|
|
23
|
-
export const testAddress = '1DrDyTr9RpRsQnDnXo2YRiPzPW4ooHX5LLoqXrqfMrpQH'
|
|
24
|
-
export const testPassword = 'alph'
|
|
25
|
-
|
|
26
|
-
export async function testWallet(provider: NodeProvider): Promise<NodeWallet> {
|
|
27
|
-
const wallet = new NodeWallet(provider, testWalletName)
|
|
28
|
-
await wallet.unlock(testPassword)
|
|
29
|
-
return wallet
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export * from './privatekey-wallet'
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { ec as EC } from 'elliptic'
|
|
20
|
-
import { NodeProvider } from '../api'
|
|
21
|
-
import { Account, SignerWithNodeProvider } from '../signer'
|
|
22
|
-
import * as utils from '../utils'
|
|
23
|
-
|
|
24
|
-
const ec = new EC('secp256k1')
|
|
25
|
-
|
|
26
|
-
export class PrivateKeyWallet extends SignerWithNodeProvider {
|
|
27
|
-
readonly privateKey: string
|
|
28
|
-
readonly publicKey: string
|
|
29
|
-
readonly address: string
|
|
30
|
-
readonly group: number
|
|
31
|
-
|
|
32
|
-
constructor(provider: NodeProvider, privateKey: string, alwaysSubmitTx = true) {
|
|
33
|
-
super(provider, alwaysSubmitTx)
|
|
34
|
-
this.privateKey = privateKey
|
|
35
|
-
this.publicKey = utils.publicKeyFromPrivateKey(privateKey)
|
|
36
|
-
this.address = utils.addressFromPublicKey(this.publicKey)
|
|
37
|
-
this.group = utils.groupOfAddress(this.address)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static Random(provider: NodeProvider, alwaysSubmitTx = true): PrivateKeyWallet {
|
|
41
|
-
const keyPair = ec.genKeyPair()
|
|
42
|
-
return new PrivateKeyWallet(provider, keyPair.getPrivate().toString('hex'), alwaysSubmitTx)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async getAccounts(): Promise<Account[]> {
|
|
46
|
-
return [{ address: this.address, publicKey: this.publicKey, group: this.group }]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async signRaw(signerAddress: string, hexString: string): Promise<string> {
|
|
50
|
-
if (signerAddress !== this.address) {
|
|
51
|
-
throw Error('Unmatched signer address')
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const key = ec.keyFromPrivate(this.privateKey)
|
|
55
|
-
const signature = key.sign(hexString)
|
|
56
|
-
return utils.signatureEncode(signature)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import EC from 'elliptic'
|
|
20
|
-
import assert from 'assert'
|
|
21
|
-
|
|
22
|
-
import { transactionSign, transactionVerifySignature } from './sign-verify'
|
|
23
|
-
|
|
24
|
-
describe('transaction', function () {
|
|
25
|
-
it('should verify signature', () => {
|
|
26
|
-
const txHash = '8fc5f0d120b730f97f6cea5f02ae4a6ee7bf451d9261c623ea69d85e870201d2'
|
|
27
|
-
const pubKey = '02625b26ae1c5f7986475009e4037b3e6fe6320fde3c3f3332bea11ecadc35dd13'
|
|
28
|
-
const txSig =
|
|
29
|
-
'78471e7c97e558c98ac307ef699ed535ece319102fc69ea416dbb44fbb3cbf9c42dbfbf4ce73eb68c5e0d66122eb25d2ebe1cf9e37ef4c4f4e7a2ed35de141bc'
|
|
30
|
-
const unnormalizedSig =
|
|
31
|
-
'78471e7c97e558c98ac307ef699ed535ece319102fc69ea416dbb44fbb3cbf9cbd24040b318c14973a1f299edd14da2bcecd0d48775953ec71582fb97254ff85'
|
|
32
|
-
const wrongSig =
|
|
33
|
-
'88471e7c97e558c98ac307ef699ed535ece319102fc69ea416dbb44fbb3cbf9c42dbfbf4ce73eb68c5e0d66122eb25d2ebe1cf9e37ef4c4f4e7a2ed35de141bc'
|
|
34
|
-
|
|
35
|
-
assert.strictEqual(transactionVerifySignature(txHash, pubKey, txSig), true)
|
|
36
|
-
assert.strictEqual(transactionVerifySignature(txHash, pubKey, unnormalizedSig), false)
|
|
37
|
-
assert.strictEqual(transactionVerifySignature(txHash, pubKey, wrongSig), false)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('should sign and verify signature', () => {
|
|
41
|
-
const ec = new EC.ec('secp256k1')
|
|
42
|
-
const key = ec.genKeyPair()
|
|
43
|
-
const privateKey = key.getPrivate().toString('hex')
|
|
44
|
-
const publicKey = key.getPublic().encode('hex', true)
|
|
45
|
-
|
|
46
|
-
const txHash = '8fc5f0d120b730f97f6cea5f02ae4a6ee7bf451d9261c623ea69d85e870201d2'
|
|
47
|
-
const signature = transactionSign(txHash, privateKey)
|
|
48
|
-
assert.strictEqual(transactionVerifySignature(txHash, publicKey, signature), true)
|
|
49
|
-
})
|
|
50
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { addressToGroup } from './address'
|
|
20
|
-
|
|
21
|
-
describe('address', function () {
|
|
22
|
-
it('should derive group', async () => {
|
|
23
|
-
function check(address: string, expected: number) {
|
|
24
|
-
const group = addressToGroup(address, 4)
|
|
25
|
-
expect(group).toEqual(expected)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
check('12psscGPMgdqctaeCA37HYAkpVBFX1LbN4dSvjyxbDyKk', 1)
|
|
29
|
-
check('16TGLiD3fqyuGFRFHffh58BC3okYCbjRH1WHPzeSp39Wi', 2)
|
|
30
|
-
check('15aTcpJfCX9akQqYuRMMgun6Mv6ek8bigB98VTUFMwKYA', 1)
|
|
31
|
-
check('164ejvnxGYRPUt3tYwJrMxBLLmeag2WACH4GfcsRUN3W7', 2)
|
|
32
|
-
check('15p5vK921GnxFSQgXZo8Wceg6EvwcXZ9rCQxE2SeXc1s5', 1)
|
|
33
|
-
check('1HSLAetSuMTKPHukvXYg6yaDuUJ67vxGashzFLEuu6qV6', 1)
|
|
34
|
-
check('1HbU1TDiUMAj33Cp5cA2xc9uTqp1bjWa5UvkeGLm4bDbE', 2)
|
|
35
|
-
check('13zn4s3fb5Q9d8rtszYdmYVpQ3MM9VM2xLBe9rMhcNxjd', 0)
|
|
36
|
-
check('1DdQwce5ZzFrEYyz1H5KU9v8hRpoTbq5i7zE5Nu5k4ope', 2)
|
|
37
|
-
check('19hpcUVGzdpWRD8yVUyP9pJwwxD6P5ixGUgSmVPbhBAVX', 2)
|
|
38
|
-
check('1DpNeY8uutS1FRW7D565WjUgu5HcKSYAMqZNWgUJWggWZ', 0)
|
|
39
|
-
check('1G1gjpt4mxij7JwP5SpX6ScwQHisWN3V5WBtFfWKtc3vo', 3)
|
|
40
|
-
check('19XyGb6f1upjvQAG4vexB1EmY3pU8G2VN5gM267Pdhogg', 3)
|
|
41
|
-
check('1H5YniQrUqxJY9ShTjMeX6DMgjPpYfdFqDvTgBYv6h1iz', 1)
|
|
42
|
-
check('18Ca9jZDqRcxTfdNr2hq5KBJjf7PJLA5PXMjRoeB83JNv', 3)
|
|
43
|
-
check('15XyPNJuZ85wyUMs4mwn98LLPMjiwUSCuTmR74NuxpwXT', 0)
|
|
44
|
-
check('1F6ssQRwH1p1omaoQR3eirFrycHC3mUr3Vw9pLcgEe33W', 1)
|
|
45
|
-
check('19JtVnQ4YLcA9mWPafnLmtWarAjdaLR3d7R5RAUjxHbe1', 3)
|
|
46
|
-
})
|
|
47
|
-
})
|
package/src/utils/djb2.test.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { Buffer } from 'buffer/'
|
|
20
|
-
import djb2 from './djb2'
|
|
21
|
-
|
|
22
|
-
describe('djb2', function () {
|
|
23
|
-
it('djb2', async () => {
|
|
24
|
-
function check(str: string, expected: number) {
|
|
25
|
-
const bytes = Buffer.from(str, 'utf8')
|
|
26
|
-
expect(djb2(bytes)).toEqual(expected)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
check('', 5381)
|
|
30
|
-
check('a', 177670)
|
|
31
|
-
check('z', 177695)
|
|
32
|
-
check('foo', 193491849)
|
|
33
|
-
check('bar', 193487034)
|
|
34
|
-
})
|
|
35
|
-
})
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { decrypt } from './password-crypto'
|
|
20
|
-
|
|
21
|
-
describe('password-crypto', () => {
|
|
22
|
-
it('should raise an error if payload version is not 1', () => {
|
|
23
|
-
const password = 'passw0rd'
|
|
24
|
-
const payloadRaw = '{"version":2}'
|
|
25
|
-
expect(() => decrypt(password, payloadRaw)).toThrow('Invalid version: got 2, expected: 1')
|
|
26
|
-
})
|
|
27
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { Buffer } from 'buffer/'
|
|
20
|
-
import { randomBytes, createCipheriv, createDecipheriv, pbkdf2Sync, CipherKey, BinaryLike } from 'crypto'
|
|
21
|
-
|
|
22
|
-
const saltByteLength = 64
|
|
23
|
-
const ivByteLength = 64
|
|
24
|
-
const authTagLength = 16
|
|
25
|
-
|
|
26
|
-
export const encrypt = (password: string, dataRaw: string): string => {
|
|
27
|
-
const data = Buffer.from(dataRaw, 'utf8')
|
|
28
|
-
|
|
29
|
-
const salt = randomBytes(saltByteLength)
|
|
30
|
-
const derivedKey = keyFromPassword(password, salt)
|
|
31
|
-
const iv = randomBytes(ivByteLength)
|
|
32
|
-
const cipher = createCipher(derivedKey, iv)
|
|
33
|
-
const encrypted = Buffer.concat([cipher.update(data), cipher.final()])
|
|
34
|
-
const authTag = cipher.getAuthTag()
|
|
35
|
-
const payload = {
|
|
36
|
-
salt: salt.toString('hex'),
|
|
37
|
-
iv: iv.toString('hex'),
|
|
38
|
-
encrypted: Buffer.concat([encrypted, authTag]).toString('hex'),
|
|
39
|
-
version: 1
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return JSON.stringify(payload)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const decrypt = (password: string, payloadRaw: string): string => {
|
|
46
|
-
const payload = JSON.parse(payloadRaw)
|
|
47
|
-
|
|
48
|
-
const version = payload.version
|
|
49
|
-
if (version !== 1) {
|
|
50
|
-
throw new Error(`Invalid version: got ${version}, expected: 1`)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const salt = Buffer.from(payload.salt, 'hex')
|
|
54
|
-
const iv = Buffer.from(payload.iv, 'hex')
|
|
55
|
-
const encrypted = Buffer.from(payload.encrypted, 'hex')
|
|
56
|
-
|
|
57
|
-
const derivedKey = keyFromPassword(password, salt)
|
|
58
|
-
const decipher = createDecipher(derivedKey, iv)
|
|
59
|
-
const data = encrypted.slice(0, encrypted.length - authTagLength)
|
|
60
|
-
const authTag = encrypted.slice(encrypted.length - authTagLength, encrypted.length)
|
|
61
|
-
decipher.setAuthTag(authTag)
|
|
62
|
-
const decrypted = Buffer.concat([decipher.update(data), decipher.final()])
|
|
63
|
-
|
|
64
|
-
return decrypted.toString('utf8')
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const createCipher = (key: CipherKey, iv: BinaryLike | null) => {
|
|
68
|
-
return createCipheriv('aes-256-gcm', key, iv)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const createDecipher = (key: CipherKey, iv: BinaryLike | null) => {
|
|
72
|
-
return createDecipheriv('aes-256-gcm', key, iv)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const keyFromPassword = (password: BinaryLike, salt: BinaryLike) => {
|
|
76
|
-
return pbkdf2Sync(password, salt, 10000, 32, 'sha256')
|
|
77
|
-
}
|