Skip to content

Commit de0b2a3

Browse files
committed
feat: accept 18 and 24 words mnemonic
1 parent c3d247e commit de0b2a3

File tree

7 files changed

+631
-127
lines changed

7 files changed

+631
-127
lines changed

Cargo.lock

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

neptune-core-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ tarpc = { version = "^0.34", features = [
3636
] }
3737
tokio = { version = "1.41", features = ["full", "tracing"] }
3838
bech32 = ">=0.9, <0.10"
39+
dialoguer = "0.12.0"
3940

4041
[dev-dependencies]
4142
arbitrary = "1.4.2"

neptune-core-cli/src/main.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use clap::CommandFactory;
1919
use clap::Parser;
2020
use clap_complete::generate;
2121
use clap_complete::Shell;
22+
use dialoguer::theme::ColorfulTheme;
23+
use dialoguer::Select;
2224
use itertools::Itertools;
2325
use neptune_cash::api::export::TransactionKernelId;
2426
use neptune_cash::api::tx_initiation::builder::tx_output_list_builder::OutputFormat;
@@ -188,7 +190,7 @@ enum Command {
188190
max_num_blocks: Option<usize>,
189191
},
190192

191-
/// Show smallest block interval in the specified range.
193+
/// Show the smallest block interval in the specified range.
192194
MinBlockInterval {
193195
last_block: BlockSelector,
194196
max_num_blocks: Option<usize>,
@@ -200,7 +202,7 @@ enum Command {
200202
max_num_blocks: Option<usize>,
201203
},
202204

203-
/// Show largest difficulty in the specified range.
205+
/// Show the largest difficulty in the specified range.
204206
MaxBlockDifficulty {
205207
last_block: BlockSelector,
206208
max_num_blocks: Option<usize>,
@@ -297,7 +299,7 @@ enum Command {
297299
/// block proposals, and new transactions from being received.
298300
Freeze,
299301

300-
/// If state updates have been paused, resumes them. Otherwise does nothing.
302+
/// If state updates have been paused, resumes them. Otherwise, does nothing.
301303
Unfreeze,
302304

303305
/// pause mining
@@ -549,12 +551,12 @@ async fn main() -> Result<()> {
549551

550552
// prompt user for all shares
551553
let mut shares = vec![];
552-
let capture_integers = Regex::new(r"^(\d+)\/(\d+)$").unwrap();
554+
let capture_integers = Regex::new(r"^(\d+)\/(\d+)$")?;
553555
while shares.len() != *t {
554556
println!("Enter share index (\"i/n\"): ");
555557

556558
let mut buffer = "".to_string();
557-
std::io::stdin()
559+
io::stdin()
558560
.read_line(&mut buffer)
559561
.expect("Cannot accept user input.");
560562
let buffer = buffer.trim();
@@ -722,7 +724,7 @@ async fn main() -> Result<()> {
722724
}
723725

724726
// all other operations need a connection to the server
725-
let server_socket = SocketAddr::new(std::net::IpAddr::V4(Ipv4Addr::LOCALHOST), args.port);
727+
let server_socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), args.port);
726728
let Ok(transport) = tarpc::serde_transport::tcp::connect(server_socket, Json::default).await
727729
else {
728730
eprintln!("This command requires a connection to `neptune-core`, but that connection could not be established. Is `neptune-core` running?");
@@ -1332,8 +1334,8 @@ async fn main() -> Result<()> {
13321334
//
13331335
// Otherwise, we call cookie_hint() RPC to obtain data-dir.
13341336
// But the API might be disabled, which we detect and fallback to the default data-dir.
1335-
async fn get_cookie_hint(client: &RPCClient, args: &Config) -> anyhow::Result<auth::CookieHint> {
1336-
async fn fallback(client: &RPCClient, args: &Config) -> anyhow::Result<auth::CookieHint> {
1337+
async fn get_cookie_hint(client: &RPCClient, args: &Config) -> Result<auth::CookieHint> {
1338+
async fn fallback(client: &RPCClient, args: &Config) -> Result<auth::CookieHint> {
13371339
let network = client.network(context::current()).await??;
13381340
let data_directory = DataDirectory::get(args.data_dir.clone(), network)?;
13391341
Ok(auth::CookieHint {
@@ -1416,7 +1418,7 @@ fn process_utxo_notifications(
14161418
network: Network,
14171419
private_notifications: Vec<PrivateNotificationData>,
14181420
receiver_tag: Option<String>,
1419-
) -> anyhow::Result<()> {
1421+
) -> Result<()> {
14201422
let data_dir = root_data_dir.utxo_transfer_directory_path();
14211423

14221424
if !private_notifications.is_empty() {
@@ -1428,10 +1430,7 @@ fn process_utxo_notifications(
14281430

14291431
// TODO: It would be better if this timestamp was read from the created
14301432
// transaction.
1431-
let timestamp = SystemTime::now()
1432-
.duration_since(UNIX_EPOCH)
1433-
.unwrap()
1434-
.as_millis();
1433+
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis();
14351434

14361435
// write out one UtxoTransferEntry in a json file, per output
14371436
let mut wrote_file_cnt = 0usize;
@@ -1461,7 +1460,7 @@ fn process_utxo_notifications(
14611460
let file_path = file_dir.join(&file_name);
14621461
println!("creating file: {}", file_path.display());
14631462
let file = std::fs::File::create_new(&file_path)?;
1464-
let mut writer = std::io::BufWriter::new(file);
1463+
let mut writer = io::BufWriter::new(file);
14651464
serde_json::to_writer_pretty(&mut writer, &entry)?;
14661465
writer.flush()?;
14671466

@@ -1491,13 +1490,20 @@ or use equivalent claim functionality of your chosen wallet software.
14911490
}
14921491

14931492
fn enter_seed_phrase_dialog() -> Result<SecretKeyMaterial> {
1493+
let mnemonic_length_list = [18, 24];
1494+
let selection = Select::with_theme(&ColorfulTheme::default())
1495+
.with_prompt("Choose your mnemonic length")
1496+
.default(0)
1497+
.items(mnemonic_length_list)
1498+
.interact()?;
1499+
let mnemonic_length = mnemonic_length_list[selection];
14941500
let mut phrase = vec![];
14951501
let mut i = 1;
14961502
loop {
14971503
print!("{i}. ");
1498-
io::stdout().flush()?;
1504+
stdout().flush()?;
14991505
let mut buffer = "".to_string();
1500-
std::io::stdin()
1506+
io::stdin()
15011507
.read_line(&mut buffer)
15021508
.expect("Cannot accept user input.");
15031509
let word = buffer.trim();
@@ -1508,7 +1514,7 @@ fn enter_seed_phrase_dialog() -> Result<SecretKeyMaterial> {
15081514
{
15091515
phrase.push(word.to_string());
15101516
i += 1;
1511-
if i > 18 {
1517+
if i > mnemonic_length {
15121518
break;
15131519
}
15141520
} else {

neptune-core/src/state/wallet/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ mod tests {
3535
use tasm_lib::prelude::Digest;
3636
use tasm_lib::prelude::Tip5;
3737
use tasm_lib::triton_vm::prelude::BFieldElement;
38-
use tasm_lib::triton_vm::prelude::XFieldElement;
39-
use tasm_lib::twenty_first::math::x_field_element::EXTENSION_DEGREE;
4038
use tracing_test::traced_test;
4139
use unlocked_utxo::UnlockedUtxo;
4240

@@ -61,6 +59,7 @@ mod tests {
6159
use crate::state::transaction::tx_creation_config::TxCreationConfig;
6260
use crate::state::transaction::tx_proving_capability::TxProvingCapability;
6361
use crate::state::wallet::expected_utxo::UtxoNotifier;
62+
use crate::state::wallet::secret_key_material::BField32Bytes;
6463
use crate::state::wallet::secret_key_material::SecretKeyMaterial;
6564
use crate::state::wallet::transaction_output::TxOutput;
6665
use crate::state::wallet::transaction_output::TxOutputList;
@@ -1151,18 +1150,18 @@ mod tests {
11511150
proptest::proptest! {
11521151
#[test]
11531152
fn master_seed_is_not_sender_randomness(
1154-
secret in proptest_arbitrary_interop::arb::<XFieldElement>()
1153+
secret in proptest_arbitrary_interop::arb::<BField32Bytes>()
11551154
) {
11561155
let secret_as_digest = Digest::new(
11571156
[
1158-
secret.coefficients.to_vec(),
1159-
vec![BFieldElement::new(0); Digest::LEN - EXTENSION_DEGREE],
1157+
secret.0.to_vec(),
1158+
vec![BFieldElement::new(0); Digest::LEN - 4],
11601159
]
11611160
.concat()
11621161
.try_into()
11631162
.unwrap(),
11641163
);
1165-
let wallet = WalletEntropy::new(SecretKeyMaterial(secret));
1164+
let wallet = WalletEntropy::new(SecretKeyMaterial::V1(secret));
11661165
assert_ne!(
11671166
wallet.generate_sender_randomness(BlockHeight::genesis(), random()),
11681167
secret_as_digest

0 commit comments

Comments
 (0)