Skip to content

Commit cb84548

Browse files
authored
Remove argon2 dependency on esm.sh (#113)
* Remove argon2 dependency on esm.sh * Remove vite-plugin-wasm (oops)
1 parent a4ff9cc commit cb84548

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@rgossiaux/svelte-headlessui": "^2.0.0",
1717
"@tldraw/vec": "^1.9.2",
1818
"@use-gesture/vanilla": "^10.2.27",
19+
"argon2-browser": "^1.18.0",
1920
"buffer": "^6.0.3",
2021
"cbor-x": "^1.6.0",
2122
"firacode": "^6.2.0",

src/lib/encrypt.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@ export class Encrypt {
1212
private constructor(private aesKey: CryptoKey) {}
1313

1414
static async new(key: string): Promise<Encrypt> {
15-
const { Argon2, Argon2Mode } = await import(
16-
"https://esm.sh/@sphereon/isomorphic-argon2@1.0.1" as any
15+
const argon2 = await import(
16+
"argon2-browser/dist/argon2-bundled.min.js" as any
1717
);
18-
const result = await Argon2.hash(key, SALT, {
19-
mode: Argon2Mode.Argon2id,
20-
memory: 19 * 1024,
21-
iterations: 2,
18+
const result = await argon2.hash({
19+
pass: key,
20+
salt: SALT,
21+
type: argon2.ArgonType.Argon2id,
22+
mem: 19 * 1024, // Memory cost in KiB
23+
time: 2, // Number of iterations
2224
parallelism: 1,
23-
hashLength: 16,
25+
hashLen: 16, // Hash length in bytes
2426
});
2527
const aesKey = await crypto.subtle.importKey(
2628
"raw",
2729
Uint8Array.from(
28-
result.hex.match(/.{1,2}/g).map((byte: string) => parseInt(byte, 16)),
30+
result.hashHex
31+
.match(/.{1,2}/g)
32+
.map((byte: string) => parseInt(byte, 16)),
2933
),
3034
{ name: "AES-CTR" },
3135
false,

0 commit comments

Comments
 (0)