BIP-39 Implementation in Rust
This repository contains a custom implementation of the BIP-39 standard in Rust. The implementation allows for the generation of mnemonic phrases based on entropy, checksum, and wordlists. It supports multiple languages and mnemonic types (128-bit and 256-bit entropy). I Developed this to simplify using the bip39 more easily in rust than the current bip39 that i found. The code is easy to understand and well documented, feel free to suggest improvements :)
Features
- Entropy Generation: Generate random entropy with secure randomness.
- Checksum Calculation: Append a checksum based on the entropy.
- Mnemonic Phrase Generation: Convert entropy to mnemonic phrases using predefined wordlists.
- Language Support: Extendable to multiple languages.
Installation
-
Clone the repository:
-
Ensure you have Rust installed. If not, install it using rustup:
-
Build the project:
-
Run the tests:
Usage
Here is an example of how to use the library to generate a mnemonic phrase:
use ;
Library Structure
Mnemonic
- Represents a BIP-39 mnemonic phrase.
- Fields:
lang: Language for the wordlist.mnemonic_type: Type of mnemonic.entropy: Generated entropy bytes.checksum: Checksum appended to entropy.mnemonic_phrase: List of words representing the mnemonic phrase.
MnemonicType
- Enum representing the type of mnemonic:
Bits128: 128-bit entropy (12 words).Bits256: 256-bit entropy (24 words).
Language
- Represents the wordlist language. You can add custom wordlists by extending this module.
Wordlist Support
The Language module provides predefined wordlists. Currently supported:
- English
- Chinese Simplified
- Chinese Traditional
- Korean
- Japanese
- French
- Czech
- Italian
- Portuguese
- Spanish
To add more languages, implement the wordlist in the Language module.
Contributing
Contributions are welcome! If you have a feature request, bug report, or want to contribute code, please open an issue or a pull request.
Steps to Contribute
- Fork the repository.
- Create a feature branch:
- Commit your changes:
- Push to your branch:
- Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Feel free to explore, modify, and use this library as per your requirements. Happy coding!