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

Refactor Crypto and UnlockBlock #104

Merged
merged 12 commits into from
Dec 24, 2020
3 changes: 3 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ thiserror = "1.0"
futures = "0.3"
riker = "0.4"

bee-signing-ext = { git = "https://github.com/wusyong/bee-p.git", branch = "sign-ext", version = "^0.1.0-alpha" }

[dependencies.stronghold-engine]
path = "../engine"

Expand All @@ -40,6 +42,7 @@ criterion = "0.3.3"

clap = { version = "3.0.0-beta.1", features = ["yaml"] }


[[bench]]
name = "benchmark"
harness = false
30 changes: 19 additions & 11 deletions client/src/actors/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ pub enum Procedure {
/// passphrase) and store them in the `output` location
BIP39MnemonicSentence { seed: Location },
/// Derive the Ed25519 public key of the key stored at the specified location
Ed25519PublicKey { key: Location },
Ed25519PublicKey { path: String, key: Location },
/// Generate the Ed25519 signature of the given message signed by the specified key
Ed25519Sign { key: Location, msg: Vec<u8> },
Ed25519Sign { path: String, key: Location, msg: Vec<u8> },
/// Derive a SLIP10 key from a SLIP10/BIP39 seed using path, sign the essence using Ed25519, return the signature
/// and the corresponding public key
///
/// This is equivalent to separate calls to SLIP10Derive, Ed25519PublicKey, and Ed25519Sign but
/// does not store the derived key.
SignUnlockBlock {
seed: Location,
path: hd::Chain,
path: String,
essence: Vec<u8>,
},
}
Expand All @@ -81,7 +81,7 @@ pub enum ProcResult {
/// Return from generating a `SLIP10` seed.
SLIP10Generate(StatusMessage),
/// Returns the public key derived from the `SLIP10Derive` call.
SLIP10Derive(ResultMessage<hd::Key>),
SLIP10Derive(StatusMessage),
/// `BIP39Recover` return value.
BIP39Recover(StatusMessage),
/// `BIP39Generate` return value.
Expand All @@ -94,8 +94,10 @@ pub enum ProcResult {
Ed25519Sign(ResultMessage<[u8; crypto::ed25519::SIGNATURE_LENGTH]>),
/// Return value for `SignUnlockBlock`. Returns a Ed25519 signature and a Ed25519 public key.
SignUnlockBlock(
ResultMessage<[u8; crypto::ed25519::SIGNATURE_LENGTH]>,
ResultMessage<[u8; crypto::ed25519::COMPRESSED_PUBLIC_KEY_LENGTH]>,
ResultMessage<(
[u8; crypto::ed25519::SIGNATURE_LENGTH],
[u8; crypto::ed25519::COMPRESSED_PUBLIC_KEY_LENGTH],
)>,
),
}

Expand Down Expand Up @@ -396,7 +398,6 @@ impl Receive<SHRequest> for Client {
ensure_vault_exists!(seed_vault_id, SLIP10Derive, "seed");

let (key_vault_id, key_record_id) = self.resolve_location(output, ReadWrite::Write);
ensure_vault_exists!(key_vault_id, SLIP10Derive, "key");

if !self.vault_exist(key_vault_id) {
self.add_new_vault(key_vault_id);
Expand Down Expand Up @@ -429,7 +430,6 @@ impl Receive<SHRequest> for Client {
ensure_vault_exists!(parent_vault_id, SLIP10Derive, "parent key");

let (child_vault_id, child_record_id) = self.resolve_location(output, ReadWrite::Write);
ensure_vault_exists!(child_vault_id, SLIP10Derive, "child key");

if !self.vault_exist(child_vault_id) {
self.add_new_vault(child_vault_id);
Expand Down Expand Up @@ -507,14 +507,22 @@ impl Receive<SHRequest> for Client {
)
}
Procedure::BIP39MnemonicSentence { .. } => todo!(),
Procedure::Ed25519PublicKey { key } => {
Procedure::Ed25519PublicKey { path, key } => {
let (vault_id, record_id) = self.resolve_location(key, ReadWrite::Read);
internal.try_tell(InternalMsg::Ed25519PublicKey { vault_id, record_id }, sender)
internal.try_tell(
InternalMsg::Ed25519PublicKey {
path,
vault_id,
record_id,
},
sender,
)
}
Procedure::Ed25519Sign { key, msg } => {
Procedure::Ed25519Sign { path, key, msg } => {
let (vault_id, record_id) = self.resolve_location(key, ReadWrite::Read);
internal.try_tell(
InternalMsg::Ed25519Sign {
path,
vault_id,
record_id,
msg,
Expand Down
Loading