npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@reclaimprotocol/js-sdk

v1.3.3

Published

Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.

Downloads

932

Readme

Reclaim js-sdk

This README provides a step-by-step guide on integrating the Reclaim Protocol JavaScript SDK into application

Pre-requisites

Create a new React application

npx create-react-app reclaim-app
cd reclaim-app

Install the Reclaim Protocol JS-SDK

npm install @reclaimprotocol/js-sdk

Install other dependencies

npm i react-qr-code

Import dependencies

In your src/App.js file, import the Reclaim SDK and the QR code generator

import { useState, useEffect } from 'react'
import { Reclaim } from '@reclaimprotocol/js-sdk'
import QRCode from 'react-qr-code'

Initialize the Reclaim SDK

Declare your application ID and initialize the Reclaim Protocol client. Replace YOUR_APPLICATION_ID_HERE with the actual application ID provided by Reclaim Protocol.

File: src/App.js

import './App.css'
import { useState, useEffect } from 'react'
import { Reclaim } from '@reclaimprotocol/js-sdk'
import QRCode from 'react-qr-code'

function App() {
  const APP_ID = 'YOUR_APPLICATION_ID_HERE'
  const reclaimProofRequest = new Reclaim.ProofRequest(APP_ID)

  return (
    <div className='App'>
      <header className='App-header'>
        <p>Reclaim App</p>
      </header>
    </div>
  )
}

export default App

Implement Verification Request Function

Create functions to handle the verification request. You'll need separate functions for prototype and production modes due to the different handling of the application secret and signature.

Prototype Mode

For testing purposes, use the prototype mode. Note that in production, you should handle the application secret securely on your server.

File: src/App.js

import './App.css'
import { useState, useEffect } from 'react'
import { Reclaim } from '@reclaimprotocol/js-sdk'
import QRCode from 'react-qr-code'

function App() {
  const [requestUrl, setRequestUrl] = useState('')
  const [proofs, setProofs] = useState([])

  const APP_ID = 'YOUR_APPLICATION_ID_HERE'

  const reclaimProofRequest = new Reclaim.ProofRequest(APP_ID)

  async function createVerificationRequest() {
    // id of the provider you want to generate the proof for
    await reclaimProofRequest.buildProofRequest('PROVIDER_ID')

    reclaimProofRequest.setSignature(
      await reclaimProofRequest.generateSignature(
        'YOUR_APPLICATION_SECRET' // Handle securely for production
      )
    )

    const { requestUrl, statusUrl } =
      await reclaimProofRequest.createVerificationRequest()

    await reclaimProofRequest.startSession({
      onSuccessCallback: proofs => {
        console.log('Verification success', proofs)
        setProofs(proofs)
        // Your business logic here
      },
      onFailureCallback: error => {
        console.error('Verification failed', error)
        // Your business logic here to handle the error
      }
    })

    setRequestUrl(requestUrl)
  }

  return (
    <div className='App'>
      <header className='App-header'>
        <p>Reclaim App</p>
        <button
          onClick={createVerificationRequest}
          style={{ marginBottom: '20px', padding: '10px', cursor: 'pointer' }}
        >
          Create Verification Request
        </button>
        <div style={{ backgroundColor: 'white', padding: '10px' }}>
          {requestUrl && (
            <div style={{ backgroundColor: 'white', padding: '10px' }}>
              <QRCode value={requestUrl} />
            </div>
          )}
          {proofs.length > 0 && (
            <div>
              <h3>Proofs</h3>
              <ul>
                {proofs.map((proof, index) => {
                  return (
                    <p key={index}>
                      {JSON.stringify(proof.extractedParameterValues)}
                    </p>
                  )
                })}
              </ul>
            </div>
          )}
        </div>
      </header>
    </div>
  )
}

export default App

Production Mode

In production mode, securely fetch and set the signature from your backend instead of using the application secret directly in the client.

Similar to the prototype mode but ensure to fetch and set the signature securely

async function createVerificationRequestProductionMode() {
  // id of the provider you want to generate the proof for
  await reclaimProofRequest.buildProofRequest('PROVIDER_ID')

  reclaim
    .setSignature
    // TODO: fetch signature from your backend
    // On the backend, generate signature using:
    // await Reclaim.getSignature(requestedProofs, APP_SECRET)
    ()

  const { requestUrl, statusUrl } =
    await reclaimProofRequest.createVerificationRequest()

  await reclaimProofRequest.startSession({
    onSuccessCallback: proofs => {
      console.log('Verification success', proofs)
      setProofs(proofs)
      // Your business logic here
    },
    onFailureCallback: error => {
      console.error('Verification failed', error)
      // Your business logic here to handle the error
    }
  })

  setRequestUrl(requestUrl)
}

Run the application

npm start

Advanced Configuration

You can configure Reclaim SDK to receive proofs in your preferref backend by setting up a callback URL. This is useful if you want to handle the proofs in your backend.

  • Set Callback Url - reclaim.setCallbackUrl('https://your-backend.com/receive-proofs')
  • Set Status URL - reclaim.setStatusUrl('https://your-backend.com/receive-status')