Просмотр исходного кода

added cashier and own key generation to tx test

rachel-rose 5 лет назад
Родитель
Сommit
e9475e949c
1 измененных файлов с 49 добавлено и 4 удалено
  1. 49 4
      src/bin/tx-test.rs

+ 49 - 4
src/bin/tx-test.rs

@@ -3,7 +3,7 @@ use log::*;
 use bellman::groth16;
 use rocksdb::DB;
 use std::fs::File;
-use rusqlite::{Statement, MappedRows, Connection};
+use rusqlite::{named_params, Connection};
 use bls12_381::Bls12;
 use ff::{Field, PrimeField};
 use rand::rngs::OsRng;
@@ -156,6 +156,51 @@ impl MemoryState {
         // We weren't able to decrypt the note with any of our keys.
         None
     }
+
+    pub async fn wallet_key(&self) -> Result<()> {
+        let path = dirs::home_dir()
+            .expect("Cannot find home directory.")
+            .as_path()
+            .join(".config/darkfi/wallet.db");
+        let connect = Connection::open(&path).expect("Failed to connect to database.");
+        let id = 0;
+        let secret: jubjub::Fr = jubjub::Fr::random(&mut OsRng);
+        debug!(target: "adapter", "key_gen() [Generating public key...]");
+        let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
+        let pubkey = drk::serial::serialize(&public);
+        let privkey = drk::serial::serialize(&secret);
+        connect.execute(
+            "INSERT INTO keys(key_id, key_private, key_public)
+            VALUES (:id, :privkey, :pubkey)",
+            named_params!{":id": id,
+                           ":privkey": privkey,
+                           ":pubkey": pubkey
+                          }
+        )?;
+        Ok(())
+    }
+
+    pub async fn cashier_key(&self) -> Result<()> {
+        let path = dirs::home_dir()
+            .expect("Cannot find home directory.")
+            .as_path()
+            .join(".config/darkfi/cashier.db");
+        let connect = Connection::open(&path).expect("Failed to connect to database.");
+        let id = 0;
+        let secret: jubjub::Fr = jubjub::Fr::random(&mut OsRng);
+        let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
+        let pubkey = drk::serial::serialize(&public);
+        let privkey = drk::serial::serialize(&secret);
+        connect.execute(
+            "INSERT INTO keys(key_id, key_private, key_public)
+            VALUES (:id, :privkey, :pubkey)",
+            named_params!{":id": id,
+                           ":privkey": privkey,
+                           ":pubkey": pubkey
+                          }
+        )?;
+        Ok(())
+    }
 }
 
 fn main() {
@@ -175,11 +220,11 @@ fn main() {
 
     // Where is cashier private key stored? Does node have its own wallet schema
     // Cashier creates a secret key
-    //let cashier_secret = jubjub::Fr::random(&mut OsRng);
+    let cashier_secret = jubjub::Fr::random(&mut OsRng);
     //// This is their public key
-    //let cashier_public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * cashier_secret;
+    let cashier_public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * cashier_secret;
 
-    let cashier_secret = state.cashier_key();
+    //let cashier_secret = state.cashier_key();
 
     // Wallet 1 creates a secret key
     let secret = jubjub::Fr::random(&mut OsRng);