Skip to content

Commit

Permalink
Exposed transaction signing to Wasm, bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
izolyomi committed Sep 4, 2020
1 parent 96569d1 commit b0a2c9e
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 30 deletions.
28 changes: 8 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion morpheus-core-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crate-type = ["rlib", "cdylib"]
[dependencies]
chrono = "*"
failure = "*"
iop-keyvault = "0.0.2"
iop-keyvault = "0.0.4"
iop-morpheus-core = "0.0.2"
log = "*"
serde_json = { version = "*", features = ["preserve_order"] }
Expand Down
2 changes: 1 addition & 1 deletion morpheus-core-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use iop_morpheus_core::{
sign::*,
},
data::{claim::*, did::*, diddoc::*, present::*, validation::*},
hydra::{crypto::HydraSigner, transaction::TransactionData},
hydra::{sign::HydraSigner, transaction::TransactionData},
};

use crate::ffi::{convert, *};
Expand Down
4 changes: 2 additions & 2 deletions morpheus-core-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
failure = "*"
iop-keyvault = "0.0.2"
iop-keyvault-wasm = "0.0.2"
iop-keyvault = "0.0.4"
iop-keyvault-wasm = "0.0.4"
iop-morpheus-core = "0.0.2"
js-sys = "*"
log = "*"
Expand Down
1 change: 1 addition & 0 deletions morpheus-core-wasm/src/hydra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod parameters;
mod plugin;
mod private;
mod public;
mod sign;
mod tx;

pub use parameters::*;
Expand Down
36 changes: 36 additions & 0 deletions morpheus-core-wasm/src/hydra/sign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use super::*;

use iop_keyvault::secp256k1::SecpPrivateKey;
use iop_morpheus_core::hydra::sign::HydraSigner;

#[wasm_bindgen(js_name = HydraSigner)]
pub struct JsHydraSigner {
inner: SecpPrivateKey,
}

#[wasm_bindgen(js_class = HydraSigner)]
impl JsHydraSigner {
#[wasm_bindgen(constructor)]
pub fn new(inner: JsSecpPrivateKey) -> JsHydraSigner {
inner.inner().to_owned().into()
}

#[wasm_bindgen(js_name = signHydraTransaction)]
pub fn sign_hydra_transaction(&self, transaction: &JsValue) -> Result<JsValue, JsValue> {
let mut tx = transaction.into_serde().map_err_to_js()?;
self.inner.sign_hydra_transaction(&mut tx).map_err_to_js()?;
JsValue::from_serde(&tx).map_err_to_js()
}
}

impl From<SecpPrivateKey> for JsHydraSigner {
fn from(inner: SecpPrivateKey) -> Self {
Self { inner }
}
}

impl Wraps<SecpPrivateKey> for JsHydraSigner {
fn inner(&self) -> &SecpPrivateKey {
&self.inner
}
}
1 change: 1 addition & 0 deletions morpheus-core-wasm/src/hydra/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl JsHydraTxBuilder {
self.create_vote_tx(delegate, sender_pubkey, nonce, hyd_core::Transaction::unvote)
}

#[wasm_bindgen(js_name = registerDelegate)]
pub fn register_delegate(
&self, sender_pubkey: &JsSecpPublicKey, delegate_name: &str, nonce: u64,
) -> Result<JsValue, JsValue> {
Expand Down
2 changes: 1 addition & 1 deletion morpheus-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
anyhow = "*"
chrono = { version = "*", features = ["wasmbind"] }
failure = "*"
iop-keyvault = "0.0.2"
iop-keyvault = "0.0.4"
jwt-compact = { version = "*", default-features = false }
log = "*"
multibase = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion morpheus-core/src/crypto/hd/hydra/private.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

use crate::hydra::crypto::HydraSigner;
use crate::hydra::sign::HydraSigner;

pub struct Private {
state: Box<dyn State<PublicState>>,
Expand Down
2 changes: 1 addition & 1 deletion morpheus-core/src/hydra/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod crypto;
pub mod serializer;
pub mod sign;
pub mod transaction;
pub mod txtype;

Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion morpheus-core/src/hydra/txtype/hyd_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ impl Aip29Transaction for Transaction {

let mut tx_data: TransactionData = self.common_fields.to_data();
tx_data.set_type(crate::hydra::txtype::TransactionType::Core(self.tx_type));
tx_data.asset = Some(crate::hydra::txtype::Asset::Core(self.asset.to_owned()));
tx_data.asset = if self.asset.is_none() {
None
} else {
Some(crate::hydra::txtype::Asset::Core(self.asset.to_owned()))
};
tx_data.recipient_id = self.recipient_id.as_ref().map(|addr| addr.to_p2pkh_addr(prefix));
tx_data.fee = self.common_fields.calculate_fee(self).to_string();
tx_data
Expand Down
2 changes: 1 addition & 1 deletion morpheus-core/src/hydra/txtype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod test {
use crate::data::{auth::Authentication, did::Did, diddoc::Right};
use crate::hydra::txtype::morpheus::OperationAttempt;
use crate::hydra::{
crypto::HydraSigner,
sign::HydraSigner,
transaction::{TransactionData, TxBatch},
txtype::{hyd_core, morpheus, Aip29Transaction, CommonTransactionFields},
};
Expand Down
2 changes: 1 addition & 1 deletion morpheus-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async-trait = "*"
failure = "*"
futures = "*"
hyper = "*"
iop-keyvault = "0.0.2"
iop-keyvault = "0.0.4"
iop-morpheus-core = "0.0.2"
log = "*"
multihash = "*"
Expand Down

0 comments on commit b0a2c9e

Please sign in to comment.