MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.62k stars 137 forks source link

fix/471-more-resilient-getwebcrypto #472

Closed MasterKale closed 1 year ago

MasterKale commented 1 year ago

This PR refines the changes made to getWebCrypto() in #468 by moving the try / catch into _getWebCryptoInternals.stubThisImportNodeCrypto. This should prevent non-Node runtimes from A) getting hung up on the use of import() or B) trying to use it to import a Node-specific identifier.

Fixes #471.

In an effort to confirm the fix, I tested these changes in the following "edge runtimes":

I tested with the following code:

import { generateAuthenticationOptions } from '@simplewebauthn/server';

// ...

const opts = await generateAuthenticationOptions(); 

Proof

Astro

Screenshot 2023-10-27 at 8 48 10 PM

CloudFlare Worker

Screenshot 2023-10-27 at 8 42 20 PM