API reference
The FIDO2 Web SDK exposes five functions through the global namespace window.com$thalesgroup$gemalto$fido2$web:
| Function | Description |
|---|---|
initSdk() |
Initialize Device Bound Key support |
getDeviceBoundKeyId(userIdBase64Url) |
Derive a device-bound key identifier and check existence |
webauthnCreateCred({options, abortSignal}) |
Create a credential (registration/attestation) |
webauthnGetCred({mediationRequirement, options, abortSignal, userIdB64Url}) |
Authenticate with an existing credential (assertion) |
registerDeviceBoundCredential({assertionReq, attestationReq, onFallbackConfirmation}) |
Register a Device Bound credential using the auto-binding pattern |
Accessing SDK functions
const {
initSdk,
getDeviceBoundKeyId,
webauthnCreateCred,
webauthnGetCred,
registerDeviceBoundCredential
} = window.com$thalesgroup$gemalto$fido2$web;
initSdk()
Initialize the FIDO2 Web SDK with Device Bound Key support. This function must be called on page load before any other SDK operations.
Signature
function initSdk(): Promise<void>
Returns
Promise<void> — Resolves when initialization is complete.
Description
Initialization performs the following actions:
- Determines the Relying Party ID (
rpId) fromlocation.hostname - Creates an HMAC-SHA256 seed for Device Bound Key operations
- Stores the seed securely in IndexedDB (skipped if already present)
The seed is stored as a non-extractable CryptoKey and is used to derive device-bound key identifiers for users.
Example
const initSdk = window.com$thalesgroup$gemalto$fido2$web.initSdk;
window.addEventListener('load', async () => {
try {
await initSdk();
console.log('SDK initialized successfully');
} catch (error) {
console.error('Initialization failed:', error);
}
});
Errors thrown
| Code | Description |
|---|---|
DBK-0001 |
Unable to determine page origin from unsupported URL scheme |
DBK-0010 |
Failed to open IndexedDB |
DBK-0011 |
Failed to store the DBK seed in IndexedDB |
Notes
- Must be called before any other SDK functions.
- Safe to call multiple times — subsequent calls have no effect if already initialized.
- Requires IndexedDB support in the browser.
- Must be served from
http://orhttps://—file://is not supported.
Warning
In incognito or private browsing mode, IndexedDB data is cleared when the session ends. The HMAC seed is regenerated on each new incognito session, resulting in different Device Bound Key identifiers for the same user across sessions.
getDeviceBoundKeyId(userIdBase64Url)
Derives a deterministic device-bound key identifier (dbkKid) for a given user and checks whether a Device Bound Key (DBK) keypair exists for this user on the current browser.
The dbkKid is unique per combination of device, browser, Relying Party hostname, and user ID.
Signature
interface DeviceBoundKeyInfo {
dbkKid: string; // The device-bound key identifier (base64url)
dbkExist: boolean; // Whether a DBK keypair exists for this user on this browser
}
function getDeviceBoundKeyId(userIdBase64Url: string): Promise<DeviceBoundKeyInfo>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userIdBase64Url |
string | Yes | The user identifier encoded as a base64url string. |
Returns
Promise<DeviceBoundKeyInfo> — An object with:
dbkKid(string): The base64url-encoded device-bound key identifierdbkExist(boolean):trueif a DBK keypair exists for this user on this browser,falseotherwise
Description
The dbkKid is computed as:
dbkKid = base64url(HMAC-SHA256(hmacKey, userId_bytes || rpId_bytes))
Where:
hmacKeyis the HMAC seed stored in IndexedDB (created byinitSdk())userId_bytesare the base64url-decoded user ID bytesrpId_bytesare the UTF-8 encodedrpIdbytes fromlocation.hostname
Example — Fail-fast pattern
const getDeviceBoundKeyId = window.com$thalesgroup$gemalto$fido2$web.getDeviceBoundKeyId;
async function handleUserLogin(userIdB64Url) {
const { dbkKid, dbkExist } = await getDeviceBoundKeyId(userIdB64Url);
if (dbkExist) {
// User has a registered DBK on this browser — proceed with FIDO authentication
await authenticateWithFIDO(dbkKid);
} else {
// User has no DBK on this browser — show alternative authentication (OTP, etc.)
await authenticateWith2FA(userIdB64Url, dbkKid);
}
}
Example — Encoding a plain user ID
function base64urlEncode(str) {
const bytes = new TextEncoder().encode(str);
const base64 = btoa(String.fromCharCode(...bytes));
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
}
const userIdB64Url = base64urlEncode('user123');
const { dbkKid, dbkExist } = await getDeviceBoundKeyId(userIdB64Url);
Errors thrown
| Code | Description |
|---|---|
VAL-0003 |
userIdBase64Url is not a valid base64url-encoded string |
VAL-0002 |
Cannot determine rpId from location.hostname (unsupported URL scheme) |
DBK-0001 |
HMAC private key (seed) not found in IndexedDB |
DBK-0012 |
Failed to load HMAC seed key from IndexedDB — call initSdk() first |
Notes
- The
dbkKidis stable across browser sessions as long as IndexedDB data persists. - Different browsers on the same device produce different
dbkKidvalues. - Clearing IndexedDB data regenerates the HMAC seed and changes the
dbkKid.
Warning
In incognito or private browsing mode, each new session generates a new HMAC seed, producing different dbkKid values for the same user. Credentials registered in one incognito session cannot be used in subsequent incognito sessions.
webauthnCreateCred({options, abortSignal})
Creates a new FIDO2 credential (registration/attestation) using the browser's WebAuthn API, and optionally generates a Device Bound Key.
Signature
function webauthnCreateCred({
options: APIModelServerPublicKeyCredentialCreationOptionsResponse,
abortSignal?: AbortSignal
}): Promise<APIModelStandardAttestationServerPublicKeyCredential>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
Object | Yes | Attestation options from the FIDO2 Server /attestation/options endpoint, passed through your Relying Party backend. |
abortSignal |
AbortSignal | No | Optional signal to cancel the operation. |
Returns
Promise<APIModelStandardAttestationServerPublicKeyCredential> — A credential object to be sent to the FIDO2 Server /attestation/result endpoint via your Relying Party backend.
Description
This function:
- Converts FIDO2 Server attestation options to WebAuthn API format
- Calls
navigator.credentials.create()to generate a credential with user interaction - If the Device Bound Key extension is present in the options, derives or retrieves the DBK keypair, generates a signature, and includes the DBK public key and signature in the response
- Returns a credential response compatible with the FIDO2 Server
Example — Basic registration
const webauthnCreateCred = window.com$thalesgroup$gemalto$fido2$web.webauthnCreateCred;
async function registerUser(userId) {
// 1. Get attestation options from your Relying Party backend
const response = await fetch('/api/rp/fido2/attestation/options', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId })
});
const attestationOptions = await response.json();
// 2. Create credential using the SDK
const credential = await webauthnCreateCred({ options: attestationOptions });
// 3. Send credential to your Relying Party backend
const resultResponse = await fetch('/api/rp/fido2/attestation/result', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(credential)
});
return await resultResponse.json();
}
Example — With abort signal
const controller = new AbortController();
setTimeout(() => controller.abort(), 60000); // Cancel after 60 seconds
try {
const credential = await webauthnCreateCred({
options: attestationOptions,
abortSignal: controller.signal
});
} catch (error) {
if (error.name === 'AbortError') {
console.log('Registration was cancelled');
}
}
Expected input format
The options parameter is the response from the FIDO2 Server /attestation/options endpoint:
{
"challenge": "base64url_encoded_challenge",
"rp": { "id": "example.com", "name": "Example RP" },
"user": {
"id": "base64url_encoded_user_id",
"name": "user@example.com",
"displayName": "User Name"
},
"pubKeyCredParams": [
{ "type": "public-key", "alg": -7 }
],
"timeout": 60000,
"extensions": {
"thalesgroup_dbk_ext": {
"v": 1,
"kid": "base64url_dbkkid",
"allowedAlgorithms": [-7]
}
}
}
Output format
{
"id": "base64url_credential_id",
"rawId": "base64url_raw_credential_id",
"type": "public-key",
"response": {
"clientDataJSON": "base64url_client_data",
"attestationObject": "base64url_attestation_object"
},
"authenticatorAttachment": "platform",
"clientExtensionResults": {
"thalesgroup_dbk_ext": {
"v": 1,
"pk": {
"kid": "base64url_dbkkid",
"kty": "EC",
"crv": "P-256",
"x": "base64url_x",
"y": "base64url_y"
},
"sig": "base64url_signature"
}
}
}
Errors thrown
| Code | Description |
|---|---|
WEB-0001 |
Invalid credential creation options |
WEB-0002 |
DBK allowedAlgorithms array is empty |
WEB-0003 |
Failed to store DBK keypair in IndexedDB |
WEB-0005 |
Failed to sign with DBK during registration |
WEB-0006 |
Unexpected credential type in create response |
DBK-0005 |
Unsupported COSE algorithm |
NotAllowedError |
User cancelled or operation timed out (browser error) |
InvalidStateError |
Authenticator is already registered (browser error) |
NotSupportedError |
WebAuthn not supported by the browser (browser error) |
Notes
- A user gesture (for example, a button click) is required before calling this function.
- Timeout is controlled by the
timeoutfield in attestation options (typically 60,000 ms). - If using the Device Bound Key extension,
initSdk()must be called first. - The
rpIdin the options must matchlocation.hostname.
webauthnGetCred({mediationRequirement, options, abortSignal, userIdB64Url})
Authenticates a user using an existing FIDO2 credential (assertion) via the browser's WebAuthn API.
Signature
function webauthnGetCred({
mediationRequirement?: CredentialMediationRequirement,
options: APIModelServerPublicKeyCredentialGetOptionsResponse,
abortSignal?: AbortSignal,
userIdB64Url?: string
}): Promise<APIModelStandardAssertionServerPublicKeyCredential>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
mediationRequirement |
string | No | Controls user mediation. Values: 'silent', 'optional' (default), 'required', 'conditional'. |
options |
Object | Yes | Assertion options from the FIDO2 Server /assertion/options endpoint, passed through your Relying Party backend. |
abortSignal |
AbortSignal | No | Optional signal to cancel the operation. |
userIdB64Url |
string | No | Optional base64url-encoded user ID. Used internally by registerDeviceBoundCredential() for the auto-binding flow when allowNewDbkBinding is true. |
Returns
Promise<APIModelStandardAssertionServerPublicKeyCredential> — A credential object to be sent to the FIDO2 Server /assertion/result endpoint via your Relying Party backend.
Example — Basic authentication
const webauthnGetCred = window.com$thalesgroup$gemalto$fido2$web.webauthnGetCred;
async function authenticateUser() {
const response = await fetch('/api/rp/fido2/assertion/options', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
const assertionOptions = await response.json();
const credential = await webauthnGetCred({ options: assertionOptions });
const resultResponse = await fetch('/api/rp/fido2/assertion/result', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(credential)
});
return await resultResponse.json();
}
Example — Conditional UI (autofill)
const credential = await webauthnGetCred({
mediationRequirement: 'conditional',
options: assertionOptions
});
Expected input format
{
"challenge": "base64url_encoded_challenge",
"timeout": 60000,
"rpId": "example.com",
"allowCredentials": [
{ "type": "public-key", "id": "base64url_credential_id" }
],
"userVerification": "required",
"extensions": {
"thalesgroup_dbk_ext": { "v": 1, "kid": "base64url_dbkkid" }
}
}
Output format
{
"id": "base64url_credential_id",
"rawId": "base64url_raw_credential_id",
"type": "public-key",
"response": {
"clientDataJSON": "base64url_client_data",
"authenticatorData": "base64url_authenticator_data",
"signature": "base64url_signature",
"userHandle": "base64url_user_handle"
},
"authenticatorAttachment": "platform",
"clientExtensionResults": {
"thalesgroup_dbk_ext": {
"v": 1,
"sig": "base64url_dbk_signature",
"kid": "base64url_dbkkid"
}
}
}
Errors thrown
| Code | Description |
|---|---|
WEB-0007 |
Invalid credential get options |
WEB-0008 |
Failed to load DBK keypair during assertion |
WEB-0009 |
Failed to sign with DBK during assertion |
WEB-0010 |
User ID is required but authenticator did not return userHandle |
WEB-0011 |
Unexpected credential type in get response |
DBK-0015 |
DBK keypair not found — user not registered with DBK on this browser |
NotAllowedError |
User cancelled or operation timed out (browser error) |
NotFoundError |
No matching credential found (browser error) |
registerDeviceBoundCredential({assertionReq, attestationReq, onFallbackConfirmation})
Registers a device-bound credential using the dual request (assertion-then-attestation fallback) pattern for the Multi-DBK Auto-Binding flow.
Signature
type FallbackConfirmationCallback = () => boolean | Promise<boolean>;
interface DualRequestOptions {
assertionReq: APIModelServerPublicKeyCredentialGetOptionsResponse;
attestationReq: APIModelServerPublicKeyCredentialCreationOptionsResponse;
onFallbackConfirmation?: FallbackConfirmationCallback;
}
type RegisterDbkCredentialResult =
| { type: 'assertion'; credential: APIModelStandardAssertionServerPublicKeyCredential }
| { type: 'attestation'; credential: APIModelStandardAttestationServerPublicKeyCredential };
function registerDeviceBoundCredential(
options: DualRequestOptions
): Promise<RegisterDbkCredentialResult>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
assertionReq |
Object | Yes | Assertion options from the FIDO2 Server. Must have extensions.thalesgroup_dbk_ext.allowNewDbkBinding: true and a non-empty allowedAlgorithms array. |
attestationReq |
Object | Yes | Attestation options from the FIDO2 Server (used as fallback if assertion fails). |
onFallbackConfirmation |
Function | No | Callback invoked when assertion fails with NotAllowedError. Return true to proceed with attestation, false to cancel. Supports synchronous and async (Promise) return values. Default: uses window.confirm(). |
Returns
Promise<RegisterDbkCredentialResult> — A discriminated union:
{ type: 'assertion', credential }— Path 2a: assertion succeeded; an existing synced passkey was bound to this device's DBK.{ type: 'attestation', credential }— Path 2b: assertion failed; a new credential was created with DBK binding.
Description
This function implements the Multi-DBK Auto-Binding flow with two paths:
- Path 2a: If the user has a synced passkey on this browser, the SDK performs a WebAuthn assertion, binding the new DBK to the existing credential.
- Path 2b: If no matching passkey is found (
NotAllowedError), the SDK invokes the fallback confirmation callback, then performs a WebAuthn attestation to create a new credential with DBK binding.
Example — Custom async modal (recommended for production)
const { registerDeviceBoundCredential } = window.com$thalesgroup$gemalto$fido2$web;
const result = await registerDeviceBoundCredential({
assertionReq,
attestationReq,
onFallbackConfirmation: () => new Promise((resolve) => {
showConfirmModal({
message: 'Your passkey was not found on this browser. Register a new one?',
onConfirm: () => resolve(true),
onCancel: () => resolve(false),
});
})
});
if (result.type === 'assertion') {
await submitAssertionResult(result.credential); // Path 2a
} else {
await submitAttestationResult(result.credential); // Path 2b
}
Warning
Do not omit onFallbackConfirmation in production. The default window.confirm() may be silently suppressed by browsers in certain conditions (repeated calls, iframes, enterprise policies, headless environments), causing the SDK to throw WEB-0016 without showing any dialog. Always provide a custom modal callback in production.
FallbackConfirmationCallback behaviour
| Return value | Behaviour |
|---|---|
true or Promise.resolve(true) |
Proceed with attestation (Path 2b) |
false or Promise.resolve(false) |
Cancel — SDK throws WEB_REGISTER_FALLBACK_CANCELLED |
Validation
The function performs upfront validation before any WebAuthn operation:
| Condition | Error thrown |
|---|---|
assertionReq or attestationReq is missing |
WEB-0015 |
assertionReq.extensions.thalesgroup_dbk_ext.allowNewDbkBinding !== true |
WEB-0012 |
assertionReq.extensions.thalesgroup_dbk_ext.allowedAlgorithms is missing |
WEB-0013 |
allowedAlgorithms is an empty array |
WEB-0014 |
attestationReq.user.id is missing or empty |
VAL-0002 |
Errors thrown
| Code | Description |
|---|---|
WEB-0015 |
Both assertionReq and attestationReq must be provided |
WEB-0012 |
allowNewDbkBinding is not true in the assertion extension |
WEB-0013 |
allowedAlgorithms is missing from the assertion extension |
WEB-0014 |
allowedAlgorithms is an empty array |
VAL-0002 |
attestationReq.user.id is missing or empty |
WEB-0016 |
User cancelled the fallback confirmation |
Notes
initSdk()must be called before this function.- The
onFallbackConfirmationcallback is only invoked on Path 2b (assertion failed withNotAllowedError). - Non-
NotAllowedErrorerrors from the assertion are re-thrown immediately without invoking the callback.
Type definitions
Mediation requirement
type CredentialMediationRequirement =
| 'silent' // No user interaction — fails if not possible
| 'optional' // User may be prompted (default)
| 'required' // User must be prompted
| 'conditional' // Autofill-assisted authentication
Error categories
All SDK errors are instances of Fido2WebSdkError with the following properties:
class Fido2WebSdkError extends Error {
name: 'Fido2WebSdkError';
code: string; // e.g. 'DBK-0005'
category: string; // 'DBK', 'VAL', 'CONV', or 'WEB'
shortDesc: string; // Brief description
details: string; // Detailed message with context
}
| Category | Code range | Description |
|---|---|---|
DBK |
DBK-0001 to DBK-0016 | Device Bound Key operation errors |
VAL |
VAL-0001 to VAL-0003 | Validation and input parameter errors |
CONV |
CONV-0001 to CONV-0011 | Type conversion and format errors |
WEB |
WEB-0001 to WEB-0016 | WebAuthn API operation errors |
For the complete error code reference, see Error handling.
Related documentation
- Integration guide: Step-by-step integration workflows
- Error handling: Full error code reference and handling patterns
- Device Bound Key extension: Server-side DBK configuration
- FIDO authentication APIs: FIDO2 Server REST API reference