Skip to content

Commit ff7dcff

Browse files
authored
feat(biometrics): android didBiometricDatabaseChange (#314)
1 parent 14d6b48 commit ff7dcff

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

packages/biometrics/index.android.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,30 @@ export class BiometricAuth implements BiometricApi {
141141
});
142142
}
143143

144-
didBiometricDatabaseChange(): Promise<boolean> {
145-
return Promise.resolve(false);
146-
}
144+
// Following: https://stackoverflow.com/questions/61193681/check-if-the-user-changed-biometric-fingerprint-in-android as a guide
145+
didBiometricDatabaseChange(): Promise<boolean> {
146+
return new Promise((resolve, reject) => {
147+
const options = {};
148+
const cipher = this.getCipher();
149+
var secretKey = this.getSecretKey(KEY_NAME);
150+
if (secretKey === null) {
151+
BiometricAuth.generateSecretKey(options, reject);
152+
secretKey = this.getSecretKey(KEY_NAME);
153+
}
154+
try {
155+
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, secretKey);
156+
} catch (ex) {
157+
console.log(`Error in biometrics-auth.verifyBiometric: ${ex}`);
158+
try {
159+
BiometricAuth.generateSecretKey(options, reject);
160+
resolve(true);
161+
} catch (e) {
162+
console.log(`Error when generating new key: ${ex}`);
163+
}
164+
}
165+
resolve(false);
166+
});
167+
}
147168

148169
// Following: https://developer.android.com/training/sign-in/biometric-auth#java as a guide
149170
verifyBiometric(options: VerifyBiometricOptions): Promise<BiometricResult> {

0 commit comments

Comments
 (0)