Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Commit 50d5711

Browse files
committed
Add gem_keystore crate with BIP39 recovery phrase suggestions
Introduce gem_keystore as the foundation crate for keystore and key management work. Initial surface is a Mnemonic helper that exposes BIP39 English word suggestions, wired through gemstone via UniFFI as suggest_recovery_phrase_words.
1 parent 5a632aa commit 50d5711

8 files changed

Lines changed: 73 additions & 0 deletions

File tree

‎Cargo.lock‎

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ sui-types = { package = "sui-sdk-types", version = "0.3.0", features = [
115115
"serde",
116116
] }
117117
k256 = { version = "0.13.4", features = ["ecdsa", "sha256"] }
118+
bip39 = { version = "2.2.2", default-features = false }
118119

119120
uniffi = { version = "0.31.1" }
120121
regex = { version = "1.12.3" }

‎crates/gem_keystore/Cargo.toml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "gem_keystore"
3+
version = { workspace = true }
4+
edition = { workspace = true }
5+
6+
[dependencies]
7+
bip39 = { workspace = true }

‎crates/gem_keystore/src/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod mnemonic;
2+
3+
pub use mnemonic::Mnemonic;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use bip39::Language;
2+
3+
pub struct Mnemonic;
4+
5+
impl Mnemonic {
6+
pub fn suggest(prefix: &str) -> Vec<String> {
7+
Language::English.words_by_prefix(prefix).iter().map(|word| word.to_string()).collect()
8+
}
9+
}
10+
11+
#[cfg(test)]
12+
mod tests {
13+
use super::*;
14+
15+
#[test]
16+
fn test_suggest() {
17+
assert_eq!(Mnemonic::suggest("woo"), vec!["wood", "wool"]);
18+
assert_eq!(Mnemonic::suggest("abandon"), vec!["abandon"]);
19+
assert_eq!(Mnemonic::suggest("woof"), Vec::<String>::new());
20+
21+
let all_words = Mnemonic::suggest("");
22+
assert_eq!(all_words.len(), 2048);
23+
assert_eq!(all_words.first().map(String::as_str), Some("abandon"));
24+
assert_eq!(all_words.last().map(String::as_str), Some("zoo"));
25+
}
26+
}

‎gemstone/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ gem_xrp = { path = "../crates/gem_xrp", features = ["rpc", "signer"] }
4141
gem_near = { path = "../crates/gem_near", features = ["rpc", "signer"] }
4242
gem_polkadot = { path = "../crates/gem_polkadot", features = ["rpc", "signer"] }
4343
gem_wallet_connect = { path = "../crates/gem_wallet_connect" }
44+
gem_keystore = { path = "../crates/gem_keystore" }
4445
chain_traits = { path = "../crates/chain_traits" }
4546
signer = { path = "../crates/signer" }
4647
number_formatter = { path = "../crates/number_formatter" }

‎gemstone/src/keystore.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use gem_keystore::Mnemonic;
2+
3+
#[uniffi::export]
4+
pub fn suggest_recovery_phrase_words(prefix: &str) -> Vec<String> {
5+
Mnemonic::suggest(prefix)
6+
}
7+
8+
#[cfg(test)]
9+
mod tests {
10+
use super::*;
11+
12+
#[test]
13+
fn test_suggest_recovery_phrase_words() {
14+
assert_eq!(suggest_recovery_phrase_words("woo"), vec!["wood", "wool"]);
15+
assert_eq!(suggest_recovery_phrase_words("woof"), Vec::<String>::new());
16+
}
17+
}

‎gemstone/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod deeplink;
99
pub mod ethereum;
1010
pub mod gateway;
1111
pub mod gem_swapper;
12+
pub mod keystore;
1213
pub mod message;
1314
pub mod models;
1415
pub mod network;

0 commit comments

Comments
 (0)