@secrecy/lib 1.75.0-feat-groups-identity.4 → 1.75.0-feat-groups-identity.5

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
@@ -3,6 +3,15 @@ import { gigaToBytes } from './utils.js';
3
3
  export const dataCache = new Map();
4
4
  export const nodesCache = new Map();
5
5
  export const nodesEncryptionCache = new Map();
6
+ export const getNodeForEncryptionFromCache = (id) => {
7
+ if (nodesEncryptionCache.has(id)) {
8
+ return nodesEncryptionCache.get(id);
9
+ }
10
+ if (nodesCache.has(id)) {
11
+ return nodesCache.get(id);
12
+ }
13
+ return undefined;
14
+ };
6
15
  export const usersCache = new Map();
7
16
  export const publicKeysCache = new Map();
8
17
  export const dataContentCache = new LRUCache({
@@ -1,4 +1,4 @@
1
- import { nodesCache, dataCache, dataContentCache, nodesEncryptionCache, } from '../cache.js';
1
+ import { nodesCache, dataCache, dataContentCache, getNodeForEncryptionFromCache, } from '../cache.js';
2
2
  import { decryptCryptoBox, encryptCryptoBox } from '../crypto/index.js';
3
3
  import { decompress } from '../minify/index.js';
4
4
  import { sodium } from '../sodium.js';
@@ -470,16 +470,23 @@ export class SecrecyCloudClient {
470
470
  const nodes = [];
471
471
  // Retrieve and format nodes.
472
472
  for (const nodeId of nodeIds) {
473
- let node = nodesEncryptionCache.get(nodeId) ?? nodesCache.get(nodeId);
474
- if (node &&
475
- 'history' in node &&
476
- node.history.length > 0 &&
477
- node.access.nameKey) {
473
+ const node = getNodeForEncryptionFromCache(nodeId);
474
+ // ! Only keep nodes FILE with history.
475
+ if (node && 'history' in node && node.history.length > 0) {
476
+ const access = 'accesses' in node
477
+ ? node.accesses.find((a) => a.nameKey !== null)
478
+ : node.access;
479
+ if (!access) {
480
+ throw new Error(`No access found for node ${node.id} to share!`);
481
+ }
482
+ if (access.nameKey === null) {
483
+ throw new Error(`No nameKey found for node ${node.id} to share!`);
484
+ }
478
485
  nodes.push({
479
486
  id: nodeId,
480
487
  name: node.name,
481
488
  type: node.type,
482
- access: { nameKey: node.access.nameKey },
489
+ access: { nameKey: access.nameKey },
483
490
  history: node.history.map((data) => {
484
491
  if (!data.key) {
485
492
  throw new Error('Unable to retrieve data key!');
@@ -516,20 +523,13 @@ export class SecrecyCloudClient {
516
523
  (!('history' in node) || node.history.length === 0)) {
517
524
  throw new Error(`Can't share a node without data (${node.id})!`);
518
525
  }
519
- const nameKey = node.access?.nameKey;
520
526
  nodesMappedUsers[pubKey].push({
521
527
  id: node.id,
522
- nameKey: nameKey !== null
523
- ? sodium.to_hex(encryptCryptoBox(sodium.from_hex(nameKey), pubKey, this.#client.uaPrivateKey))
524
- : null,
525
- data: 'history' in node
526
- ? node.history.map((f) => ({
527
- id: f.id,
528
- key: f.key
529
- ? sodium.to_hex(encryptCryptoBox(sodium.from_hex(f.key), pubKey, this.#client.uaPrivateKey))
530
- : null,
531
- }))
532
- : [],
528
+ nameKey: sodium.to_hex(encryptCryptoBox(sodium.from_hex(node.access.nameKey), pubKey, this.#client.uaPrivateKey)),
529
+ data: node.history.map((f) => ({
530
+ id: f.id,
531
+ key: sodium.to_hex(encryptCryptoBox(sodium.from_hex(f.key), pubKey, this.#client.uaPrivateKey)),
532
+ })),
533
533
  });
534
534
  }
535
535
  }
@@ -1,8 +1,10 @@
1
1
  import type { InternalNode, InternalData, InternalNodeFull, LocalData, InternalMinimalNodeForEncryption } from './client/types/index.js';
2
2
  import { LRUCache } from 'lru-cache';
3
+ type NodeForEncryptionCached = InternalNode | InternalNodeFull | InternalMinimalNodeForEncryption;
3
4
  export declare const dataCache: Map<string, InternalData>;
4
5
  export declare const nodesCache: Map<string, InternalNode | InternalNodeFull>;
5
6
  export declare const nodesEncryptionCache: Map<string, InternalMinimalNodeForEncryption>;
7
+ export declare const getNodeForEncryptionFromCache: (id: string) => NodeForEncryptionCached | undefined;
6
8
  export declare const usersCache: Map<string, {
7
9
  firstname: string;
8
10
  lastname: string;
@@ -12,3 +14,4 @@ export declare const usersCache: Map<string, {
12
14
  }>;
13
15
  export declare const publicKeysCache: Map<string, string>;
14
16
  export declare const dataContentCache: LRUCache<string, LocalData, unknown>;
17
+ export {};
@@ -67,10 +67,10 @@ export type ApiNodeParent = NonNullable<RouterOutputs['cloud']['nodeFullById']['
67
67
  export type NodeType = ApiNode['type'];
68
68
  export type EncryptedNodeInfos = {
69
69
  id: string;
70
- nameKey: string | null;
70
+ nameKey: string;
71
71
  data: {
72
72
  id: string;
73
- key: string | null;
73
+ key: string;
74
74
  }[];
75
75
  };
76
76
  export type ShareNodeDetails = {
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.75.0-feat-groups-identity.4",
5
+ "version": "1.75.0-feat-groups-identity.5",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/anonymize-org/lib.git"