• About TrustVision
  • Android SDK
  • iOS SDK
  • Flutter SDK
  • React Native SDK
  • Web SDK
  • API Client Libraries
  • eKYC Platform
  • Integration Case Studies
  • TS eKYC/FA App
TrustVision API Documentation

JavaScript

Trust Vision SDK for JavaScript, available for browsers and React Native environments.

  • Current version: 2.7.0*

Installing

Using script tag

html
<script src="https://unpkg.com/@tsocial/[email protected]/dist/trustvision-sdk.umd.js"></script>
<script>
  // create and instance of API client with provided access key, secret key and environment
  // environment values should be testing, staging, production or the API URL
  const apiClient = new trustvisionSdk.default(
    "access key", // access key
    "secret key", // secret key
    "testing" // environment (testing, staging, production) or API URL
  );

  // start using services
  apiClient
    .clientSettings()
    .then((result) => {
      // result contains information about card types and other settings
    })
    .catch((error) => {});
</script>

Using NPM

javascript
// import API Client class
import TrustVisionAPI from "@tsocial/trustvision-sdk";

// create and instance of API client with provided access key, secret key and environment
// environment values should be testing, staging, production or the API URL
const apiClient = new TrustVisionAPI(
  "access key", // access key
  "secret key", // secret key
  "testing" // environment (testing, staging, production) or API URL
);

// start using services
apiClient
  .clientSettings()
  .then((result) => {
    // result contains information about card types and other settings
  })
  .catch((error) => {});

Services

Client settings

javascript
apiClient
  .clientSettings()
  .then((result) => {
    // please refer to API document for response's format
  })
  .catch((error) => {});

Upload image

API document

javascript
apiClient
  .uploadImage({
    file: imageFile, // file object
    imageLabel: "portrait", // image label
  })
  .then((result) => {
    // please refer to API document for response's format
  })
  .catch((error) => {});

Upload image with authentication headers

Use this method if you want to generate authentication headers using your own service

javascript
const { SimpleTrustVisionAPI } = trustvisionSdk;

const simpleTVAPI = new SimpleTrustVisionAPI(
  "testing" // environment (testing, staging, production) or API URL
);

function generateAuthHeaders() {
  /*
    authentication headers
    {
      Authorization: 'authorization token',
      'X-TV-Timestamp': 'timestamp'
    }
  */
  return {
    Authorization: "authorization token",
    "X-TV-Timestamp": "timestamp",
  };
}

async function upload(file) {
  try {
    // generate headers using your own service
    const authHeaders = generateAuthHeaders();
    const res = await sdk.uploadImage(
      {
        file,
        label: "id_card.vn.cmnd_old.front",
      },
      authHeaders
    );
    console.log(res);
  } catch (err) {
    console.log(err);
  }
}

Compare faces

API document

javascript
apiClient
  .compareFaces({
    image1: {
      id: "", //ID of the image in DB
      base64: "", //Base64 encoded text of image1 data
      label: "", //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    image2: {
      id: "", //ID of the image in DB
      base64: "", //Base64 encoded text of image1 data
      label: "", //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
  })
  .then((result) => {
    // please refer to API document for response's format
  })
  .catch((error) => {});

Verify face liveness

API document

javascript
apiClient
  .verifyFaceLiveness({
    images: [
      {
        id: "", //ID of the image in DB
        base64: "", //Base64 encoded text of image1 data
        label: "", //label of the image as described at Upload Image API
        metadata: {}, //any key-value metadata to save with the image, both key and value should be string
      },
      {
        id: "", //ID of the image in DB
        base64: "", //Base64 encoded text of image1 data
        label: "", //label of the image as described at Upload Image API
        metadata: {}, //any key-value metadata to save with the image, both key and value should be string
      },
    ],
    gestures: ["<image 1 gesture>", "<image 1 gesture>"], //array of expected gestures of the face in each image, optional
  })
  .then((result) => {
    // please refer to API document for response's format
  })
  .catch((error) => {});

Read ID card

API document

javascript
apiClient
  .readIDCard({
    card_type: "card type", // card type of image
    image1: {
      id: "", //ID of the image in DB
      base64: "", //Base64 encoded text of image1 data
      label: "", //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    image2: {
      id: "", //ID of the image in DB
      base64: "", //Base64 encoded text of image1 data
      label: "", //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    }, // optional
    qr1_images: [
      {
        id: "", //ID of the image in DB
        base64: "", //Base64 encoded text of image1 data
        label: "", //label of the image as described at Upload Image API
        metadata: {}, //any key-value metadata to save with the image, both key and value should be string
      },
    ], // array of uploaded back qr code, optional
    qr2_images: [
      {
        id: "", //ID of the image in DB
        base64: "", //Base64 encoded text of image1 data
        label: "", //label of the image as described at Upload Image API
        metadata: {}, //any key-value metadata to save with the image, both key and value should be string
      },
    ], // array of uploaded front qr code, optional
  })
  .then((result) => {
    // please refer to API document for response's format
  })
  .catch((error) => {});

Request verify ID card

API document

javascript
apiClient
  .requestVerifyIDCard({
    card_type: "card type", // card type of image
    image1: {
      id: "", //ID of the image in DB
      base64: "", //Base64 encoded text of image1 data
      label: "", //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    image2: {
      id: "", //ID of the image in DB
      base64: "", //Base64 encoded text of image1 data
      label: "", //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
  })
  .then((result) => {
    // please refer to API document for response's format
  })
  .catch((error) => {});

Request verify portrait

API document

javascript
apiClient
  .requestVerifyPortrait({
    image: {
      id: "", //ID of the image in DB
      base64: "", //Base64 encoded text of image1 data
      label: "", //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
  })
  .then((result) => {
    // please refer to API document for response's format
  })
  .catch((error) => {});

Search faces (Faces retrieval)

API document

javascript
apiClient
  .searchFaces({
    image: {
      id: "", //ID of the image in DB
      base64: "", //Base64 encoded text of image1 data
      label: "", //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    collection: "", // index faces to this collection, optional
  })
  .then((result) => {
    // please refer to API document for response's format
  })
  .catch((error) => {});

Download image

API document

Example: Download an image and display it on a img HTML tag

javascript
const $img = document.getElementById("result"); // select an image tag with id result <img id="result" />
const imageId = "d70b3fd3-253d-4e35-b2f7-fad564a36443";
apiClient
  .downloadImage(imageId)
  .then((dataURL) => $img.setAttribute("src", result));

Index faces

API document

javascript
apiClient
  .indexFaces({
    image: {
      id: "", //ID of the image in DB
      base64: "", //Base64 encoded text of image1 data
      label: "", //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    collection: "", // index faces to this collection, optional
  })
  .then((result) => {
    // please refer to API document for response's format
  })
  .catch((error) => {});

Update metadata

API document

javascript
apiClient
  .updateMetadata(
    '[imageId]',  // string, id of image
    {
      "metadata": {} // any key-value metadata to save with the image, both key and value should be string,
      "label": '', //label of the image
      "override":  true, // boolean flag to allow override old metadata or not,
    }
  )
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });