11/// <reference types="web-bluetooth" />
22/// <reference types="user-agent-data-types" /> <- add this line
33import type { ClientCapabilities } from '@corbado/types' ;
4- import { parseCreationOptionsFromJSON , parseRequestOptionsFromJSON } from '@corbado/webauthn-json/browser-ponyfill' ;
4+ import { create , get } from '@corbado/webauthn-json/browser-ponyfill' ;
55import FingerprintJS from '@fingerprintjs/fingerprintjs' ;
66import { detectIncognito } from 'detectincognitojs' ;
77import log from 'loglevel' ;
@@ -40,23 +40,19 @@ export class WebAuthnService {
4040 }
4141
4242 async createPasskeyRaw ( attestationOptions : string , conditional : boolean ) : Promise < ResponseWithMessage > {
43- let message ;
4443 const abortController = this . abortOngoingOperation ( ) ;
4544 const attestationOptionsJSON = JSON . parse ( attestationOptions ) ;
4645 this . #abortController = abortController ;
4746
48- let publicKey : PublicKeyCredentialCreationOptions | undefined ;
49- if ( PublicKeyCredential . parseCreationOptionsFromJSON ) {
50- publicKey = PublicKeyCredential . parseCreationOptionsFromJSON ( attestationOptionsJSON . publicKey ) ;
51- } else {
52- message = 'parseCreationOptionsFromJSON not available' ;
53- publicKey = parseCreationOptionsFromJSON ( attestationOptionsJSON ) . publicKey ;
54- }
55-
56- if ( ! publicKey ) {
57- throw new Error ( 'No publicKey in assertionOptions' ) ;
47+ if ( ! PublicKeyCredential . parseCreationOptionsFromJSON ) {
48+ const signedChallenge = await create ( attestationOptionsJSON ) ;
49+ return {
50+ response : JSON . stringify ( signedChallenge ) ,
51+ message : 'parseCreationOptionsFromJSON not available' ,
52+ } ;
5853 }
5954
55+ const publicKey = PublicKeyCredential . parseCreationOptionsFromJSON ( attestationOptionsJSON . publicKey ) ;
6056 let credential : PublicKeyCredential ;
6157 if ( conditional ) {
6258 const result = await WebAuthnService . raceWithTimeout (
@@ -78,7 +74,7 @@ export class WebAuthnService {
7874
7975 return {
8076 response : JSON . stringify ( credential . toJSON ( ) ) ,
81- message,
77+ message : '' ,
8278 } ;
8379 }
8480
@@ -104,24 +100,19 @@ export class WebAuthnService {
104100 conditional : boolean ,
105101 onConditionalLoginStart ?: ( ac : AbortController ) => void ,
106102 ) : Promise < ResponseWithMessage > {
107- let message : string | undefined ;
108103 const abortController = this . abortOngoingOperation ( ) ;
109104 const assertionOptionsJSON = JSON . parse ( assertionOptions ) ;
110105 this . #abortController = abortController ;
111106 onConditionalLoginStart ?.( abortController ) ;
112-
113- let publicKey : PublicKeyCredentialRequestOptions | undefined ;
114- if ( PublicKeyCredential . parseRequestOptionsFromJSON ) {
115- publicKey = PublicKeyCredential . parseRequestOptionsFromJSON ( assertionOptionsJSON . publicKey ) ;
116- } else {
117- publicKey = parseRequestOptionsFromJSON ( assertionOptionsJSON ) . publicKey ;
118- message = 'parseRequestOptionsFromJSON not available' ;
119- }
120-
121- if ( ! publicKey ) {
122- throw new Error ( 'No publicKey in assertionOptions' ) ;
107+ if ( ! PublicKeyCredential . parseRequestOptionsFromJSON ) {
108+ const signedChallenge = await get ( assertionOptionsJSON ) ;
109+ return {
110+ response : JSON . stringify ( signedChallenge ) ,
111+ message : 'parseRequestOptionsFromJSON not available' ,
112+ } ;
123113 }
124114
115+ const publicKey = PublicKeyCredential . parseRequestOptionsFromJSON ( assertionOptionsJSON . publicKey ) ;
125116 let mediation : CredentialMediationRequirement | undefined ;
126117 if ( conditional ) {
127118 mediation = 'conditional' ;
@@ -135,7 +126,7 @@ export class WebAuthnService {
135126
136127 return {
137128 response : JSON . stringify ( credential . toJSON ( ) ) ,
138- message,
129+ message : '' ,
139130 } ;
140131 }
141132
0 commit comments