Enable biometric enablement capabilities (fingerprint or 3D facial recognition) for IFAA passwordless authentication on a mobile device. If a user enables IFAA passwordless authentication using an existing biometric type, the corresponding biometric authentication capability will be enabled on the mobile device.
Perform IFAA passwordless identity authentication based on existing biometric features (fingerprint or 3D facial recognition) on mobile devices. Authentication will succeed if the user runs it with enabled biometrics, and will fail if disabled biometrics are used.
Disable IFAA passwordless authentication based on biometric features (fingerprint or 3D facial recognition) on mobile devices. If a user disables IFAA passwordless authentication using an existing biometric feature type, the corresponding biometric authentication capability will be disabled on the mobile device.
Your app can obtain signature data from the IIFAA central server after accessing the IIFAA alliance.
Mobile devices must support biometric features (fingerprints or 3D faces). Check whether a mobile device supports the ATL4 authentication trust level.
import { userAuth } from '@kit.UserAuthenticationKit';
import { BusinessError } from '@kit.BasicServicesKit';
// ...
function getAvailableStatus() {
try {
// Example: Check whether the device supports the ATL4 authentication trust level for facial recognition.
userAuth.getAvailableStatus(userAuth.UserAuthType.FACE, userAuth.AuthTrustLevel.ATL4);
console.info('current auth trust level is supported');
} catch (error) {
const err: BusinessError = error as BusinessError;
console.error(`current auth trust level is not supported. Code is ${err?.code}, message is ${err?.message}`);
}
} Mobile devices must be connected to the Internet to use the service.
The IFAA service returns anonymized personal information such as fingerprint ID and facial ID to the app to provide passwordless authentication capabilities based on specific biometric features. Before uploading personal information to the cloud, an app must explicitly inform the user and obtain their consent. For details, see Personal Data Processing Description.

Registration Process:
Authentication Process:
Deregistration Process:
The following table lists the APIs required for registration, authentication, and deregistration. For details about the APIs, see API Reference.
| API | Description |
|---|---|
| register(registerData: Uint8Array): Promise<Uint8Array> | Enables IFAA passwordless authentication and returns the result asynchronously through a promise. |
| auth(authToken: Uint8Array, authData: Uint8Array): Promise<Uint8Array> | Performs IFAA passwordless authentication and returns the result asynchronously through a promise. |
| deregisterSync(deregisterData: Uint8Array): void | Deregisters IFAA passwordless authentication and returns the result synchronously. |
| getAnonymousIdSync(userToken: Uint8Array): Uint8Array | Obtains the anonymous ID for IFAA passwordless authentication and returns the result synchronously. |
Import required modules.
import { ifaa } from '@kit.OnlineAuthenticationKit';
import { userAuth } from '@kit.UserAuthenticationKit';
import { BusinessError } from '@kit.BasicServicesKit'; Enable IFAA passwordless authentication.
try {
// Construct the TLV input parameter based on the IIFAA protocol, convert it into Uint8Array to obtain userTokenFp, and call the ifaa.getAnonymousIdSync API.
let getAnonIdResult: Uint8Array = ifaa.getAnonymousIdSync(userTokenFp);
console.info('Succeeded in getting anonymous id, result:', getAnonIdResult);
} catch (error) {
const err = error as BusinessError;
console.error(`Failed to get anonymous id. Code is ${err.code}, message is ${err.message}`);
}
try {
// Use getAnonymousIdSync to obtain the signed registration data from the server.
// Convert the registration data (TLV format of the IIFAA protocol) into Uint8Array to obtain tlvRegisterFp, and then call the ifaa.register API.
let registerPromise: Promise<Uint8Array> = ifaa.register(tlvRegisterFp);
registerPromise.then(registerResult => {
console.info('Succeeded in doing register, result:', registerResult);
// The registration is successful. Obtain and process the ifaa.register result.
// ...
}).catch((err: BusinessError) =>{
console.error(`Failed to call register. Code: ${err.code}, message: ${err.message}`);
// The registration fails. Obtain the ifaa.register error and handle it.
});
} catch (error) {
const err = error as BusinessError;
console.error(`Failed to register. Code is ${err.code}, message is ${err.message}`);
} Perform IFAA passwordless authentication.
// Construct the TLV input parameter based on the IIFAA protocol, convert it into Uint8Array to obtain userTokenFp, and call the ifaa.getAnonymousIdSync API.
let getAnonIdResult: Uint8Array;
try {
getAnonIdResult = ifaa.getAnonymousIdSync(userTokenFp);
console.info('Succeeded in getting anonymous id, result:', getAnonIdResult);
} catch (error) {
const err = error as BusinessError;
console.error(`Failed to get anonymous id. Code is ${err.code}, message is ${err.message}`);
}
// Use getAnonymousIdSync to obtain the signed authentication data from the server.
// Obtain challenge of the passwordless payment.
let ifaaChallenge: Uint8Array = new Uint8Array([0]);
try {
ifaaChallenge = ifaa.preAuthSync();
} catch (error) {
const err = error as BusinessError;
console.error(`Failed to pre auth. Code is ${err.code}, message is ${err.message}`);
}
let authParam: userAuth.AuthParam = {
challenge: ifaaChallenge,
authType: [userAuth.UserAuthType.FINGERPRINT],
authTrustLevel: userAuth.AuthTrustLevel.ATL4
};
try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, {title: ' '});
userAuthInstance.on('result', {
onResult(result) {
let authToken = result.token;
try {
// After biometric features are successfully authenticated, start IFAA authentication.
console.info('IFAA auth start');
// Convert the authentication data (TLV format of the IIFAA protocol) into Uint8Array to obtain tlvAuthFp, and then call the ifaa.authSync API.
// Select a synchronous or asynchronous API based on service requirements.
let authResult: Uint8Array = ifaa.authSync(authToken, tlvAuthFp);
console.info('Succeeded in auth, result:', authResult);
// Process authResult.
// ...
} catch (error) {
const err: BusinessError = error as BusinessError;
console.error(`Failed to call auth. Code is ${err.code}, message is ${err.message}`);
// ...
}
}
});
userAuthInstance.start();
} catch (error) {
const err = error as BusinessError;
console.error(`Failed to user auth. Code is ${err.code}, message is ${err.message}`);
} Disable IFAA passwordless authentication.
// Construct the TLV input parameter based on the IIFAA protocol, convert it into Uint8Array to obtain userTokenFp, and call the ifaa.getAnonymousIdSync API.
try {
let getAnonIdResult: Uint8Array = ifaa.getAnonymousIdSync(userTokenFp);
console.info('Succeeded in getting anonymous id, result:', getAnonIdResult);
} catch (error) {
const err = error as BusinessError;
console.error(`Failed to get anonymous id. Code is ${err.code}, message is ${err.message}`);
}
// Use the result of getAnonymousId to obtain the signed deregistration data from the server.
// Convert the deregistration data (TLV format of the IIFAA protocol) into Uint8Array to obtain tlvDeregisterRp, and then call the ifaa.deregisterSync API.
try {
ifaa.deregisterSync(tlvDeregisterRp);
// ...
} catch (error) {
const err = error as BusinessError;
console.error(`Failed to deregister. Code is ${err.code}, message is ${err.message}`);
// ...
}