Server SDK
Learn how to leverage the Capsule SDK for server-side operations.
The Capsule Server SDK enables secure server-side signing by allowing you to import client-side sessions. This feature is particularly useful for scenarios where server-side signing operations are necessary.
You can also use the Server SDK with pre-generated wallets if your use case requires wallet creation to occur server-side.
To do this, follow the steps outlined in the
Pre-generated Wallet Integration Guideand import the @usecapsule/server-sdk
package in your server-side environment instead of the relevant client side package.
Server-Side Setup
Client-Side Export
First, export the session from an existing Capsule Client instance on the client-side:
Now securely transfer the serializedSession
to the server for import.
Server-Side Import
Next, import the serialized session on the server using the Capsule Server SDK:
Security Note: Implement robust security measures when transferring the serialized session between client and server to prevent unauthorized access.
Utilize Imported Session
After importing the session, you can perform signing operations similar to the client-side implementation. Here are two methods:
-
Direct Signing with Capsule Instance:
-
Signing with Ethers.js Integration:
Important: The server can only perform signing operations while the imported session remains valid. The session’s lifespan is directly tied to the client’s active session.
Best Practices
- Session Management: Implement proper session management to ensure timely expiration and renewal of imported sessions.
- Error Handling: Incorporate robust error handling to manage scenarios where the session may become invalid during server-side operations.
- Logging and Monitoring: Implement comprehensive logging and monitoring to track session imports, expirations, and signing activities for security and debugging purposes.
Was this page helpful?