Bagel SDK
Integrate private transactions into your application
Bagel SDK
The Bagel SDK enables developers to integrate private Solana transactions into their applications. It provides a simple interface for creating stealth addresses and sending private transactions.
Installation
Basic Usage
API Reference
Creating an SDK Instance
Resolving a Recipient
This function resolves a Bagel domain (e.g., "username.bagel.xyz") to retrieve the recipient's public keys.
Returns:
Example:
Creating a Stealth Address
This function creates a unique stealth address for sending funds to a recipient.
Parameters:
recipientViewingPublicKey
: The recipient's public viewing key (hex-encoded)recipientSpendingPublicKey
: The recipient's public spending key (hex-encoded)
Returns:
ephemeralSecret
: The ephemeral private key (hex-encoded)ephemeralPublic
: The ephemeral public key (hex-encoded)stealthAddress
: The stealth address (Solana base58-encoded)
Example:
Publishing an Ephemeral Key
This function publishes an ephemeral public key to the Bagel registry so that the recipient can discover and claim the payment.
Parameters:
recipientId
: The recipient's Bagel ID (e.g., "username.bagel.xyz")ephemeralPublicKey
: The ephemeral public key (hex-encoded)
Example:
Sending a Transaction
This function registers the ephemeral key and returns the stealth address.
Parameters:
Example:
Integration Guide
Integrating with Web Applications
-
Install the SDK:
-
Initialize the SDK:
-
Create a Send Function:
Best Practices
- Error Handling: Implement proper error handling for network failures and invalid inputs
- User Experience: Provide clear feedback during the resolution and transaction processes
- Security: Never expose or log ephemeral private keys
- Validation: Validate recipient IDs and amounts before creating transactions
- Testing: Test with small amounts before implementing in production
This SDK enables developers to add privacy features to their Solana applications with minimal effort, improving user experience while maintaining the security and privacy guarantees of the Bagel protocol.