Slatepack OwnerAPI Changes (#421)

* change all user-facing instances of addresses to a SlatepackAddress

* finish renaming get_slatepack_address + documentation

* get_slatepack_secret_key OwnerRPC implementation and test

* add owner api functions

* OwnerRPC functions + doctests

* add explicit slatepack API tests to exercise encryption

* update api function names to better reflect RFC
This commit is contained in:
Yeastplume
2020-05-28 08:17:51 +01:00
committed by GitHub
parent 788d050bbe
commit db12712928
16 changed files with 682 additions and 130 deletions
+2 -5
View File
@@ -19,7 +19,6 @@ extern crate grin_wallet_impls as impls;
use grin_wallet_libwallet as libwallet;
use grin_wallet_util::grin_core as core;
use grin_wallet_util::OnionV3Address;
use impls::test_framework::{self, LocalWalletClient};
use impls::{PathToSlate, SlateGetter as _, SlatePutter as _};
@@ -253,12 +252,10 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
let mut slate = Slate::blank(2, true);
let mut address = None;
wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
address = Some(api.get_public_proof_address(m, 0)?);
address = Some(api.get_slatepack_address(m, 0)?);
Ok(())
})?;
let address = OnionV3Address::from_bytes(address.as_ref().unwrap().to_bytes());
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
// send to send
let args = InitTxArgs {
@@ -268,7 +265,7 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
payment_proof_recipient_address: Some(address.clone()),
payment_proof_recipient_address: address.clone(),
..Default::default()
};
let slate = api.init_send_tx(m, args)?;
+3 -6
View File
@@ -25,8 +25,6 @@ use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
use grin_wallet_util::OnionV3Address;
#[macro_use]
mod common;
use common::{clean_output_dir, create_wallet_proxy, setup};
@@ -80,11 +78,10 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
let mut address = None;
wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
address = Some(api.get_public_proof_address(m, 0)?);
address = Some(api.get_slatepack_address(m, 0)?);
Ok(())
})?;
let address = OnionV3Address::from_bytes(address.as_ref().unwrap().to_bytes());
println!("Public address is: {:?}", address);
let amount = 60_000_000_000;
let mut slate = Slate::blank(1, false);
@@ -97,14 +94,14 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
payment_proof_recipient_address: Some(address.clone()),
payment_proof_recipient_address: address.clone(),
..Default::default()
};
let slate_i = sender_api.init_send_tx(m, args)?;
assert_eq!(
slate_i.payment_proof.as_ref().unwrap().receiver_address,
address.to_ed25519()?,
address.as_ref().unwrap().pub_key,
);
println!(
"Sender addr: {:?}",
+80 -7
View File
@@ -19,7 +19,6 @@ extern crate grin_wallet_impls as impls;
use grin_wallet_libwallet as libwallet;
use grin_wallet_util::grin_core as core;
use grin_wallet_util::OnionV3Address;
use impls::test_framework::{self, LocalWalletClient};
use impls::{PathToSlatepack, SlatePutter as _};
@@ -152,7 +151,7 @@ fn slatepack_exchange_test_impl(
let mut rec_address = SlatepackAddress::random();
let mut sec_key = edDalekSecretKey::from_bytes(&[0u8; 32]).unwrap();
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
sec_key = api.get_secret_key(m, 0)?;
sec_key = api.get_slatepack_secret_key(m, 0)?;
let pub_key = edDalekPublicKey::from(&sec_key);
rec_address = SlatepackAddress::new(&pub_key);
Ok(())
@@ -171,7 +170,7 @@ fn slatepack_exchange_test_impl(
let mut rec_address = SlatepackAddress::random();
let mut sec_key = edDalekSecretKey::from_bytes(&[0u8; 32]).unwrap();
wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
sec_key = api.get_secret_key(m, 0)?;
sec_key = api.get_slatepack_secret_key(m, 0)?;
let pub_key = edDalekPublicKey::from(&sec_key);
rec_address = SlatepackAddress::new(&pub_key);
Ok(())
@@ -379,12 +378,10 @@ fn slatepack_exchange_test_impl(
let mut slate = Slate::blank(2, true);
let mut address = None;
wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
address = Some(api.get_public_proof_address(m, 0)?);
address = Some(api.get_slatepack_address(m, 0)?);
Ok(())
})?;
let address = OnionV3Address::from_bytes(address.as_ref().unwrap().to_bytes());
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
// send to send
let args = InitTxArgs {
@@ -394,7 +391,7 @@ fn slatepack_exchange_test_impl(
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
payment_proof_recipient_address: Some(address.clone()),
payment_proof_recipient_address: address.clone(),
..Default::default()
};
let slate = api.init_send_tx(m, args)?;
@@ -447,6 +444,71 @@ fn slatepack_exchange_test_impl(
Ok(())
}
/// Exercise slate encryption/decryption via the API,
/// Since doctests don't cover encryption
fn slatepack_api_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
// Create a new wallet test client, and set its queues to communicate with the
// proxy
create_wallet_and_add!(
client1,
wallet1,
mask1_i,
test_dir,
"wallet1",
None,
&mut wallet_proxy,
false
);
let mask1 = (&mask1_i).as_ref();
// Set the wallet proxy listener running
thread::spawn(move || {
if let Err(e) = wallet_proxy.run() {
error!("Wallet Proxy error: {}", e);
}
});
// few values to keep things shorter
let reward = core::consensus::REWARD;
// Get some mining done
let bh = 6u64;
let _ =
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let args = InitTxArgs {
src_acct_name: Some("mining".to_owned()),
amount: reward * 2,
minimum_confirmations: 2,
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
..Default::default()
};
let slate = api.init_send_tx(m, args)?;
// create an encrypted slatepack (just encrypted for self)
let enc_addr = api.get_slatepack_address(m, 0)?;
let slatepack = api.create_slatepack_message(m, &slate, Some(0), vec![enc_addr])?;
println!("{}", slatepack);
let slatepack_raw = api.decode_slatepack_message(slatepack.clone())?;
println!("{}", slatepack_raw);
let decoded_slate = api.slate_from_slatepack_message(m, slatepack, vec![0])?;
println!("{}", decoded_slate);
Ok(())
})?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}
#[test]
fn slatepack_exchange_json() {
let test_dir = "test_output/slatepack_exchange_json";
@@ -512,3 +574,14 @@ fn slatepack_exchange_armored_enc() {
}
clean_output_dir(test_dir);
}
#[test]
fn slatepack_api() {
let test_dir = "test_output/slatepack_api";
setup(test_dir);
// Json output
if let Err(e) = slatepack_api_impl(test_dir) {
panic!("Libwallet Error: {} - {}", e, e.backtrace().unwrap());
}
clean_output_dir(test_dir);
}