Skip to content

Commit 72ddb86

Browse files
committed
crypto: use @scure/bip39
1 parent c64847d commit 72ddb86

File tree

7 files changed

+60
-2215
lines changed

7 files changed

+60
-2215
lines changed

.pnp.cjs

Lines changed: 23 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:c1418d1af628db45a47de1fe940d1cc2f6cb36733e9c9b51ae5931108d6cf76b
3+
size 685555
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:4a411036cb2d0f07e6b72a92a3138d67813c96fa31f190cfb3a16d6190ecff74
3+
size 202966

packages/crypto/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@noble/ciphers": "^1.3.0",
4646
"@noble/curves": "^1.9.2",
4747
"@noble/hashes": "^1.8.0",
48+
"@scure/bip39": "^2.0.1",
4849
"hash-wasm": "^4.12.0"
4950
},
5051
"devDependencies": {

packages/crypto/src/bip39.spec.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,10 @@
11
import { fromAscii, fromBase64, fromHex } from "@cosmjs/encoding";
22

3-
import { Bip39, EnglishMnemonic, entropyToMnemonic, mnemonicToEntropy } from "./bip39";
3+
import { Bip39, EnglishMnemonic } from "./bip39";
44
import { sha256 } from "./sha";
55
import bip39Vectors from "./testdata/bip39.json";
66
import wordlists from "./testdata/bip39_wordlists.json";
77

8-
describe("entropyToMnemonic", () => {
9-
it("works", () => {
10-
// From https://iancoleman.io/bip39/
11-
expect(entropyToMnemonic(fromHex("a323224e6b13d31942509dc4e2e579be3d5bb7f2"))).toEqual(
12-
"permit boil near stomach diamond million announce beauty shaft blame fury ladder stick swim slab",
13-
);
14-
});
15-
16-
it("works for all the test vectors", () => {
17-
// Test vectors from https://github.com/trezor/python-mnemonic/blob/b502451a33a440783926e04428115e0bed87d01f/vectors.json
18-
// plus similar vectors generated for the missing lengths 15 and 21 words
19-
const { "12": vec12, "15": vec15, "18": vec18, "21": vec21, "24": vec24 } = bip39Vectors.encoding;
20-
for (const vectors of [vec12, vec15, vec18, vec21, vec24]) {
21-
for (const { entropy, mnemonic } of vectors) {
22-
expect(entropyToMnemonic(fromHex(entropy))).toEqual(mnemonic);
23-
}
24-
}
25-
});
26-
});
27-
28-
describe("mnemonicToEntropy", () => {
29-
it("works", () => {
30-
// From https://iancoleman.io/bip39/
31-
expect(
32-
mnemonicToEntropy(
33-
"permit boil near stomach diamond million announce beauty shaft blame fury ladder stick swim slab",
34-
),
35-
).toEqual(fromHex("a323224e6b13d31942509dc4e2e579be3d5bb7f2"));
36-
});
37-
38-
it("works for all the test vectors", () => {
39-
const { "12": vec12, "15": vec15, "18": vec18, "21": vec21, "24": vec24 } = bip39Vectors.encoding;
40-
for (const vectors of [vec12, vec15, vec18, vec21, vec24]) {
41-
for (const { entropy, mnemonic } of vectors) {
42-
expect(mnemonicToEntropy(mnemonic)).toEqual(fromHex(entropy));
43-
}
44-
}
45-
});
46-
});
47-
488
describe("Bip39", () => {
499
describe("encode", () => {
5010
it("can encode to mnemonic", () => {

0 commit comments

Comments
 (0)