@secrecy/lib 1.30.0-feat-rename-file.1 → 1.31.0

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/lib/cache.js CHANGED
@@ -4,7 +4,7 @@ export const dataCache = new Map();
4
4
  export const nodesCache = new Map();
5
5
  export const usersCache = new Map();
6
6
  export const publicKeysCache = new Map();
7
- export const lruCache = new LRUCache({
7
+ export const dataContentCache = new LRUCache({
8
8
  max: 500,
9
9
  maxSize: gigaToBytes(0.5),
10
10
  sizeCalculation: (value) => {
@@ -1,7 +1,7 @@
1
1
  import axios from 'axios';
2
2
  import ky from 'ky';
3
3
  import { encryptName } from '../index.js';
4
- import { nodesCache, dataCache, lruCache } from '../cache.js';
4
+ import { nodesCache, dataCache, dataContentCache } from '../cache.js';
5
5
  import { secretStreamKeygen } from '../crypto/data.js';
6
6
  import { decryptCryptoBox, encryptCryptoBox } from '../crypto/index.js';
7
7
  import { compress, decompress } from '../minify/index.js';
@@ -65,16 +65,19 @@ export class SecrecyCloudClient {
65
65
  percent: 0,
66
66
  });
67
67
  if (uploadData.parts.length === 0) {
68
+ if (uploadData.keyPair.pub !== this.#keys.publicKey) {
69
+ throw new Error('The public key does not match with cached key!');
70
+ }
68
71
  await uploadProgress?.({
69
72
  total: encryptedData.byteLength,
70
73
  current: encryptedData.byteLength,
71
74
  percent: 1,
72
75
  });
73
- return uploadData.dataId;
76
+ return uploadData.id;
74
77
  }
75
78
  const uploadDataPartEnd = async (md5, order) => {
76
79
  const { isUploadPartEnded } = await this.#apiClient.cloud.uploadDataPartEnd.mutate({
77
- dataId: uploadData.dataId,
80
+ dataId: uploadData.id,
78
81
  md5,
79
82
  order,
80
83
  });
@@ -82,12 +85,12 @@ export class SecrecyCloudClient {
82
85
  };
83
86
  const uploadEnded = async () => {
84
87
  const { isUploadEnded } = await this.#apiClient.cloud.uploadDataEnd.mutate({
85
- dataId: uploadData.dataId,
88
+ dataId: uploadData.id,
86
89
  });
87
90
  return isUploadEnded;
88
91
  };
89
92
  const chunkParts = new Array();
90
- for (const [index, chunk] of enumerate(chunks(encryptedData, Number(uploadData.dataPartSize)))) {
93
+ for (const [index, chunk] of enumerate(chunks(encryptedData, Number(uploadData.partSize)))) {
91
94
  chunkParts.push({
92
95
  order: index + 1,
93
96
  data: chunk,
@@ -113,7 +116,7 @@ export class SecrecyCloudClient {
113
116
  for (const [key, value] of Object.entries(part.fields)) {
114
117
  formData.append(key, value);
115
118
  }
116
- formData.append('data', new Blob([chunk.data]), `${uploadData.dataId}-${chunk.order}`);
119
+ formData.append('data', new Blob([chunk.data]), `${uploadData.id}-${chunk.order}`);
117
120
  await axios.post(part.url, formData, {
118
121
  onUploadProgress: (progressEvent) => {
119
122
  onProgress(part.order, progressEvent);
@@ -126,8 +129,8 @@ export class SecrecyCloudClient {
126
129
  await byPart(p);
127
130
  }));
128
131
  await uploadEnded();
129
- lruCache.set(uploadData.dataId, dataBuffer);
130
- return uploadData.dataId;
132
+ dataContentCache.set(uploadData.id, dataBuffer);
133
+ return uploadData.id;
131
134
  }
132
135
  async uploadDataInCloud({ data, name, nodeId, encryptProgress, uploadProgress, signal, }) {
133
136
  const dataId = await this.uploadData({
@@ -271,7 +274,7 @@ export class SecrecyCloudClient {
271
274
  return await apiNodeToExternalNodeFull(updateNode, this.#keys);
272
275
  }
273
276
  async dataContent({ dataId, onDownloadProgress, progressDecrypt, signal, }) {
274
- const cached = lruCache.get(dataId);
277
+ const cached = dataContentCache.get(dataId);
275
278
  if (cached !== undefined) {
276
279
  return cached;
277
280
  }
@@ -335,12 +338,12 @@ export class SecrecyCloudClient {
335
338
  return decompress(src);
336
339
  };
337
340
  const encryptedContent = dataContent.type === 'lite'
338
- ? dataContent.content
341
+ ? new Uint8Array(dataContent.content)
339
342
  : dataContent.type === 'cloud'
340
343
  ? await encryptedContentFromParts(dataContent.parts)
341
344
  : // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
342
345
  dataContent.maybeContent !== null
343
- ? dataContent.maybeContent
346
+ ? new Uint8Array(dataContent.maybeContent)
344
347
  : dataContent.maybeParts !== null
345
348
  ? await encryptedContentFromParts(dataContent.maybeParts)
346
349
  : null;
@@ -348,7 +351,7 @@ export class SecrecyCloudClient {
348
351
  throw `Can't find content for data ${dataId}`;
349
352
  }
350
353
  const data = await finalize(encryptedContent);
351
- lruCache.set(dataId, data);
354
+ dataContentCache.set(dataId, data);
352
355
  return data;
353
356
  }
354
357
  async deleteData({ dataId, nodeId, }) {
@@ -10,4 +10,4 @@ export declare const usersCache: Map<string, {
10
10
  isSearchable: boolean;
11
11
  }>;
12
12
  export declare const publicKeysCache: Map<string, string>;
13
- export declare const lruCache: LRUCache<string, Uint8Array, unknown>;
13
+ export declare const dataContentCache: LRUCache<string, Uint8Array, unknown>;
@@ -4400,22 +4400,32 @@ export declare const createTRPCClient: (session?: string | null | undefined, onA
4400
4400
  dataKey: string;
4401
4401
  };
4402
4402
  _output_in: {
4403
- dataId: string;
4403
+ id: string;
4404
+ keyPair: {
4405
+ pub: string;
4406
+ encPriv: string;
4407
+ };
4408
+ key: string;
4409
+ partSize: bigint;
4404
4410
  parts: {
4405
4411
  fields: Record<string, string>;
4406
4412
  url: string;
4407
4413
  order: number;
4408
4414
  }[];
4409
- dataPartSize: bigint;
4410
4415
  };
4411
4416
  _output_out: {
4412
- dataId: string;
4417
+ id: string;
4418
+ keyPair: {
4419
+ pub: string;
4420
+ encPriv: string;
4421
+ };
4422
+ key: string;
4423
+ partSize: bigint;
4413
4424
  parts: {
4414
4425
  fields: Record<string, string>;
4415
4426
  url: string;
4416
4427
  order: number;
4417
4428
  }[];
4418
- dataPartSize: bigint;
4419
4429
  };
4420
4430
  }, unknown>>;
4421
4431
  };
@@ -4483,9 +4493,19 @@ export declare const createTRPCClient: (session?: string | null | undefined, onA
4483
4493
  };
4484
4494
  _output_in: {
4485
4495
  id: string;
4496
+ keyPair: {
4497
+ pub: string;
4498
+ encPriv: string;
4499
+ };
4500
+ key: string;
4486
4501
  };
4487
4502
  _output_out: {
4488
4503
  id: string;
4504
+ keyPair: {
4505
+ pub: string;
4506
+ encPriv: string;
4507
+ };
4508
+ key: string;
4489
4509
  };
4490
4510
  }, unknown>>;
4491
4511
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@secrecy/lib",
3
3
  "author": "Anonymize <anonymize@gmail.com>",
4
4
  "description": "Anonymize Secrecy Library",
5
- "version": "1.30.0-feat-rename-file.1",
5
+ "version": "1.31.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/anonymize-org/lib.git"
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "dependencies": {
76
76
  "@secrecy/lib-utils": "^1.0.18",
77
- "@secrecy/trpc-api-types": "1.27.0-feat-rename-file.13",
77
+ "@secrecy/trpc-api-types": "1.27.0-feat-file-upload-access.2",
78
78
  "@trpc/client": "10.45.2",
79
79
  "@trpc/server": "10.45.2",
80
80
  "@types/libsodium-wrappers-sumo": "^0.7.8",