1.1.0 • Published 26 days ago

@reclaimprotocol/reactnative-sdk v1.1.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
26 days ago

Reclaim reactnative-sdk

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

Pre-requisites

Create a new React application

npx react-native init ReclaimApp
cd ReclaimApp

Install the Reclaim Protocol JS-SDK

npm install @reclaimprotocol/reactnative-sdk

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/reactnative-sdk'

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 { Reclaim } from '@reclaimprotocol/reactnative-sdk'
import { SafeAreaView, Text, View } from 'react-native'

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

  return (
    <SafeAreaView>
      <View>
        <Text>App</Text>
      </View>
    </SafeAreaView>
  )
}

export default App

Add your app deep link

You'll need to add a deep link to your app. This will be used to redirect the user back to your app after they have completed the verification process.

  • Guide to setup deep link on react-native can be found here.
import { SafeAreaView, Text, View } from 'react-native'
import { ReclaimClient } from '@reclaimprotocol/reactnative-sdk'

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

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

    const appDeepLink = 'YOUR_APP_DEEP_LINK_HERE' //TODO: replace with your app deep link
    reclaimProofRequest.setAppCallbackUrl(appDeepLink)
  }

  return (
    <SafeAreaView>
      <View>
        <Text>App</Text>
      </View>
    </SafeAreaView>
  )
}

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 { Reclaim } from '@reclaimprotocol/reactnative-sdk'
import { SafeAreaView, Text, View, Pressable } from 'react-native'

function App() {
  const APP_ID = 'YOUR_APPLICATION_ID_HERE'

  const reclaimProofRequest = new Reclaim.ProofRequest(APP_ID)

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

    const appDeepLink = 'YOUR_APP_DEEP_LINK_HERE' //TODO: replace with your app deep link
    reclaimProofRequest.setAppCallbackUrl(appDeepLink)

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

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

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

  return (
    <SafeAreaView>
      <View>
        <Pressable onPress={startVerificationFlow}>
          <Text>Start Verification Flow</Text>
        </Pressable>
      </View>
    </SafeAreaView>
  )
}

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')

  const appDeepLink = 'YOUR_APP_DEEP_LINK_HERE' //TODO: replace with your app deep link
  reclaimProofRequest.setAppCallbackUrl(appDeepLink)

  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: proof => {
      console.log('Verification success', proof)
      // Your business logic here
    },
    onFailureCallback: error => {
      console.error('Verification failed', error)
      // Your business logic here to handle the error
    },
  })
}
1.1.0

26 days ago

1.0.6

26 days ago

1.0.5

1 month ago

1.0.4

1 month ago

1.0.3

1 month ago

1.0.2

1 month ago

1.0.1

2 months ago

1.0.0

2 months ago

0.1.4

2 months ago

0.1.3

2 months ago

0.1.2

2 months ago

0.0.3

2 months ago

0.1.1

2 months ago

0.0.2

3 months ago