@storacha/encrypt-upload-client 1.1.65 → 1.1.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/dist/config/constants.d.ts +1 -1
  3. package/dist/config/constants.d.ts.map +1 -1
  4. package/dist/config/constants.js +2 -2
  5. package/dist/config/env.d.ts +0 -1
  6. package/dist/config/env.d.ts.map +1 -1
  7. package/dist/config/env.js +0 -7
  8. package/dist/core/client.js +1 -1
  9. package/dist/crypto/adapters/lit-crypto-adapter.d.ts +35 -4
  10. package/dist/crypto/adapters/lit-crypto-adapter.d.ts.map +1 -1
  11. package/dist/crypto/adapters/lit-crypto-adapter.js +38 -41
  12. package/dist/crypto/factories.node.d.ts +4 -10
  13. package/dist/crypto/factories.node.d.ts.map +1 -1
  14. package/dist/crypto/factories.node.js +6 -16
  15. package/dist/protocols/lit.d.ts +13 -18
  16. package/dist/protocols/lit.d.ts.map +1 -1
  17. package/dist/protocols/lit.js +67 -88
  18. package/dist/types.d.ts +24 -15
  19. package/dist/types.d.ts.map +1 -1
  20. package/dist/utils/file-metadata.d.ts.map +1 -1
  21. package/dist/utils/file-metadata.js +39 -14
  22. package/package.json +12 -11
  23. package/dist/test/cid-verification.spec.d.ts +0 -2
  24. package/dist/test/cid-verification.spec.d.ts.map +0 -1
  25. package/dist/test/cid-verification.spec.js +0 -314
  26. package/dist/test/crypto-compatibility.spec.d.ts +0 -2
  27. package/dist/test/crypto-compatibility.spec.d.ts.map +0 -1
  28. package/dist/test/crypto-compatibility.spec.js +0 -124
  29. package/dist/test/crypto-counter-security.spec.d.ts +0 -2
  30. package/dist/test/crypto-counter-security.spec.d.ts.map +0 -1
  31. package/dist/test/crypto-counter-security.spec.js +0 -147
  32. package/dist/test/crypto-streaming.spec.d.ts +0 -2
  33. package/dist/test/crypto-streaming.spec.d.ts.map +0 -1
  34. package/dist/test/crypto-streaming.spec.js +0 -129
  35. package/dist/test/crypto-streaming.spec.js.map +0 -1
  36. package/dist/test/encrypted-metadata.spec.d.ts +0 -2
  37. package/dist/test/encrypted-metadata.spec.d.ts.map +0 -1
  38. package/dist/test/encrypted-metadata.spec.js +0 -68
  39. package/dist/test/encrypted-metadata.spec.js.map +0 -1
  40. package/dist/test/factories.spec.d.ts +0 -2
  41. package/dist/test/factories.spec.d.ts.map +0 -1
  42. package/dist/test/factories.spec.js +0 -142
  43. package/dist/test/factories.spec.js.map +0 -1
  44. package/dist/test/file-metadata.spec.d.ts +0 -2
  45. package/dist/test/file-metadata.spec.d.ts.map +0 -1
  46. package/dist/test/file-metadata.spec.js +0 -433
  47. package/dist/test/file-metadata.spec.js.map +0 -1
  48. package/dist/test/helpers/test-file-utils.d.ts +0 -60
  49. package/dist/test/helpers/test-file-utils.d.ts.map +0 -1
  50. package/dist/test/helpers/test-file-utils.js +0 -139
  51. package/dist/test/setup.d.ts +0 -2
  52. package/dist/test/setup.d.ts.map +0 -1
  53. package/dist/test/setup.js +0 -12
