Express Backend
We will start from a simple Express backend. You can use any backend infrastructure or library of your choosing but note that current library support is limited to JavaScript/TypeScript. Install express
, @ethsign/sp-sdk
, and viem
.
This boilerplate code is the simplest backend you can create. It creates a new server and listens for requests on port 3000.
Initializing the Sign Protocol Client
Since we are running this code from a backend server, Sign Protocol's SDK requires you to pass in a private key account when creating your SignProtocolClient
. Typically, when no account is provided, the client will use window.ethereum
, which does not exist in a backend environment. Your code should look something like the following, assuming you are building on Sepolia:
Setting Up Your Controller
Your controller will be responsible for creating the attestation. Since this is a delegate attestation, it must provide the attestation object and the delegation signature. The backend is not responsible for generating the delegation signature because the user's wallet must sign a message to retrieve the signature. Your controller should look something like the following:
(Frontend) Generating a Delegation Signature
This section must be implemented on your frontend. Delegation signatures are a mechanism to allow a third party to upload an attestation on behalf of an attester. The attester must approve (sign) the attestation that is being created to prevent fraudulent attestations. In other words, you would not want someone making attestations using your wallet address without you approving the attestation content first - unapproved attestations could pose a major security threat. After attaining a signature from the user/attester, the attestation and signature can be sent to the backend we wrote above. Your frontend code should include the following:
Recap
The general flow to create a delegated attestation using a backend is the following:
Generate the attestation content. This can be done on the frontend (as shown above) or on a dedicated backend (and then sent to the frontend for step 2).
Request a delegation signature from the user in a browser.
Forward the attestation and delegation signature to your dedicated backend.
Create the attestation, providing the attestation and delegation signature.
Last updated