Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onAuthenticationError(int errorCode, @NonNull CharSequence errString
resultMap.putString("error", "User cancellation");
this.promise.resolve(resultMap);
} else {
this.promise.reject(errString.toString(), errString.toString());
this.promise.reject(String.valueOf(errorCode), errString.toString());
}
}

Expand Down
28 changes: 28 additions & 0 deletions android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,32 @@ protected boolean deleteBiometricKey() {
return false;
}
}

@ReactMethod
public void biometricKeysExistAndSignatureValid(Promise promise) {
try {
boolean doesBiometricKeyExist = doesBiometricKeyExistAndSignatureValid();
WritableMap resultMap = new WritableNativeMap();
resultMap.putBoolean("keysExist", doesBiometricKeyExist);
promise.resolve(resultMap);
} catch (Exception e) {
promise.reject("Error checking if biometric key exists: " + e.getMessage(),
"Error checking if biometric key exists: " + e.getMessage());
}
}

protected boolean doesBiometricKeyExistAndSignatureValid() {
try {
Signature signature = Signature.getInstance("SHA256withRSA");
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);

PrivateKey privateKey = (PrivateKey) keyStore.getKey(biometricKeyAlias, null);
signature.initSign(privateKey);

return true;
} catch (Exception e) {
return false;
}
}
}
21 changes: 21 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ interface SimplePromptResult {
success: boolean
error?: string
}
interface BiometricKeysExistAndSignatureValidResult {
keysExist: boolean
}

/**
* Enum for touch id sensor type
Expand Down Expand Up @@ -132,6 +135,15 @@ export module ReactNativeBiometricsLegacy {
export function simplePrompt(simplePromptOptions: SimplePromptOptions): Promise<SimplePromptResult> {
return new ReactNativeBiometrics().simplePrompt(simplePromptOptions)
}

/**
* Returns promise that resolves to an object with object.keysExists = true | false
* indicating if the keys were found to exist or not and signature valid
* @returns {Promise<Object>} Promise that resolves to object with details aobut the existence of keys
*/
export function biometricKeysExistAndSignatureValid(): Promise<BiometricKeysExistAndSignatureValidResult> {
return new ReactNativeBiometrics().biometricKeysExistAndSignatureValid();
}
}

export default class ReactNativeBiometrics {
Expand Down Expand Up @@ -221,4 +233,13 @@ export default class ReactNativeBiometrics {
...simplePromptOptions
})
}

/**
* Returns promise that resolves to an object with object.keysExists = true | false
* indicating if the keys were found to exist or not and signature valid
* @returns {Promise<Object>} Promise that resolves to object with details aobut the existence of keys
*/
biometricKeysExistAndSignatureValid(): Promise<BiometricKeysExistAndSignatureValidResult> {
return bridge.biometricKeysExistAndSignatureValid();
}
}
18 changes: 18 additions & 0 deletions ios/ReactNativeBiometrics.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ @implementation ReactNativeBiometrics
});
}

RCT_EXPORT_METHOD(biometricKeysExistAndSignatureValid: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
BOOL biometricKeyExists = [self doesBiometricKeyExist];

if (biometricKeyExists) {
NSDictionary *result = @{
@"keysExist": @(YES)
};
resolve(result);
} else {
NSDictionary *result = @{
@"keysExist": @(NO)
};
resolve(result);
}
});
}

- (NSData *) getBiometricKeyTag {
NSString *biometricKeyAlias = @"com.rnbiometrics.biometricKey";
NSData *biometricKeyTag = [biometricKeyAlias dataUsingEncoding:NSUTF8StringEncoding];
Expand Down