@secrecy/lib 1.86.3 → 1.86.4-fix-md5.1
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/lib/client/SecrecyCloudClient.js +4 -2
- package/dist/lib/client/data-link.js +6 -12
- package/dist/lib/client/helpers.js +4 -16
- package/dist/lib/client/upload.js +12 -14
- package/dist/lib/crypto/data.js +146 -91
- package/dist/lib/crypto/domain.js +1 -3
- package/dist/lib/crypto/helpers.js +23 -1
- package/dist/lib/crypto/index.js +2 -9
- package/dist/lib/utils/popup-tools.js +18 -8
- package/dist/lib/versioning.js +1 -1
- package/dist/lib/worker/generated/md5.js +2 -0
- package/dist/lib/worker/generated/sodium.js +2 -0
- package/dist/lib/worker/md5.js +2 -2
- package/dist/lib/worker/sodium.js +17 -15
- package/dist/types/client/data-link.d.ts +4 -4
- package/dist/types/client/helpers.d.ts +0 -1
- package/dist/types/client/types/data.d.ts +2 -1
- package/dist/types/client.d.ts +66 -74
- package/dist/types/crypto/data.d.ts +11 -1
- package/dist/types/crypto/domain.d.ts +0 -1
- package/dist/types/crypto/helpers.d.ts +7 -0
- package/dist/types/crypto/index.d.ts +3 -3
- package/dist/types/sodium.d.ts +5 -0
- package/dist/types/utils/popup-tools.d.ts +4 -0
- package/dist/types/versioning.d.ts +1 -1
- package/dist/types/worker/generated/md5.d.ts +1 -0
- package/dist/types/worker/generated/sodium.d.ts +1 -0
- package/package.json +8 -8
- package/dist/lib/worker/workerCodes.js +0 -254
- package/dist/types/worker/workerCodes.d.ts +0 -2
package/dist/lib/worker/md5.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import SparkMD5 from 'spark-md5';
|
|
2
|
-
import { workerMd5Script } from './workerCodes.js';
|
|
3
2
|
function* chunks(arr, n) {
|
|
4
3
|
for (let i = 0; i < arr.length; i += n) {
|
|
5
4
|
yield arr.slice(i, i + n);
|
|
@@ -8,8 +7,9 @@ function* chunks(arr, n) {
|
|
|
8
7
|
const CHUNK_SIZE = 8192;
|
|
9
8
|
export const md5 = process.env.NODE_ENV !== 'test'
|
|
10
9
|
? async (data) => {
|
|
10
|
+
const { workerMd5Script } = await import('./generated/md5.js');
|
|
11
|
+
const worker = new Worker(URL.createObjectURL(new Blob([workerMd5Script], { type: 'text/javascript' })));
|
|
11
12
|
return await new Promise((resolve, reject) => {
|
|
12
|
-
const worker = new Worker(URL.createObjectURL(new Blob([workerMd5Script], { type: 'text/javascript' })));
|
|
13
13
|
worker.addEventListener('error', reject);
|
|
14
14
|
worker.addEventListener('messageerror', reject);
|
|
15
15
|
worker.addEventListener('message', ({ data }) => {
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import { decryptSecretStream, encryptSecretStream, } from '../crypto/data.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// values.filter(v => {
|
|
8
|
-
// if (v instanceof ArrayBuffer) {
|
|
9
|
-
// return v.byteLength === 0;
|
|
10
|
-
// } else {
|
|
11
|
-
// return true;
|
|
12
|
-
// }
|
|
13
|
-
// })
|
|
14
|
-
// );
|
|
2
|
+
// Loaded lazily so the bundled libsodium only ships when a worker is needed.
|
|
3
|
+
const createSodiumWorker = async () => {
|
|
4
|
+
const { workerSodiumScript } = await import('./generated/sodium.js');
|
|
5
|
+
return new Worker(URL.createObjectURL(new Blob([workerSodiumScript], { type: 'text/javascript' })));
|
|
6
|
+
};
|
|
15
7
|
export const encrypt = process.env.NODE_ENV !== 'test'
|
|
16
8
|
? async (key, dataToEncrypt, progress, signal) => {
|
|
9
|
+
const worker = await createSodiumWorker();
|
|
17
10
|
return await new Promise((resolve, reject) => {
|
|
18
11
|
void progress?.({
|
|
19
12
|
current: 0,
|
|
20
13
|
percent: 0,
|
|
21
14
|
total: dataToEncrypt.byteLength,
|
|
22
15
|
});
|
|
23
|
-
const worker = new Worker(URL.createObjectURL(new Blob([workerSodiumScript], { type: 'text/javascript' })));
|
|
24
16
|
worker.addEventListener('error', reject);
|
|
25
17
|
worker.addEventListener('messageerror', reject);
|
|
26
18
|
worker.addEventListener('message', ({ data }) => {
|
|
@@ -46,6 +38,11 @@ export const encrypt = process.env.NODE_ENV !== 'test'
|
|
|
46
38
|
void progress?.(data.data);
|
|
47
39
|
break;
|
|
48
40
|
}
|
|
41
|
+
case 'error': {
|
|
42
|
+
worker.terminate();
|
|
43
|
+
reject(new Error(data.data));
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
49
46
|
case 'encrypt-result': {
|
|
50
47
|
worker.terminate();
|
|
51
48
|
resolve(data.data);
|
|
@@ -59,13 +56,13 @@ export const encrypt = process.env.NODE_ENV !== 'test'
|
|
|
59
56
|
};
|
|
60
57
|
export const decrypt = process.env.NODE_ENV !== 'test'
|
|
61
58
|
? async (key, dataToDecrypt, progress, signal) => {
|
|
59
|
+
const worker = await createSodiumWorker();
|
|
62
60
|
return await new Promise((resolve, reject) => {
|
|
63
61
|
void progress?.({
|
|
64
62
|
current: 0,
|
|
65
63
|
percent: 0,
|
|
66
64
|
total: dataToDecrypt.byteLength,
|
|
67
65
|
});
|
|
68
|
-
const worker = new Worker(URL.createObjectURL(new Blob([workerSodiumScript], { type: 'text/javascript' })));
|
|
69
66
|
worker.addEventListener('error', reject);
|
|
70
67
|
worker.addEventListener('messageerror', reject);
|
|
71
68
|
worker.addEventListener('message', ({ data }) => {
|
|
@@ -91,6 +88,11 @@ export const decrypt = process.env.NODE_ENV !== 'test'
|
|
|
91
88
|
void progress?.(data.data);
|
|
92
89
|
break;
|
|
93
90
|
}
|
|
91
|
+
case 'error': {
|
|
92
|
+
worker.terminate();
|
|
93
|
+
reject(new Error(data.data));
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
94
96
|
case 'decrypt-result': {
|
|
95
97
|
worker.terminate();
|
|
96
98
|
resolve(data.data);
|
|
@@ -3,7 +3,7 @@ import { type ProgressCallback } from '.';
|
|
|
3
3
|
import { type Progress } from 'ky';
|
|
4
4
|
export declare const downloadDataLinkSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
5
5
|
name: z.ZodString;
|
|
6
|
-
md5: z.ZodString
|
|
6
|
+
md5: z.ZodNullable<z.ZodString>;
|
|
7
7
|
md5Encrypted: z.ZodNullable<z.ZodString>;
|
|
8
8
|
size: z.ZodCoercedBigInt<unknown>;
|
|
9
9
|
parts: z.ZodArray<z.ZodObject<{
|
|
@@ -15,7 +15,7 @@ export declare const downloadDataLinkSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
15
15
|
isEncrypted: z.ZodBoolean;
|
|
16
16
|
}, z.core.$strip>, z.ZodObject<{
|
|
17
17
|
name: z.ZodString;
|
|
18
|
-
md5: z.ZodString
|
|
18
|
+
md5: z.ZodNullable<z.ZodString>;
|
|
19
19
|
md5Encrypted: z.ZodNullable<z.ZodString>;
|
|
20
20
|
size: z.ZodCoercedBigInt<unknown>;
|
|
21
21
|
bytes: z.ZodString;
|
|
@@ -34,7 +34,7 @@ export type DownloadDataFromLinkOptions = {
|
|
|
34
34
|
};
|
|
35
35
|
export declare function fetchDataLinkMetadata(dataLinkSlug: string, dataUrl?: string): Promise<{
|
|
36
36
|
name: string;
|
|
37
|
-
md5: string;
|
|
37
|
+
md5: string | null;
|
|
38
38
|
md5Encrypted: string | null;
|
|
39
39
|
size: bigint;
|
|
40
40
|
parts: {
|
|
@@ -46,7 +46,7 @@ export declare function fetchDataLinkMetadata(dataLinkSlug: string, dataUrl?: st
|
|
|
46
46
|
isEncrypted: boolean;
|
|
47
47
|
} | {
|
|
48
48
|
name: string;
|
|
49
|
-
md5: string;
|
|
49
|
+
md5: string | null;
|
|
50
50
|
md5Encrypted: string | null;
|
|
51
51
|
size: bigint;
|
|
52
52
|
bytes: string;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SecrecyClient } from './index.js';
|
|
2
2
|
import { type SecrecyUserApp } from './types/index.js';
|
|
3
3
|
import type { SecrecyUrls } from '../base-client.js';
|
|
4
|
-
export declare function assertBrowser(fn: string): void;
|
|
5
4
|
export declare function parseInfos(): SecrecyUserApp | null;
|
|
6
5
|
export interface HashInfos {
|
|
7
6
|
appId?: string;
|
|
@@ -7,7 +7,8 @@ export type LocalData = {
|
|
|
7
7
|
storageType: DataStorageType;
|
|
8
8
|
size: bigint;
|
|
9
9
|
sizeEncrypted: bigint | null;
|
|
10
|
-
md5:
|
|
10
|
+
/** md5 of the content: only for unencrypted and legacy encrypted data. */
|
|
11
|
+
md5: string | null;
|
|
11
12
|
data: Uint8Array<ArrayBuffer>;
|
|
12
13
|
mime?: string;
|
|
13
14
|
ext?: string;
|