Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

valora-inc/react-native-confirm-device-credentials

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-confirm-device-credentials

A simple React Native module to access Android's native device authentication screen.

Getting started

$ npm install react-native-confirm-device-credentials --save

Mostly automatic installation

$ react-native link react-native-confirm-device-credentials

Manual installation

Android (Only API 23 and above are supported)

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import org.celo.devicecredentials.RNConfirmDeviceCredentialsPackage; to the imports at the top of the file
  • Add new RNConfirmDeviceCredentialsPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-confirm-device-credentials'
    project(':react-native-confirm-device-credentials').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-confirm-device-credentials/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-confirm-device-credentials')
    

Usage

import ConfirmDeviceCredentials from "react-native-confirm-device-credentials";

ConfirmDeviceCredentials.isDeviceSecure().then(
  (isDeviceSecureResult: boolean) => {
    console.log("Is device secure: " + isDeviceSecureResult);
    if (!isDeviceSecureResult) {
      ConfirmDeviceCredentials.makeDeviceSecure(
        humanReadableMessage,
        securitySettingsButtonLabel
      )
        .then((result: boolean) => {
          console.log("Result of make device secure: " + result);
        })
        .catch((error: any) => {
          console.log("User canceled authentication: " + error);
        });
    }
    if (isDeviceSecureResult) {
      ConfirmDeviceCredentials.keystoreInit(keyName, 10, false).then(
        (keyStoreInitResult: boolean) => {
          console.log("Keystore init result: " + keyStoreInitResult);
          if (keyStoreInitResult) {
            ConfirmDeviceCredentials.storePin(keyName, pin)
              .then((storePinResult: boolean) => {
                console.log("Store Pin result: " + storePinResult);
                ConfirmDeviceCredentials.retrievePin(keyName).then(
                  (decryptedPin: string) => {
                    console.log("Decrypted Pin is : " + decryptedPin);
                  }
                );
              })
              .catch((reason: any) => {
                console.log("Store pin failed: " + reason);
              });
          }
        }
      );
    }
  }
);

About

Confirm Device Credentials React Native module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •