@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.
Files changed (72) hide show
  1. package/dist/config/constants.d.ts +3 -3
  2. package/dist/config/constants.js +4 -3
  3. package/dist/config/env.d.ts +9 -6
  4. package/dist/config/service.d.ts +13 -13
  5. package/dist/core/client.d.ts +54 -41
  6. package/dist/core/client.js +68 -56
  7. package/dist/core/errors.d.ts +6 -6
  8. package/dist/core/metadata/encrypted-metadata.d.ts +13 -8
  9. package/dist/core/metadata/kms-metadata.d.ts +68 -36
  10. package/dist/core/metadata/lit-metadata.d.ts +63 -28
  11. package/dist/crypto/adapters/kms-crypto-adapter.d.ts +172 -137
  12. package/dist/crypto/adapters/lit-crypto-adapter.d.ts +107 -86
  13. package/dist/crypto/factories.browser.d.ts +9 -5
  14. package/dist/crypto/factories.browser.js +15 -7
  15. package/dist/crypto/factories.node.d.ts +13 -6
  16. package/dist/crypto/factories.node.js +19 -13
  17. package/dist/crypto/index.d.ts +5 -5
  18. package/dist/crypto/index.js +5 -5
  19. package/dist/crypto/symmetric/generic-aes-ctr-streaming-crypto.d.ts +58 -54
  20. package/dist/crypto/symmetric/generic-aes-ctr-streaming-crypto.js +174 -146
  21. package/dist/crypto/symmetric/node-aes-cbc-crypto.d.ts +36 -32
  22. package/dist/crypto/symmetric/node-aes-cbc-crypto.js +101 -95
  23. package/dist/examples/decrypt-test.d.ts +2 -2
  24. package/dist/examples/decrypt-test.js +78 -69
  25. package/dist/examples/encrypt-test.d.ts +5 -3
  26. package/dist/examples/encrypt-test.js +58 -55
  27. package/dist/handlers/decrypt-handler.d.ts +19 -5
  28. package/dist/handlers/encrypt-handler.d.ts +9 -3
  29. package/dist/handlers/encrypt-handler.js +93 -57
  30. package/dist/index.d.ts +2 -2
  31. package/dist/index.js +2 -2
  32. package/dist/protocols/lit.d.ts +33 -9
  33. package/dist/protocols/lit.js +134 -98
  34. package/dist/test/cid-verification.spec.d.ts +2 -2
  35. package/dist/test/cid-verification.spec.js +341 -313
  36. package/dist/test/crypto-compatibility.spec.d.ts +2 -2
  37. package/dist/test/crypto-compatibility.spec.js +184 -120
  38. package/dist/test/crypto-counter-security.spec.d.ts +2 -2
  39. package/dist/test/crypto-counter-security.spec.js +177 -138
  40. package/dist/test/crypto-streaming.spec.d.ts +2 -2
  41. package/dist/test/crypto-streaming.spec.js +208 -126
  42. package/dist/test/encrypted-metadata.spec.d.ts +2 -2
  43. package/dist/test/encrypted-metadata.spec.js +89 -62
  44. package/dist/test/factories.spec.d.ts +2 -2
  45. package/dist/test/factories.spec.js +275 -139
  46. package/dist/test/file-metadata.spec.d.ts +2 -2
  47. package/dist/test/file-metadata.spec.js +472 -416
  48. package/dist/test/fixtures/test-fixtures.d.ts +25 -20
  49. package/dist/test/fixtures/test-fixtures.js +61 -53
  50. package/dist/test/helpers/test-file-utils.d.ts +19 -14
  51. package/dist/test/helpers/test-file-utils.js +78 -76
  52. package/dist/test/https-enforcement.spec.d.ts +2 -2
  53. package/dist/test/https-enforcement.spec.js +278 -124
  54. package/dist/test/kms-crypto-adapter.spec.d.ts +2 -2
  55. package/dist/test/kms-crypto-adapter.spec.js +473 -304
  56. package/dist/test/lit-crypto-adapter.spec.d.ts +2 -2
  57. package/dist/test/lit-crypto-adapter.spec.js +206 -118
  58. package/dist/test/memory-efficiency.spec.d.ts +2 -2
  59. package/dist/test/memory-efficiency.spec.js +100 -87
  60. package/dist/test/mocks/key-manager.d.ts +71 -38
  61. package/dist/test/mocks/key-manager.js +129 -113
  62. package/dist/test/node-crypto-adapter.spec.d.ts +2 -2
  63. package/dist/test/node-crypto-adapter.spec.js +155 -102
  64. package/dist/test/node-generic-crypto-adapter.spec.d.ts +2 -2
  65. package/dist/test/node-generic-crypto-adapter.spec.js +134 -94
  66. package/dist/test/setup.d.ts +2 -2
  67. package/dist/test/setup.js +8 -9
  68. package/dist/tsconfig.spec.tsbuildinfo +1 -1
  69. package/dist/types.d.ts +219 -181
  70. package/dist/utils/file-metadata.d.ts +19 -13
  71. package/dist/utils.d.ts +14 -5
  72. package/package.json +4 -4
