@secrecy/lib 1.75.0-feat-groups-identity.3 → 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({
|
|
@@ -88,22 +88,35 @@ export class SecrecyAppClient {
|
|
|
88
88
|
...new Set(userIds.filter((userId) => publicKeys[userId] === undefined)),
|
|
89
89
|
];
|
|
90
90
|
if (missingKeys.length > 0) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
if (missingKeys.length === 1) {
|
|
92
|
+
const userKey = await this.#client.apiClient.application.userPublicKey.query({
|
|
93
|
+
id: missingKeys[0],
|
|
94
|
+
appId,
|
|
95
|
+
});
|
|
96
|
+
if (userKey.appId !== appId) {
|
|
97
|
+
throw new Error(`AppId mismatch: ${userKey.appId} !== ${appId}`);
|
|
98
|
+
}
|
|
99
|
+
publicKeys[missingKeys[0]] = userKey.publicKey;
|
|
100
|
+
publicKeysCache.set(`userPublicKey:${missingKeys[0]}-${appId}`, userKey.publicKey);
|
|
97
101
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
else {
|
|
103
|
+
const userKeysMap = await this.#client.apiClient.application.usersPublicKey.query({
|
|
104
|
+
userIds: missingKeys,
|
|
105
|
+
appId,
|
|
106
|
+
});
|
|
107
|
+
if ('publicKey' in userKeysMap) {
|
|
108
|
+
throw Error('Should not happen!');
|
|
109
|
+
}
|
|
110
|
+
if (userKeysMap.appId !== appId) {
|
|
111
|
+
throw new Error(`AppId mismatch: ${userKeysMap.appId} !== ${appId}`);
|
|
112
|
+
}
|
|
113
|
+
if (Object.keys(userKeysMap.publicKeys).length !== missingKeys.length) {
|
|
114
|
+
throw new Error("Unable to load some user's public keys!");
|
|
115
|
+
}
|
|
116
|
+
for (const [userId, userPublicKey] of Object.entries(userKeysMap.publicKeys)) {
|
|
117
|
+
publicKeys[userId] = userPublicKey;
|
|
118
|
+
publicKeysCache.set(`userPublicKey:${userId}-${appId}`, userPublicKey);
|
|
119
|
+
}
|
|
107
120
|
}
|
|
108
121
|
}
|
|
109
122
|
return Array.isArray(input) ? publicKeys : publicKeys[input];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { nodesCache, dataCache, dataContentCache,
|
|
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
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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:
|
|
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
|
|
523
|
-
|
|
524
|
-
:
|
|
525
|
-
|
|
526
|
-
|
|
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
|
}
|
package/dist/types/cache.d.ts
CHANGED
|
@@ -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
|
|
70
|
+
nameKey: string;
|
|
71
71
|
data: {
|
|
72
72
|
id: string;
|
|
73
|
-
key: string
|
|
73
|
+
key: string;
|
|
74
74
|
}[];
|
|
75
75
|
};
|
|
76
76
|
export type ShareNodeDetails = {
|
package/dist/types/client.d.ts
CHANGED
|
@@ -244,6 +244,17 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
|
|
|
244
244
|
meta: any;
|
|
245
245
|
}>;
|
|
246
246
|
userPublicKey: import("@trpc/server").TRPCQueryProcedure<{
|
|
247
|
+
input: {
|
|
248
|
+
id: string;
|
|
249
|
+
appId?: string | undefined;
|
|
250
|
+
};
|
|
251
|
+
output: {
|
|
252
|
+
appId: string;
|
|
253
|
+
publicKey: string;
|
|
254
|
+
};
|
|
255
|
+
meta: any;
|
|
256
|
+
}>;
|
|
257
|
+
usersPublicKey: import("@trpc/server").TRPCQueryProcedure<{
|
|
247
258
|
input: {
|
|
248
259
|
userId: string;
|
|
249
260
|
appId?: string | undefined;
|
|
@@ -4976,9 +4987,10 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
|
|
|
4976
4987
|
kind: "GROUP";
|
|
4977
4988
|
identityPubKey: string;
|
|
4978
4989
|
groupId: string;
|
|
4990
|
+
groupOwnerPubKey: string;
|
|
4979
4991
|
encPriv: string;
|
|
4980
4992
|
sharedByPubKey: string;
|
|
4981
|
-
|
|
4993
|
+
groupRole: "ADMIN" | "MEMBER";
|
|
4982
4994
|
})[];
|
|
4983
4995
|
};
|
|
4984
4996
|
meta: any;
|
|
@@ -5006,9 +5018,10 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
|
|
|
5006
5018
|
kind: "GROUP";
|
|
5007
5019
|
identityPubKey: string;
|
|
5008
5020
|
groupId: string;
|
|
5021
|
+
groupOwnerPubKey: string;
|
|
5009
5022
|
encPriv: string;
|
|
5010
5023
|
sharedByPubKey: string;
|
|
5011
|
-
|
|
5024
|
+
groupRole: "ADMIN" | "MEMBER";
|
|
5012
5025
|
})[] | null;
|
|
5013
5026
|
};
|
|
5014
5027
|
meta: any;
|
|
@@ -5681,15 +5694,6 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
|
|
|
5681
5694
|
};
|
|
5682
5695
|
meta: any;
|
|
5683
5696
|
}>;
|
|
5684
|
-
publicKey: import("@trpc/server").TRPCQueryProcedure<{
|
|
5685
|
-
input: {
|
|
5686
|
-
id: string;
|
|
5687
|
-
};
|
|
5688
|
-
output: {
|
|
5689
|
-
pub: string;
|
|
5690
|
-
};
|
|
5691
|
-
meta: any;
|
|
5692
|
-
}>;
|
|
5693
5697
|
self: import("@trpc/server").TRPCQueryProcedure<{
|
|
5694
5698
|
input: {
|
|
5695
5699
|
t?: number | undefined;
|
|
@@ -5816,6 +5820,7 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
|
|
|
5816
5820
|
kind: "GROUP";
|
|
5817
5821
|
identityPubKey: string;
|
|
5818
5822
|
groupId: string;
|
|
5823
|
+
groupOwnerPubKey: string;
|
|
5819
5824
|
};
|
|
5820
5825
|
};
|
|
5821
5826
|
meta: any;
|
|
@@ -5834,6 +5839,7 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
|
|
|
5834
5839
|
kind: "GROUP";
|
|
5835
5840
|
identityPubKey: string;
|
|
5836
5841
|
groupId: string;
|
|
5842
|
+
groupOwnerPubKey: string;
|
|
5837
5843
|
})[];
|
|
5838
5844
|
};
|
|
5839
5845
|
meta: any;
|
|
@@ -5851,9 +5857,10 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
|
|
|
5851
5857
|
kind: "GROUP";
|
|
5852
5858
|
identityPubKey: string;
|
|
5853
5859
|
groupId: string;
|
|
5860
|
+
groupOwnerPubKey: string;
|
|
5854
5861
|
encPriv: string;
|
|
5855
5862
|
sharedByPubKey: string;
|
|
5856
|
-
|
|
5863
|
+
groupRole: "ADMIN" | "MEMBER";
|
|
5857
5864
|
})[];
|
|
5858
5865
|
};
|
|
5859
5866
|
meta: any;
|
|
@@ -6097,6 +6104,17 @@ export declare const getTrpcGuestClient: ({ url }?: {
|
|
|
6097
6104
|
meta: any;
|
|
6098
6105
|
}>;
|
|
6099
6106
|
userPublicKey: import("@trpc/server").TRPCQueryProcedure<{
|
|
6107
|
+
input: {
|
|
6108
|
+
id: string;
|
|
6109
|
+
appId?: string | undefined;
|
|
6110
|
+
};
|
|
6111
|
+
output: {
|
|
6112
|
+
appId: string;
|
|
6113
|
+
publicKey: string;
|
|
6114
|
+
};
|
|
6115
|
+
meta: any;
|
|
6116
|
+
}>;
|
|
6117
|
+
usersPublicKey: import("@trpc/server").TRPCQueryProcedure<{
|
|
6100
6118
|
input: {
|
|
6101
6119
|
userId: string;
|
|
6102
6120
|
appId?: string | undefined;
|
|
@@ -10829,9 +10847,10 @@ export declare const getTrpcGuestClient: ({ url }?: {
|
|
|
10829
10847
|
kind: "GROUP";
|
|
10830
10848
|
identityPubKey: string;
|
|
10831
10849
|
groupId: string;
|
|
10850
|
+
groupOwnerPubKey: string;
|
|
10832
10851
|
encPriv: string;
|
|
10833
10852
|
sharedByPubKey: string;
|
|
10834
|
-
|
|
10853
|
+
groupRole: "ADMIN" | "MEMBER";
|
|
10835
10854
|
})[];
|
|
10836
10855
|
};
|
|
10837
10856
|
meta: any;
|
|
@@ -10859,9 +10878,10 @@ export declare const getTrpcGuestClient: ({ url }?: {
|
|
|
10859
10878
|
kind: "GROUP";
|
|
10860
10879
|
identityPubKey: string;
|
|
10861
10880
|
groupId: string;
|
|
10881
|
+
groupOwnerPubKey: string;
|
|
10862
10882
|
encPriv: string;
|
|
10863
10883
|
sharedByPubKey: string;
|
|
10864
|
-
|
|
10884
|
+
groupRole: "ADMIN" | "MEMBER";
|
|
10865
10885
|
})[] | null;
|
|
10866
10886
|
};
|
|
10867
10887
|
meta: any;
|
|
@@ -11534,15 +11554,6 @@ export declare const getTrpcGuestClient: ({ url }?: {
|
|
|
11534
11554
|
};
|
|
11535
11555
|
meta: any;
|
|
11536
11556
|
}>;
|
|
11537
|
-
publicKey: import("@trpc/server").TRPCQueryProcedure<{
|
|
11538
|
-
input: {
|
|
11539
|
-
id: string;
|
|
11540
|
-
};
|
|
11541
|
-
output: {
|
|
11542
|
-
pub: string;
|
|
11543
|
-
};
|
|
11544
|
-
meta: any;
|
|
11545
|
-
}>;
|
|
11546
11557
|
self: import("@trpc/server").TRPCQueryProcedure<{
|
|
11547
11558
|
input: {
|
|
11548
11559
|
t?: number | undefined;
|
|
@@ -11669,6 +11680,7 @@ export declare const getTrpcGuestClient: ({ url }?: {
|
|
|
11669
11680
|
kind: "GROUP";
|
|
11670
11681
|
identityPubKey: string;
|
|
11671
11682
|
groupId: string;
|
|
11683
|
+
groupOwnerPubKey: string;
|
|
11672
11684
|
};
|
|
11673
11685
|
};
|
|
11674
11686
|
meta: any;
|
|
@@ -11687,6 +11699,7 @@ export declare const getTrpcGuestClient: ({ url }?: {
|
|
|
11687
11699
|
kind: "GROUP";
|
|
11688
11700
|
identityPubKey: string;
|
|
11689
11701
|
groupId: string;
|
|
11702
|
+
groupOwnerPubKey: string;
|
|
11690
11703
|
})[];
|
|
11691
11704
|
};
|
|
11692
11705
|
meta: any;
|
|
@@ -11704,9 +11717,10 @@ export declare const getTrpcGuestClient: ({ url }?: {
|
|
|
11704
11717
|
kind: "GROUP";
|
|
11705
11718
|
identityPubKey: string;
|
|
11706
11719
|
groupId: string;
|
|
11720
|
+
groupOwnerPubKey: string;
|
|
11707
11721
|
encPriv: string;
|
|
11708
11722
|
sharedByPubKey: string;
|
|
11709
|
-
|
|
11723
|
+
groupRole: "ADMIN" | "MEMBER";
|
|
11710
11724
|
})[];
|
|
11711
11725
|
};
|
|
11712
11726
|
meta: any;
|
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.
|
|
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"
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@js-temporal/polyfill": "^0.5.1",
|
|
79
|
-
"@secrecy/trpc-api-types": "1.33.0-feat-groups-identity.
|
|
79
|
+
"@secrecy/trpc-api-types": "1.33.0-feat-groups-identity.25",
|
|
80
80
|
"@trpc/client": "11.6.0",
|
|
81
81
|
"@trpc/server": "^11.6.0",
|
|
82
82
|
"@types/libsodium-wrappers-sumo": "^0.7.8",
|