@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,125 +1,279 @@
|
|
|
1
|
-
import assert from 'node:assert'
|
|
2
|
-
import { describe, test } from 'node:test'
|
|
3
|
-
import { KMSCryptoAdapter } from '../src/crypto/adapters/kms-crypto-adapter.js'
|
|
4
|
-
import { GenericAesCtrStreamingCrypto } from '../src/crypto/symmetric/generic-aes-ctr-streaming-crypto.js'
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import { describe, test } from 'node:test'
|
|
3
|
+
import { KMSCryptoAdapter } from '../src/crypto/adapters/kms-crypto-adapter.js'
|
|
4
|
+
import { GenericAesCtrStreamingCrypto } from '../src/crypto/symmetric/generic-aes-ctr-streaming-crypto.js'
|
|
5
5
|
await describe('HTTPS Enforcement', async () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
6
|
+
await describe('KMSCryptoAdapter Constructor', async () => {
|
|
7
|
+
await test('should accept valid HTTPS URL as string', async () => {
|
|
8
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
9
|
+
// Should not throw
|
|
10
|
+
const adapter = new KMSCryptoAdapter(
|
|
11
|
+
symmetricCrypto,
|
|
12
|
+
'https://private.storacha.link',
|
|
13
|
+
'did:web:private.storacha.link'
|
|
14
|
+
)
|
|
15
|
+
assert(
|
|
16
|
+
adapter instanceof KMSCryptoAdapter,
|
|
17
|
+
'Should create adapter successfully'
|
|
18
|
+
)
|
|
19
|
+
assert.strictEqual(
|
|
20
|
+
adapter.keyManagerServiceURL.protocol,
|
|
21
|
+
'https:',
|
|
22
|
+
'Should store HTTPS protocol'
|
|
23
|
+
)
|
|
24
|
+
assert.strictEqual(
|
|
25
|
+
adapter.keyManagerServiceURL.toString(),
|
|
26
|
+
'https://private.storacha.link/',
|
|
27
|
+
'Should store correct URL'
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
await test('should accept valid HTTPS URL object', async () => {
|
|
31
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
32
|
+
const httpsURL = new URL('https://example.com:8443/path')
|
|
33
|
+
// Should not throw
|
|
34
|
+
const adapter = new KMSCryptoAdapter(
|
|
35
|
+
symmetricCrypto,
|
|
36
|
+
httpsURL,
|
|
37
|
+
'did:web:example.com'
|
|
38
|
+
)
|
|
39
|
+
assert(
|
|
40
|
+
adapter instanceof KMSCryptoAdapter,
|
|
41
|
+
'Should create adapter successfully'
|
|
42
|
+
)
|
|
43
|
+
assert.strictEqual(
|
|
44
|
+
adapter.keyManagerServiceURL.protocol,
|
|
45
|
+
'https:',
|
|
46
|
+
'Should store HTTPS protocol'
|
|
47
|
+
)
|
|
48
|
+
assert.strictEqual(
|
|
49
|
+
adapter.keyManagerServiceURL.toString(),
|
|
50
|
+
'https://example.com:8443/path',
|
|
51
|
+
'Should preserve URL structure'
|
|
52
|
+
)
|
|
53
|
+
})
|
|
54
|
+
await test('should reject HTTP URL string', async () => {
|
|
55
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
56
|
+
assert.throws(
|
|
57
|
+
() =>
|
|
58
|
+
new KMSCryptoAdapter(
|
|
59
|
+
symmetricCrypto,
|
|
60
|
+
'http://insecure.example.com',
|
|
61
|
+
'did:web:example.com'
|
|
62
|
+
),
|
|
63
|
+
/Key manager service must use HTTPS protocol for security/,
|
|
64
|
+
'Should reject HTTP protocol'
|
|
65
|
+
)
|
|
66
|
+
})
|
|
67
|
+
await test('should reject HTTP URL object', async () => {
|
|
68
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
69
|
+
const httpURL = new URL('http://insecure.example.com')
|
|
70
|
+
assert.throws(
|
|
71
|
+
() =>
|
|
72
|
+
new KMSCryptoAdapter(symmetricCrypto, httpURL, 'did:web:example.com'),
|
|
73
|
+
/Key manager service must use HTTPS protocol for security/,
|
|
74
|
+
'Should reject HTTP URL object'
|
|
75
|
+
)
|
|
76
|
+
})
|
|
77
|
+
await test('should reject other protocols', async () => {
|
|
78
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
79
|
+
const protocolTestCases = [
|
|
80
|
+
'ftp://example.com',
|
|
81
|
+
'ws://example.com',
|
|
82
|
+
'file://example.com',
|
|
83
|
+
'data:text/plain;base64,SGVsbG8=',
|
|
84
|
+
]
|
|
85
|
+
for (const testURL of protocolTestCases) {
|
|
86
|
+
assert.throws(
|
|
87
|
+
() =>
|
|
88
|
+
new KMSCryptoAdapter(
|
|
89
|
+
symmetricCrypto,
|
|
90
|
+
testURL,
|
|
91
|
+
'did:web:example.com'
|
|
92
|
+
),
|
|
93
|
+
/Key manager service must use HTTPS protocol for security/,
|
|
94
|
+
`Should reject protocol: ${testURL}`
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
await test('should provide helpful error message', async () => {
|
|
99
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
100
|
+
try {
|
|
101
|
+
new KMSCryptoAdapter(
|
|
102
|
+
symmetricCrypto,
|
|
103
|
+
'http://example.com',
|
|
104
|
+
'did:web:example.com'
|
|
105
|
+
)
|
|
106
|
+
assert.fail('Should have thrown an error')
|
|
107
|
+
} catch (error) {
|
|
108
|
+
assert(error instanceof Error, 'Should throw Error instance')
|
|
109
|
+
assert(
|
|
110
|
+
error.message.includes('Key manager service must use HTTPS protocol'),
|
|
111
|
+
'Should include main error message'
|
|
112
|
+
)
|
|
113
|
+
assert(
|
|
114
|
+
error.message.includes('Received: http:'),
|
|
115
|
+
'Should include received protocol'
|
|
116
|
+
)
|
|
117
|
+
assert(
|
|
118
|
+
error.message.includes('https://your-key-manager-service.com'),
|
|
119
|
+
'Should include example of correct format'
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
await test('should handle localhost development URLs correctly', async () => {
|
|
124
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
125
|
+
// Even localhost should require HTTPS for consistency
|
|
126
|
+
assert.throws(
|
|
127
|
+
() =>
|
|
128
|
+
new KMSCryptoAdapter(
|
|
129
|
+
symmetricCrypto,
|
|
130
|
+
'http://localhost:3000',
|
|
131
|
+
'did:web:localhost'
|
|
132
|
+
),
|
|
133
|
+
/Key manager service must use HTTPS protocol for security/,
|
|
134
|
+
'Should reject HTTP even for localhost'
|
|
135
|
+
)
|
|
136
|
+
// But HTTPS localhost should work
|
|
137
|
+
const adapter = new KMSCryptoAdapter(
|
|
138
|
+
symmetricCrypto,
|
|
139
|
+
'https://localhost:3000',
|
|
140
|
+
'did:web:localhost'
|
|
141
|
+
)
|
|
142
|
+
assert(
|
|
143
|
+
adapter instanceof KMSCryptoAdapter,
|
|
144
|
+
'Should accept HTTPS localhost'
|
|
145
|
+
)
|
|
146
|
+
})
|
|
147
|
+
await test('should handle invalid URL strings gracefully', async () => {
|
|
148
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
149
|
+
assert.throws(
|
|
150
|
+
() =>
|
|
151
|
+
new KMSCryptoAdapter(
|
|
152
|
+
symmetricCrypto,
|
|
153
|
+
'not-a-valid-url',
|
|
154
|
+
'did:web:example.com'
|
|
155
|
+
),
|
|
156
|
+
/Invalid URL/,
|
|
157
|
+
'Should throw URL parsing error for invalid URLs'
|
|
158
|
+
)
|
|
159
|
+
})
|
|
160
|
+
await test('should preserve all adapter functionality after HTTPS validation', async () => {
|
|
161
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
162
|
+
const adapter = new KMSCryptoAdapter(
|
|
163
|
+
symmetricCrypto,
|
|
164
|
+
'https://private.storacha.link',
|
|
165
|
+
'did:web:private.storacha.link'
|
|
166
|
+
)
|
|
167
|
+
// Verify all expected methods exist
|
|
168
|
+
assert.strictEqual(
|
|
169
|
+
typeof adapter.encryptStream,
|
|
170
|
+
'function',
|
|
171
|
+
'Should have encryptStream method'
|
|
172
|
+
)
|
|
173
|
+
assert.strictEqual(
|
|
174
|
+
typeof adapter.decryptStream,
|
|
175
|
+
'function',
|
|
176
|
+
'Should have decryptStream method'
|
|
177
|
+
)
|
|
178
|
+
assert.strictEqual(
|
|
179
|
+
typeof adapter.encryptSymmetricKey,
|
|
180
|
+
'function',
|
|
181
|
+
'Should have encryptSymmetricKey method'
|
|
182
|
+
)
|
|
183
|
+
assert.strictEqual(
|
|
184
|
+
typeof adapter.decryptSymmetricKey,
|
|
185
|
+
'function',
|
|
186
|
+
'Should have decryptSymmetricKey method'
|
|
187
|
+
)
|
|
188
|
+
assert.strictEqual(
|
|
189
|
+
typeof adapter.extractEncryptedMetadata,
|
|
190
|
+
'function',
|
|
191
|
+
'Should have extractEncryptedMetadata method'
|
|
192
|
+
)
|
|
193
|
+
assert.strictEqual(
|
|
194
|
+
typeof adapter.getEncryptedKey,
|
|
195
|
+
'function',
|
|
196
|
+
'Should have getEncryptedKey method'
|
|
197
|
+
)
|
|
198
|
+
assert.strictEqual(
|
|
199
|
+
typeof adapter.encodeMetadata,
|
|
200
|
+
'function',
|
|
201
|
+
'Should have encodeMetadata method'
|
|
202
|
+
)
|
|
203
|
+
// Verify adapter properties are set correctly
|
|
204
|
+
assert(
|
|
205
|
+
adapter.symmetricCrypto === symmetricCrypto,
|
|
206
|
+
'Should store symmetric crypto reference'
|
|
207
|
+
)
|
|
208
|
+
assert.strictEqual(
|
|
209
|
+
adapter.keyManagerServiceDID.did(),
|
|
210
|
+
'did:web:private.storacha.link',
|
|
211
|
+
'Should store gateway DID'
|
|
212
|
+
)
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
await describe('Secure by Default Principle', async () => {
|
|
216
|
+
await test('should demonstrate secure by default - HTTPS is automatically used', async () => {
|
|
217
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
218
|
+
// All of these should work without any special configuration
|
|
219
|
+
const validHttpsUrls = [
|
|
220
|
+
'https://gateway.example.com',
|
|
221
|
+
'https://localhost:8080',
|
|
222
|
+
'https://192.168.1.100:3000',
|
|
223
|
+
'https://api.storacha.network:443/v1',
|
|
224
|
+
]
|
|
225
|
+
for (const url of validHttpsUrls) {
|
|
226
|
+
const adapter = new KMSCryptoAdapter(
|
|
227
|
+
symmetricCrypto,
|
|
228
|
+
url,
|
|
229
|
+
'did:web:example.com'
|
|
230
|
+
)
|
|
231
|
+
assert.strictEqual(
|
|
232
|
+
adapter.keyManagerServiceURL.protocol,
|
|
233
|
+
'https:',
|
|
234
|
+
`Should store HTTPS protocol for URL: ${url}`
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
await test('should require explicit insecure configuration to bypass HTTPS', async () => {
|
|
239
|
+
// This demonstrates that HTTP is never accidentally allowed
|
|
240
|
+
// If someone really needs HTTP (like for testing), they would need to
|
|
241
|
+
// modify our security validation code intentionally
|
|
242
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
243
|
+
const httpUrls = [
|
|
244
|
+
'http://example.com',
|
|
245
|
+
'http://localhost:3000',
|
|
246
|
+
'http://192.168.1.100:8080',
|
|
247
|
+
]
|
|
248
|
+
for (const url of httpUrls) {
|
|
249
|
+
assert.throws(
|
|
250
|
+
() =>
|
|
251
|
+
new KMSCryptoAdapter(symmetricCrypto, url, 'did:web:example.com'),
|
|
252
|
+
/Key manager service must use HTTPS protocol for security/,
|
|
253
|
+
`Should reject HTTP URL: ${url}`
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
await test('should allow HTTP for testing when explicitly enabled', async () => {
|
|
258
|
+
// This demonstrates the testing escape hatch
|
|
259
|
+
const symmetricCrypto = new GenericAesCtrStreamingCrypto()
|
|
260
|
+
const adapter = new KMSCryptoAdapter(
|
|
261
|
+
symmetricCrypto,
|
|
262
|
+
'http://localhost:8080',
|
|
263
|
+
'did:web:localhost',
|
|
264
|
+
{ allowInsecureHttp: true } // Explicit testing option
|
|
265
|
+
)
|
|
266
|
+
assert.strictEqual(
|
|
267
|
+
adapter.keyManagerServiceURL.protocol,
|
|
268
|
+
'http:',
|
|
269
|
+
'Should allow HTTP when explicitly enabled for testing'
|
|
270
|
+
)
|
|
271
|
+
assert.strictEqual(
|
|
272
|
+
adapter.keyManagerServiceURL.toString(),
|
|
273
|
+
'http://localhost:8080/',
|
|
274
|
+
'Should preserve HTTP URL when testing option is enabled'
|
|
275
|
+
)
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
//# sourceMappingURL=https-enforcement.spec.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {}
|
|
2
|
-
//# sourceMappingURL=kms-crypto-adapter.spec.d.ts.map
|
|
1
|
+
export {}
|
|
2
|
+
//# sourceMappingURL=kms-crypto-adapter.spec.d.ts.map
|