@storacha/encrypt-upload-client 1.1.56 → 1.1.58

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 (72) hide show
  1. package/dist/config/constants.d.ts +3 -3
  2. package/dist/config/constants.js +4 -3
  3. package/dist/config/env.d.ts +9 -6
  4. package/dist/config/service.d.ts +13 -13
  5. package/dist/core/client.d.ts +54 -41
  6. package/dist/core/client.js +68 -56
  7. package/dist/core/errors.d.ts +6 -6
  8. package/dist/core/metadata/encrypted-metadata.d.ts +13 -8
  9. package/dist/core/metadata/kms-metadata.d.ts +68 -36
  10. package/dist/core/metadata/lit-metadata.d.ts +63 -28
  11. package/dist/crypto/adapters/kms-crypto-adapter.d.ts +172 -137
  12. package/dist/crypto/adapters/lit-crypto-adapter.d.ts +107 -86
  13. package/dist/crypto/factories.browser.d.ts +9 -5
  14. package/dist/crypto/factories.browser.js +15 -7
  15. package/dist/crypto/factories.node.d.ts +13 -6
  16. package/dist/crypto/factories.node.js +19 -13
  17. package/dist/crypto/index.d.ts +5 -5
  18. package/dist/crypto/index.js +5 -5
  19. package/dist/crypto/symmetric/generic-aes-ctr-streaming-crypto.d.ts +58 -54
  20. package/dist/crypto/symmetric/generic-aes-ctr-streaming-crypto.js +174 -146
  21. package/dist/crypto/symmetric/node-aes-cbc-crypto.d.ts +36 -32
  22. package/dist/crypto/symmetric/node-aes-cbc-crypto.js +101 -95
  23. package/dist/examples/decrypt-test.d.ts +2 -2
  24. package/dist/examples/decrypt-test.js +78 -69
  25. package/dist/examples/encrypt-test.d.ts +5 -3
  26. package/dist/examples/encrypt-test.js +58 -55
  27. package/dist/handlers/decrypt-handler.d.ts +19 -5
  28. package/dist/handlers/encrypt-handler.d.ts +9 -3
  29. package/dist/handlers/encrypt-handler.js +93 -57
  30. package/dist/index.d.ts +2 -2
  31. package/dist/index.js +2 -2
  32. package/dist/protocols/lit.d.ts +33 -9
  33. package/dist/protocols/lit.js +134 -98
  34. package/dist/test/cid-verification.spec.d.ts +2 -2
  35. package/dist/test/cid-verification.spec.js +341 -313
  36. package/dist/test/crypto-compatibility.spec.d.ts +2 -2
  37. package/dist/test/crypto-compatibility.spec.js +184 -120
  38. package/dist/test/crypto-counter-security.spec.d.ts +2 -2
  39. package/dist/test/crypto-counter-security.spec.js +177 -138
  40. package/dist/test/crypto-streaming.spec.d.ts +2 -2
  41. package/dist/test/crypto-streaming.spec.js +208 -126
  42. package/dist/test/encrypted-metadata.spec.d.ts +2 -2
  43. package/dist/test/encrypted-metadata.spec.js +89 -62
  44. package/dist/test/factories.spec.d.ts +2 -2
  45. package/dist/test/factories.spec.js +275 -139
  46. package/dist/test/file-metadata.spec.d.ts +2 -2
  47. package/dist/test/file-metadata.spec.js +472 -416
  48. package/dist/test/fixtures/test-fixtures.d.ts +25 -20
  49. package/dist/test/fixtures/test-fixtures.js +61 -53
  50. package/dist/test/helpers/test-file-utils.d.ts +19 -14
  51. package/dist/test/helpers/test-file-utils.js +78 -76
  52. package/dist/test/https-enforcement.spec.d.ts +2 -2
  53. package/dist/test/https-enforcement.spec.js +278 -124
  54. package/dist/test/kms-crypto-adapter.spec.d.ts +2 -2
  55. package/dist/test/kms-crypto-adapter.spec.js +473 -304
  56. package/dist/test/lit-crypto-adapter.spec.d.ts +2 -2
  57. package/dist/test/lit-crypto-adapter.spec.js +206 -118
  58. package/dist/test/memory-efficiency.spec.d.ts +2 -2
  59. package/dist/test/memory-efficiency.spec.js +100 -87
  60. package/dist/test/mocks/key-manager.d.ts +71 -38
  61. package/dist/test/mocks/key-manager.js +129 -113
  62. package/dist/test/node-crypto-adapter.spec.d.ts +2 -2
  63. package/dist/test/node-crypto-adapter.spec.js +155 -102
  64. package/dist/test/node-generic-crypto-adapter.spec.d.ts +2 -2
  65. package/dist/test/node-generic-crypto-adapter.spec.js +134 -94
  66. package/dist/test/setup.d.ts +2 -2
  67. package/dist/test/setup.js +8 -9
  68. package/dist/tsconfig.spec.tsbuildinfo +1 -1
  69. package/dist/types.d.ts +219 -181
  70. package/dist/utils/file-metadata.d.ts +19 -13
  71. package/dist/utils.d.ts +14 -5
  72. package/package.json +4 -4
