Skip to content

Commit d316d2b

Browse files
committed
Remove DOM dependency. Use any type for TextEncoder, webcrypto. Closes #66, #75
1 parent b973b76 commit d316d2b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export {
1212
utf8ToBytes
1313
} from "@noble/hashes/utils";
1414

15+
// Global symbols in both browsers and Node.js since v11
16+
// See https://github.com/microsoft/TypeScript/issues/31535
17+
declare const TextEncoder: any;
18+
declare const TextDecoder: any;
19+
1520
// buf.toString('utf8') -> bytesToUtf8(buf)
1621
export function bytesToUtf8(data: Uint8Array): string {
1722
if (!(data instanceof Uint8Array)) {
@@ -46,9 +51,10 @@ export function wrapHash(hash: (msg: Uint8Array) => Uint8Array) {
4651
};
4752
}
4853

49-
export const crypto: { node?: any; web?: Crypto } = (() => {
54+
// TODO(v3): switch away from node crypto, remove this unnecessary variable.
55+
export const crypto: { node?: any; web?: any } = (() => {
5056
const webCrypto =
51-
typeof self === "object" && "crypto" in self ? self.crypto : undefined;
57+
typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : undefined;
5258
const nodeRequire =
5359
typeof module !== "undefined" &&
5460
typeof module.require === "function" &&

0 commit comments

Comments
 (0)