✨Works out of the box guarantee. If you face any issue at all, hit us up on Telegram and we will write the integration for you.
logoReclaim Protocol Docs
NodeJS SDK

Usage

NodeJS SDK for Reclaim Protocol

Quickstart

We will be creating two endpoints

  1. Start Verification
  2. Process Verification

Import the library

import { ReclaimProofRequest } from '@reclaimprotocol/js-sdk';

Part 1 : Start Verification Endpoint

Init

const reclaimProofRequest = await ReclaimProofRequest.init(
    process.env.RECLAIMPROTOCOL_APP_ID,
    process.env.RECLAIMPROTOCOL_APP_SECRET,
    'ff4d7afe-4b78-4795-9429-d20df2deaad7' // Example. Replace with provider ID
)
  • You can get the RECLAIMPROTOCOL_APP_ID and RECLAIMPROTOCOL_APP_SECRET using this guide
  • The PROVIDER_ID is the proof you want the user to generate. You can see all the available providers here. If you are just testing the flow, you can use the provider id ff4d7afe-4b78-4795-9429-d20df2deaad7.

Success Callback

reclaimProofRequest.setAppCallbackUrl(url, true);
// true : sets contentType to JSON

This is the endpoint to which the proofs will be submitted after the verification - this is where you will process the verification. We will define this endpoint in the next section.

Set Context

You can set context to the proof request that helps identify the request when you receive it back in the callback once the proof is generated.

const address = "unique-user-id"; 
const message = "some meta data for processing on callback";
reclaimProofRequest.setContext(address, message)
  • address : this is usually a unique identifier for the user. This could be an email address, a wallet address, or just a session id generated on your system. Set the variable you'd need to identify the user in the callback endpoint, when the proof is sent to your backend.
  • message : this is an open field where you can add any other information that you want passed around from the build request to the callback endpoint. You can stringify jsons here for convenience.

Both context address and context message are tamper resistant. Even if the user tries to edit one byte, the proof verification will fail.

Open verification

  const proofRequestUrl = await reclaimProofRequest.getRequestUrl();
 
  // Redirect user to this URL or, open URL in an iFrame

Store the Provider Version

  const { providerId, providerVersion } = reclaimProofRequest.getProviderVersion();
  • Store (providerId, providerVersion) corresponding to this user's uuid that you stored in address. You will need this providerVersion

More options

Part 2 : Process Verification endpoint

Be sure to expose this endpoint over the public internet. If testing locally, use Ngrok

Verify Proofs

import { verifyProof } from '@reclaimprotocol/js-sdk';
const proofs = await request.json();
const { isVerified, data } = await verifyProof(proofs, { providerId: PROVIDER_ID });

You can get the provider version

Continue Business Logic

const { context, extractedParameters } = data[0];
// Note if there are multiple proofs, you will have to iterate over data[]
  • context.address & context.message: Same as address and message set in Set Context. Use this to map user to verification.
  • extractedParameters : JSON object of all the data that has been extracted and verified. You can see the structure of each provider's response in the Provider Explorer.

More options

Source code