✨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

Usage

This example will help you get started with a basic backend implementation to start proof requests and verify proofs.

Step-by-Step Implementation

1. Install the SDK

Make sure you have installed the SDKs by following the instructions on the Installation page.

2. Prepare your variables

  • You will need to have the APPLICATION_ID and APPLICATION_SECRET from dev.reclaimprotocol.org.
  • You will also need to add providers to your application, keep the PROVIDER_ID handy too.
  • The providers you add to the application, will be the providers you will be able to ask the user to generate a proof for.
  • Make sure you add to your Application from the dev tool.

3. Create the Proof Request generator endpoint

This endpoint defines what proof you are requesting from the user.

If you are deploying this on localhost, be sure to use ngrok to make your server accessible over the internet.

Create a new file named server.js and add the following code:

const express = require('express')
const { ReclaimProofRequest, verifyProof } = require('@reclaimprotocol/js-sdk')
 
const app = express()
const port = 3000
 
app.use(express.json())
app.use(express.text({ type: '*/*', limit: '50mb' })) // This is to parse the urlencoded proof object that is returned to the callback url
 
const BASE_URL = "https://your-domain.com"; // if using ngrok, provide the ngrok base url
 
// Route to generate SDK configuration
app.get('/generate-config', async (req, res) => {
  const APP_ID = 'YOUR_APPLICATION_ID' 
  const APP_SECRET = 'YOUR_APPLICATION_SECRET'
  const PROVIDER_ID = 'YOUR_PROVIDER_ID' 
 
  try {
    const reclaimProofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID)
    
    // we will be defining this endpoint in the next step
    reclaimProofRequest.setAppCallbackUrl(BASE_URL+'/receive-proofs')
    
    const reclaimProofRequestConfig = reclaimProofRequest.toJsonString()
 
    return res.json({ reclaimProofRequestConfig })
  } catch (error) {
    console.error('Error generating request config:', error)
    return res.status(500).json({ error: 'Failed to generate request config' })
  }
})
 
app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`)
})

Do not use the express.urlencoded() middleware as it will conflict with the express.text() middleware above. The proof object sent to the callback URL needs to be parsed as text, otherwise it won't be processed correctly.

4. Add the Receive Proof endpoint to verify the proofs

This endpoint will be called once the user generates the proof. Here is where we must verify the submitted proof and execute business logic accordingly.

Add this function to your server.js

 
// Route to receive proofs
app.post('/receive-proofs', async (req, res) => {
  // decode the urlencoded proof object; see below if not using express middlewares for decoding
  const decodedBody = decodeURIComponent(req.body);
  const proof = JSON.parse(decodedBody);
 
  // Verify the proof using the SDK verifyProof function
  const result = await verifyProof(proof)
  if (!result) {
    return res.status(400).json({ error: 'Invalid proofs data' });
  }
 
  console.log('Received proofs:', proof)
  // Process the proofs here
  return res.sendStatus(200)
})

If not using a middleware to parse the body, be sure to parse the body manually, like so:

  const body = {};
  for (const [key, value] of formData.entries()) {
    body[key] = value;
  }
  console.log('Processed body:', body);

  const parsedBody = JSON.parse(Object.keys(body)[0]);

For detailed information about the proof object received in the /receive-proofs endpoint, refer to the Proof Structure section.

3. Run the server

Start your Express server:

node server.js

4. Display the Proof Request to the user

You can now display the Proof Request to the user, by following the Fullstack Example here

On this page