@storacha/encrypt-upload-client 1.1.66 → 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.
- package/README.md +1 -1
- package/dist/config/constants.d.ts +1 -1
- package/dist/config/constants.d.ts.map +1 -1
- package/dist/config/constants.js +2 -2
- package/dist/config/env.d.ts +0 -1
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +0 -7
- package/dist/core/client.js +1 -1
- package/dist/crypto/adapters/lit-crypto-adapter.d.ts +35 -4
- package/dist/crypto/adapters/lit-crypto-adapter.d.ts.map +1 -1
- package/dist/crypto/adapters/lit-crypto-adapter.js +38 -41
- package/dist/crypto/factories.node.d.ts +4 -10
- package/dist/crypto/factories.node.d.ts.map +1 -1
- package/dist/crypto/factories.node.js +6 -16
- package/dist/protocols/lit.d.ts +13 -18
- package/dist/protocols/lit.d.ts.map +1 -1
- package/dist/protocols/lit.js +67 -88
- package/dist/types.d.ts +24 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/file-metadata.d.ts.map +1 -1
- package/dist/utils/file-metadata.js +39 -14
- package/package.json +12 -11
- package/dist/examples/decrypt-test.d.ts +0 -2
- package/dist/examples/decrypt-test.d.ts.map +0 -1
- package/dist/examples/decrypt-test.js +0 -73
- package/dist/examples/encrypt-test.d.ts +0 -4
- package/dist/examples/encrypt-test.d.ts.map +0 -1
- package/dist/examples/encrypt-test.js +0 -61
- package/dist/test/cid-verification.spec.d.ts +0 -2
- package/dist/test/cid-verification.spec.d.ts.map +0 -1
- package/dist/test/cid-verification.spec.js +0 -314
- package/dist/test/crypto-compatibility.spec.d.ts +0 -2
- package/dist/test/crypto-compatibility.spec.d.ts.map +0 -1
- package/dist/test/crypto-compatibility.spec.js +0 -124
- package/dist/test/crypto-counter-security.spec.d.ts +0 -2
- package/dist/test/crypto-counter-security.spec.d.ts.map +0 -1
- package/dist/test/crypto-counter-security.spec.js +0 -147
- package/dist/test/crypto-streaming.spec.d.ts +0 -2
- package/dist/test/crypto-streaming.spec.d.ts.map +0 -1
- package/dist/test/crypto-streaming.spec.js +0 -129
- package/dist/test/encrypted-metadata.spec.d.ts +0 -2
- package/dist/test/encrypted-metadata.spec.d.ts.map +0 -1
- package/dist/test/encrypted-metadata.spec.js +0 -68
- package/dist/test/factories.spec.d.ts +0 -2
- package/dist/test/factories.spec.d.ts.map +0 -1
- package/dist/test/factories.spec.js +0 -142
- package/dist/test/file-metadata.spec.d.ts +0 -2
- package/dist/test/file-metadata.spec.d.ts.map +0 -1
- package/dist/test/file-metadata.spec.js +0 -433
- package/dist/test/fixtures/test-fixtures.d.ts +0 -28
- package/dist/test/fixtures/test-fixtures.d.ts.map +0 -1
- package/dist/test/fixtures/test-fixtures.js +0 -63
- package/dist/test/helpers/test-file-utils.d.ts +0 -60
- package/dist/test/helpers/test-file-utils.d.ts.map +0 -1
- package/dist/test/helpers/test-file-utils.js +0 -139
- package/dist/test/https-enforcement.spec.d.ts +0 -2
- package/dist/test/https-enforcement.spec.d.ts.map +0 -1
- package/dist/test/https-enforcement.spec.js +0 -125
- package/dist/test/kms-crypto-adapter.spec.d.ts +0 -2
- package/dist/test/kms-crypto-adapter.spec.d.ts.map +0 -1
- package/dist/test/kms-crypto-adapter.spec.js +0 -305
- package/dist/test/lit-crypto-adapter.spec.d.ts +0 -2
- package/dist/test/lit-crypto-adapter.spec.d.ts.map +0 -1
- package/dist/test/lit-crypto-adapter.spec.js +0 -120
- package/dist/test/memory-efficiency.spec.d.ts +0 -2
- package/dist/test/memory-efficiency.spec.d.ts.map +0 -1
- package/dist/test/memory-efficiency.spec.js +0 -93
- package/dist/test/mocks/key-manager.d.ts +0 -58
- package/dist/test/mocks/key-manager.d.ts.map +0 -1
- package/dist/test/mocks/key-manager.js +0 -137
- package/dist/test/node-crypto-adapter.spec.d.ts +0 -2
- package/dist/test/node-crypto-adapter.spec.d.ts.map +0 -1
- package/dist/test/node-crypto-adapter.spec.js +0 -103
- package/dist/test/node-generic-crypto-adapter.spec.d.ts +0 -2
- package/dist/test/node-generic-crypto-adapter.spec.d.ts.map +0 -1
- package/dist/test/node-generic-crypto-adapter.spec.js +0 -95
- package/dist/test/setup.d.ts +0 -2
- package/dist/test/setup.d.ts.map +0 -1
- package/dist/test/setup.js +0 -12
- package/dist/tsconfig.spec.tsbuildinfo +0 -1
|
@@ -1,129 +0,0 @@
|
|
|
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 { createTestFile, streamToUint8Array, } from './helpers/test-file-utils.js';
|
|
6
|
-
// FIXME (fforbeck) - Remove this skip when ready to run streaming crypto tests. It is failing on CI.
|
|
7
|
-
await describe.skip('Streaming Crypto - Core Functionality', async () => {
|
|
8
|
-
await test('should encrypt and decrypt small files correctly', async () => {
|
|
9
|
-
const crypto = new GenericAesCtrStreamingCrypto();
|
|
10
|
-
const testFile = createTestFile(0.01); // 10KB (ultra-small for memory safety)
|
|
11
|
-
// Encrypt
|
|
12
|
-
const { key, iv, encryptedStream } = await crypto.encryptStream(testFile);
|
|
13
|
-
assert(key instanceof Uint8Array, 'Key should be Uint8Array');
|
|
14
|
-
assert.strictEqual(key.length, 32, 'Key should be 32 bytes');
|
|
15
|
-
assert(iv instanceof Uint8Array, 'IV should be Uint8Array');
|
|
16
|
-
assert.strictEqual(iv.length, 16, 'IV should be 16 bytes');
|
|
17
|
-
// Convert stream to bytes
|
|
18
|
-
const encryptedBytes = await streamToUint8Array(encryptedStream);
|
|
19
|
-
assert.strictEqual(encryptedBytes.length, testFile.size, 'Encrypted size should match original');
|
|
20
|
-
// Decrypt
|
|
21
|
-
const encryptedForDecrypt = new ReadableStream({
|
|
22
|
-
start(controller) {
|
|
23
|
-
controller.enqueue(encryptedBytes);
|
|
24
|
-
controller.close();
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
const decryptedStream = await crypto.decryptStream(encryptedForDecrypt, key, iv);
|
|
28
|
-
const decryptedBytes = await streamToUint8Array(decryptedStream);
|
|
29
|
-
// Verify round-trip
|
|
30
|
-
const originalBytes = new Uint8Array(await testFile.arrayBuffer());
|
|
31
|
-
assert.deepStrictEqual(decryptedBytes, originalBytes, 'Decrypted should match original');
|
|
32
|
-
console.log(`✓ Successfully encrypted/decrypted ${testFile.size} bytes`);
|
|
33
|
-
});
|
|
34
|
-
await test('should handle edge cases', async () => {
|
|
35
|
-
const crypto = new GenericAesCtrStreamingCrypto();
|
|
36
|
-
// Empty file
|
|
37
|
-
const emptyFile = new Blob([]);
|
|
38
|
-
const { encryptedStream: emptyEncrypted } = await crypto.encryptStream(emptyFile);
|
|
39
|
-
const emptyBytes = await streamToUint8Array(emptyEncrypted);
|
|
40
|
-
assert.strictEqual(emptyBytes.length, 0, 'Empty file should produce empty encrypted data');
|
|
41
|
-
// Single byte
|
|
42
|
-
const singleByteFile = new Blob([new Uint8Array([42])]);
|
|
43
|
-
const { key, iv, encryptedStream } = await crypto.encryptStream(singleByteFile);
|
|
44
|
-
const encryptedBytes = await streamToUint8Array(encryptedStream);
|
|
45
|
-
assert.strictEqual(encryptedBytes.length, 1, 'Single byte should produce single encrypted byte');
|
|
46
|
-
// Decrypt single byte
|
|
47
|
-
const encryptedForDecrypt = new ReadableStream({
|
|
48
|
-
start(controller) {
|
|
49
|
-
controller.enqueue(encryptedBytes);
|
|
50
|
-
controller.close();
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
const decryptedStream = await crypto.decryptStream(encryptedForDecrypt, key, iv);
|
|
54
|
-
const decryptedBytes = await streamToUint8Array(decryptedStream);
|
|
55
|
-
assert.deepStrictEqual(decryptedBytes, new Uint8Array([42]), 'Should decrypt to original byte');
|
|
56
|
-
console.log('✓ Edge cases handled correctly');
|
|
57
|
-
});
|
|
58
|
-
await test('should handle medium-sized files without issues', async () => {
|
|
59
|
-
try {
|
|
60
|
-
const crypto = new GenericAesCtrStreamingCrypto();
|
|
61
|
-
// Test with progressively larger files to show streaming works consistently
|
|
62
|
-
// Reduced sizes for CI stability while still testing streaming functionality
|
|
63
|
-
const testSizes = [0.5, 1, 2]; // MB
|
|
64
|
-
for (const sizeMB of testSizes) {
|
|
65
|
-
console.log(`Testing ${sizeMB}MB file...`);
|
|
66
|
-
const testFile = createTestFile(sizeMB);
|
|
67
|
-
const { key, iv, encryptedStream } = await crypto.encryptStream(testFile);
|
|
68
|
-
// Convert encrypted stream to bytes first
|
|
69
|
-
const encryptedBytes = await streamToUint8Array(encryptedStream);
|
|
70
|
-
// Create a new stream from the encrypted bytes for decryption
|
|
71
|
-
const encryptedForDecrypt = new ReadableStream({
|
|
72
|
-
start(controller) {
|
|
73
|
-
controller.enqueue(encryptedBytes);
|
|
74
|
-
controller.close();
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
const decryptedStream = await crypto.decryptStream(encryptedForDecrypt, key, iv);
|
|
78
|
-
const decryptedBytes = await streamToUint8Array(decryptedStream);
|
|
79
|
-
assert.strictEqual(decryptedBytes.length, sizeMB * 1024 * 1024, `Decrypted file size mismatch for ${sizeMB}MB`);
|
|
80
|
-
console.log(`✓ ${sizeMB}MB file encrypted and decrypted successfully`);
|
|
81
|
-
}
|
|
82
|
-
console.log('✓ Medium-sized files handled without issues');
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
console.error('Test error (type):', typeof err, err && err.constructor && err.constructor.name);
|
|
86
|
-
console.error('Test error (keys):', err && Object.keys(err));
|
|
87
|
-
console.error('Test error (string):', String(err));
|
|
88
|
-
console.log(err);
|
|
89
|
-
assert.fail('Unable to test medium-sized files');
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
await test('should use proper counter arithmetic', async () => {
|
|
93
|
-
const crypto = new GenericAesCtrStreamingCrypto();
|
|
94
|
-
// Test counter increment function directly
|
|
95
|
-
const baseCounter = new Uint8Array([
|
|
96
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
97
|
-
]);
|
|
98
|
-
// Increment by 1
|
|
99
|
-
const counter1 = crypto.incrementCounter(baseCounter, 1);
|
|
100
|
-
assert.deepStrictEqual(counter1, new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), 'Should increment last byte by 1');
|
|
101
|
-
// Increment by 255
|
|
102
|
-
const counter255 = crypto.incrementCounter(baseCounter, 255);
|
|
103
|
-
assert.deepStrictEqual(counter255, new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255]), 'Should increment last byte by 255');
|
|
104
|
-
// Increment by 256 (should carry)
|
|
105
|
-
const counter256 = crypto.incrementCounter(baseCounter, 256);
|
|
106
|
-
assert.deepStrictEqual(counter256, new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]), 'Should carry to second-to-last byte');
|
|
107
|
-
console.log('✓ Counter arithmetic works correctly');
|
|
108
|
-
});
|
|
109
|
-
await test('should implement complete interface', async () => {
|
|
110
|
-
const crypto = new GenericAesCtrStreamingCrypto();
|
|
111
|
-
// Check all required methods exist
|
|
112
|
-
assert(typeof crypto.generateKey === 'function', 'Should have generateKey method');
|
|
113
|
-
assert(typeof crypto.encryptStream === 'function', 'Should have encryptStream method');
|
|
114
|
-
assert(typeof crypto.decryptStream === 'function', 'Should have decryptStream method');
|
|
115
|
-
assert(typeof crypto.combineKeyAndIV === 'function', 'Should have combineKeyAndIV method');
|
|
116
|
-
assert(typeof crypto.splitKeyAndIV === 'function', 'Should have splitKeyAndIV method');
|
|
117
|
-
assert(typeof crypto.incrementCounter === 'function', 'Should have incrementCounter method');
|
|
118
|
-
// Test combine/split methods
|
|
119
|
-
const key = await crypto.generateKey();
|
|
120
|
-
const iv = globalThis.crypto.getRandomValues(new Uint8Array(16));
|
|
121
|
-
const combined = crypto.combineKeyAndIV(key, iv);
|
|
122
|
-
assert.strictEqual(combined.length, 48, 'Combined should be 48 bytes (32 key + 16 IV)');
|
|
123
|
-
const { key: splitKey, iv: splitIV } = crypto.splitKeyAndIV(combined);
|
|
124
|
-
assert.deepStrictEqual(splitKey, key, 'Split key should match original');
|
|
125
|
-
assert.deepStrictEqual(splitIV, iv, 'Split IV should match original');
|
|
126
|
-
console.log('Complete interface implemented correctly');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
//# sourceMappingURL=crypto-streaming.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encrypted-metadata.spec.d.ts","sourceRoot":"","sources":["../../test/encrypted-metadata.spec.js"],"names":[],"mappings":""}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import { describe, it } from 'node:test';
|
|
3
|
-
import * as Result from '@storacha/client/result';
|
|
4
|
-
import * as Types from '../src/types.js';
|
|
5
|
-
import { create, extract } from '../src/core/metadata/encrypted-metadata.js';
|
|
6
|
-
import { CID } from 'multiformats';
|
|
7
|
-
/** @type {Types.LitMetadataInput} */
|
|
8
|
-
const encryptedMetadataInput = {
|
|
9
|
-
encryptedDataCID: 'bafkreids275u5ex6xfw7d4k67afej43c6rhm2kzdox2z6or4jxrndgevae',
|
|
10
|
-
identityBoundCiphertext: 'mF3OPa9dQ0wO4B1/XylmAV/eaHhLtM3JUPIbS175bvmqGaJUYroyDbsytV29q0cLD4XCpCRfCinntASNg9s730FIM7f4Mw2hVWeJ5g4akFA6BoZoaKgDC5Ln6MOQK5Ymb1y6No7um7Bn4uIIJTYNuUukDQvVxzY8LcRBc2ySR1Md+VSGzmyEgyvHtAI=',
|
|
11
|
-
plaintextKeyHash: '15f39e9a977cca43f16f3cd25237d711cd8130ff9763197b29df52a198607206',
|
|
12
|
-
accessControlConditions: [
|
|
13
|
-
{
|
|
14
|
-
contractAddress: '',
|
|
15
|
-
standardContractType: '',
|
|
16
|
-
chain: 'ethereum',
|
|
17
|
-
method: '',
|
|
18
|
-
parameters: [
|
|
19
|
-
':currentActionIpfsId',
|
|
20
|
-
'did:key:z6MktfnQz8Kcz5nsC65oyXWFXhbbAZQavjg6LYuHgv4YbxzN',
|
|
21
|
-
],
|
|
22
|
-
returnValueTest: {
|
|
23
|
-
comparator: '=',
|
|
24
|
-
value: 'QmPFrQGo5RAtdSTZ4bkaeDHVGrmy2TeEUwTu4LuVAPHiMd',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
};
|
|
29
|
-
/** @type {Types.KMSMetadata} */
|
|
30
|
-
const kmsMetadataInput = {
|
|
31
|
-
encryptedDataCID: CID.parse('bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'),
|
|
32
|
-
encryptedSymmetricKey: 'bXlLTVNLZXlCeXRlcw==', // 'myKMSKeyBytes' in base64 for example
|
|
33
|
-
space: 'did:key:z6MktfnQz8Kcz5nsC65oyXWFXhbbAZQavjg6LYuHgv4YbxzN',
|
|
34
|
-
kms: {
|
|
35
|
-
provider: 'google-kms',
|
|
36
|
-
keyId: 'test-key',
|
|
37
|
-
algorithm: 'RSA-OAEP-2048-SHA256',
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
await describe('LitEncrypted Metadata', async () => {
|
|
41
|
-
await it('should create a valid block content', async () => {
|
|
42
|
-
const encryptedMetadata = create('lit', encryptedMetadataInput);
|
|
43
|
-
const block = await encryptedMetadata.archiveBlock();
|
|
44
|
-
// Encode the block into a CAR file
|
|
45
|
-
const car = await import('@ucanto/core').then((m) => m.CAR.encode({ roots: [block] }));
|
|
46
|
-
// Use the extract function to get the JSON object
|
|
47
|
-
const extractedData = Result.unwrap(extract(car));
|
|
48
|
-
const extractedDataJson = extractedData.toJSON();
|
|
49
|
-
assert.equal(extractedDataJson.identityBoundCiphertext, encryptedMetadataInput.identityBoundCiphertext);
|
|
50
|
-
assert.equal(extractedDataJson.plaintextKeyHash, encryptedMetadataInput.plaintextKeyHash);
|
|
51
|
-
assert.equal(extractedDataJson.encryptedDataCID, encryptedMetadataInput.encryptedDataCID);
|
|
52
|
-
assert.deepEqual(extractedDataJson.accessControlConditions, encryptedMetadataInput.accessControlConditions);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
await describe('KMS Encrypted Metadata', async () => {
|
|
56
|
-
await it('should create a valid block content', async () => {
|
|
57
|
-
const kmsMetadata = create('kms', kmsMetadataInput);
|
|
58
|
-
const block = await kmsMetadata.archiveBlock();
|
|
59
|
-
const car = await import('@ucanto/core').then((m) => m.CAR.encode({ roots: [block] }));
|
|
60
|
-
const extractedData = Result.unwrap(extract(car));
|
|
61
|
-
const extractedDataJson = extractedData.toJSON();
|
|
62
|
-
assert.equal(extractedDataJson.encryptedSymmetricKey, kmsMetadataInput.encryptedSymmetricKey);
|
|
63
|
-
assert.equal(extractedDataJson.encryptedDataCID, kmsMetadataInput.encryptedDataCID);
|
|
64
|
-
assert.equal(extractedDataJson.space, kmsMetadataInput.space);
|
|
65
|
-
assert.deepEqual(extractedDataJson.kms, kmsMetadataInput.kms);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
//# sourceMappingURL=encrypted-metadata.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factories.spec.d.ts","sourceRoot":"","sources":["../../test/factories.spec.js"],"names":[],"mappings":""}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import './setup.js';
|
|
2
|
-
import { test, describe } from 'node:test';
|
|
3
|
-
import assert from 'node:assert';
|
|
4
|
-
import { createGenericKMSAdapter, createGenericLitAdapter, createNodeLitAdapter, } from '../src/crypto/factories.node.js';
|
|
5
|
-
import { GenericAesCtrStreamingCrypto } from '../src/crypto/symmetric/generic-aes-ctr-streaming-crypto.js';
|
|
6
|
-
import { NodeAesCbcCrypto } from '../src/crypto/symmetric/node-aes-cbc-crypto.js';
|
|
7
|
-
import { LitCryptoAdapter } from '../src/crypto/adapters/lit-crypto-adapter.js';
|
|
8
|
-
import { KMSCryptoAdapter } from '../src/crypto/adapters/kms-crypto-adapter.js';
|
|
9
|
-
// Mock Lit client for testing
|
|
10
|
-
const mockLitClient = /** @type {any} */ ({
|
|
11
|
-
connect: () => Promise.resolve(),
|
|
12
|
-
disconnect: () => Promise.resolve(),
|
|
13
|
-
});
|
|
14
|
-
await describe('Crypto Factory Functions', async () => {
|
|
15
|
-
await describe('createBrowserLitAdapter', async () => {
|
|
16
|
-
await test('should create LitCryptoAdapter with streaming crypto', async () => {
|
|
17
|
-
const adapter = createGenericLitAdapter(mockLitClient);
|
|
18
|
-
// Verify adapter type
|
|
19
|
-
assert(adapter instanceof LitCryptoAdapter, 'Should create LitCryptoAdapter instance');
|
|
20
|
-
// Verify symmetric crypto implementation
|
|
21
|
-
assert(adapter.symmetricCrypto instanceof GenericAesCtrStreamingCrypto, 'Should use GenericAesCtrStreamingCrypto for browser environment');
|
|
22
|
-
// Verify lit client is passed through
|
|
23
|
-
assert.strictEqual(adapter.litClient, mockLitClient, 'Should pass through the lit client');
|
|
24
|
-
});
|
|
25
|
-
await test('should create adapter with required interface methods', async () => {
|
|
26
|
-
const adapter = createGenericLitAdapter(mockLitClient);
|
|
27
|
-
// Verify adapter has all required methods
|
|
28
|
-
assert(typeof adapter.encryptStream === 'function', 'Should have encryptStream method');
|
|
29
|
-
assert(typeof adapter.decryptStream === 'function', 'Should have decryptStream method');
|
|
30
|
-
assert(typeof adapter.encryptSymmetricKey === 'function', 'Should have encryptSymmetricKey method');
|
|
31
|
-
assert(typeof adapter.decryptSymmetricKey === 'function', 'Should have decryptSymmetricKey method');
|
|
32
|
-
assert(typeof adapter.extractEncryptedMetadata === 'function', 'Should have extractEncryptedMetadata method');
|
|
33
|
-
assert(typeof adapter.getEncryptedKey === 'function', 'Should have getEncryptedKey method');
|
|
34
|
-
});
|
|
35
|
-
await test('should handle null or undefined lit client gracefully', async () => {
|
|
36
|
-
// This should still create the adapter (validation happens at runtime)
|
|
37
|
-
const adapter = createGenericLitAdapter(/** @type {any} */ (null));
|
|
38
|
-
assert(adapter instanceof LitCryptoAdapter, 'Should create adapter even with null client');
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
await describe('createNodeLitAdapter', async () => {
|
|
42
|
-
await test('should create LitCryptoAdapter with Node crypto', async () => {
|
|
43
|
-
const adapter = createNodeLitAdapter(mockLitClient);
|
|
44
|
-
// Verify adapter type
|
|
45
|
-
assert(adapter instanceof LitCryptoAdapter, 'Should create LitCryptoAdapter instance');
|
|
46
|
-
// Verify symmetric crypto implementation
|
|
47
|
-
assert(adapter.symmetricCrypto instanceof NodeAesCbcCrypto, 'Should use NodeAesCbcCrypto for Node.js environment');
|
|
48
|
-
// Verify lit client is passed through
|
|
49
|
-
assert.strictEqual(adapter.litClient, mockLitClient, 'Should pass through the lit client');
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
await describe('createBrowserKMSAdapter', async () => {
|
|
53
|
-
await test('should create KMSCryptoAdapter with streaming crypto', async () => {
|
|
54
|
-
const keyManagerServiceURL = 'https://gateway.example.com';
|
|
55
|
-
const keyManagerServiceDID = 'did:web:gateway.example.com';
|
|
56
|
-
const adapter = createGenericKMSAdapter(keyManagerServiceURL, keyManagerServiceDID);
|
|
57
|
-
// Verify adapter type
|
|
58
|
-
assert(adapter instanceof KMSCryptoAdapter, 'Should create KMSCryptoAdapter instance');
|
|
59
|
-
// Verify symmetric crypto implementation
|
|
60
|
-
assert(adapter.symmetricCrypto instanceof GenericAesCtrStreamingCrypto, 'Should use GenericAesCtrStreamingCrypto for browser environment');
|
|
61
|
-
// Verify configuration is passed through
|
|
62
|
-
assert.strictEqual(adapter.keyManagerServiceURL.toString(), keyManagerServiceURL + '/', 'Should set the key manager service URL');
|
|
63
|
-
assert.strictEqual(adapter.keyManagerServiceDID.did(), keyManagerServiceDID, 'Should set the key manager service DID');
|
|
64
|
-
});
|
|
65
|
-
await test('should accept URL object for gateway URL', async () => {
|
|
66
|
-
const keyManagerServiceURL = new URL('https://gateway.example.com');
|
|
67
|
-
const keyManagerServiceDID = 'did:web:gateway.example.com';
|
|
68
|
-
const adapter = createGenericKMSAdapter(keyManagerServiceURL, keyManagerServiceDID);
|
|
69
|
-
assert(adapter instanceof KMSCryptoAdapter, 'Should create KMSCryptoAdapter with URL object');
|
|
70
|
-
assert.strictEqual(adapter.keyManagerServiceURL.toString(), keyManagerServiceURL.toString(), 'Should handle URL object input');
|
|
71
|
-
});
|
|
72
|
-
await test('should enforce HTTPS for security', async () => {
|
|
73
|
-
const httpKeyManagerServiceURL = 'http://insecure.example.com';
|
|
74
|
-
const keyManagerServiceDID = 'did:web:example.com';
|
|
75
|
-
assert.throws(() => createGenericKMSAdapter(httpKeyManagerServiceURL, keyManagerServiceDID), /Key manager service must use HTTPS protocol for security/, 'Should reject HTTP URLs for security');
|
|
76
|
-
});
|
|
77
|
-
await test('should allow HTTP with explicit insecure option', async () => {
|
|
78
|
-
// Note: The current implementation doesn't expose options in the factory
|
|
79
|
-
// but we can test this through direct adapter construction
|
|
80
|
-
const httpKeyManagerServiceURL = 'http://localhost:3000';
|
|
81
|
-
const keyManagerServiceDID = 'did:web:localhost';
|
|
82
|
-
assert.throws(() => createGenericKMSAdapter(httpKeyManagerServiceURL, keyManagerServiceDID), /Key manager service must use HTTPS protocol for security/, 'Should reject HTTP URLs even for localhost by default');
|
|
83
|
-
});
|
|
84
|
-
await test('should have all required KMS adapter methods', async () => {
|
|
85
|
-
const adapter = createGenericKMSAdapter('https://gateway.example.com', 'did:web:gateway.example.com');
|
|
86
|
-
// Verify adapter has all required methods
|
|
87
|
-
assert(typeof adapter.encryptStream === 'function', 'Should have encryptStream method');
|
|
88
|
-
assert(typeof adapter.decryptStream === 'function', 'Should have decryptStream method');
|
|
89
|
-
assert(typeof adapter.encryptSymmetricKey === 'function', 'Should have encryptSymmetricKey method');
|
|
90
|
-
assert(typeof adapter.decryptSymmetricKey === 'function', 'Should have decryptSymmetricKey method');
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
await describe('Factory Function Consistency', async () => {
|
|
94
|
-
await test('browser factories should use streaming crypto', async () => {
|
|
95
|
-
const litAdapter = createGenericLitAdapter(mockLitClient);
|
|
96
|
-
const kmsAdapter = createGenericKMSAdapter('https://gateway.example.com', 'did:web:gateway.example.com');
|
|
97
|
-
assert(litAdapter.symmetricCrypto.constructor.name ===
|
|
98
|
-
'GenericAesCtrStreamingCrypto', 'Browser Lit adapter should use streaming crypto');
|
|
99
|
-
assert(kmsAdapter.symmetricCrypto.constructor.name ===
|
|
100
|
-
'GenericAesCtrStreamingCrypto', 'Browser KMS adapter should use streaming crypto');
|
|
101
|
-
});
|
|
102
|
-
await test('node factories should use Node crypto', async () => {
|
|
103
|
-
const litAdapter = createNodeLitAdapter(mockLitClient);
|
|
104
|
-
assert(litAdapter.symmetricCrypto.constructor.name === 'NodeAesCbcCrypto', 'Node Lit adapter should use Node crypto');
|
|
105
|
-
});
|
|
106
|
-
await test('all adapters should implement the same interface', async () => {
|
|
107
|
-
const adapters = [
|
|
108
|
-
createGenericLitAdapter(mockLitClient),
|
|
109
|
-
createNodeLitAdapter(mockLitClient),
|
|
110
|
-
createGenericKMSAdapter('https://gateway.example.com', 'did:web:gateway.example.com'),
|
|
111
|
-
createGenericKMSAdapter('https://gateway.example.com', 'did:web:gateway.example.com'),
|
|
112
|
-
];
|
|
113
|
-
const requiredMethods = [
|
|
114
|
-
'encryptStream',
|
|
115
|
-
'decryptStream',
|
|
116
|
-
'encryptSymmetricKey',
|
|
117
|
-
'decryptSymmetricKey',
|
|
118
|
-
'extractEncryptedMetadata',
|
|
119
|
-
'getEncryptedKey',
|
|
120
|
-
];
|
|
121
|
-
for (const adapter of adapters) {
|
|
122
|
-
for (const method of requiredMethods) {
|
|
123
|
-
assert(typeof ( /** @type {any} */(adapter)[method]) === 'function', `${adapter.constructor.name} should have ${method} method`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
await describe('Memory Usage Verification', async () => {
|
|
129
|
-
await test('browser adapters should use memory-efficient streaming crypto', async () => {
|
|
130
|
-
const litAdapter = createGenericLitAdapter(mockLitClient);
|
|
131
|
-
const kmsAdapter = createGenericKMSAdapter('https://gateway.example.com', 'did:web:gateway.example.com');
|
|
132
|
-
// Verify both use the streaming implementation
|
|
133
|
-
assert(litAdapter.symmetricCrypto instanceof GenericAesCtrStreamingCrypto, 'Lit adapter should use streaming crypto for memory efficiency');
|
|
134
|
-
assert(kmsAdapter.symmetricCrypto instanceof GenericAesCtrStreamingCrypto, 'KMS adapter should use streaming crypto for memory efficiency');
|
|
135
|
-
// Verify they have the streaming characteristics
|
|
136
|
-
const testBlob = new Blob([new Uint8Array(1024)]); // 1KB test
|
|
137
|
-
const litResult = await litAdapter.encryptStream(testBlob);
|
|
138
|
-
assert(litResult.encryptedStream instanceof ReadableStream, 'Should return ReadableStream for streaming');
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
//# sourceMappingURL=factories.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-metadata.spec.d.ts","sourceRoot":"","sources":["../../test/file-metadata.spec.js"],"names":[],"mappings":""}
|