Skip to content

Commit 9169c09

Browse files
committed
migrate to argon2id from @noble/hashes
1 parent 81a7b5d commit 9169c09

File tree

6 files changed

+14
-71
lines changed

6 files changed

+14
-71
lines changed

.pnp.cjs

Lines changed: 0 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/cache/libsodium-sumo-npm-0.7.11-aaac6bcc6c-f7518d1781.zip

Lines changed: 0 additions & 3 deletions
This file was deleted.

.yarn/cache/libsodium-wrappers-sumo-npm-0.7.11-08fe1b2cf4-81270738b3.zip

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/crypto/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
"@cosmjs/utils": "workspace:^",
4343
"@noble/ciphers": "^1.3.0",
4444
"@noble/curves": "^1.9.2",
45-
"@noble/hashes": "^1",
46-
"libsodium-wrappers-sumo": "^0.7.11"
45+
"@noble/hashes": "^1"
4746
},
4847
"devDependencies": {
4948
"@istanbuljs/nyc-config-typescript": "^1.0.1",

packages/crypto/src/libsodium.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
// Keep all classes requiring libsodium-js in one file as having multiple
2-
// requiring of the libsodium-wrappers module currently crashes browsers
3-
//
4-
// libsodium.js API: https://gist.github.com/webmaster128/b2dbe6d54d36dd168c9fabf441b9b09c
5-
61
import { isNonNullObject } from "@cosmjs/utils";
72
import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
83
import { ed25519 } from "@noble/curves/ed25519.js";
9-
// Using crypto_pwhash requires sumo. Once we migrate to a standalone
10-
// Argon2 implementation, we can use the normal libsodium-wrappers
11-
// again: https://github.com/cosmos/cosmjs/issues/1031
12-
import sodium from "libsodium-wrappers-sumo";
4+
import { type ArgonOpts, argon2id } from "@noble/hashes/argon2.js";
135

146
export interface Argon2idOptions {
157
/** Output length in bytes */
@@ -44,15 +36,18 @@ export class Argon2id {
4436
salt: Uint8Array,
4537
options: Argon2idOptions,
4638
): Promise<Uint8Array> {
47-
await sodium.ready;
48-
return sodium.crypto_pwhash(
49-
options.outputLength,
50-
password,
51-
salt, // libsodium only supports 16 byte salts and will throw when you don't respect that
52-
options.opsLimit,
53-
options.memLimitKib * 1024,
54-
sodium.crypto_pwhash_ALG_ARGON2ID13,
55-
);
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,
44+
};
45+
46+
if (salt.length !== 16) {
47+
throw new Error(`Got invalid salt length ${salt.length}. Must be 16.`);
48+
}
49+
50+
return argon2id(password, salt, opts);
5651
}
5752
}
5853

yarn.lock

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ __metadata:
340340
karma-firefox-launcher: "npm:^2.1.0"
341341
karma-jasmine: "npm:^5"
342342
karma-jasmine-html-reporter: "npm:^1.5.4"
343-
libsodium-wrappers-sumo: "npm:^0.7.11"
344343
nyc: "npm:^15.1.0"
345344
prettier: "npm:^3.5.3"
346345
ses: "npm:^1.13.0"
@@ -5616,22 +5615,6 @@ __metadata:
56165615
languageName: node
56175616
linkType: hard
56185617

5619-
"libsodium-sumo@npm:^0.7.11":
5620-
version: 0.7.11
5621-
resolution: "libsodium-sumo@npm:0.7.11"
5622-
checksum: 10c0/f7518d178148d17c04d716898ea8aa5c5ebc302920ff67258a1fbe52e9d4605bb4a9912541db06bce7c16bde9a3af86110b749c869846d087a1b64a921007db8
5623-
languageName: node
5624-
linkType: hard
5625-
5626-
"libsodium-wrappers-sumo@npm:^0.7.11":
5627-
version: 0.7.11
5628-
resolution: "libsodium-wrappers-sumo@npm:0.7.11"
5629-
dependencies:
5630-
libsodium-sumo: "npm:^0.7.11"
5631-
checksum: 10c0/81270738b3e7c50910c34e161aa34d84ab6fbfe9e5256561fc279498b594cb3b090c58ec19d40ada67dc24e7f1f7e018d9fd68d2ae367196116164795b6d2896
5632-
languageName: node
5633-
linkType: hard
5634-
56355618
"linkify-it@npm:^5.0.0":
56365619
version: 5.0.0
56375620
resolution: "linkify-it@npm:5.0.0"

0 commit comments

Comments
 (0)