@@ -1,8 +1,8 @@
1
- import { randomBytes, createCipheriv, createDecipheriv } from 'crypto';
2
- import * as Type from '../../types.js';
3
- const ENCRYPTION_ALGORITHM = 'aes-256-cbc';
4
- const KEY_LENGTH = 256; // bits
5
- const IV_LENGTH = 16; // bytes (128 bits, used as initialization vector)
1
+ import { randomBytes, createCipheriv, createDecipheriv } from 'crypto'
2
+ import * as Type from '../../types.js'
3
+ const ENCRYPTION_ALGORITHM = 'aes-256-cbc'
4
+ const KEY_LENGTH = 256 // bits
5
+ const IV_LENGTH = 16 // bytes (128 bits, used as initialization vector)
6
6
  /**
7
7
  * NodeAesCbcCrypto implements AES-CBC symmetric encryption for Node.js environments.
8
8
  * It uses AES-CBC mode for encryption via the Node.js crypto module.
@@ -13,98 +13,104 @@ const IV_LENGTH = 16; // bytes (128 bits, used as initialization vector)
13
13
  * @implements {Type.SymmetricCrypto}
14
14
  */
15
15
  export class NodeAesCbcCrypto {
16
- /** @param {Type.BlobLike} data */
17
- async encryptStream(data) {
18
- const symmetricKey = randomBytes(KEY_LENGTH / 8); // KEY_LENGTH bits for AES
19
- const initializationVector = randomBytes(IV_LENGTH); // IV_LENGTH bytes for AES
20
- const cipher = createCipheriv(ENCRYPTION_ALGORITHM, symmetricKey, initializationVector);
21
- const encryptStream = new TransformStream({
22
- transform: async (chunk, controller) => {
23
- const encryptedChunk = cipher.update(chunk);
24
- if (encryptedChunk.length) {
25
- controller.enqueue(encryptedChunk);
26
- }
27
- },
28
- flush: (controller) => {
29
- const final = cipher.final();
30
- if (final.length) {
31
- controller.enqueue(final);
32
- }
33
- },
34
- });
35
- return Promise.resolve({
36
- key: symmetricKey,
37
- iv: initializationVector,
38
- encryptedStream: data.stream().pipeThrough(encryptStream),
39
- });
40
- }
41
- /**
42
- * @param {ReadableStream} encryptedData
43
- * @param {Uint8Array} key
44
- * @param {Uint8Array} iv
45
- */
46
- async decryptStream(encryptedData, key, iv) {
47
- const decipher = createDecipheriv(ENCRYPTION_ALGORITHM, key, iv);
48
- const decryptor = new TransformStream({
49
- async transform(chunk, controller) {
50
- try {
51
- const decryptedChunk = decipher.update(chunk);
52
- if (decryptedChunk.length > 0) {
53
- controller.enqueue(decryptedChunk);
54
- }
55
- }
56
- catch (err) {
57
- controller.error(err);
58
- }
59
- },
60
- flush(controller) {
61
- try {
62
- const finalChunk = decipher.final();
63
- if (finalChunk.length > 0) {
64
- controller.enqueue(finalChunk);
65
- }
66
- controller.terminate();
67
- }
68
- catch (err) {
69
- controller.error(err);
70
- }
71
- },
72
- });
73
- return Promise.resolve(encryptedData.pipeThrough(decryptor));
74
- }
75
- /**
76
- * Combine key and IV into a single array for AES-CBC
77
- *
78
- * @param {Uint8Array} key - The AES key (KEY_LENGTH/8 bytes)
79
- * @param {Uint8Array} iv - The AES-CBC IV (IV_LENGTH bytes)
80
- * @returns {Uint8Array} Combined key and IV (KEY_LENGTH/8 + IV_LENGTH bytes)
81
- */
82
- combineKeyAndIV(key, iv) {
83
- const keyBytes = KEY_LENGTH / 8;
84
- if (key.length !== keyBytes) {
85
- throw new Error(`AES-${KEY_LENGTH} key must be ${keyBytes} bytes, got ${key.length}`);
16
+ /** @param {Type.BlobLike} data */
17
+ async encryptStream(data) {
18
+ const symmetricKey = randomBytes(KEY_LENGTH / 8) // KEY_LENGTH bits for AES
19
+ const initializationVector = randomBytes(IV_LENGTH) // IV_LENGTH bytes for AES
20
+ const cipher = createCipheriv(
21
+ ENCRYPTION_ALGORITHM,
22
+ symmetricKey,
23
+ initializationVector
24
+ )
25
+ const encryptStream = new TransformStream({
26
+ transform: async (chunk, controller) => {
27
+ const encryptedChunk = cipher.update(chunk)
28
+ if (encryptedChunk.length) {
29
+ controller.enqueue(encryptedChunk)
86
30
  }
87
- if (iv.length !== IV_LENGTH) {
88
- throw new Error(`AES-CBC IV must be ${IV_LENGTH} bytes, got ${iv.length}`);
31
+ },
32
+ flush: (controller) => {
33
+ const final = cipher.final()
34
+ if (final.length) {
35
+ controller.enqueue(final)
89
36
  }
90
- return new Uint8Array([...key, ...iv]);
91
- }
92
- /**
93
- * Split combined key and IV for AES-CBC
94
- *
95
- * @param {Uint8Array} combined - Combined key and IV (KEY_LENGTH/8 + IV_LENGTH bytes)
96
- * @returns {{ key: Uint8Array, iv: Uint8Array }} Separated key and IV
97
- */
98
- splitKeyAndIV(combined) {
99
- const keyBytes = KEY_LENGTH / 8;
100
- const expectedLength = keyBytes + IV_LENGTH;
101
- if (combined.length !== expectedLength) {
102
- throw new Error(`AES-${KEY_LENGTH}-CBC combined key+IV must be ${expectedLength} bytes, got ${combined.length}`);
37
+ },
38
+ })
39
+ return Promise.resolve({
40
+ key: symmetricKey,
41
+ iv: initializationVector,
42
+ encryptedStream: data.stream().pipeThrough(encryptStream),
43
+ })
44
+ }
45
+ /**
46
+ * @param {ReadableStream} encryptedData
47
+ * @param {Uint8Array} key
48
+ * @param {Uint8Array} iv
49
+ */
50
+ async decryptStream(encryptedData, key, iv) {
51
+ const decipher = createDecipheriv(ENCRYPTION_ALGORITHM, key, iv)
52
+ const decryptor = new TransformStream({
53
+ async transform(chunk, controller) {
54
+ try {
55
+ const decryptedChunk = decipher.update(chunk)
56
+ if (decryptedChunk.length > 0) {
57
+ controller.enqueue(decryptedChunk)
58
+ }
59
+ } catch (err) {
60
+ controller.error(err)
61
+ }
62
+ },
63
+ flush(controller) {
64
+ try {
65
+ const finalChunk = decipher.final()
66
+ if (finalChunk.length > 0) {
67
+ controller.enqueue(finalChunk)
68
+ }
69
+ controller.terminate()
70
+ } catch (err) {
71
+ controller.error(err)
103
72
  }
104
- return {
105
- key: combined.subarray(0, keyBytes),
106
- iv: combined.subarray(keyBytes, keyBytes + IV_LENGTH),
107
- };
73
+ },
74
+ })
75
+ return Promise.resolve(encryptedData.pipeThrough(decryptor))
76
+ }
77
+ /**
78
+ * Combine key and IV into a single array for AES-CBC
79
+ *
80
+ * @param {Uint8Array} key - The AES key (KEY_LENGTH/8 bytes)
81
+ * @param {Uint8Array} iv - The AES-CBC IV (IV_LENGTH bytes)
82
+ * @returns {Uint8Array} Combined key and IV (KEY_LENGTH/8 + IV_LENGTH bytes)
83
+ */
84
+ combineKeyAndIV(key, iv) {
85
+ const keyBytes = KEY_LENGTH / 8
86
+ if (key.length !== keyBytes) {
87
+ throw new Error(
88
+ `AES-${KEY_LENGTH} key must be ${keyBytes} bytes, got ${key.length}`
89
+ )
90
+ }
91
+ if (iv.length !== IV_LENGTH) {
92
+ throw new Error(`AES-CBC IV must be ${IV_LENGTH} bytes, got ${iv.length}`)
93
+ }
94
+ return new Uint8Array([...key, ...iv])
95
+ }
96
+ /**
97
+ * Split combined key and IV for AES-CBC
98
+ *
99
+ * @param {Uint8Array} combined - Combined key and IV (KEY_LENGTH/8 + IV_LENGTH bytes)
100
+ * @returns {{ key: Uint8Array, iv: Uint8Array }} Separated key and IV
101
+ */
102
+ splitKeyAndIV(combined) {
103
+ const keyBytes = KEY_LENGTH / 8
104
+ const expectedLength = keyBytes + IV_LENGTH
105
+ if (combined.length !== expectedLength) {
106
+ throw new Error(
107
+ `AES-${KEY_LENGTH}-CBC combined key+IV must be ${expectedLength} bytes, got ${combined.length}`
108
+ )
109
+ }
110
+ return {
111
+ key: combined.subarray(0, keyBytes),
112
+ iv: combined.subarray(keyBytes, keyBytes + IV_LENGTH),
108
113
  }
114
+ }
109
115
  }
110
- //# sourceMappingURL=node-aes-cbc-crypto.js.map
116
+ //# sourceMappingURL=node-aes-cbc-crypto.js.map
@@ -1,2 +1,2 @@
1
- export {};
2
- //# sourceMappingURL=decrypt-test.d.ts.map
1
+ export {}
2
+ //# sourceMappingURL=decrypt-test.d.ts.map
@@ -1,73 +1,82 @@
1
- import * as fs from 'fs';
2
- import dotenv from 'dotenv';
3
- import { CID } from 'multiformats';
4
- import * as Client from '@storacha/client';
5
- import * as Signer from '@ucanto/principal/ed25519';
6
- import { StoreMemory } from '@storacha/client/stores/memory';
7
- import { create } from '../src/index.js';
8
- import { Wallet } from 'ethers';
9
- import { serviceConf, receiptsEndpoint } from '../src/config/service.js';
10
- import { createNodeLitAdapter } from '../src/crypto/factories.node.js';
11
- import { LitNodeClient } from '@lit-protocol/lit-node-client';
12
- import { extract } from '@ucanto/core/delegation';
13
- dotenv.config();
1
+ import * as fs from 'fs'
2
+ import dotenv from 'dotenv'
3
+ import { CID } from 'multiformats'
4
+ import * as Client from '@storacha/client'
5
+ import * as Signer from '@ucanto/principal/ed25519'
6
+ import { StoreMemory } from '@storacha/client/stores/memory'
7
+ import { create } from '../src/index.js'
8
+ import { Wallet } from 'ethers'
9
+ import { serviceConf, receiptsEndpoint } from '../src/config/service.js'
10
+ import { createNodeLitAdapter } from '../src/crypto/factories.node.js'
11
+ import { LitNodeClient } from '@lit-protocol/lit-node-client'
12
+ import { extract } from '@ucanto/core/delegation'
13
+ dotenv.config()
14
14
  async function main() {
15
- // set up storacha client with a new agent
16
- const cid = CID.parse('bafyreifhwqmspdjsy6rgcmcizgodv7bwskgiehjhdx7wukax3z5r7tz5ji');
17
- const delegationCarBuffer = fs.readFileSync('delegation.car');
18
- const wallet = new Wallet(process.env.WALLET_PK || '');
19
- const principal = Signer.parse(process.env.DELEGATEE_AGENT_PK || '');
20
- const store = new StoreMemory();
21
- const client = await Client.create({
22
- principal,
23
- store,
24
- serviceConf,
25
- receiptsEndpoint,
26
- });
27
- // Set up Lit client
28
- const litClient = new LitNodeClient({
29
- litNetwork: 'datil-dev',
30
- });
31
- await litClient.connect();
32
- const encryptedClient = await create({
33
- storachaClient: client,
34
- cryptoAdapter: createNodeLitAdapter(litClient),
35
- });
36
- const res = await extract(delegationCarBuffer);
37
- if (res.error) {
38
- throw new Error(`Failed to extract delegation: ${res.error.message}`);
15
+ // set up storacha client with a new agent
16
+ const cid = CID.parse(
17
+ 'bafyreifhwqmspdjsy6rgcmcizgodv7bwskgiehjhdx7wukax3z5r7tz5ji'
18
+ )
19
+ const delegationCarBuffer = fs.readFileSync('delegation.car')
20
+ const wallet = new Wallet(process.env.WALLET_PK || '')
21
+ const principal = Signer.parse(process.env.DELEGATEE_AGENT_PK || '')
22
+ const store = new StoreMemory()
23
+ const client = await Client.create({
24
+ principal,
25
+ store,
26
+ serviceConf,
27
+ receiptsEndpoint,
28
+ })
29
+ // Set up Lit client
30
+ const litClient = new LitNodeClient({
31
+ litNetwork: 'datil-dev',
32
+ })
33
+ await litClient.connect()
34
+ const encryptedClient = await create({
35
+ storachaClient: client,
36
+ cryptoAdapter: createNodeLitAdapter(litClient),
37
+ })
38
+ const res = await extract(delegationCarBuffer)
39
+ if (res.error) {
40
+ throw new Error(`Failed to extract delegation: ${res.error.message}`)
41
+ }
42
+ const decryptDelegation = res.ok
43
+ const decryptionCapability = decryptDelegation.capabilities.find(
44
+ (c) => c.can === 'space/content/decrypt'
45
+ )
46
+ if (!decryptionCapability) {
47
+ throw new Error('Failed to find decryption capability')
48
+ }
49
+ const spaceDID = /** @type {`did:key:${string}`} */ (
50
+ decryptionCapability.with
51
+ )
52
+ const decryptionConfig = {
53
+ wallet,
54
+ decryptDelegation,
55
+ spaceDID,
56
+ }
57
+ const decryptedContent = await encryptedClient.retrieveAndDecryptFile(
58
+ cid,
59
+ decryptionConfig
60
+ )
61
+ const reader = decryptedContent.stream.getReader()
62
+ const decoder = new TextDecoder()
63
+ let result = ''
64
+ let done = false
65
+ while (!done) {
66
+ const { value, done: isDone } = await reader.read()
67
+ done = isDone
68
+ if (value) {
69
+ result += decoder.decode(value, { stream: true })
39
70
  }
40
- const decryptDelegation = res.ok;
41
- const decryptionCapability = decryptDelegation.capabilities.find((c) => c.can === 'space/content/decrypt');
42
- if (!decryptionCapability) {
43
- throw new Error('Failed to find decryption capability');
44
- }
45
- const spaceDID = /** @type {`did:key:${string}`} */ (decryptionCapability.with);
46
- const decryptionConfig = {
47
- wallet,
48
- decryptDelegation,
49
- spaceDID,
50
- };
51
- const decryptedContent = await encryptedClient.retrieveAndDecryptFile(cid, decryptionConfig);
52
- const reader = decryptedContent.stream.getReader();
53
- const decoder = new TextDecoder();
54
- let result = '';
55
- let done = false;
56
- while (!done) {
57
- const { value, done: isDone } = await reader.read();
58
- done = isDone;
59
- if (value) {
60
- result += decoder.decode(value, { stream: true });
61
- }
62
- }
63
- console.log('================ RESULT ===================');
64
- console.log(result);
65
- console.log('===========================================');
71
+ }
72
+ console.log('================ RESULT ===================')
73
+ console.log(result)
74
+ console.log('===========================================')
66
75
  }
67
76
  main()
68
- .then(() => process.exit(0))
69
- .catch((err) => {
70
- console.error(err);
71
- process.exit(1);
72
- });
73
- //# sourceMappingURL=decrypt-test.js.map
77
+ .then(() => process.exit(0))
78
+ .catch((err) => {
79
+ console.error(err)
80
+ process.exit(1)
81
+ })
82
+ //# sourceMappingURL=decrypt-test.js.map
@@ -1,4 +1,6 @@
1
1
  /** @param {string} data Base64 encoded CAR file */
2
- export function parseProof(data: string): Promise<Signer.Delegation<Signer.Signer.Capabilities>>;
3
- import * as Signer from '@ucanto/principal/ed25519';
4
- //# sourceMappingURL=encrypt-test.d.ts.map
2
+ export function parseProof(
3
+ data: string
4
+ ): Promise<Signer.Delegation<Signer.Signer.Capabilities>>
5
+ import * as Signer from '@ucanto/principal/ed25519'
6
+ //# sourceMappingURL=encrypt-test.d.ts.map
@@ -1,61 +1,64 @@
1
- import * as fs from 'fs';
2
- import dotenv from 'dotenv';
3
- import { CarReader } from '@ipld/car';
4
- import * as Client from '@storacha/client';
5
- import { importDAG } from '@ucanto/core/delegation';
6
- import * as Signer from '@ucanto/principal/ed25519';
7
- import { StoreMemory } from '@storacha/client/stores/memory';
8
- import * as EncryptClient from '../src/index.js';
9
- import { serviceConf, receiptsEndpoint } from '../src/config/service.js';
10
- import { createNodeLitAdapter } from '../src/crypto/factories.node.js';
11
- import { LitNodeClient } from '@lit-protocol/lit-node-client';
12
- dotenv.config();
1
+ import * as fs from 'fs'
2
+ import dotenv from 'dotenv'
3
+ import { CarReader } from '@ipld/car'
4
+ import * as Client from '@storacha/client'
5
+ import { importDAG } from '@ucanto/core/delegation'
6
+ import * as Signer from '@ucanto/principal/ed25519'
7
+ import { StoreMemory } from '@storacha/client/stores/memory'
8
+ import * as EncryptClient from '../src/index.js'
9
+ import { serviceConf, receiptsEndpoint } from '../src/config/service.js'
10
+ import { createNodeLitAdapter } from '../src/crypto/factories.node.js'
11
+ import { LitNodeClient } from '@lit-protocol/lit-node-client'
12
+ dotenv.config()
13
13
  /** @param {string} data Base64 encoded CAR file */
14
14
  export async function parseProof(data) {
15
- const blocks = [];
16
- const reader = await CarReader.fromBytes(Buffer.from(data, 'base64'));
17
- for await (const block of reader.blocks()) {
18
- blocks.push(block);
19
- }
20
- return importDAG(blocks);
15
+ const blocks = []
16
+ const reader = await CarReader.fromBytes(Buffer.from(data, 'base64'))
17
+ for await (const block of reader.blocks()) {
18
+ blocks.push(block)
19
+ }
20
+ return importDAG(blocks)
21
21
  }
22
22
  async function main() {
23
- // set up storacha client with a new agent
24
- const principal = Signer.parse(process.env.AGENT_PK || '');
25
- const store = new StoreMemory();
26
- const client = await Client.create({
27
- principal,
28
- store,
29
- serviceConf,
30
- receiptsEndpoint,
31
- });
32
- // now give Agent the delegation from the Space
33
- const proof = await parseProof(process.env.PROOF || '');
34
- const space = await client.addSpace(proof);
35
- await client.setCurrentSpace(space.did());
36
- // Set up Lit client
37
- const litClient = new LitNodeClient({
38
- litNetwork: 'datil-dev',
39
- });
40
- await litClient.connect();
41
- const encryptedClient = await EncryptClient.create({
42
- storachaClient: client,
43
- cryptoAdapter: createNodeLitAdapter(litClient),
44
- });
45
- const fileContent = await fs.promises.readFile('./README.md');
46
- const blob = new Blob([fileContent]);
47
- // Create encryption config
48
- const encryptionConfig = {
49
- issuer: principal,
50
- spaceDID: space.did(),
51
- };
52
- const link = await encryptedClient.encryptAndUploadFile(blob, encryptionConfig);
53
- console.log(link);
23
+ // set up storacha client with a new agent
24
+ const principal = Signer.parse(process.env.AGENT_PK || '')
25
+ const store = new StoreMemory()
26
+ const client = await Client.create({
27
+ principal,
28
+ store,
29
+ serviceConf,
30
+ receiptsEndpoint,
31
+ })
32
+ // now give Agent the delegation from the Space
33
+ const proof = await parseProof(process.env.PROOF || '')
34
+ const space = await client.addSpace(proof)
35
+ await client.setCurrentSpace(space.did())
36
+ // Set up Lit client
37
+ const litClient = new LitNodeClient({
38
+ litNetwork: 'datil-dev',
39
+ })
40
+ await litClient.connect()
41
+ const encryptedClient = await EncryptClient.create({
42
+ storachaClient: client,
43
+ cryptoAdapter: createNodeLitAdapter(litClient),
44
+ })
45
+ const fileContent = await fs.promises.readFile('./README.md')
46
+ const blob = new Blob([fileContent])
47
+ // Create encryption config
48
+ const encryptionConfig = {
49
+ issuer: principal,
50
+ spaceDID: space.did(),
51
+ }
52
+ const link = await encryptedClient.encryptAndUploadFile(
53
+ blob,
54
+ encryptionConfig
55
+ )
56
+ console.log(link)
54
57
  }
55
58
  main()
56
- .then(() => process.exit(0))
57
- .catch((err) => {
58
- console.error(err);
59
- process.exit(1);
60
- });
61
- //# sourceMappingURL=encrypt-test.js.map
59
+ .then(() => process.exit(0))
60
+ .catch((err) => {
61
+ console.error(err)
62
+ process.exit(1)
63
+ })
64
+ //# sourceMappingURL=encrypt-test.js.map
@@ -8,8 +8,22 @@
8
8
  * @param {AsyncIterable<Uint8Array>|Uint8Array} content - The encrypted file content
9
9
  * @returns {Promise<ReadableStream>} The decrypted file stream
10
10
  */
11
- export function decryptFileWithKey(cryptoAdapter: Type.CryptoAdapter, key: Uint8Array, iv: Uint8Array, content: AsyncIterable<Uint8Array> | Uint8Array): Promise<ReadableStream>;
12
- export function retrieveAndDecrypt(storachaClient: import("@storacha/client").Client, cryptoAdapter: Type.CryptoAdapter, gatewayURL: URL, cid: Type.AnyLink, decryptionConfig: Type.DecryptionConfig): Promise<Type.DecryptionResult>;
13
- export function getCarFileFromPublicGateway(gatewayURL: URL, cid: string): Promise<Uint8Array>;
14
- import * as Type from '../types.js';
15
- //# sourceMappingURL=decrypt-handler.d.ts.map
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,3 +1,9 @@
1
- export function encryptAndUpload(storachaClient: import("@storacha/client").Client, cryptoAdapter: Type.CryptoAdapter, file: Type.BlobLike, encryptionConfig: Type.EncryptionConfig, uploadOptions?: Type.UploadOptions): Promise<Type.AnyLink>;
2
- import * as Type from '../types.js';
3
- //# sourceMappingURL=encrypt-handler.d.ts.map
1
+ export function encryptAndUpload(
2
+ storachaClient: import('@storacha/client').Client,
3
+ cryptoAdapter: Type.CryptoAdapter,
4
+ file: Type.BlobLike,
5
+ encryptionConfig: Type.EncryptionConfig,
6
+ uploadOptions?: Type.UploadOptions
7
+ ): Promise<Type.AnyLink>
8
+ import * as Type from '../types.js'
9
+ //# sourceMappingURL=encrypt-handler.d.ts.map