@@ -1,2 +1,2 @@
1
- export {};
2
- //# sourceMappingURL=crypto-compatibility.spec.d.ts.map
1
+ export {}
2
+ //# sourceMappingURL=crypto-compatibility.spec.d.ts.map
@@ -1,124 +1,188 @@
1
- import './setup.js';
2
- import { test, describe } from 'node:test';
3
- import assert from 'node:assert';
4
- import { GenericAesCtrStreamingCrypto } from '../src/crypto/symmetric/generic-aes-ctr-streaming-crypto.js';
5
- import { NodeAesCbcCrypto } from '../src/crypto/symmetric/node-aes-cbc-crypto.js';
6
- import { createTestFile, streamToUint8Array, } from './helpers/test-file-utils.js';
1
+ import './setup.js'
2
+ import { test, describe } from 'node:test'
3
+ import assert from 'node:assert'
4
+ import { GenericAesCtrStreamingCrypto } from '../src/crypto/symmetric/generic-aes-ctr-streaming-crypto.js'
5
+ import { NodeAesCbcCrypto } from '../src/crypto/symmetric/node-aes-cbc-crypto.js'
6
+ import {
7
+ createTestFile,
8
+ streamToUint8Array,
9
+ } from './helpers/test-file-utils.js'
7
10
  /**
8
11
  * These tests verify cross-environment compatibility and consistency of crypto implementations.
9
12
  */
