Support Monero Wallet RPC authentication
This commit is contained in:
parent
faca485ebf
commit
4a4e3e9e4a
7 changed files with 75 additions and 11 deletions
|
@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Support Monero Wallet RPC authentication.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Added emoji count check to profile data validator.
|
- Added emoji count check to profile data validator.
|
||||||
|
|
38
Cargo.lock
generated
38
Cargo.lock
generated
|
@ -835,6 +835,30 @@ dependencies = [
|
||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "digest_auth"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa30657988b2ced88f68fe490889e739bf98d342916c33ed3100af1d6f1cbc9c"
|
||||||
|
dependencies = [
|
||||||
|
"digest 0.9.0",
|
||||||
|
"hex",
|
||||||
|
"md-5 0.9.1",
|
||||||
|
"rand 0.8.4",
|
||||||
|
"sha2 0.9.9",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "diqwest"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70822b55cc8af405e65915d22ee0031433414f4464fa276cd6cdb9fff203bb40"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"digest_auth",
|
||||||
|
"reqwest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dotenv"
|
name = "dotenv"
|
||||||
version = "0.15.0"
|
version = "0.15.0"
|
||||||
|
@ -1752,6 +1776,17 @@ version = "0.1.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "md-5"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
|
||||||
|
dependencies = [
|
||||||
|
"block-buffer 0.9.0",
|
||||||
|
"digest 0.9.0",
|
||||||
|
"opaque-debug",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "md-5"
|
name = "md-5"
|
||||||
version = "0.10.1"
|
version = "0.10.1"
|
||||||
|
@ -1965,6 +2000,7 @@ checksum = "e016b5ed7dbf76e123516b22f35653a95d8c4b784d2ce2113395863dfd9f482f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"diqwest",
|
||||||
"fixed-hash 0.8.0",
|
"fixed-hash 0.8.0",
|
||||||
"hex",
|
"hex",
|
||||||
"http",
|
"http",
|
||||||
|
@ -2357,7 +2393,7 @@ dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"fallible-iterator",
|
"fallible-iterator",
|
||||||
"hmac 0.12.1",
|
"hmac 0.12.1",
|
||||||
"md-5",
|
"md-5 0.10.1",
|
||||||
"memchr",
|
"memchr",
|
||||||
"rand 0.8.4",
|
"rand 0.8.4",
|
||||||
"sha2 0.10.5",
|
"sha2 0.10.5",
|
||||||
|
|
|
@ -51,7 +51,7 @@ ed25519-dalek = "1.0.1"
|
||||||
ed25519 = "1.5.3"
|
ed25519 = "1.5.3"
|
||||||
blake2 = "0.10.5"
|
blake2 = "0.10.5"
|
||||||
# Used to query Monero node
|
# Used to query Monero node
|
||||||
monero-rpc = "0.3.2"
|
monero-rpc = { version = "0.3.2", features = ["rpc_authentication"] }
|
||||||
# Used to determine the number of CPUs on the system
|
# Used to determine the number of CPUs on the system
|
||||||
num_cpus = "1.13.0"
|
num_cpus = "1.13.0"
|
||||||
# Used for working with regular expressions
|
# Used for working with regular expressions
|
||||||
|
|
|
@ -18,7 +18,9 @@ blockchains:
|
||||||
# Parameters for local Monero node
|
# Parameters for local Monero node
|
||||||
- chain_id: monero:regtest
|
- chain_id: monero:regtest
|
||||||
node_url: 'http://127.0.0.1:58081'
|
node_url: 'http://127.0.0.1:58081'
|
||||||
wallet_url: 'http://127.0.0.1:58083'
|
wallet_rpc_url: 'http://127.0.0.1:58083'
|
||||||
|
wallet_rpc_username: null
|
||||||
|
wallet_rpc_password: null
|
||||||
wallet_name: test
|
wallet_name: test
|
||||||
wallet_password: test
|
wallet_password: test
|
||||||
account_index: 0
|
account_index: 0
|
||||||
|
|
|
@ -63,7 +63,9 @@ retention:
|
||||||
#blockchains:
|
#blockchains:
|
||||||
# - chain_id: monero:mainnet
|
# - chain_id: monero:mainnet
|
||||||
# node_url: 'http://opennode.xmr-tw.org:18089'
|
# node_url: 'http://opennode.xmr-tw.org:18089'
|
||||||
# wallet_url: 'http://127.0.0.1:18083'
|
# wallet_rpc_url: 'http://127.0.0.1:18083'
|
||||||
|
# wallet_rpc_username: null
|
||||||
|
# wallet_rpc_password: null
|
||||||
# wallet_name: null
|
# wallet_name: null
|
||||||
# wallet_password: null
|
# wallet_password: null
|
||||||
# account_index: 0
|
# account_index: 0
|
||||||
|
|
|
@ -56,7 +56,10 @@ pub struct MoneroConfig {
|
||||||
pub chain_id: ChainId,
|
pub chain_id: ChainId,
|
||||||
#[serde(alias = "daemon_url")]
|
#[serde(alias = "daemon_url")]
|
||||||
pub node_url: String,
|
pub node_url: String,
|
||||||
pub wallet_url: String,
|
#[serde(alias = "wallet_url")]
|
||||||
|
pub wallet_rpc_url: String,
|
||||||
|
pub wallet_rpc_username: Option<String>,
|
||||||
|
pub wallet_rpc_password: Option<String>,
|
||||||
// Wallet name and password are required when
|
// Wallet name and password are required when
|
||||||
// monero-wallet-rpc is running with --wallet-dir option
|
// monero-wallet-rpc is running with --wallet-dir option
|
||||||
pub wallet_name: Option<String>,
|
pub wallet_name: Option<String>,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use monero_rpc::{
|
use monero_rpc::{
|
||||||
HashString,
|
HashString,
|
||||||
|
RpcAuthentication,
|
||||||
RpcClientBuilder,
|
RpcClientBuilder,
|
||||||
SubaddressBalanceData,
|
SubaddressBalanceData,
|
||||||
SweepAllArgs,
|
SweepAllArgs,
|
||||||
|
@ -34,15 +35,33 @@ pub enum MoneroError {
|
||||||
OtherError(&'static str),
|
OtherError(&'static str),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_wallet_client(config: &MoneroConfig)
|
||||||
|
-> Result<WalletClient, MoneroError>
|
||||||
|
{
|
||||||
|
let rpc_authentication = match config.wallet_rpc_username {
|
||||||
|
Some(ref username) => {
|
||||||
|
RpcAuthentication::Credentials {
|
||||||
|
username: username.clone(),
|
||||||
|
password: config.wallet_rpc_password.as_deref()
|
||||||
|
.unwrap_or("").to_string(),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => RpcAuthentication::None,
|
||||||
|
};
|
||||||
|
let wallet_client = RpcClientBuilder::new()
|
||||||
|
.rpc_authentication(rpc_authentication)
|
||||||
|
.build(config.wallet_rpc_url.clone())?
|
||||||
|
.wallet();
|
||||||
|
Ok(wallet_client)
|
||||||
|
}
|
||||||
|
|
||||||
/// https://monerodocs.org/interacting/monero-wallet-rpc-reference/#create_wallet
|
/// https://monerodocs.org/interacting/monero-wallet-rpc-reference/#create_wallet
|
||||||
pub async fn create_monero_wallet(
|
pub async fn create_monero_wallet(
|
||||||
config: &MoneroConfig,
|
config: &MoneroConfig,
|
||||||
name: String,
|
name: String,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
) -> Result<(), MoneroError> {
|
) -> Result<(), MoneroError> {
|
||||||
let wallet_client = RpcClientBuilder::new()
|
let wallet_client = build_wallet_client(config)?;
|
||||||
.build(config.wallet_url.clone())?
|
|
||||||
.wallet();
|
|
||||||
let language = "English".to_string();
|
let language = "English".to_string();
|
||||||
wallet_client.create_wallet(name, password, language).await?;
|
wallet_client.create_wallet(name, password, language).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -52,9 +71,7 @@ pub async fn create_monero_wallet(
|
||||||
pub async fn open_monero_wallet(
|
pub async fn open_monero_wallet(
|
||||||
config: &MoneroConfig,
|
config: &MoneroConfig,
|
||||||
) -> Result<WalletClient, MoneroError> {
|
) -> Result<WalletClient, MoneroError> {
|
||||||
let wallet_client = RpcClientBuilder::new()
|
let wallet_client = build_wallet_client(config)?;
|
||||||
.build(config.wallet_url.clone())?
|
|
||||||
.wallet();
|
|
||||||
if let Err(error) = wallet_client.refresh(None).await {
|
if let Err(error) = wallet_client.refresh(None).await {
|
||||||
if error.to_string() == "Server error: No wallet file" {
|
if error.to_string() == "Server error: No wallet file" {
|
||||||
// Try to open wallet
|
// Try to open wallet
|
||||||
|
|
Loading…
Reference in a new issue