mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
Update deps (#768)
* build: update grin submodule to last staging * build: update grin submodule * build: remove remove_dir_all dependency * build: update rpassword * build: update semver * build: remove unused deps * build: update ring * build: update lock file deps * build: update rustyline * build: update ed25519-dalek * build: update curve25519-dalek * build: update age * build: update uuid * fix: uuid test * build: update x25519-dalek * fix: x25519-dalek build * build: update arti * build: update grin submodule * build: update hyper * fix: initialize rustls provider for tests * build: update grin submodule * fix: rustls install provider * tor: share getting private key * fix: show an error on node version parse * cli: renamed prompt password method * fix: replace into_boxed_slice with try_from * fix: dalek tests for onion * config: comment expanded secret key * fix: import api body for controller * password: handle prompt error * wallet: parse node error message * tests: do not use random values for sign messages * build: make hook executable * build: cargo format all * rustls: do not install provider at tests and globally * build: update grin submodule * build: fix api channel from grin submodule * args: use read_password for piped prompt * build: remove unused dep * test: fixed signature * preserve piped pw input --------- Co-authored-by: wiesche <wiesche89@googlemail.com>
This commit is contained in:
Regular → Executable
Generated
+769
-1134
File diff suppressed because it is too large
Load Diff
+3
-8
@@ -21,13 +21,12 @@ exclude = ["integration"]
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "2.33", features = ["yaml"] }
|
||||
rpassword = "4.0"
|
||||
rpassword = "7.5.4"
|
||||
thiserror = "1"
|
||||
prettytable-rs = "0.10"
|
||||
log = "0.4"
|
||||
linefeed = "0.6"
|
||||
semver = "0.10"
|
||||
rustyline = "6"
|
||||
semver = "1.0.28"
|
||||
rustyline = "9"
|
||||
lazy_static = "1"
|
||||
|
||||
grin_wallet_api = { path = "./api", version = "5.4.1" }
|
||||
@@ -35,8 +34,6 @@ grin_wallet_impls = { path = "./impls", version = "5.4.1" }
|
||||
grin_wallet_libwallet = { path = "./libwallet", version = "5.4.1" }
|
||||
grin_wallet_controller = { path = "./controller", version = "5.4.1" }
|
||||
grin_wallet_config = { path = "./config", version = "5.4.1" }
|
||||
grin_wallet_util = { path = "./util", version = "5.4.1" }
|
||||
|
||||
|
||||
##### Grin Imports
|
||||
|
||||
@@ -53,7 +50,5 @@ built = { version = "0.8.0", features = ["git2"]}
|
||||
[dev-dependencies]
|
||||
url = "2.1"
|
||||
serde = "1"
|
||||
serde_derive = "1"
|
||||
serde_json = "1"
|
||||
remove_dir_all = "0.7"
|
||||
easy-jsonrpc-mw = "0.5.4"
|
||||
+3
-3
@@ -11,16 +11,16 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||
uuid = { version = "1.23.4", features = ["serde", "v4"] }
|
||||
serde = "1"
|
||||
rand = "0.6"
|
||||
serde_derive = "1"
|
||||
serde_json = "1"
|
||||
easy-jsonrpc-mw = "0.5.4"
|
||||
chrono = { version = "0.4.11", features = ["serde"] }
|
||||
ring = "0.16"
|
||||
ring = "0.17.14"
|
||||
base64 = "0.12"
|
||||
ed25519-dalek = "1.0.0-pre.4"
|
||||
ed25519-dalek = "2"
|
||||
|
||||
grin_wallet_libwallet = { path = "../libwallet", version = "5.4.1" }
|
||||
grin_wallet_config = { path = "../config", version = "5.4.1" }
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
//! Owner API External Definition
|
||||
|
||||
use chrono::prelude::*;
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
use grin_wallet_libwallet::mwixnet::{MixnetReqCreationParams, SwapReq};
|
||||
use grin_wallet_libwallet::RetrieveTxQueryArgs;
|
||||
use uuid::Uuid;
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ use crate::libwallet::slate_versions::ser as dalek_ser;
|
||||
use crate::libwallet::Error;
|
||||
use crate::util::secp::key::{PublicKey, SecretKey};
|
||||
use crate::util::{from_hex, ToHex};
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
|
||||
use base64;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
@@ -16,8 +16,6 @@ serde_derive = "1"
|
||||
toml = "0.5"
|
||||
dirs = "2.0"
|
||||
|
||||
grin_wallet_util = { path = "../util", version = "5.4.1" }
|
||||
|
||||
##### Grin Imports
|
||||
|
||||
grin_core = { path = "../grin/core"}
|
||||
@@ -25,6 +23,4 @@ grin_util = { path = "../grin/util"}
|
||||
|
||||
#####
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "0.6"
|
||||
|
||||
|
||||
+5
-11
@@ -7,24 +7,19 @@ license = "Apache-2.0"
|
||||
repository = "https://github.com/mimblewimble/grin-wallet"
|
||||
keywords = [ "crypto", "grin", "mimblewimble" ]
|
||||
exclude = ["**/*.grin", "**/*.grin2"]
|
||||
#build = "src/build/build.rs"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
futures = "0.3"
|
||||
hyper = "0.14"
|
||||
tokio = { version = "1", features = ["sync"] }
|
||||
hyper = { version = "1.10.1", features = ["full"] }
|
||||
http-body-util = "0.1.3"
|
||||
rand = "0.7"
|
||||
serde = "1"
|
||||
serde_derive = "1"
|
||||
serde_json = "1"
|
||||
log = "0.4"
|
||||
prettytable-rs = "0.10"
|
||||
ring = "0.16"
|
||||
term = "0.6"
|
||||
tokio = { version = "1.52.3", features = ["full"] }
|
||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||
url = "2.1"
|
||||
chrono = { version = "0.4.11", features = ["serde"] }
|
||||
uuid = { version = "1.23.4", features = ["serde", "v4"] }
|
||||
easy-jsonrpc-mw = "0.5.4"
|
||||
lazy_static = "1"
|
||||
thiserror = "1"
|
||||
@@ -47,5 +42,4 @@ grin_chain = { path = "../grin/chain"}
|
||||
#####
|
||||
|
||||
[dev-dependencies]
|
||||
ed25519-dalek = "1.0.0-pre.4"
|
||||
remove_dir_all = "0.7"
|
||||
ed25519-dalek = "2"
|
||||
@@ -23,17 +23,16 @@ use crate::libwallet::{
|
||||
};
|
||||
use crate::util::secp::key::SecretKey;
|
||||
use crate::util::{from_hex, static_secp_instance, to_base64, Mutex};
|
||||
use futures::channel::oneshot;
|
||||
use grin_wallet_api::JsonId;
|
||||
use grin_wallet_util::OnionV3Address;
|
||||
use hyper::body;
|
||||
use hyper::header::HeaderValue;
|
||||
use hyper::{Body, Request, Response, StatusCode};
|
||||
use hyper::{Request, Response, StatusCode};
|
||||
use qr_code::QrCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::io::Cursor;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -47,8 +46,12 @@ use crate::apiwallet::{
|
||||
};
|
||||
use easy_jsonrpc_mw;
|
||||
use easy_jsonrpc_mw::{Handler, MaybeReply};
|
||||
use grin_api::ApiBody;
|
||||
use grin_wallet_impls::tor::arti::start_tor_service;
|
||||
use grin_wallet_impls::tor::Tor;
|
||||
use http_body_util::{BodyExt, Full};
|
||||
use hyper::body::Incoming;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref GRIN_OWNER_BASIC_REALM: HeaderValue =
|
||||
@@ -155,9 +158,9 @@ where
|
||||
let wallet = match wallet {
|
||||
Some(w) => w,
|
||||
None => {
|
||||
return Err(Error::GenericError(format!(
|
||||
"Instantiated wallet or Owner API context must be provided"
|
||||
)))
|
||||
return Err(Error::GenericError(
|
||||
"Instantiated wallet or Owner API context must be provided".to_string(),
|
||||
))
|
||||
}
|
||||
};
|
||||
f(&mut Owner::new(wallet, None), keychain_mask)?
|
||||
@@ -244,8 +247,7 @@ where
|
||||
.map_err(|_| Error::GenericError("Router failed to add route".to_string()))?;
|
||||
}
|
||||
|
||||
let api_chan: &'static mut (oneshot::Sender<()>, oneshot::Receiver<()>) =
|
||||
Box::leak(Box::new(oneshot::channel::<()>()));
|
||||
let api_chan: (mpsc::Sender<()>, mpsc::Receiver<()>) = mpsc::channel::<()>(1);
|
||||
|
||||
let mut apis = ApiServer::new();
|
||||
warn!("Starting HTTP Owner API server at {}.", addr);
|
||||
@@ -303,8 +305,7 @@ where
|
||||
.add_route("/v2/foreign", Arc::new(api_handler_v2))
|
||||
.map_err(|_| Error::GenericError("Router failed to add route".to_string()))?;
|
||||
|
||||
let api_chan: &'static mut (oneshot::Sender<()>, oneshot::Receiver<()>) =
|
||||
Box::leak(Box::new(oneshot::channel::<()>()));
|
||||
let api_chan: (mpsc::Sender<()>, mpsc::Receiver<()>) = mpsc::channel::<()>(1);
|
||||
|
||||
let mut apis = ApiServer::new();
|
||||
warn!("Starting HTTP Foreign listener API server at {}.", addr);
|
||||
@@ -552,8 +553,7 @@ impl OwnerV3Helpers {
|
||||
None
|
||||
};
|
||||
match err_string {
|
||||
Some(s) => {
|
||||
return (
|
||||
Some(s) => (
|
||||
true,
|
||||
serde_json::json!({
|
||||
"jsonrpc": "2.0",
|
||||
@@ -563,8 +563,7 @@ impl OwnerV3Helpers {
|
||||
"code": -32099
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
),
|
||||
None => (false, val.clone()),
|
||||
}
|
||||
}
|
||||
@@ -590,13 +589,13 @@ where
|
||||
wallet,
|
||||
owner_api,
|
||||
shared_key: Arc::new(Mutex::new(None)),
|
||||
keychain_mask: keychain_mask,
|
||||
keychain_mask,
|
||||
running_foreign,
|
||||
}
|
||||
}
|
||||
|
||||
async fn call_api(
|
||||
req: Request<Body>,
|
||||
req: Request<Incoming>,
|
||||
key: Arc<Mutex<Option<SecretKey>>>,
|
||||
mask: Arc<Mutex<Option<SecretKey>>>,
|
||||
running_foreign: bool,
|
||||
@@ -662,12 +661,12 @@ where
|
||||
}
|
||||
|
||||
async fn handle_post_request(
|
||||
req: Request<Body>,
|
||||
req: Request<Incoming>,
|
||||
key: Arc<Mutex<Option<SecretKey>>>,
|
||||
mask: Arc<Mutex<Option<SecretKey>>>,
|
||||
running_foreign: bool,
|
||||
api: Arc<Owner<L, C, K>>,
|
||||
) -> Result<Response<Body>, Error> {
|
||||
) -> Result<Response<ApiBody>, Error> {
|
||||
let res = Self::call_api(req, key, mask, running_foreign, api).await?;
|
||||
Ok(json_response_pretty(&res))
|
||||
}
|
||||
@@ -679,7 +678,7 @@ where
|
||||
C: NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
fn post(&self, req: Request<Body>) -> ResponseFuture {
|
||||
fn post(&self, req: Request<Incoming>) -> ResponseFuture {
|
||||
let key = self.shared_key.clone();
|
||||
let mask = self.keychain_mask.clone();
|
||||
let running_foreign = self.running_foreign;
|
||||
@@ -696,7 +695,7 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
fn options(&self, _req: Request<Body>) -> ResponseFuture {
|
||||
fn options(&self, _req: Request<Incoming>) -> ResponseFuture {
|
||||
Box::pin(async { Ok(create_ok_response("{}")) })
|
||||
}
|
||||
}
|
||||
@@ -739,7 +738,7 @@ where
|
||||
}
|
||||
|
||||
async fn call_api(
|
||||
req: Request<Body>,
|
||||
req: Request<Incoming>,
|
||||
api: Foreign<'static, L, C, K>,
|
||||
) -> Result<serde_json::Value, Error> {
|
||||
let val: serde_json::Value = parse_body(req).await?;
|
||||
@@ -754,12 +753,12 @@ where
|
||||
}
|
||||
|
||||
async fn handle_post_request(
|
||||
req: Request<Body>,
|
||||
req: Request<Incoming>,
|
||||
mask: Option<SecretKey>,
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
test_mode: bool,
|
||||
tor_config: Option<TorConfig>,
|
||||
) -> Result<Response<Body>, Error> {
|
||||
) -> Result<Response<ApiBody>, Error> {
|
||||
let api = Foreign::new(wallet, mask, Some(check_middleware), test_mode);
|
||||
api.set_tor_config(tor_config);
|
||||
let res = Self::call_api(req, api).await?;
|
||||
@@ -773,7 +772,7 @@ where
|
||||
C: NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
fn post(&self, req: Request<Body>) -> ResponseFuture {
|
||||
fn post(&self, req: Request<Incoming>) -> ResponseFuture {
|
||||
let mask = self.keychain_mask.lock().clone();
|
||||
let wallet = self.wallet.clone();
|
||||
let test_mode = self.test_mode;
|
||||
@@ -790,35 +789,24 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
fn options(&self, _req: Request<Body>) -> ResponseFuture {
|
||||
fn options(&self, _req: Request<Incoming>) -> ResponseFuture {
|
||||
Box::pin(async { Ok(create_ok_response("{}")) })
|
||||
}
|
||||
}
|
||||
|
||||
// Utility to serialize a struct into JSON and produce a sensible Response
|
||||
// out of it.
|
||||
fn _json_response<T>(s: &T) -> Response<Body>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
match serde_json::to_string(s) {
|
||||
Ok(json) => response(StatusCode::OK, json),
|
||||
Err(_) => response(StatusCode::INTERNAL_SERVER_ERROR, ""),
|
||||
}
|
||||
}
|
||||
|
||||
// pretty-printed version of above
|
||||
fn json_response_pretty<T>(s: &T) -> Response<Body>
|
||||
/// Utility to serialize a struct into JSON and produce a sensible Response
|
||||
/// out of it.
|
||||
fn json_response_pretty<T>(s: &T) -> Response<ApiBody>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
match serde_json::to_string_pretty(s) {
|
||||
Ok(json) => response(StatusCode::OK, json),
|
||||
Err(_) => response(StatusCode::INTERNAL_SERVER_ERROR, ""),
|
||||
Ok(json) => response(StatusCode::OK, Full::from(json).boxed()),
|
||||
Err(_) => response(StatusCode::INTERNAL_SERVER_ERROR, Full::from("").boxed()),
|
||||
}
|
||||
}
|
||||
|
||||
fn create_error_response(e: Error) -> Response<Body> {
|
||||
fn create_error_response(e: Error) -> Response<ApiBody> {
|
||||
Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.header("access-control-allow-origin", "*")
|
||||
@@ -826,11 +814,11 @@ fn create_error_response(e: Error) -> Response<Body> {
|
||||
"access-control-allow-headers",
|
||||
"Content-Type, Authorization",
|
||||
)
|
||||
.body(format!("{}", e).into())
|
||||
.body(Full::from(format!("{}", e)).boxed())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn create_ok_response(json: &str) -> Response<Body> {
|
||||
fn create_ok_response(json: &str) -> Response<ApiBody> {
|
||||
Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header("access-control-allow-origin", "*")
|
||||
@@ -839,7 +827,7 @@ fn create_ok_response(json: &str) -> Response<Body> {
|
||||
"Content-Type, Authorization",
|
||||
)
|
||||
.header(hyper::header::CONTENT_TYPE, "application/json")
|
||||
.body(json.to_string().into())
|
||||
.body(Full::from(json.to_string()).boxed())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
@@ -847,7 +835,7 @@ fn create_ok_response(json: &str) -> Response<Body> {
|
||||
///
|
||||
/// Whenever the status code is `StatusCode::OK` the text parameter should be
|
||||
/// valid JSON as the content type header will be set to `application/json'
|
||||
fn response<T: Into<Body>>(status: StatusCode, text: T) -> Response<Body> {
|
||||
fn response<T: Into<ApiBody>>(status: StatusCode, text: T) -> Response<ApiBody> {
|
||||
let mut builder = Response::builder()
|
||||
.status(status)
|
||||
.header("access-control-allow-origin", "*")
|
||||
@@ -863,14 +851,18 @@ fn response<T: Into<Body>>(status: StatusCode, text: T) -> Response<Body> {
|
||||
builder.body(text.into()).unwrap()
|
||||
}
|
||||
|
||||
async fn parse_body<T>(req: Request<Body>) -> Result<T, Error>
|
||||
async fn parse_body<T>(req: Request<Incoming>) -> Result<T, Error>
|
||||
where
|
||||
for<'de> T: Deserialize<'de> + Send + 'static,
|
||||
{
|
||||
let body = body::to_bytes(req.into_body())
|
||||
let body_req = req
|
||||
.into_body()
|
||||
.collect()
|
||||
.await
|
||||
.map_err(|_| Error::GenericError("Failed to read request".to_string()))?;
|
||||
.map_err(|e| Error::GenericError(format!("Failed to read request: {}", e)))?;
|
||||
let raw = body_req.to_bytes();
|
||||
|
||||
serde_json::from_reader(&body[..])
|
||||
let cursor = Cursor::new(raw);
|
||||
serde_json::from_reader(cursor)
|
||||
.map_err(|e| Error::GenericError(format!("Invalid request body: {}", e)))
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ macro_rules! open_wallet_and_add {
|
||||
pub fn clean_output_dir(test_dir: &str) {
|
||||
let path = std::path::Path::new(test_dir);
|
||||
if path.is_dir() {
|
||||
remove_dir_all::remove_dir_all(test_dir).unwrap();
|
||||
std::fs::remove_dir_all(test_dir).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ use grin_wallet_libwallet::{
|
||||
SlatepackerArgs,
|
||||
};
|
||||
|
||||
use ed25519_dalek::PublicKey as edDalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as edDalekSecretKey;
|
||||
use ed25519_dalek::SigningKey as edDalekSecretKey;
|
||||
use ed25519_dalek::VerifyingKey as edDalekPublicKey;
|
||||
|
||||
#[macro_use]
|
||||
mod common;
|
||||
@@ -149,7 +149,7 @@ fn slatepack_exchange_test_impl(
|
||||
let (recipients_1, dec_key_1, sender_1) = match use_encryption {
|
||||
true => {
|
||||
let mut rec_address = SlatepackAddress::random();
|
||||
let mut sec_key = edDalekSecretKey::from_bytes(&[0u8; 32]).unwrap();
|
||||
let mut sec_key = edDalekSecretKey::from_bytes(&[0u8; 32]);
|
||||
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
|
||||
sec_key = api.get_slatepack_secret_key(m, 0)?;
|
||||
let pub_key = edDalekPublicKey::from(&sec_key);
|
||||
@@ -168,7 +168,7 @@ fn slatepack_exchange_test_impl(
|
||||
let (recipients_2, dec_key_2, sender_2) = match use_encryption {
|
||||
true => {
|
||||
let mut rec_address = SlatepackAddress::random();
|
||||
let mut sec_key = edDalekSecretKey::from_bytes(&[0u8; 32]).unwrap();
|
||||
let mut sec_key = edDalekSecretKey::from_bytes(&[0u8; 32]);
|
||||
wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
|
||||
sec_key = api.get_slatepack_secret_key(m, 0)?;
|
||||
let pub_key = edDalekPublicKey::from(&sec_key);
|
||||
|
||||
+1
-1
Submodule grin updated: 17a768c770...bad44b4e9b
+10
-17
@@ -18,32 +18,29 @@ serde = "1"
|
||||
serde_derive = "1"
|
||||
serde_json = "1"
|
||||
log = "0.4"
|
||||
ring = "0.16"
|
||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||
ring = "0.17.14"
|
||||
chrono = { version = "0.4.11", features = ["serde"] }
|
||||
lazy_static = "1"
|
||||
tokio = { version = "1.52.3", features = ["full"] }
|
||||
reqwest = { version = "0.13.3", features = ["socks"] }
|
||||
|
||||
#Socks/Tor/Bridge/Proxy
|
||||
ed25519-dalek = "1.0.0-pre.4"
|
||||
arti-ed25519-dalek = { version = "2.1.1", package = "ed25519-dalek" }
|
||||
ed25519-dalek = "2"
|
||||
regex = "1.3"
|
||||
timer = "0.2"
|
||||
sysinfo = "0.29"
|
||||
base64 = "0.12.0"
|
||||
url = "2.1"
|
||||
|
||||
arti-client = { version = "0.43.0", features = ["static", "pt-client", "onion-service-service", "onion-service-client"] }
|
||||
tor-rtcompat = { version = "0.43.0", features = ["static"] }
|
||||
fs-mistrust = "0.14.2"
|
||||
tor-hsservice = "0.43.0"
|
||||
tor-hsrproxy = "0.43.0"
|
||||
tor-keymgr = "0.43.0"
|
||||
tor-llcrypto = "0.43.0"
|
||||
tor-hscrypto = "0.43.0"
|
||||
arti-client = { version = "0.44.0", features = ["static", "pt-client", "onion-service-service", "onion-service-client"] }
|
||||
tor-rtcompat = { version = "0.44.0", features = ["static"] }
|
||||
fs-mistrust = "0.15.0"
|
||||
tor-hsservice = "0.44.0"
|
||||
tor-hsrproxy = "0.44.0"
|
||||
tor-keymgr = "0.44.0"
|
||||
tor-llcrypto = "0.44.0"
|
||||
tor-hscrypto = "0.44.0"
|
||||
sha2 = "0.10.8"
|
||||
curve25519-dalek = "4.1.3"
|
||||
hyper = { version = "1.10.1", features = ["http1", "client"] }
|
||||
hyper-util = { version = "0.1.20", features = ["tokio"] }
|
||||
http-body-util = "0.1.3"
|
||||
@@ -60,9 +57,5 @@ grin_keychain = { path = "../grin/keychain"}
|
||||
grin_chain = { path = "../grin/chain"}
|
||||
grin_util = { path = "../grin/util"}
|
||||
grin_api = { path = "../grin/api"}
|
||||
grin_store = { path = "../grin/store"}
|
||||
|
||||
#####
|
||||
|
||||
[dev-dependencies]
|
||||
"remove_dir_all" = "0.7"
|
||||
@@ -104,7 +104,7 @@ mod tests {
|
||||
use grin_core::global;
|
||||
|
||||
fn clean_output_dir(test_dir: &str) {
|
||||
let _ = remove_dir_all::remove_dir_all(test_dir);
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
}
|
||||
|
||||
fn setup(test_dir: &str) {
|
||||
|
||||
@@ -12,13 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::tor::config::exp_sec_key_bytes;
|
||||
use crate::tor::{ArtiRuntimeWrapper, Tor};
|
||||
use arti_client::config::pt::TransportConfigBuilder;
|
||||
use arti_client::config::{BridgeConfigBuilder, TorClientConfigBuilder};
|
||||
use arti_client::{TorClient, TorClientConfig};
|
||||
use arti_ed25519_dalek::hazmat::ExpandedSecretKey;
|
||||
use bytes::Bytes;
|
||||
use curve25519_dalek::digest::Digest;
|
||||
use ed25519_dalek::hazmat::ExpandedSecretKey;
|
||||
use ed25519_dalek::Digest;
|
||||
use fs_mistrust::Mistrust;
|
||||
use grin_util::secp::SecretKey;
|
||||
use grin_wallet_config::TorConfig;
|
||||
@@ -402,10 +403,7 @@ fn add_service_key(
|
||||
|
||||
let expanded_sk =
|
||||
ExpandedSecretKey::from_bytes(Sha512::default().chain_update(key).finalize().as_ref());
|
||||
|
||||
let mut sk_bytes = [0_u8; 64];
|
||||
sk_bytes[0..32].copy_from_slice(&expanded_sk.scalar.to_bytes());
|
||||
sk_bytes[32..64].copy_from_slice(&expanded_sk.hash_prefix);
|
||||
let sk_bytes = exp_sec_key_bytes(expanded_sk);
|
||||
match ExpandedKeypair::from_secret_key_bytes(sk_bytes) {
|
||||
None => {
|
||||
return Err(Error::TorProcess(
|
||||
|
||||
+16
-9
@@ -17,9 +17,9 @@ use crate::util::secp::key::SecretKey;
|
||||
use crate::Error;
|
||||
use grin_wallet_util::OnionV3Address;
|
||||
|
||||
use ed25519_dalek::ExpandedSecretKey;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::hazmat::ExpandedSecretKey;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::fs::{self, File};
|
||||
@@ -92,6 +92,14 @@ impl TorRcConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert expanded secret key to byte array (works for both external Tor process and Arti).
|
||||
pub(crate) fn exp_sec_key_bytes(expanded_sk: ExpandedSecretKey) -> [u8; 64] {
|
||||
let mut sk_bytes = [0_u8; 64];
|
||||
sk_bytes[0..32].copy_from_slice(&expanded_sk.scalar.to_bytes());
|
||||
sk_bytes[32..64].copy_from_slice(&expanded_sk.hash_prefix);
|
||||
sk_bytes
|
||||
}
|
||||
|
||||
pub fn create_onion_service_sec_key_file(
|
||||
os_directory: &str,
|
||||
sec_key: &DalekSecretKey,
|
||||
@@ -101,9 +109,9 @@ pub fn create_onion_service_sec_key_file(
|
||||
// Tag is always 32 bytes, so pad with null zeroes
|
||||
file.write(b"== ed25519v1-secret: type0 ==\0\0\0")
|
||||
.map_err(|_| Error::IO)?;
|
||||
let expanded_skey: ExpandedSecretKey = ExpandedSecretKey::from(sec_key);
|
||||
file.write_all(&expanded_skey.to_bytes())
|
||||
.map_err(|_| Error::IO)?;
|
||||
let expanded_skey: ExpandedSecretKey = ExpandedSecretKey::from(sec_key.as_bytes());
|
||||
let sk_bytes = exp_sec_key_bytes(expanded_skey);
|
||||
file.write_all(&sk_bytes).map_err(|_| Error::IO)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -138,8 +146,7 @@ pub fn output_onion_service_config(
|
||||
tor_config_directory: &str,
|
||||
sec_key: &SecretKey,
|
||||
) -> Result<OnionV3Address, Error> {
|
||||
let d_sec_key = DalekSecretKey::from_bytes(&sec_key.0)
|
||||
.map_err(|_| Error::ED25519Key("Unable to parse private key".into()))?;
|
||||
let d_sec_key = DalekSecretKey::from_bytes(&sec_key.0);
|
||||
let address = OnionV3Address::from_private(&sec_key.0)?;
|
||||
let hs_dir_file_path = format!(
|
||||
"{}{}{}{}{}",
|
||||
@@ -291,7 +298,7 @@ mod tests {
|
||||
use crate::util::{self, secp, static_secp_instance};
|
||||
|
||||
pub fn clean_output_dir(test_dir: &str) {
|
||||
let _ = remove_dir_all::remove_dir_all(test_dir);
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
}
|
||||
|
||||
pub fn setup(test_dir: &str) {
|
||||
|
||||
@@ -37,7 +37,7 @@ use std::{fs, thread, time};
|
||||
/// Just removes all results from previous runs
|
||||
pub fn clean_all_output(test_name_dir: &str) {
|
||||
let target_dir = format!("target/tmp/{}", test_name_dir);
|
||||
if let Err(e) = remove_dir_all::remove_dir_all(target_dir) {
|
||||
if let Err(e) = fs::remove_dir_all(target_dir) {
|
||||
println!("can't remove output from previous test :{}, may be ok", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ license = "Apache-2.0"
|
||||
repository = "https://github.com/mimblewimble/grin-wallet"
|
||||
keywords = [ "crypto", "grin", "mimblewimble" ]
|
||||
exclude = ["**/*.grin", "**/*.grin2"]
|
||||
#build = "src/build/build.rs"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -17,21 +16,20 @@ serde = "1"
|
||||
serde_derive = "1"
|
||||
serde_json = "1"
|
||||
log = "0.4"
|
||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||
uuid = { version = "1.23.4", features = ["serde", "v4"] }
|
||||
chrono = { version = "0.4.11", features = ["serde"] }
|
||||
lazy_static = "1"
|
||||
strum = "0.18"
|
||||
strum_macros = "0.18"
|
||||
thiserror = "1"
|
||||
ed25519-dalek = "1.0.0-pre.4"
|
||||
x25519-dalek = "0.6"
|
||||
ed25519-dalek = "2"
|
||||
x25519-dalek = { version = "2", features = ["static_secrets"] }
|
||||
base64 = "0.9"
|
||||
regex = "1.3"
|
||||
sha2 = "0.10.0"
|
||||
bs58 = "0.3"
|
||||
age = "0.7"
|
||||
curve25519-dalek = "2.1"
|
||||
secrecy = "0.6"
|
||||
age = "0.8"
|
||||
curve25519-dalek = "5"
|
||||
bech32 = "0.7"
|
||||
byteorder = "1.3"
|
||||
num-bigint = "0.2"
|
||||
|
||||
@@ -25,7 +25,7 @@ use crate::grin_keychain::ViewKey;
|
||||
use crate::grin_util::secp::{key::SecretKey, pedersen::Commitment};
|
||||
use crate::grin_util::Mutex;
|
||||
use crate::grin_util::ToHex;
|
||||
use crate::util::{OnionV3Address, OnionV3AddressError};
|
||||
use crate::util::OnionV3Address;
|
||||
|
||||
use crate::api_impl::owner_updater::StatusMessage;
|
||||
use crate::grin_keychain::{BlindingFactor, Identifier, Keychain, SwitchCommitmentType};
|
||||
@@ -41,9 +41,9 @@ use crate::{
|
||||
WalletInitStatus, WalletInst, WalletLCProvider,
|
||||
};
|
||||
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
use ed25519_dalek::Verifier;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use x25519_dalek::{PublicKey as xPublicKey, StaticSecret};
|
||||
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
@@ -133,16 +133,7 @@ where
|
||||
let parent_key_id = w.parent_key_id();
|
||||
let k = w.keychain(keychain_mask)?;
|
||||
let sec_addr_key = address::address_from_derivation_path(&k, &parent_key_id, index)?;
|
||||
let d_skey = match DalekSecretKey::from_bytes(&sec_addr_key.0) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(OnionV3AddressError::InvalidPrivateKey(format!(
|
||||
"Unable to create secret key: {}",
|
||||
e
|
||||
))
|
||||
.into());
|
||||
}
|
||||
};
|
||||
let d_skey = DalekSecretKey::from_bytes(&sec_addr_key.0);
|
||||
Ok(d_skey)
|
||||
}
|
||||
|
||||
@@ -1238,12 +1229,7 @@ where
|
||||
|
||||
// for now, simple test whether one of the addresses belongs to this wallet
|
||||
let sec_key = address::address_from_derivation_path(&keychain, &parent_key_id, 0)?;
|
||||
let d_skey = match DalekSecretKey::from_bytes(&sec_key.0) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(Error::ED25519Key(format!("{}", e)));
|
||||
}
|
||||
};
|
||||
let d_skey = DalekSecretKey::from_bytes(&sec_key.0);
|
||||
let my_address_pubkey: DalekPublicKey = (&d_skey).into();
|
||||
|
||||
let sender_mine = my_address_pubkey == sender_pubkey;
|
||||
|
||||
@@ -30,10 +30,9 @@ use crate::types::{Context, NodeClient, StoredProofInfo, TxLogEntryType};
|
||||
use crate::util::OnionV3Address;
|
||||
use crate::{address, Error};
|
||||
use crate::{InitTxArgs, WalletBackend};
|
||||
use ed25519_dalek::Keypair as DalekKeypair;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::Signature as DalekSignature;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use ed25519_dalek::{Signer, Verifier};
|
||||
use grin_core::core::FeeFields;
|
||||
|
||||
@@ -480,18 +479,8 @@ pub fn create_payment_proof_signature(
|
||||
sec_key: SecretKey,
|
||||
) -> Result<DalekSignature, Error> {
|
||||
let msg = payment_proof_message(amount, kernel_commitment, sender_address)?;
|
||||
let d_skey = match DalekSecretKey::from_bytes(&sec_key.0) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(Error::ED25519Key(format!("{}", e)));
|
||||
}
|
||||
};
|
||||
let pub_key: DalekPublicKey = (&d_skey).into();
|
||||
let keypair = DalekKeypair {
|
||||
public: pub_key,
|
||||
secret: d_skey,
|
||||
};
|
||||
Ok(keypair.sign(&msg))
|
||||
let d_skey = DalekSecretKey::from_bytes(&sec_key.0);
|
||||
Ok(d_skey.sign(&msg))
|
||||
}
|
||||
|
||||
/// Verify all aspects of a completed payment proof on the current slate
|
||||
@@ -630,7 +619,7 @@ mod test {
|
||||
let secp = secp_inst.lock();
|
||||
let mut test_rng = StepRng::new(1_234_567_890_u64, 1);
|
||||
let sec_key = secp::key::SecretKey::new(&secp, &mut test_rng);
|
||||
let d_skey = DalekSecretKey::from_bytes(&sec_key.0).unwrap();
|
||||
let d_skey = DalekSecretKey::from_bytes(&sec_key.0);
|
||||
|
||||
let address: DalekPublicKey = (&d_skey).into();
|
||||
|
||||
|
||||
@@ -204,7 +204,6 @@ mod tests {
|
||||
use super::{ComSigError, ComSignature, ContextFlag, Secp256k1, SecretKey};
|
||||
|
||||
use grin_util::secp::rand::{thread_rng, RngCore};
|
||||
use rand::Rng;
|
||||
|
||||
/// Test signing and verification of ComSignatures
|
||||
#[test]
|
||||
@@ -213,13 +212,13 @@ mod tests {
|
||||
|
||||
let amount = thread_rng().next_u64();
|
||||
let blind = SecretKey::new(&secp, &mut thread_rng());
|
||||
let msg: [u8; 16] = rand::thread_rng().gen();
|
||||
let msg: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
||||
let comsig = ComSignature::sign(amount, &blind, &msg.to_vec(), false)?;
|
||||
|
||||
let commit = secp.commit(amount, blind.clone())?;
|
||||
assert!(comsig.verify(&commit, &msg.to_vec()).is_ok());
|
||||
|
||||
let wrong_msg: [u8; 16] = rand::thread_rng().gen();
|
||||
let wrong_msg: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17];
|
||||
assert!(comsig.verify(&commit, &wrong_msg.to_vec()).is_err());
|
||||
|
||||
let wrong_commit = secp.commit(amount, SecretKey::new(&secp, &mut thread_rng()))?;
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
|
||||
//! Dalek key wrapper for mwixnet primitives
|
||||
|
||||
use ed25519_dalek::Verifier;
|
||||
use grin_util::secp::key::SecretKey;
|
||||
|
||||
use ed25519_dalek::{PublicKey, Signature, Verifier};
|
||||
use ed25519_dalek::VerifyingKey;
|
||||
use grin_core::ser::{self, Readable, Reader, Writeable, Writer};
|
||||
use grin_util::ToHex;
|
||||
use thiserror::Error;
|
||||
@@ -37,7 +38,7 @@ pub enum DalekError {
|
||||
|
||||
/// Encapsulates an ed25519_dalek::PublicKey and provides (de-)serialization
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct DalekPublicKey(PublicKey);
|
||||
pub struct DalekPublicKey(VerifyingKey);
|
||||
|
||||
impl DalekPublicKey {
|
||||
/// Convert DalekPublicKey to hex string
|
||||
@@ -47,23 +48,23 @@ impl DalekPublicKey {
|
||||
|
||||
/// Convert hex string to DalekPublicKey.
|
||||
pub fn from_hex(hex: &str) -> Result<Self, DalekError> {
|
||||
let bytes = grin_util::from_hex(hex)
|
||||
.map_err(|_| DalekError::HexError(format!("failed to decode {}", hex)))?;
|
||||
let pk = PublicKey::from_bytes(bytes.as_ref())
|
||||
.map_err(|_| DalekError::HexError(format!("failed to decode {}", hex)))?;
|
||||
let err = DalekError::HexError(format!("failed to decode {}", hex));
|
||||
let bytes = grin_util::from_hex(hex).map_err(|_| err.clone())?;
|
||||
let b = <&[u8; 32]>::try_from(bytes.as_slice()).map_err(|_| err.clone())?;
|
||||
let pk = VerifyingKey::from_bytes(b).map_err(|_| err)?;
|
||||
Ok(DalekPublicKey(pk))
|
||||
}
|
||||
|
||||
/// Compute DalekPublicKey from a SecretKey
|
||||
pub fn from_secret(key: &SecretKey) -> Self {
|
||||
let secret = ed25519_dalek::SecretKey::from_bytes(&key.0).unwrap();
|
||||
let pk: PublicKey = (&secret).into();
|
||||
let secret = ed25519_dalek::SigningKey::from_bytes(&key.0);
|
||||
let pk: VerifyingKey = (&secret).into();
|
||||
DalekPublicKey(pk)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<PublicKey> for DalekPublicKey {
|
||||
fn as_ref(&self) -> &PublicKey {
|
||||
impl AsRef<VerifyingKey> for DalekPublicKey {
|
||||
fn as_ref(&self) -> &VerifyingKey {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
@@ -103,8 +104,9 @@ pub mod option_dalek_pubkey_serde {
|
||||
|
||||
impl Readable for DalekPublicKey {
|
||||
fn read<R: Reader>(reader: &mut R) -> Result<Self, ser::Error> {
|
||||
let pk = PublicKey::from_bytes(&reader.read_fixed_bytes(32)?)
|
||||
.map_err(|_| ser::Error::CorruptedData)?;
|
||||
let bytes = reader.read_fixed_bytes(32)?;
|
||||
let b = <&[u8; 32]>::try_from(bytes.as_slice()).map_err(|_| ser::Error::CorruptedData)?;
|
||||
let pk = VerifyingKey::from_bytes(b).map_err(|_| ser::Error::CorruptedData)?;
|
||||
Ok(DalekPublicKey(pk))
|
||||
}
|
||||
}
|
||||
@@ -119,7 +121,7 @@ impl Writeable for DalekPublicKey {
|
||||
/// Encapsulates an ed25519_dalek::Signature and provides (de-)serialization
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct DalekSignature(Signature);
|
||||
pub struct DalekSignature(ed25519_dalek::Signature);
|
||||
|
||||
impl DalekSignature {
|
||||
/// Convert hex string to DalekSignature.
|
||||
@@ -127,7 +129,9 @@ impl DalekSignature {
|
||||
pub fn from_hex(hex: &str) -> Result<Self, DalekError> {
|
||||
let bytes = grin_util::from_hex(hex)
|
||||
.map_err(|_| DalekError::HexError(format!("failed to decode {}", hex)))?;
|
||||
let sig = Signature::from_bytes(bytes.as_ref())
|
||||
let b = <[u8; 64]>::try_from(bytes.as_slice())
|
||||
.map_err(|_| DalekError::HexError(format!("failed to decode {}", hex)))?;
|
||||
let sig = ed25519_dalek::Signature::try_from(b)
|
||||
.map_err(|_| DalekError::HexError(format!("failed to decode {}", hex)))?;
|
||||
Ok(DalekSignature(sig))
|
||||
}
|
||||
@@ -141,8 +145,8 @@ impl DalekSignature {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Signature> for DalekSignature {
|
||||
fn as_ref(&self) -> &Signature {
|
||||
impl AsRef<ed25519_dalek::Signature> for DalekSignature {
|
||||
fn as_ref(&self) -> &ed25519_dalek::Signature {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
@@ -160,7 +164,7 @@ pub mod dalek_sig_serde {
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(&sig.0.to_hex())
|
||||
serializer.serialize_str(&sig.0.to_bytes().to_hex())
|
||||
}
|
||||
|
||||
///
|
||||
@@ -178,22 +182,19 @@ pub mod dalek_sig_serde {
|
||||
// TODO: This is likely duplicated throughout crate, check
|
||||
#[cfg(test)]
|
||||
pub fn sign(sk: &SecretKey, message: &[u8]) -> Result<DalekSignature, DalekError> {
|
||||
use ed25519_dalek::{Keypair, Signer};
|
||||
let secret =
|
||||
ed25519_dalek::SecretKey::from_bytes(&sk.0).map_err(|_| DalekError::KeyParseError)?;
|
||||
let public: PublicKey = (&secret).into();
|
||||
let keypair = Keypair { secret, public };
|
||||
let sig = keypair.sign(&message);
|
||||
use ed25519_dalek::{Signer, SigningKey};
|
||||
let secret = SigningKey::from_bytes(&sk.0);
|
||||
let sig = secret.sign(&message);
|
||||
Ok(DalekSignature(sig))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::mwixnet::onion::crypto::secp::Secp256k1;
|
||||
use crate::mwixnet::onion::test_util::rand_keypair;
|
||||
use grin_core::ser::{self, ProtocolVersion};
|
||||
use grin_util::ToHex;
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -262,23 +263,27 @@ mod tests {
|
||||
#[test]
|
||||
fn sig_test() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Sign a message
|
||||
let (sk, pk) = rand_keypair();
|
||||
let msg: [u8; 16] = rand::thread_rng().gen();
|
||||
let s = Secp256k1::new();
|
||||
let sk = SecretKey::from_slice(&s, &[1; 32]).unwrap();
|
||||
let pk = DalekPublicKey::from_secret(&sk);
|
||||
|
||||
let msg: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
||||
let sig = sign(&sk, &msg).unwrap();
|
||||
|
||||
// Verify signature
|
||||
assert!(sig.verify(&pk, &msg).is_ok());
|
||||
|
||||
// Wrong message
|
||||
let wrong_msg: [u8; 16] = rand::thread_rng().gen();
|
||||
let wrong_msg: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17];
|
||||
assert!(sig.verify(&pk, &wrong_msg).is_err());
|
||||
|
||||
// Wrong pubkey
|
||||
let wrong_pk = rand_keypair().1;
|
||||
let wrong_sk = SecretKey::from_slice(&s, &[2; 32]).unwrap();
|
||||
let wrong_pk = DalekPublicKey::from_secret(&wrong_sk);
|
||||
assert!(sig.verify(&wrong_pk, &msg).is_err());
|
||||
|
||||
// Test from_hex
|
||||
let sig_from_hex = DalekSignature::from_hex(sig.0.to_hex().as_str()).unwrap();
|
||||
let sig_from_hex = DalekSignature::from_hex(sig.0.to_bytes().to_hex().as_str()).unwrap();
|
||||
assert_eq!(sig.0, sig_from_hex.0);
|
||||
|
||||
// Test serde (de-)serialization
|
||||
@@ -286,7 +291,7 @@ mod tests {
|
||||
let val = serde_json::to_value(serde_test.clone()).unwrap();
|
||||
if let Value::Object(o) = &val {
|
||||
if let Value::String(s) = o.get("sig").unwrap() {
|
||||
assert_eq!(s, &sig.0.to_hex());
|
||||
assert_eq!(s, &sig.0.to_bytes().to_hex());
|
||||
} else {
|
||||
panic!("Invalid type");
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ use crate::grin_util::secp::key::{PublicKey, SecretKey};
|
||||
use crate::grin_util::secp::pedersen::Commitment;
|
||||
use crate::grin_util::secp::Signature;
|
||||
use crate::grin_util::{secp, static_secp_instance};
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::Signature as DalekSignature;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use serde::ser::{Serialize, Serializer};
|
||||
use serde_json;
|
||||
use std::fmt;
|
||||
|
||||
@@ -131,7 +131,7 @@ pub mod ov3_serde {
|
||||
/// Serializes an ed25519 PublicKey to and from hex
|
||||
pub mod dalek_seckey_serde {
|
||||
use crate::grin_util::{from_hex, ToHex};
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
|
||||
///
|
||||
@@ -151,7 +151,9 @@ pub mod dalek_seckey_serde {
|
||||
String::deserialize(deserializer)
|
||||
.and_then(|string| from_hex(&string).map_err(|err| Error::custom(err.to_string())))
|
||||
.and_then(|bytes: Vec<u8>| {
|
||||
DalekSecretKey::from_bytes(&bytes).map_err(|err| Error::custom(err.to_string()))
|
||||
let b = <&[u8; 32]>::try_from(bytes.as_slice())
|
||||
.map_err(|_| Error::custom("Error deserializing secret key"))?;
|
||||
Ok(DalekSecretKey::from_bytes(b))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -159,7 +161,7 @@ pub mod dalek_seckey_serde {
|
||||
/// Serializes an ed25519 PublicKey to and from hex
|
||||
pub mod dalek_pubkey_serde {
|
||||
use crate::grin_util::{from_hex, ToHex};
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
|
||||
///
|
||||
@@ -179,12 +181,17 @@ pub mod dalek_pubkey_serde {
|
||||
String::deserialize(deserializer)
|
||||
.and_then(|string| from_hex(&string).map_err(|err| Error::custom(err.to_string())))
|
||||
.and_then(|bytes: Vec<u8>| {
|
||||
DalekPublicKey::from_bytes(&bytes).map_err(|err| Error::custom(err.to_string()))
|
||||
let b = <&[u8; 32]>::try_from(bytes.as_slice())
|
||||
.map_err(|_| Error::custom("Error deserializing public key"))?;
|
||||
Ok(match DalekPublicKey::from_bytes(b) {
|
||||
Ok(pk) => pk,
|
||||
Err(e) => return Err(Error::custom(format!("{:?}", e))),
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Serializes an x25519 PublicKey to and from hex
|
||||
/// Serializes a x25519 PublicKey to and from hex
|
||||
pub mod dalek_xpubkey_serde {
|
||||
use crate::grin_util::{from_hex, ToHex};
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
@@ -217,7 +224,7 @@ pub mod dalek_xpubkey_serde {
|
||||
/// Serializes an ed25519 PublicKey to and from base64
|
||||
pub mod dalek_pubkey_base64 {
|
||||
use base64;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
|
||||
///
|
||||
@@ -239,7 +246,12 @@ pub mod dalek_pubkey_base64 {
|
||||
base64::decode(&string).map_err(|err| Error::custom(err.to_string()))
|
||||
})
|
||||
.and_then(|bytes: Vec<u8>| {
|
||||
DalekPublicKey::from_bytes(&bytes).map_err(|err| Error::custom(err.to_string()))
|
||||
let b = <&[u8; 32]>::try_from(bytes.as_slice())
|
||||
.map_err(|_| Error::custom("Error deserializing public key"))?;
|
||||
Ok(match DalekPublicKey::from_bytes(b) {
|
||||
Ok(pk) => pk,
|
||||
Err(e) => return Err(Error::custom(format!("{:?}", e))),
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -247,7 +259,7 @@ pub mod dalek_pubkey_base64 {
|
||||
/// Serializes an Option<ed25519_dalek::PublicKey> to and from hex
|
||||
pub mod option_dalek_pubkey_base64 {
|
||||
use base64;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use serde::de::Error;
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
|
||||
@@ -287,7 +299,7 @@ pub mod option_dalek_pubkey_base64 {
|
||||
|
||||
/// Serializes an Option<ed25519_dalek::PublicKey> to and from hex
|
||||
pub mod option_dalek_pubkey_serde {
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use serde::de::Error;
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
|
||||
@@ -597,11 +609,10 @@ mod test {
|
||||
use rand::rngs::mock::StepRng;
|
||||
|
||||
use crate::grin_util::{secp, static_secp_instance};
|
||||
use ed25519_dalek::Keypair;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::Signature as DalekSignature;
|
||||
use ed25519_dalek::Signer;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use serde::Deserialize;
|
||||
|
||||
use serde_json;
|
||||
@@ -624,15 +635,10 @@ mod test {
|
||||
let secp = secp_inst.lock();
|
||||
let mut test_rng = StepRng::new(1234567890u64, 1);
|
||||
let sec_key = secp::key::SecretKey::new(&secp, &mut test_rng);
|
||||
let d_skey = DalekSecretKey::from_bytes(&sec_key.0).unwrap();
|
||||
let d_skey = DalekSecretKey::from_bytes(&sec_key.0);
|
||||
let d_pub_key: DalekPublicKey = (&d_skey).into();
|
||||
|
||||
let keypair = Keypair {
|
||||
public: d_pub_key,
|
||||
secret: d_skey,
|
||||
};
|
||||
|
||||
let d_sig = keypair.sign("test sig".as_bytes());
|
||||
let d_sig = d_skey.sign("test sig".as_bytes());
|
||||
println!("D sig: {:?}", d_sig);
|
||||
|
||||
SerTest {
|
||||
|
||||
@@ -62,8 +62,8 @@ use crate::grin_util::secp::key::PublicKey;
|
||||
use crate::grin_util::secp::pedersen::{Commitment, RangeProof};
|
||||
use crate::grin_util::secp::Signature;
|
||||
use crate::{slate_versions::ser, CbData};
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::Signature as DalekSignature;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
||||
@@ -21,8 +21,8 @@ use crate::grin_keychain::BlindingFactor;
|
||||
use crate::grin_util::secp::key::PublicKey;
|
||||
use crate::grin_util::secp::pedersen::{Commitment, RangeProof};
|
||||
use crate::grin_util::secp::Signature;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::Signature as DalekSignature;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use std::convert::TryFrom;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -345,10 +345,18 @@ impl<'a> Writeable for ProofWrapRef<'a> {
|
||||
|
||||
impl Readable for ProofWrap {
|
||||
fn read<R: Reader>(reader: &mut R) -> Result<ProofWrap, grin_ser::Error> {
|
||||
let saddr = DalekPublicKey::from_bytes(&reader.read_fixed_bytes(32)?)
|
||||
let saddr_bytes = reader.read_fixed_bytes(32)?;
|
||||
let saddr_bytes = <&[u8; 32]>::try_from(saddr_bytes.as_slice())
|
||||
.map_err(|_| grin_ser::Error::CorruptedData)?;
|
||||
let raddr = DalekPublicKey::from_bytes(&reader.read_fixed_bytes(32)?)
|
||||
let saddr =
|
||||
DalekPublicKey::from_bytes(saddr_bytes).map_err(|_| grin_ser::Error::CorruptedData)?;
|
||||
|
||||
let raddr_bytes = reader.read_fixed_bytes(32)?;
|
||||
let raddr_bytes = <&[u8; 32]>::try_from(raddr_bytes.as_slice())
|
||||
.map_err(|_| grin_ser::Error::CorruptedData)?;
|
||||
let raddr =
|
||||
DalekPublicKey::from_bytes(raddr_bytes).map_err(|_| grin_ser::Error::CorruptedData)?;
|
||||
|
||||
let rsig = match reader.read_u8()? {
|
||||
0 => None,
|
||||
1 | _ => Some(
|
||||
@@ -500,6 +508,7 @@ fn slate_v4_serialize_deserialize() {
|
||||
use crate::Slate;
|
||||
use grin_core::global::{set_local_chain_type, ChainTypes};
|
||||
use grin_keychain::{ExtKeychain, Keychain, SwitchCommitmentType};
|
||||
|
||||
set_local_chain_type(ChainTypes::Mainnet);
|
||||
let slate = Slate::blank(1, false);
|
||||
let mut v4 = SlateV4::from(slate);
|
||||
@@ -573,8 +582,9 @@ fn slate_v4_serialize_deserialize() {
|
||||
// Include Payment proof, remove coms to mix it up a bit
|
||||
let mut v4 = v4_1_copy;
|
||||
let raw_pubkey_str = "d03c09e9c19bb74aa9ea44e0fe5ae237a9bf40bddf0941064a80913a4459c8bb";
|
||||
let b = from_hex(raw_pubkey_str).unwrap();
|
||||
let d_pkey = DalekPublicKey::from_bytes(&b).unwrap();
|
||||
let bytes = from_hex(raw_pubkey_str).unwrap();
|
||||
let b = <&[u8; 32]>::try_from(bytes.as_slice()).unwrap();
|
||||
let d_pkey = DalekPublicKey::from_bytes(b.as_array().unwrap()).unwrap();
|
||||
v4.proof = Some(PaymentInfoV4 {
|
||||
raddr: d_pkey.clone(),
|
||||
saddr: d_pkey.clone(),
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
// limitations under the License.
|
||||
|
||||
use bech32::{self, FromBase32, ToBase32};
|
||||
use ed25519_dalek::SigningKey as edDalekSecretKey;
|
||||
/// Slatepack Address definition
|
||||
use ed25519_dalek::PublicKey as edDalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as edDalekSecretKey;
|
||||
use ed25519_dalek::VerifyingKey as edDalekPublicKey;
|
||||
use rand::{thread_rng, Rng};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use x25519_dalek::PublicKey as xDalekPublicKey;
|
||||
@@ -57,7 +57,7 @@ impl SlatepackAddress {
|
||||
/// new with a random key
|
||||
pub fn random() -> Self {
|
||||
let bytes: [u8; 32] = thread_rng().gen();
|
||||
let pub_key = edDalekPublicKey::from(&edDalekSecretKey::from_bytes(&bytes).unwrap());
|
||||
let pub_key = edDalekPublicKey::from(&edDalekSecretKey::from_bytes(&bytes));
|
||||
SlatepackAddress::new(&pub_key)
|
||||
}
|
||||
|
||||
@@ -88,7 +88,9 @@ impl TryFrom<&str> for SlatepackAddress {
|
||||
fn try_from(encoded: &str) -> Result<Self, Self::Error> {
|
||||
let (hrp, data) = bech32::decode(&encoded)?;
|
||||
let bytes = Vec::<u8>::from_base32(&data)?;
|
||||
let pub_key = match edDalekPublicKey::from_bytes(&bytes) {
|
||||
let b = <&[u8; 32]>::try_from(bytes.as_slice())
|
||||
.map_err(|_| Error::SlatepackAddress("Wrong encoded data".to_string()))?;
|
||||
let pub_key = match edDalekPublicKey::from_bytes(&b) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(Error::ED25519Key(format!("{}", e)));
|
||||
@@ -124,7 +126,10 @@ impl TryFrom<&SlatepackAddress> for xDalekPublicKey {
|
||||
fn try_from(addr: &SlatepackAddress) -> Result<Self, Self::Error> {
|
||||
let cep =
|
||||
curve25519_dalek::edwards::CompressedEdwardsY::from_slice(addr.pub_key.as_bytes());
|
||||
let ep = match cep.decompress() {
|
||||
let ep = match cep
|
||||
.map_err(|e| Error::ED25519Key(format!("{}", e)))?
|
||||
.decompress()
|
||||
{
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(Error::ED25519Key(
|
||||
@@ -140,15 +145,7 @@ impl TryFrom<&SlatepackAddress> for xDalekPublicKey {
|
||||
impl TryFrom<&SecretKey> for SlatepackAddress {
|
||||
type Error = Error;
|
||||
fn try_from(key: &SecretKey) -> Result<Self, Self::Error> {
|
||||
let d_skey = match edDalekSecretKey::from_bytes(&key.0) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(Error::ED25519Key(format!(
|
||||
"Can't create slatepack address from SecretKey: {}",
|
||||
e
|
||||
)));
|
||||
}
|
||||
};
|
||||
let d_skey = edDalekSecretKey::from_bytes(&key.0);
|
||||
let d_pub_key: edDalekPublicKey = (&d_skey).into();
|
||||
Ok(Self::new(&d_pub_key))
|
||||
}
|
||||
@@ -251,7 +248,7 @@ fn slatepack_address() -> Result<(), Error> {
|
||||
global::set_local_chain_type(global::ChainTypes::AutomatedTesting);
|
||||
let sec_key_bytes: [u8; 32] = thread_rng().gen();
|
||||
|
||||
let ed_sec_key = edDalekSecretKey::from_bytes(&sec_key_bytes).unwrap();
|
||||
let ed_sec_key = edDalekSecretKey::from_bytes(&sec_key_bytes);
|
||||
let ed_pub_key = edDalekPublicKey::from(&ed_sec_key);
|
||||
let addr = SlatepackAddress::new(&ed_pub_key);
|
||||
let x_pub_key = xDalekPublicKey::try_from(&addr)?;
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::{
|
||||
|
||||
use grin_wallet_util::byte_ser;
|
||||
|
||||
use ed25519_dalek::SecretKey as edSecretKey;
|
||||
use ed25519_dalek::SigningKey as edSecretKey;
|
||||
|
||||
#[derive(Clone)]
|
||||
/// Arguments, mostly for encrypting decrypting a slatepack
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
use bech32::{self, ToBase32};
|
||||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||
/// Slatepack Types + Serialization implementation
|
||||
use ed25519_dalek::SecretKey as edSecretKey;
|
||||
use ed25519_dalek::SigningKey as edSecretKey;
|
||||
use sha2::{Digest, Sha512};
|
||||
use x25519_dalek::StaticSecret;
|
||||
|
||||
@@ -768,15 +768,15 @@ fn slatepack_bin_future() -> Result<(), grin_wallet_util::byte_ser::Error> {
|
||||
fn slatepack_encrypted_meta() -> Result<(), Error> {
|
||||
use crate::grin_core::global;
|
||||
use crate::{Slate, SlateVersion, VersionedBinSlate, VersionedSlate};
|
||||
use ed25519_dalek::PublicKey as edDalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as edDalekSecretKey;
|
||||
use ed25519_dalek::SigningKey as edDalekSecretKey;
|
||||
use ed25519_dalek::VerifyingKey as edDalekPublicKey;
|
||||
use rand::{thread_rng, Rng};
|
||||
use std::convert::TryFrom;
|
||||
global::set_local_chain_type(global::ChainTypes::AutomatedTesting);
|
||||
|
||||
let sec_key_bytes: [u8; 32] = thread_rng().gen();
|
||||
|
||||
let ed_sec_key = edDalekSecretKey::from_bytes(&sec_key_bytes).unwrap();
|
||||
let ed_sec_key = edDalekSecretKey::from_bytes(&sec_key_bytes);
|
||||
let ed_pub_key = edDalekPublicKey::from(&ed_sec_key);
|
||||
let addr = SlatepackAddress::new(&ed_pub_key);
|
||||
|
||||
@@ -817,15 +817,15 @@ fn slatepack_encrypted_meta() -> Result<(), Error> {
|
||||
fn slatepack_encrypted_meta_future() -> Result<(), Error> {
|
||||
use crate::grin_core::global;
|
||||
use crate::{Slate, SlateVersion, VersionedBinSlate, VersionedSlate};
|
||||
use ed25519_dalek::PublicKey as edDalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as edDalekSecretKey;
|
||||
use ed25519_dalek::SigningKey as edDalekSecretKey;
|
||||
use ed25519_dalek::VerifyingKey as edDalekPublicKey;
|
||||
use rand::{thread_rng, Rng};
|
||||
use std::convert::TryFrom;
|
||||
global::set_local_chain_type(global::ChainTypes::AutomatedTesting);
|
||||
|
||||
let sec_key_bytes: [u8; 32] = thread_rng().gen();
|
||||
|
||||
let ed_sec_key = edDalekSecretKey::from_bytes(&sec_key_bytes).unwrap();
|
||||
let ed_sec_key = edDalekSecretKey::from_bytes(&sec_key_bytes);
|
||||
let ed_pub_key = edDalekPublicKey::from(&ed_sec_key);
|
||||
let addr = SlatepackAddress::new(&ed_pub_key);
|
||||
|
||||
@@ -864,11 +864,11 @@ fn slatepack_encrypted_meta_future() -> Result<(), Error> {
|
||||
|
||||
#[cfg(test)]
|
||||
fn slatepack_test_decryption_key() -> (edSecretKey, SlatepackAddress) {
|
||||
use ed25519_dalek::PublicKey as edDalekPublicKey;
|
||||
use ed25519_dalek::VerifyingKey as edDalekPublicKey;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
let sec_key_bytes: [u8; 32] = thread_rng().gen();
|
||||
let ed_sec_key = edSecretKey::from_bytes(&sec_key_bytes).unwrap();
|
||||
let ed_sec_key = edSecretKey::from_bytes(&sec_key_bytes);
|
||||
let ed_pub_key = edDalekPublicKey::from(&ed_sec_key);
|
||||
let addr = SlatepackAddress::new(&ed_pub_key);
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ use crate::grin_util::{ToHex, ZeroingString};
|
||||
use crate::slate_versions::ser as dalek_ser;
|
||||
use crate::{InitTxArgs, SlateState, WalletBackend};
|
||||
use chrono::prelude::*;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::Signature as DalekSignature;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use rand::rngs::mock::StepRng;
|
||||
use rand::thread_rng;
|
||||
use serde;
|
||||
|
||||
@@ -131,8 +131,6 @@ fn real_main() -> i32 {
|
||||
},
|
||||
};
|
||||
|
||||
//config.members.as_mut().unwrap().wallet.chain_type = Some(chain_type);
|
||||
|
||||
// Load logging config
|
||||
let mut l = config.members.as_mut().unwrap().logging.clone().unwrap();
|
||||
// no logging to stdout if we're running cli
|
||||
|
||||
+3
-1
@@ -189,7 +189,7 @@ where
|
||||
let lc = wallet_lock.lc_provider().unwrap();
|
||||
let mask = match lc.open_wallet(
|
||||
None,
|
||||
wallet_args::prompt_password(&global_wallet_args.password),
|
||||
wallet_args::prompt_password(&global_wallet_args.password)?,
|
||||
false,
|
||||
false,
|
||||
) {
|
||||
@@ -276,6 +276,8 @@ impl Completer for EditorHelper {
|
||||
}
|
||||
|
||||
impl Hinter for EditorHelper {
|
||||
type Hint = String;
|
||||
|
||||
fn hint(&self, line: &str, _pos: usize, _ctx: &Context<'_>) -> Option<String> {
|
||||
let mut contents = STDIN_CONTENTS.lock();
|
||||
*contents = line.into();
|
||||
|
||||
+12
-2
@@ -42,14 +42,24 @@ where
|
||||
|
||||
// This will also cache the node version info for calls to foreign API check middleware
|
||||
if let Some(v) = node_client.clone().get_version_info() {
|
||||
if Version::parse(&v.node_version) < Version::parse(MIN_COMPAT_NODE_VERSION) {
|
||||
println!("The Grin Node in use (version {}) is outdated and incompatible with this wallet version.", v.node_version);
|
||||
let node_version = Version::parse(&v.node_version);
|
||||
let min_version = Version::parse(MIN_COMPAT_NODE_VERSION).ok();
|
||||
if let Ok(v) = node_version {
|
||||
if Some(v.clone()) < min_version {
|
||||
println!("The Grin Node in use (version {}) is outdated and incompatible with this wallet version.", v);
|
||||
println!(
|
||||
"Please update the node to version {} or later and try again.",
|
||||
MIN_COMPAT_NODE_VERSION
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
println!(
|
||||
"Can not parse node version {}. Minimal compatible node version: {}",
|
||||
v.node_version, MIN_COMPAT_NODE_VERSION
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
// ... if node isn't available, allow offline functions
|
||||
|
||||
|
||||
+38
-21
@@ -12,13 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// Argument parsing and error handling for wallet commands
|
||||
use crate::api::TLSConfig;
|
||||
use crate::cli::command_loop;
|
||||
use crate::config::GRIN_WALLET_DIR;
|
||||
use crate::util::file::get_first_line;
|
||||
use crate::util::secp::key::SecretKey;
|
||||
use crate::util::{Mutex, ZeroingString};
|
||||
/// Argument parsing and error handling for wallet commands
|
||||
|
||||
use clap::ArgMatches;
|
||||
use grin_core as core;
|
||||
use grin_core::core::amount_to_hr_string;
|
||||
@@ -33,6 +34,7 @@ use linefeed::terminal::Signal;
|
||||
use linefeed::{Interface, ReadResult};
|
||||
use rpassword;
|
||||
use std::convert::TryFrom;
|
||||
use std::io::{IsTerminal, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -67,25 +69,39 @@ impl From<std::io::Error> for ParseError {
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_password_stdout(prompt: &str) -> ZeroingString {
|
||||
ZeroingString::from(rpassword::prompt_password_stdout(prompt).unwrap())
|
||||
fn prompt_password_internal(prompt: &str) -> Result<ZeroingString, Error> {
|
||||
print!("{}", prompt);
|
||||
std::io::stdout().flush().unwrap();
|
||||
let stdin = std::io::stdin();
|
||||
let password = if stdin.is_terminal() {
|
||||
rpassword::read_password()
|
||||
} else {
|
||||
rpassword::read_password_with_config(
|
||||
rpassword::ConfigBuilder::new()
|
||||
.input_reader(stdin)
|
||||
.output_discard()
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
.map_err(|e| Error::GenericError(format!("{}", e)))?;
|
||||
Ok(ZeroingString::from(password))
|
||||
}
|
||||
|
||||
pub fn prompt_password(password: &Option<ZeroingString>) -> ZeroingString {
|
||||
pub fn prompt_password(password: &Option<ZeroingString>) -> Result<ZeroingString, Error> {
|
||||
match password {
|
||||
None => prompt_password_stdout("Password: "),
|
||||
Some(p) => p.clone(),
|
||||
None => Ok(prompt_password_internal("Password: ")?),
|
||||
Some(p) => Ok(p.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_password_confirm() -> ZeroingString {
|
||||
fn prompt_password_confirm() -> Result<ZeroingString, Error> {
|
||||
let mut first = ZeroingString::from("first");
|
||||
let mut second = ZeroingString::from("second");
|
||||
while first != second {
|
||||
first = prompt_password_stdout("Password: ");
|
||||
second = prompt_password_stdout("Confirm Password: ");
|
||||
first = prompt_password_internal("Password: ")?;
|
||||
second = prompt_password_internal("Confirm Password: ")?;
|
||||
}
|
||||
first
|
||||
Ok(first)
|
||||
}
|
||||
|
||||
fn prompt_recovery_phrase<L, C, K>(
|
||||
@@ -333,7 +349,7 @@ pub fn parse_init_args<L, C, K>(
|
||||
g_args: &command::GlobalArgs,
|
||||
args: &ArgMatches,
|
||||
_test_mode: bool,
|
||||
) -> Result<command::InitArgs, ParseError>
|
||||
) -> Result<command::InitArgs, Error>
|
||||
where
|
||||
DefaultWalletImpl<C>: WalletInst<'static, L, C, K>,
|
||||
L: WalletLCProvider<'static, C, K>,
|
||||
@@ -345,7 +361,9 @@ where
|
||||
true => 16,
|
||||
};
|
||||
let recovery_phrase = match args.is_present("recover") {
|
||||
true => Some(prompt_recovery_phrase(wallet)?),
|
||||
true => {
|
||||
Some(prompt_recovery_phrase(wallet).map_err(|e| Error::GenericError(e.to_string()))?)
|
||||
}
|
||||
false => None,
|
||||
};
|
||||
|
||||
@@ -355,10 +373,11 @@ where
|
||||
println!("Please enter a password for your new wallet");
|
||||
}
|
||||
|
||||
let password = g_args
|
||||
.password
|
||||
.clone()
|
||||
.unwrap_or_else(|| prompt_password_confirm());
|
||||
let password = if let Some(p) = g_args.password.clone() {
|
||||
p
|
||||
} else {
|
||||
prompt_password_confirm()?
|
||||
};
|
||||
|
||||
Ok(command::InitArgs {
|
||||
list_length,
|
||||
@@ -369,12 +388,10 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_recover_args(
|
||||
g_args: &command::GlobalArgs,
|
||||
) -> Result<command::RecoverArgs, ParseError>
|
||||
pub fn parse_recover_args(g_args: &command::GlobalArgs) -> Result<command::RecoverArgs, Error>
|
||||
where
|
||||
{
|
||||
let passphrase = prompt_password(&g_args.password);
|
||||
let passphrase = prompt_password(&g_args.password)?;
|
||||
Ok(command::RecoverArgs { passphrase })
|
||||
}
|
||||
|
||||
@@ -1073,7 +1090,7 @@ where
|
||||
let lc = wallet_lock.lc_provider()?;
|
||||
let mask = lc.open_wallet(
|
||||
None,
|
||||
prompt_password(&global_wallet_args.password),
|
||||
prompt_password(&global_wallet_args.password)?,
|
||||
false,
|
||||
false,
|
||||
)?;
|
||||
|
||||
@@ -637,7 +637,7 @@ fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
let some_tx_id = txs[0].tx_slate_id.clone();
|
||||
assert!(some_tx_id.is_some());
|
||||
tx_id = some_tx_id.unwrap().to_hyphenated().to_string().clone();
|
||||
tx_id = some_tx_id.unwrap().to_string().clone();
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ macro_rules! setup_proxy {
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn clean_output_dir(test_dir: &str) {
|
||||
let _ = remove_dir_all::remove_dir_all(test_dir);
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
+2
-8
@@ -10,21 +10,15 @@ workspace = ".."
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.6"
|
||||
serde = "1"
|
||||
serde_derive = "1"
|
||||
ed25519-dalek = "1.0.0-pre.4"
|
||||
ed25519-dalek = "2"
|
||||
data-encoding = "2"
|
||||
sha3 = "0.8"
|
||||
thiserror = "1"
|
||||
|
||||
##### Grin Imports
|
||||
|
||||
# For Release
|
||||
|
||||
grin_util = { path = "../grin/util"}
|
||||
|
||||
#####
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "0.6"
|
||||
######
|
||||
|
||||
+3
-11
@@ -13,8 +13,8 @@
|
||||
// limitations under the License.
|
||||
|
||||
use data_encoding::BASE32;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use grin_util::from_hex;
|
||||
use sha3::{Digest, Sha3_256};
|
||||
use std::convert::TryFrom;
|
||||
@@ -49,15 +49,7 @@ impl OnionV3Address {
|
||||
|
||||
/// populate from a private key
|
||||
pub fn from_private(key: &[u8; 32]) -> Result<Self, OnionV3Error> {
|
||||
let d_skey = match DalekSecretKey::from_bytes(key) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(OnionV3Error::InvalidPrivateKey(format!(
|
||||
"Unable to create public key: {}",
|
||||
e
|
||||
)));
|
||||
}
|
||||
};
|
||||
let d_skey = DalekSecretKey::from_bytes(key);
|
||||
let d_pub_key: DalekPublicKey = (&d_skey).into();
|
||||
Ok(OnionV3Address(*d_pub_key.as_bytes()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user