@secrecy/lib 1.84.0 → 1.84.1
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.
|
@@ -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) {
|
|
@@ -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.84.
|
|
5
|
+
"version": "1.84.1",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/anonymize-org/lib.git"
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"npm-run-all": "^4.1.5",
|
|
69
69
|
"prettier": "^3.6.2",
|
|
70
70
|
"rimraf": "^6.0.1",
|
|
71
|
-
"semantic-release": "^
|
|
71
|
+
"semantic-release": "^25.0.2",
|
|
72
72
|
"typedoc": "^0.28.14",
|
|
73
73
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
74
74
|
"typedoc-plugin-missing-exports": "^4.1.2",
|