mirror of
https://github.com/documenso/documenso.git
synced 2026-06-22 04:12:06 +10:00
fabd69bd62
The v9 packages are deprecated. This updates to v13 which includes breaking API changes: optionsJSON wrapper for auth functions, renamed properties (authenticator→credential), and base64 encoding for credential IDs via isoBase64URL helper.
7.8 KiB
7.8 KiB
date, title
| date | title |
|---|---|
| 2026-01-14 | Simplewebauthn V13 Upgrade |
Overview
Upgrade SimpleWebAuthn packages from v9.x to v13.x to address the deprecation of @simplewebauthn/types and take advantage of new features and improvements.
Current State
The codebase currently uses:
@simplewebauthn/browser@9.x@simplewebauthn/server@9.x@simplewebauthn/types@9.x
Breaking Changes Summary (v9 → v13)
v10.0.0 Breaking Changes
- Minimum Node version raised to Node v20
generateRegistrationOptions()now expectsBase64URLStringforexcludeCredentialsIDs (no moretype: 'public-key'needed)generateAuthenticationOptions()now expectsBase64URLStringforallowCredentialsIDscredentialIDreturned from verification methods is nowBase64URLStringinstead ofUint8ArrayAuthenticatorDevice.credentialIDis nowBase64URLStringrpIDis now required when callinggenerateAuthenticationOptions()generateRegistrationOptions()will generate random user IDs if not provideduser.idis treated as base64url string instartRegistration()userHandleis treated as base64url string instartAuthentication()
v11.0.0 Breaking Changes
- Positional arguments in
startRegistration()andstartAuthentication()replaced by object- Before:
startRegistration(options) - After:
startRegistration({ optionsJSON: options }) - Before:
startAuthentication(options) - After:
startAuthentication({ optionsJSON: options })
- Before:
AuthenticatorDevicetype renamed toWebAuthnCredentialcredentialID→credential.idcredentialPublicKey→credential.publicKey
verifyRegistrationResponse()returnsregistrationInfo.credentialinstead of individual propertiescredentialID→credential.idcredentialPublicKey→credential.publicKeycounter→credential.countertransportsare now incredential.transports
verifyAuthenticationResponse()usescredentialargument instead ofauthenticator
v13.0.0 Breaking Changes
@simplewebauthn/typespackage is retired- Types are now exported from
@simplewebauthn/browserand@simplewebauthn/server - Import types from
@simplewebauthn/serverinstead
- Types are now exported from
Files to Update
Package Changes
- Remove
@simplewebauthn/typesdependency - Update
@simplewebauthn/browserto^13.2.2 - Update
@simplewebauthn/serverto^13.2.2
Server-side Files
1. packages/lib/server-only/auth/create-passkey-registration-options.ts
- Change import from
@simplewebauthn/typesto@simplewebauthn/server - Remove
type: 'public-key'fromexcludeCredentialsitems - Update
userIDto useisoUint8Array.fromUTF8String()for proper encoding
2. packages/lib/server-only/auth/create-passkey-authentication-options.ts
- Change import from
@simplewebauthn/typesto@simplewebauthn/server - Remove
type: 'public-key'fromallowCredentialsitems
3. packages/lib/server-only/auth/create-passkey-signin-options.ts
- No changes needed (already using correct options)
4. packages/lib/server-only/auth/create-passkey.ts
- Change import from
@simplewebauthn/typesto@simplewebauthn/server - Update to use new
registrationInfo.credentialstructure:credentialID→credential.idcredentialPublicKey→credential.publicKeycounter→credential.counter
- Note:
credential.idis now aBase64URLString, soBuffer.from(credentialID)needs updating
5. packages/lib/server-only/document/is-recipient-authorized.ts
- Update
verifyAuthenticationResponse()to usecredentialinstead ofauthenticator:- Change
authenticator: { credentialID, credentialPublicKey, counter }tocredential: { id, publicKey, counter }
- Change
- Since
credential.idis now base64url string, convert storedcredentialIdbuffer to base64url
6. packages/auth/server/routes/passkey.ts
- Update
verifyAuthenticationResponse()to usecredentialinstead ofauthenticator - Same changes as
is-recipient-authorized.ts
7. packages/trpc/server/auth-router/create-passkey.ts
- Change import from
@simplewebauthn/typesto@simplewebauthn/server
Browser-side Files
8. apps/remix/app/components/dialogs/passkey-create-dialog.tsx
- Update
startRegistration()call:- Before:
startRegistration(passkeyRegistrationOptions) - After:
startRegistration({ optionsJSON: passkeyRegistrationOptions })
- Before:
9. apps/remix/app/components/forms/signin.tsx
- Update
startAuthentication()call:- Before:
startAuthentication(options) - After:
startAuthentication({ optionsJSON: options })
- Before:
10. apps/remix/app/components/general/document-signing/document-signing-auth-passkey.tsx
- Update
startAuthentication()call:- Before:
startAuthentication(options) - After:
startAuthentication({ optionsJSON: options })
- Before:
Database/Schema Considerations
The database stores credentialId as Bytes. The new API returns credential.id as Base64URLString. We need to:
- When storing a new passkey: Convert from
Base64URLStringtoBuffer - When passing to verification: Convert from
BuffertoBase64URLString
Use isoBase64URL helper from @simplewebauthn/server/helpers for these conversions.
Implementation Steps
Step 1: Update package.json dependencies
npm uninstall @simplewebauthn/types
npm install @simplewebauthn/browser@^13.2.2 @simplewebauthn/server@^13.2.2
Step 2: Update type imports
Replace all @simplewebauthn/types imports with @simplewebauthn/server
Step 3: Update browser-side API calls
startRegistration(options)→startRegistration({ optionsJSON: options })startAuthentication(options)→startAuthentication({ optionsJSON: options })
Step 4: Update server-side registration
- Update
excludeCredentialsformat (removetype: 'public-key') - Update
userIDencoding if needed - Update
verifyRegistrationResponse()result handling for newcredentialstructure
Step 5: Update server-side authentication
- Update
allowCredentialsformat (removetype: 'public-key') - Update
verifyAuthenticationResponse()to usecredentialinstead ofauthenticator - Handle
Base64URLStringforcredential.id
Step 6: Update credential storage/retrieval
- When storing: Convert
Base64URLStringtoBuffer - When reading: Convert
BuffertoBase64URLString
Step 7: Test passkey flows
- Test passkey creation
- Test passkey sign-in
- Test passkey authentication for document signing
- Test passkey deletion
Code Examples
Converting stored Buffer to Base64URLString for verification
import { isoBase64URL } from '@simplewebauthn/server/helpers';
// When reading from database (Buffer) and passing to verification
const credential = {
id: isoBase64URL.fromBuffer(passkey.credentialId),
publicKey: new Uint8Array(passkey.credentialPublicKey),
counter: Number(passkey.counter),
transports: passkey.transports,
};
Converting Base64URLString to Buffer for storage
import { isoBase64URL } from '@simplewebauthn/server/helpers';
// When storing from registration response
const credentialIdBuffer = Buffer.from(
isoBase64URL.toBuffer(registrationInfo.credential.id)
);
Risks and Mitigations
-
Database compatibility: The
credentialIdis stored asBytesin the database. The new API usesBase64URLString. We need proper conversion functions.- Mitigation: Use
isoBase64URL.fromBuffer()andisoBase64URL.toBuffer()for conversions
- Mitigation: Use
-
Existing passkeys: Existing passkeys should continue to work as long as conversion is done correctly.
- Mitigation: Test with existing passkeys after upgrade
-
Browser compatibility: v10+ requires newer browser APIs.
- Mitigation:
browserSupportsWebAuthn()already handles this check
- Mitigation: