File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -2,20 +2,21 @@ import { assert } from "@cosmjs/utils";
22import { pbkdf2Async as noblePbkdf2Async } from "@noble/hashes/pbkdf2" ;
33import { sha512 as nobleSha512 } from "@noble/hashes/sha2.js" ;
44
5+ /**
6+ * Returns the SubtleCrypto API for this environment if present.
7+ *
8+ * Right now (CosmJS 0.35), all supported environments we are aware of have
9+ * SubtleCrypto. However, we keep the optional return type just in case as we can
10+ * use the pure-JS fallback.
11+ */
512export async function getSubtle ( ) : Promise < typeof crypto . subtle | undefined > {
613 // From Node.js 15 onwards, webcrypto is available in globalThis.
714 // In version 15 and 16 this was stored under the webcrypto key.
815 // With Node.js 17 it was moved to the same locations where browsers
916 // make it available.
1017 // Loading `require("crypto")` here seems unnecessary since it only
1118 // causes issues with bundlers and does not increase compatibility.
12-
13- // Browsers and Node.js 17+
14- let subtle : typeof crypto . subtle | undefined = ( globalThis as any ) ?. crypto ?. subtle ;
15- // Node.js 15+
16- if ( ! subtle ) subtle = ( globalThis as any ) ?. crypto ?. webcrypto ?. subtle ;
17-
18- return subtle ;
19+ return ( globalThis as any ) ?. crypto ?. subtle ;
1920}
2021
2122export async function pbkdf2Sha512Subtle (
You can’t perform that action at this time.
0 commit comments