@exodus/react-native-biometrics 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Exodus Movement, Inc
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @exodus/react-native-biometrics
2
+
3
+ A biometric authentication library for Android platform using the BiometricPrompt API.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install @exodus/react-native-biometrics
9
+ ```
10
+
11
+ ## Usage
12
+
13
+
14
+ ```js
15
+ import Biometrics from '@exodus/react-native-biometrics';
16
+
17
+ // ...
18
+
19
+ const valid = await Biometrics.authenticate(
20
+ 'Authenticate to continue',
21
+ 'Use your fingerprint to authenticate',
22
+ 'Cancel',
23
+ );
24
+ ```
25
+
26
+ ## Props
27
+
28
+ | Name | Type | Description |
29
+ | ---- | ---- | ----------- |
30
+ | title | string | The title of the biometric prompt |
31
+ | subtitle | string | The subtitle of the biometric prompt |
32
+ | cancelButtonText | string | The text of the cancel button |
33
+
34
+
35
+ ## License
36
+
37
+ MIT
38
+
39
+ ---
40
+
41
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,34 @@
1
+ buildscript {
2
+ ext.safeExtGet = {prop, fallback ->
3
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
4
+ }
5
+ }
6
+
7
+ apply plugin: 'com.android.library'
8
+
9
+ // Matches values in recent template from React Native (0.59)
10
+ // https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L5-L9
11
+ def DEFAULT_COMPILE_SDK_VERSION = 28
12
+ def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3"
13
+ def DEFAULT_MIN_SDK_VERSION = 16
14
+ def DEFAULT_TARGET_SDK_VERSION = 28
15
+
16
+ android {
17
+ compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
18
+ buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
19
+
20
+ defaultConfig {
21
+ minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
22
+ targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
23
+ versionCode 1
24
+ versionName "1.0"
25
+ }
26
+ lintOptions {
27
+ abortOnError false
28
+ }
29
+ }
30
+
31
+ dependencies {
32
+ implementation "com.facebook.react:react-native:${safeExtGet('reactnativeVersion', '+')}"
33
+ implementation "androidx.biometric:biometric:1.1.0"
34
+ }
@@ -0,0 +1,4 @@
1
+ ReactNativeBiometrics_minSdkVersion=21
2
+ ReactNativeBiometrics_targetSdkVersion=31
3
+ ReactNativeBiometrics_compileSdkVersion=31
4
+ ReactNativeBiometrics_ndkversion=21.4.7075529
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="org.exodusmovement.rn.biometrics">
3
+ </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,68 @@
1
+ package org.exodusmovement.rn.biometrics;
2
+
3
+ import java.util.concurrent.Executor;
4
+ import com.facebook.react.bridge.Promise;
5
+ import com.facebook.react.bridge.ReactMethod;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
8
+ import com.facebook.react.module.annotations.ReactModule;
9
+
10
+ import androidx.biometric.BiometricPrompt;
11
+ import androidx.biometric.BiometricManager;
12
+ import androidx.core.content.ContextCompat;
13
+ import androidx.fragment.app.FragmentActivity;
14
+
15
+ @ReactModule(name = RNBiometricsModule.NAME)
16
+ public final class RNBiometricsModule extends ReactContextBaseJavaModule {
17
+ public static final String NAME = "Biometrics";
18
+
19
+ private final ReactApplicationContext context;
20
+
21
+ public RNBiometricsModule(ReactApplicationContext context) {
22
+ super(context);
23
+ this.context = context;
24
+ }
25
+
26
+ @Override
27
+ public String getName() {
28
+ return NAME;
29
+ }
30
+
31
+ @ReactMethod
32
+ public void authenticate(String title, String subtitle, String cancelButtonText, Promise promise) {
33
+ context.getCurrentActivity().runOnUiThread(new Runnable() {
34
+ @Override
35
+ public void run() {
36
+ try {
37
+ new BiometricPrompt(
38
+ (FragmentActivity) context.getCurrentActivity(),
39
+ ContextCompat.getMainExecutor(context),
40
+ new BiometricPrompt.AuthenticationCallback() {
41
+ @Override
42
+ public void onAuthenticationError(int errorCode, CharSequence errString) {
43
+ super.onAuthenticationError(errorCode, errString);
44
+ promise.resolve(false);
45
+ }
46
+
47
+ @Override
48
+ public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
49
+ super.onAuthenticationSucceeded(result);
50
+ promise.resolve(true);
51
+ }
52
+ }
53
+ ).authenticate(
54
+ new BiometricPrompt.PromptInfo.Builder()
55
+ .setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG)
56
+ .setTitle(title)
57
+ .setSubtitle(subtitle)
58
+ .setNegativeButtonText(cancelButtonText)
59
+ .build()
60
+ );
61
+
62
+ } catch (Exception e) {
63
+ promise.reject(e);
64
+ }
65
+ }
66
+ });
67
+ }
68
+ }
@@ -0,0 +1,23 @@
1
+ package org.exodusmovement.rn.biometrics;
2
+
3
+ import com.facebook.react.ReactPackage;
4
+ import com.facebook.react.bridge.NativeModule;
5
+ import com.facebook.react.bridge.ReactApplicationContext;
6
+ import com.facebook.react.uimanager.ViewManager;
7
+
8
+ import java.util.Arrays;
9
+ import java.util.Collections;
10
+ import java.util.List;
11
+
12
+ public class RNBiometricsPackage implements ReactPackage {
13
+ @Override
14
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
+ return Arrays.<NativeModule>asList(new RNBiometricsModule(reactContext));
16
+ }
17
+
18
+ @Override
19
+ @SuppressWarnings("rawtypes")
20
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
21
+ return Collections.emptyList();
22
+ }
23
+ }
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import Biometrics from './src/Biometrics';
2
+
3
+ export default Biometrics;
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@exodus/react-native-biometrics",
3
+ "version": "0.1.0",
4
+ "description": "React Native Biometrics",
5
+ "main": "index.js",
6
+ "files": [
7
+ "src",
8
+ "lib",
9
+ "android",
10
+ "ios",
11
+ "cpp",
12
+ "index.js",
13
+ "*.podspec",
14
+ "!ios/build",
15
+ "!android/build",
16
+ "!android/gradle",
17
+ "!android/.gradle",
18
+ "!android/gradlew",
19
+ "!android/gradlew.bat",
20
+ "!android/local.properties",
21
+ "!**/__tests__",
22
+ "!**/__fixtures__",
23
+ "!**/__mocks__",
24
+ "!**/.*"
25
+ ],
26
+ "scripts": {
27
+ "test": "jest",
28
+ "lint": "eslint ./"
29
+ },
30
+ "keywords": [
31
+ "react-native",
32
+ "ios",
33
+ "android"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/ExodusMovement/react-native-biometrics.git"
38
+ },
39
+ "author": "Exodus Movement, Inc (https://github.com/ExodusMovement)",
40
+ "license": "MIT",
41
+ "bugs": {
42
+ "url": "https://github.com/ExodusMovement/react-native-biometrics/issues"
43
+ },
44
+ "homepage": "https://github.com/ExodusMovement/react-native-biometrics#readme",
45
+ "publishConfig": {
46
+ "registry": "https://registry.npmjs.org/"
47
+ },
48
+ "peerDependencies": {
49
+ "react": ">=16.8.0",
50
+ "react-native": ">=0.57.0"
51
+ },
52
+ "react-native": {
53
+ "_stream_transform": "readable-stream/transform",
54
+ "_stream_readable": "readable-stream/readable",
55
+ "_stream_writable": "readable-stream/writable",
56
+ "_stream_duplex": "readable-stream/duplex",
57
+ "_stream_passthrough": "readable-stream/passthrough",
58
+ "stream": "stream-browserify"
59
+ },
60
+ "browser": {
61
+ "_stream_duplex": "readable-stream/duplex",
62
+ "_stream_passthrough": "readable-stream/passthrough",
63
+ "_stream_readable": "readable-stream/readable",
64
+ "_stream_transform": "readable-stream/transform",
65
+ "_stream_writable": "readable-stream/writable",
66
+ "stream": "stream-browserify"
67
+ },
68
+ "devDependencies": {
69
+ "@eslint/js": "^9.13.0",
70
+ "eslint": "^9.13.0",
71
+ "eslint-plugin-react": "^7.37.2",
72
+ "globals": "^15.11.0"
73
+ }
74
+ }
@@ -0,0 +1,9 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ const AndroidBiometrics = NativeModules.Biometrics;
4
+
5
+ export default {
6
+ authenticate: async (title, subtitle, description) => {
7
+ return AndroidBiometrics.authenticate(title, subtitle, description);
8
+ }
9
+ }
@@ -0,0 +1,5 @@
1
+ export default {
2
+ authenticate: async () => {
3
+ return Promise.reject('Biometrics is not supported on this platform');
4
+ }
5
+ }