Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New signer UI #14

Merged
merged 17 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added docs/manta-signer-state-machine.pdf
Binary file not shown.
54 changes: 54 additions & 0 deletions docs/manta-signer-state-machine.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz-cd}

\tikzcdset{row sep/normal = 3.5em}

\begin{document}

\begin{center}
\Large{\textbf{Manta Signer State Machine}}
\end{center}

\vspace{2em}

\begin{center}
% https://tikzcd.yichuanshen.de/#N4Igdg9gJgpgziAXAbVABwnAlgFyxMJZABgBoBGAXVJADcBDAGwFcYkQAdDnGADxzgAzYAGUAogCUAapIC+IWaXSZc+QigDMpAEzU6TVuy49+wAIIBjCxGZgcAAjG8scAQH55i5djwEiWjT0GFjZETm4+AWEAGQgAcywwTyUQDB81IgBWUkCaYMMw40ihYABhACcYeh57S2tbHGTvVT9NCiCDUPCTKOAAVQBJJtSVX3VkLQAWDpCjCP4SkRgwKHsABXo4OAB3CHKoYbSW8bJpvM65uABHZnpKhRSjsaIyTJmC7uKYiHpVpZgDg9ms82gAOd5dLjXW73LwjdKtEikABsELmPUWMHKtBgh1GGRQZAA7GjCvMcOZmDgABZ7LAALxgHiB8OORHIpHB51mZIxwjMVNp5QZuJZTwJSPIVG5HyKC2EIiwcSSYvxiI55GIpPC0LubDh4sRWk12rlvSWK3Wmx2e0BBrV4y0AE5TeSSmtyhAALZoRqqhEnCi6GWQjgWLDlCz+tltKWu8OR6MgpFakPoyIAIwVABUzBJs3iA-5SG807yvsAABJYWCePQAuLwIigQSer1IDkgHAQJDaGiMegZmCMNYO9iJbCwEBlz7y4AATTEImGre9HZo3aQWn0PNnvQAcgB5eT9wfD0dFsITmv6lKr9uISYbnuIchw++95+fkCMCAQNBENoRJkIITBwDAegDkOI5jleYCTmwM5miU2z0LgJ4-okXRQJs1IAiyH6INum5Ef2f4ASg5CgmQODlKwkFnjBl4gNeU5IW6wioeh06YWA2G4fh75tt+JGZEJa6kV2L5iXewmINkUlIMi7F8sA4ErBhUHnrBLHwTePGMFh7BQDYGaMIhIB4b8SBgMwjCMBuaGMOwkB8QRclkIpiDKbx-FwHhUAGYxF4xrpCE8fkoaqZUFi0BhVmBYgtn2Y5WDOWErm3i2ck+SRRLiQ+RJfogToFUgTrFZqZWvp5JFSqe0EhSCYX6SpFaLsu7kSZqlV9jusoccAR6acFOmsVlICERVXnTb+-5EE6IFgRBDXacx40RRc5Zzlxfr9kZYQ4f5gmyd1nYkaCq1MaFG1tXOaBtr6mkHSAcAQIZgWpelXZOV1D71V55DboZbmHQJn0-qN616Wx-VRRWMVxX9HZPoDwNQzdMMWZF6ZzupgL7aDIAmcwZkWQlNl2Q5P1pS5BATYRl2AwpWnXc1t1w7jvT+RA2wrnJ5AKXVkzVYLlUs+RgHAaQoGMOBDGNWNWMGS9R0BZtu7IZxaF+qLxEvuQ2ii31dXIqLuUvtNQ4rEgkylad-2o3V+UO0gtUvqjrNNQSLWwzj23c7SfM8Tgv1hKHtOi0zJHENVQsG-b2XddNF2E356tXd7rS+9jW17iUhmuMs-PdUVgNW8siUALR27IlCyEAA
\begin{tikzcd}
\textbf{START} \arrow[d] & & & & & \\
\textsf{SERVER} \arrow[ddd, "\textsf{recv}" description, dashed] \arrow[rrr, "\textsf{show}" description, tail] & & & \textsf{UI} \arrow[d] & & \\
& & & \text{Account Exists?} \arrow[d, "\textsf{YES}" description] \arrow[rrd, "\textsf{NO}" description] & & \\
& & & \textsf{Login} \arrow["\textsf{wait}" description, dashed, loop, distance=2em, in=215, out=145] \arrow[d] & & \textsf{Create Account} \arrow["\textsf{wait}" description, dashed, loop, distance=2em, in=55, out=125] \arrow[lld] \\
\square \arrow[d] & & & \textsf{Send Password} \arrow[lll, "\textsf{send}" description, Rightarrow] \arrow[d] & & \\
\textsf{Load Seed} \arrow[d] & & & \textsf{Hide} \arrow[ddd, "\textsf{listen}" description, dashed] & & \\
\textsf{Serve} \arrow[d] \arrow["\textsf{wait}" description, dashed, loop, distance=2em, in=35, out=325] & & & & & \\
\text{Authorize?} \arrow[rd, "\textsf{YES}" description] \arrow[dddd, "\textsf{NO}" description] & & & & & \\
& \textsf{Authorize} \arrow[rr, "\textsf{prompt}" description, tail] \arrow[dd, "\textsf{recv}" description, dashed] & & \square \arrow[d, "\textsf{show}" description] & & \\
& & & \textsf{Prompt} \arrow[d] \arrow["\textsf{wait}" description, dashed, loop, distance=2em, in=215, out=145] & & \\
& \square \arrow[ld] & & \textsf{Send Password} \arrow[ll, "\textsf{send}" description, Rightarrow] \arrow[d] & & \\
\textsf{Sign} \arrow[d] & & & \circ \arrow[uuuuuu, bend right=49] & & \\
\circ \arrow[uuuuuu, bend left=49] & & & & &
\end{tikzcd}
\end{center}

\vspace{2em}

\[
\square := \text{synchronization point}
\,\,\,\,\,\,\,
\circ := \text{loop}
\,\,\,\,\,\,\,
(\Rightarrow) := \text{channel}
\,\,\,\,\,\,\,
(\dasharrow) := \text{suspending}
\]

\end{document}

10 changes: 4 additions & 6 deletions examples/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
use async_std::io;
use manta_signer::{
config::Config,
secret::{
create_account, sample_password, Authorization, Authorizer, AuthorizerSetup, Password,
SecretString,
},
secret::{create_account, sample_password, Authorizer, Password, PasswordFuture, SecretString},
service::Service,
};
use rand::thread_rng;
Expand All @@ -44,16 +41,17 @@ impl MockUser {

impl Authorizer for MockUser {
#[inline]
fn setup<'s>(&'s mut self, config: &'s Config) -> AuthorizerSetup<'s> {
fn setup<'s>(&'s mut self, config: &'s Config) -> PasswordFuture<'s> {
Box::pin(async move {
let _ = create_account(&config.root_seed_file, &self.password)
.await
.expect("Unable to create account for a mock user.");
Password::from_known(self.password.clone())
})
}

#[inline]
fn authorize<T>(&mut self, prompt: T) -> Authorization
fn authorize<T>(&mut self, prompt: T) -> PasswordFuture
where
T: Serialize,
{
Expand Down
21 changes: 9 additions & 12 deletions src/batching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use manta_api::{
GeneratePrivateTransferParams, GenerateReclaimBatchParams, GenerateReclaimParams,
MantaRootSeed, PrivateTransferBatch, ReclaimBatch,
};
use manta_asset::{AssetId, MantaAsset, MantaAssetShieldedAddress, Process, Sampling};
use manta_asset::{AssetId, MantaAsset, MantaAssetShieldedAddress, Process};
use manta_crypto::{commitment_parameters, leaf_parameters, two_to_one_parameters, Groth16Pk};
use manta_data::{BuildMetadata, PrivateTransferData, ReclaimData};
use rand::{CryptoRng, RngCore};
Expand Down Expand Up @@ -100,7 +100,7 @@ where
{
let private_transfer_pk = load_proving_key(private_transfer_pk_path).await;
let reclaim_pk = load_proving_key(reclaim_pk_path).await;
let asset_id = params.asset_id;
let asset_id = params.reclaim_params.asset_id;
ReclaimBatch {
reclaim_data: generate_reclaim_data(
params.reclaim_params,
Expand Down Expand Up @@ -177,23 +177,21 @@ where
None => manta_api::derive_shielded_address(
DeriveShieldedAddressParams {
keypath: params.non_change_output_keypath.unwrap(),
asset_id,
},
root_seed,
),
};
let non_change_processed_receiver = non_change_receiving_address
.process(&params.non_change_output_value, rng)
.process(asset_id, params.non_change_output_value, rng)
.expect("Failed to process receiver 1 shielded address");
let change_address = manta_api::derive_shielded_address(
DeriveShieldedAddressParams {
keypath: params.change_output_keypath,
asset_id,
},
root_seed,
);
let change_processed_receiver = change_address
.process(&params.change_output_value, rng)
.process(asset_id, params.change_output_value, rng)
.expect("Failed to process receiver 2 shielded address");
manta_api::generate_private_transfer_struct(
commit_params,
Expand Down Expand Up @@ -256,14 +254,13 @@ where
let change_address = manta_api::derive_shielded_address(
DeriveShieldedAddressParams {
keypath: params.change_keypath,
asset_id,
},
root_seed,
);
let change_value =
params.input_asset_1_value + params.input_asset_2_value - params.reclaim_value;
let change_processed_receiver = change_address
.process(&change_value, rng)
.process(asset_id, change_value, rng)
.expect("Failed to build processed receiver");
manta_api::generate_reclaim_struct(
commit_params,
Expand All @@ -290,11 +287,11 @@ pub fn generate_asset(params: GenerateAssetParams, root_seed: &MantaRootSeed) ->
.to_bytes()
.try_into()
.unwrap();
MantaAsset::sample(
MantaAsset::new(
asset_secret_key,
&commitment_parameters(),
&asset_secret_key,
&params.asset_id,
&params.value,
params.asset_id,
params.value,
)
.expect("Failed to sample asset")
}
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl Config {
Some(Self {
root_seed_file: file(dirs_next::config_dir(), "root_seed.aes")?,
proving_key_directory: directory(dirs_next::data_local_dir())?,
service_url: String::from("http://localhost:29987"),
origin_url: String::from("http://localhost:8000"),
service_url: String::from("http://127.0.0.1:29987"),
origin_url: String::from("http://127.0.0.1:8000"),
})
}

Expand Down
24 changes: 11 additions & 13 deletions src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,19 @@ impl Default for Password {
}
}

/// Authorizer Setup Future
/// Password Future
///
/// This `type` is returned by the [`setup`](Authorizer::setup) method on [`Authorizer`].
/// See its documentation for more.
pub type AuthorizerSetup<'t> = BoxFuture<'t, ()>;

/// Authorization Future
/// This `type` is returned by the [`authorize`] and [`setup`] methods on [`Authorizer`].
/// See their documentation for more.
///
/// This `type` is returned by the [`authorize`](Authorizer::authorize) method on [`Authorizer`].
/// See its documentation for more.
pub type Authorization<'t> = BoxFuture<'t, Password>;
/// [`authorize`]: Authorizer::authorize
/// [`setup`]: Authorizer::setup
pub type PasswordFuture<'t> = BoxFuture<'t, Password>;

/// Authorizer
pub trait Authorizer {
/// Runs some setup for the authorizer using the `config`.
/// Runs some setup for the authorizer using the `config`, returning a [`Password`] if already
/// known during setup.
///
/// # Implementation Note
///
Expand All @@ -107,13 +105,13 @@ pub trait Authorizer {
/// [`Service`]: crate::service::Service
/// [`Service::serve`]: crate::service::Service::serve
#[inline]
fn setup<'s>(&'s mut self, config: &'s Config) -> AuthorizerSetup<'s> {
fn setup<'s>(&'s mut self, config: &'s Config) -> PasswordFuture<'s> {
let _ = config;
Box::pin(async move {})
Box::pin(async move { Password::from_unknown() })
}

/// Shows the given `prompt` to the authorizer, requesting their password.
fn authorize<T>(&mut self, prompt: T) -> Authorization
fn authorize<T>(&mut self, prompt: T) -> PasswordFuture
where
T: Serialize;
}
Expand Down