Step 3: Verify User
Finally, we are ready to verify if User is eligible to perform an action from PureFi Issuer perspective taking into account all the details, such as:
- User EOA
- Partner Smart Contract
- Rule ID specifics
- etc
For example, there is a gist how to get _purefidata using PureFi Verifier-SDK npm package in Typescript, but feel free to write your own implementation.
Successfull response means that User is eligible to perform onchain action, PureFi Data is returned as
string. Further this string value has to be used as a parameter_purefidataof transaction, see details
import {
PureFI,
PureFIErrorCodes,
PureFIRuleV5Payload,
} from '@purefi/verifier-sdk';
async function verify(payload: PureFIRuleV5Payload): Promise<string | null> {
try {
const purefiData = await PureFI.verifyRuleV5(payload);
return purefiData;
} catch (error: unknown) {
// User can not prefrom an action
const theError = error as PureFIError;
if (theError.code === PureFIErrorCodes.FORBIDDEN) {
// Highly likely User must go through KYC verification if configured
// so redirect User or suggest going to PureFi Dashboard to https://(stage.)dashboard.purefi.io/kyc
// Once he's finished KYC process successfully, the the same flow won't lead him in this catch block
} else {
// Handle in a different way
}
console.log(theError.message);
return null;
}
}
Another example
To verify a user, send POST request with PureFIRuleV5Payload to PureFi Issuer, to be precise to /v5/rule endpoint.
For details, see PureFi Issuer swagger according to Environment
async function verify(payload: PureFIRuleV5Payload): Promise<string | null> {
try {
const issuerUrl = 'https://stage.issuer.app.purefi.io';
const response = await fetch(`${issuerUrl}/v5/rule`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'text/html',
},
body: JSON.stringify(payload),
});
if (response.ok) {
const data = await response.html();
return data;
}
const errorData = await response.json();
// Handle error response
console.log(errorData);
return null;
} catch (error: unknown) {
console.log('Network error', error);
return null;
}
}