@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.
- package/dist/config/constants.d.ts +3 -3
- package/dist/config/constants.js +4 -3
- package/dist/config/env.d.ts +9 -6
- package/dist/config/service.d.ts +13 -13
- package/dist/core/client.d.ts +54 -41
- package/dist/core/client.js +68 -56
- package/dist/core/errors.d.ts +6 -6
- package/dist/core/metadata/encrypted-metadata.d.ts +13 -8
- package/dist/core/metadata/kms-metadata.d.ts +68 -36
- package/dist/core/metadata/lit-metadata.d.ts +63 -28
- package/dist/crypto/adapters/kms-crypto-adapter.d.ts +172 -137
- package/dist/crypto/adapters/lit-crypto-adapter.d.ts +107 -86
- package/dist/crypto/factories.browser.d.ts +9 -5
- package/dist/crypto/factories.browser.js +15 -7
- package/dist/crypto/factories.node.d.ts +13 -6
- package/dist/crypto/factories.node.js +19 -13
- package/dist/crypto/index.d.ts +5 -5
- package/dist/crypto/index.js +5 -5
- package/dist/crypto/symmetric/generic-aes-ctr-streaming-crypto.d.ts +58 -54
- package/dist/crypto/symmetric/generic-aes-ctr-streaming-crypto.js +174 -146
- package/dist/crypto/symmetric/node-aes-cbc-crypto.d.ts +36 -32
- package/dist/crypto/symmetric/node-aes-cbc-crypto.js +101 -95
- package/dist/examples/decrypt-test.d.ts +2 -2
- package/dist/examples/decrypt-test.js +78 -69
- package/dist/examples/encrypt-test.d.ts +5 -3
- package/dist/examples/encrypt-test.js +58 -55
- package/dist/handlers/decrypt-handler.d.ts +19 -5
- package/dist/handlers/encrypt-handler.d.ts +9 -3
- package/dist/handlers/encrypt-handler.js +93 -57
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/protocols/lit.d.ts +33 -9
- package/dist/protocols/lit.js +134 -98
- package/dist/test/cid-verification.spec.d.ts +2 -2
- package/dist/test/cid-verification.spec.js +341 -313
- package/dist/test/crypto-compatibility.spec.d.ts +2 -2
- package/dist/test/crypto-compatibility.spec.js +184 -120
- package/dist/test/crypto-counter-security.spec.d.ts +2 -2
- package/dist/test/crypto-counter-security.spec.js +177 -138
- package/dist/test/crypto-streaming.spec.d.ts +2 -2
- package/dist/test/crypto-streaming.spec.js +208 -126
- package/dist/test/encrypted-metadata.spec.d.ts +2 -2
- package/dist/test/encrypted-metadata.spec.js +89 -62
- package/dist/test/factories.spec.d.ts +2 -2
- package/dist/test/factories.spec.js +275 -139
- package/dist/test/file-metadata.spec.d.ts +2 -2
- package/dist/test/file-metadata.spec.js +472 -416
- package/dist/test/fixtures/test-fixtures.d.ts +25 -20
- package/dist/test/fixtures/test-fixtures.js +61 -53
- package/dist/test/helpers/test-file-utils.d.ts +19 -14
- package/dist/test/helpers/test-file-utils.js +78 -76
- package/dist/test/https-enforcement.spec.d.ts +2 -2
- package/dist/test/https-enforcement.spec.js +278 -124
- package/dist/test/kms-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/kms-crypto-adapter.spec.js +473 -304
- package/dist/test/lit-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/lit-crypto-adapter.spec.js +206 -118
- package/dist/test/memory-efficiency.spec.d.ts +2 -2
- package/dist/test/memory-efficiency.spec.js +100 -87
- package/dist/test/mocks/key-manager.d.ts +71 -38
- package/dist/test/mocks/key-manager.js +129 -113
- package/dist/test/node-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/node-crypto-adapter.spec.js +155 -102
- package/dist/test/node-generic-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/node-generic-crypto-adapter.spec.js +134 -94
- package/dist/test/setup.d.ts +2 -2
- package/dist/test/setup.js +8 -9
- package/dist/tsconfig.spec.tsbuildinfo +1 -1
- package/dist/types.d.ts +219 -181
- package/dist/utils/file-metadata.d.ts +19 -13
- package/dist/utils.d.ts +14 -5
- package/package.json +4 -4
|
@@ -1,142 +1,278 @@
|
|
|
1
|
-
import './setup.js'
|
|
2
|
-
import { test, describe } from 'node:test'
|
|
3
|
-
import assert from 'node:assert'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import './setup.js'
|
|
2
|
+
import { test, describe } from 'node:test'
|
|
3
|
+
import assert from 'node:assert'
|
|
4
|
+
import {
|
|
5
|
+
createGenericKMSAdapter,
|
|
6
|
+
createGenericLitAdapter,
|
|
7
|
+
createNodeLitAdapter,
|
|
8
|
+
} from '../src/crypto/factories.node.js'
|
|
9
|
+
import { GenericAesCtrStreamingCrypto } from '../src/crypto/symmetric/generic-aes-ctr-streaming-crypto.js'
|
|
10
|
+
import { NodeAesCbcCrypto } from '../src/crypto/symmetric/node-aes-cbc-crypto.js'
|
|
11
|
+
import { LitCryptoAdapter } from '../src/crypto/adapters/lit-crypto-adapter.js'
|
|
12
|
+
import { KMSCryptoAdapter } from '../src/crypto/adapters/kms-crypto-adapter.js'
|
|
9
13
|
// Mock Lit client for testing
|
|
10
14
|
const mockLitClient = /** @type {any} */ ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
15
|
+
connect: () => Promise.resolve(),
|
|
16
|
+
disconnect: () => Promise.resolve(),
|
|
17
|
+
})
|
|
14
18
|
await describe('Crypto Factory Functions', async () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
19
|
+
await describe('createBrowserLitAdapter', async () => {
|
|
20
|
+
await test('should create LitCryptoAdapter with streaming crypto', async () => {
|
|
21
|
+
const adapter = createGenericLitAdapter(mockLitClient)
|
|
22
|
+
// Verify adapter type
|
|
23
|
+
assert(
|
|
24
|
+
adapter instanceof LitCryptoAdapter,
|
|
25
|
+
'Should create LitCryptoAdapter instance'
|
|
26
|
+
)
|
|
27
|
+
// Verify symmetric crypto implementation
|
|
28
|
+
assert(
|
|
29
|
+
adapter.symmetricCrypto instanceof GenericAesCtrStreamingCrypto,
|
|
30
|
+
'Should use GenericAesCtrStreamingCrypto for browser environment'
|
|
31
|
+
)
|
|
32
|
+
// Verify lit client is passed through
|
|
33
|
+
assert.strictEqual(
|
|
34
|
+
adapter.litClient,
|
|
35
|
+
mockLitClient,
|
|
36
|
+
'Should pass through the lit client'
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
await test('should create adapter with required interface methods', async () => {
|
|
40
|
+
const adapter = createGenericLitAdapter(mockLitClient)
|
|
41
|
+
// Verify adapter has all required methods
|
|
42
|
+
assert(
|
|
43
|
+
typeof adapter.encryptStream === 'function',
|
|
44
|
+
'Should have encryptStream method'
|
|
45
|
+
)
|
|
46
|
+
assert(
|
|
47
|
+
typeof adapter.decryptStream === 'function',
|
|
48
|
+
'Should have decryptStream method'
|
|
49
|
+
)
|
|
50
|
+
assert(
|
|
51
|
+
typeof adapter.encryptSymmetricKey === 'function',
|
|
52
|
+
'Should have encryptSymmetricKey method'
|
|
53
|
+
)
|
|
54
|
+
assert(
|
|
55
|
+
typeof adapter.decryptSymmetricKey === 'function',
|
|
56
|
+
'Should have decryptSymmetricKey method'
|
|
57
|
+
)
|
|
58
|
+
assert(
|
|
59
|
+
typeof adapter.extractEncryptedMetadata === 'function',
|
|
60
|
+
'Should have extractEncryptedMetadata method'
|
|
61
|
+
)
|
|
62
|
+
assert(
|
|
63
|
+
typeof adapter.getEncryptedKey === 'function',
|
|
64
|
+
'Should have getEncryptedKey method'
|
|
65
|
+
)
|
|
66
|
+
})
|
|
67
|
+
await test('should handle null or undefined lit client gracefully', async () => {
|
|
68
|
+
// This should still create the adapter (validation happens at runtime)
|
|
69
|
+
const adapter = createGenericLitAdapter(/** @type {any} */ (null))
|
|
70
|
+
assert(
|
|
71
|
+
adapter instanceof LitCryptoAdapter,
|
|
72
|
+
'Should create adapter even with null client'
|
|
73
|
+
)
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
await describe('createNodeLitAdapter', async () => {
|
|
77
|
+
await test('should create LitCryptoAdapter with Node crypto', async () => {
|
|
78
|
+
const adapter = createNodeLitAdapter(mockLitClient)
|
|
79
|
+
// Verify adapter type
|
|
80
|
+
assert(
|
|
81
|
+
adapter instanceof LitCryptoAdapter,
|
|
82
|
+
'Should create LitCryptoAdapter instance'
|
|
83
|
+
)
|
|
84
|
+
// Verify symmetric crypto implementation
|
|
85
|
+
assert(
|
|
86
|
+
adapter.symmetricCrypto instanceof NodeAesCbcCrypto,
|
|
87
|
+
'Should use NodeAesCbcCrypto for Node.js environment'
|
|
88
|
+
)
|
|
89
|
+
// Verify lit client is passed through
|
|
90
|
+
assert.strictEqual(
|
|
91
|
+
adapter.litClient,
|
|
92
|
+
mockLitClient,
|
|
93
|
+
'Should pass through the lit client'
|
|
94
|
+
)
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
await describe('createBrowserKMSAdapter', async () => {
|
|
98
|
+
await test('should create KMSCryptoAdapter with streaming crypto', async () => {
|
|
99
|
+
const keyManagerServiceURL = 'https://gateway.example.com'
|
|
100
|
+
const keyManagerServiceDID = 'did:web:gateway.example.com'
|
|
101
|
+
const adapter = createGenericKMSAdapter(
|
|
102
|
+
keyManagerServiceURL,
|
|
103
|
+
keyManagerServiceDID
|
|
104
|
+
)
|
|
105
|
+
// Verify adapter type
|
|
106
|
+
assert(
|
|
107
|
+
adapter instanceof KMSCryptoAdapter,
|
|
108
|
+
'Should create KMSCryptoAdapter instance'
|
|
109
|
+
)
|
|
110
|
+
// Verify symmetric crypto implementation
|
|
111
|
+
assert(
|
|
112
|
+
adapter.symmetricCrypto instanceof GenericAesCtrStreamingCrypto,
|
|
113
|
+
'Should use GenericAesCtrStreamingCrypto for browser environment'
|
|
114
|
+
)
|
|
115
|
+
// Verify configuration is passed through
|
|
116
|
+
assert.strictEqual(
|
|
117
|
+
adapter.keyManagerServiceURL.toString(),
|
|
118
|
+
keyManagerServiceURL + '/',
|
|
119
|
+
'Should set the key manager service URL'
|
|
120
|
+
)
|
|
121
|
+
assert.strictEqual(
|
|
122
|
+
adapter.keyManagerServiceDID.did(),
|
|
123
|
+
keyManagerServiceDID,
|
|
124
|
+
'Should set the key manager service DID'
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
await test('should accept URL object for gateway URL', async () => {
|
|
128
|
+
const keyManagerServiceURL = new URL('https://gateway.example.com')
|
|
129
|
+
const keyManagerServiceDID = 'did:web:gateway.example.com'
|
|
130
|
+
const adapter = createGenericKMSAdapter(
|
|
131
|
+
keyManagerServiceURL,
|
|
132
|
+
keyManagerServiceDID
|
|
133
|
+
)
|
|
134
|
+
assert(
|
|
135
|
+
adapter instanceof KMSCryptoAdapter,
|
|
136
|
+
'Should create KMSCryptoAdapter with URL object'
|
|
137
|
+
)
|
|
138
|
+
assert.strictEqual(
|
|
139
|
+
adapter.keyManagerServiceURL.toString(),
|
|
140
|
+
keyManagerServiceURL.toString(),
|
|
141
|
+
'Should handle URL object input'
|
|
142
|
+
)
|
|
143
|
+
})
|
|
144
|
+
await test('should enforce HTTPS for security', async () => {
|
|
145
|
+
const httpKeyManagerServiceURL = 'http://insecure.example.com'
|
|
146
|
+
const keyManagerServiceDID = 'did:web:example.com'
|
|
147
|
+
assert.throws(
|
|
148
|
+
() =>
|
|
149
|
+
createGenericKMSAdapter(
|
|
150
|
+
httpKeyManagerServiceURL,
|
|
151
|
+
keyManagerServiceDID
|
|
152
|
+
),
|
|
153
|
+
/Key manager service must use HTTPS protocol for security/,
|
|
154
|
+
'Should reject HTTP URLs for security'
|
|
155
|
+
)
|
|
156
|
+
})
|
|
157
|
+
await test('should allow HTTP with explicit insecure option', async () => {
|
|
158
|
+
// Note: The current implementation doesn't expose options in the factory
|
|
159
|
+
// but we can test this through direct adapter construction
|
|
160
|
+
const httpKeyManagerServiceURL = 'http://localhost:3000'
|
|
161
|
+
const keyManagerServiceDID = 'did:web:localhost'
|
|
162
|
+
assert.throws(
|
|
163
|
+
() =>
|
|
164
|
+
createGenericKMSAdapter(
|
|
165
|
+
httpKeyManagerServiceURL,
|
|
166
|
+
keyManagerServiceDID
|
|
167
|
+
),
|
|
168
|
+
/Key manager service must use HTTPS protocol for security/,
|
|
169
|
+
'Should reject HTTP URLs even for localhost by default'
|
|
170
|
+
)
|
|
171
|
+
})
|
|
172
|
+
await test('should have all required KMS adapter methods', async () => {
|
|
173
|
+
const adapter = createGenericKMSAdapter(
|
|
174
|
+
'https://gateway.example.com',
|
|
175
|
+
'did:web:gateway.example.com'
|
|
176
|
+
)
|
|
177
|
+
// Verify adapter has all required methods
|
|
178
|
+
assert(
|
|
179
|
+
typeof adapter.encryptStream === 'function',
|
|
180
|
+
'Should have encryptStream method'
|
|
181
|
+
)
|
|
182
|
+
assert(
|
|
183
|
+
typeof adapter.decryptStream === 'function',
|
|
184
|
+
'Should have decryptStream method'
|
|
185
|
+
)
|
|
186
|
+
assert(
|
|
187
|
+
typeof adapter.encryptSymmetricKey === 'function',
|
|
188
|
+
'Should have encryptSymmetricKey method'
|
|
189
|
+
)
|
|
190
|
+
assert(
|
|
191
|
+
typeof adapter.decryptSymmetricKey === 'function',
|
|
192
|
+
'Should have decryptSymmetricKey method'
|
|
193
|
+
)
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
await describe('Factory Function Consistency', async () => {
|
|
197
|
+
await test('browser factories should use streaming crypto', async () => {
|
|
198
|
+
const litAdapter = createGenericLitAdapter(mockLitClient)
|
|
199
|
+
const kmsAdapter = createGenericKMSAdapter(
|
|
200
|
+
'https://gateway.example.com',
|
|
201
|
+
'did:web:gateway.example.com'
|
|
202
|
+
)
|
|
203
|
+
assert(
|
|
204
|
+
litAdapter.symmetricCrypto.constructor.name ===
|
|
205
|
+
'GenericAesCtrStreamingCrypto',
|
|
206
|
+
'Browser Lit adapter should use streaming crypto'
|
|
207
|
+
)
|
|
208
|
+
assert(
|
|
209
|
+
kmsAdapter.symmetricCrypto.constructor.name ===
|
|
210
|
+
'GenericAesCtrStreamingCrypto',
|
|
211
|
+
'Browser KMS adapter should use streaming crypto'
|
|
212
|
+
)
|
|
213
|
+
})
|
|
214
|
+
await test('node factories should use Node crypto', async () => {
|
|
215
|
+
const litAdapter = createNodeLitAdapter(mockLitClient)
|
|
216
|
+
assert(
|
|
217
|
+
litAdapter.symmetricCrypto.constructor.name === 'NodeAesCbcCrypto',
|
|
218
|
+
'Node Lit adapter should use Node crypto'
|
|
219
|
+
)
|
|
220
|
+
})
|
|
221
|
+
await test('all adapters should implement the same interface', async () => {
|
|
222
|
+
const adapters = [
|
|
223
|
+
createGenericLitAdapter(mockLitClient),
|
|
224
|
+
createNodeLitAdapter(mockLitClient),
|
|
225
|
+
createGenericKMSAdapter(
|
|
226
|
+
'https://gateway.example.com',
|
|
227
|
+
'did:web:gateway.example.com'
|
|
228
|
+
),
|
|
229
|
+
createGenericKMSAdapter(
|
|
230
|
+
'https://gateway.example.com',
|
|
231
|
+
'did:web:gateway.example.com'
|
|
232
|
+
),
|
|
233
|
+
]
|
|
234
|
+
const requiredMethods = [
|
|
235
|
+
'encryptStream',
|
|
236
|
+
'decryptStream',
|
|
237
|
+
'encryptSymmetricKey',
|
|
238
|
+
'decryptSymmetricKey',
|
|
239
|
+
'extractEncryptedMetadata',
|
|
240
|
+
'getEncryptedKey',
|
|
241
|
+
]
|
|
242
|
+
for (const adapter of adapters) {
|
|
243
|
+
for (const method of requiredMethods) {
|
|
244
|
+
assert(
|
|
245
|
+
typeof (/** @type {any} */ (adapter)[method]) === 'function',
|
|
246
|
+
`${adapter.constructor.name} should have ${method} method`
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
await describe('Memory Usage Verification', async () => {
|
|
253
|
+
await test('browser adapters should use memory-efficient streaming crypto', async () => {
|
|
254
|
+
const litAdapter = createGenericLitAdapter(mockLitClient)
|
|
255
|
+
const kmsAdapter = createGenericKMSAdapter(
|
|
256
|
+
'https://gateway.example.com',
|
|
257
|
+
'did:web:gateway.example.com'
|
|
258
|
+
)
|
|
259
|
+
// Verify both use the streaming implementation
|
|
260
|
+
assert(
|
|
261
|
+
litAdapter.symmetricCrypto instanceof GenericAesCtrStreamingCrypto,
|
|
262
|
+
'Lit adapter should use streaming crypto for memory efficiency'
|
|
263
|
+
)
|
|
264
|
+
assert(
|
|
265
|
+
kmsAdapter.symmetricCrypto instanceof GenericAesCtrStreamingCrypto,
|
|
266
|
+
'KMS adapter should use streaming crypto for memory efficiency'
|
|
267
|
+
)
|
|
268
|
+
// Verify they have the streaming characteristics
|
|
269
|
+
const testBlob = new Blob([new Uint8Array(1024)]) // 1KB test
|
|
270
|
+
const litResult = await litAdapter.encryptStream(testBlob)
|
|
271
|
+
assert(
|
|
272
|
+
litResult.encryptedStream instanceof ReadableStream,
|
|
273
|
+
'Should return ReadableStream for streaming'
|
|
274
|
+
)
|
|
275
|
+
})
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
//# sourceMappingURL=factories.spec.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {}
|
|
2
|
-
//# sourceMappingURL=file-metadata.spec.d.ts.map
|
|
1
|
+
export {}
|
|
2
|
+
//# sourceMappingURL=file-metadata.spec.d.ts.map
|