Skip to content

Commit 3df0541

Browse files
Update webauthn to v2 (#5458)
Co-authored-by: Joaquim Verges <joaquim.verges@gmail.com>
1 parent 2591c75 commit 3df0541

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

packages/thirdweb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
"@google/model-viewer": "2.1.1",
206206
"@noble/curves": "1.6.0",
207207
"@noble/hashes": "1.5.0",
208-
"@passwordless-id/webauthn": "^1.6.1",
208+
"@passwordless-id/webauthn": "^2.1.2",
209209
"@radix-ui/react-dialog": "1.1.2",
210210
"@radix-ui/react-focus-scope": "1.1.0",
211211
"@radix-ui/react-icons": "1.3.2",

packages/thirdweb/src/wallets/in-app/web/lib/auth/passkeys.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { client } from "@passwordless-id/webauthn";
1+
import { client, parsers } from "@passwordless-id/webauthn";
22
import type { ThirdwebClient } from "../../../../../client/client.js";
33
import { webLocalStorage } from "../../../../../utils/storage/webStorage.js";
44
import {
@@ -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
}

pnpm-lock.yaml

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)