Skip to content

Commit

Permalink
Remove argon2 dependency on esm.sh (#113)
Browse files Browse the repository at this point in the history
* Remove argon2 dependency on esm.sh

* Remove vite-plugin-wasm (oops)
  • Loading branch information
ekzhang authored Jan 15, 2025
1 parent a4ff9cc commit cb84548
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@rgossiaux/svelte-headlessui": "^2.0.0",
"@tldraw/vec": "^1.9.2",
"@use-gesture/vanilla": "^10.2.27",
"argon2-browser": "^1.18.0",
"buffer": "^6.0.3",
"cbor-x": "^1.6.0",
"firacode": "^6.2.0",
Expand Down
20 changes: 12 additions & 8 deletions src/lib/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ export class Encrypt {
private constructor(private aesKey: CryptoKey) {}

static async new(key: string): Promise<Encrypt> {
const { Argon2, Argon2Mode } = await import(
"https://esm.sh/@sphereon/isomorphic-argon2@1.0.1" as any
const argon2 = await import(
"argon2-browser/dist/argon2-bundled.min.js" as any
);
const result = await Argon2.hash(key, SALT, {
mode: Argon2Mode.Argon2id,
memory: 19 * 1024,
iterations: 2,
const result = await argon2.hash({
pass: key,
salt: SALT,
type: argon2.ArgonType.Argon2id,
mem: 19 * 1024, // Memory cost in KiB
time: 2, // Number of iterations
parallelism: 1,
hashLength: 16,
hashLen: 16, // Hash length in bytes
});
const aesKey = await crypto.subtle.importKey(
"raw",
Uint8Array.from(
result.hex.match(/.{1,2}/g).map((byte: string) => parseInt(byte, 16)),
result.hashHex
.match(/.{1,2}/g)
.map((byte: string) => parseInt(byte, 16)),
),
{ name: "AES-CTR" },
false,
Expand Down

0 comments on commit cb84548

Please sign in to comment.