WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@MasterKale
Copy link
Owner

This PR refactors @simplewebauthn/browser and @simplewebauthn/server to support use in Deno projects running Deno v2.2+.

Deno v2.2 launched with TypeScript 5.7. In this version of TypeScript, Uint8Array was made generic, to be of type Uint8Array<ArrayBufferLike>. Existing values typed simply as Uint8Array now needed to be refactored to specify the type of their array buffer:

Before

const value: Uint8Array = new Uint8Array();

After

const value: Uint8Array<ArrayBuffer> = new Uint8Array<ArrayBuffer>();

Unfortunately "simply refactoring all instances of Uint8Array" to specify a buffer type would break the code in Deno v2.1 and earlier where Uint8Array is not generic.

To support both runtimes, I took a page out of Deno's handbook and defined a new Uint8Array_ type instead. This type is equivalent to non-generic Uint8Array in Deno v2.1 and earlier, and equivalent to Uint8Array<ArrayBuffer> in Deno v2.2 and beyond.

I'm not entirely happy with how this bit of Deno runtime changes gets exposed in the public API of the project. I'm keeping my fingers crossed that it'll be transparent to most everyone. A more succinct copy of all of the context above has been included in the docstring for Uint8Array_ for those who go digging.

@MasterKale MasterKale added package:browser @simplewebauthn/browser package:server @simplewebauthn/server labels Aug 22, 2025
@MasterKale MasterKale merged commit a1a3d4d into master Aug 22, 2025
4 checks passed
@MasterKale MasterKale deleted the fix/deno-2-4-support branch August 22, 2025 23:29
@MasterKale MasterKale added this to the v13.2.0 milestone Aug 22, 2025
@P4sca1
Copy link
Contributor

P4sca1 commented Oct 7, 2025

Hey @MasterKale, for my implementation this change introduced a type error.
credential.publicKey now expects Uint8Array<ArrayBuffer>, but my database driver (prisma) returns Uint8Array<ArrayBufferLike>. For now I resolved the type error, by instantiating a new Uint8Array with the same content:

// Before:
publicKey:passkey.publicKey,

// After:
publicKey: new Uint8Array(passkey.publicKey),

@MasterKale
Copy link
Owner Author

@P4sca1 thanks for sharing that, the move to Deno 2.4 (specifically its upgrading to TypeScript 5.7) has I'm sure created a ton of headaches for devs like you. It's definitely making a ton of trouble for library maintainers like me as the "Uint8Array_" trick I went with in here exposes the internal workings of TypeScript in a way I don't typically like to do.

The only way I know to get an "old-style" Uint8Array into a new, non-generic Uint8Array in Deno 2.4+ is to do as you did and drop the value into a new Uint8Array(...) wherever you have such a type error.

And as for anything I might do in SimpleWebAuthn to help alleviate this problem, I think I've done all I can. The way I see it it'd have to be Prisma that updates to communicate that it's returning Uint8Array<ArrayBuffer> to help devs like you skip that step 🙀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package:browser @simplewebauthn/browser package:server @simplewebauthn/server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants