✨Works out of the box guarantee. If you face any issue at all, hit us up on Telegram and we will write the integration for you.

Methods for Off-chain sdks

Reclaim Class Documentation

The Reclaim class provides methods to verify and manage proofs creation and blockchain transformation for claims. It cannot be instantiated directly.

Methods

verifySignedProof(proof) ⇒ Promise<boolean>

Verifies the authenticity and completeness of a given proof. It checks if the proof contains signatures, recalculates the proof identifier, and verifies it against the provided signatures. If the verification fails, it will log the error and return false.

Parameters:

  • proof: Proof - The proof to verify, containing signatures, claim data, and identifiers etc.. you can read a breif description of the proof object here
interface Proof {
  identifier: string; /// The proof identifier, used to verify the proof.
  claimData: ProviderClaimData; /// Contains data of the proof, including provider data and the context field 
  signatures: string[]; /// Contains signatures of witness that verified & signed the proof.
  witnesses: WitnessData[]; /// Contains witness data, including the witness id and url.
}

For more details, you can take a look at the Proof type section.

Returns:

  • Promise<boolean> - Resolves to true if the proof is verified correctly, otherwise false.

verifySignedProof is called automatically right after the proof is recieved to the sdk.

transformForOnchain(proof) ⇒ onChainProof

Transforms proof data into a format suitable for on-chain transactions, you need to use it before sending the proof to the blockchain.

Parameters:

  • proof: Proof - The proof object to be transformed.

Returns:

  • onChainProof - Contains claimInfo and signedClaim data, prepared for blockchain transactions.

Please note that Reclaim verifier contracts only accept proofs that were processed by the transformForOnchain method.

verifyProvider(proof, providerHash) ⇒ boolean

Validates the provider used to generate the proof against the provided one. Logs will provide detials in case of verification failure. This method is optional for off-chain sdks.

Parameters:

Returns:

  • boolean - True if proof's provider is same to the one expected, otherwise false.

Please note that you will be able to get the providerHash for the provider you used from https://dev.reclaimprotocol.org (opens in a new tab).

Nested Class: ProofRequest

Handles the configuration and management of proof requests.

Constructor: ProofRequest

Initializes a new instance of ProofRequest, optionally configuring logging and session management.

Parameters:

  • applicationId: string - Your application Id, can be found on https://dev.reclaimprotocol.org (opens in a new tab).
  • options?: ProofRequestOptions - Optional parameters to customize the proof request instance. These can include:
    • log: boolean - If set to true, enables logging. Defaults to false if not specified.
    • sessionId: string - A predefined session ID. If not provided, a new session ID is generated automatically.

Example Usage:

const options = { log: true, sessionId: "your-session-id" };
const proofRequest = new Reclaim.ProofRequest("your-application-id", options);
 

addContext(address:string, message:string) ⇒ void

Adds a context to the proof request, such as a blockchain address and a related message. You can read more about this field here Context.

Parameters:

  • address: string - The blockchain address associated with the context.
  • message: string - The message or data related to the context.

setAppCallbackUrl(url: string) ⇒ void

Sets the application callback URL for the proof request. Usually a proof is sent to our Reclaim backend upon it is generated, then the sdk will fetch and process it. Here we give you the option to set a custom callback URL for your application, which means you will be receving the proofs to your endpoint. We have a section on how to set up a callback endpoint for more information.

Parameters:

  • url: string - The URL to set as the application callback.

Note that in case you're using react-native or flutter sdks, you will need to set the callback URL to your deep link, note that the flow won't be functional without this for mobile-sdks.

setStatusUrl(url: string) ⇒ void

Sets the status URL for the proof request to monitor the progress or status updates.

Parameters:

  • url: string - The URL to set as the status URL.

generateSignature(applicationSecret: string) ⇒ Promise<Signature>

Generates a signature using the provided application secret. The method uses ethers library to sign a hashed message derived from the requested proofs. Signing the request is necessary so that users don't get tricked on phishing websites, and mistakenly upload all their data to a malicious website.

Parameters:

Returns:

  • Promise<string> - The generated signature.

Exceptions:

  • Throws BuildProofRequestError if there is an issue during signature generation.

We don't recommend generating the signature on the frontend, you should do this in your backend as it is more secure.

setSignature(signature: string) ⇒ void

Assigns a signature to the proof request, you can easily use the above mentioned method to generate a signature. For production mode, we recommend you to generate the signature on the backend. For prototype mode, you can set it on the frontned similar to here.

Parameters:

  • signature: string - The signature to assign to the proof request.

getAppCallbackUrl() ⇒ string

Retrieves the application callback URL. If not set, it defaults to the Reclaim callback URL appended with the session ID.

Returns:

  • string - The current application callback URL.

getStatusUrl() ⇒ string

Fetches the status URL. If not set, it defaults to a predefined status URL appended with the session ID.

Returns:

  • string - The current status URL.

buildProofRequest(providerId: string) ⇒ Promise<RequestedProofs>

Builds the proof request using the provided provider ID and initializes necessary proof details.

Parameters:

Returns:

  • Promise<RequestedProofs> - The proofs requested for the application.

Exceptions:

  • Throws BuildProofRequestError if there is an error in generating the proof request.

getRequestedProofs() ⇒ RequestedProofs

Retrieves the requested proofs. Throws an error if buildProofRequest was not called prior to this method.

Returns:

  • RequestedProofs - The requested proofs associated with the proof request.

Exceptions:

  • Throws BuildProofRequestError if the proofs are accessed before they are set.

createVerificationRequest() ⇒ Promise<{requestUrl: string, statusUrl: string}>

Creates a verification request for the session, returning URLs for the verification process and status updates. requestUrl will be used by the user to start generating the proof, while statusUrl will be used to monitor the status of the session.

Returns:

  • Promise<{requestUrl: string, statusUrl: string}> - URLs for the verification request and session status updates.

Exceptions:

  • Throws various errors if the request cannot be created, including BuildProofRequestError and SignatureNotFoundError.

startSession({ onSuccessCallback, onFailureCallback }) ⇒ void

Initiates a session for proof verification, it periodically checks for proof submission, once the proof is submitted, it will be fetched an verified using verifySignedProof. Then it will be handling success or failure callbacks based on proof checks.

Parameters:

  • onSuccessCallback: (proofs: Proof[]) => void - Callback function executed when proofs are verified successfully.
  • onFailureCallback: (error: Error) => void - Callback function executed upon verification failure or session errors.

Exceptions:

  • Throws SessionNotStartedError if session parameters are incorrectly defined or missing.

Proof type

You can take a look at Proof type and its fields here:

interface Proof {
  identifier: string; /// The proof identifier, used to verify the proof.
  claimData: ProviderClaimData; /// Contains data of the proof, including provider data and the context field 
  signatures: string[]; /// Contains signatures of witness that verified & signed the proof.
  witnesses: WitnessData[]; /// Contains witness data, including the witness id and url.
}
interface WitnessData {
  id: string; // witness id
  url: string; // witness url
}
export interface ProviderClaimData {
  provider: string; // provider type
  parameters: string; // parameters of the provider
  owner: string; // owner of the claim
  timestampS: number; // timestamp of the claim creation in seconds
  context: string; // a stringified object, containg  contextMessage, contextAddress, and extractedParams 
  identifier: string; //identifier of the claim; Hash of (provider, parameters, context)
  epoch: number; // number of the epoch when the claim was created
}