1 unstable release
0.1.0 | Aug 19, 2024 |
---|
#109 in #cryptocurrency
105KB
1.5K
SLoC
Bittensor Wallet
Bittensor Wallet is a Rust crate that provides wallet functionality for the Bittensor network. It includes features for managing wallets, keypairs, and integrates with Python through PyO3 bindings.
Architecture
The crate is structured into several key components:
- Wallet: The main struct that handles wallet operations such as creation, key management, and encryption.
- Keypair: Manages cryptographic keypairs, including signing and encryption.
- Error Handling: Custom error types for wallet-specific errors.
- Python Bindings: Allows the wallet functionality to be used from Python.
Key files:
src/wallet.rs
: Contains theWallet
struct and its implementations.src/keypair.rs
: Implements theKeypair
struct for cryptographic operations.src/errors.rs
: Defines custom error types.src/python_bindings.rs
: Implements Python bindings using PyO3.
Using the Python Bindings
This project uses Maturin to build and manage Python bindings. To use the Bittensor Wallet in Python:
-
Install Maturin:
pip install maturin
-
Build the Python module:
maturin develop
-
In your Python code:
import bittensor_wallet # Create a new wallet wallet = bittensor_wallet.PyWallet("my_wallet", "/path/to/wallet") # Create a new wallet with a mnemonic wallet.create_new_wallet(12, "my_password") # Create a new hotkey wallet.create_new_hotkey("my_hotkey", "my_password") # Get the coldkey coldkey = wallet.get_coldkey("my_password") # Get a hotkey hotkey = wallet.get_hotkey("my_hotkey", "my_password") # Sign a message message = b"Hello, Bittensor!" signature = hotkey.sign(message, "my_password")
Building and Testing
To build the crate:
cargo build
To run tests:
cargo test
Dependencies
This crate relies on several key dependencies:
pyo3
: For Python bindingssp-core
andsp-runtime
: For Substrate-based cryptographyaes-gcm
andargon2
: For encryption and key derivationbip39
: For mnemonic generation and handling
For a full list of dependencies, please refer to the Cargo.toml
file.
Dependencies
~35–48MB
~828K SLoC