mirror of
https://github.com/mimblewimble/mwixnet.git
synced 2025-01-20 19:11:09 +03:00
improving documentation and error handling
This commit is contained in:
parent
115e0d2022
commit
8cf41e4730
4 changed files with 47 additions and 11 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -5,3 +5,5 @@ target
|
||||||
*.iml
|
*.iml
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
mwixnet-config.toml
|
14
README.md
14
README.md
|
@ -3,6 +3,20 @@ This is an implementation of @tromp's [CoinSwap Proposal](https://forum.grin.mw/
|
||||||
|
|
||||||
A set of n CoinSwap servers (node<sub>i</sub> with i=1...n) are agreed upon in advance. They each have a known public key.
|
A set of n CoinSwap servers (node<sub>i</sub> with i=1...n) are agreed upon in advance. They each have a known public key.
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
#### init-config
|
||||||
|
To setup a new server, run `mwixnet --pass "server-password-here" init-config`.
|
||||||
|
This will generate a key for the server and then create a new config file named `mwixnet-config.toml` in the current working directory.
|
||||||
|
The configuration file will contain the private key of the server encrypted with the server password you provided.
|
||||||
|
|
||||||
|
**Back this config file up! It's the only copy of the server's private key!**
|
||||||
|
|
||||||
|
#### Wallet
|
||||||
|
A grin-wallet account must be created for receiving extra mwixnet fees.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
With your wallet and fully synced node both online and listening at the addresses configured, the mwixnet server can be started by running `mwixnet --pass "server-password-here" --wallet_pass "wallet-password-here"`
|
||||||
|
|
||||||
### SWAP API
|
### SWAP API
|
||||||
The first CoinSwap server (n<sub>1</sub>) provides the `swap` API, publicly available for use by GRIN wallets.
|
The first CoinSwap server (n<sub>1</sub>) provides the `swap` API, publicly available for use by GRIN wallets.
|
||||||
|
|
||||||
|
|
|
@ -14,22 +14,31 @@ use std::path::PathBuf;
|
||||||
// The decrypted server config to be passed around and used by the rest of the mwixnet code
|
// The decrypted server config to be passed around and used by the rest of the mwixnet code
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||||
pub struct ServerConfig {
|
pub struct ServerConfig {
|
||||||
|
/// private key used by the server to decrypt onion packets
|
||||||
pub key: SecretKey,
|
pub key: SecretKey,
|
||||||
|
/// interval (in seconds) to wait before each mixing round
|
||||||
pub interval_s: u32,
|
pub interval_s: u32,
|
||||||
|
/// socket address the server listener should bind to
|
||||||
pub addr: SocketAddr,
|
pub addr: SocketAddr,
|
||||||
|
/// foreign api address of the grin node
|
||||||
pub grin_node_url: SocketAddr,
|
pub grin_node_url: SocketAddr,
|
||||||
|
/// owner api address of the grin wallet
|
||||||
pub wallet_owner_url: SocketAddr,
|
pub wallet_owner_url: SocketAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encrypted server key, for storing on disk and decrypting with provided password
|
/// Encrypted server key, for storing on disk and decrypting with a password.
|
||||||
|
/// Includes a salt used by key derivation and a nonce used when sealing the encrypted data.
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||||
struct EncryptedServerKey {
|
struct EncryptedServerKey {
|
||||||
encrypted_key: String,
|
encrypted_key: String,
|
||||||
pub salt: String,
|
salt: String,
|
||||||
pub nonce: String,
|
nonce: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptedServerKey {
|
impl EncryptedServerKey {
|
||||||
|
/// Generates a random salt for pbkdf2 key derivation and a random nonce for aead sealing.
|
||||||
|
/// Then derives an encryption key from the password and salt. Finally, it encrypts and seals
|
||||||
|
/// the server key with chacha20-poly1305 using the derived key and random nonce.
|
||||||
pub fn from_secret_key(
|
pub fn from_secret_key(
|
||||||
server_key: &SecretKey,
|
server_key: &SecretKey,
|
||||||
password: &ZeroingString,
|
password: &ZeroingString,
|
||||||
|
@ -104,13 +113,13 @@ impl EncryptedServerKey {
|
||||||
/// The config attributes saved to disk
|
/// The config attributes saved to disk
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||||
struct RawConfig {
|
struct RawConfig {
|
||||||
pub encrypted_key: String,
|
encrypted_key: String,
|
||||||
pub salt: String,
|
salt: String,
|
||||||
pub nonce: String,
|
nonce: String,
|
||||||
pub interval_s: u32,
|
interval_s: u32,
|
||||||
pub addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
pub grin_node_url: SocketAddr,
|
grin_node_url: SocketAddr,
|
||||||
pub wallet_owner_url: SocketAddr,
|
wallet_owner_url: SocketAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes the server config to the config_path given, encrypting the server_key first.
|
/// Writes the server config to the config_path given, encrypting the server_key first.
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -6,6 +6,7 @@ use wallet::HttpWallet;
|
||||||
use clap::App;
|
use clap::App;
|
||||||
use grin_util::{StopState, ZeroingString};
|
use grin_util::{StopState, ZeroingString};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::io::{self, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -26,7 +27,16 @@ mod wallet;
|
||||||
|
|
||||||
const DEFAULT_INTERVAL: u32 = 12 * 60 * 60;
|
const DEFAULT_INTERVAL: u32 = 12 * 60 * 60;
|
||||||
|
|
||||||
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
fn main() {
|
||||||
|
if let Err(e) = real_main() {
|
||||||
|
io::stderr().write_all(format!("mwixnet server exited with error:\n{}\n", e).as_bytes()).unwrap();
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn real_main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||||
let yml = load_yaml!("../mwixnet.yml");
|
let yml = load_yaml!("../mwixnet.yml");
|
||||||
let args = App::from_yaml(yml).get_matches();
|
let args = App::from_yaml(yml).get_matches();
|
||||||
|
|
||||||
|
@ -61,6 +71,7 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||||
};
|
};
|
||||||
|
|
||||||
config::write_config(&config_path, &server_config, &password)?;
|
config::write_config(&config_path, &server_config, &password)?;
|
||||||
|
println!("Config file written to {:?}. Please back this file up in a safe place.", config_path);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue