@secrecy/lib 1.84.0 → 1.85.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/client/SecrecyGroupClient.js +5 -3
- package/dist/lib/client/helpers.js +2 -2
- package/dist/lib/worker/workerCodes.js +1 -1
- package/dist/types/client/SecrecyGroupClient.d.ts +1 -1
- package/dist/types/client/helpers.d.ts +2 -1
- package/dist/types/client.d.ts +4 -4
- package/dist/types/worker/workerCodes.d.ts +1 -1
- package/package.json +23 -23
|
@@ -5,7 +5,7 @@ export class SecrecyGroupClient {
|
|
|
5
5
|
constructor(client) {
|
|
6
6
|
this.#client = client;
|
|
7
7
|
}
|
|
8
|
-
async addMember(input) {
|
|
8
|
+
async addMember(input, fromIdentityPubKey) {
|
|
9
9
|
const groupIdentity = this.#client.groupIdentities.find((g) => g.groupId === input.id);
|
|
10
10
|
if (!groupIdentity) {
|
|
11
11
|
throw new Error('Group identity not found');
|
|
@@ -18,11 +18,13 @@ export class SecrecyGroupClient {
|
|
|
18
18
|
pubKey: input.pubKey,
|
|
19
19
|
role: input.role,
|
|
20
20
|
id: input.id,
|
|
21
|
-
encPriv: sodium.to_hex(encryptCryptoBox(sodium.from_hex(groupPriv), input.pubKey,
|
|
21
|
+
encPriv: sodium.to_hex(encryptCryptoBox(sodium.from_hex(groupPriv), input.pubKey, fromIdentityPubKey
|
|
22
|
+
? this.#client.getPrivateKey(fromIdentityPubKey)
|
|
23
|
+
: this.#client.currentIdentityPrivateKey)),
|
|
22
24
|
};
|
|
23
25
|
return this.#client.apiClient.group.addMember.mutate({
|
|
24
26
|
...opts,
|
|
25
|
-
fromIdentityPubKey: this.#client.currentIdentity.identityPubKey,
|
|
27
|
+
fromIdentityPubKey: fromIdentityPubKey ?? this.#client.currentIdentity.identityPubKey,
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
30
|
async create(input) {
|
|
@@ -48,7 +48,7 @@ export function getSecrecyClient(opts = {}) {
|
|
|
48
48
|
}
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
|
-
export async function login({ appId, context, path, redirect, scopes, backPath, session, secrecyUrls, }) {
|
|
51
|
+
export async function login({ appId, context, path, redirect, scopes, backPath, session, secrecyUrls, forceLogin, }) {
|
|
52
52
|
return await new Promise(async (resolve, reject) => {
|
|
53
53
|
const appUrl = window.location.origin;
|
|
54
54
|
const client = getSecrecyClient({ session, secrecyUrls });
|
|
@@ -109,7 +109,7 @@ export async function login({ appId, context, path, redirect, scopes, backPath,
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
|
-
if (client === null) {
|
|
112
|
+
if (client === null || forceLogin === true) {
|
|
113
113
|
innerLogin();
|
|
114
114
|
}
|
|
115
115
|
else {
|
|
@@ -7,7 +7,7 @@ self.sodium = {
|
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
importScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@
|
|
10
|
+
importScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@0.7.15/dist/browsers/sodium.js');
|
|
11
11
|
importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');
|
|
12
12
|
|
|
13
13
|
function* chunks(arr, n) {
|
|
@@ -3,7 +3,7 @@ import { type SecrecyClient } from '../index.js';
|
|
|
3
3
|
export declare class SecrecyGroupClient {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(client: SecrecyClient);
|
|
6
|
-
addMember(input: Pick<RouterInputs['group']['addMember'], 'pubKey' | 'role' | 'id'
|
|
6
|
+
addMember(input: Pick<RouterInputs['group']['addMember'], 'pubKey' | 'role' | 'id'>, fromIdentityPubKey?: string): Promise<RouterOutputs['group']['addMember']>;
|
|
7
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']>;
|
|
@@ -19,6 +19,7 @@ export interface HashInfos {
|
|
|
19
19
|
export type UseSecrecyParams = Omit<HashInfos, 'appUrl'> & {
|
|
20
20
|
session?: boolean | undefined;
|
|
21
21
|
secrecyUrls?: Partial<SecrecyUrls>;
|
|
22
|
+
forceLogin?: boolean | undefined;
|
|
22
23
|
};
|
|
23
24
|
export declare function getSecrecyClient(opts?: {
|
|
24
25
|
session?: boolean;
|
|
@@ -27,5 +28,5 @@ export declare function getSecrecyClient(opts?: {
|
|
|
27
28
|
type LoginResponse<Params extends UseSecrecyParams> = Params extends {
|
|
28
29
|
redirect: true;
|
|
29
30
|
} ? SecrecyClient | null : SecrecyClient;
|
|
30
|
-
export declare function login<Params extends UseSecrecyParams>({ appId, context, path, redirect, scopes, backPath, session, secrecyUrls, }: Params): Promise<LoginResponse<Params>>;
|
|
31
|
+
export declare function login<Params extends UseSecrecyParams>({ appId, context, path, redirect, scopes, backPath, session, secrecyUrls, forceLogin, }: Params): Promise<LoginResponse<Params>>;
|
|
31
32
|
export {};
|
package/dist/types/client.d.ts
CHANGED
|
@@ -764,7 +764,7 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
|
|
|
764
764
|
tags: string[];
|
|
765
765
|
lang: "en" | "fr";
|
|
766
766
|
blogId: string;
|
|
767
|
-
|
|
767
|
+
targets: string[];
|
|
768
768
|
} & {
|
|
769
769
|
blog: {
|
|
770
770
|
id: string;
|
|
@@ -789,7 +789,7 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => import
|
|
|
789
789
|
tags: string[];
|
|
790
790
|
lang: "en" | "fr";
|
|
791
791
|
blogId: string;
|
|
792
|
-
|
|
792
|
+
targets: string[];
|
|
793
793
|
} & {
|
|
794
794
|
blog: {
|
|
795
795
|
id: string;
|
|
@@ -7141,7 +7141,7 @@ export declare const getTrpcGuestClient: ({ url }?: {
|
|
|
7141
7141
|
tags: string[];
|
|
7142
7142
|
lang: "en" | "fr";
|
|
7143
7143
|
blogId: string;
|
|
7144
|
-
|
|
7144
|
+
targets: string[];
|
|
7145
7145
|
} & {
|
|
7146
7146
|
blog: {
|
|
7147
7147
|
id: string;
|
|
@@ -7166,7 +7166,7 @@ export declare const getTrpcGuestClient: ({ url }?: {
|
|
|
7166
7166
|
tags: string[];
|
|
7167
7167
|
lang: "en" | "fr";
|
|
7168
7168
|
blogId: string;
|
|
7169
|
-
|
|
7169
|
+
targets: string[];
|
|
7170
7170
|
} & {
|
|
7171
7171
|
blog: {
|
|
7172
7172
|
id: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const workerSodiumScript = "let sodium;\n\nself.sodium = {\n onload: (sod) => {\n sodium = sod\n postMessage({ event: \"ready\" })\n }\n};\n\nimportScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@
|
|
1
|
+
export declare const workerSodiumScript = "let sodium;\n\nself.sodium = {\n onload: (sod) => {\n sodium = sod\n postMessage({ event: \"ready\" })\n }\n};\n\nimportScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@0.7.15/dist/browsers/sodium.js');\nimportScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');\n\nfunction* chunks(arr, n) {\n for (let i = 0; i < arr.length; i += n) {\n yield arr.slice(i, i + n);\n }\n}\n\nfunction assert(c, message) {\n if (!c) {\n throw new Error(message);\n }\n}\n\nfunction encrypt(key) {\n let destroyed = false;\n const {\n state,\n header\n } = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);\n\n const encrypt = (tag, plaintext) => {\n assert(destroyed === false, \"state already destroyed\");\n\n return sodium.crypto_secretstream_xchacha20poly1305_push(\n state,\n plaintext,\n null,\n tag\n );\n };\n\n function destroy() {\n assert(destroyed === false, \"state already destroyed\");\n destroyed = true;\n }\n\n return {\n encrypt,\n destroy,\n header\n };\n}\n\nfunction decrypt(header, key) {\n assert(\n header.byteLength >=\n sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES,\n \"header must be at least HEADERBYTES (\" + sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES + \") long\"\n );\n assert(\n key.byteLength >= sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES,\n \"key must be at least KEYBYTES (\" + sodium.crypto_secretstream_xchacha20poly1305_KEYBYTES + \") long\"\n );\n\n let destroyed = false;\n const state = sodium.crypto_secretstream_xchacha20poly1305_init_pull(\n header,\n key\n );\n\n const decrypt = ciphertext => {\n assert(destroyed === false, \"state already destroyed\");\n\n return sodium.crypto_secretstream_xchacha20poly1305_pull(state, ciphertext);\n };\n\n function destroy() {\n assert(destroyed === false, \"state already destroyed\");\n destroyed = true;\n }\n\n return {\n decrypt,\n destroy\n };\n}\n\nconst CHUNK_SIZE = 8192;\n\nasync function encryptSecretstream(key, data, progress) {\n const { encrypt: crypt, destroy, header } = encrypt(key);\n const cryptedChunk =\n CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;\n const max =\n Math.ceil(data.byteLength / CHUNK_SIZE) * cryptedChunk + header.byteLength;\n\n progress?.({\n percent: 0,\n total: max,\n current: 0\n });\n const final = new Uint8Array(max);\n const sparkEncrypted = new SparkMD5.ArrayBuffer();\n const spark = new SparkMD5.ArrayBuffer();\n\n final.set(header);\n sparkEncrypted.append(header);\n let total = header.byteLength;\n progress?.({\n percent: total / max,\n total: max,\n current: total\n });\n let lastPercent = total / max;\n\n for (const chunk of chunks(data, CHUNK_SIZE)) {\n spark.append(chunk);\n const tag =\n chunk.length < CHUNK_SIZE\n ? sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL\n : sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;\n const crypted = crypt(tag, chunk);\n sparkEncrypted.append(crypted);\n final.set(crypted, total);\n total += crypted.byteLength;\n const percent = total / max;\n if (percent > lastPercent + 0.01) {\n progress?.({\n percent,\n total: max,\n current: total\n });\n lastPercent = percent;\n }\n }\n\n destroy();\n progress?.({\n percent: 1,\n total,\n current: total\n });\n return {\n data: final.slice(0, total),\n md5Encrypted: sparkEncrypted.end(),\n md5: spark.end()\n };\n}\n\nasync function decryptSecretstream(key, data, progress) {\n const header = data.slice(\n 0,\n sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES\n );\n data = data.slice(sodium.crypto_secretstream_xchacha20poly1305_HEADERBYTES);\n\n const { decrypt: decryptt, destroy } = decrypt(header, key);\n const chunkSize =\n CHUNK_SIZE + sodium.crypto_secretstream_xchacha20poly1305_ABYTES;\n const max = Math.ceil(data.byteLength / chunkSize) * CHUNK_SIZE;\n\n progress?.({\n percent: 0,\n total: max,\n current: 0\n });\n const final = new Uint8Array(max);\n let total = 0;\n let lastPercent = total / max;\n\n for (const chunk of chunks(data, chunkSize)) {\n const tmp = decryptt(chunk);\n final.set(tmp.message, total);\n total += tmp.message.byteLength;\n\n const percent = total / max;\n if (percent > lastPercent + 0.01) {\n progress?.({\n percent,\n total: max,\n current: total\n });\n lastPercent = percent;\n }\n }\n\n destroy();\n progress?.({\n percent: 1,\n total,\n current: total\n });\n return final.slice(0, total);\n}\n\nself.onmessage = async ({ data }) => {\n switch (data.event) {\n case \"encrypt\": {\n postMessage({ event: \"working\" })\n postMessage({\n event: \"encrypt-result\",\n data: await encryptSecretstream(data.key, data.data, progress => postMessage({\n event: \"encrypt-progress\",\n data: progress\n }))\n });\n postMessage({ event: \"ready\" })\n break;\n }\n case \"decrypt\": {\n postMessage({ event: \"working\" })\n postMessage({\n event: \"decrypt-result\",\n data: await decryptSecretstream(data.key, data.data, progress => postMessage({\n event: \"decrypt-progress\",\n data: progress\n }))\n });\n postMessage({ event: \"ready\" })\n break;\n }\n }\n}";
|
|
2
2
|
export declare const workerMd5Script = "importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');\n\nfunction* chunks(arr, n) {\n for (let i = 0; i < arr.length; i += n) {\n yield arr.slice(i, i + n);\n }\n}\n\nconst CHUNK_SIZE = 8192;\n\nfunction md5(data) {\n const spark = new SparkMD5.ArrayBuffer();\n for (const chunk of chunks(data, CHUNK_SIZE)) {\n spark.append(chunk);\n }\n return spark.end();\n}\n\n\nself.onmessage = ({ data }) => {\n switch (data.event) {\n case \"md5\": {\n postMessage({\n event: \"md5-result\",\n data: md5(data.data)\n });\n break;\n }\n }\n}";
|
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.
|
|
5
|
+
"version": "1.85.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/anonymize-org/lib.git"
|
|
@@ -49,48 +49,48 @@
|
|
|
49
49
|
"semantic-release": "semantic-release"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@commitlint/cli": "^20.
|
|
53
|
-
"@commitlint/config-conventional": "^20.
|
|
52
|
+
"@commitlint/cli": "^20.3.0",
|
|
53
|
+
"@commitlint/config-conventional": "^20.3.0",
|
|
54
54
|
"@prisma/client": "6.17.1",
|
|
55
|
-
"@types/bun": "^1.3.
|
|
55
|
+
"@types/bun": "^1.3.5",
|
|
56
56
|
"@types/jsonwebtoken": "^9.0.10",
|
|
57
57
|
"@types/spark-md5": "^3.0.5",
|
|
58
58
|
"@types/streamsaver": "^2.0.5",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
60
|
-
"@typescript-eslint/parser": "^8.
|
|
61
|
-
"eslint": "^9.
|
|
62
|
-
"eslint-config-love": "^
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
60
|
+
"@typescript-eslint/parser": "^8.52.0",
|
|
61
|
+
"eslint": "^9.39.2",
|
|
62
|
+
"eslint-config-love": "^140.0.0",
|
|
63
63
|
"eslint-config-prettier": "^10.1.8",
|
|
64
64
|
"eslint-plugin-import": "^2.32.0",
|
|
65
65
|
"eslint-plugin-n": "^17.23.1",
|
|
66
66
|
"eslint-plugin-promise": "^7.2.1",
|
|
67
67
|
"husky": "^9.1.7",
|
|
68
68
|
"npm-run-all": "^4.1.5",
|
|
69
|
-
"prettier": "^3.
|
|
70
|
-
"rimraf": "^6.
|
|
71
|
-
"semantic-release": "^
|
|
72
|
-
"typedoc": "^0.28.
|
|
69
|
+
"prettier": "^3.7.4",
|
|
70
|
+
"rimraf": "^6.1.2",
|
|
71
|
+
"semantic-release": "^25.0.2",
|
|
72
|
+
"typedoc": "^0.28.15",
|
|
73
73
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
74
74
|
"typedoc-plugin-missing-exports": "^4.1.2",
|
|
75
75
|
"typescript": "^5.9.3"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@js-temporal/polyfill": "^0.5.1",
|
|
79
|
-
"@secrecy/trpc-api-types": "1.
|
|
79
|
+
"@secrecy/trpc-api-types": "1.40.1",
|
|
80
80
|
"@trpc/client": "11.6.0",
|
|
81
81
|
"@trpc/server": "^11.6.0",
|
|
82
82
|
"@types/libsodium-wrappers-sumo": "^0.7.8",
|
|
83
|
-
"axios": "^1.
|
|
84
|
-
"bson": "^
|
|
85
|
-
"ethers": "^6.
|
|
86
|
-
"file-type": "^21.
|
|
87
|
-
"jsonwebtoken": "^9.0.
|
|
88
|
-
"ky": "^1.
|
|
89
|
-
"libsodium-wrappers-sumo": "^0.
|
|
90
|
-
"lru-cache": "^11.2.
|
|
83
|
+
"axios": "^1.13.2",
|
|
84
|
+
"bson": "^7.0.0",
|
|
85
|
+
"ethers": "^6.16.0",
|
|
86
|
+
"file-type": "^21.3.0",
|
|
87
|
+
"jsonwebtoken": "^9.0.3",
|
|
88
|
+
"ky": "^1.14.2",
|
|
89
|
+
"libsodium-wrappers-sumo": "^0.8.0",
|
|
90
|
+
"lru-cache": "^11.2.4",
|
|
91
91
|
"spark-md5": "^3.0.2",
|
|
92
92
|
"streamsaver": "^2.0.6",
|
|
93
|
-
"superjson": "2.2.
|
|
94
|
-
"zod": "4.
|
|
93
|
+
"superjson": "2.2.6",
|
|
94
|
+
"zod": "4.3.5"
|
|
95
95
|
}
|
|
96
96
|
}
|