sign doing regular signing
This commit is contained in:
parent
a2fa178c16
commit
72a62849e1
|
@ -23,12 +23,13 @@ required-features = ["dotenv"]
|
||||||
#name = "ledger"
|
#name = "ledger"
|
||||||
#path = "src/main/ledger.rs"
|
#path = "src/main/ledger.rs"
|
||||||
|
|
||||||
#[[bin]]
|
[[bin]]
|
||||||
#name = "sign"
|
name = "sign"
|
||||||
#path = "src/main/sign.rs"
|
path = "src/main/sign.rs"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "warp_api_ffi"
|
name = "warp_api_ffi"
|
||||||
|
# cdylib
|
||||||
crate-type = ["rlib"]
|
crate-type = ["rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
127
src/main/sign.rs
127
src/main/sign.rs
|
@ -1,65 +1,86 @@
|
||||||
use clap::{Arg, Command};
|
// use clap::{Arg, Command};
|
||||||
use std::fs::File;
|
// use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
// use std::io::{Read, Write};
|
||||||
use std::str::FromStr;
|
// use std::str::FromStr;
|
||||||
use sync::{KeyHelpers, Tx};
|
// use sync::{KeyHelpers, Tx};
|
||||||
use zcash_client_backend::encoding::decode_extended_spending_key;
|
// 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 warp_api_ffi::TransactionPlan;
|
||||||
use zcash_params::coin::CoinType;
|
use zcash_params::coin::CoinType;
|
||||||
use zcash_primitives::consensus::{Network, Parameters};
|
|
||||||
use zcash_proofs::prover::LocalTxProver;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async 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 coin = matches.value_of("coin").expect("coin argument missing");
|
let tx_plan = fs::read_to_string("tx.json").expect("Should have been able to read the file");
|
||||||
let tx_filename = matches
|
let coin = 0;
|
||||||
.value_of("tx_filename")
|
let account = 1;
|
||||||
.expect("input filename missing");
|
|
||||||
let out_filename = matches
|
|
||||||
.value_of("out_filename")
|
|
||||||
.expect("output filename missing");
|
|
||||||
|
|
||||||
let (coin_type, network) = match coin {
|
let res = async {
|
||||||
"zcash" => (CoinType::Zcash, Network::MainNetwork),
|
warp_api_ffi::init_coin(coin, "/home/conrado/databases/zec.db").unwrap();
|
||||||
"ycash" => (CoinType::Ycash, Network::YCashMainNetwork),
|
let tx_plan: TransactionPlan = serde_json::from_str(&tx_plan)?;
|
||||||
_ => panic!("Invalid coin"),
|
let raw_tx = warp_api_ffi::api::payment_v2::sign_plan(coin, account, &tx_plan)?;
|
||||||
|
let tx_str = base64::encode(&raw_tx);
|
||||||
|
Ok::<_, anyhow::Error>(tx_str)
|
||||||
};
|
};
|
||||||
let key = dotenv::var("KEY").unwrap();
|
let res = res.await.unwrap();
|
||||||
let index = u32::from_str(&dotenv::var("INDEX").unwrap_or_else(|_| "0".to_string())).unwrap();
|
println!("{}", res);
|
||||||
let kh = KeyHelpers::new(coin_type);
|
|
||||||
let (_seed, sk, _ivk, _address) = kh.decode_key(&key, index)?;
|
|
||||||
|
|
||||||
let sk = sk.unwrap();
|
// let matches = Command::new("Cold wallet Signer CLI")
|
||||||
let sk =
|
// .version("1.0")
|
||||||
decode_extended_spending_key(network.hrp_sapling_extended_spending_key(), &sk)?.unwrap();
|
// .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 mut file = File::open(tx_filename)?;
|
// let coin = matches.value_of("coin").expect("coin argument missing");
|
||||||
let mut s = String::new();
|
// let tx_filename = matches
|
||||||
file.read_to_string(&mut s).unwrap();
|
// .value_of("tx_filename")
|
||||||
let tx: Tx = serde_json::from_str(&s)?;
|
// .expect("input filename missing");
|
||||||
let prover = LocalTxProver::with_default_location()
|
// let out_filename = matches
|
||||||
.ok_or_else(|| anyhow::anyhow!("Cannot create prover. Missing zcash-params?"))?;
|
// .value_of("out_filename")
|
||||||
let raw_tx = tx.sign(None, &sk, &prover, |p| {
|
// .expect("output filename missing");
|
||||||
println!("Progress {}", p.cur());
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut out_file = File::create(out_filename)?;
|
// let (coin_type, network) = match coin {
|
||||||
writeln!(out_file, "{}", hex::encode(&raw_tx))?;
|
// "zcash" => (CoinType::Zcash, Network::MainNetwork),
|
||||||
|
// "ycash" => (CoinType::Ycash, Network::YCashMainNetwork),
|
||||||
|
// _ => 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 sk =
|
||||||
|
// decode_extended_spending_key(network.hrp_sapling_extended_spending_key(), &sk)?.unwrap();
|
||||||
|
|
||||||
|
// let mut file = File::open(tx_filename)?;
|
||||||
|
// let mut s = String::new();
|
||||||
|
// 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)?;
|
||||||
|
// writeln!(out_file, "{}", hex::encode(&raw_tx))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue