1- import { client } from "@passwordless-id/webauthn" ;
1+ import { client , parsers } from "@passwordless-id/webauthn" ;
22import type { ThirdwebClient } from "../../../../../client/client.js" ;
33import { webLocalStorage } from "../../../../../utils/storage/webStorage.js" ;
44import {
@@ -25,22 +25,26 @@ export class PasskeyWebClient implements PasskeyClient {
2525 rp : RpInfo ;
2626 } ) : Promise < RegisterResult > {
2727 const { name, challenge, rp } = args ;
28- const registration = await client . register ( name , challenge , {
29- authenticatorType : "auto" ,
28+ const registration = await client . register ( {
29+ user : name ,
30+ challenge,
3031 userVerification : "required" ,
3132 domain : rp . id ,
3233 attestation : true ,
33- debug : false ,
3434 } ) ;
35- const clientDataB64 = base64UrlToBase64 ( registration . clientData ) ;
35+ const clientDataB64 = base64UrlToBase64 (
36+ registration . response . clientDataJSON ,
37+ ) ;
3638 const clientDataParsed = JSON . parse ( base64ToString ( clientDataB64 ) ) ;
3739 return {
38- authenticatorData : registration . authenticatorData ,
39- credentialId : registration . credential . id ,
40- clientData : registration . clientData ,
40+ authenticatorData : registration . response . authenticatorData ,
41+ credentialId : registration . id ,
42+ clientData : registration . response . clientDataJSON ,
4143 credential : {
42- publicKey : registration . credential . publicKey ,
43- algorithm : registration . credential . algorithm ,
44+ publicKey : registration . response . publicKey ,
45+ algorithm : parsers . getAlgoName (
46+ registration . response . publicKeyAlgorithm ,
47+ ) ,
4448 } ,
4549 origin : clientDataParsed . origin ,
4650 } ;
@@ -52,22 +56,19 @@ export class PasskeyWebClient implements PasskeyClient {
5256 rp : RpInfo ;
5357 } ) : Promise < AuthenticateResult > {
5458 const { credentialId, challenge, rp } = args ;
55- const result = await client . authenticate (
56- credentialId ? [ credentialId ] : [ ] ,
59+ const result = await client . authenticate ( {
60+ allowCredentials : credentialId ? [ credentialId ] : [ ] ,
5761 challenge,
58- {
59- authenticatorType : "auto" ,
60- userVerification : "required" ,
61- domain : rp . id ,
62- } ,
63- ) ;
64- const clientDataB64 = base64UrlToBase64 ( result . clientData ) ;
62+ userVerification : "required" ,
63+ domain : rp . id ,
64+ } ) ;
65+ const clientDataB64 = base64UrlToBase64 ( result . response . clientDataJSON ) ;
6566 const clientDataParsed = JSON . parse ( base64ToString ( clientDataB64 ) ) ;
6667 return {
67- authenticatorData : result . authenticatorData ,
68- credentialId : result . credentialId ,
69- clientData : result . clientData ,
70- signature : result . signature ,
68+ authenticatorData : result . response . authenticatorData ,
69+ credentialId : result . id ,
70+ clientData : result . response . clientDataJSON ,
71+ signature : result . response . signature ,
7172 origin : clientDataParsed . origin ,
7273 } ;
7374 }
0 commit comments