@secrecy/lib 1.75.8 → 1.76.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,13 +1,32 @@
1
+ import { encryptCryptoBox, generateCryptoBoxKeyPair, sodium, } from '../index.js';
1
2
  export class SecrecyGroupClient {
2
3
  #client;
3
4
  constructor(client) {
4
5
  this.#client = client;
5
6
  }
6
7
  async addMember(input) {
7
- return this.#client.apiClient.group.addMember.mutate(input);
8
+ const groupIdentity = this.#client.groupIdentities.find((g) => g.groupId === input.id);
9
+ if (!groupIdentity) {
10
+ throw new Error('Group identity not found');
11
+ }
12
+ const opts = {
13
+ pubKey: input.pubKey,
14
+ role: input.role,
15
+ fromPubKey: this.#client.uaIdentity.identityPubKey,
16
+ id: input.id,
17
+ encPriv: sodium.to_hex(encryptCryptoBox(sodium.from_hex(groupIdentity.identityPubKey), input.pubKey, this.#client.uaPrivateKey)),
18
+ };
19
+ return this.#client.apiClient.group.addMember.mutate(opts);
8
20
  }
9
21
  async create(input) {
10
- return this.#client.apiClient.group.create.mutate(input);
22
+ const keyPair = generateCryptoBoxKeyPair();
23
+ const opts = {
24
+ name: input.name,
25
+ fromPubKey: this.#client.uaIdentity.identityPubKey,
26
+ pubKey: keyPair.publicKey,
27
+ encPriv: sodium.to_hex(encryptCryptoBox(sodium.from_hex(keyPair.privateKey), this.#client.uaIdentity.identityPubKey, this.#client.uaPrivateKey)),
28
+ };
29
+ return this.#client.apiClient.group.create.mutate(opts);
11
30
  }
12
31
  async deleteMember(input) {
13
32
  return this.#client.apiClient.group.deleteMember.mutate(input);
@@ -38,26 +38,10 @@ export async function downloadDataFromLink(opts) {
38
38
  console.error(err);
39
39
  throw new Error(`Unable to fetch "${`${dataUrl}${opts.dataLinkSlug}/json"`}`, { cause: err });
40
40
  });
41
- console.log('rawDataLinkRes.status', rawDataLinkRes.status);
42
- if (!rawDataLinkRes.ok) {
43
- throw new Error(`Unable to fetch data link! Server responded with ${rawDataLinkRes.status} ${rawDataLinkRes.statusText}`);
44
- }
45
- // const rawDataLink = await rawDataLinkRes.json().catch((err) => {
46
- // console.error(err)
47
- // throw new Error('Unable to parse data link json!', { cause: err })
48
- // })
49
- const arrayBuffer = await rawDataLinkRes.bytes();
50
- console.log('arrayBuffer.byteLength', arrayBuffer.byteLength);
51
- const rawDataLinkText = new TextDecoder().decode(arrayBuffer);
52
- console.log('rawDataLinkText', rawDataLinkText);
53
- let rawDataLink;
54
- try {
55
- rawDataLink = JSON.parse(rawDataLinkText);
56
- }
57
- catch (err) {
41
+ const rawDataLink = await rawDataLinkRes.json().catch((err) => {
58
42
  console.error(err);
59
43
  throw new Error('Unable to parse data link json!', { cause: err });
60
- }
44
+ });
61
45
  const dataLink = downloadDataLinkSchema.safeParse(rawDataLink);
62
46
  if (dataLink.error) {
63
47
  throw new Error(`Should not happen!`, { cause: dataLink.error });
@@ -1,10 +1,10 @@
1
1
  import type { RouterInputs, RouterOutputs } from '../client.js';
2
- import type { SecrecyClient } from '../index.js';
2
+ import { type SecrecyClient } from '../index.js';
3
3
  export declare class SecrecyGroupClient {
4
4
  #private;
5
5
  constructor(client: SecrecyClient);
6
- addMember(input: RouterInputs['group']['addMember']): Promise<RouterOutputs['group']['addMember']>;
7
- create(input: RouterInputs['group']['create']): Promise<RouterOutputs['group']['create']>;
6
+ addMember(input: Pick<RouterInputs['group']['addMember'], 'pubKey' | 'role' | 'id'>): Promise<RouterOutputs['group']['addMember']>;
7
+ create(input: Pick<RouterInputs['group']['create'], 'name'>): Promise<RouterOutputs['group']['create']>;
8
8
  deleteMember(input: RouterInputs['group']['deleteMember']): Promise<RouterOutputs['group']['deleteMember']>;
9
9
  delete(input: RouterInputs['group']['delete']): Promise<RouterOutputs['group']['delete']>;
10
10
  get(input: RouterInputs['group']['get']): Promise<RouterOutputs['group']['get']>;
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.8",
5
+ "version": "1.76.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/anonymize-org/lib.git"