File tree Expand file tree Collapse file tree 3 files changed +6
-12
lines changed Expand file tree Collapse file tree 3 files changed +6
-12
lines changed Original file line number Diff line number Diff line change 1
- import { concatBytes , crypto , equalsBytes } from "./utils" ;
1
+ import { crypto } from "@noble/hashes/crypto" ;
2
+ import { concatBytes , equalsBytes } from "./utils" ;
2
3
3
4
function validateOpt ( key : Uint8Array , iv : Uint8Array , mode : string ) {
4
5
if ( ! mode . startsWith ( "aes-" ) ) {
Original file line number Diff line number Diff line change 1
1
import { pbkdf2 , pbkdf2Async } from "@noble/hashes/pbkdf2" ;
2
2
import { sha256 } from "@noble/hashes/sha256" ;
3
3
import { sha512 } from "@noble/hashes/sha512" ;
4
- import { assertBytes , assertNumber } from "@noble/hashes/utils" ;
4
+ import { assertBytes , assertNumber , randomBytes } from "@noble/hashes/utils" ;
5
5
import { utils as baseUtils } from "micro-base" ;
6
- import { getRandomBytesSync } from "../random" ;
7
6
8
7
const isJapanese = ( wordlist : string [ ] ) =>
9
8
wordlist [ 0 ] === "\u3042\u3044\u3053\u304f\u3057\u3093" ; // Japanese wordlist
@@ -27,7 +26,7 @@ export function generateMnemonic(
27
26
if ( strength % 32 !== 0 ) {
28
27
throw new TypeError ( "Invalid entropy" ) ;
29
28
}
30
- return entropyToMnemonic ( getRandomBytesSync ( strength / 8 ) , wordlist ) ;
29
+ return entropyToMnemonic ( randomBytes ( strength / 8 ) , wordlist ) ;
31
30
}
32
31
33
32
const checksum = ( entropy : Uint8Array ) => {
Original file line number Diff line number Diff line change 1
- import { crypto } from ". /utils" ;
1
+ import { randomBytes } from "@noble/hashes /utils" ;
2
2
3
3
export function getRandomBytesSync ( bytes : number ) : Uint8Array {
4
- if ( crypto . web ) {
5
- return crypto . web . getRandomValues ( new Uint8Array ( bytes ) ) ;
6
- } else if ( crypto . node ) {
7
- return new Uint8Array ( crypto . node . randomBytes ( bytes ) . buffer ) ;
8
- } else {
9
- throw new Error ( "The environment doesn't have randomBytes function" ) ;
10
- }
4
+ return randomBytes ( bytes ) ;
11
5
}
12
6
13
7
export async function getRandomBytes ( bytes : number ) : Promise < Uint8Array > {
You can’t perform that action at this time.
0 commit comments