Rust Amp Client (amp-rust)
⚠️ DEVELOPMENT STATUS: This package is currently in development and undergoing early integration testing. The API may change and some endpoints are not yet implemented. Don't use in production environments.
A Rust client for the Blockstream AMP API.
Usage
Add the following to your Cargo.toml:
[]
= "0.0.3"
Examples
For more detailed examples, please refer to the crate documentation.
Running Examples
You can run the included examples using cargo:
# Show a summary of all assets issued by your credentials
# View the API changelog
# Validate a GAID (Global Asset ID)
# Get information about a specific distribution
# Create, issue, and authorize a new asset for distribution tests (requires live API)
AMP_TESTS=live
# Run end-to-end asset distribution workflow with specific asset and user (requires live API)
Make sure to set up your .env file with the required credentials first.
Get a registered user
use ApiClient;
async
Get an asset
use ApiClient;
async
Create a category
use ;
async
Manage asset assignments
use ApiClient;
async
Create and execute asset distributions
use ;
async
Missing Endpoints
The following AMP API endpoints are not yet implemented in this client library. This list may not be exhaustive:
Asset Operations
POST /api/assets/{assetUuid}/reissue-request- Request asset reissuancePOST /api/assets/{assetUuid}/reissue-confirm- Confirm asset reissuancePOST /api/assets/{assetUuid}/burn-request- Request asset burnPOST /api/assets/{assetUuid}/burn-confirm- Confirm asset burnGET /api/assets/{assetUuid}/reissuances- Get asset reissuancesGET /api/assets/{assetUuid}/txs- Get asset transactionsGET /api/assets/{assetUuid}/txs/{txid}- Get specific asset transactionGET /api/assets/{assetUuid}/lost-outputs- Get asset lost outputsPOST /api/assets/{assetUuid}/update-blinders- Update asset blinders
Manager Operations
POST /api/managers/{managerId}/change-password- Change manager password
These and potentially other endpoints will be added in future releases. If you need any of these endpoints urgently, please open an issue on the project repository.
Token Management
The AMP client includes sophisticated token management with automatic persistence and refresh capabilities.
Features
- Automatic Token Persistence: Tokens are automatically saved to
token.jsonand loaded on subsequent runs - Proactive Refresh: Tokens are automatically refreshed 5 minutes before expiry
- Thread-Safe Operations: All token operations are thread-safe and prevent race conditions
- Retry Logic: Built-in retry logic with exponential backoff for token operations
- Secure Storage: Tokens are stored securely using the
secrecycrate
Token Lifecycle
- First Run: Client obtains a new token from the API and persists it to disk
- Subsequent Runs: Client loads the existing token from disk if still valid
- Automatic Refresh: Token is automatically refreshed when it expires soon (within 5 minutes)
- Fallback: If refresh fails, client automatically obtains a new token
Usage Examples
use ApiClient;
async
Token Persistence Configuration
Token persistence is automatically enabled in the following scenarios:
- When
AMP_TESTS=live(for live API testing) - When
AMP_TOKEN_PERSISTENCE=trueis set - In test environments (
cfg!(test))
The token file (token.json) contains:
Configuration
Environment Variables
The client can be configured using the following environment variables:
Authentication (Required for live tests)
AMP_USERNAME: Username for AMP API authenticationAMP_PASSWORD: Password for AMP API authenticationAMP_API_BASE_URL: Base URL for the AMP API (default:https://amp-test.blockstream.com/api)
Retry Configuration (Optional)
API_RETRY_MAX_ATTEMPTS: Maximum number of retry attempts (default: 3)API_RETRY_BASE_DELAY_MS: Base delay between retries in milliseconds (default: 1000)API_RETRY_MAX_DELAY_MS: Maximum delay between retries in milliseconds (default: 30000)API_REQUEST_TIMEOUT_SECONDS: Request timeout in seconds (default: 10)
Test Configuration
AMP_TESTS: Set toliveto run tests against the actual API
Token Persistence (Optional)
AMP_TOKEN_PERSISTENCE: Set totrueto enable token persistence to disk (default: enabled for live tests)
Example Configuration
# Authentication
# Retry configuration (optional)
# Enable live tests
# Enable token persistence (optional)
Signer Setup and Usage
The AMP client includes a comprehensive signer implementation for handling asset operations like distribution, reissuance, and burning. The LwkSoftwareSigner provides testnet-focused transaction signing using Blockstream's Liquid Wallet Kit (LWK).
⚠️ Security Warning
TESTNET/REGTEST ONLY: The LwkSoftwareSigner is designed exclusively for testnet and regtest environments. It stores mnemonic phrases in plain text and should NEVER be used in production or with real funds.
Basic Signer Setup
Creating a Signer from Existing Mnemonic
use ;
async
Generating a New Signer
use LwkSoftwareSigner;
async
Indexed Mnemonic Access for Testing
For test isolation and consistent test environments, use indexed mnemonic access:
use LwkSoftwareSigner;
async
Generating Addresses for Asset Issuance
Before issuing assets, you need to generate addresses that can receive the issued assets:
use LwkSoftwareSigner;
async
Using Signer with Asset Distribution
The signer integrates seamlessly with the distribute_asset method and will be essential for future burn and reissuance operations:
use ;
async
Wallet Integration
For Elements wallet integration, you can generate descriptors from the signer:
use LwkSoftwareSigner;
async
Future Operations
The same signer setup and passing pattern will be used for upcoming operations:
- Asset Reissuance:
reissue_asset(asset_uuid, amount, &signer) - Asset Burning:
burn_asset(asset_uuid, amount, &signer) - Advanced Distribution: Enhanced distribution workflows with complex signing requirements
The signer abstraction ensures consistent transaction signing across all asset operations while maintaining security best practices for testnet development.
Testing
To run the tests, you will need to set the AMP_USERNAME and AMP_PASSWORD environment variables.
AMP_USERNAME=... AMP_PASSWORD=... cargo test
To run the live tests, you will also need to set the AMP_TESTS environment variable to live.
AMP_USERNAME=... AMP_PASSWORD=... AMP_TESTS=live cargo test
Some tests that perform state-changing operations are ignored by default. To run them, use the --ignored flag.
AMP_USERNAME=... AMP_PASSWORD=... AMP_TESTS=live cargo test -- --ignored