Skip to content

Commit 4c02665

Browse files
committed
Use assertBytes from noble-hashes
1 parent 7956729 commit 4c02665

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
],
2626
"dependencies": {
2727
"micro-base": "^0.10.0",
28-
"@noble/hashes": "^0.5.1",
28+
"@noble/hashes": "^0.5.2",
2929
"@noble/secp256k1": "^1.3.3"
3030
},
3131
"browser": {

src/bip39/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { pbkdf2, pbkdf2Async } from "@noble/hashes/pbkdf2";
22
import { sha256 } from "@noble/hashes/sha256";
33
import { sha512 } from "@noble/hashes/sha512";
4-
import { assertNumber } from "@noble/hashes/utils";
4+
import { assertBytes, assertNumber } from "@noble/hashes/utils";
55
import { utils as baseUtils } from "micro-base";
66
import { getRandomBytesSync } from "../random";
7-
import { assertBytes } from "../utils";
87

98
const isJapanese = (wordlist: string[]) =>
109
wordlist[0] === "\u3042\u3044\u3053\u304f\u3057\u3093"; // Japanese wordlist

src/utils.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// buf.toString('hex') -> toHex(buf)
2-
export { bytesToHex as toHex, createView } from "@noble/hashes/utils";
2+
import { assertBytes } from "@noble/hashes/utils";
3+
export { bytesToHex as toHex, assertBytes, createView } from "@noble/hashes/utils";
34
// Buffer.from(hex, 'hex') -> hexToBytes(hex)
45
export function hexToBytes(hex: string): Uint8Array {
56
if (typeof hex !== "string") {
@@ -56,18 +57,6 @@ export function concatBytes(...arrays: Uint8Array[]): Uint8Array {
5657
return result;
5758
}
5859
// Internal utils
59-
export function assertBytes(bytes: Uint8Array, ...len: number[]) {
60-
if (
61-
bytes instanceof Uint8Array &&
62-
(!len.length || len.includes(bytes.length))
63-
) {
64-
return;
65-
}
66-
throw new TypeError(
67-
`Expected ${len} bytes, not ${typeof bytes} with length=${bytes.length}`
68-
);
69-
}
70-
7160
export function assertBool(b: boolean) {
7261
if (typeof b !== "boolean") {
7362
throw new Error(`Expected boolean, not ${b}`);

0 commit comments

Comments
 (0)