UNPKG

@ambisafe/tabla-client

Version:

Ambisafe Tabla client library

77 lines (73 loc) 1.77 kB
// src/client.ts import axios from "axios"; import { utils } from "ethers"; import * as jwt from "jsonwebtoken"; // src/mappers/kyc-data.mapper.ts var KycDataMapper = class { map(dto) { if ("firstName" in dto) { return this.mapPersonal(dto); } return this.mapCorporate(dto); } mapPersonal(dto) { return dto; } mapCorporate(dto) { const { companyName, dateOfIncorporation, ...rest } = dto; return { ...rest, firstName: companyName, birthDate: dateOfIncorporation }; } }; var kyc_data_mapper_default = new KycDataMapper(); // src/client.ts var TablaClient = class { constructor(url, platformPublicId, jwtSecret) { this.url = url; this.platformPublicId = platformPublicId; this.jwtSecret = jwtSecret; } /** * @param kycData User KYC data that will passed on Tabla */ async userWhitelist(kycData) { const mappedKycData = kyc_data_mapper_default.map(kycData); const hashedData = utils.keccak256(Buffer.from(JSON.stringify(mappedKycData))); const accessToken = jwt.sign( { platformPublicId: this.platformPublicId, hashedData, exp: Math.round(Date.now() / 1e3) + 60 }, this.jwtSecret ); const response = await axios.post( `${this.url}/api/v2/accounts/kyc/set-kyc-properties/calldata`, mappedKycData, { headers: { "platform-authorization": `Bearer ${accessToken}` } } ); return response.data; } }; // src/types.ts var PersonalKYCTypes = [ "PERSONAL:EMPTY", "PERSONAL:BASIC_KYC", "PERSONAL:ACCREDITED_INVESTOR" ]; var CorporateKYCTypes = [ "CORPORATE:EMPTY", "CORPORATE:BASIC_KYC" ]; export { CorporateKYCTypes, PersonalKYCTypes, TablaClient };