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

Update `getWebCrypto()` for Node 20 #532

Closed MasterKale closed 8 months ago

MasterKale commented 9 months ago

Describe the issue

Once #519 raises the minimum supported Node version to v20 then getWebCrypto() can consistently access WebCrypto at globalThis.crypto instead of having to require('node:crypto'). This is an issue to track this work while I continue working on the v10 release.

Node docs related to using globalThis.crypto to access WebCrypto:

https://nodejs.org/docs/latest-v20.x/api/webcrypto.html#web-crypto-api

MasterKale commented 8 months ago

A poll on Mastodon didn't help me choose between "change only a couple of files by keeping getWebCrypto() asynchronous" and "change a bunch of files by making getWebCrypto() synchronous because it doesn't need async anymore":

image

So I prepard two PRs:

Honestly I'm leaning towards #535 for what feels like an odd justification: not making generateRegistrationOptions() and generateAuthenticationOptions() synchronous means all four of the "core library API" methods (those two along with verifyRegistrationResponse() and verifyAuthenticationResponse()) remain asynchronous. Put another way, keeping getWebCrypto() asynchronous means there's no need to remember which core library methods need to be awaited or not because they all need to be await'd!

I'm gonna sleep on this for a few days and see what I settle on.

MasterKale commented 7 months ago

This change is now available in the recently-published @simplewebauthn/server@10.0.0 ✌️