mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 15:21:39 +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:
+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,19 +553,17 @@ impl OwnerV3Helpers {
|
||||
None
|
||||
};
|
||||
match err_string {
|
||||
Some(s) => {
|
||||
return (
|
||||
true,
|
||||
serde_json::json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": val["id"],
|
||||
"error": {
|
||||
"message": s,
|
||||
"code": -32099
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
Some(s) => (
|
||||
true,
|
||||
serde_json::json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": val["id"],
|
||||
"error": {
|
||||
"message": s,
|
||||
"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);
|
||||
|
||||
Reference in New Issue
Block a user