Skip to content

Commit 7b65103

Browse files
committed
migrate to argon2id from hash-wasm
1 parent 072243d commit 7b65103

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

.pnp.cjs

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:505d7271f3fa67b1baedc9c0259b5c37dcfdbd8a3334f962266468c4945b9de0
3+
size 1820660

packages/crypto/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"@cosmjs/utils": "workspace:^",
4343
"@noble/ciphers": "^1.3.0",
4444
"@noble/curves": "^1.9.2",
45-
"@noble/hashes": "^1"
45+
"@noble/hashes": "^1",
46+
"hash-wasm": "^4.12.0"
4647
},
4748
"devDependencies": {
4849
"@istanbuljs/nyc-config-typescript": "^1.0.1",

packages/crypto/src/libsodium.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { isNonNullObject } from "@cosmjs/utils";
1+
import { assert, isNonNullObject } from "@cosmjs/utils";
22
import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
33
import { ed25519 } from "@noble/curves/ed25519.js";
4-
import { type ArgonOpts, argon2id } from "@noble/hashes/argon2.js";
4+
import { type IArgon2Options, argon2id } from "hash-wasm";
55

66
export interface Argon2idOptions {
77
/** Output length in bytes */
@@ -36,18 +36,24 @@ export class Argon2id {
3636
salt: Uint8Array,
3737
options: Argon2idOptions,
3838
): Promise<Uint8Array> {
39-
const opts: ArgonOpts = {
40-
t: options.opsLimit,
41-
m: options.memLimitKib,
42-
p: 1, // no parallelism allowed, just like libsodium
43-
dkLen: options.outputLength,
39+
const opts: IArgon2Options = {
40+
password,
41+
salt,
42+
outputType: "binary",
43+
iterations: options.opsLimit,
44+
memorySize: options.memLimitKib,
45+
parallelism: 1, // no parallelism allowed, just like libsodium
46+
hashLength: options.outputLength,
4447
};
4548

4649
if (salt.length !== 16) {
4750
throw new Error(`Got invalid salt length ${salt.length}. Must be 16.`);
4851
}
4952

50-
return argon2id(password, salt, opts);
53+
const hash = await argon2id(opts);
54+
// guaranteed by outputType: 'binary'
55+
assert(typeof hash !== "string");
56+
return hash;
5157
}
5258
}
5359

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ __metadata:
333333
"@types/node": "npm:*"
334334
buffer: "npm:^6.0.3"
335335
glob: "npm:^11"
336+
hash-wasm: "npm:^4.12.0"
336337
jasmine: "npm:^4"
337338
jasmine-spec-reporter: "npm:^6"
338339
karma: "npm:^6.3.14"
@@ -4601,6 +4602,13 @@ __metadata:
46014602
languageName: node
46024603
linkType: hard
46034604

4605+
"hash-wasm@npm:^4.12.0":
4606+
version: 4.12.0
4607+
resolution: "hash-wasm@npm:4.12.0"
4608+
checksum: 10c0/6cb95055319810b6f673de755289960683a9831807690795f0e8918b2fd7e6ae5b82a9dc47cbace171cf2814b412ef68c315a0ead0b4d96bd3e56a05e4bde136
4609+
languageName: node
4610+
linkType: hard
4611+
46044612
"hasha@npm:^5.0.0":
46054613
version: 5.2.2
46064614
resolution: "hasha@npm:5.2.2"

0 commit comments

Comments
 (0)