Guides
React.js SDK
You can use our React.js SDK to:
- Encrypt data client-side
- Collect or display card data with UI Components
Quickstart
Install SDK
Our React.js SDK is distributed via npm
, and can be installed using your preferred package manager.
Initialize SDK
Once installed, initialize the React.js SDK with your Team and App ID found in the Evervault Dashboard.
Use the <EvervaultProvider>
component as a provider for your app.
Encrypt a string
Once you've added the <EvervaultProvider>
, you can access the useEvervault()
hook in its children. The useEvervault()
hook returns an initialized instance of the JavaScript SDK, which includes the encrypt()
function. The encrypt()
function can can be used to encrypt plaintext data in your application.
Reference
<EvervaultProvider />
The EvervaultProvider
component exposes the useEvervault()
hook to any nested components.
useEvervault()
The useEvervault
hook is accessible in children of the EvervaultProvider
, and returns an initialized instance of the Evervault JavaScript SDK. One of the functions included in the returned object is encrypt()
, which can be passed any plaintext data structure.
evervault.encrypt(data)
Encrypts data using Evervault Encryption. Evervault Strings can be used across all of our Primitives. It is accessible on the returned value from the useEvervault()
hook. To encrypt data using the React.js SDK, simply pass a String
or an Object
into the evervault.encrypt()
function.
The encrypted data can be passed to your server and stored in your database as normal. It can also be used with any of Evervault’s other services.
<EvervaultInput />
The <EvervaultInput>
component makes it easy to use Evervault's Inputs UI Component in your React application. Inputs make it easy to collect encrypted cardholder data in a completely PCI-compliant environment.
Inputs is served within an iFrame retrieved directly from Evervault’s PCI-compliant infrastructure, which can reduce your PCI DSS compliance scope to the simplest form (SAQ A).
Simply include the component in your JSX to get started.
The component also supports themes and custom styles so you can customise how Inputs looks in your UI.
Retrieving card data
There are two ways of accessing encrypted card data once it has been entered.
In each case, a cardData
object containing details about the card data your user has entered is returned.
You can see the format of this object below:
Card data can be retrieved in one of the following two ways:
onChange()
This option is best when you are looking to handle the card values in realtime, like displaying validation errors as a user is inputting their card data. The callback function is run every time your user updates the card data.
Localization
The iFrame can be localized on initialization by providing a set of labels in the config. The labels can then be updated as required using the setLabels
method.
Custom Fonts
A custom font can be loaded from Google's Fonts API and the font-family
set with the fontFamily
config paramerter
iFrame loading status
If you need to wait for the iFrame that serves inputs to load before doing some action, you can used the onInputsLoad
prop callback:
<EvervaultReveal />
Use evervault.reveal to show your users their encrypted card details in plaintext in a secure iframe hosted by Evervault. Before using Reveal you'll first have to create a Relay to decrypt the card details; Reveal expects to receive the card data from the Relay as a JSON object with the schema below.
It is important that the endpoint that you create sets the applicable CORS headers so that it can be accessed from the Reveal iframe. Otherwise your requests will fail!
Once you have your endpoint that returns the encrypted card data, you'll need to create an Evervault Inbound Relay that will decrypt the encrypted card data as is passes through it, before it gets to the iFrame. Once you have created your Relay you can add the component to your React app.
The only required field is request
which takes an object that supports all of the same fields as a Javascript Request Object. The URL must be the Evervault Inbound Relay you configured earlier.