1
- import { client } from "@passwordless-id/webauthn" ;
1
+ import { client , parsers } from "@passwordless-id/webauthn" ;
2
2
import type { ThirdwebClient } from "../../../../../client/client.js" ;
3
3
import { webLocalStorage } from "../../../../../utils/storage/webStorage.js" ;
4
4
import {
@@ -25,22 +25,26 @@ export class PasskeyWebClient implements PasskeyClient {
25
25
rp : RpInfo ;
26
26
} ) : Promise < RegisterResult > {
27
27
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,
30
31
userVerification : "required" ,
31
32
domain : rp . id ,
32
33
attestation : true ,
33
- debug : false ,
34
34
} ) ;
35
- const clientDataB64 = base64UrlToBase64 ( registration . clientData ) ;
35
+ const clientDataB64 = base64UrlToBase64 (
36
+ registration . response . clientDataJSON ,
37
+ ) ;
36
38
const clientDataParsed = JSON . parse ( base64ToString ( clientDataB64 ) ) ;
37
39
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 ,
41
43
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
+ ) ,
44
48
} ,
45
49
origin : clientDataParsed . origin ,
46
50
} ;
@@ -52,22 +56,19 @@ export class PasskeyWebClient implements PasskeyClient {
52
56
rp : RpInfo ;
53
57
} ) : Promise < AuthenticateResult > {
54
58
const { credentialId, challenge, rp } = args ;
55
- const result = await client . authenticate (
56
- credentialId ? [ credentialId ] : [ ] ,
59
+ const result = await client . authenticate ( {
60
+ allowCredentials : credentialId ? [ credentialId ] : [ ] ,
57
61
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 ) ;
65
66
const clientDataParsed = JSON . parse ( base64ToString ( clientDataB64 ) ) ;
66
67
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 ,
71
72
origin : clientDataParsed . origin ,
72
73
} ;
73
74
}
0 commit comments