@secrecy/lib 1.0.0-dev.68 → 1.0.0-dev.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +257 -2
- package/dist/index.d.ts +5016 -18
- package/dist/index.js +257 -2
- package/package.json +4 -4
- package/dist/BaseClient-e5e97df7.d.ts +0 -351
- package/dist/BaseClient.cjs +0 -2
- package/dist/BaseClient.cjs.map +0 -1
- package/dist/BaseClient.d.ts +0 -16
- package/dist/BaseClient.js +0 -2
- package/dist/BaseClient.js.map +0 -1
- package/dist/PopupTools.cjs +0 -2
- package/dist/PopupTools.cjs.map +0 -1
- package/dist/PopupTools.d.ts +0 -18
- package/dist/PopupTools.js +0 -2
- package/dist/PopupTools.js.map +0 -1
- package/dist/ZeusThunder.cjs +0 -2
- package/dist/ZeusThunder.cjs.map +0 -1
- package/dist/ZeusThunder.d.ts +0 -6
- package/dist/ZeusThunder.js +0 -2
- package/dist/ZeusThunder.js.map +0 -1
- package/dist/cache.cjs +0 -2
- package/dist/cache.cjs.map +0 -1
- package/dist/cache.d.ts +0 -24
- package/dist/cache.js +0 -2
- package/dist/cache.js.map +0 -1
- package/dist/chunk-UPFDSEKI.js +0 -2
- package/dist/chunk-UPFDSEKI.js.map +0 -1
- package/dist/chunk-XDPEU3HV.cjs +0 -2
- package/dist/chunk-XDPEU3HV.cjs.map +0 -1
- package/dist/client/SecrecyAppClient.cjs +0 -2
- package/dist/client/SecrecyAppClient.cjs.map +0 -1
- package/dist/client/SecrecyAppClient.d.ts +0 -16
- package/dist/client/SecrecyAppClient.js +0 -2
- package/dist/client/SecrecyAppClient.js.map +0 -1
- package/dist/client/SecrecyCloudClient.cjs +0 -2
- package/dist/client/SecrecyCloudClient.cjs.map +0 -1
- package/dist/client/SecrecyCloudClient.d.ts +0 -16
- package/dist/client/SecrecyCloudClient.js +0 -2
- package/dist/client/SecrecyCloudClient.js.map +0 -1
- package/dist/client/SecrecyDbClient.cjs +0 -2
- package/dist/client/SecrecyDbClient.cjs.map +0 -1
- package/dist/client/SecrecyDbClient.d.ts +0 -16
- package/dist/client/SecrecyDbClient.js +0 -2
- package/dist/client/SecrecyDbClient.js.map +0 -1
- package/dist/client/SecrecyMailClient.cjs +0 -2
- package/dist/client/SecrecyMailClient.cjs.map +0 -1
- package/dist/client/SecrecyMailClient.d.ts +0 -16
- package/dist/client/SecrecyMailClient.js +0 -2
- package/dist/client/SecrecyMailClient.js.map +0 -1
- package/dist/client/SecrecyPayClient.cjs +0 -2
- package/dist/client/SecrecyPayClient.cjs.map +0 -1
- package/dist/client/SecrecyPayClient.d.ts +0 -16
- package/dist/client/SecrecyPayClient.js +0 -2
- package/dist/client/SecrecyPayClient.js.map +0 -1
- package/dist/client/SecrecyWalletClient.cjs +0 -2
- package/dist/client/SecrecyWalletClient.cjs.map +0 -1
- package/dist/client/SecrecyWalletClient.d.ts +0 -16
- package/dist/client/SecrecyWalletClient.js +0 -2
- package/dist/client/SecrecyWalletClient.js.map +0 -1
- package/dist/client/convert/file.cjs +0 -2
- package/dist/client/convert/file.cjs.map +0 -1
- package/dist/client/convert/file.d.ts +0 -11
- package/dist/client/convert/file.js +0 -2
- package/dist/client/convert/file.js.map +0 -1
- package/dist/client/convert/mail.cjs +0 -2
- package/dist/client/convert/mail.cjs.map +0 -1
- package/dist/client/convert/mail.d.ts +0 -13
- package/dist/client/convert/mail.js +0 -2
- package/dist/client/convert/mail.js.map +0 -1
- package/dist/client/convert/node.cjs +0 -2
- package/dist/client/convert/node.cjs.map +0 -1
- package/dist/client/convert/node.d.ts +0 -18
- package/dist/client/convert/node.js +0 -2
- package/dist/client/convert/node.js.map +0 -1
- package/dist/client/helpers.cjs +0 -2
- package/dist/client/helpers.cjs.map +0 -1
- package/dist/client/helpers.d.ts +0 -16
- package/dist/client/helpers.js +0 -2
- package/dist/client/helpers.js.map +0 -1
- package/dist/client/index.cjs +0 -2
- package/dist/client/index.cjs.map +0 -1
- package/dist/client/index.d.ts +0 -16
- package/dist/client/index.js +0 -2
- package/dist/client/index.js.map +0 -1
- package/dist/client/storage.cjs +0 -2
- package/dist/client/storage.cjs.map +0 -1
- package/dist/client/storage.d.ts +0 -10
- package/dist/client/storage.js +0 -2
- package/dist/client/storage.js.map +0 -1
- package/dist/client/types/File.cjs +0 -1
- package/dist/client/types/File.cjs.map +0 -1
- package/dist/client/types/File.d.ts +0 -18
- package/dist/client/types/File.js +0 -1
- package/dist/client/types/File.js.map +0 -1
- package/dist/client/types/Inputs.cjs +0 -1
- package/dist/client/types/Inputs.cjs.map +0 -1
- package/dist/client/types/Inputs.d.ts +0 -18
- package/dist/client/types/Inputs.js +0 -1
- package/dist/client/types/Inputs.js.map +0 -1
- package/dist/client/types/Node.cjs +0 -1
- package/dist/client/types/Node.cjs.map +0 -1
- package/dist/client/types/Node.d.ts +0 -9
- package/dist/client/types/Node.js +0 -1
- package/dist/client/types/Node.js.map +0 -1
- package/dist/client/types/UserAppNotifications.cjs +0 -1
- package/dist/client/types/UserAppNotifications.cjs.map +0 -1
- package/dist/client/types/UserAppNotifications.d.ts +0 -8
- package/dist/client/types/UserAppNotifications.js +0 -1
- package/dist/client/types/UserAppNotifications.js.map +0 -1
- package/dist/client/types/UserAppSettings.cjs +0 -1
- package/dist/client/types/UserAppSettings.cjs.map +0 -1
- package/dist/client/types/UserAppSettings.d.ts +0 -7
- package/dist/client/types/UserAppSettings.js +0 -1
- package/dist/client/types/UserAppSettings.js.map +0 -1
- package/dist/client/types/index.cjs +0 -2
- package/dist/client/types/index.cjs.map +0 -1
- package/dist/client/types/index.d.ts +0 -176
- package/dist/client/types/index.js +0 -2
- package/dist/client/types/index.js.map +0 -1
- package/dist/client/types/selectors.cjs +0 -2
- package/dist/client/types/selectors.cjs.map +0 -1
- package/dist/client/types/selectors.d.ts +0 -402
- package/dist/client/types/selectors.js +0 -2
- package/dist/client/types/selectors.js.map +0 -1
- package/dist/crypto/file.cjs +0 -2
- package/dist/crypto/file.cjs.map +0 -1
- package/dist/crypto/file.d.ts +0 -16
- package/dist/crypto/file.js +0 -2
- package/dist/crypto/file.js.map +0 -1
- package/dist/crypto/index.cjs +0 -2
- package/dist/crypto/index.cjs.map +0 -1
- package/dist/crypto/index.d.ts +0 -14
- package/dist/crypto/index.js +0 -2
- package/dist/crypto/index.js.map +0 -1
- package/dist/error.cjs +0 -1
- package/dist/error.cjs.map +0 -1
- package/dist/error.d.ts +0 -35
- package/dist/error.js +0 -1
- package/dist/error.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/minify/index.cjs +0 -2
- package/dist/minify/index.cjs.map +0 -1
- package/dist/minify/index.d.ts +0 -4
- package/dist/minify/index.js +0 -2
- package/dist/minify/index.js.map +0 -1
- package/dist/minify/lz4.cjs +0 -3
- package/dist/minify/lz4.cjs.map +0 -1
- package/dist/minify/lz4.d.ts +0 -7
- package/dist/minify/lz4.js +0 -3
- package/dist/minify/lz4.js.map +0 -1
- package/dist/sodium.cjs +0 -2
- package/dist/sodium.cjs.map +0 -1
- package/dist/sodium.d.ts +0 -5
- package/dist/sodium.js +0 -2
- package/dist/sodium.js.map +0 -1
- package/dist/utils/store-buddy.cjs +0 -2
- package/dist/utils/store-buddy.cjs.map +0 -1
- package/dist/utils/store-buddy.d.ts +0 -15
- package/dist/utils/store-buddy.js +0 -2
- package/dist/utils/store-buddy.js.map +0 -1
- package/dist/utils/time.cjs +0 -2
- package/dist/utils/time.cjs.map +0 -1
- package/dist/utils/time.d.ts +0 -12
- package/dist/utils/time.js +0 -2
- package/dist/utils/time.js.map +0 -1
- package/dist/utils/utils.cjs +0 -2
- package/dist/utils/utils.cjs.map +0 -1
- package/dist/utils/utils.d.ts +0 -6
- package/dist/utils/utils.js +0 -2
- package/dist/utils/utils.js.map +0 -1
- package/dist/worker/md5.cjs +0 -2
- package/dist/worker/md5.cjs.map +0 -1
- package/dist/worker/md5.d.ts +0 -3
- package/dist/worker/md5.js +0 -2
- package/dist/worker/md5.js.map +0 -1
- package/dist/worker/sodium.cjs +0 -2
- package/dist/worker/sodium.cjs.map +0 -1
- package/dist/worker/sodium.d.ts +0 -6
- package/dist/worker/sodium.js +0 -2
- package/dist/worker/sodium.js.map +0 -1
- package/dist/worker/workerCodes.cjs +0 -254
- package/dist/worker/workerCodes.cjs.map +0 -1
- package/dist/worker/workerCodes.d.ts +0 -4
- package/dist/worker/workerCodes.js +0 -254
- package/dist/worker/workerCodes.js.map +0 -1
- package/dist/zeus/const.cjs +0 -2
- package/dist/zeus/const.cjs.map +0 -1
- package/dist/zeus/const.d.ts +0 -9
- package/dist/zeus/const.js +0 -2
- package/dist/zeus/const.js.map +0 -1
- package/dist/zeus/index.cjs +0 -5
- package/dist/zeus/index.cjs.map +0 -1
- package/dist/zeus/index.d.ts +0 -8218
- package/dist/zeus/index.js +0 -5
- package/dist/zeus/index.js.map +0 -1
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-XDPEU3HV.cjs');const e=`let sodium;
|
|
2
|
-
|
|
3
|
-
self.sodium = {
|
|
4
|
-
onload: (sod) => {
|
|
5
|
-
sodium = sod
|
|
6
|
-
postMessage({ event: "ready" })
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
importScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@master/dist/browsers/sodium.js');
|
|
11
|
-
importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');
|
|
12
|
-
|
|
13
|
-
function* chunks(arr, n) {
|
|
14
|
-
for (let i = 0; i < arr.length; i += n) {
|
|
15
|
-
yield arr.slice(i, i + n);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function assert(c, message) {
|
|
20
|
-
if (!c) {
|
|
21
|
-
throw new Error(message);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function encrypt(key) {
|
|
26
|
-
let destroyed = false;
|
|
27
|
-
const {
|
|
28
|
-
state,
|
|
29
|
-
header
|
|
30
|
-
} = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);
|
|
31
|
-
|
|
32
|
-
const encrypt = (tag, plaintext) => {
|
|
33
|
-
assert(destroyed === false, "state already destroyed");
|
|
34
|
-
|
|
35
|
-
return sodium.crypto_secretstream_xchacha20poly1305_push(
|
|
36
|
-
state,
|
|
37
|
-
plaintext,
|
|
38
|
-
null,
|
|
39
|
-
tag
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
function destroy() {
|
|
44
|
-
assert(destroyed === false, "state already destroyed");
|
|
45
|
-
destroyed = true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
encrypt,
|
|
50
|
-
destroy,
|
|
51
|
-
header
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function decrypt(header, key) {
|
|
56
|
-
assert(
|
|
57
|
-
header.byteLength >=
|
|
58
|
-
sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES,
|
|
59
|
-
"header must be at least HEADERBYTES (" + sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES + ") long"
|
|
60
|
-
);
|
|
61
|
-
assert(
|
|
62
|
-
key.byteLength >= sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES,
|
|
63
|
-
"key must be at least KEYBYTES (" + sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES + ") long"
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
let destroyed = false;
|
|
67
|
-
const state = sodium.crypto_secretstream_xchacha20poly1305_init_pull(
|
|
68
|
-
header,
|
|
69
|
-
key
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const decrypt = ciphertext => {
|
|
73
|
-
assert(destroyed === false, "state already destroyed");
|
|
74
|
-
|
|
75
|
-
return sodium.crypto_secretstream_xchacha20poly1305_pull(state, ciphertext);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
function destroy() {
|
|
79
|
-
assert(destroyed === false, "state already destroyed");
|
|
80
|
-
destroyed = true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
decrypt,
|
|
85
|
-
destroy
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const CHUNK_SIZE = 8192;
|
|
90
|
-
|
|
91
|
-
async function encryptSecretstream(key, data, progress) {
|
|
92
|
-
const { encrypt: crypt, destroy, header } = encrypt(key);
|
|
93
|
-
const cryptedChunk =
|
|
94
|
-
CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;
|
|
95
|
-
const max =
|
|
96
|
-
Math.ceil(data.byteLength / CHUNK_SIZE) * cryptedChunk + header.byteLength;
|
|
97
|
-
|
|
98
|
-
progress?.({
|
|
99
|
-
percent: 0,
|
|
100
|
-
total: max,
|
|
101
|
-
current: 0
|
|
102
|
-
});
|
|
103
|
-
const final = new Uint8Array(max);
|
|
104
|
-
const sparkEncrypted = new SparkMD5.ArrayBuffer();
|
|
105
|
-
const spark = new SparkMD5.ArrayBuffer();
|
|
106
|
-
|
|
107
|
-
final.set(header);
|
|
108
|
-
sparkEncrypted.append(header);
|
|
109
|
-
let total = header.byteLength;
|
|
110
|
-
progress?.({
|
|
111
|
-
percent: total / max,
|
|
112
|
-
total: max,
|
|
113
|
-
current: total
|
|
114
|
-
});
|
|
115
|
-
let lastPercent = total / max;
|
|
116
|
-
|
|
117
|
-
for (const chunk of chunks(data, CHUNK_SIZE)) {
|
|
118
|
-
spark.append(chunk);
|
|
119
|
-
const tag =
|
|
120
|
-
chunk.length < CHUNK_SIZE
|
|
121
|
-
? sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL
|
|
122
|
-
: sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;
|
|
123
|
-
const crypted = crypt(tag, chunk);
|
|
124
|
-
sparkEncrypted.append(crypted);
|
|
125
|
-
final.set(crypted, total);
|
|
126
|
-
total += crypted.byteLength;
|
|
127
|
-
const percent = total / max;
|
|
128
|
-
if (percent > lastPercent + 0.01) {
|
|
129
|
-
progress?.({
|
|
130
|
-
percent,
|
|
131
|
-
total: max,
|
|
132
|
-
current: total
|
|
133
|
-
});
|
|
134
|
-
lastPercent = percent;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
destroy();
|
|
139
|
-
progress?.({
|
|
140
|
-
percent: 1,
|
|
141
|
-
total,
|
|
142
|
-
current: total
|
|
143
|
-
});
|
|
144
|
-
return {
|
|
145
|
-
data: final.slice(0, total),
|
|
146
|
-
md5Encrypted: sparkEncrypted.end(),
|
|
147
|
-
md5: spark.end()
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async function decryptSecretstream(key, data, progress) {
|
|
152
|
-
const header = data.slice(
|
|
153
|
-
0,
|
|
154
|
-
sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES
|
|
155
|
-
);
|
|
156
|
-
data = data.slice(sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES);
|
|
157
|
-
|
|
158
|
-
const { decrypt: decryptt, destroy } = decrypt(header, key);
|
|
159
|
-
const chunkSize =
|
|
160
|
-
CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;
|
|
161
|
-
const max = Math.ceil(data.byteLength / chunkSize) * CHUNK_SIZE;
|
|
162
|
-
|
|
163
|
-
progress?.({
|
|
164
|
-
percent: 0,
|
|
165
|
-
total: max,
|
|
166
|
-
current: 0
|
|
167
|
-
});
|
|
168
|
-
const final = new Uint8Array(max);
|
|
169
|
-
let total = 0;
|
|
170
|
-
let lastPercent = total / max;
|
|
171
|
-
|
|
172
|
-
for (const chunk of chunks(data, chunkSize)) {
|
|
173
|
-
const tmp = decryptt(chunk);
|
|
174
|
-
final.set(tmp.message, total);
|
|
175
|
-
total += tmp.message.byteLength;
|
|
176
|
-
|
|
177
|
-
const percent = total / max;
|
|
178
|
-
if (percent > lastPercent + 0.01) {
|
|
179
|
-
progress?.({
|
|
180
|
-
percent,
|
|
181
|
-
total: max,
|
|
182
|
-
current: total
|
|
183
|
-
});
|
|
184
|
-
lastPercent = percent;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
destroy();
|
|
189
|
-
progress?.({
|
|
190
|
-
percent: 1,
|
|
191
|
-
total,
|
|
192
|
-
current: total
|
|
193
|
-
});
|
|
194
|
-
return final.slice(0, total);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
self.onmessage = async ({ data }) => {
|
|
198
|
-
switch (data.event) {
|
|
199
|
-
case "encrypt": {
|
|
200
|
-
postMessage({ event: "working" })
|
|
201
|
-
postMessage({
|
|
202
|
-
event: "encrypt-result",
|
|
203
|
-
data: await encryptSecretstream(data.key, data.data, progress => postMessage({
|
|
204
|
-
event: "encrypt-progress",
|
|
205
|
-
data: progress
|
|
206
|
-
}))
|
|
207
|
-
});
|
|
208
|
-
postMessage({ event: "ready" })
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
case "decrypt": {
|
|
212
|
-
postMessage({ event: "working" })
|
|
213
|
-
postMessage({
|
|
214
|
-
event: "decrypt-result",
|
|
215
|
-
data: await decryptSecretstream(data.key, data.data, progress => postMessage({
|
|
216
|
-
event: "decrypt-progress",
|
|
217
|
-
data: progress
|
|
218
|
-
}))
|
|
219
|
-
});
|
|
220
|
-
postMessage({ event: "ready" })
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}`,t= exports.workerMd5Script =`importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');
|
|
225
|
-
|
|
226
|
-
function* chunks(arr, n) {
|
|
227
|
-
for (let i = 0; i < arr.length; i += n) {
|
|
228
|
-
yield arr.slice(i, i + n);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const CHUNK_SIZE = 8192;
|
|
233
|
-
|
|
234
|
-
function md5(data) {
|
|
235
|
-
const spark = new SparkMD5.ArrayBuffer();
|
|
236
|
-
for (const chunk of chunks(data, CHUNK_SIZE)) {
|
|
237
|
-
spark.append(chunk);
|
|
238
|
-
}
|
|
239
|
-
return spark.end();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
self.onmessage = ({ data }) => {
|
|
244
|
-
switch (data.event) {
|
|
245
|
-
case "md5": {
|
|
246
|
-
postMessage({
|
|
247
|
-
event: "md5-result",
|
|
248
|
-
data: md5(data.data)
|
|
249
|
-
});
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}`;exports.workerMd5Script = t; exports.workerSodiumScript = e;
|
|
254
|
-
//# sourceMappingURL=workerCodes.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/worker/workerCodes.ts"],"names":["workerSodiumScript","workerMd5Script"],"mappings":"8BAAO,MAAMA,EAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAiOrBC,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export const workerSodiumScript = `let sodium;\n\nself.sodium = {\n onload: (sod) => {\n sodium = sod\n postMessage({ event: \"ready\" })\n }\n};\n\nimportScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@master/dist/browsers/sodium.js');\nimportScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');\n\nfunction* chunks(arr, n) {\n for (let i = 0; i < arr.length; i += n) {\n yield arr.slice(i, i + n);\n }\n}\n\nfunction assert(c, message) {\n if (!c) {\n throw new Error(message);\n }\n}\n\nfunction encrypt(key) {\n let destroyed = false;\n const {\n state,\n header\n } = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);\n\n const encrypt = (tag, plaintext) => {\n assert(destroyed === false, \"state already destroyed\");\n\n return sodium.crypto_secretstream_xchacha20poly1305_push(\n state,\n plaintext,\n null,\n tag\n );\n };\n\n function destroy() {\n assert(destroyed === false, \"state already destroyed\");\n destroyed = true;\n }\n\n return {\n encrypt,\n destroy,\n header\n };\n}\n\nfunction decrypt(header, key) {\n assert(\n header.byteLength >=\n sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES,\n \"header must be at least HEADERBYTES (\" + sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES + \") long\"\n );\n assert(\n key.byteLength >= sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES,\n \"key must be at least KEYBYTES (\" + sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES + \") long\"\n );\n\n let destroyed = false;\n const state = sodium.crypto_secretstream_xchacha20poly1305_init_pull(\n header,\n key\n );\n\n const decrypt = ciphertext => {\n assert(destroyed === false, \"state already destroyed\");\n\n return sodium.crypto_secretstream_xchacha20poly1305_pull(state, ciphertext);\n };\n\n function destroy() {\n assert(destroyed === false, \"state already destroyed\");\n destroyed = true;\n }\n\n return {\n decrypt,\n destroy\n };\n}\n\nconst CHUNK_SIZE = 8192;\n\nasync function encryptSecretstream(key, data, progress) {\n const { encrypt: crypt, destroy, header } = encrypt(key);\n const cryptedChunk =\n CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;\n const max =\n Math.ceil(data.byteLength / CHUNK_SIZE) * cryptedChunk + header.byteLength;\n\n progress?.({\n percent: 0,\n total: max,\n current: 0\n });\n const final = new Uint8Array(max);\n const sparkEncrypted = new SparkMD5.ArrayBuffer();\n const spark = new SparkMD5.ArrayBuffer();\n\n final.set(header);\n sparkEncrypted.append(header);\n let total = header.byteLength;\n progress?.({\n percent: total / max,\n total: max,\n current: total\n });\n let lastPercent = total / max;\n\n for (const chunk of chunks(data, CHUNK_SIZE)) {\n spark.append(chunk);\n const tag =\n chunk.length < CHUNK_SIZE\n ? sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL\n : sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;\n const crypted = crypt(tag, chunk);\n sparkEncrypted.append(crypted);\n final.set(crypted, total);\n total += crypted.byteLength;\n const percent = total / max;\n if (percent > lastPercent + 0.01) {\n progress?.({\n percent,\n total: max,\n current: total\n });\n lastPercent = percent;\n }\n }\n\n destroy();\n progress?.({\n percent: 1,\n total,\n current: total\n });\n return {\n data: final.slice(0, total),\n md5Encrypted: sparkEncrypted.end(),\n md5: spark.end()\n };\n}\n\nasync function decryptSecretstream(key, data, progress) {\n const header = data.slice(\n 0,\n sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES\n );\n data = data.slice(sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES);\n\n const { decrypt: decryptt, destroy } = decrypt(header, key);\n const chunkSize =\n CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;\n const max = Math.ceil(data.byteLength / chunkSize) * CHUNK_SIZE;\n\n progress?.({\n percent: 0,\n total: max,\n current: 0\n });\n const final = new Uint8Array(max);\n let total = 0;\n let lastPercent = total / max;\n\n for (const chunk of chunks(data, chunkSize)) {\n const tmp = decryptt(chunk);\n final.set(tmp.message, total);\n total += tmp.message.byteLength;\n\n const percent = total / max;\n if (percent > lastPercent + 0.01) {\n progress?.({\n percent,\n total: max,\n current: total\n });\n lastPercent = percent;\n }\n }\n\n destroy();\n progress?.({\n percent: 1,\n total,\n current: total\n });\n return final.slice(0, total);\n}\n\nself.onmessage = async ({ data }) => {\n switch (data.event) {\n case \"encrypt\": {\n postMessage({ event: \"working\" })\n postMessage({\n event: \"encrypt-result\",\n data: await encryptSecretstream(data.key, data.data, progress => postMessage({\n event: \"encrypt-progress\",\n data: progress\n }))\n });\n postMessage({ event: \"ready\" })\n break;\n }\n case \"decrypt\": {\n postMessage({ event: \"working\" })\n postMessage({\n event: \"decrypt-result\",\n data: await decryptSecretstream(data.key, data.data, progress => postMessage({\n event: \"decrypt-progress\",\n data: progress\n }))\n });\n postMessage({ event: \"ready\" })\n break;\n }\n }\n}`;\n\nexport const workerMd5Script = `importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');\n\nfunction* chunks(arr, n) {\n for (let i = 0; i < arr.length; i += n) {\n yield arr.slice(i, i + n);\n }\n}\n\nconst CHUNK_SIZE = 8192;\n\nfunction md5(data) {\n const spark = new SparkMD5.ArrayBuffer();\n for (const chunk of chunks(data, CHUNK_SIZE)) {\n spark.append(chunk);\n }\n return spark.end();\n}\n\n\nself.onmessage = ({ data }) => {\n switch (data.event) {\n case \"md5\": {\n postMessage({\n event: \"md5-result\",\n data: md5(data.data)\n });\n break;\n }\n }\n}`;\n"]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
declare const workerSodiumScript = "let sodium;\n\nself.sodium = {\n onload: (sod) => {\n sodium = sod\n postMessage({ event: \"ready\" })\n }\n};\n\nimportScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@master/dist/browsers/sodium.js');\nimportScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');\n\nfunction* chunks(arr, n) {\n for (let i = 0; i < arr.length; i += n) {\n yield arr.slice(i, i + n);\n }\n}\n\nfunction assert(c, message) {\n if (!c) {\n throw new Error(message);\n }\n}\n\nfunction encrypt(key) {\n let destroyed = false;\n const {\n state,\n header\n } = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);\n\n const encrypt = (tag, plaintext) => {\n assert(destroyed === false, \"state already destroyed\");\n\n return sodium.crypto_secretstream_xchacha20poly1305_push(\n state,\n plaintext,\n null,\n tag\n );\n };\n\n function destroy() {\n assert(destroyed === false, \"state already destroyed\");\n destroyed = true;\n }\n\n return {\n encrypt,\n destroy,\n header\n };\n}\n\nfunction decrypt(header, key) {\n assert(\n header.byteLength >=\n sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES,\n \"header must be at least HEADERBYTES (\" + sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES + \") long\"\n );\n assert(\n key.byteLength >= sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES,\n \"key must be at least KEYBYTES (\" + sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES + \") long\"\n );\n\n let destroyed = false;\n const state = sodium.crypto_secretstream_xchacha20poly1305_init_pull(\n header,\n key\n );\n\n const decrypt = ciphertext => {\n assert(destroyed === false, \"state already destroyed\");\n\n return sodium.crypto_secretstream_xchacha20poly1305_pull(state, ciphertext);\n };\n\n function destroy() {\n assert(destroyed === false, \"state already destroyed\");\n destroyed = true;\n }\n\n return {\n decrypt,\n destroy\n };\n}\n\nconst CHUNK_SIZE = 8192;\n\nasync function encryptSecretstream(key, data, progress) {\n const { encrypt: crypt, destroy, header } = encrypt(key);\n const cryptedChunk =\n CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;\n const max =\n Math.ceil(data.byteLength / CHUNK_SIZE) * cryptedChunk + header.byteLength;\n\n progress?.({\n percent: 0,\n total: max,\n current: 0\n });\n const final = new Uint8Array(max);\n const sparkEncrypted = new SparkMD5.ArrayBuffer();\n const spark = new SparkMD5.ArrayBuffer();\n\n final.set(header);\n sparkEncrypted.append(header);\n let total = header.byteLength;\n progress?.({\n percent: total / max,\n total: max,\n current: total\n });\n let lastPercent = total / max;\n\n for (const chunk of chunks(data, CHUNK_SIZE)) {\n spark.append(chunk);\n const tag =\n chunk.length < CHUNK_SIZE\n ? sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL\n : sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;\n const crypted = crypt(tag, chunk);\n sparkEncrypted.append(crypted);\n final.set(crypted, total);\n total += crypted.byteLength;\n const percent = total / max;\n if (percent > lastPercent + 0.01) {\n progress?.({\n percent,\n total: max,\n current: total\n });\n lastPercent = percent;\n }\n }\n\n destroy();\n progress?.({\n percent: 1,\n total,\n current: total\n });\n return {\n data: final.slice(0, total),\n md5Encrypted: sparkEncrypted.end(),\n md5: spark.end()\n };\n}\n\nasync function decryptSecretstream(key, data, progress) {\n const header = data.slice(\n 0,\n sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES\n );\n data = data.slice(sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES);\n\n const { decrypt: decryptt, destroy } = decrypt(header, key);\n const chunkSize =\n CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;\n const max = Math.ceil(data.byteLength / chunkSize) * CHUNK_SIZE;\n\n progress?.({\n percent: 0,\n total: max,\n current: 0\n });\n const final = new Uint8Array(max);\n let total = 0;\n let lastPercent = total / max;\n\n for (const chunk of chunks(data, chunkSize)) {\n const tmp = decryptt(chunk);\n final.set(tmp.message, total);\n total += tmp.message.byteLength;\n\n const percent = total / max;\n if (percent > lastPercent + 0.01) {\n progress?.({\n percent,\n total: max,\n current: total\n });\n lastPercent = percent;\n }\n }\n\n destroy();\n progress?.({\n percent: 1,\n total,\n current: total\n });\n return final.slice(0, total);\n}\n\nself.onmessage = async ({ data }) => {\n switch (data.event) {\n case \"encrypt\": {\n postMessage({ event: \"working\" })\n postMessage({\n event: \"encrypt-result\",\n data: await encryptSecretstream(data.key, data.data, progress => postMessage({\n event: \"encrypt-progress\",\n data: progress\n }))\n });\n postMessage({ event: \"ready\" })\n break;\n }\n case \"decrypt\": {\n postMessage({ event: \"working\" })\n postMessage({\n event: \"decrypt-result\",\n data: await decryptSecretstream(data.key, data.data, progress => postMessage({\n event: \"decrypt-progress\",\n data: progress\n }))\n });\n postMessage({ event: \"ready\" })\n break;\n }\n }\n}";
|
|
2
|
-
declare const workerMd5Script = "importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');\n\nfunction* chunks(arr, n) {\n for (let i = 0; i < arr.length; i += n) {\n yield arr.slice(i, i + n);\n }\n}\n\nconst CHUNK_SIZE = 8192;\n\nfunction md5(data) {\n const spark = new SparkMD5.ArrayBuffer();\n for (const chunk of chunks(data, CHUNK_SIZE)) {\n spark.append(chunk);\n }\n return spark.end();\n}\n\n\nself.onmessage = ({ data }) => {\n switch (data.event) {\n case \"md5\": {\n postMessage({\n event: \"md5-result\",\n data: md5(data.data)\n });\n break;\n }\n }\n}";
|
|
3
|
-
|
|
4
|
-
export { workerMd5Script, workerSodiumScript };
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import"../chunk-UPFDSEKI.js";const e=`let sodium;
|
|
2
|
-
|
|
3
|
-
self.sodium = {
|
|
4
|
-
onload: (sod) => {
|
|
5
|
-
sodium = sod
|
|
6
|
-
postMessage({ event: "ready" })
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
importScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@master/dist/browsers/sodium.js');
|
|
11
|
-
importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');
|
|
12
|
-
|
|
13
|
-
function* chunks(arr, n) {
|
|
14
|
-
for (let i = 0; i < arr.length; i += n) {
|
|
15
|
-
yield arr.slice(i, i + n);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function assert(c, message) {
|
|
20
|
-
if (!c) {
|
|
21
|
-
throw new Error(message);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function encrypt(key) {
|
|
26
|
-
let destroyed = false;
|
|
27
|
-
const {
|
|
28
|
-
state,
|
|
29
|
-
header
|
|
30
|
-
} = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);
|
|
31
|
-
|
|
32
|
-
const encrypt = (tag, plaintext) => {
|
|
33
|
-
assert(destroyed === false, "state already destroyed");
|
|
34
|
-
|
|
35
|
-
return sodium.crypto_secretstream_xchacha20poly1305_push(
|
|
36
|
-
state,
|
|
37
|
-
plaintext,
|
|
38
|
-
null,
|
|
39
|
-
tag
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
function destroy() {
|
|
44
|
-
assert(destroyed === false, "state already destroyed");
|
|
45
|
-
destroyed = true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
encrypt,
|
|
50
|
-
destroy,
|
|
51
|
-
header
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function decrypt(header, key) {
|
|
56
|
-
assert(
|
|
57
|
-
header.byteLength >=
|
|
58
|
-
sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES,
|
|
59
|
-
"header must be at least HEADERBYTES (" + sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES + ") long"
|
|
60
|
-
);
|
|
61
|
-
assert(
|
|
62
|
-
key.byteLength >= sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES,
|
|
63
|
-
"key must be at least KEYBYTES (" + sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES + ") long"
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
let destroyed = false;
|
|
67
|
-
const state = sodium.crypto_secretstream_xchacha20poly1305_init_pull(
|
|
68
|
-
header,
|
|
69
|
-
key
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const decrypt = ciphertext => {
|
|
73
|
-
assert(destroyed === false, "state already destroyed");
|
|
74
|
-
|
|
75
|
-
return sodium.crypto_secretstream_xchacha20poly1305_pull(state, ciphertext);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
function destroy() {
|
|
79
|
-
assert(destroyed === false, "state already destroyed");
|
|
80
|
-
destroyed = true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
decrypt,
|
|
85
|
-
destroy
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const CHUNK_SIZE = 8192;
|
|
90
|
-
|
|
91
|
-
async function encryptSecretstream(key, data, progress) {
|
|
92
|
-
const { encrypt: crypt, destroy, header } = encrypt(key);
|
|
93
|
-
const cryptedChunk =
|
|
94
|
-
CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;
|
|
95
|
-
const max =
|
|
96
|
-
Math.ceil(data.byteLength / CHUNK_SIZE) * cryptedChunk + header.byteLength;
|
|
97
|
-
|
|
98
|
-
progress?.({
|
|
99
|
-
percent: 0,
|
|
100
|
-
total: max,
|
|
101
|
-
current: 0
|
|
102
|
-
});
|
|
103
|
-
const final = new Uint8Array(max);
|
|
104
|
-
const sparkEncrypted = new SparkMD5.ArrayBuffer();
|
|
105
|
-
const spark = new SparkMD5.ArrayBuffer();
|
|
106
|
-
|
|
107
|
-
final.set(header);
|
|
108
|
-
sparkEncrypted.append(header);
|
|
109
|
-
let total = header.byteLength;
|
|
110
|
-
progress?.({
|
|
111
|
-
percent: total / max,
|
|
112
|
-
total: max,
|
|
113
|
-
current: total
|
|
114
|
-
});
|
|
115
|
-
let lastPercent = total / max;
|
|
116
|
-
|
|
117
|
-
for (const chunk of chunks(data, CHUNK_SIZE)) {
|
|
118
|
-
spark.append(chunk);
|
|
119
|
-
const tag =
|
|
120
|
-
chunk.length < CHUNK_SIZE
|
|
121
|
-
? sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL
|
|
122
|
-
: sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;
|
|
123
|
-
const crypted = crypt(tag, chunk);
|
|
124
|
-
sparkEncrypted.append(crypted);
|
|
125
|
-
final.set(crypted, total);
|
|
126
|
-
total += crypted.byteLength;
|
|
127
|
-
const percent = total / max;
|
|
128
|
-
if (percent > lastPercent + 0.01) {
|
|
129
|
-
progress?.({
|
|
130
|
-
percent,
|
|
131
|
-
total: max,
|
|
132
|
-
current: total
|
|
133
|
-
});
|
|
134
|
-
lastPercent = percent;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
destroy();
|
|
139
|
-
progress?.({
|
|
140
|
-
percent: 1,
|
|
141
|
-
total,
|
|
142
|
-
current: total
|
|
143
|
-
});
|
|
144
|
-
return {
|
|
145
|
-
data: final.slice(0, total),
|
|
146
|
-
md5Encrypted: sparkEncrypted.end(),
|
|
147
|
-
md5: spark.end()
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async function decryptSecretstream(key, data, progress) {
|
|
152
|
-
const header = data.slice(
|
|
153
|
-
0,
|
|
154
|
-
sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES
|
|
155
|
-
);
|
|
156
|
-
data = data.slice(sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES);
|
|
157
|
-
|
|
158
|
-
const { decrypt: decryptt, destroy } = decrypt(header, key);
|
|
159
|
-
const chunkSize =
|
|
160
|
-
CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;
|
|
161
|
-
const max = Math.ceil(data.byteLength / chunkSize) * CHUNK_SIZE;
|
|
162
|
-
|
|
163
|
-
progress?.({
|
|
164
|
-
percent: 0,
|
|
165
|
-
total: max,
|
|
166
|
-
current: 0
|
|
167
|
-
});
|
|
168
|
-
const final = new Uint8Array(max);
|
|
169
|
-
let total = 0;
|
|
170
|
-
let lastPercent = total / max;
|
|
171
|
-
|
|
172
|
-
for (const chunk of chunks(data, chunkSize)) {
|
|
173
|
-
const tmp = decryptt(chunk);
|
|
174
|
-
final.set(tmp.message, total);
|
|
175
|
-
total += tmp.message.byteLength;
|
|
176
|
-
|
|
177
|
-
const percent = total / max;
|
|
178
|
-
if (percent > lastPercent + 0.01) {
|
|
179
|
-
progress?.({
|
|
180
|
-
percent,
|
|
181
|
-
total: max,
|
|
182
|
-
current: total
|
|
183
|
-
});
|
|
184
|
-
lastPercent = percent;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
destroy();
|
|
189
|
-
progress?.({
|
|
190
|
-
percent: 1,
|
|
191
|
-
total,
|
|
192
|
-
current: total
|
|
193
|
-
});
|
|
194
|
-
return final.slice(0, total);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
self.onmessage = async ({ data }) => {
|
|
198
|
-
switch (data.event) {
|
|
199
|
-
case "encrypt": {
|
|
200
|
-
postMessage({ event: "working" })
|
|
201
|
-
postMessage({
|
|
202
|
-
event: "encrypt-result",
|
|
203
|
-
data: await encryptSecretstream(data.key, data.data, progress => postMessage({
|
|
204
|
-
event: "encrypt-progress",
|
|
205
|
-
data: progress
|
|
206
|
-
}))
|
|
207
|
-
});
|
|
208
|
-
postMessage({ event: "ready" })
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
case "decrypt": {
|
|
212
|
-
postMessage({ event: "working" })
|
|
213
|
-
postMessage({
|
|
214
|
-
event: "decrypt-result",
|
|
215
|
-
data: await decryptSecretstream(data.key, data.data, progress => postMessage({
|
|
216
|
-
event: "decrypt-progress",
|
|
217
|
-
data: progress
|
|
218
|
-
}))
|
|
219
|
-
});
|
|
220
|
-
postMessage({ event: "ready" })
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}`,t=`importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');
|
|
225
|
-
|
|
226
|
-
function* chunks(arr, n) {
|
|
227
|
-
for (let i = 0; i < arr.length; i += n) {
|
|
228
|
-
yield arr.slice(i, i + n);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const CHUNK_SIZE = 8192;
|
|
233
|
-
|
|
234
|
-
function md5(data) {
|
|
235
|
-
const spark = new SparkMD5.ArrayBuffer();
|
|
236
|
-
for (const chunk of chunks(data, CHUNK_SIZE)) {
|
|
237
|
-
spark.append(chunk);
|
|
238
|
-
}
|
|
239
|
-
return spark.end();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
self.onmessage = ({ data }) => {
|
|
244
|
-
switch (data.event) {
|
|
245
|
-
case "md5": {
|
|
246
|
-
postMessage({
|
|
247
|
-
event: "md5-result",
|
|
248
|
-
data: md5(data.data)
|
|
249
|
-
});
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}`;export{t as workerMd5Script,e as workerSodiumScript};
|
|
254
|
-
//# sourceMappingURL=workerCodes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/worker/workerCodes.ts"],"sourcesContent":["export const workerSodiumScript = `let sodium;\n\nself.sodium = {\n onload: (sod) => {\n sodium = sod\n postMessage({ event: \"ready\" })\n }\n};\n\nimportScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@master/dist/browsers/sodium.js');\nimportScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');\n\nfunction* chunks(arr, n) {\n for (let i = 0; i < arr.length; i += n) {\n yield arr.slice(i, i + n);\n }\n}\n\nfunction assert(c, message) {\n if (!c) {\n throw new Error(message);\n }\n}\n\nfunction encrypt(key) {\n let destroyed = false;\n const {\n state,\n header\n } = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);\n\n const encrypt = (tag, plaintext) => {\n assert(destroyed === false, \"state already destroyed\");\n\n return sodium.crypto_secretstream_xchacha20poly1305_push(\n state,\n plaintext,\n null,\n tag\n );\n };\n\n function destroy() {\n assert(destroyed === false, \"state already destroyed\");\n destroyed = true;\n }\n\n return {\n encrypt,\n destroy,\n header\n };\n}\n\nfunction decrypt(header, key) {\n assert(\n header.byteLength >=\n sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES,\n \"header must be at least HEADERBYTES (\" + sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES + \") long\"\n );\n assert(\n key.byteLength >= sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES,\n \"key must be at least KEYBYTES (\" + sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES + \") long\"\n );\n\n let destroyed = false;\n const state = sodium.crypto_secretstream_xchacha20poly1305_init_pull(\n header,\n key\n );\n\n const decrypt = ciphertext => {\n assert(destroyed === false, \"state already destroyed\");\n\n return sodium.crypto_secretstream_xchacha20poly1305_pull(state, ciphertext);\n };\n\n function destroy() {\n assert(destroyed === false, \"state already destroyed\");\n destroyed = true;\n }\n\n return {\n decrypt,\n destroy\n };\n}\n\nconst CHUNK_SIZE = 8192;\n\nasync function encryptSecretstream(key, data, progress) {\n const { encrypt: crypt, destroy, header } = encrypt(key);\n const cryptedChunk =\n CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;\n const max =\n Math.ceil(data.byteLength / CHUNK_SIZE) * cryptedChunk + header.byteLength;\n\n progress?.({\n percent: 0,\n total: max,\n current: 0\n });\n const final = new Uint8Array(max);\n const sparkEncrypted = new SparkMD5.ArrayBuffer();\n const spark = new SparkMD5.ArrayBuffer();\n\n final.set(header);\n sparkEncrypted.append(header);\n let total = header.byteLength;\n progress?.({\n percent: total / max,\n total: max,\n current: total\n });\n let lastPercent = total / max;\n\n for (const chunk of chunks(data, CHUNK_SIZE)) {\n spark.append(chunk);\n const tag =\n chunk.length < CHUNK_SIZE\n ? sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL\n : sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;\n const crypted = crypt(tag, chunk);\n sparkEncrypted.append(crypted);\n final.set(crypted, total);\n total += crypted.byteLength;\n const percent = total / max;\n if (percent > lastPercent + 0.01) {\n progress?.({\n percent,\n total: max,\n current: total\n });\n lastPercent = percent;\n }\n }\n\n destroy();\n progress?.({\n percent: 1,\n total,\n current: total\n });\n return {\n data: final.slice(0, total),\n md5Encrypted: sparkEncrypted.end(),\n md5: spark.end()\n };\n}\n\nasync function decryptSecretstream(key, data, progress) {\n const header = data.slice(\n 0,\n sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES\n );\n data = data.slice(sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES);\n\n const { decrypt: decryptt, destroy } = decrypt(header, key);\n const chunkSize =\n CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;\n const max = Math.ceil(data.byteLength / chunkSize) * CHUNK_SIZE;\n\n progress?.({\n percent: 0,\n total: max,\n current: 0\n });\n const final = new Uint8Array(max);\n let total = 0;\n let lastPercent = total / max;\n\n for (const chunk of chunks(data, chunkSize)) {\n const tmp = decryptt(chunk);\n final.set(tmp.message, total);\n total += tmp.message.byteLength;\n\n const percent = total / max;\n if (percent > lastPercent + 0.01) {\n progress?.({\n percent,\n total: max,\n current: total\n });\n lastPercent = percent;\n }\n }\n\n destroy();\n progress?.({\n percent: 1,\n total,\n current: total\n });\n return final.slice(0, total);\n}\n\nself.onmessage = async ({ data }) => {\n switch (data.event) {\n case \"encrypt\": {\n postMessage({ event: \"working\" })\n postMessage({\n event: \"encrypt-result\",\n data: await encryptSecretstream(data.key, data.data, progress => postMessage({\n event: \"encrypt-progress\",\n data: progress\n }))\n });\n postMessage({ event: \"ready\" })\n break;\n }\n case \"decrypt\": {\n postMessage({ event: \"working\" })\n postMessage({\n event: \"decrypt-result\",\n data: await decryptSecretstream(data.key, data.data, progress => postMessage({\n event: \"decrypt-progress\",\n data: progress\n }))\n });\n postMessage({ event: \"ready\" })\n break;\n }\n }\n}`;\n\nexport const workerMd5Script = `importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');\n\nfunction* chunks(arr, n) {\n for (let i = 0; i < arr.length; i += n) {\n yield arr.slice(i, i + n);\n }\n}\n\nconst CHUNK_SIZE = 8192;\n\nfunction md5(data) {\n const spark = new SparkMD5.ArrayBuffer();\n for (const chunk of chunks(data, CHUNK_SIZE)) {\n spark.append(chunk);\n }\n return spark.end();\n}\n\n\nself.onmessage = ({ data }) => {\n switch (data.event) {\n case \"md5\": {\n postMessage({\n event: \"md5-result\",\n data: md5(data.data)\n });\n break;\n }\n }\n}`;\n"],"mappings":"6BAAO,MAAMA,EAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAiOrBC,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":["workerSodiumScript","workerMd5Script"]}
|