Skip to main content

API

Node.js module with the Verifier Widget for PureFI decentralized AML protocol. Providing widgets for communicating with PureFI issuers

note

The package is built on top of @purefi/verifier-sdk

PureFIWidget works around concept of signing messages and to do it properly it needs a signer.

So every time chain or user account changes, pass the new signer instance to PureFIWidget.setSigner()

// Example is based on ethers and metamask
import { ethers } from 'ethers';

const updateSigner = () => {
const provider = new ethers.providers.Web3Provider(ethereum);
const signer = provider.getSigner();
PureFIWidget.setSigner(signer);
};

ethereum.on('accountsChanged', (accounts) => {
// handling account changes
updateSigner();
});

ethereum.on('chainChanged', (chainId) => {
// handling chain changes
updateSigner();
});

To render a widget into a DOM node, pass the element and relevant config to PureFIWidget.render()

import { PureFIWidget } from '@purefi/verifier-widget';

const element = document.querySelector('#widget');
const config = {
address: {
address: '0xaAaAAAAaaAAaaaAAAaaaaaAAAAAaaAaAaAAAAaaa',
type: 'wallet',
},
};

PureFIWidget.render(element, config);

In case you need more control over screening results, pass onSuccess and onError callbacks to PureFIWidget.render()

import { PureFIWidget } from '@purefi/verifier-widget';

const element = document.querySelector('#widget');
const config = {
address: {
address: '0xaAaAAAAaaAAaaaAAAaaaaaAAAAAaaAaAaAAAAaaa',
type: 'wallet',
},
};
const onSuccess = (response, thresholds) =>
console.log('onSuccess', response, thresholds);
const onError = (error) => console.log('onError', error);

PureFIWidget.render(element, config, onSuccess, onError);

Whenever widget container unmounts, you are supposed to notify PureFIWidget about it by passing the element to PureFIWidget.unmount()

// React example
const widgetContainerRef = useRef();

useEffect(() => {
const widgetContainerElement = widgetContainerRef.current;
PureFIWidget.render(widgetContainerElement, {
shouldCheckSignerAddress: true,
});
return () => {
PureFIWidget.unmount(widgetContainerElement);
};
}, []);

return <div ref={widgetContainerRef}></div>;