@secrecy/lib 1.81.0 → 1.82.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.
@@ -1,3 +1,4 @@
1
+ import { publicKeysCache } from '../cache.js';
1
2
  import { encryptCryptoBox, generateCryptoBoxKeyPair, sodium, } from '../index.js';
2
3
  export class SecrecyGroupClient {
3
4
  #client;
@@ -57,4 +58,35 @@ export class SecrecyGroupClient {
57
58
  async updateMember(input) {
58
59
  return this.#client.apiClient.group.updateMember.mutate(input);
59
60
  }
61
+ async publicKeys(input) {
62
+ const groupIds = Array.isArray(input) ? input : [input];
63
+ if (groupIds.length === 0) {
64
+ return {};
65
+ }
66
+ const publicKeys = Object.fromEntries(groupIds
67
+ .map((groupId) => [
68
+ groupId,
69
+ publicKeysCache.get(`groupPublicKey:${groupId}`),
70
+ ])
71
+ .filter(([_, key]) => key !== undefined));
72
+ const missingKeys = [
73
+ ...new Set(groupIds.filter((groupId) => publicKeys[groupId] === undefined)),
74
+ ];
75
+ if (missingKeys.length > 0) {
76
+ const groupKeysMap = await this.#client.apiClient.group.publicKeys.query({
77
+ groupIds: missingKeys,
78
+ });
79
+ if ('publicKey' in groupKeysMap) {
80
+ throw Error('Should not happen!');
81
+ }
82
+ if (Object.keys(groupKeysMap.publicKeys).length !== missingKeys.length) {
83
+ throw new Error("Unable to load some user's public keys!");
84
+ }
85
+ for (const [groupId, publicKey] of Object.entries(groupKeysMap.publicKeys)) {
86
+ publicKeys[groupId] = publicKey;
87
+ publicKeysCache.set(`groupPublicKey:${groupId}`, publicKey);
88
+ }
89
+ }
90
+ return publicKeys;
91
+ }
60
92
  }
@@ -12,4 +12,5 @@ export declare class SecrecyGroupClient {
12
12
  transferOwnership(input: RouterInputs['group']['transferOwnership']): Promise<RouterOutputs['group']['transferOwnership']>;
13
13
  update(input: RouterInputs['group']['update']): Promise<RouterOutputs['group']['update']>;
14
14
  updateMember(input: RouterInputs['group']['updateMember']): Promise<RouterOutputs['group']['updateMember']>;
15
+ publicKeys(input: string[]): Promise<Record<string, string>>;
15
16
  }
@@ -6367,6 +6367,19 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
6367
6367
  };
6368
6368
  meta: any;
6369
6369
  }>;
6370
+ publicKeys: import("@trpc/server").TRPCQueryProcedure<{
6371
+ input: {
6372
+ groupId: string;
6373
+ } | {
6374
+ groupIds: string[];
6375
+ };
6376
+ output: {
6377
+ publicKey: string;
6378
+ } | {
6379
+ publicKeys: Record<string, string>;
6380
+ };
6381
+ meta: any;
6382
+ }>;
6370
6383
  }>;
6371
6384
  }>>;
6372
6385
  export declare const getTrpcGuestClient: ({ url }?: {
@@ -12729,6 +12742,19 @@ export declare const getTrpcGuestClient: ({ url }?: {
12729
12742
  };
12730
12743
  meta: any;
12731
12744
  }>;
12745
+ publicKeys: import("@trpc/server").TRPCQueryProcedure<{
12746
+ input: {
12747
+ groupId: string;
12748
+ } | {
12749
+ groupIds: string[];
12750
+ };
12751
+ output: {
12752
+ publicKey: string;
12753
+ } | {
12754
+ publicKeys: Record<string, string>;
12755
+ };
12756
+ meta: any;
12757
+ }>;
12732
12758
  }>;
12733
12759
  }>>;
12734
12760
  export type ApiClient = ReturnType<typeof createTRPCClient>;
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.81.0",
5
+ "version": "1.82.0",
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.36.0",
79
+ "@secrecy/trpc-api-types": "1.37.0-dev.1",
80
80
  "@trpc/client": "11.6.0",
81
81
  "@trpc/server": "^11.6.0",
82
82
  "@types/libsodium-wrappers-sumo": "^0.7.8",