@storacha/encrypt-upload-client 1.1.58 → 1.1.60
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 +3 -4
- package/dist/config/env.d.ts +6 -9
- package/dist/config/service.d.ts +13 -13
- package/dist/core/client.d.ts +41 -54
- package/dist/core/client.js +56 -68
- package/dist/core/errors.d.ts +6 -6
- package/dist/core/metadata/encrypted-metadata.d.ts +8 -13
- package/dist/core/metadata/kms-metadata.d.ts +36 -68
- package/dist/core/metadata/lit-metadata.d.ts +28 -63
- package/dist/crypto/adapters/kms-crypto-adapter.d.ts +137 -172
- package/dist/crypto/adapters/lit-crypto-adapter.d.ts +86 -107
- package/dist/crypto/factories.browser.d.ts +5 -9
- package/dist/crypto/factories.browser.js +7 -15
- package/dist/crypto/factories.node.d.ts +6 -13
- package/dist/crypto/factories.node.js +13 -19
- 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 +54 -58
- package/dist/crypto/symmetric/generic-aes-ctr-streaming-crypto.js +146 -174
- package/dist/crypto/symmetric/node-aes-cbc-crypto.d.ts +32 -36
- package/dist/crypto/symmetric/node-aes-cbc-crypto.js +95 -101
- package/dist/examples/decrypt-test.d.ts +2 -2
- package/dist/examples/decrypt-test.js +69 -78
- package/dist/examples/encrypt-test.d.ts +3 -5
- package/dist/examples/encrypt-test.js +55 -58
- package/dist/handlers/decrypt-handler.d.ts +5 -19
- package/dist/handlers/encrypt-handler.d.ts +3 -9
- package/dist/handlers/encrypt-handler.js +57 -93
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/protocols/lit.d.ts +9 -33
- package/dist/protocols/lit.js +98 -134
- package/dist/test/cid-verification.spec.d.ts +2 -2
- package/dist/test/cid-verification.spec.js +313 -341
- package/dist/test/crypto-compatibility.spec.d.ts +2 -2
- package/dist/test/crypto-compatibility.spec.js +120 -184
- package/dist/test/crypto-counter-security.spec.d.ts +2 -2
- package/dist/test/crypto-counter-security.spec.js +138 -177
- package/dist/test/crypto-streaming.spec.d.ts +2 -2
- package/dist/test/crypto-streaming.spec.js +126 -208
- package/dist/test/encrypted-metadata.spec.d.ts +2 -2
- package/dist/test/encrypted-metadata.spec.js +62 -89
- package/dist/test/factories.spec.d.ts +2 -2
- package/dist/test/factories.spec.js +139 -275
- package/dist/test/file-metadata.spec.d.ts +2 -2
- package/dist/test/file-metadata.spec.js +416 -472
- package/dist/test/fixtures/test-fixtures.d.ts +20 -25
- package/dist/test/fixtures/test-fixtures.js +53 -61
- package/dist/test/helpers/test-file-utils.d.ts +14 -19
- package/dist/test/helpers/test-file-utils.js +76 -78
- package/dist/test/https-enforcement.spec.d.ts +2 -2
- package/dist/test/https-enforcement.spec.js +124 -278
- package/dist/test/kms-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/kms-crypto-adapter.spec.js +304 -473
- package/dist/test/lit-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/lit-crypto-adapter.spec.js +118 -206
- package/dist/test/memory-efficiency.spec.d.ts +2 -2
- package/dist/test/memory-efficiency.spec.js +87 -100
- package/dist/test/mocks/key-manager.d.ts +38 -71
- package/dist/test/mocks/key-manager.js +113 -129
- package/dist/test/node-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/node-crypto-adapter.spec.js +102 -155
- package/dist/test/node-generic-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/node-generic-crypto-adapter.spec.js +94 -134
- package/dist/test/setup.d.ts +2 -2
- package/dist/test/setup.js +9 -8
- package/dist/tsconfig.spec.tsbuildinfo +1 -1
- package/dist/types.d.ts +181 -219
- package/dist/utils/file-metadata.d.ts +13 -19
- package/dist/utils.d.ts +5 -14
- package/package.json +2 -2
|
@@ -2,32 +2,27 @@
|
|
|
2
2
|
* Generate mock RSA key pair for testing that works with Web Crypto API
|
|
3
3
|
*/
|
|
4
4
|
export function generateMockRSAKeyPair(): Promise<{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
keyPair: CryptoKeyPair;
|
|
6
|
+
publicKeyPem: string;
|
|
7
|
+
}>;
|
|
8
8
|
/**
|
|
9
9
|
* Helper to create test fixtures
|
|
10
10
|
*/
|
|
11
11
|
export function createTestFixtures(): Promise<{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
>
|
|
30
|
-
}>
|
|
31
|
-
import { ed25519 } from '@ucanto/principal'
|
|
32
|
-
import * as Server from '@ucanto/server'
|
|
33
|
-
//# sourceMappingURL=test-fixtures.d.ts.map
|
|
12
|
+
keyManagerServiceDID: ed25519.EdSigner;
|
|
13
|
+
spaceDID: `did:key:${string}`;
|
|
14
|
+
spaceSigner: ed25519.EdSigner;
|
|
15
|
+
issuer: ed25519.EdSigner;
|
|
16
|
+
keyPair: CryptoKeyPair;
|
|
17
|
+
publicKeyPem: string;
|
|
18
|
+
delegationProof: Server.API.Delegation<[{
|
|
19
|
+
with: `did:key:${string}`;
|
|
20
|
+
can: "space/encryption/setup";
|
|
21
|
+
}, {
|
|
22
|
+
with: `did:key:${string}`;
|
|
23
|
+
can: "space/encryption/key/decrypt";
|
|
24
|
+
}]>;
|
|
25
|
+
}>;
|
|
26
|
+
import { ed25519 } from '@ucanto/principal';
|
|
27
|
+
import * as Server from '@ucanto/server';
|
|
28
|
+
//# sourceMappingURL=test-fixtures.d.ts.map
|
|
@@ -1,71 +1,63 @@
|
|
|
1
|
-
import * as Server from '@ucanto/server'
|
|
2
|
-
import { ed25519 } from '@ucanto/principal'
|
|
1
|
+
import * as Server from '@ucanto/server';
|
|
2
|
+
import { ed25519 } from '@ucanto/principal';
|
|
3
3
|
/**
|
|
4
4
|
* Generate mock RSA key pair for testing that works with Web Crypto API
|
|
5
5
|
*/
|
|
6
6
|
export async function generateMockRSAKeyPair() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// Format as proper PEM with line breaks every 64 characters like real KMS
|
|
26
|
-
const formattedBase64 =
|
|
27
|
-
base64String.match(/.{1,64}/g)?.join('\n') || base64String
|
|
28
|
-
const publicKeyPem = `-----BEGIN PUBLIC KEY-----\n${formattedBase64}\n-----END PUBLIC KEY-----`
|
|
29
|
-
return {
|
|
30
|
-
keyPair,
|
|
31
|
-
publicKeyPem,
|
|
32
|
-
}
|
|
7
|
+
// Generate key pair using Web Crypto API first
|
|
8
|
+
const keyPair = await globalThis.crypto.subtle.generateKey({
|
|
9
|
+
name: 'RSA-OAEP',
|
|
10
|
+
modulusLength: 2048,
|
|
11
|
+
publicExponent: new Uint8Array([1, 0, 1]),
|
|
12
|
+
hash: 'SHA-256',
|
|
13
|
+
}, true, ['encrypt', 'decrypt']);
|
|
14
|
+
// Export public key to SPKI format (this will work with our adapter)
|
|
15
|
+
const publicKeyBuffer = await globalThis.crypto.subtle.exportKey('spki', keyPair.publicKey);
|
|
16
|
+
// Convert to proper PEM format using standard base64 (not multibase)
|
|
17
|
+
const base64String = Buffer.from(publicKeyBuffer).toString('base64');
|
|
18
|
+
// Format as proper PEM with line breaks every 64 characters like real KMS
|
|
19
|
+
const formattedBase64 = base64String.match(/.{1,64}/g)?.join('\n') || base64String;
|
|
20
|
+
const publicKeyPem = `-----BEGIN PUBLIC KEY-----\n${formattedBase64}\n-----END PUBLIC KEY-----`;
|
|
21
|
+
return {
|
|
22
|
+
keyPair,
|
|
23
|
+
publicKeyPem,
|
|
24
|
+
};
|
|
33
25
|
}
|
|
34
26
|
/**
|
|
35
27
|
* Helper to create test fixtures
|
|
36
28
|
*/
|
|
37
29
|
export async function createTestFixtures() {
|
|
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
|
-
|
|
30
|
+
// Create mock key manager service DID
|
|
31
|
+
const keyManagerServiceDID = await ed25519.generate();
|
|
32
|
+
// Create mock space DID - this will be the issuer
|
|
33
|
+
const spaceSigner = await ed25519.generate();
|
|
34
|
+
const spaceDID = spaceSigner.did();
|
|
35
|
+
// Generate mock RSA key pair
|
|
36
|
+
const { keyPair, publicKeyPem } = await generateMockRSAKeyPair();
|
|
37
|
+
// Create mock delegation proof - space delegates to itself (self-issued)
|
|
38
|
+
const delegationProof = await Server.delegate({
|
|
39
|
+
issuer: spaceSigner,
|
|
40
|
+
audience: spaceSigner, // Self-delegation for testing
|
|
41
|
+
capabilities: [
|
|
42
|
+
{
|
|
43
|
+
with: spaceDID,
|
|
44
|
+
can: 'space/encryption/setup',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
with: spaceDID,
|
|
48
|
+
can: 'space/encryption/key/decrypt',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
expiration: Infinity,
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
keyManagerServiceDID,
|
|
55
|
+
spaceDID,
|
|
56
|
+
spaceSigner,
|
|
57
|
+
issuer: spaceSigner, // Use space signer as issuer
|
|
58
|
+
keyPair,
|
|
59
|
+
publicKeyPem,
|
|
60
|
+
delegationProof,
|
|
61
|
+
};
|
|
70
62
|
}
|
|
71
|
-
//# sourceMappingURL=test-fixtures.js.map
|
|
63
|
+
//# sourceMappingURL=test-fixtures.js.map
|
|
@@ -4,31 +4,31 @@
|
|
|
4
4
|
* @param {number} sizeMB - Size of the test file in megabytes
|
|
5
5
|
* @returns {Blob} A Blob containing test data with predictable patterns
|
|
6
6
|
*/
|
|
7
|
-
export function createTestFile(sizeMB: number): Blob
|
|
7
|
+
export function createTestFile(sizeMB: number): Blob;
|
|
8
8
|
/**
|
|
9
9
|
* Convert ReadableStream to Uint8Array
|
|
10
10
|
*
|
|
11
11
|
* @param {ReadableStream} stream - The stream to convert
|
|
12
12
|
* @returns {Promise<Uint8Array>} The stream content as a Uint8Array
|
|
13
13
|
*/
|
|
14
|
-
export function streamToUint8Array(stream: ReadableStream): Promise<Uint8Array
|
|
14
|
+
export function streamToUint8Array(stream: ReadableStream): Promise<Uint8Array>;
|
|
15
15
|
/**
|
|
16
16
|
* @param {Uint8Array} arr
|
|
17
17
|
* @returns {string}
|
|
18
18
|
*/
|
|
19
|
-
export function uint8ArrayToString(arr: Uint8Array): string
|
|
19
|
+
export function uint8ArrayToString(arr: Uint8Array): string;
|
|
20
20
|
/**
|
|
21
21
|
* @param {string} str
|
|
22
22
|
* @returns {Uint8Array}
|
|
23
23
|
*/
|
|
24
|
-
export function stringToUint8Array(str: string): Uint8Array
|
|
24
|
+
export function stringToUint8Array(str: string): Uint8Array;
|
|
25
25
|
/**
|
|
26
26
|
* Check if an error is a memory-related error (out of heap space, etc.)
|
|
27
27
|
*
|
|
28
28
|
* @param {unknown} error - The error to check
|
|
29
29
|
* @returns {boolean} True if the error appears to be memory-related
|
|
30
30
|
*/
|
|
31
|
-
export function isMemoryError(error: unknown): boolean
|
|
31
|
+
export function isMemoryError(error: unknown): boolean;
|
|
32
32
|
/**
|
|
33
33
|
* Test an encryption operation and expect it might fail with memory errors
|
|
34
34
|
*
|
|
@@ -36,13 +36,10 @@ export function isMemoryError(error: unknown): boolean
|
|
|
36
36
|
* @param {string} operationName - Name of the operation for logging
|
|
37
37
|
* @returns {Promise<{success: boolean, error?: Error}>} Result of the operation
|
|
38
38
|
*/
|
|
39
|
-
export function testEncryptionWithMemoryHandling(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
success: boolean
|
|
44
|
-
error?: Error
|
|
45
|
-
}>
|
|
39
|
+
export function testEncryptionWithMemoryHandling(encryptOperation: Function, operationName: string): Promise<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
error?: Error;
|
|
42
|
+
}>;
|
|
46
43
|
/**
|
|
47
44
|
* Create a CAR file with KMS metadata content
|
|
48
45
|
*
|
|
@@ -50,16 +47,14 @@ export function testEncryptionWithMemoryHandling(
|
|
|
50
47
|
* @returns {Promise<{car: Uint8Array, actualRootCID: import('multiformats').UnknownLink}>}
|
|
51
48
|
*/
|
|
52
49
|
export function createTestCar(content: any): Promise<{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
50
|
+
car: Uint8Array;
|
|
51
|
+
actualRootCID: import("multiformats").UnknownLink;
|
|
52
|
+
}>;
|
|
56
53
|
/**
|
|
57
54
|
* Create a mock BlobLike object for testing
|
|
58
55
|
*
|
|
59
56
|
* @param {Uint8Array} data
|
|
60
57
|
* @returns {import('../../src/types.js').BlobLike}
|
|
61
58
|
*/
|
|
62
|
-
export function createMockBlob(
|
|
63
|
-
|
|
64
|
-
): import('../../src/types.js').BlobLike
|
|
65
|
-
//# sourceMappingURL=test-file-utils.d.ts.map
|
|
59
|
+
export function createMockBlob(data: Uint8Array): import("../../src/types.js").BlobLike;
|
|
60
|
+
//# sourceMappingURL=test-file-utils.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KMSMetadata } from '../../src/core/metadata/encrypted-metadata.js'
|
|
1
|
+
import { KMSMetadata } from '../../src/core/metadata/encrypted-metadata.js';
|
|
2
2
|
/**
|
|
3
3
|
* Create test data with specific patterns for easy verification
|
|
4
4
|
*
|
|
@@ -6,24 +6,24 @@ import { KMSMetadata } from '../../src/core/metadata/encrypted-metadata.js'
|
|
|
6
6
|
* @returns {Blob} A Blob containing test data with predictable patterns
|
|
7
7
|
*/
|
|
8
8
|
export function createTestFile(sizeMB) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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);
|
|
23
25
|
}
|
|
24
|
-
chunks
|
|
25
|
-
}
|
|
26
|
-
return new Blob(chunks, { type: 'application/octet-stream' })
|
|
26
|
+
return new Blob(chunks, { type: 'application/octet-stream' });
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Convert ReadableStream to Uint8Array
|
|
@@ -32,36 +32,37 @@ export function createTestFile(sizeMB) {
|
|
|
32
32
|
* @returns {Promise<Uint8Array>} The stream content as a Uint8Array
|
|
33
33
|
*/
|
|
34
34
|
export async function streamToUint8Array(stream) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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;
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* @param {Uint8Array} arr
|
|
54
55
|
* @returns {string}
|
|
55
56
|
*/
|
|
56
57
|
export function uint8ArrayToString(arr) {
|
|
57
|
-
|
|
58
|
+
return new TextDecoder().decode(arr);
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
61
|
* @param {string} str
|
|
61
62
|
* @returns {Uint8Array}
|
|
62
63
|
*/
|
|
63
64
|
export function stringToUint8Array(str) {
|
|
64
|
-
|
|
65
|
+
return new TextEncoder().encode(str);
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Check if an error is a memory-related error (out of heap space, etc.)
|
|
@@ -70,13 +71,11 @@ export function stringToUint8Array(str) {
|
|
|
70
71
|
* @returns {boolean} True if the error appears to be memory-related
|
|
71
72
|
*/
|
|
72
73
|
export function isMemoryError(error) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
errorMessage.includes('out of memory')
|
|
79
|
-
)
|
|
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'));
|
|
80
79
|
}
|
|
81
80
|
/**
|
|
82
81
|
* Test an encryption operation and expect it might fail with memory errors
|
|
@@ -85,25 +84,24 @@ export function isMemoryError(error) {
|
|
|
85
84
|
* @param {string} operationName - Name of the operation for logging
|
|
86
85
|
* @returns {Promise<{success: boolean, error?: Error}>} Result of the operation
|
|
87
86
|
*/
|
|
88
|
-
export async function testEncryptionWithMemoryHandling(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
}
|
|
105
104
|
}
|
|
106
|
-
}
|
|
107
105
|
}
|
|
108
106
|
/**
|
|
109
107
|
* Create a CAR file with KMS metadata content
|
|
@@ -112,13 +110,13 @@ export async function testEncryptionWithMemoryHandling(
|
|
|
112
110
|
* @returns {Promise<{car: Uint8Array, actualRootCID: import('multiformats').UnknownLink}>}
|
|
113
111
|
*/
|
|
114
112
|
export async function createTestCar(content) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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 };
|
|
122
120
|
}
|
|
123
121
|
/**
|
|
124
122
|
* Create a mock BlobLike object for testing
|
|
@@ -127,15 +125,15 @@ export async function createTestCar(content) {
|
|
|
127
125
|
* @returns {import('../../src/types.js').BlobLike}
|
|
128
126
|
*/
|
|
129
127
|
export function createMockBlob(data) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
return {
|
|
129
|
+
stream() {
|
|
130
|
+
return new ReadableStream({
|
|
131
|
+
start(controller) {
|
|
132
|
+
controller.enqueue(data);
|
|
133
|
+
controller.close();
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
136
|
},
|
|
137
|
-
|
|
138
|
-
},
|
|
139
|
-
}
|
|
137
|
+
};
|
|
140
138
|
}
|
|
141
|
-
//# sourceMappingURL=test-file-utils.js.map
|
|
139
|
+
//# sourceMappingURL=test-file-utils.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {}
|
|
2
|
-
//# sourceMappingURL=https-enforcement.spec.d.ts.map
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=https-enforcement.spec.d.ts.map
|