1- import { ClerkRuntimeError } from '@clerk/shared/error' ;
1+ import type { ClerkRuntimeError } from '@clerk/shared/error' ;
2+ import { ClerkWebAuthnError } from '@clerk/shared/error' ;
23import type {
4+ CredentialReturn ,
35 PublicKeyCredentialCreationOptionsJSON ,
46 PublicKeyCredentialCreationOptionsWithoutExtensions ,
57 PublicKeyCredentialRequestOptionsJSON ,
@@ -8,33 +10,9 @@ import type {
810 PublicKeyCredentialWithAuthenticatorAttestationResponse ,
911} from '@clerk/types' ;
1012
11- type CredentialReturn < T > =
12- | {
13- publicKeyCredential : T ;
14- error : null ;
15- }
16- | {
17- publicKeyCredential : null ;
18- error : ClerkWebAuthnError | Error ;
19- } ;
20-
2113type WebAuthnCreateCredentialReturn = CredentialReturn < PublicKeyCredentialWithAuthenticatorAttestationResponse > ;
2214type WebAuthnGetCredentialReturn = CredentialReturn < PublicKeyCredentialWithAuthenticatorAssertionResponse > ;
2315
24- type ClerkWebAuthnErrorCode =
25- // Generic
26- | 'passkey_not_supported'
27- | 'passkey_pa_not_supported'
28- | 'passkey_invalid_rpID_or_domain'
29- | 'passkey_already_exists'
30- | 'passkey_operation_aborted'
31- // Retrieval
32- | 'passkey_retrieval_cancelled'
33- | 'passkey_retrieval_failed'
34- // Registration
35- | 'passkey_registration_cancelled'
36- | 'passkey_registration_failed' ;
37-
3816class Base64Converter {
3917 static encode ( buffer : ArrayBuffer ) : string {
4018 return btoa ( String . fromCharCode ( ...new Uint8Array ( buffer ) ) )
@@ -243,18 +221,6 @@ function serializePublicKeyCredentialAssertion(pkc: PublicKeyCredentialWithAuthe
243221const bufferToBase64Url = Base64Converter . encode . bind ( Base64Converter ) ;
244222const base64UrlToBuffer = Base64Converter . decode . bind ( Base64Converter ) ;
245223
246- export class ClerkWebAuthnError extends ClerkRuntimeError {
247- /**
248- * A unique code identifying the error, can be used for localization.
249- */
250- code : ClerkWebAuthnErrorCode ;
251-
252- constructor ( message : string , { code } : { code : ClerkWebAuthnErrorCode } ) {
253- super ( message , { code } ) ;
254- this . code = code ;
255- }
256- }
257-
258224export {
259225 base64UrlToBuffer ,
260226 bufferToBase64Url ,
0 commit comments