bitrouter-swig-sdk
A standalone Rust SDK for the Swig wallet protocol on Solana.
Why this SDK?
The original Swig SDK has not been updated with newer dependency versions, which may conflict with modern Solana projects.
bitrouter-swig-sdk is a from-scratch reimplementation that provides the same Swig wallet functionality with up-to-date dependencies (Solana SDK v3–v4), so you can integrate Swig wallets without version conflicts.
Pure Rust, no system dependencies, no openssl-sys.
Installation
Add the crate to your project with Cargo:
Or add it directly to your Cargo.toml:
[]
= "0.1"
Feature flags
| Feature | Default | Description |
|---|---|---|
rpc |
✓ | Enables solana-transaction and solana-keypair for building and signing transactions |
token |
✓ | Enables SPL Token and Associated Token Account support |
alloy |
— | Enables Ethereum-compatible signing via Alloy (secp256k1) |
openssl-vendored |
— | Vendor OpenSSL for secp256r1 support (useful in CI/Docker) |
Usage
The SDK covers the full Swig wallet lifecycle:
- Wallet creation —
instruction::create::create_v1 - Authority management — add, update, remove authorities with granular permissions
- Session keys — slot-based expiring session keys for delegated signing
- Delegated execution —
sign_v2to execute arbitrary instructions through the wallet - Sub-accounts — create, sign, withdraw, and toggle sub-accounts
- Asset transfers — transfer assets out of the wallet
- Close wallet — reclaim rent
Quick start
use Ed25519ClientRole;
use ClientRole;
use instruction;
use ;
use ;
// Derive the Swig PDA
let swig_id: = random;
let = swig_account;
let = swig_wallet_address;
// Create a wallet with full permissions
let ix = create_v1;
// Build a role handle for subsequent operations
let role = new;
// Add a delegated authority with specific permissions
let new_auth = AuthorityConfig ;
let ixs = role.add_authority.expect;
// Execute an instruction through the wallet via SignV2
let inner_ix = sol_transfer_ix;
let ixs = role
.sign_v2
.expect;
Full example
The examples/round_trip.rs example exercises every major SDK feature on-chain using a single Ed25519 keypair. It covers:
- Wallet creation
- Adding delegated authorities with rich permission sets
- Updating authority permissions (AddActions, RemoveActionsByType, RemoveActionsByIndex, ReplaceAll)
- Creating session keys with slot-based expiry
- Delegated SOL transfers via SignV2
- Sub-account lifecycle (create, sign, withdraw, toggle)
- Removing authorities
- Transferring assets
- Fee-payer separation (payer ≠ authority)
Run it against devnet:
SWIG_PRIVATE_KEY=<base58-64-byte-keypair> cargo
# With airdrop enabled:
AIRDROP=true SWIG_PRIVATE_KEY=<base58-keypair> cargo
# Custom RPC:
SOLANA_RPC_URL=https://api.devnet.solana.com SWIG_PRIVATE_KEY=<base58-keypair> cargo
License
Apache-2.0