Example
This example demonstrates how to create a simple Express.js backend that works with the Reclaim Protocol. The backend will handle generating the configuration for the SDK and receiving proofs.
Backend Example
This example demonstrates how to create a simple backend that works with the Reclaim Protocol. The backend will handle generating the configuration for the SDK and receiving proofs.
Step-by-Step Implementation
1. Set up the project
First, create a new directory for your backend project and initialize it:
2. Create the server file
Create a new file named server.js
and add the following code:
Do not use the express.urlencoded()
middleware as it will conflict with the express.text()
middleware above. The proof object sent to the callback URL needs to be parsed as text, otherwise it won't be processed correctly.
For detailed information about the proof
object received in the /receive-proofs
endpoint, refer to the Advance Configuration Proof Structure section.
3. Run the server
Start your Express server:
Understanding the reclaimProofRequestConfig
The reclaimProofRequestConfig
is a JSON string that contains all the necessary information for initializing the Reclaim SDK on the client-side. Here's an example of what the response from the /reclaim/generate-config
endpoint might look like:
Let's break down the structure of the reclaimProofRequestConfig
:
applicationId
: Your unique application identifier.providerId
: The ID of the provider you're using.sessionId
: A unique identifier for this particular proof request session.context
:contextAddress
: The address associated with the context (often set to "0x0").contextMessage
: A custom message providing context for the proof request.
requestedProof
:url
: The URL from which the proof will be generated.parameters
: Key-value pairs of parameters required for the proof.
appCallbackUrl
: The URL where the proofs will be sent after generation.signature
: A cryptographic signature ensuring the integrity of the request.timeStamp
: The timestamp when the configuration was generated.
When you receive this response from your backend, you'll need to use the reclaimProofRequestConfig
string to initialize the Reclaim SDK in your client application.
Using the Configuration in Client Applications
You can use this configuration to initialize the Reclaim SDK in various client platforms:
By using this approach, you keep sensitive information like your APP_SECRET
on the server-side while still allowing your client applications to utilize all the SDK features securely.