Add CLI command to get applicant details #2
@ -1,6 +1,7 @@
|
||||
import { Arguments } from 'yargs';
|
||||
import dotenv from 'dotenv';
|
||||
import { sumsubAxios } from '../../..';
|
||||
|
||||
import { sumsubAxios } from '../../../utils';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
36
src/index.ts
36
src/index.ts
@ -1,47 +1,15 @@
|
||||
import express from 'express';
|
||||
import axios, { InternalAxiosRequestConfig } from 'axios';
|
||||
import dotenv from 'dotenv';
|
||||
import FormData from 'form-data';
|
||||
import crypto from 'crypto';
|
||||
import assert from 'assert';
|
||||
import cors from 'cors';
|
||||
|
||||
import { sumsubAxios } from './utils';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const SUMSUB_BASE_URL = 'https://api.sumsub.com';
|
||||
const DEFAULT_KYC_LEVEL = process.env.KYC_LEVEL || 'basic-kyc-level';
|
||||
const DEFAULT_TOKEN_TTL_IN_SECS = process.env.TTL_IN_SECS || 600;
|
||||
|
||||
const sumsubAxios = axios.create();
|
||||
|
||||
sumsubAxios.interceptors.request.use(createSignature, function (error) {
|
||||
return Promise.reject(error);
|
||||
})
|
||||
|
||||
export { sumsubAxios };
|
||||
|
||||
// This function creates signature for the request as described here: https://developers.sumsub.com/api-reference/#app-tokens
|
||||
function createSignature(config: InternalAxiosRequestConfig) {
|
||||
assert(config.method);
|
||||
|
||||
console.log('Creating a signature for the request...');
|
||||
|
||||
var ts = Math.floor(Date.now() / 1000);
|
||||
const signature = crypto.createHmac('sha256', process.env.SUMSUB_SECRET_KEY || "");
|
||||
signature.update(ts + config.method.toUpperCase() + config.url);
|
||||
|
||||
if (config.data instanceof FormData) {
|
||||
signature.update(config.data.getBuffer());
|
||||
} else if (config.data) {
|
||||
signature.update(config.data);
|
||||
}
|
||||
|
||||
config.headers['X-App-Access-Ts'] = ts;
|
||||
config.headers['X-App-Access-Sig'] = signature.digest('hex');
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
// https://developers.sumsub.com/api-reference/#access-tokens-for-sdks
|
||||
function createAccessToken (externalUserId: string, levelName: string, ttlInSecs: number) {
|
||||
const config: any = { baseURL: SUMSUB_BASE_URL};
|
||||
|
32
src/utils.ts
Normal file
32
src/utils.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import axios, { InternalAxiosRequestConfig } from 'axios';
|
||||
import FormData from 'form-data';
|
||||
import crypto from 'crypto';
|
||||
import assert from 'assert';
|
||||
|
||||
const sumsubAxios = axios.create();
|
||||
|
||||
sumsubAxios.interceptors.request.use(createSignature, function (error) {
|
||||
return Promise.reject(error);
|
||||
})
|
||||
|
||||
export { sumsubAxios };
|
||||
|
||||
// This function creates signature for the request as described here: https://developers.sumsub.com/api-reference/#app-tokens
|
||||
function createSignature(config: InternalAxiosRequestConfig) {
|
||||
assert(config.method);
|
||||
|
||||
var ts = Math.floor(Date.now() / 1000);
|
||||
const signature = crypto.createHmac('sha256', process.env.SUMSUB_SECRET_KEY || "");
|
||||
signature.update(ts + config.method.toUpperCase() + config.url);
|
||||
|
||||
if (config.data instanceof FormData) {
|
||||
signature.update(config.data.getBuffer());
|
||||
} else if (config.data) {
|
||||
signature.update(config.data);
|
||||
}
|
||||
|
||||
config.headers['X-App-Access-Ts'] = ts;
|
||||
config.headers['X-App-Access-Sig'] = signature.digest('hex');
|
||||
|
||||
return config;
|
||||
}
|
Loading…
Reference in New Issue
Block a user