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
| Parameter | Type | Required | Description |
|---|---|---|---|
customerId | string | Yes | Your unique customer identifier from Vouch |
start
| Parameter | Type | Required | Description |
|---|---|---|---|
dataSourceId | string | Yes | The identifier for the data source to use for verification |
webhookUrl | string | Yes | The URL where verification results will be sent |
inputs | Object | No | Additional 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
| Code | Description |
|---|---|
| -1 | SDK not initialized or internal error |
| 0 | Data source or customer not found |
| 1 | Outdated SDK version |
| 2 | Failed to create proof request |
| 3 | Background timeout |
| 4 | Request too large |
| 5 | Data source misconfigured |
| 6 | Proving failed |
| 7 | Proof upload failed |
| 8 | Attachment reupload failed |
| 9 | Proof ID already taken |
| 10 | Network 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
}