From ebe616247f0a63a1b1374861a5292c5c82a06ae1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Thu, 4 Sep 2025 17:49:55 +0300 Subject: [PATCH] fix: seed generation from mnemonic --- Cargo.toml | 1 + key_protocol/Cargo.toml | 1 + key_protocol/src/key_management/secret_holders.rs | 11 ++++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2b98867..5f2ee32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ ark-bn254 = "0.5.0" ark-ff = "0.5.0" tiny-keccak = { version = "2.0.2", features = ["keccak"] } base64 = "0.22.1" +bip39 = "2.2.0" rocksdb = { version = "0.21.0", default-features = false, features = [ "snappy", diff --git a/key_protocol/Cargo.toml b/key_protocol/Cargo.toml index 947bd7a..8b9701a 100644 --- a/key_protocol/Cargo.toml +++ b/key_protocol/Cargo.toml @@ -15,6 +15,7 @@ elliptic-curve.workspace = true hex.workspace = true aes-gcm.workspace = true lazy_static.workspace = true +bip39.workspace = true [dependencies.common] path = "../common" diff --git a/key_protocol/src/key_management/secret_holders.rs b/key_protocol/src/key_management/secret_holders.rs index 47342ec..4fc1a63 100644 --- a/key_protocol/src/key_management/secret_holders.rs +++ b/key_protocol/src/key_management/secret_holders.rs @@ -1,3 +1,4 @@ +use bip39::Mnemonic; use common::merkle_tree_public::TreeHashType; use elliptic_curve::PrimeField; use k256::{AffinePoint, FieldBytes, Scalar}; @@ -29,12 +30,16 @@ pub struct UTXOSecretKeyHolder { impl SeedHolder { pub fn new_os_random() -> Self { - let mut bytes = FieldBytes::default(); + let mut enthopy_bytes: [u8; 32] = [0; 32]; + OsRng.fill_bytes(&mut enthopy_bytes); - OsRng.fill_bytes(&mut bytes); + let mnemonic = Mnemonic::from_entropy(&enthopy_bytes).unwrap(); + let seed = mnemonic.to_seed(""); + + let field_bytes = FieldBytes::from_slice(&seed); Self { - seed: Scalar::from_repr(bytes).unwrap(), + seed: Scalar::from_repr(*field_bytes).unwrap(), } }