Vouch logovouch
React Native

Usage

Under Development: This SDK is currently in development. Documentation and API may change. For production use, please contact our team.

Overview

The vouch React Native SDK provides a simple Promise-based API for initiating and managing verification flows within your React Native application. The SDK handles the entire verification process, presenting a native modal UI for user interaction.

Initialization

The SDK must be initialized before use. This should be done early in your application lifecycle, typically in your root component or app entry point.

import VouchSDK from '@getvouch/react-native-sdk';

// Initialize the SDK with your customer ID
VouchSDK.initialize({
  customerId: 'CUSTOMER_ID'
});

Important: Initialize the SDK only once during your application's lifecycle. Calling initialize() multiple times will log a warning.

Checking Initialization Status

You can check if the SDK has been initialized:

const isReady = VouchSDK.isInitialized();

if (!isReady) {
  VouchSDK.initialize({ customerId: 'CUSTOMER_ID' });
}

Requesting a Verification

To initiate a verification flow, call the start method. This method returns a Promise that resolves with a success result or rejects with an error.

Basic Usage

import VouchSDK from '@getvouch/react-native-sdk';

async function requestVerification() {
  try {
    const result = await VouchSDK.start({
      dataSourceId: 'DATA_SOURCE_ID',
      webhookUrl: 'https://your-server.com/webhook',
      inputs: {
        INPUT1_NAME: 'INPUT1_VALUE',
        INPUT2_NAME: 'INPUT2_VALUE'
      }
    });

    console.log('Verification successful! Proof ID:', result.proofId);
  } catch (error) {
    console.error('Verification failed:', error.description);
    console.error('Proof ID:', error.proofId);
    console.error('Error code:', error.reason);
  }
}

Parameters

initialize

ParameterTypeRequiredDescription
customerIdstringYesYour unique customer identifier from Vouch

start

ParameterTypeRequiredDescription
dataSourceIdstringYesThe identifier for the data source to use for verification
webhookUrlstringYesThe URL where verification results will be sent
inputsObjectNoAdditional input parameters required by the data source

For detailed documentation on dataSourceId, webhookUrl, and inputs, see the Vouch URL Parameters section.

Response Types

Success Response

interface VouchSuccess {
  proofId: string;  // Unique identifier for the generated proof
}

Error Response

interface VouchError {
  proofId: string;      // Proof ID (may be empty if error occurs before proof creation)
  reason: number;       // Numeric error code
  description: string;  // Human-readable error message
}

Error Handling

The SDK provides comprehensive error handling through Promise rejection. All errors include a reason code, description, and proofId (when available).

Error Codes

CodeDescription
-1SDK not initialized or internal error
0Data source or customer not found
1Outdated SDK version
2Failed to create proof request
3Background timeout
4Request too large
5Data source misconfigured
6Proving failed
7Proof upload failed
8Attachment reupload failed
9Proof ID already taken
10Network connection lost

Best Practice: Always handle both success and error cases. Log the proofId for debugging and user support purposes, even in error cases.

Version checking (iOS 14-16.3)

VouchSDK functionalities are disabled on iOS 14-16.3. To check if your current iOS version is supported:

if (VouchSDK.isSupported()) {
    // Initialize and start
} else {
    // Show an error
}