Skip to content

Commit

Permalink
fix: default to polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
kwikwag committed Dec 17, 2023
1 parent cca9547 commit 1b9ea80
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ function isNode() {
// Import webcrypto
let webcrypto;
const __setWebCrypto = async () => {
const usePolyfill = async () => {
return import("@peculiar/webcrypto").then(m => {
webcrypto = new m.Crypto();
});
}

Check failure on line 38 in lib/toolbox.js

View workflow job for this annotation

GitHub Actions / test_node (ubuntu-latest, 18.x)

Missing semicolon

Check failure on line 38 in lib/toolbox.js

View workflow job for this annotation

GitHub Actions / test_node (ubuntu-latest, 20.x)

Missing semicolon

Check failure on line 38 in lib/toolbox.js

View workflow job for this annotation

GitHub Actions / test_node (macos-latest, 18.x)

Missing semicolon

if (isNode()) {
// Always use node webcrypto if available ( >= 16.0 )
return import("crypto").then(m => {
webcrypto = m.webcrypto;
}).catch(() => {
// Fallback to @peculiar/webcrypto
return import("@peculiar/webcrypto").then(m => {
webcrypto = new m.Crypto();
});
});
}).catch(usePolyfill);
}
if ((typeof self !== "undefined") && "crypto" in self) {
// Always use crypto if available natively (browser / Deno)
webcrypto = self.crypto;
return;
}
throw new Error("Environment is neither Node nor WebCrypto-enabled " +
"browser; no crypto support. If running on an older browser, consider " +
"using a WebCrypto polyfill.");
// Some environment without WebCrypto; use a polyfill
return usePolyfill();
};
let ready = __setWebCrypto();

Expand Down

0 comments on commit 1b9ea80

Please sign in to comment.