mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Pull out and fix getSubtle()
This commit is contained in:
parent
956b5379a3
commit
9603a1da46
@ -2177,6 +2177,18 @@ export class EnglishMnemonic {
|
||||
}
|
||||
}
|
||||
|
||||
async function getSubtle(): Promise<any | undefined> {
|
||||
const g: any = globalThis;
|
||||
let subtle = g.crypto && g.crypto.subtle;
|
||||
if (!subtle) {
|
||||
const crypto: any = await import("crypto");
|
||||
if (crypto.webcrypto && crypto.webcrypto.subtle) {
|
||||
subtle = crypto.webcrypto.subtle;
|
||||
}
|
||||
}
|
||||
return subtle;
|
||||
}
|
||||
|
||||
export class Bip39 {
|
||||
/**
|
||||
* Encodes raw entropy of length 16, 20, 24, 28 or 32 bytes as an English mnemonic between 12 and 24 words.
|
||||
@ -2215,13 +2227,7 @@ export class Bip39 {
|
||||
iterations: number,
|
||||
keylen: number,
|
||||
): Promise<Uint8Array> {
|
||||
const g: any = globalThis;
|
||||
let subtle = g.crypto && g.crypto.subtle;
|
||||
if (!subtle) {
|
||||
const crypto = await import("crypto");
|
||||
subtle = (crypto as any).webcrypto.subtle;
|
||||
}
|
||||
|
||||
const subtle = await getSubtle();
|
||||
if (subtle) {
|
||||
return subtle
|
||||
.importKey("raw", secret, { name: "PBKDF2" }, false, ["deriveBits"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user