1
- import { ClerkRuntimeError } from '@clerk/shared/error' ;
1
+ import type { ClerkRuntimeError } from '@clerk/shared/error' ;
2
+ import { ClerkWebAuthnError } from '@clerk/shared/error' ;
2
3
import type {
4
+ CredentialReturn ,
3
5
PublicKeyCredentialCreationOptionsJSON ,
4
6
PublicKeyCredentialCreationOptionsWithoutExtensions ,
5
7
PublicKeyCredentialRequestOptionsJSON ,
@@ -8,33 +10,9 @@ import type {
8
10
PublicKeyCredentialWithAuthenticatorAttestationResponse ,
9
11
} from '@clerk/types' ;
10
12
11
- type CredentialReturn < T > =
12
- | {
13
- publicKeyCredential : T ;
14
- error : null ;
15
- }
16
- | {
17
- publicKeyCredential : null ;
18
- error : ClerkWebAuthnError | Error ;
19
- } ;
20
-
21
13
type WebAuthnCreateCredentialReturn = CredentialReturn < PublicKeyCredentialWithAuthenticatorAttestationResponse > ;
22
14
type WebAuthnGetCredentialReturn = CredentialReturn < PublicKeyCredentialWithAuthenticatorAssertionResponse > ;
23
15
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
-
38
16
class Base64Converter {
39
17
static encode ( buffer : ArrayBuffer ) : string {
40
18
return btoa ( String . fromCharCode ( ...new Uint8Array ( buffer ) ) )
@@ -243,18 +221,6 @@ function serializePublicKeyCredentialAssertion(pkc: PublicKeyCredentialWithAuthe
243
221
const bufferToBase64Url = Base64Converter . encode . bind ( Base64Converter ) ;
244
222
const base64UrlToBuffer = Base64Converter . decode . bind ( Base64Converter ) ;
245
223
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
-
258
224
export {
259
225
base64UrlToBuffer ,
260
226
bufferToBase64Url ,
0 commit comments