fix: seed generation from mnemonic

This commit is contained in:
Oleksandr Pravdyvyi 2025-09-04 17:49:55 +03:00
parent e07733e5c3
commit ebe616247f
No known key found for this signature in database
GPG Key ID: 9F8955C63C443871
3 changed files with 10 additions and 3 deletions

View File

@ -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",

View File

@ -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"

View File

@ -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(),
}
}