Skip to content

Commit 1354803

Browse files
authored
Remove Node.js 15 and 16 support from getSubtle() (#1781)
1 parent 89fb431 commit 1354803

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/crypto/src/pbkdf2.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ import { assert } from "@cosmjs/utils";
22
import { pbkdf2Async as noblePbkdf2Async } from "@noble/hashes/pbkdf2";
33
import { 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+
*/
512
export 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

2122
export async function pbkdf2Sha512Subtle(

0 commit comments

Comments
 (0)