mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-04 06:13:10 +00:00
feat: stat of deterministic passwords
This commit is contained in:
parent
f593e6be94
commit
9788f189b1
@ -39,6 +39,25 @@ impl KeyChain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_mnemonic(passphrase: String) -> Self {
|
||||||
|
//Currently dropping SeedHolder at the end of initialization.
|
||||||
|
//Now entirely sure if we need it in the future.
|
||||||
|
let seed_holder = SeedHolder::new_mnemonic(passphrase);
|
||||||
|
let secret_spending_key = seed_holder.produce_top_secret_key_holder();
|
||||||
|
|
||||||
|
let private_key_holder = secret_spending_key.produce_private_key_holder();
|
||||||
|
|
||||||
|
let nullifer_public_key = private_key_holder.generate_nullifier_public_key();
|
||||||
|
let incoming_viewing_public_key = private_key_holder.generate_incoming_viewing_public_key();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
secret_spending_key,
|
||||||
|
private_key_holder,
|
||||||
|
nullifer_public_key,
|
||||||
|
incoming_viewing_public_key,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn calculate_shared_secret_receiver(
|
pub fn calculate_shared_secret_receiver(
|
||||||
&self,
|
&self,
|
||||||
ephemeral_public_key_sender: EphemeralPublicKey,
|
ephemeral_public_key_sender: EphemeralPublicKey,
|
||||||
|
|||||||
@ -44,6 +44,18 @@ impl SeedHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_mnemonic(passphrase: String) -> Self {
|
||||||
|
let mut enthopy_bytes: [u8; 32] = [0; 32];
|
||||||
|
OsRng.fill_bytes(&mut enthopy_bytes);
|
||||||
|
|
||||||
|
let mnemonic = Mnemonic::from_entropy(&enthopy_bytes).unwrap();
|
||||||
|
let seed_wide = mnemonic.to_seed(passphrase);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
seed: seed_wide.to_vec(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate_secret_spending_key_hash(&self) -> HashType {
|
pub fn generate_secret_spending_key_hash(&self) -> HashType {
|
||||||
let mut hash = hmac_sha512::HMAC::mac(&self.seed, "NSSA_seed");
|
let mut hash = hmac_sha512::HMAC::mac(&self.seed, "NSSA_seed");
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,8 @@ pub struct NSSAUserData {
|
|||||||
pub pub_account_signing_keys: HashMap<nssa::Address, nssa::PrivateKey>,
|
pub pub_account_signing_keys: HashMap<nssa::Address, nssa::PrivateKey>,
|
||||||
///Map for all user private accounts
|
///Map for all user private accounts
|
||||||
pub user_private_accounts: HashMap<nssa::Address, (KeyChain, nssa_core::account::Account)>,
|
pub user_private_accounts: HashMap<nssa::Address, (KeyChain, nssa_core::account::Account)>,
|
||||||
|
///Mnemonic passphrase
|
||||||
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NSSAUserData {
|
impl NSSAUserData {
|
||||||
@ -64,6 +66,31 @@ impl NSSAUserData {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
pub_account_signing_keys: accounts_keys,
|
pub_account_signing_keys: accounts_keys,
|
||||||
user_private_accounts: accounts_key_chains,
|
user_private_accounts: accounts_key_chains,
|
||||||
|
password: "mnemonic".to_string(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_with_accounts_and_password(
|
||||||
|
accounts_keys: HashMap<nssa::Address, nssa::PrivateKey>,
|
||||||
|
accounts_key_chains: HashMap<nssa::Address, (KeyChain, nssa_core::account::Account)>,
|
||||||
|
password: String,
|
||||||
|
) -> Result<Self> {
|
||||||
|
if !Self::valid_public_key_transaction_pairing_check(&accounts_keys) {
|
||||||
|
anyhow::bail!(
|
||||||
|
"Key transaction pairing check not satisfied, there is addresses, which is not derived from keys"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !Self::valid_private_key_transaction_pairing_check(&accounts_key_chains) {
|
||||||
|
anyhow::bail!(
|
||||||
|
"Key transaction pairing check not satisfied, there is addresses, which is not derived from keys"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
pub_account_signing_keys: accounts_keys,
|
||||||
|
user_private_accounts: accounts_key_chains,
|
||||||
|
password,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +127,21 @@ impl NSSAUserData {
|
|||||||
address
|
address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generated new private key for privacy preserving transactions
|
||||||
|
///
|
||||||
|
/// Returns the address of new account
|
||||||
|
pub fn generate_new_privacy_preserving_transaction_key_chain_mnemonic(
|
||||||
|
&mut self,
|
||||||
|
) -> nssa::Address {
|
||||||
|
let key_chain = KeyChain::new_mnemonic(self.password.clone());
|
||||||
|
let address = nssa::Address::from(&key_chain.nullifer_public_key);
|
||||||
|
|
||||||
|
self.user_private_accounts
|
||||||
|
.insert(address, (key_chain, nssa_core::account::Account::default()));
|
||||||
|
|
||||||
|
address
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the signing key for public transaction signatures
|
/// Returns the signing key for public transaction signatures
|
||||||
pub fn get_private_account(
|
pub fn get_private_account(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user