This Rust project provides a simple tool for managing private and public keys in Base58 format, commonly used for wallets like Backpack wallet. It decodes the keys, validates their size, and serializes them into a JSON file for storage.
- Base58 Decoding: Converts Base58-encoded private and public keys into byte arrays.
- Key Validation: Ensures that both private and public keys are 32 bytes long, trimming the private key if necessary.
- Keypair Serialization: Concatenates the private and public keys into a single keypair and serializes it into a JSON file (
wallet.json
).
To run this code, you need to have the following installed:
- Rust (Programming Language)
- bs58 (Base58 encoding/decoding library for Rust)
- serde_json (Serialization library for JSON in Rust)
The project is organized as follows: rust-wallet-key-manager/ │ └── wallet_key_json/ ├── Cargo.toml # Rust manifest file └── src/ └── main.rs # Main Rust code
-
Install dependencies by adding the necessary crates to your
Cargo.toml
file:[dependencies] bs58 = "0.4" serde_json = "1.0"
-
Compile the project:
cargo build
-
Open the
src/main.rs
file and replace the placeholder valuesyour_base58_private_key_here
andyour_base58_public_key_here
with your actual Base58-encoded private and public keys. -
Run the project:
cargo run
-
Once the program runs successfully, it will generate a file called
wallet.json
in the project directory containing the serialized keypair.
If you encounter any bugs, have suggestions, or want to discuss this project, feel free to comment here #1
For example, if your private and public keys are as follows:
- Private Key:
8p3fsFU7GnRTU5L26WQiqM7RAEs8nXyZ2L9Qqc8vCRT8XctwUqe
- Public Key:
B2QmI8eA5WNSnH5F7MZRVNYvExg5AQkrtk
The resulting wallet.json
file will look something like this:
[67, 98, 65, 213, 135, 20, ... ]