From 9bb2cf6a08609752154a7863f0a0248db8ba7b3c Mon Sep 17 00:00:00 2001 From: kierancrown Date: Thu, 22 Aug 2024 21:30:14 +0100 Subject: [PATCH 01/10] feat: biometrics type --- .../SimpleBiometricsModule.java | 21 ++++++++++++-- example/App.tsx | 11 +++++++- ios/SimpleBiometrics.mm | 28 +++++++++++++++++++ src/index.tsx | 10 +++++++ 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java b/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java index d4c53a4..9313c05 100644 --- a/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java +++ b/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java @@ -1,6 +1,7 @@ package com.reactnativesimplebiometrics; import android.app.Activity; +import android.content.pm.PackageManager; import androidx.annotation.NonNull; import java.util.concurrent.Executor; @@ -16,8 +17,6 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentActivity; - - @ReactModule(name = SimpleBiometricsModule.NAME) public class SimpleBiometricsModule extends ReactContextBaseJavaModule { public static final String NAME = "SimpleBiometrics"; @@ -96,4 +95,22 @@ public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationRes ); } + + @ReactMethod + public void getBiometryType(Promise promise) { + try { + ReactApplicationContext context = getReactApplicationContext(); + PackageManager pm = context.getPackageManager(); + + if (pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) { + promise.resolve("Fingerprint"); + } else if (pm.hasSystemFeature(PackageManager.FEATURE_FACE)) { + promise.resolve("Face"); + } else { + promise.resolve("Unknown"); + } + } catch (Exception e) { + promise.reject(e); + } + } } diff --git a/example/App.tsx b/example/App.tsx index 2743461..ed9fab7 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -10,12 +10,21 @@ import RNBiometrics from 'react-native-simple-biometrics'; const App = () => { const [canAuth, setCanAuth] = useState(false); + const [type, setType] = useState(''); const [authenticated, setAuthenticated] = useState(false); useEffect(() => { RNBiometrics.canAuthenticate().then(setCanAuth); }, []); + useEffect(() => { + if (!canAuth) { + setType('Unknown'); + return; + } + RNBiometrics.getBiometryType().then(setType); + }, [canAuth]); + const authenticate = useCallback(async () => { try { const success = await RNBiometrics.requestBioAuth( @@ -40,7 +49,7 @@ const App = () => { {authenticated ? '🔓' : '🔒'} - {authenticated ? '$1,000,000' : '(tap to unlock)'} + {authenticated ? '$1,000,000' : `(tap to unlock using ${type})`} ) : ( diff --git a/ios/SimpleBiometrics.mm b/ios/SimpleBiometrics.mm index 1bad425..e9e8812 100644 --- a/ios/SimpleBiometrics.mm +++ b/ios/SimpleBiometrics.mm @@ -56,6 +56,34 @@ @implementation SimpleBiometrics } +RCT_REMAP_METHOD(getBiometryType, + getBiometryTypeWithResolver:(RCTPromiseResolveBlock)resolve + rejecter:(RCTPromiseRejectBlock)reject) +{ + LAContext *context = [[LAContext alloc] init]; + NSError *la_error = nil; + + // Check if the device can evaluate a biometric policy + if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&la_error]) { + if (@available(iOS 11.0, *)) { + // iOS 11+ supports biometryType property + if (context.biometryType == LABiometryTypeFaceID) { + resolve(@"FaceID"); + } else if (context.biometryType == LABiometryTypeTouchID) { + resolve(@"TouchID"); + } else { + resolve(@"None"); + } + } else { + // Fallback for iOS versions earlier than 11.0 + resolve(@"Unknown"); + } + } else { + // Handle the error case where biometric authentication is not available + resolve(@"None"); + } +} + // Don't compile this code when we build for the old architecture. #ifdef RCT_NEW_ARCH_ENABLED - (std::shared_ptr)getTurboModule: diff --git a/src/index.tsx b/src/index.tsx index 1f688e0..5c81979 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -32,9 +32,19 @@ const requestBioAuth = ( return RNBiometricsNative.requestBioAuth(promptTitle, promptMessage); }; +/** + * Get the type of biometric authentication available on the device + */ +const getBiometryType = (): Promise< + 'Fingerprint' | 'Face' | 'None' | 'Unknown' +> => { + return RNBiometricsNative.getBiometryType(); +}; + const RNBiometrics = { requestBioAuth, canAuthenticate, + getBiometryType, // Added new method here }; export default RNBiometrics; From b2460e92f9cf496c9b3ee394893173c00634b8b3 Mon Sep 17 00:00:00 2001 From: kierancrown Date: Sat, 24 Aug 2024 12:28:26 +0100 Subject: [PATCH 02/10] fix: android states --- .../reactnativesimplebiometrics/SimpleBiometricsModule.java | 4 ++-- src/index.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java b/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java index 9313c05..4b3ab22 100644 --- a/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java +++ b/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java @@ -107,10 +107,10 @@ public void getBiometryType(Promise promise) { } else if (pm.hasSystemFeature(PackageManager.FEATURE_FACE)) { promise.resolve("Face"); } else { - promise.resolve("Unknown"); + promise.resolve("None"); } } catch (Exception e) { - promise.reject(e); + promise.resolve("Unknown") } } } diff --git a/src/index.tsx b/src/index.tsx index 5c81979..4c77e4a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -44,7 +44,7 @@ const getBiometryType = (): Promise< const RNBiometrics = { requestBioAuth, canAuthenticate, - getBiometryType, // Added new method here + getBiometryType, }; export default RNBiometrics; From dccde017c774475ec174ed851c28990772938daf Mon Sep 17 00:00:00 2001 From: kierancrown Date: Wed, 28 Aug 2024 00:38:21 +0100 Subject: [PATCH 03/10] fix: missing typo --- .../com/reactnativesimplebiometrics/SimpleBiometricsModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java b/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java index 4b3ab22..64fff5f 100644 --- a/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java +++ b/android/src/main/java/com/reactnativesimplebiometrics/SimpleBiometricsModule.java @@ -110,7 +110,7 @@ public void getBiometryType(Promise promise) { promise.resolve("None"); } } catch (Exception e) { - promise.resolve("Unknown") + promise.resolve("Unknown"); } } } From 27488cab2affcaf648c3e561945c9773e7076aa2 Mon Sep 17 00:00:00 2001 From: kierancrown Date: Thu, 24 Oct 2024 17:22:47 +0100 Subject: [PATCH 04/10] updated RN compatability --- package.json | 16 ++++++++-------- react-native-simple-biometrics.podspec | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index ff04659..309be1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-simple-biometrics", - "version": "1.5.2", + "version": "1.5.3", "description": "test", "main": "lib/commonjs/index", "module": "lib/module/index", @@ -35,13 +35,13 @@ "ios", "android" ], - "repository": "https://github.com/smallcase/react-native-simple-biometrics", + "repository": "https://github.com/kierancrown/react-native-simple-biometrics", "author": "smallcase (https://github.com/smallcase)", "license": "MIT", "bugs": { - "url": "https://github.com/smallcase/react-native-simple-biometrics/issues" + "url": "https://github.com/kierancrown/react-native-simple-biometrics/issues" }, - "homepage": "https://github.com/smallcase/react-native-simple-biometrics#readme", + "homepage": "https://github.com/kierancrown/react-native-simple-biometrics#readme", "publishConfig": { "registry": "https://registry.npmjs.org/" }, @@ -49,11 +49,11 @@ "@arkweid/lefthook": "^0.7.7", "@babel/eslint-parser": "^7.18.2", "@commitlint/config-conventional": "^17.0.2", - "@react-native-community/eslint-config": "^3.0.2", + "@react-native-community/eslint-config": "^3.2.0", "@release-it/conventional-changelog": "^5.0.0", "@types/jest": "^28.1.2", "@types/react": "~17.0.21", - "@types/react-native": "0.68.0", + "@types/react-native": "^0.73.0", "commitlint": "^17.0.2", "eslint": "^8.4.1", "eslint-config-prettier": "^8.5.0", @@ -61,8 +61,8 @@ "jest": "^28.1.1", "pod-install": "^0.1.0", "prettier": "^2.0.5", - "react": "17.0.2", - "react-native": "0.68.2", + "react": "18.3.1", + "react-native": "^0.76.0", "react-native-builder-bob": "^0.18.3", "release-it": "^15.0.0", "typescript": "^4.5.2" diff --git a/react-native-simple-biometrics.podspec b/react-native-simple-biometrics.podspec index eb3e077..19ee038 100644 --- a/react-native-simple-biometrics.podspec +++ b/react-native-simple-biometrics.podspec @@ -1,7 +1,7 @@ require "json" package = JSON.parse(File.read(File.join(__dir__, "package.json"))) -folly_version = '2021.06.28.00-v2' +folly_version = '2024.01.01.00' folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' Pod::Spec.new do |s| @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.authors = package["author"] s.platforms = { :ios => "10.0" } - s.source = { :git => "https://github.com/smallcase/react-native-simple-biometrics.git", :tag => "#{s.version}" } + s.source = { :git => "https://github.com/kierancrown/react-native-simple-biometrics.git", :tag => "#{s.version}" } s.source_files = "ios/**/*.{h,m,mm}" From 0bf0b7965b500306c7b5d668cbe26700552ff5a2 Mon Sep 17 00:00:00 2001 From: kierancrown Date: Thu, 24 Oct 2024 17:23:12 +0100 Subject: [PATCH 05/10] chore: release 1.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 309be1f..840ebfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-simple-biometrics", - "version": "1.5.3", + "version": "1.6.0", "description": "test", "main": "lib/commonjs/index", "module": "lib/module/index", From d0ed8a51b17f53ad44c7ced54c62cbade9069d62 Mon Sep 17 00:00:00 2001 From: kierancrown Date: Thu, 24 Oct 2024 17:33:29 +0100 Subject: [PATCH 06/10] chore: release 1.6.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 840ebfd..85deca7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-simple-biometrics", - "version": "1.6.0", + "version": "1.6.1", "description": "test", "main": "lib/commonjs/index", "module": "lib/module/index", From a1c3144e692d6df58c9a6c14681888bcd567f829 Mon Sep 17 00:00:00 2001 From: kierancrown Date: Thu, 24 Oct 2024 17:35:17 +0100 Subject: [PATCH 07/10] feat(rn upgrade): add spec --- ios/SimpleBiometrics.spec.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ios/SimpleBiometrics.spec.h diff --git a/ios/SimpleBiometrics.spec.h b/ios/SimpleBiometrics.spec.h new file mode 100644 index 0000000..8760e14 --- /dev/null +++ b/ios/SimpleBiometrics.spec.h @@ -0,0 +1,20 @@ +#import +#import +#import +#import + +namespace facebook { +namespace react { + + class JSI_EXPORT NativeSimpleBiometricsSpecJSI : public ObjCTurboModule { + public: + NativeSimpleBiometricsSpecJSI(const ObjCTurboModule::InitParams ¶ms); + + // Declare the methods your module exports + void canAuthenticate(jsi::Runtime &rt, std::function &&resolve, std::function &&reject); + void requestBioAuth(jsi::Runtime &rt, const std::string &title, const std::string &subtitle, std::function &&resolve, std::function &&reject); + void getBiometryType(jsi::Runtime &rt, std::function &&resolve, std::function &&reject); + }; + +} +} From e37c46023e3923e6ba6a19688ae473f9cf76f103 Mon Sep 17 00:00:00 2001 From: kierancrown Date: Thu, 24 Oct 2024 17:35:41 +0100 Subject: [PATCH 08/10] chore: release 1.7.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 85deca7..23bb251 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-simple-biometrics", - "version": "1.6.1", + "version": "1.7.0", "description": "test", "main": "lib/commonjs/index", "module": "lib/module/index", From 93c6d036153c2075bd90b5620b8c300a3f98a23c Mon Sep 17 00:00:00 2001 From: kierancrown Date: Thu, 24 Oct 2024 17:40:13 +0100 Subject: [PATCH 09/10] feat(rn upgrade): add spec --- ios/{SimpleBiometrics.spec.h => RNSimpleBiometricsSpec.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ios/{SimpleBiometrics.spec.h => RNSimpleBiometricsSpec.h} (100%) diff --git a/ios/SimpleBiometrics.spec.h b/ios/RNSimpleBiometricsSpec.h similarity index 100% rename from ios/SimpleBiometrics.spec.h rename to ios/RNSimpleBiometricsSpec.h From d5d3cee4ae36e97c0cc9655eb1775597b2c63275 Mon Sep 17 00:00:00 2001 From: kierancrown Date: Thu, 24 Oct 2024 17:40:30 +0100 Subject: [PATCH 10/10] chore: release 1.8.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 23bb251..877c7ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-simple-biometrics", - "version": "1.7.0", + "version": "1.8.0", "description": "test", "main": "lib/commonjs/index", "module": "lib/module/index",