@enface/sdk

    1.1.7 • Public • Published

    Enface SDK JS library

    This package works both in Node.js and Browser environment. Supported browsers:

    • Chrome
    • Opera
    • FireFox
    • Internet Explorer (Edge)
    • Safari

    Installation

    NPM

    npm i --save @enface/sdk

    Yarn

    yarn add @enface/sdk

    Usage

    // ES2015 module import:
    import { createEnfaceApi } from "@enface/sdk";
     
    // CommonJS module require:
    const { createEnfaceApi } = require("@enface/sdk");
     
    // Initialization:
    const enfaceApi = createEnfaceApi({
      apiKey: 'YOUR_API_KEY'
    });

    Face recognition:

    // Request:
    const result = await enfaceApi.recognize({
      images: [image]
    });

    Liveness detection:

    // Request:
    const result = await enfaceApi.liveness({
      images: [image1, image2, image3]
    });

    Both face recognition & liveness detection in one request:

    // Request:
    const result = await enfaceApi.recognizeLiveness({
      images: [image1, image2, image3]
    });

    Images should be in JPEG format with minimal resolution of 800x600 pixels (1280x720 is recommended for better performance). For liveness and complex requests 3 images are required. They should be taken from a camera with strict time frames - 160-200 milliseconds between each other. Supported images inputs:

    • ArrayBuffer (node.js or browser environment)
    • Uint8Array (node.js or browser environment)
    • Blob (browser environment)
    • File, taken from <input type="file"> (browser environment)

    Tests

    To completely pass the tests fill the values of the corresponding variables below with your own API keys in "__tests__/api.js".

    • const recognitionApiKey = 'YOUR_RECOGNITION_API_KEY';
    • const livenessApiKey = 'YOUR_LIVENESS_API_KEY';
    • const recognizeLivenessApiKey = 'YOUR_RECOGNIZE_LIVENESS_API_KEY';
    // Running the tests
    npm test

    Browser usage

    Get the minified "enface.web.js" script from "dist/" folder and link to your web page. Enface library constructor will become available in the global scope:

    <script src="set_correct_path/enface.web.js"></script>
    <script>
     
      const enfaceApi = createEnfaceApi({
        apiKey: 'YOUR_API_KEY'
      });
     
      enfaceApi.recognize({ images: [image] }).then(function(result){
        console.log(result);
      });
     
    </script> 

    Enface REST API

    Enface supports 2 types of API requests - GraphQL & REST. Full GraphQL documentstion can be found here: http://docs.enface.io. REST API accepts data in multipart/form-data format with following fields:

    • apiKey
    • array of images in binary form

    JavaScript examples:

    Face recognition:

      const formData  = new FormData();
      formData.append('apiKey', 'YOUR_RECOGNITION_API_KEY');
      formData.append('image', image, `image1.jpg`);
      const result = await fetch('https://enface-api-server.herokuapp.com/rest/recognize', {
        method: 'post',
        body: formData,
      });

    Liveness detection:

      const formData  = new FormData();
      formData.append('apiKey', 'YOUR_LIVENESS_API_KEY');
      images.forEach((image, index) => formData.append('image', image, `${index}.jpg`));
      const result = await fetch('https://enface-api-server.herokuapp.com/rest/liveness', {
        method: 'post',
        body: formData,
      });

    Both face recognition & liveness detection in one request:

      const formData  = new FormData();
      formData.append('apiKey', 'YOUR_RECOGNITION_LIVENESS_API_KEY');
      images.forEach((image, index) => formData.append('image', image, `${index}.jpg`));
      const result = await fetch('https://enface-api-server.herokuapp.com/rest/recognizeLiveness', {
        method: 'post',
        body: formData,
      });

    Raw REST API post request with header:

    POST https://enface-api-server.herokuapp.com/rest/recognizeLiveness HTTP/1.1
    Host: enface-api-server.herokuapp.com
    Content-Type: multipart/form-data; boundary=----------------------------794180515515914733140144
     
    ----------------------------794180515515914733140144
    Content-Disposition: form-data; name="apiKey"
    9e9d58b2-d0c9-4465-a4a0-c96db3ebc3b4
     
    ----------------------------794180515515914733140144
    Content-Disposition: form-data; name="image";
    filename="0.jpg"
    Content-Type: image/jpeg
     
    binary image1
    ----------------------------794180515515914733140144
    Content-Disposition: form-data; name="image";
    filename="1.jpg"
    Content-Type: image/jpeg
     
    binary image2
    ----------------------------794180515515914733140144
    Content-Disposition: form-data; name="image";
    filename="2.jpg"
    Content-Type: image/jpeg
     
    binary image3

    Install

    npm i @enface/sdk

    Homepage

    enface.io

    DownloadsWeekly Downloads

    21

    Version

    1.1.7

    License

    MIT

    Unpacked Size

    707 kB

    Total Files

    28

    Last publish

    Collaborators

    • enface