Switch sha256 to be synchronous in @turnkey/webauthn-stamper
#179
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary & Motivation
Bug discovered by @SimonVillage in tkhq/demo-passkey-wallet#3: on ios/safari, cancelling the passkey prompt results in subsequent prompts automatically failing. The reason why: ios is stricter than other browsers when deciding whether a passkey prompt can be triggered or not. This blog post has more information on this, but TL;DR: you need to have a maximum of one async promise between a user gesture (tap, click) and the code triggering a passkey prompt.
In our SDK we use
crypto.subtle.digest
to compute the SHA256 of the message to sign:sdk/packages/webauthn-stamper/src/index.ts
Line 72 in bed2bea
This means we have an async promise between a button click and the call to
navigator.credentials.get
, causing iOS to fail. The fix? Use a synchonous version of sha256.@noble/hashes
is a great oneHow I Tested These Changes
Used the federated passkey example on my localhost, and reached the demo through an ngrok tunnel. I was able to repro the issue to start with, and observe it fixed after I replaced sha256 with the synchronous variant.