To implement Self in your app, you need to implement it in both your front-end and back-end. The front-end will generate a QR code containing all the information relative to your app and what you are requesting users to disclose. The back-end will verify proofs and manage nullifiers.
🚧 Deeplinking is WIP. If you want to implement Self in a mobile application, please contact us.
Implement SelfBackendVerifier in your back-end
Requirements
Node v 16
Install dependencies
npm install @selfxyz/core
For yarn, use the following command:
yarn add @selfxyz/core
Set up Environment Variables
Create an .env file or add to your existing file the following environment variables:
In your api folder or verify.ts file you can start setting up the SelfBackendVerifier in the verify.ts file.
import { SelfBackendVerifier } from '@selfxyz/core';
const selfBackendVerifier = new SelfBackendVerifier(
process.env.CELO_RPC_URL as string,
process.env.SCOPE as string,
);
SelfBackendVerifier requires two arguments: mode and scope.
rpcUrl an RPC URL, use for example Celo's free RPC endpoint https://forno.celo.org
scope is simply an identifier for your app, choose a simple one in standard ASCII.
Methods - Disclosing passport data
Now you can call methods from the SelfBackendVerifier to ask users to disclose specific passport data.
// Set the methods for the verifier.
selfBackendVerifier.setMinimumAge(21);
Find all methods available here:
Method Name
Description
setMinimumAge(age: number)
Set the minimum age for verification.
setNationality(nationality: string)
Set the nationality for verification.
excludeCountries(...countries: string[])
Set excludes specified countries from verification. At most 40. You can use countryCodes from '@selfxyz/core'
enablePassportNoOfacCheck()
Enables OFAC check for passport numbers. Default false.
enableNameAndDobOfacCheck()
Enables OFAC check for name and date of birth. Default false.
enableNameAndYobOfacCheck()
Enables OFAC check for name and year of birth. Default false.
Working with Country Codes
The SDK provides a countryCodes object for referencing ISO country codes:
import { countryCodes } from '@selfxyz/core';
// Examples of usage
const iranCode = countryCodes.IRN; // "Iran"
const northKoreaCode = countryCodes.PRK; // "North Korea"
// Use in excludeCountries
selfBackendVerifier.excludeCountries(
countryCodes.IRN,
countryCodes.PRK,
countryCodes.SYR
);
Verification
Now you can do the verification. For that you can all the verify function.
This is the structure of the result SelfVerificationResul:
export interface SelfVerificationResult {
// Check if the whole verification has succeeded
isValid: boolean;
isValidDetails: {
// Verifies that the proof is generated under the expected scope.
isValidScope: boolean;
// Checks that the attestation identifier in the proof matches the expected value.
isValidAttestationId: boolean;
// Verifies the cryptographic validity of the proof.
isValidProof: boolean;
// Ensures that the revealed nationality is correct (when nationality verification is enabled).
isValidNationality: boolean;
};
// User Identifier which is included in the proof
userId: string;
// Application name which is shown as scope
application: string;
// A cryptographic value used to prevent double registration or reuse of the same proof.
nullifier: string;
// Revealed data by users
credentialSubject: {
// Merkle root which is used to generate proof.
merkle_root?: string;
// Proved identity type, for passport this value is fixed as 1.
attestation_id?: string;
// Date when the proof is generated
current_date?: string;
// Revealed issuing state in the passport
issuing_state?: string;
// Revealed name in the passport
name?: string;
// Revealed passport number in the passport
passport_number?: string;
// Revealed nationality in the passport
nationality?: string;
// Revealed date of birth in the passport
date_of_birth?: string;
// Revealed gender in the passport
gender?: string;
// Revealed expiry date in the passport
expiry_date?: string;
// Result of older than
older_than?: string;
// Result of passport number ofac check
// Gives true if the user passed the check (is not on the list),
// false if the check was not requested or if the user is in the list
passport_no_ofac?: boolean;
// Result of name and date of birth ofac check
name_and_dob_ofac?: boolean;
// Result of name and year of birth ofac check
name_and_yob_ofac?: boolean;
};
proof: {
// Proof which is used for this verification
value: {
proof: Groth16Proof;
publicSignals: PublicSignals;
};
};