✨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.

JS
Build your own callback

Building your own callback URL

By default, the sdk returns an AppCallbackUrl as an endpoint provided by Reclaim Protocol. In some situations, you might want the proofs to be uploaded to your backend once the user creates it. Particularly if you want to process the proofs in the backend and take some actions.

Note that you can parse all incoming requests to your callback as plain text, this will make parsing easier for you, if you're using Express.js or NestJS, you can use the following middleware:

  app.use(express.text({ type: "*/*" }));

Expose a POST endpoint

The path should contain a session id as a query param.

app.post('/callback/', async (req, res) => {
  const sessionId = req.query.callbackId
})

Parse the uploaded blob

app.post('/callback/', async (req, res) => {
  const sessionId = req.query.callbackId
  const proof = JSON.parse(decodeURIComponent(req.body))
})

Verify the proofs

The proof must be verified to make sure the requested proof matches the proof created.

  • Install @reclaimprotocol/js-sdk
  • Use Reclaim.verifySignedProof(proof)
import { Reclaim } from '@reclaimprotocol/js-sdk'
 
app.post('/callback/', async (req, res) => {
  const sessionId = req.query.callbackId
  const proof = JSON.parse(decodeURIComponent(req.body))
 
  const isProofVerified = await Reclaim.verifySignedProof(proof)
  if (!isProofVerified) {
    return res.status(400).send({ message: 'Proof verification failed' })
  }
})

Verify the metadata

import { Reclaim } from '@reclaimprotocol/js-sdk'
 
app.post('/callback/', async (req, res) => {
  const sessionId = req.query.callbackId
  const proof = JSON.parse(decodeURIComponent(req.body))
 
  const isProofVerified = await ReclaimClient.verifySignedProof(proof)
  if (!isProofVerified) {
    return res.status(400).send({ message: 'Proof verification failed' })
  }
 
  const context = proof.claimData.context
  const extractedParameterValues = proof.extractedParameterValues
  // TODO: Verify with the context depending on your business logic
  // TODO: Save the proof to your backend
 
  return res.status(200).send({ message: 'Proof verified' })
})

If you're building your own callback, you need to set your callback URL before calling reclaimClient.createVerificationRequest

const reclaimClient = new Reclaim.ProofRequest('YOUR_APPLICATION_ID_HERE')
  //... other code
reclaimClient.setAppCallbackUrl('YOUR_CALLBACK_URL_HERE')
 
const {requestUrl, statusUrl} = await reclaimClient.createVerificationRequest();
res.send('request-proof', {requestUrl, statusUrl})