Git Product home page Git Product logo

rust-bip39's Introduction

bip39

A Rust implementation of BIP-39 mnemonic codes.

Word lists (languages)

We support all languages specified in the BIP-39 standard as of writing.

The English language is always loaded and other languages can be loaded using the corresponding feature.

Use the all-languages feature to enable all languages.

  • English (always enabled)
  • Simplified Chinese (chinese-simplified)
  • Traditional Chinese (chinese-traditional)
  • Czech (czech)
  • French (french)
  • Italian (italian)
  • Japanese (japanese)
  • Korean (korean)
  • Portuguese (portuguese)
  • Spanish (spanish)

MSRV

This crate supports Rust v1.41.1 and up and works with no_std.

When using older version of Rust, you might have to pin the version of the bitcoin_hashes crate used as such:

$ cargo update --package "bitcoin_hashes" --precise "0.12.0"

If you enable the zeroize feature the MSRV becomes 1.51.

rust-bip39's People

Contributors

ayrat555 avatar benma avatar dr-julius-no avatar flemosr avatar jeandudey avatar kayabanerve avatar michalkucharczyk avatar pezcore avatar praveenperera avatar stevenroose avatar tcharding avatar trevyn avatar yancyribbens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-bip39's Issues

Question: Get word by index

I have a situation where I need to access a word in some language by some index [0, 2047]. It does not seem like it's currently possible to do this.

Specifically, I am attempting to implement the current SeedQR encoding used by @SeedSigner. The encoding is a list of length n of 4-digit numbers each corresponding to an index in the word list.

I can submit a PR addressing this issue, but I would like to hear the maintainers' opinion as to the best way to do it. The simplest solution that comes to mind would be to make Language::word_list public instead of just create-visible.

New release?

The latest version of this crate 1.0.1 was released on April 1st, 2021 - over 1 year and 8 months ago. Since then, there's been a PR to add Zeroize support which we'd like to use without having to specify a git dependency. Would you mind cutting a new release so we can use the zeroize feature via crates.io?

Use alloc instead of std

For example in

rust-bip39/src/lib.rs

Lines 603 to 605 in a7649ae

/// Convert the mnemonic back to the entropy used to generate it.
#[cfg(feature = "std")]
pub fn to_entropy(&self) -> Vec<u8> {

It would be helpful to be able to access this function (and others that return a Vec) with no_std, if one has access to alloc (alloc::vec::Vec)

A new feature alloc could be added and used instead of std for Vec.

Docsrs API documentation fails to display feature-gated items

For example: Mnemonic::generate, Mnemonic::generate_in and Mnemonic::generate_in_with are completely omitted from the API documentation, and there is no mention of the features that enable them:
2023-03-11-135525_1008x1143_scrot

From the API documentation alone, one would have no idea that this functionality exists or how to use it.

Instead, these feature gated items should appear in the API documentation along with a marker that identifies them as being available only with certain crate features enabled. Here is an example of how it should look taken from the k256 crate:
2023-03-11-140233_541x184_scrot
.

passphrases with 15 words should be possible

The JavaScript npm implementation of BIP39 allows word counts divisible by 3:
https://github.com/bitcoinjs/bip39/blob/5faee2c17b2195f30b03cb125df68c20d7dd584b/src/index.js#L72
Same in the Python reference implementation linked from the BIP0039 wiki page:
https://github.com/trezor/python-mnemonic/blob/75629ff0e1a2dec7fbb3aa2c70a964c9023db5b4/src/mnemonic/mnemonic.py#L129
Real life example: The Yorio wallet for Cardano uses 15 words.
So this should be changed as well in this code:
https://github.com/rust-bitcoin/rust-bip39/blob/master/src/lib.rs
Looks like there are 2 occurrences of % 6. This should be refactored to a constant, and probably % 3, so that it is the same as in the npm library, or testing for the fixed set [12, 15, 18, 21, 24], as used in the Python reference implementation.

Is this still maintained?

Is this project still maintained and are there any plans for a release? I noticed the last release on crates.io was about a year and a half ago, but it appears there have been several desirable feature upgrades merged into master since then.

Additional maintainers

@stevenroose would you be open to adding additional maintainers on this repo? I know you're taking care of a bunch of other repos and it looks like this one hasn't been getting enough attention in terms of ACK'd PRs being merged and creating regular releases. I ask because this repo is a dependency for bitcoindevkit/bdk. I found a dev from the BDK team, @vladimirfomene who said he'd be happy help out as a maintainer, he's currently also the maintainer for the bitcoindevkit/rust-esplora-client repo. And/or @tcharding are you able to help?

store the words in a more compact way to reduce binary sizes

The words are currently stored as

pub const WORDS: [&str; 2048] = [

This carries an overhead of 16 bytes per element (8 bytes pointer to data and 8 bytes length), which is an overhead of ~32kB.

You can verify this with:

println!("{}",` std::mem::size_of_val(&WORDS))   

This is not great for embedded use (in 32 bit systems the overhead is half as big but it is still very big).

It would be way more efficient to store the words as one big &str plus array of indices for the word boundaries

Would you be open to a PR that implements this behind a feature? The Language::words_by_prefix() and Language::wordlist() functions would be disabled if this feature was active. Instead a get_word(idx: usize) -> Option<'static str> method would be added, which would still allow users to access the words efficiently.

Rename "to_seed_normalize" to "add_passphrase" for adding BIP39 passphrase

Is the to_seed_normalize" the canonical way to add a bip39 passphrase in this crate?

If so, would it be possible to rename the method? Something like "add_passhphrase" would be very obvious to someone new.

Or making the canonical way to add a passphrase much clearer in the API in some other manner. The current method name and its arguments are not very obvious.

Missing Cargo.lock

Is there a specific reason for this repo to not have a Cargo.lock?

I need to build this package with Nix and the Cargo.lock is required. It wouldn't make sense to generate this during build, in this case.

passphrase support?

would passphrase support fit in this library? It is part of the BIP and is very useful for hot wallets.

Why allow invalid Mnemonics?

Why does Mnemonic::parse_in_normalized_without_checksum_check exist? Isn't the main usefulness of this crate the fact that Mnemonic instances are guaranteed to be valid? Now if someone writes an application that presents a Mnemonic to a user, they have to manually trace the source of its initialization and make sure it wasn't created with parse_in_normalized_without_checksum_check or else they risk presenting an invalid mnemonic.

It makes sense for possibly-invalid mnemonics and operations thereof to be in scope of this crate, but I feel like their implementation shouldn't break the checksum validity invariant of Mnemonic. That way, application authors can simply trust that Mnemonic instances are valid.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.