restore standalone offline signer
This commit is contained in:
parent
72a62849e1
commit
c36c311c01
|
@ -26,6 +26,7 @@ required-features = ["dotenv"]
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "sign"
|
name = "sign"
|
||||||
path = "src/main/sign.rs"
|
path = "src/main/sign.rs"
|
||||||
|
required-features = ["dotenv"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "warp_api_ffi"
|
name = "warp_api_ffi"
|
||||||
|
|
|
@ -80,19 +80,19 @@ mod contact;
|
||||||
mod db;
|
mod db;
|
||||||
mod fountain;
|
mod fountain;
|
||||||
mod hash;
|
mod hash;
|
||||||
mod orchard;
|
pub mod orchard;
|
||||||
mod sapling;
|
mod sapling;
|
||||||
mod sync;
|
mod sync;
|
||||||
// mod key;
|
// mod key;
|
||||||
mod key2;
|
pub mod key2;
|
||||||
mod mempool;
|
mod mempool;
|
||||||
mod misc;
|
mod misc;
|
||||||
mod pay;
|
mod pay;
|
||||||
mod prices;
|
mod prices;
|
||||||
// mod print;
|
// mod print;
|
||||||
mod note_selection;
|
pub mod note_selection;
|
||||||
mod scan;
|
mod scan;
|
||||||
mod taddr;
|
pub mod taddr;
|
||||||
mod transaction;
|
mod transaction;
|
||||||
mod unified;
|
mod unified;
|
||||||
// mod ua;
|
// mod ua;
|
||||||
|
|
151
src/main/sign.rs
151
src/main/sign.rs
|
@ -1,86 +1,95 @@
|
||||||
// use clap::{Arg, Command};
|
|
||||||
// use std::fs::File;
|
|
||||||
// use std::io::{Read, Write};
|
|
||||||
// use std::str::FromStr;
|
|
||||||
// use sync::{KeyHelpers, Tx};
|
|
||||||
// use zcash_client_backend::encoding::decode_extended_spending_key;
|
|
||||||
// use zcash_params::coin::CoinType;
|
|
||||||
// use zcash_primitives::consensus::{Network, Parameters};
|
|
||||||
// use zcash_proofs::prover::LocalTxProver;
|
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use warp_api_ffi::TransactionPlan;
|
use clap::{Arg, Command};
|
||||||
use zcash_params::coin::CoinType;
|
use orchard::keys::SpendingKey;
|
||||||
|
use rand_chacha::rand_core::OsRng;
|
||||||
|
use secp256k1::SecretKey;
|
||||||
|
use warp_api_ffi::note_selection::SecretKeys;
|
||||||
|
use warp_api_ffi::orchard::derive_orchard_keys;
|
||||||
|
use warp_api_ffi::{build_tx, TransactionPlan};
|
||||||
|
use warp_api_ffi::{key2::decode_key, taddr::derive_tkeys};
|
||||||
|
use zcash_client_backend::encoding::{
|
||||||
|
decode_extended_full_viewing_key, decode_extended_spending_key,
|
||||||
|
};
|
||||||
|
use zcash_params::coin::{get_coin_id, CoinType};
|
||||||
|
use zcash_primitives::consensus::{Network, Parameters};
|
||||||
|
|
||||||
#[tokio::main]
|
fn main() -> anyhow::Result<()> {
|
||||||
async fn main() -> anyhow::Result<()> {
|
let matches = Command::new("Cold wallet Signer CLI")
|
||||||
println!("Hello world!");
|
.version("1.0")
|
||||||
|
.arg(Arg::new("coin").short('c').long("coin").takes_value(true))
|
||||||
|
.arg(
|
||||||
|
Arg::new("tx_filename")
|
||||||
|
.short('t')
|
||||||
|
.long("tx")
|
||||||
|
.takes_value(true),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("out_filename")
|
||||||
|
.short('o')
|
||||||
|
.long("out")
|
||||||
|
.takes_value(true),
|
||||||
|
)
|
||||||
|
.get_matches();
|
||||||
|
|
||||||
let tx_plan = fs::read_to_string("tx.json").expect("Should have been able to read the file");
|
let coin = matches.value_of("coin").expect("coin argument missing");
|
||||||
let coin = 0;
|
let tx_filename = matches
|
||||||
let account = 1;
|
.value_of("tx_filename")
|
||||||
|
.expect("input filename missing");
|
||||||
|
let out_filename = matches
|
||||||
|
.value_of("out_filename")
|
||||||
|
.expect("output filename missing");
|
||||||
|
|
||||||
let res = async {
|
let tx_plan = fs::read_to_string(tx_filename).expect("Should have been able to read the file");
|
||||||
warp_api_ffi::init_coin(coin, "/home/conrado/databases/zec.db").unwrap();
|
|
||||||
let tx_plan: TransactionPlan = serde_json::from_str(&tx_plan)?;
|
let tx_plan: TransactionPlan = serde_json::from_str(&tx_plan)?;
|
||||||
let raw_tx = warp_api_ffi::api::payment_v2::sign_plan(coin, account, &tx_plan)?;
|
|
||||||
let tx_str = base64::encode(&raw_tx);
|
let (coin_type, network) = match coin {
|
||||||
Ok::<_, anyhow::Error>(tx_str)
|
"zcash" => (CoinType::Zcash, Network::MainNetwork),
|
||||||
|
"ycash" => (CoinType::Ycash, Network::YCashMainNetwork),
|
||||||
|
_ => panic!("Invalid coin"),
|
||||||
};
|
};
|
||||||
let res = res.await.unwrap();
|
let key = dotenv::var("KEY").unwrap();
|
||||||
println!("{}", res);
|
let index = u32::from_str(&dotenv::var("INDEX").unwrap_or_else(|_| "0".to_string())).unwrap();
|
||||||
|
let coin = get_coin_id(coin_type);
|
||||||
|
let (seed, sk, fvk, _pa, _ofvk) = decode_key(coin, &key, index)?;
|
||||||
|
let seed = seed.unwrap();
|
||||||
|
|
||||||
// let matches = Command::new("Cold wallet Signer CLI")
|
let fvk =
|
||||||
// .version("1.0")
|
decode_extended_full_viewing_key(network.hrp_sapling_extended_full_viewing_key(), &fvk)
|
||||||
// .arg(Arg::new("coin").short('c').long("coin").takes_value(true))
|
.unwrap()
|
||||||
// .arg(
|
.to_diversifiable_full_viewing_key();
|
||||||
// Arg::new("tx_filename")
|
let tx_plan_fvk = decode_extended_full_viewing_key(
|
||||||
// .short('t')
|
network.hrp_sapling_extended_full_viewing_key(),
|
||||||
// .long("tx")
|
&tx_plan.fvk,
|
||||||
// .takes_value(true),
|
)
|
||||||
// )
|
.unwrap()
|
||||||
// .arg(
|
.to_diversifiable_full_viewing_key();
|
||||||
// Arg::new("out_filename")
|
|
||||||
// .short('o')
|
|
||||||
// .long("out")
|
|
||||||
// .takes_value(true),
|
|
||||||
// )
|
|
||||||
// .get_matches();
|
|
||||||
|
|
||||||
// let coin = matches.value_of("coin").expect("coin argument missing");
|
if fvk.to_bytes() != tx_plan_fvk.to_bytes() {
|
||||||
// let tx_filename = matches
|
return Err(anyhow::anyhow!("Account does not match transaction"));
|
||||||
// .value_of("tx_filename")
|
}
|
||||||
// .expect("input filename missing");
|
|
||||||
// let out_filename = matches
|
|
||||||
// .value_of("out_filename")
|
|
||||||
// .expect("output filename missing");
|
|
||||||
|
|
||||||
// let (coin_type, network) = match coin {
|
let bip44_path = format!("m/44'/{}'/0'/0/{}", network.coin_type(), index);
|
||||||
// "zcash" => (CoinType::Zcash, Network::MainNetwork),
|
let (tsk, _address) = derive_tkeys(&network, &seed, &bip44_path)?;
|
||||||
// "ycash" => (CoinType::Ycash, Network::YCashMainNetwork),
|
let transparent_sk = SecretKey::from_str(&tsk).unwrap();
|
||||||
// _ => panic!("Invalid coin"),
|
|
||||||
// };
|
|
||||||
// let key = dotenv::var("KEY").unwrap();
|
|
||||||
// let index = u32::from_str(&dotenv::var("INDEX").unwrap_or_else(|_| "0".to_string())).unwrap();
|
|
||||||
// let kh = KeyHelpers::new(coin_type);
|
|
||||||
// let (_seed, sk, _ivk, _address) = kh.decode_key(&key, index)?;
|
|
||||||
|
|
||||||
// let sk = sk.unwrap();
|
let sapling_sk = sk.unwrap();
|
||||||
// let sk =
|
let sapling_sk =
|
||||||
// decode_extended_spending_key(network.hrp_sapling_extended_spending_key(), &sk)?.unwrap();
|
decode_extended_spending_key(network.hrp_sapling_extended_spending_key(), &sapling_sk)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// let mut file = File::open(tx_filename)?;
|
let ob = derive_orchard_keys(network.coin_type(), &seed, index);
|
||||||
// let mut s = String::new();
|
let orchard_sk = ob.sk.map(|sk| SpendingKey::from_bytes(sk).unwrap());
|
||||||
// file.read_to_string(&mut s).unwrap();
|
|
||||||
// let tx: Tx = serde_json::from_str(&s)?;
|
|
||||||
// let prover = LocalTxProver::with_default_location()
|
|
||||||
// .ok_or_else(|| anyhow::anyhow!("Cannot create prover. Missing zcash-params?"))?;
|
|
||||||
// let raw_tx = tx.sign(None, &sk, &prover, |p| {
|
|
||||||
// println!("Progress {}", p.cur());
|
|
||||||
// })?;
|
|
||||||
|
|
||||||
// let mut out_file = File::create(out_filename)?;
|
let keys = SecretKeys {
|
||||||
// writeln!(out_file, "{}", hex::encode(&raw_tx))?;
|
transparent: Some(transparent_sk),
|
||||||
|
sapling: Some(sapling_sk),
|
||||||
|
orchard: orchard_sk,
|
||||||
|
};
|
||||||
|
|
||||||
|
let tx = build_tx(&network, &keys, &tx_plan, OsRng)?;
|
||||||
|
|
||||||
|
fs::write(out_filename, hex::encode(&tx))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue