1.0.4 β€’ Published 8 months ago

@capitual/react-native-capface-sdk v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@capitual/react-native-capface-sdk

Capface sdk adapter to react native. πŸ“±

Installation

npm install @capitual/react-native-capface-sdk

Usage

import * as React from 'react';

import {
  StyleSheet,
  View,
  Text,
  TouchableOpacity,
  ScrollView,
  NativeEventEmitter,
} from 'react-native';
import ReactNativeCapfaceSdk, {
  authenticate,
  enroll,
  initialize,
  photoMatch,
} from '@capitual/react-native-capface-sdk';

export default function App() {
  const init = async () => {
    /*
     * The SDK must be initialized first
     * so that the rest of the library
     * functions can work!
     *
     * */
    const headers = {
      'clientInfo': 'YUOR_CLIENT_INFO',
      'contentType': 'YOUR_CONTENT_TYPE',
      'device': 'YOUR_DEVICE',
      'deviceid': 'YOUR_DEVICE_ID',
      'deviceip': 'YOUR_DEVICE_IP',
      'locale': 'YOUR_LOCALE',
      'xForwardedFor': 'YOUR_X_FORWARDED_FOR',
      'user-agent': 'YOUR_USER_AGENT',
    };
    const params = {
      device: 'YOUR_DEVICE',
      url: 'YOUR_BASE_URL',
      key: 'YOUR_KEY',
      productionKey: 'YOUR_PRODUCTION_KEY',
    };

    const isInitialized = await initialize({
      params,
      headers,
    });

    console.log(isInitialized);
  };

  const emitter = new NativeEventEmitter(ReactNativeCapfaceSdk);
  emitter.addListener('onCloseModal', (event: boolean) =>
    console.log('onCloseModal', event)
  );

  const onPressPhotoMatch = async () => {
    try {
      const isSuccess = await photoMatch();
      console.log(isSuccess);
    } catch (error: any) {
      console.error(error.message);
    }
  };

  const onPressEnroll = async () => {
    try {
      const isSuccess = await enroll();
      console.log(isSuccess);
    } catch (error: any) {
      console.error(error.message);
    }
  };

  const onPressAuthenticate = async () => {
    try {
      const isSuccess = await authenticate();
      console.log(isSuccess);
    } catch (error: any) {
      console.error(error.message);
    }
  };

  return (
    <ScrollView style={styles.container}>
      <View style={styles.content}>
        <TouchableOpacity
          style={styles.button}
          onPress={async () => await init()}
        >
          <Text style={styles.text}>Init Capface Module</Text>
        </TouchableOpacity>
        <TouchableOpacity style={styles.button} onPress={onPressPhotoMatch}>
          <Text style={styles.text}>Open Photo Match</Text>
        </TouchableOpacity>
        <TouchableOpacity style={styles.button} onPress={onPressEnroll}>
          <Text style={styles.text}>Open Enroll</Text>
        </TouchableOpacity>
        <TouchableOpacity style={styles.button} onPress={onPressAuthenticate}>
          <Text style={styles.text}>Open Authenticate</Text>
        </TouchableOpacity>
      </View>
    </ScrollView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 20,
  },
  content: {
    justifyContent: 'center',
    alignItems: 'center',
    marginVertical: 30,
  },
  button: {
    width: '100%',
    backgroundColor: '#4a68b3',
    padding: 20,
    borderRadius: 15,
    alignItems: 'center',
    justifyContent: 'center',
    marginVertical: 20,
  },
  text: {
    color: 'white',
    fontWeight: '700',
    fontSize: 22,
  },
});

API

MethodsReturn TypeiOSAndroid
initialize(init: CapfaceSdk.Initialize)Promise<boolean>βœ…βœ…
enroll(data?: Object)Promise<boolean>βœ…βœ…
authenticate(data?: Object)Promise<boolean>βœ…βœ…
photoMatch(data?: Object)Promise<boolean>βœ…βœ…
setTheme(options?: CapfaceSdk.Theme)voidβœ…βœ…

initialize(init: CapfaceSdk.Initialize)

This is the principal method to be called, he must be called first to initialize the Capface SDK. If he doens't be called the other methods don't works!

CapfaceSdk.InitializetypeRequiredDefault
paramsCapfaceSdk.Paramsβœ…-
headersCapfaceSdk.Headers❌undefined

enroll(data?: Object)

This method makes a 3D reading of the user's face. But, you must use to subscribe user in Capface SDK or in your server.

ObjecttypeRequiredDefault
dataObject❌undefined

authenticate(data?: Object)

This method makes a 3D reading of the user's face. But, you must use to authenticate user in Capface SDK or in your server.

ObjecttypeRequiredDefault
dataObject❌undefined

photoScan(data?: Object)

This method make to read from documents for user.

ObjecttypeRequiredDefault
dataObject❌undefined

photoMatch(data?: Object)

This method make to read from face and documents for user, after comparate face and face documents from user to check veracity.

ObjecttypeRequiredDefault
dataObject❌undefined

setTheme(options?: CapfaceSdk.Theme)

This method must be used to set the theme of the Capface SDK screen.

CapfaceSdk.ThemetypeRequiredDefault
optionsCapfaceSdk.Theme❌undefined

Types

CapfaceSdk - TypesiOSAndroid
CapfaceSdk.Paramsβœ…βœ…
CapfaceSdk.Headersβœ…βœ…
CapfaceSdk.Themeβœ…βœ…
CapfaceSdk.ButtonLocationβœ…βœ…
CapfaceSdk.StatusBarColorβœ…βŒ
CapfaceSdk.FeedbackBackgroundColorβœ…βŒ
CapfaceSdk.Pointβœ…βŒ
CapfaceSdk.DefaultMessageβœ…βœ…
CapfaceSdk.DefaultScanMessageβœ…βœ…

CapfaceSdk.Params

Here must be passed to initialize the Capface SDK! Case the parameters isn't provided the Capface SDK goes to be not initialized.

CapfaceSdk.ParamstypeRequired
devicestringβœ…
urlstringβœ…
keystringβœ…
productionKeystringβœ…
isDeveloperModeboolean❌

CapfaceSdk.Headers

Here you can add your headers to send request when some method is called. Only values from type string, null or undefined are accepts!

CapfaceSdk.HeaderstypeRequiredDefault
[key: string]string, null or undefined❌undefined

CapfaceSdk.Theme

This is a list of theme properties that can be used to styling. Note, we recommend that you use only hexadecimal values to colors, between six and eight characters, because still we don't supported others color type.

CapfaceSdk.ThemetypeiOSAndroidRequiredDefault
logoImagestringβœ…βœ…βŒfacetec_your_app_logo.png
cancelImagestringβœ…βœ…βŒfacetec_cancel.png
cancelButtonLocationCapfaceSdk.ButtonLocationβœ…βœ…βŒTOP_RIGHT
defaultStatusBarColorIosCapfaceSdk.StatusBarColorβœ…βŒβŒDARK_CONTENT
frameCornerRadiusnumberβœ…βœ…βŒ10 (iOS) and 20 (Android)
frameBackgroundColorstringβœ…βœ…βŒ#FFFFFF
frameBorderColorstringβœ…βœ…βŒ#FFFFFF
overlayBackgroundColorstringβœ…βœ…βŒ#FFFFFF
guidanceBackgroundColorsAndroidstringβŒβœ…βŒ#FFFFFF
guidanceBackgroundColorsIosstring[]βœ…βŒβŒ["#FFFFFF", "#FFFFFF"]
guidanceForegroundColorstringβœ…βœ…βŒ#272937
guidanceButtonBackgroundNormalColorstringβœ…βœ…βŒ#026FF4
guidanceButtonBackgroundDisabledColorstringβœ…βœ…βŒ#B3D4FC
guidanceButtonBackgroundHighlightColorstringβœ…βœ…βŒ#0264DC
guidanceButtonTextNormalColorstringβœ…βœ…βŒ#FFFFFF
guidanceButtonTextDisabledColorstringβœ…βœ…βŒ#FFFFFF
guidanceButtonTextHighlightColorstringβœ…βœ…βŒ#FFFFFF
guidanceRetryScreenImageBorderColorstringβœ…βœ…βŒ#FFFFFF
guidanceRetryScreenOvalStrokeColorstringβœ…βœ…βŒ#FFFFFF
ovalStrokeColorstringβœ…βœ…βŒ#026FF4
ovalFirstProgressColorstringβœ…βœ…βŒ#0264DC
ovalSecondProgressColorstringβœ…βœ…βŒ#0264DC
feedbackBackgroundColorsAndroidstringβŒβœ…βŒ#026FF4
feedbackBackgroundColorsIosCapfaceSdk.FeedbackBackgroundColor βœ…βŒβŒFeedbackBackgroundColor
feedbackTextColorstringβœ…βœ…βŒ#FFFFFF
resultScreenBackgroundColorsAndroidstringβŒβœ…βŒ#FFFFFF
resultScreenBackgroundColorsIosstring[]βœ…βŒβŒ["#FFFFFF", "#FFFFFF"]
resultScreenForegroundColorstringβœ…βœ…βŒ#272937
resultScreenActivityIndicatorColorstringβœ…βœ…βŒ#026FF4
resultScreenResultAnimationBackgroundColorstringβœ…βœ…βŒ#026FF4
resultScreenResultAnimationForegroundColorstringβœ…βœ…βŒ#FFFFFF
resultScreenUploadProgressFillColorstringβœ…βœ…βŒ#026FF4
idScanSelectionScreenBackgroundColorsAndroidstringβŒβœ…βŒ#FFFFFF
idScanSelectionScreenBackgroundColorsIosstring[]βœ…βŒβŒ["#FFFFFF", "#FFFFFF"]
idScanSelectionScreenForegroundColorstringβœ…βœ…βŒ#272937
idScanReviewScreenForegroundColorstringβœ…βœ…βŒ#FFFFFF
idScanReviewScreenTextBackgroundColorstringβœ…βœ…βŒ#026FF4
idScanCaptureScreenForegroundColorstringβœ…βœ…βŒ#FFFFFF
idScanCaptureScreenTextBackgroundColorstringβœ…βœ…βŒ#026FF4
idScanButtonBackgroundNormalColorstringβœ…βœ…βŒ#026FF4
idScanButtonBackgroundDisabledColorstringβœ…βœ…βŒ#B3D4FC
idScanButtonBackgroundHighlightColorstringβœ…βœ…βŒ#0264DC
idScanButtonTextNormalColorstringβœ…βœ…βŒ#FFFFFF
idScanButtonTextDisabledColorstringβœ…βœ…βŒ#FFFFFF
idScanButtonTextHighlightColorstringβœ…βœ…βŒ#FFFFFF
idScanCaptureScreenBackgroundColorstringβœ…βœ…βŒ#FFFFFF
idScanCaptureFrameStrokeColorstringβœ…βœ…βŒ#FFFFFF
autheticanteMessageCapfaceSdk.DefaultMessageβœ…βœ…βŒDefaultMessage
enrollMessageCapfaceSdk.DefaultMessageβœ…βœ…βŒDefaultMessage
photoIdScanMessageCapfaceSdk.DefaultScanMessageβœ…βœ…βŒDefaultScanMessage
photoIdMatchMessageCapfaceSdk.DefaultScanMessage and CapfaceSdk.DefaultMessageβœ…βœ…βŒDefaultScanMessage and DefaultMessage

CapfaceSdk.ButtonLocation

This type must be used to position of the cancel button on screen.

CapfaceSdk.ButtonLocationDescription
DISABLEDDisable cancel button and doesn't show it.
TOP_LEFTPosition cancel button in top right.
TOP_RIGHTPosition cancel button in top right. It's default position.

CapfaceSdk.StatusBarColor (iOS only)

This type must be used to status bar color.

CapfaceSdk.StatusBarColorDescription
DARK_CONTENTDefault color to status bar.
DEFAULTStatus bar color that's set from the device.
LIGHT_CONTENTLight color to status bar.

CapfaceSdk.FeedbackBackgroundColor (iOS only)

This type must be used to set the theme of the feedback box.

CapfaceSdk.FeedbackBackgroundColorDescriptiontypeRequiredDefault
colorsAn array of colors defining the color of each gradient stop.string[]❌["#026FF4", "#026FF4"]
locationsIt's accepts only two values between 0 and 1 that defining the location of each gradient stop.[number, number]❌[0, 1]
startPointThe start point of the gradient when drawn in the layer’s coordinate space.Point❌x: 0 and y: 0
endPointThe end point of the gradient when drawn in the layer’s coordinate space.Point❌x: 1 and y: 0

CapfaceSdk.Point (iOS only)

This interface defines the drawn in the layer's coordinate space.

CapfaceSdk.PointtypeRequiredDefault
xnumber❌undefined
ynumber❌undefined

CapfaceSdk.DefaultMessage

This interface represents the success message and loading data message during to CapfaceSDK flow. It interface is used more by processors's authenticate and enroll processors.

CapfaceSdk.DefaultMessagetypeiOSAndroidRequiredDefault
successMessagestringβœ…βœ…βŒLiveness Confirmed (Exception to authenticate method: Autheticated)
uploadMessageIosstringβœ…βŒβŒStill Uploading...

CapfaceSdk.DefaultScanMessage

This interface represents the all scan messages during to CapfaceSDK flow. It interface is used by photoMatch processors.

CapfaceSdk.DefaultScanMessagetypeiOSAndroidRequiredDefault
frontSideUploadStartedstringβœ…βœ…βŒUploading Encrypted ID Scan
frontSideStillUploadingstringβœ…βœ…βŒStill Uploading... Slow Connection
frontSideUploadCompleteAwaitingResponsestringβœ…βœ…βŒUpload Complete
frontSideUploadCompleteAwaitingResponsestringβœ…βœ…βŒProcessing ID Scan
backSideUploadStartedstringβœ…βœ…βŒUploading Encrypted Back of ID
backSideStillUploadingstringβœ…βœ…βŒStill Uploading... Slow Connection
backSideUploadCompleteAwaitingResponsestringβœ…βœ…βŒUpload Complete
backSideUploadCompleteAwaitingProcessingstringβœ…βœ…βŒProcessing Back of ID
userConfirmedInfoUploadStartedstringβœ…βœ…βŒUploading Your Confirmed Info
userConfirmedInfoStillUploadingstringβœ…βœ…βŒStill Uploading... Slow Connection
userConfirmedInfoUploadCompleteAwaitingResponsestringβœ…βœ…βŒUpload Complete
userConfirmedInfoUploadCompleteAwaitingProcessingstringβœ…βœ…βŒProcessing
nfcUploadStartedstringβœ…βœ…βŒUploading Encrypted NFC Details
nfcStillUploadingstringβœ…βœ…βŒStill Uploading... Slow Connection
nfcUploadCompleteAwaitingResponsestringβœ…βœ…βŒUpload Complete
nfcUploadCompleteAwaitingProcessingstringβœ…βœ…βŒProcessing NFC Details
skippedNFCUploadStartedstringβœ…βœ…βŒUploading Encrypted ID Details
skippedNFCStillUploadingstringβœ…βœ…βŒStill Uploading... Slow Connection
skippedNFCUploadCompleteAwaitingResponsestringβœ…βœ…βŒUpload Complete
skippedNFCUploadCompleteAwaitingProcessingstringβœ…βœ…βŒProcessing ID Details
successFrontSidestringβœ…βœ…βŒID Scan Complete
successFrontSideBackNextstringβœ…βœ…βŒFront of ID Scanned
successFrontSideNFCNextstringβœ…βœ…βŒFront of ID Scanned
successBackSidestringβœ…βœ…βŒID Scan Complete
successBackSideNFCNextstringβœ…βœ…βŒBack of ID Scanned
successPassportstringβœ…βœ…βŒPassport Scan Complete
successPassportNFCNextstringβœ…βœ…βŒPassport Scanned
successUserConfirmationstringβœ…βœ…βŒPhoto ID Scan Complete
successNFCstringβœ…βœ…βŒID Scan Complete
retryFaceDidNotMatchstringβœ…βœ…βŒFace Didn’t Match Highly Enough
retryIDNotFullyVisiblestringβœ…βœ…βŒID Document Not Fully Visible
retryOCRResultsNotGoodEnoughstringβœ…βœ…βŒID Text Not Legible
retryIDTypeNotSupportedstringβœ…βœ…βŒID Type Mismatch Please Try Again
skipOrErrorNFCstringβœ…βœ…βŒID Details Uploaded

CapfaceSdk.Errors

CapfaceSdk.ErrorsDescriptioniOSAndroid
CapFaceHasNotBeenInitializedWhen some processors method is runned, but CapfaceSDK has not been initialized.βœ…βœ…
CapFaceValuesWereNotProcessedWhen the image sent to the processors cannot be processed due to inconsistency.βœ…βœ…
HTTPSErrorWhen exists some network error.βœ…βœ…
JSONErrorWhen exists some problem in getting data in request of base URL information.βŒβœ…
CapFaceInvalidSessionWhen session status is invalid.βŒβœ…
CapFaceLivenessWasntProcessedWhen the image user sent to the processors cannot be processed due to inconsistency.βŒβœ…
CapFaceScanWasntProcessedWhen the image ID sent to the processors cannot be processed due to inconsistency.βŒβœ…

Native Events

MethodsReturn TypeiOSAndroid
addListener(eventType: string, callback: (event: boolean) => void)EmitterSubscriptionβœ…βœ…

Event Types

This is a list of event types that can be used on addListener.

eventTypeReturnDescription
onCloseModalbooleanThis event listener verify if Capface modal biometric is open. Return true if modal is open, false otherwise.

How to add images in CapfaceSDK module?

The logoImage and cancelImage properties represents your logo and icon of the button cancel. Does not possible to remove them from the module. Default are Capitual images and .png format. By default in Android the logo image is shown, but on iOS it isn't shown, It's necessary to add manually.

How to add images in Android?

To add your images in Android, you must go to your project's android/src/main/res/drawable directory. If in your project drawable folder doesn't exist, it create one. Inside the drawable folder, you must put your images and done!

How to add images in iOS?

In iOS, open your XCode and go to your project's ios/<YOUR_PROJECT_NAME>/Images.xcassets directory. Open the Images.xcassets folder and only put your images inside there.

Example with images added

Now, go back to where you want to apply the styles, import setTheme method and add only the image name, no extension format, in image property (logoImage or cancelImage). Note: If the image is not founded the default image will be showed. Check the code example below:

import React, { useEffect } from 'react';
import { View, TouchableOpacity, Text } from 'react-native';
import {
  initialize,
  enroll,
  setTheme,
} from '@capitual/react-native-capface-sdk';

export default function App() {
  useEffect(() => {
    const params = {
      device: 'YOUR_DEVICE',
      url: 'YOUR_URL',
      key: 'YOUR_PUBLIC_KEY',
      productionKey: 'YOUR_PRODUCTION_KEY',
    };

    async function initialize() {
      await initialize({ params });
      setTheme({
        logoImage: 'yourLogoImage', // yourLogoImage.png
        cancelImage: 'yourCancelImage', // yourCancelImage.png
      });
    }

    initialize();
  }, []);

  return (
    <View
      style={{
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        paddingHorizontal: 20,
      }}
    >
      <TouchableOpacity
        style={{
          width: '100%',
          height: 64,
          justifyContent: 'center',
          alignItems: 'center',
          backgroundColor: 'black',
        }}
        onPress={async () => {
          try {
            const isSuccess = await enroll();
            console.log(isSuccess);
          } catch (error: any) {
            console.error(error);
          }
        }}
      >
        <Text style={{ textAlign: 'center', fontSize: 24, color: 'white' }}>
          Open!
        </Text>
      </TouchableOpacity>
    </View>
  );
}

Limitations, Features or Camera Problems

See the native implementation to learn more about the limitations and features that will need improving in the react-native-capface-sdk.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT License. πŸ™‚


Made with create-react-native-library. 😊

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago