remove keys related functions in cashierdb and remove keys table from cashierdb's schema. cashier no longer handle private and public keys

This commit is contained in:
ghassmo
2021-09-08 01:30:00 +03:00
parent 4fe2138dfd
commit 4f0ab6e569
3 changed files with 7 additions and 74 deletions

View File

@@ -1,8 +1,3 @@
CREATE TABLE IF NOT EXISTS keys(
key_id INTEGER PRIMARY KEY NOT NULL,
key_public BLOB NOT NULL,
key_private BLOB NOT NULL
);
CREATE TABLE IF NOT EXISTS keypairs(
dkey_id INTEGER PRIMARY KEY NOT NULL,
btc_key_private BLOB NOT NULL,

View File

@@ -3,7 +3,6 @@ use super::reqrep::{PeerId, RepProtocol, Reply, ReqProtocol, Request};
use crate::blockchain::Rocks;
use crate::client::Client;
use crate::serial::{deserialize, serialize};
use crate::wallet::WalletApi;
use crate::wallet::{CashierDbPtr, WalletPtr};
use crate::{Error, Result};
@@ -54,10 +53,6 @@ impl CashierService {
let rocks = Rocks::new(&cashier_database_path)?;
if wallet.get_private_keys()?.is_empty() {
wallet.key_gen()?;
}
let client = Client::new(rocks, gateway_addrs, params_paths, client_wallet.clone())?;
let client = Arc::new(Mutex::new(client));

View File

@@ -1,14 +1,12 @@
use super::WalletApi;
use crate::client::ClientFailed;
use crate::serial;
use crate::service::btc::{PrivKey, PubKey};
use crate::{Error, Result};
use async_std::sync::Arc;
use ff::Field;
use log::*;
use rand::rngs::OsRng;
use rusqlite::{named_params, params, Connection};
use rusqlite::{named_params, Connection};
use std::path::PathBuf;
@@ -51,55 +49,6 @@ impl CashierDb {
Ok(())
}
pub fn key_gen(&self) -> Result<(Vec<u8>, Vec<u8>)> {
debug!(target: "CASHIERDB", "Generating cashier keys...");
let secret: jubjub::Fr = jubjub::Fr::random(&mut OsRng);
let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
let pubkey = serial::serialize(&public);
let privkey = serial::serialize(&secret);
self.put_keypair(pubkey.clone(), privkey.clone())?;
Ok((pubkey, privkey))
}
pub fn put_keypair(&self, key_public: Vec<u8>, key_private: Vec<u8>) -> Result<()> {
let conn = Connection::open(&self.path)?;
conn.pragma_update(None, "key", &self.password)?;
conn.execute(
"INSERT INTO keys(key_public, key_private) VALUES (?1, ?2)",
params![key_public, key_private],
)?;
Ok(())
}
pub fn get_public_keys(&self) -> Result<Vec<jubjub::SubgroupPoint>> {
debug!(target: "CASHIERDB", "Returning keys...");
let conn = Connection::open(&self.path)?;
conn.pragma_update(None, "key", &self.password)?;
let mut stmt = conn.prepare("SELECT key_public FROM keys")?;
let key_iter = stmt.query_map::<Vec<u8>, _, _>([], |row| row.get(0))?;
let mut pub_keys = Vec::new();
for key in key_iter {
let public: jubjub::SubgroupPoint =
self.get_value_deserialized::<jubjub::SubgroupPoint>(key?)?;
pub_keys.push(public);
}
Ok(pub_keys)
}
pub fn get_private_keys(&self) -> Result<Vec<jubjub::Fr>> {
debug!(target: "CASHIERDB", "Returning keys...");
let conn = Connection::open(&self.path)?;
conn.pragma_update(None, "key", &self.password)?;
let mut stmt = conn.prepare("SELECT key_private FROM keys")?;
let key_iter = stmt.query_map::<Vec<u8>, _, _>([], |row| row.get(0))?;
let mut keys = Vec::new();
for key in key_iter {
let private: jubjub::Fr = self.get_value_deserialized(key?)?;
keys.push(private);
}
Ok(keys)
}
pub fn get_keys_by_dkey(&self, dkey_pub: &Vec<u8>) -> Result<()> {
debug!(target: "CASHIERDB", "Check for existing dkey");
//let dkey_id = self.get_value_deserialized(dkey_pub)?;
@@ -208,22 +157,18 @@ impl CashierDb {
)?;
Ok(())
}
pub fn test_wallet(&self) -> Result<()> {
let conn = Connection::open(&self.path)?;
conn.pragma_update(None, "key", &self.password)?;
let mut stmt = conn.prepare("SELECT * FROM keys")?;
let _rows = stmt.query([])?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::util::join_config_path;
use crate::serial::serialize;
use crate::util::join_config_path;
use crate::serial;
use ff::Field;
use rand::rngs::OsRng;
#[test]
pub fn test_put_withdraw_keys_and_load_them_with_btc_key() -> Result<()> {
@@ -231,8 +176,6 @@ mod tests {
let wallet = CashierDb::new(&walletdb_path, "darkfi".into())?;
wallet.init_db()?;
wallet.key_gen()?;
let secret2: jubjub::Fr = jubjub::Fr::random(&mut OsRng);
let public2 = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret2;
let key_public2 = serial::serialize(&public2);