README
@purefi/verifier-sdk
Node.js module with the Verifier SDK for PureFI decentralized AML protocol. Providing wrappers for communicating with PureFI issuers
Documentation
For more detailed documentation see https://verifier-sdk.purefi.io/
Installation
Using npm:
npm install @purefi/verifier-sdk
Using yarn:
yarn add @purefi/verifier-sdk
Using unpkg CDN:
<script src="https://unpkg.com/@purefi/verifier-sdk/lib/index.umd.min.js"></script>
<!-- The library will be availble as window.PureFIModule or just PureFIModule -->
Quick Start
The first use case
In case you have a specific process around signing messages or you want to sign messages by yourself
CommonJS:
const { ethers } = require('ethers');
const { PureFI, AddressType } = require('@purefi/verifier-sdk');
const privateKey = '<private_key>';
const infuraApiKey = '<infura_api_key>';
const provider = new ethers.providers.InfuraProvider('homestead', infuraApiKey);
const wallet = new ethers.Wallet(privateKey, provider);
const addresses = [
{
address: '0xaAaAAAAaaAAaaaAAAaaaaaAAAAAaaAaAaAAAAaaa',
type: AddressType.WALLET,
},
{
address: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
type: AddressType.CONTRACT,
},
{
address: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
},
];
const message = JSON.stringify(addresses);
wallet
.signMessage(message)
.then((signature) => {
const purefiPayload = {
message,
signature,
};
return Promise.all([
PureFI.checkRisk(purefiPayload),
PureFI.downloadReport(purefiPayload),
]);
})
.then(([checkRiskResponse, downloadReportResponse]) => {
// process checkRiskResponse
checkRiskResponse.forEach((item) => {
const { address, riskScore, connections } = item;
console.log(address, riskScore, connections);
});
// process downloadReportResponse
const { buffer } = downloadReportResponse;
console.log(buffer);
})
.catch((error) => {
console.log(error);
});
The second use case
In case you want to delegate signing messages to PureFI
NOTE
Ethers signers are compatible with PureFI out of the box. If you tend to use Web3 or other solutions just implement ISigner interface and follow along
See details: ISigner
Typescript:
import { ethers } from 'ethers';
import {
PureFI,
AddressType,
PureFIErrorCodes,
PureFIError,
CheckRiskResponse,
DownloadReportResponse,
} from '@purefi/verifier-sdk';
// assuming you have givenProvider
const givenProvider = ...;
const provider = new ethers.providers.Web3Provider(givenProvider);
const signer = provider.getSigner();
// empower PureFI to sign messages for you
PureFI.setSigner(signer);
async function checkRiskExample() {
const addresstoCheck = '0xaAaAAAAaaAAaaaAAAaaaaaAAAAAaaAaAaAAAAaaa';
try {
const response: CheckRiskResponse = await PureFI.checkRisk(addresstoCheck);
const { address, riskScore, connections } = response;
console.log(address, riskScore, connections);
} catch (error) {
const purefiError = error as PureFIError;
switch (purefiError.code) {
case PureFIErrorCodes.VALIDATION: {
console.log(purefiError.message);
break;
}
// handle other cases
default: {
break;
}
}
}
}
async function downloadReportExample() {
const addresstoCheck = {
address: '0xaAaAAAAaaAAaaaAAAaaaaaAAAAAaaAaAaAAAAaaa',
type: AddressType.WALLET,
};
try {
const response: DownloadReportResponse = await PureFI.downloadReport(
addresstoCheck
);
const { buffer } = response;
console.log(buffer);
// let user to download PureFI VC certificate
const url = window.URL.createObjectURL(new Blob([buffer]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'PureFI VC Certificate.pdf');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error) {
const purefiError = error as PureFIError;
switch (purefiError.code) {
case PureFIErrorCodes.VALIDATION: {
console.log(purefiError.message);
break;
}
// handle other cases
default: {
break;
}
}
}
}
checkRiskExample();
downloadReportExample();