verifyBiometric method
Implementation
Future<Map<String, dynamic>> verifyBiometric(List<dynamic> args) async {
final data = processArgs(args);
final missingFields = validateRequiredFields(data, ["challenge"]);
if (missingFields.isNotEmpty) {
return VerifyBiometricModel(
success: false,
message: "Verification failed",
device: await getDeviceInfo(),
errorCodes: [
Status.jsMissingFields.name,
],
).toMap();
}
final String challenge = data["challenge"];
final result = await sl<BiometricService>().verify();
if (result != BiometricStatus.success) {
return VerifyBiometricModel(
success: false,
message: result == BiometricStatus.bioNotAvailable
? "No biometrics found in the device"
: "Verification Failed.",
device: await getDeviceInfo(),
errorCodes: [
BiometricStatus.bioPublicKeyNotFound.name,
],
).toMap();
}
final publicKey = await sl<StorageService>().readBioPublicKey();
final encryptedChallenge =
sl<EncryptionService>().encryptWithRsa(publicKey!.key, challenge);
return VerifyBiometricModel(
success: true,
message: "Verification success",
device: await getDeviceInfo(),
errorCodes: [],
encryptedChallenge: encryptedChallenge,
credentialId: publicKey.credId,
).toMap();
}