@storacha/encrypt-upload-client 1.1.76-rc.1 → 1.1.76-rc.2
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/core/metadata/encrypted-metadata.d.ts +12 -13
- package/dist/core/metadata/encrypted-metadata.d.ts.map +1 -1
- package/dist/core/metadata/encrypted-metadata.js +16 -3
- package/dist/crypto/adapters/kms-crypto-adapter.d.ts +13 -0
- package/dist/crypto/adapters/kms-crypto-adapter.d.ts.map +1 -1
- package/dist/crypto/adapters/kms-crypto-adapter.js +18 -3
- package/dist/crypto/adapters/lit-crypto-adapter.d.ts +13 -0
- package/dist/crypto/adapters/lit-crypto-adapter.d.ts.map +1 -1
- package/dist/crypto/adapters/lit-crypto-adapter.js +15 -1
- package/dist/handlers/decrypt-handler.d.ts +4 -29
- package/dist/handlers/decrypt-handler.d.ts.map +1 -1
- package/dist/handlers/decrypt-handler.js +5 -85
- package/dist/tsconfig.spec.tsbuildinfo +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/decrypt.d.ts +24 -0
- package/dist/utils/decrypt.d.ts.map +1 -0
- package/dist/utils/decrypt.js +108 -0
- package/package.json +7 -3
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
export function extract(archive: Uint8Array): any
|
|
2
|
-
export function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
):
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import * as
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=encrypted-metadata.d.ts.map
|
|
1
|
+
export function extract(archive: Uint8Array): Types.Result<any>;
|
|
2
|
+
export function view({ root }: {
|
|
3
|
+
root: Types.IPLDBlock;
|
|
4
|
+
}): Types.Result<any>;
|
|
5
|
+
export function create(strategy: "lit" | "kms", data: any): Types.LitMetadataView | Types.KMSMetadataView;
|
|
6
|
+
export function getSupportedVersions(): string[];
|
|
7
|
+
export function isVersionSupported(version: string): boolean;
|
|
8
|
+
import type * as Types from '../../types.js';
|
|
9
|
+
import * as LitMetadata from './lit-metadata.js';
|
|
10
|
+
import * as KMSMetadata from './kms-metadata.js';
|
|
11
|
+
export { LitMetadata, KMSMetadata };
|
|
12
|
+
//# sourceMappingURL=encrypted-metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypted-metadata.d.ts","sourceRoot":"","sources":["../../../src/core/metadata/encrypted-metadata.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encrypted-metadata.d.ts","sourceRoot":"","sources":["../../../src/core/metadata/encrypted-metadata.js"],"names":[],"mappings":"AA2BO,iCAHI,UAAU,GACR,aAAa,GAAG,CAAC,CAkB7B;AASM,+BAHJ;IAAgC,IAAI,EAA5B,eAAe;CACvB,GAAU,aAAa,GAAG,CAAC,CAgB7B;AAQM,iCAHI,KAAK,GAAG,KAAK,QACb,GAAG,iDAWb;AAKM,iDAAuD;AAOvD,4CAFI,MAAM,WAEgD;4BAlFtC,gBAAgB;6BAPd,mBAAmB;6BACnB,mBAAmB"}
|
|
@@ -8,6 +8,9 @@ import * as KMSMetadata from './kms-metadata.js';
|
|
|
8
8
|
import { CAR, error } from '@ucanto/core';
|
|
9
9
|
import * as dagCBOR from '@ipld/dag-cbor';
|
|
10
10
|
import { UnknownFormat } from '../errors.js';
|
|
11
|
+
/**
|
|
12
|
+
* @import * as Types from '../../types.js'
|
|
13
|
+
*/
|
|
11
14
|
const FORMATS = {
|
|
12
15
|
[LitMetadata.version]: LitMetadata, // 'encrypted-metadata@0.1'
|
|
13
16
|
[KMSMetadata.version]: KMSMetadata, // 'encrypted-metadata@0.2'
|
|
@@ -16,7 +19,7 @@ const FORMATS = {
|
|
|
16
19
|
* Universal extract function - tries each registered format
|
|
17
20
|
*
|
|
18
21
|
* @param {Uint8Array} archive
|
|
19
|
-
* @returns {any}
|
|
22
|
+
* @returns {Types.Result<any>}
|
|
20
23
|
*/
|
|
21
24
|
export const extract = (archive) => {
|
|
22
25
|
// Decode CAR to check version
|
|
@@ -28,12 +31,22 @@ export const extract = (archive) => {
|
|
|
28
31
|
if (code !== dagCBOR.code) {
|
|
29
32
|
return error(new UnknownFormat(`unexpected root CID codec: 0x${code.toString(16)}`));
|
|
30
33
|
}
|
|
34
|
+
return view({ root: roots[0] });
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Universal view function - tries each registered format
|
|
38
|
+
*
|
|
39
|
+
* @param {object} source
|
|
40
|
+
* @param {Types.IPLDBlock} source.root
|
|
41
|
+
* @returns {Types.Result<any>}
|
|
42
|
+
*/
|
|
43
|
+
export const view = ({ root }) => {
|
|
31
44
|
// Check which version this metadata uses
|
|
32
|
-
const value = dagCBOR.decode(
|
|
45
|
+
const value = dagCBOR.decode(root.bytes);
|
|
33
46
|
for (const [version, formatModule] of Object.entries(FORMATS)) {
|
|
34
47
|
if (value && typeof value === 'object' && version in value) {
|
|
35
48
|
// Found matching version, delegate to specific format module
|
|
36
|
-
return formatModule.
|
|
49
|
+
return formatModule.view({ root });
|
|
37
50
|
}
|
|
38
51
|
}
|
|
39
52
|
return error(new UnknownFormat('Unknown metadata format - no matching version found'));
|
|
@@ -91,6 +91,19 @@ export class KMSCryptoAdapter implements Type.CryptoAdapter {
|
|
|
91
91
|
* @returns {Type.ExtractedMetadata}
|
|
92
92
|
*/
|
|
93
93
|
extractEncryptedMetadata(car: Uint8Array): Type.ExtractedMetadata;
|
|
94
|
+
/**
|
|
95
|
+
* @param {object} source
|
|
96
|
+
* @param {Type.IPLDBlock} source.root
|
|
97
|
+
*/
|
|
98
|
+
viewEncryptedMetadata({ root }: {
|
|
99
|
+
root: Type.IPLDBlock;
|
|
100
|
+
}): Type.ExtractedMetadata;
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* @param {Type.Result<any>} kmsContentResult
|
|
104
|
+
* @returns {Type.ExtractedMetadata}
|
|
105
|
+
*/
|
|
106
|
+
_validateKMSMetadata(kmsContentResult: Type.Result<any>): Type.ExtractedMetadata;
|
|
94
107
|
/**
|
|
95
108
|
* @param {Type.ExtractedMetadata} metadata
|
|
96
109
|
* @returns {string}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kms-crypto-adapter.d.ts","sourceRoot":"","sources":["../../../src/crypto/adapters/kms-crypto-adapter.js"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,yCAFgB,IAAI,CAAC,aAAa;IAMhC;;;;;;;;OAQG;IACH,6BANW,IAAI,CAAC,eAAe,wBACpB,GAAG,GAAC,MAAM,wBACV,OAAO,MAAM,IAAI,MAAM,EAAE,YAEjC;QAA0B,iBAAiB;KAC7C,EA0BA;IArCD,6FAA6F;IAC7F,mBADW,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAC5D;IAiB3B,sCAAsC;IAiBtC,0BAA+B;IAC/B,wFAA2D;IAG7D;;;;OAIG;IACH,oBAFW,IAAI,CAAC,QAAQ,+BAIvB;IAED;;;;;;OAMG;IACH,6BAJW,cAAc,OACd,UAAU,MACV,UAAU,gCAIpB;IAED;;;;;;;OAOG;IACH,yBALW,UAAU,MACV,UAAU,oBACV,IAAI,CAAC,gBAAgB,GACnB,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CA4B5C;IAED;;;;;;;;OAQG;IACH,kCARW,MAAM,WAEd;QAAuC,gBAAgB,EAA/C,IAAI,CAAC,gBAAgB;QACW,QAAQ,EAAxC,IAAI,CAAC,iBAAiB;QACA,WAAW,EAAjC,IAAI,CAAC,OAAO;QACoH,MAAM,EAAtI,OAAO,wBAAwB,EAAE,MAAM,CAAC,OAAO,wBAAwB,EAAE,GAAG,EAAE,OAAO,wBAAwB,EAAE,MAAM,CAAC;QACxE,QAAQ,EA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C,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAsC/E;IAED;;;;OAIG;IACH,mBAFa,YAAY,CAWxB;IAED;;;;;;OAMG;IACH,8BAJW,UAAU,gBACV,MAAM,GACJ,OAAO,CAAC,UAAU,CAAC,CAyB/B;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,WAAW,CA6BvB;IAED,kFASC;IAED;;;;;OAKG;IACH,sCAHW,IAAI,CAAC,QAAQ,GACX,MAAM,CAIlB;CACF;sBAtbqB,gBAAgB"}
|
|
@@ -3,7 +3,7 @@ import { CAR, HTTP } from '@ucanto/transport';
|
|
|
3
3
|
import { base64 } from 'multiformats/bases/base64';
|
|
4
4
|
import * as Type from '../../types.js';
|
|
5
5
|
import { EncryptionSetup, EncryptionKeyDecrypt, } from '@storacha/capabilities/space';
|
|
6
|
-
import
|
|
6
|
+
import * as EncryptedMetadata from '../../core/metadata/encrypted-metadata.js';
|
|
7
7
|
import * as DID from '@ipld/dag-ucan/did';
|
|
8
8
|
/**
|
|
9
9
|
* KMSCryptoAdapter implements the complete CryptoAdapter interface using KMS.
|
|
@@ -155,7 +155,22 @@ export class KMSCryptoAdapter {
|
|
|
155
155
|
* @returns {Type.ExtractedMetadata}
|
|
156
156
|
*/
|
|
157
157
|
extractEncryptedMetadata(car) {
|
|
158
|
-
const kmsContentResult =
|
|
158
|
+
const kmsContentResult = EncryptedMetadata.extract(car);
|
|
159
|
+
return this._validateKMSMetadata(kmsContentResult);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @param {object} source
|
|
163
|
+
* @param {Type.IPLDBlock} source.root
|
|
164
|
+
*/
|
|
165
|
+
viewEncryptedMetadata({ root }) {
|
|
166
|
+
return this._validateKMSMetadata(EncryptedMetadata.view({ root }));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* @param {Type.Result<any>} kmsContentResult
|
|
171
|
+
* @returns {Type.ExtractedMetadata}
|
|
172
|
+
*/
|
|
173
|
+
_validateKMSMetadata(kmsContentResult) {
|
|
159
174
|
if (kmsContentResult.error) {
|
|
160
175
|
throw kmsContentResult.error;
|
|
161
176
|
}
|
|
@@ -213,7 +228,7 @@ export class KMSCryptoAdapter {
|
|
|
213
228
|
algorithm: kmsKeyMetadata.kms.algorithm,
|
|
214
229
|
},
|
|
215
230
|
};
|
|
216
|
-
const kmsMetadata =
|
|
231
|
+
const kmsMetadata = EncryptedMetadata.create('kms', uploadData);
|
|
217
232
|
return await kmsMetadata.archiveBlock();
|
|
218
233
|
}
|
|
219
234
|
/**
|
|
@@ -103,6 +103,19 @@ export class LitCryptoAdapter implements Type.CryptoAdapter {
|
|
|
103
103
|
* @returns {Type.ExtractedMetadata} - The extracted metadata
|
|
104
104
|
*/
|
|
105
105
|
extractEncryptedMetadata(car: Uint8Array): Type.ExtractedMetadata;
|
|
106
|
+
/**
|
|
107
|
+
* @param {object} source
|
|
108
|
+
* @param {Type.IPLDBlock} source.root
|
|
109
|
+
*/
|
|
110
|
+
viewEncryptedMetadata({ root }: {
|
|
111
|
+
root: Type.IPLDBlock;
|
|
112
|
+
}): Type.ExtractedMetadata;
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @param {Type.Result<any>} encryptedContentResult
|
|
116
|
+
* @returns {Type.ExtractedMetadata}
|
|
117
|
+
*/
|
|
118
|
+
_validateLitMetadata(encryptedContentResult: Type.Result<any>): Type.ExtractedMetadata;
|
|
106
119
|
/**
|
|
107
120
|
* Get the encrypted key from the metadata
|
|
108
121
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lit-crypto-adapter.d.ts","sourceRoot":"","sources":["../../../src/crypto/adapters/lit-crypto-adapter.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,yCAFgB,IAAI,CAAC,aAAa;IAGhC;;;;;;OAMG;IACH,6BAJW,IAAI,CAAC,eAAe,aACpB,OAAO,0BAA0B,EAAE,aAAa,eAChD,IAAI,CAAC,W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GACjB,OAAO,CAAC;QAAE,GAAG,EAAE,OAAO,+BAA+B,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,CAAC,CAehG;CACF;sBAtQqB,gBAAgB"}
|
|
@@ -152,7 +152,21 @@ export class LitCryptoAdapter {
|
|
|
152
152
|
* @returns {Type.ExtractedMetadata} - The extracted metadata
|
|
153
153
|
*/
|
|
154
154
|
extractEncryptedMetadata(car) {
|
|
155
|
-
|
|
155
|
+
return this._validateLitMetadata(EncryptedMetadata.extract(car));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @param {object} source
|
|
159
|
+
* @param {Type.IPLDBlock} source.root
|
|
160
|
+
*/
|
|
161
|
+
viewEncryptedMetadata({ root }) {
|
|
162
|
+
return this._validateLitMetadata(EncryptedMetadata.view({ root }));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
*
|
|
166
|
+
* @param {Type.Result<any>} encryptedContentResult
|
|
167
|
+
* @returns {Type.ExtractedMetadata}
|
|
168
|
+
*/
|
|
169
|
+
_validateLitMetadata(encryptedContentResult) {
|
|
156
170
|
if (encryptedContentResult.error) {
|
|
157
171
|
throw encryptedContentResult.error;
|
|
158
172
|
}
|
|
@@ -1,29 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
* encryption and decryption operations.
|
|
6
|
-
* @param {Uint8Array} key - The symmetric key
|
|
7
|
-
* @param {Uint8Array} iv - The initialization vector
|
|
8
|
-
* @param {AsyncIterable<Uint8Array>|Uint8Array} content - The encrypted file content
|
|
9
|
-
* @returns {Promise<ReadableStream>} The decrypted file stream
|
|
10
|
-
*/
|
|
11
|
-
export function decryptFileWithKey(
|
|
12
|
-
cryptoAdapter: Type.CryptoAdapter,
|
|
13
|
-
key: Uint8Array,
|
|
14
|
-
iv: Uint8Array,
|
|
15
|
-
content: AsyncIterable<Uint8Array> | Uint8Array
|
|
16
|
-
): Promise<ReadableStream>
|
|
17
|
-
export function retrieveAndDecrypt(
|
|
18
|
-
storachaClient: import('@storacha/client').Client,
|
|
19
|
-
cryptoAdapter: Type.CryptoAdapter,
|
|
20
|
-
gatewayURL: URL,
|
|
21
|
-
cid: Type.AnyLink,
|
|
22
|
-
decryptionConfig: Type.DecryptionConfig
|
|
23
|
-
): Promise<Type.DecryptionResult>
|
|
24
|
-
export function getCarFileFromPublicGateway(
|
|
25
|
-
gatewayURL: URL,
|
|
26
|
-
cid: string
|
|
27
|
-
): Promise<Uint8Array>
|
|
28
|
-
import * as Type from '../types.js'
|
|
29
|
-
//# sourceMappingURL=decrypt-handler.d.ts.map
|
|
1
|
+
export function retrieveAndDecrypt(storachaClient: import("@storacha/client").Client, cryptoAdapter: Type.CryptoAdapter, gatewayURL: URL, cid: Type.AnyLink, decryptionConfig: Type.DecryptionConfig): Promise<Type.DecryptionResult>;
|
|
2
|
+
export function getCarFileFromPublicGateway(gatewayURL: URL, cid: string): Promise<Uint8Array>;
|
|
3
|
+
import * as Type from '../types.js';
|
|
4
|
+
//# sourceMappingURL=decrypt-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/decrypt-handler.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decrypt-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/decrypt-handler.js"],"names":[],"mappings":"AAkBO,mDARI,OAAO,kBAAkB,EAAE,MAAM,iBACjC,IAAI,CAAC,aAAa,cAElB,GAAG,OACH,IAAI,CAAC,OAAO,oBACZ,IAAI,CAAC,gBAAgB,GACnB,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CA2B1C;AAaM,wDAJI,GAAG,OACH,MAAM,GACJ,OAAO,CAAC,UAAU,CAAC,CA+B/B;sBAjFqB,aAAa"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { CID } from 'multiformats';
|
|
2
2
|
import { CarIndexer, CarReader } from '@ipld/car';
|
|
3
|
-
import { exporter } from 'ipfs-unixfs-exporter';
|
|
4
3
|
import { MemoryBlockstore } from 'blockstore-core';
|
|
5
4
|
import * as Type from '../types.js';
|
|
6
|
-
import {
|
|
5
|
+
import { decryptFile } from '../utils/decrypt.js';
|
|
7
6
|
/**
|
|
8
7
|
* Retrieve and decrypt a file from the IPFS gateway using any supported encryption strategy.
|
|
9
8
|
*
|
|
@@ -18,84 +17,9 @@ import { extractFileMetadata } from '../utils/file-metadata.js';
|
|
|
18
17
|
export const retrieveAndDecrypt = async (storachaClient, cryptoAdapter, gatewayURL, cid, decryptionConfig) => {
|
|
19
18
|
// Step 1: Get the encrypted metadata from the public gateway
|
|
20
19
|
const encryptedMetadataCar = await getCarFileFromPublicGateway(gatewayURL, cid.toString());
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Step 3: Get the encrypted data from the CAR file
|
|
24
|
-
const encryptedData = await getEncryptedDataFromCar(encryptedMetadataCar, metadata.encryptedDataCID);
|
|
25
|
-
// Step 4: Decrypt the encrypted symmetric key
|
|
26
|
-
const encryptedSymmetricKey = cryptoAdapter.getEncryptedKey(metadata);
|
|
27
|
-
const { key, iv } = await cryptoAdapter.decryptSymmetricKey(encryptedSymmetricKey, {
|
|
28
|
-
decryptionConfig,
|
|
29
|
-
metadata,
|
|
30
|
-
resourceCID: cid,
|
|
31
|
-
issuer: storachaClient.agent.issuer,
|
|
32
|
-
audience: storachaClient.defaultProvider(),
|
|
33
|
-
});
|
|
34
|
-
// Step 5: Decrypt the encrypted file content using the decrypted symmetric key and IV
|
|
35
|
-
const decryptedStreamWithMetadata = await decryptFileWithKey(cryptoAdapter, key, iv, encryptedData);
|
|
36
|
-
// Step 6: Extract file content and metadata
|
|
37
|
-
const { fileStream, fileMetadata } = await extractFileMetadata(decryptedStreamWithMetadata);
|
|
38
|
-
return {
|
|
39
|
-
stream: fileStream,
|
|
40
|
-
fileMetadata,
|
|
41
|
-
};
|
|
20
|
+
const blockstore = await makeBlockstoreForCar(encryptedMetadataCar, cid.toString());
|
|
21
|
+
return decryptFile(cryptoAdapter, storachaClient, blockstore, cid, decryptionConfig);
|
|
42
22
|
};
|
|
43
|
-
/**
|
|
44
|
-
* Decrypt file content using the decrypted symmetric key and IV.
|
|
45
|
-
*
|
|
46
|
-
* @param {Type.CryptoAdapter} cryptoAdapter - The crypto adapter responsible for performing
|
|
47
|
-
* encryption and decryption operations.
|
|
48
|
-
* @param {Uint8Array} key - The symmetric key
|
|
49
|
-
* @param {Uint8Array} iv - The initialization vector
|
|
50
|
-
* @param {AsyncIterable<Uint8Array>|Uint8Array} content - The encrypted file content
|
|
51
|
-
* @returns {Promise<ReadableStream>} The decrypted file stream
|
|
52
|
-
*/
|
|
53
|
-
export async function decryptFileWithKey(cryptoAdapter, key, iv, content) {
|
|
54
|
-
// Convert content to ReadableStream with true on-demand streaming
|
|
55
|
-
/** @type {AsyncIterator<Uint8Array> | null} */
|
|
56
|
-
let iterator = null;
|
|
57
|
-
const contentStream = new ReadableStream({
|
|
58
|
-
start() {
|
|
59
|
-
// Initialize iterator for async iterable (no memory loading here)
|
|
60
|
-
if (!(content instanceof Uint8Array)) {
|
|
61
|
-
iterator = content[Symbol.asyncIterator]();
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
async pull(controller) {
|
|
65
|
-
try {
|
|
66
|
-
if (content instanceof Uint8Array) {
|
|
67
|
-
// Handle single Uint8Array (legacy case)
|
|
68
|
-
controller.enqueue(content);
|
|
69
|
-
controller.close();
|
|
70
|
-
}
|
|
71
|
-
else if (iterator) {
|
|
72
|
-
// Handle async iterable - get next chunk on-demand
|
|
73
|
-
const { value, done } = await iterator.next();
|
|
74
|
-
if (done) {
|
|
75
|
-
controller.close();
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
controller.enqueue(value); // Only load one chunk at a time
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
controller.close();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
controller.error(error);
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
cancel() {
|
|
90
|
-
// Clean up iterator if stream is cancelled
|
|
91
|
-
if (iterator && typeof iterator.return === 'function') {
|
|
92
|
-
void iterator.return();
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
const decryptedStream = await cryptoAdapter.decryptStream(contentStream, key, iv);
|
|
97
|
-
return decryptedStream;
|
|
98
|
-
}
|
|
99
23
|
/**
|
|
100
24
|
* Fetch a CAR file from the public IPFS gateway with root CID verification.
|
|
101
25
|
*
|
|
@@ -131,9 +55,8 @@ export const getCarFileFromPublicGateway = async (gatewayURL, cid) => {
|
|
|
131
55
|
*
|
|
132
56
|
* @param {Uint8Array} car - The CAR file bytes
|
|
133
57
|
* @param {string} encryptedDataCID - The CID of the encrypted data
|
|
134
|
-
* @returns {Promise<Uint8Array>} The encrypted data bytes
|
|
135
58
|
*/
|
|
136
|
-
const
|
|
59
|
+
const makeBlockstoreForCar = async (car, encryptedDataCID) => {
|
|
137
60
|
// Step 1: Index the CAR file for efficient block lookup
|
|
138
61
|
const iterable = await CarIndexer.fromBytes(car);
|
|
139
62
|
const blockIndex = new Map();
|
|
@@ -151,9 +74,6 @@ const getEncryptedDataFromCar = async (car, encryptedDataCID) => {
|
|
|
151
74
|
const bytes = car.subarray(blockOffset, blockOffset + blockLength);
|
|
152
75
|
await blockstore.put(CID.parse(cidStr), bytes);
|
|
153
76
|
}
|
|
154
|
-
|
|
155
|
-
const encryptedDataEntry = await exporter(CID.parse(encryptedDataCID), blockstore);
|
|
156
|
-
// Step 5: Return the async iterable for streaming
|
|
157
|
-
return encryptedDataEntry.content();
|
|
77
|
+
return blockstore;
|
|
158
78
|
};
|
|
159
79
|
//# sourceMappingURL=decrypt-handler.js.map
|