10
13
  await describe('Cross-Environment Crypto Compatibility', async () => {
11
- await test('should work consistently across multiple instances', async () => {
12
- const crypto1 = new GenericAesCtrStreamingCrypto();
13
- const crypto2 = new GenericAesCtrStreamingCrypto();
14
- const testFile = createTestFile(0.01); // 10KB test (ultra-small for memory safety)
15
- console.log('Testing consistency across instances...');
16
- // Use SAME key and IV for both instances
17
- const sharedKey = globalThis.crypto.getRandomValues(new Uint8Array(32));
18
- const sharedIV = globalThis.crypto.getRandomValues(new Uint8Array(16));
19
- // Override generateKey to return our shared key
20
- crypto1.generateKey = async () => sharedKey;
21
- crypto2.generateKey = async () => sharedKey;
22
- // Override IV generation to return our shared IV
23
- const originalRandomValues = globalThis.crypto.getRandomValues;
24
- let ivCallCount = 0;
25
- // @ts-ignore - Overriding for test purposes
26
- globalThis.crypto.getRandomValues = (array) => {
27
- // @ts-ignore - TypeScript is confused about the array type
28
- if (array && array.length === 16 && ivCallCount < 2) {
29
- ivCallCount++;
30
- // @ts-ignore - TypeScript is confused about the array type
31
- array.set(sharedIV);
32
- return array;
33
- }
34
- return originalRandomValues.call(globalThis.crypto, array);
35
- };
36
- try {
37
- // Get encryption results from both instances
38
- const result1 = await crypto1.encryptStream(testFile);
39
- const result2 = await crypto2.encryptStream(testFile);
40
- // Verify keys and IVs are identical
41
- assert.deepStrictEqual(result1.key, result2.key, 'Keys should be identical');
42
- assert.deepStrictEqual(result1.iv, result2.iv, 'IVs should be identical');
43
- // Convert streams to bytes for comparison
44
- const encrypted1 = await streamToUint8Array(result1.encryptedStream);
45
- const encrypted2 = await streamToUint8Array(result2.encryptedStream);
46
- // Verify encrypted outputs are byte-for-byte identical
47
- assert.strictEqual(encrypted1.length, encrypted2.length, 'Encrypted lengths should match');
48
- assert.deepStrictEqual(encrypted1, encrypted2, 'Encrypted data should be identical');
49
- console.log('Multiple instances produce identical results');
50
- }
51
- finally {
52
- // Restore original methods
53
- globalThis.crypto.getRandomValues = originalRandomValues;
54
- }
55
- });
56
- await test('should support cross-instance decrypt', async () => {
57
- const crypto1 = new GenericAesCtrStreamingCrypto();
58
- const crypto2 = new GenericAesCtrStreamingCrypto();
59
- const testFile = createTestFile(0.01); // 10KB test (ultra-small for memory safety)
60
- console.log('Testing cross-instance decryption...');
61
- // Encrypt with first instance
62
- const { key, iv, encryptedStream } = await crypto1.encryptStream(testFile);
63
- const encryptedBytes = await streamToUint8Array(encryptedStream);
64
- // Decrypt with second instance
65
- const encryptedForDecrypt = new ReadableStream({
66
- start(controller) {
67
- controller.enqueue(encryptedBytes);
68
- controller.close();
69
- },
70
- });
71
- const decryptedStream = await crypto2.decryptStream(encryptedForDecrypt, key, iv);
72
- const decryptedBytes = await streamToUint8Array(decryptedStream);
73
- // Verify decrypted data matches original
74
- const originalBytes = new Uint8Array(await testFile.arrayBuffer());
75
- assert.deepStrictEqual(decryptedBytes, originalBytes, 'Cross-instance decryption should work');
76
- console.log('Cross-instance decryption verified');
77
- });
78
- await test('should handle edge cases consistently', async () => {
79
- const crypto = new GenericAesCtrStreamingCrypto();
80
- console.log('Testing edge case consistency...');
81
- // Test empty file
82
- const emptyFile = new Blob([]);
83
- const emptyResult = await crypto.encryptStream(emptyFile);
84
- const emptyEncrypted = await streamToUint8Array(emptyResult.encryptedStream);
85
- assert.strictEqual(emptyEncrypted.length, 0, 'Empty file should encrypt to 0 bytes');
86
- // Test single byte file
87
- const singleByteFile = new Blob([new Uint8Array([42])]);
88
- const singleResult = await crypto.encryptStream(singleByteFile);
89
- const singleEncrypted = await streamToUint8Array(singleResult.encryptedStream);
90
- assert.strictEqual(singleEncrypted.length, 1, 'Single byte file should encrypt to 1 byte');
91
- // Test round-trip of single byte
92
- const singleDecryptStream = new ReadableStream({
93
- start(controller) {
94
- controller.enqueue(singleEncrypted);
95
- controller.close();
96
- },
97
- });
98
- const singleDecrypted = await crypto.decryptStream(singleDecryptStream, singleResult.key, singleResult.iv);
99
- const singleDecryptedBytes = await streamToUint8Array(singleDecrypted);
100
- assert.deepStrictEqual(singleDecryptedBytes, new Uint8Array([42]), 'Single byte round-trip should work');
101
- console.log('Edge cases handled consistently');
102
- });
103
- await test('should demonstrate algorithm differences with NodeAesCbcCrypto', async () => {
104
- const genericCrypto = new GenericAesCtrStreamingCrypto();
105
- const nodeCrypto = new NodeAesCbcCrypto();
106
- const testFile = createTestFile(0.01); // 10KB test (ultra-small for memory safety)
107
- console.log('Testing algorithm differences...');
108
- // Encrypt with both implementations
109
- const genericResult = await genericCrypto.encryptStream(testFile);
110
- const nodeResult = await nodeCrypto.encryptStream(testFile);
111
- // Convert streams to bytes
112
- const genericEncrypted = await streamToUint8Array(genericResult.encryptedStream);
113
- const nodeEncrypted = await streamToUint8Array(nodeResult.encryptedStream);
114
- // Verify they produce different results (different algorithms)
115
- assert.notDeepEqual(genericEncrypted, nodeEncrypted, 'AES-CTR and AES-CBC should produce different results');
116
- // Verify they have different key/IV formats
117
- assert.strictEqual(genericResult.key.length, 32, 'Generic crypto should use 32-byte keys');
118
- assert.strictEqual(genericResult.iv.length, 16, 'Generic crypto should use 16-byte IVs');
119
- assert.strictEqual(nodeResult.key.length, 32, 'Node crypto should use 32-byte keys');
120
- assert.strictEqual(nodeResult.iv.length, 16, 'Node crypto should use 16-byte IVs');
121
- console.log('Algorithm differences confirmed - use consistent crypto for encrypt/decrypt');
122
- });
123
- });
124
- //# sourceMappingURL=crypto-compatibility.spec.js.map
14
+ await test('should work consistently across multiple instances', async () => {
15
+ const crypto1 = new GenericAesCtrStreamingCrypto()
16
+ const crypto2 = new GenericAesCtrStreamingCrypto()
17
+ const testFile = createTestFile(0.01) // 10KB test (ultra-small for memory safety)
18
+ console.log('Testing consistency across instances...')
19
+ // Use SAME key and IV for both instances
20
+ const sharedKey = globalThis.crypto.getRandomValues(new Uint8Array(32))
21
+ const sharedIV = globalThis.crypto.getRandomValues(new Uint8Array(16))
22
+ // Override generateKey to return our shared key
23
+ crypto1.generateKey = async () => sharedKey
24
+ crypto2.generateKey = async () => sharedKey
25
+ // Override IV generation to return our shared IV
26
+ const originalRandomValues = globalThis.crypto.getRandomValues
27
+ let ivCallCount = 0
28
+ // @ts-ignore - Overriding for test purposes
29
+ globalThis.crypto.getRandomValues = (array) => {
30
+ // @ts-ignore - TypeScript is confused about the array type
31
+ if (array && array.length === 16 && ivCallCount < 2) {
32
+ ivCallCount++
33
+ // @ts-ignore - TypeScript is confused about the array type
34
+ array.set(sharedIV)
35
+ return array
36
+ }
37
+ return originalRandomValues.call(globalThis.crypto, array)
38
+ }
39
+ try {
40
+ // Get encryption results from both instances
41
+ const result1 = await crypto1.encryptStream(testFile)
42
+ const result2 = await crypto2.encryptStream(testFile)
43
+ // Verify keys and IVs are identical
44
+ assert.deepStrictEqual(
45
+ result1.key,
46
+ result2.key,
47
+ 'Keys should be identical'
48
+ )
49
+ assert.deepStrictEqual(result1.iv, result2.iv, 'IVs should be identical')
50
+ // Convert streams to bytes for comparison
51
+ const encrypted1 = await streamToUint8Array(result1.encryptedStream)
52
+ const encrypted2 = await streamToUint8Array(result2.encryptedStream)
53
+ // Verify encrypted outputs are byte-for-byte identical
54
+ assert.strictEqual(
55
+ encrypted1.length,
56
+ encrypted2.length,
57
+ 'Encrypted lengths should match'
58
+ )
59
+ assert.deepStrictEqual(
60
+ encrypted1,
61
+ encrypted2,
62
+ 'Encrypted data should be identical'
63
+ )
64
+ console.log('Multiple instances produce identical results')
65
+ } finally {
66
+ // Restore original methods
67
+ globalThis.crypto.getRandomValues = originalRandomValues
68
+ }
69
+ })
70
+ await test('should support cross-instance decrypt', async () => {
71
+ const crypto1 = new GenericAesCtrStreamingCrypto()
72
+ const crypto2 = new GenericAesCtrStreamingCrypto()
73
+ const testFile = createTestFile(0.01) // 10KB test (ultra-small for memory safety)
74
+ console.log('Testing cross-instance decryption...')
75
+ // Encrypt with first instance
76
+ const { key, iv, encryptedStream } = await crypto1.encryptStream(testFile)
77
+ const encryptedBytes = await streamToUint8Array(encryptedStream)
78
+ // Decrypt with second instance
79
+ const encryptedForDecrypt = new ReadableStream({
80
+ start(controller) {
81
+ controller.enqueue(encryptedBytes)
82
+ controller.close()
83
+ },
84
+ })
85
+ const decryptedStream = await crypto2.decryptStream(
86
+ encryptedForDecrypt,
87
+ key,
88
+ iv
89
+ )
90
+ const decryptedBytes = await streamToUint8Array(decryptedStream)
91
+ // Verify decrypted data matches original
92
+ const originalBytes = new Uint8Array(await testFile.arrayBuffer())
93
+ assert.deepStrictEqual(
94
+ decryptedBytes,
95
+ originalBytes,
96
+ 'Cross-instance decryption should work'
97
+ )
98
+ console.log('Cross-instance decryption verified')
99
+ })
100
+ await test('should handle edge cases consistently', async () => {
101
+ const crypto = new GenericAesCtrStreamingCrypto()
102
+ console.log('Testing edge case consistency...')
103
+ // Test empty file
104
+ const emptyFile = new Blob([])
105
+ const emptyResult = await crypto.encryptStream(emptyFile)
106
+ const emptyEncrypted = await streamToUint8Array(emptyResult.encryptedStream)
107
+ assert.strictEqual(
108
+ emptyEncrypted.length,
109
+ 0,
110
+ 'Empty file should encrypt to 0 bytes'
111
+ )
112
+ // Test single byte file
113
+ const singleByteFile = new Blob([new Uint8Array([42])])
114
+ const singleResult = await crypto.encryptStream(singleByteFile)
115
+ const singleEncrypted = await streamToUint8Array(
116
+ singleResult.encryptedStream
117
+ )
118
+ assert.strictEqual(
119
+ singleEncrypted.length,
120
+ 1,
121
+ 'Single byte file should encrypt to 1 byte'
122
+ )
123
+ // Test round-trip of single byte
124
+ const singleDecryptStream = new ReadableStream({
125
+ start(controller) {
126
+ controller.enqueue(singleEncrypted)
127
+ controller.close()
128
+ },
129
+ })
130
+ const singleDecrypted = await crypto.decryptStream(
131
+ singleDecryptStream,
132
+ singleResult.key,
133
+ singleResult.iv
134
+ )
135
+ const singleDecryptedBytes = await streamToUint8Array(singleDecrypted)
136
+ assert.deepStrictEqual(
137
+ singleDecryptedBytes,
138
+ new Uint8Array([42]),
139
+ 'Single byte round-trip should work'
140
+ )
141
+ console.log('Edge cases handled consistently')
142
+ })
143
+ await test('should demonstrate algorithm differences with NodeAesCbcCrypto', async () => {
144
+ const genericCrypto = new GenericAesCtrStreamingCrypto()
145
+ const nodeCrypto = new NodeAesCbcCrypto()
146
+ const testFile = createTestFile(0.01) // 10KB test (ultra-small for memory safety)
147
+ console.log('Testing algorithm differences...')
148
+ // Encrypt with both implementations
149
+ const genericResult = await genericCrypto.encryptStream(testFile)
150
+ const nodeResult = await nodeCrypto.encryptStream(testFile)
151
+ // Convert streams to bytes
152
+ const genericEncrypted = await streamToUint8Array(
153
+ genericResult.encryptedStream
154
+ )
155
+ const nodeEncrypted = await streamToUint8Array(nodeResult.encryptedStream)
156
+ // Verify they produce different results (different algorithms)
157
+ assert.notDeepEqual(
158
+ genericEncrypted,
159
+ nodeEncrypted,
160
+ 'AES-CTR and AES-CBC should produce different results'
161
+ )
162
+ // Verify they have different key/IV formats
163
+ assert.strictEqual(
164
+ genericResult.key.length,
165
+ 32,
166
+ 'Generic crypto should use 32-byte keys'
167
+ )
168
+ assert.strictEqual(
169
+ genericResult.iv.length,
170
+ 16,
171
+ 'Generic crypto should use 16-byte IVs'
172
+ )
173
+ assert.strictEqual(
174
+ nodeResult.key.length,
175
+ 32,
176
+ 'Node crypto should use 32-byte keys'
177
+ )
178
+ assert.strictEqual(
179
+ nodeResult.iv.length,
180
+ 16,
181
+ 'Node crypto should use 16-byte IVs'
182
+ )
183
+ console.log(
184
+ 'Algorithm differences confirmed - use consistent crypto for encrypt/decrypt'
185
+ )
186
+ })
187
+ })
188
+ //# sourceMappingURL=crypto-compatibility.spec.js.map
@@ -1,2 +1,2 @@
1
- export {};
2
- //# sourceMappingURL=crypto-counter-security.spec.d.ts.map
1
+ export {}
2
+ //# sourceMappingURL=crypto-counter-security.spec.d.ts.map