Skip to content

Commit cc72156

Browse files
Support for hints in paskey (#120)
1 parent 8248e37 commit cc72156

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@authsignal/browser",
3-
"version": "1.14.1",
3+
"version": "1.15.0",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

src/passkey.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AuthenticationResponseJSON,
55
RegistrationResponseJSON,
66
AuthenticatorAttachment,
7+
PublicKeyCredentialHint,
78
} from "@simplewebauthn/browser";
89

910
import {PasskeyApiClient} from "./api/passkey-api-client";
@@ -25,6 +26,7 @@ type SignUpParams = {
2526
username?: string;
2627
displayName?: string;
2728
authenticatorAttachment?: AuthenticatorAttachment | null;
29+
hints?: PublicKeyCredentialHint[];
2830
useAutoRegister?: boolean;
2931
useCookies?: boolean;
3032
};
@@ -73,6 +75,7 @@ export class Passkey {
7375
displayName,
7476
token,
7577
authenticatorAttachment = "platform",
78+
hints,
7679
useAutoRegister = false,
7780
useCookies = false,
7881
}: SignUpParams): Promise<AuthsignalResponse<SignUpResponse>> {
@@ -103,7 +106,9 @@ export class Passkey {
103106
}
104107

105108
try {
106-
const registrationResponse = await startRegistration({optionsJSON: optionsResponse.options, useAutoRegister});
109+
const optionsJSON = hints ? {...optionsResponse.options, hints} : optionsResponse.options;
110+
111+
const registrationResponse = await startRegistration({optionsJSON, useAutoRegister});
107112

108113
const addAuthenticatorResponse = await this.api.addAuthenticator({
109114
registrationCredential: registrationResponse,

src/security-key.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
startRegistration,
44
AuthenticationResponseJSON,
55
RegistrationResponseJSON,
6+
PublicKeyCredentialHint,
67
} from "@simplewebauthn/browser";
78

89
import {TokenCache} from "./token-cache";
@@ -38,7 +39,7 @@ export class SecurityKey {
3839
this.enableLogging = enableLogging;
3940
}
4041

41-
async enroll(): Promise<AuthsignalResponse<EnrollResponse>> {
42+
async enroll({hints}: {hints?: PublicKeyCredentialHint[]} = {}): Promise<AuthsignalResponse<EnrollResponse>> {
4243
if (!this.cache.token) {
4344
return this.cache.handleTokenNotSetError();
4445
}
@@ -54,7 +55,9 @@ export class SecurityKey {
5455
}
5556

5657
try {
57-
const registrationResponse = await startRegistration({optionsJSON: optionsResponse});
58+
const optionsJSON = hints ? {...optionsResponse, hints} : optionsResponse;
59+
60+
const registrationResponse = await startRegistration({optionsJSON});
5861

5962
const addAuthenticatorResponse = await this.api.addAuthenticator({
6063
registrationCredential: registrationResponse,

0 commit comments

Comments
 (0)