This project demonstrates how to integrate the Para SDK with a Bun server, showcasing various ways to handle wallet creation and sign transactions using Para Pre-Generated (PreGen) wallets and different signers. The project highlights several key libraries and protocols, such as Ethers, CosmJS, Viem, Solana Web3, and Alchemy Account Abstraction (AA).
This server provides different routes to create wallets and sign transactions using the Para SDK and other blockchain technologies. The server supports multiple signing mechanisms across several blockchain networks, ensuring robust, secure, and decentralized transaction signing.
The routes utilize Para PreGen wallets and different signers, and the project strongly emphasizes securely storing
the userShare
with encryption to ensure user data safety. We use encryption-utils.ts
for handling encryption and decryption of key shares.
For userOps signing with Alchemy AA, we demonstrate the use of a simple contract that increases the count on the contract using user operations, which is a key feature of account abstraction (AA).
A Para PreGen wallet is a wallet account generated by taking an identifier provided by the app (e.g., an email) and
creating a Para account and wallet using our distributed 2-of-2 Multi-Party Computation (MPC) technology. The server
then returns the userShare
half of the key to the app, allowing it to initiate user operations with its half of the
key.
This means the app can create an account on the user's behalf, rather than requiring the user to create the account
themselves. The userShare
is crucial because Para has no way of recovering it. This is why securely storing the
userShare
with encryption is essential. Without this key share, the user would lose access to their account.
These wallet accounts are claimable by the user. Once a user claims their Para account, the keys are refreshed, and
Para provides the user with recovery options for the account. Until the account is claimed, the app holds the
userShare
and can perform actions with that account. This setup has numerous use cases, especially for server-side
applications, allowing sophisticated bots and agents to take actions for users with wallets that users can eventually
control and use across multiple applications.
The Para Server SDK can also import a session that is exported from a client-side application. This allows the server to use a user-owned account, rather than a PreGen account, to perform all of the actions. This flexibility makes it easy to transition from app-generated accounts to fully user-owned accounts when needed.
Before running the server, ensure that you have a .env
file properly configured based on .env.example
. You will need
API keys such as PARA_API_KEY
and ALCHEMY_API_KEY
for various services used in the project.
-
Install dependencies:
bun install
-
Start the server in development mode:
bun dev
Alternatively, you can run the server directly with:
bun run server.ts
The server starts on port 8000
. The following routes are available for interacting with the wallet and signing
functionalities. Each route requires an email
in the request body, and all requests must be authenticated using a
Bearer token in the Authorization
header.
- [POST]
/wallets/create
- Creates a new Para Pre-Generated wallet.curl -X POST http://localhost:8000/wallets/create -H "Content-Type: application/json" -d '{"email": "[email protected]"}'
-
[POST]
/wallets/sign/paraPreGen
- Signs a message and transaction using the Para PreGen wallet.curl -X POST http://localhost:8000/wallets/sign/paraPreGen -H "Content-Type: application/json" -d '{"email": "[email protected]"}'
-
[POST]
/wallets/sign/paraSession
- Signs using a Para session imported from the client.curl -X POST http://localhost:8000/wallets/sign/paraSession -H "Content-Type: application/json" -d '{"email": "[email protected]", "session": "session_data"}'
-
[POST]
/wallets/sign/ethers
- Signs a message and transaction using the Para Ethers signer.curl -X POST http://localhost:8000/wallets/sign/ethers -H "Content-Type: application/json" -d '{"email": "[email protected]"}'
-
[POST]
/wallets/sign/viem
- Signs a transaction using the Para Viem signer.curl -X POST http://localhost:8000/wallets/sign/viem -H "Content-Type: application/json" -d '{"email": "[email protected]"}'
-
[POST]
/wallets/sign/cosmjs
- Signs a Cosmos transaction using the Para CosmJS signer.curl -X POST http://localhost:8000/wallets/sign/cosmjs -H "Content-Type: application/json" -d '{"email": "[email protected]"}'
-
[POST]
/wallets/sign/solana-web3
- Signs a Solana transaction using the Para Solana Web3 signer.curl -X POST http://localhost:8000/wallets/sign/solana-web3 -H "Content-Type: application/json" -d '{"email": "[email protected]"}'
-
[POST]
/wallets/sign/alchemy
- Demonstrates userOps signing with Alchemy AA, using a simple contract to increase a count. For more details, refer to the contract Example.sol.curl -X POST http://localhost:8000/wallets/sign/alchemy -H "Content-Type: application/json" -d '{"email": "[email protected]"}'
It is strongly recommended to securely store the userShare
with encryption. The encryption and decryption of key
shares are handled in the encryption-utils.ts file. Always encrypt user data before
storing it in the database, and ensure decryption is done securely during usage.
The key shares are stored and managed in the keySharesDB.ts file, and the actual database is found in keyShares.db. Be sure to follow best practices when handling sensitive cryptographic materials.
For more detailed documentation and API references, visit the official Para SDK documentation.