Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Portuguese language support #53

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ french = []
italian = []
japanese = []
korean = []
portuguese = []
spanish = []

all-languages = [
Expand All @@ -34,6 +35,7 @@ all-languages = [
"italian",
"japanese",
"korean",
"portuguese",
"spanish"
]

Expand All @@ -50,8 +52,8 @@ bitcoin_hashes = { version = "0.11.0", default-features = false }
unicode-normalization = { version = "=0.1.22", optional = true }

[dev-dependencies]
rand_core = { version = "0.6.4", optional = false }
crate_rand = { package = "rand", version = "0.8.5", optional = false }
# Enabling the "rand" feature by default to run the benches
bip39 = { path = ".", features = ["rand"] }
bitcoin_hashes = "0.11.0" # enable default features for test


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Use the `all-languages` feature to enable all languages.
- Italian (`italian`)
- Japanese (`japanese`)
- Korean (`korean`)
- Portuguese (`portuguese`)
- Spanish (`spanish`)


Expand Down
3 changes: 3 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use bip39::*;
feature = "italian",
feature = "japanese",
feature = "korean",
feature = "portuguese",
feature = "spanish"
)))]
const LANG: Language = Language::English;
Expand All @@ -32,6 +33,8 @@ const LANG: Language = Language::Italian;
const LANG: Language = Language::Japanese;
#[cfg(feature = "korean")]
const LANG: Language = Language::Korean;
#[cfg(feature = "portuguese")]
const LANG: Language = Language::Portuguese;
#[cfg(feature = "spanish")]
const LANG: Language = Language::Spanish;

Expand Down
20 changes: 19 additions & 1 deletion src/language/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ mod italian;
mod japanese;
#[cfg(feature = "korean")]
mod korean;
#[cfg(feature = "portuguese")]
mod portuguese;
#[cfg(feature = "spanish")]
mod spanish;

/// The maximum number of languages enabled.
pub(crate) const MAX_NB_LANGUAGES: usize = 9;
pub(crate) const MAX_NB_LANGUAGES: usize = 10;

/// Language to be used for the mnemonic phrase.
///
Expand Down Expand Up @@ -50,6 +52,9 @@ pub enum Language {
#[cfg(feature = "korean")]
/// The Korean language.
Korean,
#[cfg(feature = "portuguese")]
/// The Portuguese language.
Portuguese,
#[cfg(feature = "spanish")]
/// The Spanish language.
Spanish,
Expand Down Expand Up @@ -81,6 +86,8 @@ impl Language {
Language::Japanese,
#[cfg(feature = "korean")]
Language::Korean,
#[cfg(feature = "portuguese")]
Language::Portuguese,
#[cfg(feature = "spanish")]
Language::Spanish,
]
Expand All @@ -105,6 +112,8 @@ impl Language {
Language::Japanese => &japanese::WORDS,
#[cfg(feature = "korean")]
Language::Korean => &korean::WORDS,
#[cfg(feature = "portuguese")]
Language::Portuguese => &portuguese::WORDS,
#[cfg(feature = "spanish")]
Language::Spanish => &spanish::WORDS,
}
Expand All @@ -130,6 +139,8 @@ impl Language {
Language::Japanese => true,
#[cfg(feature = "korean")]
Language::Korean => true,
#[cfg(feature = "portuguese")]
Language::Portuguese => true,
#[cfg(feature = "spanish")]
Language::Spanish => true,
}
Expand Down Expand Up @@ -175,6 +186,7 @@ mod tests {
feature = "italian",
feature = "japanese",
feature = "korean",
feature = "portuguese",
feature = "spanish"
))]
#[test]
Expand All @@ -190,6 +202,7 @@ mod tests {
//! d392c49fdb700a24cd1fceb237c1f65dcc128f6b34a8aacb58b59384b5c648c2 italian.txt
//! 2eed0aef492291e061633d7ad8117f1a2b03eb80a29d0e4e3117ac2528d05ffd japanese.txt
//! 9e95f86c167de88f450f0aaf89e87f6624a57f973c67b516e338e8e8b8897f60 korean.txt
//! 2685e9c194c82ae67e10ba59d9ea5345a23dc093e92276fc5361f6667d79cd3f portuguese.txt
//! 46846a5a0139d1e3cb77293e521c2865f7bcdb82c44e8d0a06a2cd0ecba48c0b spanish.txt

use bitcoin_hashes::{sha256, Hash, HashEngine};
Expand All @@ -212,6 +225,10 @@ mod tests {
Language::Japanese,
),
("9e95f86c167de88f450f0aaf89e87f6624a57f973c67b516e338e8e8b8897f60", Language::Korean),
(
"2685e9c194c82ae67e10ba59d9ea5345a23dc093e92276fc5361f6667d79cd3f",
Language::Portuguese,
),
("46846a5a0139d1e3cb77293e521c2865f7bcdb82c44e8d0a06a2cd0ecba48c0b", Language::Spanish),
];
assert_eq!(MAX_NB_LANGUAGES, checksums.len());
Expand Down Expand Up @@ -256,6 +273,7 @@ mod tests {
feature = "italian",
feature = "japanese",
feature = "korean",
feature = "portuguese",
feature = "spanish"
))]
#[test]
Expand Down
Loading