@@ -1,60 +0,0 @@
1
- /**
2
- * Create test data with specific patterns for easy verification
3
- *
4
- * @param {number} sizeMB - Size of the test file in megabytes
5
- * @returns {Blob} A Blob containing test data with predictable patterns
6
- */
7
- export function createTestFile(sizeMB: number): Blob;
8
- /**
9
- * Convert ReadableStream to Uint8Array
10
- *
11
- * @param {ReadableStream} stream - The stream to convert
12
- * @returns {Promise<Uint8Array>} The stream content as a Uint8Array
13
- */
14
- export function streamToUint8Array(stream: ReadableStream): Promise<Uint8Array>;
15
- /**
16
- * @param {Uint8Array} arr
17
- * @returns {string}
18
- */
19
- export function uint8ArrayToString(arr: Uint8Array): string;
20
- /**
21
- * @param {string} str
22
- * @returns {Uint8Array}
23
- */
24
- export function stringToUint8Array(str: string): Uint8Array;
25
- /**
26
- * Check if an error is a memory-related error (out of heap space, etc.)
27
- *
28
- * @param {unknown} error - The error to check
29
- * @returns {boolean} True if the error appears to be memory-related
30
- */
31
- export function isMemoryError(error: unknown): boolean;
32
- /**
33
- * Test an encryption operation and expect it might fail with memory errors
34
- *
35
- * @param {Function} encryptOperation - Function that performs encryption
36
- * @param {string} operationName - Name of the operation for logging
37
- * @returns {Promise<{success: boolean, error?: Error}>} Result of the operation
38
- */
39
- export function testEncryptionWithMemoryHandling(encryptOperation: Function, operationName: string): Promise<{
40
- success: boolean;
41
- error?: Error;
42
- }>;
43
- /**
44
- * Create a CAR file with KMS metadata content
45
- *
46
- * @param {any} content - The KMS metadata content
47
- * @returns {Promise<{car: Uint8Array, actualRootCID: import('multiformats').UnknownLink}>}
48
- */
49
- export function createTestCar(content: any): Promise<{
50
- car: Uint8Array;
51
- actualRootCID: import("multiformats").UnknownLink;
52
- }>;
53
- /**
54
- * Create a mock BlobLike object for testing
55
- *
56
- * @param {Uint8Array} data
57
- * @returns {import('../../src/types.js').BlobLike}
58
- */
59
- export function createMockBlob(data: Uint8Array): import("../../src/types.js").BlobLike;
60
- //# sourceMappingURL=test-file-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-file-utils.d.ts","sourceRoot":"","sources":["../../../test/helpers/test-file-utils.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,uCAHW,MAAM,GACJ,IAAI,CAuBhB;AAED;;;;;GAKG;AACH,2CAHW,cAAc,GACZ,OAAO,CAAC,UAAU,CAAC,CAmB/B;AAED;;;GAGG;AACH,wCAHW,UAAU,GACR,MAAM,CAIlB;AAED;;;GAGG;AACH,wCAHW,MAAM,GACJ,UAAU,CAItB;AAED;;;;;GAKG;AACH,qCAHW,OAAO,GACL,OAAO,CAUnB;AAED;;;;;;GAMG;AACH,4FAHW,MAAM,GACJ,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAC,CAAC,CAqBtD;AAED;;;;;GAKG;AACH,uCAHW,GAAG,GACD,OAAO,CAAC;IAAC,GAAG,EAAE,UAAU,CAAC;IAAC,aAAa,EAAE,OAAO,cAAc,EAAE,WAAW,CAAA;CAAC,CAAC,CAYzF;AAED;;;;;GAKG;AACH,qCAHW,UAAU,GACR,OAAO,oBAAoB,EAAE,QAAQ,CAajD"}
@@ -1,139 +0,0 @@
1
- import { KMSMetadata } from '../../src/core/metadata/encrypted-metadata.js';
2
- /**
3
- * Create test data with specific patterns for easy verification
4
- *
5
- * @param {number} sizeMB - Size of the test file in megabytes
6
- * @returns {Blob} A Blob containing test data with predictable patterns
7
- */
8
- export function createTestFile(sizeMB) {
9
- const chunkSize = 64 * 1024; // 64KB chunks
10
- const totalSize = sizeMB * 1024 * 1024;
11
- const numChunks = Math.ceil(totalSize / chunkSize);
12
- const chunks = [];
13
- for (let i = 0; i < numChunks; i++) {
14
- const isLastChunk = i === numChunks - 1;
15
- const currentChunkSize = isLastChunk
16
- ? totalSize % chunkSize || chunkSize
17
- : chunkSize;
18
- const chunk = new Uint8Array(currentChunkSize);
19
- // Create pattern: chunk index in first byte, then sequence
20
- chunk[0] = i % 256;
21
- for (let j = 1; j < currentChunkSize; j++) {
22
- chunk[j] = (i + j) % 256;
23
- }
24
- chunks.push(chunk);
25
- }
26
- return new Blob(chunks, { type: 'application/octet-stream' });
27
- }
28
- /**
29
- * Convert ReadableStream to Uint8Array
30
- *
31
- * @param {ReadableStream} stream - The stream to convert
32
- * @returns {Promise<Uint8Array>} The stream content as a Uint8Array
33
- */
34
- export async function streamToUint8Array(stream) {
35
- const reader = stream.getReader();
36
- const chunks = [];
37
- // eslint-disable-next-line no-constant-condition
38
- while (true) {
39
- const { done, value } = await reader.read();
40
- if (done)
41
- break;
42
- chunks.push(value);
43
- }
44
- const totalLength = chunks.reduce((acc, val) => acc + val.length, 0);
45
- const result = new Uint8Array(totalLength);
46
- let offset = 0;
47
- for (const chunk of chunks) {
48
- result.set(chunk, offset);
49
- offset += chunk.length;
50
- }
51
- return result;
52
- }
53
- /**
54
- * @param {Uint8Array} arr
55
- * @returns {string}
56
- */
57
- export function uint8ArrayToString(arr) {
58
- return new TextDecoder().decode(arr);
59
- }
60
- /**
61
- * @param {string} str
62
- * @returns {Uint8Array}
63
- */
64
- export function stringToUint8Array(str) {
65
- return new TextEncoder().encode(str);
66
- }
67
- /**
68
- * Check if an error is a memory-related error (out of heap space, etc.)
69
- *
70
- * @param {unknown} error - The error to check
71
- * @returns {boolean} True if the error appears to be memory-related
72
- */
73
- export function isMemoryError(error) {
74
- const errorMessage = error instanceof Error ? error.message : String(error);
75
- return (errorMessage.includes('heap') ||
76
- errorMessage.includes('memory') ||
77
- errorMessage.includes('allocation failed') ||
78
- errorMessage.includes('out of memory'));
79
- }
80
- /**
81
- * Test an encryption operation and expect it might fail with memory errors
82
- *
83
- * @param {Function} encryptOperation - Function that performs encryption
84
- * @param {string} operationName - Name of the operation for logging
85
- * @returns {Promise<{success: boolean, error?: Error}>} Result of the operation
86
- */
87
- export async function testEncryptionWithMemoryHandling(encryptOperation, operationName) {
88
- try {
89
- await encryptOperation();
90
- return { success: true };
91
- }
92
- catch (error) {
93
- if (isMemoryError(error)) {
94
- console.log(`✓ ${operationName} failed as expected: Out of memory`);
95
- return {
96
- success: false,
97
- error: error instanceof Error ? error : new Error(String(error)),
98
- };
99
- }
100
- else {
101
- // Re-throw if it's not a memory error
102
- throw error;
103
- }
104
- }
105
- }
106
- /**
107
- * Create a CAR file with KMS metadata content
108
- *
109
- * @param {any} content - The KMS metadata content
110
- * @returns {Promise<{car: Uint8Array, actualRootCID: import('multiformats').UnknownLink}>}
111
- */
112
- export async function createTestCar(content) {
113
- // Create KMS metadata and archive it to get the CAR
114
- const kmsMetadata = KMSMetadata.create(content);
115
- const { cid, bytes } = await kmsMetadata.archiveBlock();
116
- // Use UCANTO's CAR encoding to create a proper CAR file
117
- const { CAR } = await import('@ucanto/core');
118
- const car = CAR.encode({ roots: [{ cid, bytes }] });
119
- return { car, actualRootCID: cid };
120
- }
121
- /**
122
- * Create a mock BlobLike object for testing
123
- *
124
- * @param {Uint8Array} data
125
- * @returns {import('../../src/types.js').BlobLike}
126
- */
127
- export function createMockBlob(data) {
128
- return {
129
- stream() {
130
- return new ReadableStream({
131
- start(controller) {
132
- controller.enqueue(data);
133
- controller.close();
134
- },
135
- });
136
- },
137
- };
138
- }
139
- //# sourceMappingURL=test-file-utils.js.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=setup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../test/setup.js"],"names":[],"mappings":""}
@@ -1,12 +0,0 @@
1
- // Centralized polyfill for globalThis.crypto for Node.js <19
2
- if (typeof globalThis.crypto === 'undefined') {
3
- try {
4
- // @ts-expect-error
5
- globalThis.crypto = (await import('crypto')).webcrypto;
6
- }
7
- catch (e) {
8
- throw new Error('globalThis.crypto is not available.');
9
- }
10
- }
11
- export {};
12
- //# sourceMappingURL=setup.js.map