From f59ed47b1b78f891466f3100666afabb2209c8f8 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Mon, 14 Oct 2019 12:56:38 +0200 Subject: [PATCH 01/13] Aura: Report malice on sibling blocks from the same validator (#11160) * Aura: Report malice on sibling blocks from the same validator This was originally written by @vkomenda, then squashed for easier rebasing on master. Cleanup of `received_step_hashes` was moved to `verify_block_family`, since `on_prepare_block` does not exist on master, and a unit test was added. Original commit messages: added the map of received block header hashes do not return an error and remove older received block records optimised older record removal block hash comparison optimisation and the weak client ref fix SIBLING_MALICE_DETECTION_PERIOD constant review comments using step numbers instead of block numbers * Add docs; use map_or. * Update step hash record comment. Co-Authored-By: David * Remove hash records after 2 rounds instead of 100 steps. --- ethcore/engines/authority-round/src/lib.rs | 70 +++++++++++++++++++++- ethcore/engines/validator-set/src/test.rs | 14 ++++- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/ethcore/engines/authority-round/src/lib.rs b/ethcore/engines/authority-round/src/lib.rs index 99ee36b7826..2f4202f168e 100644 --- a/ethcore/engines/authority-round/src/lib.rs +++ b/ethcore/engines/authority-round/src/lib.rs @@ -19,6 +19,17 @@ //! It is recommended to use the `two_thirds_majority_transition` option, to defend against the //! ["Attack of the Clones"](https://arxiv.org/pdf/1902.10244.pdf). Newly started networks can //! set this option to `0`, to use a 2/3 quorum from the beginning. +//! +//! To support on-chain governance, the [ValidatorSet] is pluggable: Aura supports simple +//! constant lists of validators as well as smart contract-based dynamic validator sets. +//! Misbehavior is reported to the [ValidatorSet] as well, so that e.g. governance contracts +//! can penalize or ban attacker's nodes. +//! +//! * "Benign" misbehavior are faults that can happen in normal operation, like failing +//! to propose a block in your slot, which could be due to a temporary network outage, or +//! wrong timestamps (due to out-of-sync clocks). +//! * "Malicious" reports are made only if the sender misbehaved deliberately (or due to a +//! software bug), e.g. if they proposed multiple blocks with the same step number. use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::{cmp, fmt}; @@ -482,6 +493,8 @@ pub struct AuthorityRound { two_thirds_majority_transition: BlockNumber, maximum_empty_steps: usize, machine: Machine, + /// History of step hashes recently received from peers. + received_step_hashes: RwLock>, } // header-chain validator. @@ -572,7 +585,7 @@ fn header_expected_seal_fields(header: &Header, empty_steps_transition: u64) -> fn header_step(header: &Header, empty_steps_transition: u64) -> Result { Rlp::new(&header.seal().get(0).unwrap_or_else(|| - panic!("was either checked with verify_block_basic or is genesis; has {} fields; qed (Make sure the spec + panic!("was either checked with verify_block_basic or is genesis; has {} fields; qed (Make sure the spec \ file has a correct genesis seal)", header_expected_seal_fields(header, empty_steps_transition)) )) .as_val() @@ -751,6 +764,7 @@ impl AuthorityRound { two_thirds_majority_transition: our_params.two_thirds_majority_transition, strict_empty_steps_transition: our_params.strict_empty_steps_transition, machine, + received_step_hashes: RwLock::new(Default::default()), }); // Do not initialize timeouts for tests. @@ -1377,6 +1391,26 @@ impl Engine for AuthorityRound { Err(EngineError::DoubleVote(*header.author()))?; } + // Report malice if the validator produced other sibling blocks in the same step. + let received_step_key = (step, *header.author()); + let new_hash = header.hash(); + if self.received_step_hashes.read().get(&received_step_key).map_or(false, |h| *h != new_hash) { + trace!(target: "engine", "Validator {} produced sibling blocks in the same step", header.author()); + self.validators.report_malicious(header.author(), set_number, header.number(), Default::default()); + } else { + self.received_step_hashes.write().insert(received_step_key, new_hash); + } + + // Remove hash records older than two full rounds of steps (picked as a reasonable trade-off between + // memory consumption and fault-tolerance). + let sibling_malice_detection_period = 2 * validators.count(&parent.hash()) as u64; + let oldest_step = parent_step.saturating_sub(sibling_malice_detection_period); + if oldest_step > 0 { + let mut rsh = self.received_step_hashes.write(); + let new_rsh = rsh.split_off(&(oldest_step, Address::zero())); + *rsh = new_rsh; + } + // If empty step messages are enabled we will validate the messages in the seal, missing messages are not // reported as there's no way to tell whether the empty step message was never sent or simply not included. let empty_steps_len = if header.number() >= self.empty_steps_transition { @@ -1936,8 +1970,6 @@ mod tests { #[test] fn reports_skipped() { - let _ = ::env_logger::try_init(); - let validator1 = Address::from_low_u64_be(1); let validator2 = Address::from_low_u64_be(2); let last_benign = Arc::new(AtomicUsize::new(0)); @@ -1980,6 +2012,38 @@ mod tests { assert_eq!(last_benign.load(AtomicOrdering::SeqCst), 2); } + #[test] + fn reports_multiple_blocks_per_step() { + let tap = AccountProvider::transient_provider(); + let addr0 = tap.insert_account(keccak("0").into(), &"0".into()).unwrap(); + let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); + + let validator_set = TestSet::from_validators(vec![addr0, addr1]); + let aura = build_aura(|p| p.validators = Box::new(validator_set.clone())); + + aura.set_signer(Some(Box::new((Arc::new(tap), addr0, "0".into())))); + + let mut parent_header: Header = Header::default(); + parent_header.set_number(2); + parent_header.set_seal(vec![encode(&1usize)]); + parent_header.set_gas_limit("222222".parse::().unwrap()); + let mut header: Header = Header::default(); + header.set_number(3); + header.set_difficulty(calculate_score(1, 2, 0)); + header.set_gas_limit("222222".parse::().unwrap()); + header.set_seal(vec![encode(&2usize)]); + header.set_author(addr1); + + // First sibling block. + assert!(aura.verify_block_family(&header, &parent_header).is_ok()); + assert_eq!(validator_set.last_malicious(), 0); + + // Second sibling block: should be reported. + header.set_gas_limit("222223".parse::().unwrap()); + assert!(aura.verify_block_family(&header, &parent_header).is_ok()); + assert_eq!(validator_set.last_malicious(), 3); + } + #[test] fn test_uncles_transition() { let aura = build_aura(|params| { diff --git a/ethcore/engines/validator-set/src/test.rs b/ethcore/engines/validator-set/src/test.rs index 0198c2d5b75..4293542b4e9 100644 --- a/ethcore/engines/validator-set/src/test.rs +++ b/ethcore/engines/validator-set/src/test.rs @@ -36,7 +36,7 @@ use parity_bytes::Bytes; use super::{ValidatorSet, SimpleList}; /// Set used for testing with a single validator. -#[derive(MallocSizeOf, Debug)] +#[derive(Clone, MallocSizeOf, Debug)] pub struct TestSet { validator: SimpleList, #[ignore_malloc_size_of = "zero sized"] @@ -63,6 +63,18 @@ impl TestSet { last_benign, } } + + pub fn from_validators(validators: Vec
) -> Self { + TestSet::new(Default::default(), Default::default(), validators) + } + + pub fn last_malicious(&self) -> usize { + self.last_malicious.load(AtomicOrdering::SeqCst) + } + + pub fn last_benign(&self) -> usize { + self.last_benign.load(AtomicOrdering::SeqCst) + } } impl ValidatorSet for TestSet { From 6b57429d724c954ad5d64c1b1d42c746f8a4d08e Mon Sep 17 00:00:00 2001 From: Boqin Qin Date: Wed, 16 Oct 2019 06:03:48 -0400 Subject: [PATCH 02/13] ethcore client: fix a double Read Lock bug in fn Client::logs() (#11172) --- ethcore/src/client/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 04e7074f1d2..30c5ba02080 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -2038,7 +2038,7 @@ impl BlockChainClient for Client { blocks }; - Ok(self.chain.read().logs(blocks, |entry| filter.matches(entry), filter.limit)) + Ok(chain.logs(blocks, |entry| filter.matches(entry), filter.limit)) } fn filter_traces(&self, filter: TraceFilter) -> Option> { From f99819d32679fdce1f4231453c370ea240a99c58 Mon Sep 17 00:00:00 2001 From: Boqin Qin Date: Thu, 17 Oct 2019 04:59:37 -0400 Subject: [PATCH 03/13] util Host: fix a double Read Lock bug in fn Host::session_readable() (#11175) --- util/network-devp2p/src/host.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/util/network-devp2p/src/host.rs b/util/network-devp2p/src/host.rs index a16f9625229..27949839f41 100644 --- a/util/network-devp2p/src/host.rs +++ b/util/network-devp2p/src/host.rs @@ -842,6 +842,7 @@ impl Host { if duplicate { trace!(target: "network", "Rejected duplicate connection: {}", token); session.lock().disconnect(io, DisconnectReason::DuplicatePeer); + drop(handlers); self.kill_connection(token, io, false); return; } From 9c8b7c23d173f3a768550f956d0e0f34a9a74ae2 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Thu, 17 Oct 2019 14:02:41 +0200 Subject: [PATCH 04/13] [ethash] chainspec validate `ecip1017EraRounds` non-zero (#11123) * [ethash]: validate `ecip1017EraRounds` non-zero When `ecip1017EraRounds` ethash will divide by zero. This commit ensures that the chainspec deserialization fails and gives a better error message. * [ecip1017_eras_block_reward]: document behaviour * nit * docs(ethash ecip1071): resolve `TODO` --- ethcore/engines/ethash/src/lib.rs | 11 ++++++++++- json/src/spec/ethash.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ethcore/engines/ethash/src/lib.rs b/ethcore/engines/ethash/src/lib.rs index bd901ef888a..acac922fdbc 100644 --- a/ethcore/engines/ethash/src/lib.rs +++ b/ethcore/engines/ethash/src/lib.rs @@ -464,7 +464,16 @@ impl Ethash { } } -fn ecip1017_eras_block_reward(era_rounds: u64, mut reward: U256, block_number:u64) -> (u64, U256) { + +/// Calculates the number of eras and reward +/// +/// # Panics +/// +/// This function will panic if `era_rounds` is less than `2` +fn ecip1017_eras_block_reward(era_rounds: u64, mut reward: U256, block_number: u64) -> (u64, U256) { + // NOTE(niklasad1): all numbers is divisible by 1, it will cause the if below + // to succeed except for the first block. Thus, `era_rounds - 1 == 0` and cause `divide by zero` + assert!(era_rounds > 1, "ecip1017EraRounds must be bigger than 1"); let eras = if block_number != 0 && block_number % era_rounds == 0 { block_number / era_rounds - 1 } else { diff --git a/json/src/spec/ethash.rs b/json/src/spec/ethash.rs index eee44d02bf1..2db6892751f 100644 --- a/json/src/spec/ethash.rs +++ b/json/src/spec/ethash.rs @@ -91,6 +91,7 @@ pub struct EthashParams { pub ecip1010_continue_transition: Option, /// See main EthashParams docs. + #[serde(default, deserialize_with="uint::validate_optional_non_zero")] pub ecip1017_era_rounds: Option, /// Delays of difficulty bombs. @@ -101,7 +102,6 @@ pub struct EthashParams { /// EXPIP-2 duration limit pub expip2_duration_limit: Option, /// Block to transition to progpow - #[serde(rename="progpowTransition")] pub progpow_transition: Option, } From ff697b64b365e3f6c3a32692428fb347638a8ffa Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Fri, 18 Oct 2019 12:12:06 +0200 Subject: [PATCH 05/13] TxPermissions ver 3: gas price & data (#11170) --- ethcore/machine/res/tx_acl_gas_price.json | 83 +++++++++++++++++++ ethcore/machine/src/tx_filter.rs | 63 +++++++++++++- .../tx_permission_tests/contract_ver_3.sol | 60 ++++++++++++++ .../contract_ver_3_genesis.json | 44 ++++++++++ 4 files changed, 247 insertions(+), 3 deletions(-) create mode 100644 ethcore/machine/res/tx_acl_gas_price.json create mode 100644 ethcore/res/tx_permission_tests/contract_ver_3.sol create mode 100644 ethcore/res/tx_permission_tests/contract_ver_3_genesis.json diff --git a/ethcore/machine/res/tx_acl_gas_price.json b/ethcore/machine/res/tx_acl_gas_price.json new file mode 100644 index 00000000000..bc355dee7e6 --- /dev/null +++ b/ethcore/machine/res/tx_acl_gas_price.json @@ -0,0 +1,83 @@ +[ + { + "constant": true, + "inputs": [], + "name": "contractNameHash", + "outputs": [ + { + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "contractName", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "contractVersion", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "sender", + "type": "address" + }, + { + "name": "to", + "type": "address" + }, + { + "name": "value", + "type": "uint256" + }, + { + "name": "gasPrice", + "type": "uint256" + }, + { + "name": "data", + "type": "bytes" + } + ], + "name": "allowedTxTypes", + "outputs": [ + { + "name": "", + "type": "uint32" + }, + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/ethcore/machine/src/tx_filter.rs b/ethcore/machine/src/tx_filter.rs index 9d479fe24b4..18074330ed6 100644 --- a/ethcore/machine/src/tx_filter.rs +++ b/ethcore/machine/src/tx_filter.rs @@ -35,6 +35,7 @@ use keccak_hash::KECCAK_EMPTY; use_contract!(transact_acl_deprecated, "res/tx_acl_deprecated.json"); use_contract!(transact_acl, "res/tx_acl.json"); +use_contract!(transact_acl_gas_price, "res/tx_acl_gas_price.json"); const MAX_CACHE_SIZE: usize = 4096; @@ -86,6 +87,7 @@ impl TransactionFilter { let sender = transaction.sender(); let value = transaction.value; + let gas_price = transaction.gas_price; let key = (*parent_hash, sender); if let Some(permissions) = permission_cache.get_mut(&key) { @@ -115,6 +117,19 @@ impl TransactionFilter { (tx_permissions::NONE, true) }) }, + 3 => { + trace!(target: "tx_filter", "Using filter with gas price and data"); + let (data, decoder) = transact_acl_gas_price::functions::allowed_tx_types::call( + sender, to, value, gas_price, transaction.data.clone() + ); + client.call_contract(BlockId::Hash(*parent_hash), contract_address, data) + .and_then(|value| decoder.decode(&value).map_err(|e| e.to_string())) + .map(|(p, f)| (p.low_u32(), f)) + .unwrap_or_else(|e| { + error!(target: "tx_filter", "Error calling tx permissions contract: {:?}", e); + (tx_permissions::NONE, true) + }) + } _ => { error!(target: "tx_filter", "Unknown version of tx permissions contract is used"); (tx_permissions::NONE, true) @@ -138,8 +153,8 @@ impl TransactionFilter { permission_cache.insert((*parent_hash, sender), permissions); } trace!(target: "tx_filter", - "Given transaction data: sender: {:?} to: {:?} value: {}. Permissions required: {:X}, got: {:X}", - sender, to, value, tx_type, permissions + "Given transaction data: sender: {:?} to: {:?} value: {}, gas_price: {}. Permissions required: {:X}, got: {:X}", + sender, to, value, gas_price, tx_type, permissions ); permissions & tx_type != 0 } @@ -171,7 +186,7 @@ mod test { /// Contract code: https://gist.github.com/VladLupashevskyi/84f18eabb1e4afadf572cf92af3e7e7f #[test] - fn transaction_filter() { + fn transaction_filter_ver_2() { let spec_data = include_str!("../../res/tx_permission_tests/contract_ver_2_genesis.json"); let db = test_helpers::new_db(); @@ -248,6 +263,48 @@ mod test { assert!(!filter.transaction_allowed(&genesis, block_number, &basic_tx_with_ether_and_to_key6.clone().sign(key7.secret(), None), &*client)); } + /// Contract code: res/tx_permission_tests/contract_ver_3.sol + #[test] + fn transaction_filter_ver_3() { + let spec_data = include_str!("../../res/tx_permission_tests/contract_ver_3_genesis.json"); + + let db = test_helpers::new_db(); + let tempdir = TempDir::new("").unwrap(); + let spec = Spec::load(&tempdir.path(), spec_data.as_bytes()).unwrap(); + + let client = Client::new( + ClientConfig::default(), + &spec, + db, + Arc::new(Miner::new_for_tests(&spec, None)), + IoChannel::disconnected(), + ).unwrap(); + let key1 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000001")).unwrap(); + + // The only difference to version 2 is that the contract now knows the transaction's gas price and data. + // So we only test those: The contract allows only transactions with either nonzero gas price or short data. + + let filter = TransactionFilter::from_params(spec.params()).unwrap(); + let mut tx = Transaction::default(); + tx.action = Action::Call(Address::from_str("0000000000000000000000000000000000000042").unwrap()); + tx.data = b"01234567".to_vec(); + tx.gas_price = 0.into(); + + let genesis = client.block_hash(BlockId::Latest).unwrap(); + let block_number = 1; + + // Data too long and gas price zero. This transaction is not allowed. + assert!(!filter.transaction_allowed(&genesis, block_number, &tx.clone().sign(key1.secret(), None), &*client)); + + // But if we either set a nonzero gas price or short data or both, it is allowed. + tx.gas_price = 1.into(); + assert!(filter.transaction_allowed(&genesis, block_number, &tx.clone().sign(key1.secret(), None), &*client)); + tx.data = b"01".to_vec(); + assert!(filter.transaction_allowed(&genesis, block_number, &tx.clone().sign(key1.secret(), None), &*client)); + tx.gas_price = 0.into(); + assert!(filter.transaction_allowed(&genesis, block_number, &tx.clone().sign(key1.secret(), None), &*client)); + } + /// Contract code: https://gist.github.com/arkpar/38a87cb50165b7e683585eec71acb05a #[test] fn transaction_filter_deprecated() { diff --git a/ethcore/res/tx_permission_tests/contract_ver_3.sol b/ethcore/res/tx_permission_tests/contract_ver_3.sol new file mode 100644 index 00000000000..b361815dc68 --- /dev/null +++ b/ethcore/res/tx_permission_tests/contract_ver_3.sol @@ -0,0 +1,60 @@ +pragma solidity ^0.4.20; + +// Adapted from https://gist.github.com/VladLupashevskyi/84f18eabb1e4afadf572cf92af3e7e7f +// and: https://github.com/poanetwork/posdao-contracts/blob/master/contracts/TxPermission.sol + +contract TxPermission { + /// Allowed transaction types mask + uint32 constant None = 0; + uint32 constant All = 0xffffffff; + uint32 constant Basic = 0x01; + uint32 constant Call = 0x02; + uint32 constant Create = 0x04; + uint32 constant Private = 0x08; + + /// Contract name + function contractName() public constant returns (string) { + return "TX_PERMISSION_CONTRACT"; + } + + /// Contract name hash + function contractNameHash() public constant returns (bytes32) { + return keccak256(contractName()); + } + + /// Contract version + function contractVersion() public constant returns (uint256) { + return 3; + } + + /// @dev Defines the allowed transaction types which may be initiated by the specified sender with + /// the specified gas price and data. Used by the Parity engine each time a transaction is about to be + /// included into a block. See https://wiki.parity.io/Permissioning.html#how-it-works-1 + /// @param _sender Transaction sender address. + /// @param _to Transaction recipient address. If creating a contract, the `_to` address is zero. + /// @param _value Transaction amount in wei. + /// @param _gasPrice Gas price in wei for the transaction. + /// @param _data Transaction data. + /// @return `uint32 typesMask` - Set of allowed transactions for `_sender` depending on tx `_to` address, + /// `_gasPrice`, and `_data`. The result is represented as a set of flags: + /// 0x01 - basic transaction (e.g. ether transferring to user wallet); + /// 0x02 - contract call; + /// 0x04 - contract creation; + /// 0x08 - private transaction. + /// `bool cache` - If `true` is returned, the same permissions will be applied from the same + /// `_sender` without calling this contract again. + function allowedTxTypes( + address _sender, + address _to, + uint256 _value, + uint256 _gasPrice, + bytes memory _data + ) + public + view + returns(uint32 typesMask, bool cache) + { + if (_gasPrice > 0 || _data.length < 4) return (All, false); + return (None, false); + } +} diff --git a/ethcore/res/tx_permission_tests/contract_ver_3_genesis.json b/ethcore/res/tx_permission_tests/contract_ver_3_genesis.json new file mode 100644 index 00000000000..a40b6be05a4 --- /dev/null +++ b/ethcore/res/tx_permission_tests/contract_ver_3_genesis.json @@ -0,0 +1,44 @@ +{ + "name": "TestNodeFilterContract", + "engine": { + "authorityRound": { + "params": { + "stepDuration": 1, + "startStep": 2, + "validators": { + "contract": "0x0000000000000000000000000000000000000000" + } + } + } + }, + "params": { + "accountStartNonce": "0x0", + "maximumExtraDataSize": "0x20", + "minGasLimit": "0x1388", + "networkID" : "0x69", + "gasLimitBoundDivisor": "0x0400", + "transactionPermissionContract": "0x0000000000000000000000000000000000000005", + "transactionPermissionContractTransition": "1" + }, + "genesis": { + "seal": { + "generic": "0xc180" + }, + "difficulty": "0x20000", + "author": "0x0000000000000000000000000000000000000000", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x", + "gasLimit": "0x222222" + }, + "accounts": { + "0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } }, + "0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } }, + "0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } }, + "0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } }, + "0000000000000000000000000000000000000005": { + "balance": "1", + "constructor": "6060604052341561000f57600080fd5b61035e8061001e6000396000f300606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063469ab1e31461006757806375d0c0dc14610098578063a0a8e46014610126578063b9056afa1461014f575b600080fd5b341561007257600080fd5b61007a610227565b60405180826000191660001916815260200191505060405180910390f35b34156100a357600080fd5b6100ab610298565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100eb5780820151818401526020810190506100d0565b50505050905090810190601f1680156101185780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561013157600080fd5b6101396102db565b6040518082815260200191505060405180910390f35b341561015a57600080fd5b6101fa600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001909190803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919050506102e4565b604051808363ffffffff1663ffffffff168152602001821515151581526020019250505060405180910390f35b6000610231610298565b6040518082805190602001908083835b6020831015156102665780518252602082019150602081019050602083039250610241565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040518091039020905090565b6102a061031e565b6040805190810160405280601681526020017f54585f5045524d495353494f4e5f434f4e545241435400000000000000000000815250905090565b60006003905090565b60008060008411806102f7575060048351105b1561030c5763ffffffff600091509150610314565b600080915091505b9550959350505050565b6020604051908101604052806000815250905600a165627a7a72305820be61565bc09fec6e9223a1fecd2e94783ca5c6f506c03f71d479a8c3285493310029" + } + } +} From 3696f686269ff337949d1d6ab1e6dffd5d2c1f2d Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 18 Oct 2019 15:10:00 +0200 Subject: [PATCH 06/13] [ethcore/builtin]: do not panic in blake2pricer on short input (#11180) * [ethcore/builtin]: do not panic in blake2pricer on short input * [ethcore/builtin]: add a test for blake2pricer --- ethcore/builtin/src/lib.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ethcore/builtin/src/lib.rs b/ethcore/builtin/src/lib.rs index 795bf6f4796..78633a12ef7 100644 --- a/ethcore/builtin/src/lib.rs +++ b/ethcore/builtin/src/lib.rs @@ -18,7 +18,7 @@ use std::{ cmp::{max, min}, - convert::TryFrom, + convert::{TryFrom, TryInto}, io::{self, Read, Cursor}, mem::size_of, }; @@ -56,11 +56,14 @@ pub type Blake2FPricer = u64; impl Pricer for Blake2FPricer { fn cost(&self, input: &[u8], _at: u64) -> U256 { - use std::convert::TryInto; - let (rounds_bytes, _) = input.split_at(std::mem::size_of::()); + const FOUR: usize = std::mem::size_of::(); // Returning zero if the conversion fails is fine because `execute()` will check the length // and bail with the appropriate error. - let rounds = u32::from_be_bytes(rounds_bytes.try_into().unwrap_or([0u8; 4])); + if input.len() < FOUR { + return U256::zero(); + } + let (rounds_bytes, _) = input.split_at(FOUR); + let rounds = u32::from_be_bytes(rounds_bytes.try_into().unwrap_or([0u8; FOUR])); U256::from(*self as u128 * rounds as u128) } } @@ -708,6 +711,19 @@ mod tests { assert_eq!(f.cost(&input[..], 0), U256::from(123*5)); } + #[test] + fn blake2f_cost_on_invalid_length() { + let f = Builtin { + pricer: Box::new(123), + native: ethereum_builtin("blake2_f").expect("known builtin"), + activate_at: 0, + }; + // invalid input (too short) + let input = hex!("00"); + + assert_eq!(f.cost(&input[..], 0), U256::from(0)); + } + #[test] fn blake2_f_is_err_on_invalid_length() { let blake2 = ethereum_builtin("blake2_f").expect("known builtin"); From 2d2513b35ae5b9f204332f61a267554b0b1e1bc1 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 18 Oct 2019 15:12:16 +0200 Subject: [PATCH 07/13] [dependencies] bump rand 0.7 (#11022) * network-devp2p: bump rand `0.7` * updater: bump rand `0.7` * hash-fetch: bump rand `0.7` * ethcore-sync: bump rand `0.7` * rpc: dont work yet * [private-tx] remove unused rand * [ethcore-snapshot] bump rand 0.7 * [engine clique]: bump rand 0.7 * [engine authority-round]: remove rand * [ethcore-blockchain]: bump rand 0.7 * [ethcore]: bump rand 0.7 * [ethcore-light]: bump rand 0.7 * [ethstore]: bump rand 0.7 * Fix for rand usage in rpc * [rpc]: fix test build * [ethcore-sync]: fix test build * [snapshot tests]: rand 0.7 * [ethkey]: bump rand 0.7 * [rpc]: resolve TODO incompatible `rand versions` * [ethkey] use `rust-secp256k1` master branch * fix(bad merge): ethcoore-light remove itertools * [rpc tests]: revert rpc test changes in #11139 `#11139` makes use a different `RNG/seed`, not `H64::random_using(&mut self.rand)` This commit reverts the changed tests (the generated id by `Subscribers::next_id`) * [ethkey/random]: resolve introduced `TODO` --- Cargo.lock | 105 ++++++++++++------ accounts/ethkey/Cargo.toml | 2 +- accounts/ethkey/src/random.rs | 10 +- accounts/ethstore/Cargo.toml | 2 +- accounts/ethstore/src/random.rs | 6 +- accounts/ethstore/tests/util/transient_dir.rs | 2 +- ethcore/Cargo.toml | 3 +- ethcore/blockchain/Cargo.toml | 2 +- ethcore/engines/authority-round/Cargo.toml | 1 - ethcore/engines/clique/Cargo.toml | 2 +- ethcore/light/Cargo.toml | 2 +- ethcore/snapshot/Cargo.toml | 4 +- ethcore/snapshot/snapshot-tests/Cargo.toml | 4 +- ethcore/snapshot/src/consensus/work.rs | 2 +- ethcore/src/client/client.rs | 2 +- ethcore/sync/Cargo.toml | 4 +- ethcore/sync/src/light_sync/mod.rs | 2 +- rpc/Cargo.toml | 6 +- rpc/src/authcodes.rs | 2 +- rpc/src/v1/helpers/secretstore.rs | 2 +- rpc/src/v1/helpers/subscribers.rs | 10 +- rpc/src/v1/helpers/subscription_manager.rs | 2 +- rpc/src/v1/tests/mocked/eth_pubsub.rs | 29 +++-- rpc/src/v1/tests/mocked/pubsub.rs | 8 +- updater/Cargo.toml | 2 +- updater/hash-fetch/Cargo.toml | 2 +- updater/hash-fetch/src/client.rs | 4 +- util/network-devp2p/Cargo.toml | 2 +- util/network-devp2p/src/node_table.rs | 5 +- 29 files changed, 130 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3c465b998c..e13978c9396 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,7 +183,6 @@ dependencies = [ "machine 0.1.0", "macros 0.1.0", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "spec 0.1.0", @@ -544,7 +543,7 @@ dependencies = [ "machine 0.1.0", "macros 0.1.0", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "spec 0.1.0", "state-db 0.1.0", @@ -929,12 +928,12 @@ dependencies = [ [[package]] name = "eth-secp256k1" version = "0.5.7" -source = "git+https://github.com/paritytech/rust-secp256k1#a96ad75aead23caa7f79cb61620c3a8c77d711d9" +source = "git+https://github.com/paritytech/rust-secp256k1#246aefeef6337d208d820936e8e868f11d80e98c" dependencies = [ "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1067,7 +1066,8 @@ dependencies = [ "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "pod 0.1.0", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "registrar 0.0.1", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1126,7 +1126,7 @@ dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_compress 0.1.0", @@ -1235,7 +1235,7 @@ dependencies = [ "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1344,7 +1344,7 @@ dependencies = [ "parity-path 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1515,8 +1515,8 @@ dependencies = [ "parity-runtime 0.1.0", "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "snapshot 0.1.0", @@ -1561,7 +1561,7 @@ dependencies = [ "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wordlist 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1598,7 +1598,7 @@ dependencies = [ "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wordlist 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1811,6 +1811,11 @@ name = "fs_extra" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -2085,7 +2090,7 @@ dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "xmltree 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2822,7 +2827,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3058,7 +3063,7 @@ dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "registrar 0.0.1", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3171,8 +3176,8 @@ dependencies = [ "parity-version 2.7.0", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3285,7 +3290,7 @@ dependencies = [ "parity-path 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-version 2.7.0", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3667,11 +3672,13 @@ dependencies = [ [[package]] name = "rand" -version = "0.4.3" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3696,7 +3703,7 @@ dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3722,7 +3729,7 @@ name = "rand_chacha" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3740,12 +3747,20 @@ name = "rand_core" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" -version = "0.3.0" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3761,7 +3776,7 @@ name = "rand_hc" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3777,7 +3792,7 @@ name = "rand_isaac" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3794,7 +3809,7 @@ name = "rand_pcg" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3803,7 +3818,15 @@ name = "rand_xorshift" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_xorshift" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3836,6 +3859,14 @@ dependencies = [ "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "redox_syscall" version = "0.1.40" @@ -4213,8 +4244,8 @@ dependencies = [ "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", "snapshot-tests 0.1.0", @@ -4258,8 +4289,8 @@ dependencies = [ "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "snapshot 0.1.0", "spec 0.1.0", @@ -4442,7 +4473,7 @@ name = "tempdir" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -5403,6 +5434,7 @@ dependencies = [ "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum fs-swap 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "921d332c89b3b61a826de38c61ee5b6e02c56806cade1b0e5d81bd71f57a71bb" "checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" @@ -5553,14 +5585,15 @@ dependencies = [ "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" +"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" "checksum rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9d223d52ae411a33cf7e54ec6034ec165df296ccd23533d671a28252b6f66a" "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412" "checksum rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "771b009e3a508cb67e8823dda454aaa5368c7bc1c16829fb77d3e980440dd34a" "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" "checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372" -"checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" @@ -5568,9 +5601,11 @@ dependencies = [ "checksum rand_os 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a788ae3edb696cfcba1c19bfd388cc4b8c21f8a408432b199c072825084da58a" "checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77d416b86801d23dde1aa643023b775c3a462efc0ed96443add11546cdf1dca8" "checksum rand_xoshiro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e18c91676f670f6f0312764c759405f13afb98d5d73819840cf72a518487bff" "checksum rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a4b0186e22767d5b9738a05eab7c6ac90b15db17e5b5f9bd87976dd7d89a10a4" "checksum rayon-core 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ebbe0df8435ac0c397d467b6cad6d25543d06e8a019ef3f6af3c384597515bd2" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" diff --git a/accounts/ethkey/Cargo.toml b/accounts/ethkey/Cargo.toml index 2719b200934..fb3716ad08a 100644 --- a/accounts/ethkey/Cargo.toml +++ b/accounts/ethkey/Cargo.toml @@ -13,7 +13,7 @@ lazy_static = "1.0" log = "0.4" parity-wordlist = "1.3" quick-error = "1.2.2" -rand = "0.6" +rand = "0.7" rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" diff --git a/accounts/ethkey/src/random.rs b/accounts/ethkey/src/random.rs index 39f72eb0cdf..08ccd2624c4 100644 --- a/accounts/ethkey/src/random.rs +++ b/accounts/ethkey/src/random.rs @@ -21,14 +21,12 @@ use super::{Generator, KeyPair, SECP256K1}; pub struct Random; impl Generator for Random { - type Error = ::std::io::Error; + type Error = std::io::Error; fn generate(&mut self) -> Result { - let mut rng = OsRng::new()?; - match rng.generate() { - Ok(pair) => Ok(pair), - Err(void) => match void {}, // LLVM unreachable - } + Generator::generate(&mut OsRng).map_err(|void| { + match void {} // LLVM unreachable + }) } } diff --git a/accounts/ethstore/Cargo.toml b/accounts/ethstore/Cargo.toml index 1cd69d8aa9c..99943611c54 100644 --- a/accounts/ethstore/Cargo.toml +++ b/accounts/ethstore/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Parity Technologies "] [dependencies] log = "0.4" libc = "0.2" -rand = "0.6" +rand = "0.7" ethkey = { path = "../ethkey" } serde = "1.0" serde_json = "1.0" diff --git a/accounts/ethstore/src/random.rs b/accounts/ethstore/src/random.rs index 3e2df33b61a..bbaa0f3c457 100644 --- a/accounts/ethstore/src/random.rs +++ b/accounts/ethstore/src/random.rs @@ -23,7 +23,7 @@ pub trait Random { impl Random for [u8; 16] { fn random() -> Self { let mut result = [0u8; 16]; - let mut rng = OsRng::new().unwrap(); + let mut rng = OsRng; rng.fill_bytes(&mut result); result } @@ -32,7 +32,7 @@ impl Random for [u8; 16] { impl Random for [u8; 32] { fn random() -> Self { let mut result = [0u8; 32]; - let mut rng = OsRng::new().unwrap(); + let mut rng = OsRng; rng.fill_bytes(&mut result); result } @@ -40,6 +40,6 @@ impl Random for [u8; 32] { /// Generate a random string of given length. pub fn random_string(length: usize) -> String { - let mut rng = OsRng::new().expect("Not able to operate without random source."); + let rng = OsRng; rng.sample_iter(&Alphanumeric).take(length).collect() } diff --git a/accounts/ethstore/tests/util/transient_dir.rs b/accounts/ethstore/tests/util/transient_dir.rs index 90fe7303b07..8d91000f774 100644 --- a/accounts/ethstore/tests/util/transient_dir.rs +++ b/accounts/ethstore/tests/util/transient_dir.rs @@ -21,7 +21,7 @@ use ethstore::accounts_dir::{KeyDirectory, RootDiskDirectory}; use ethstore::{Error, SafeAccount}; pub fn random_dir() -> PathBuf { - let mut rng = OsRng::new().unwrap(); + let mut rng = OsRng; let mut dir = env::temp_dir(); dir.push(format!("{:x}-{:x}", rng.next_u64(), rng.next_u64())); dir diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 97c1e8f1aa1..aca6a924319 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -45,7 +45,8 @@ parking_lot = "0.9" pod = { path = "pod", optional = true } trie-db = "0.15.0" patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" } -rand = "0.6" +rand = "0.7" +rand_xorshift = "0.2" rayon = "1.1" registrar = { path = "../util/registrar" } rlp = "0.4.0" diff --git a/ethcore/blockchain/Cargo.toml b/ethcore/blockchain/Cargo.toml index 5e69700bbd5..5552e966fcd 100644 --- a/ethcore/blockchain/Cargo.toml +++ b/ethcore/blockchain/Cargo.toml @@ -19,8 +19,8 @@ itertools = "0.5" kvdb = "0.1" log = "0.4" parity-bytes = "0.1" +rand = "0.7" parking_lot = "0.9" -rand = "0.6" rayon = "1.0" rlp = "0.4.0" rlp_compress = { path = "../../util/rlp-compress" } diff --git a/ethcore/engines/authority-round/Cargo.toml b/ethcore/engines/authority-round/Cargo.toml index f27f42d4b24..79083299adb 100644 --- a/ethcore/engines/authority-round/Cargo.toml +++ b/ethcore/engines/authority-round/Cargo.toml @@ -23,7 +23,6 @@ lru-cache = "0.1" machine = { path = "../../machine" } macros = { path = "../../../util/macros" } parking_lot = "0.9" -rand = "0.6" rlp = "0.4.0" time-utils = { path = "../../../util/time-utils" } unexpected = { path = "../../../util/unexpected" } diff --git a/ethcore/engines/clique/Cargo.toml b/ethcore/engines/clique/Cargo.toml index fa7efa184f8..2c831813c83 100644 --- a/ethcore/engines/clique/Cargo.toml +++ b/ethcore/engines/clique/Cargo.toml @@ -19,8 +19,8 @@ log = "0.4" lru-cache = "0.1" machine = { path = "../../machine" } macros = { path = "../../../util/macros" } +rand = "0.7" parking_lot = "0.9" -rand = "0.6" rlp = "0.4.0" time-utils = { path = "../../../util/time-utils" } unexpected = { path = "../../../util/unexpected" } diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index 6f02dc284e1..e52faf85434 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -33,7 +33,7 @@ rlp = "0.4.0" rlp_derive = { path = "../../util/rlp-derive" } smallvec = "0.6" futures = "0.1" -rand = "0.6" +rand = "0.7" bincode = "1.1" serde = "1.0" serde_derive = "1.0" diff --git a/ethcore/snapshot/Cargo.toml b/ethcore/snapshot/Cargo.toml index dd3749274db..882c9c5c91c 100644 --- a/ethcore/snapshot/Cargo.toml +++ b/ethcore/snapshot/Cargo.toml @@ -28,9 +28,9 @@ keccak-hasher = { path = "../../util/keccak-hasher" } kvdb = "0.1" log = "0.4.8" num_cpus = "1.10.1" +rand = "0.7" +rand_xorshift = "0.2" parking_lot = "0.9" -rand = "0.6" -rand_xorshift = "0.1.1" rlp = "0.4.2" rlp_derive = { path = "../../util/rlp-derive" } snappy = { package = "parity-snappy", version ="0.1.0" } diff --git a/ethcore/snapshot/snapshot-tests/Cargo.toml b/ethcore/snapshot/snapshot-tests/Cargo.toml index 9172977ae44..efe6ec190d3 100644 --- a/ethcore/snapshot/snapshot-tests/Cargo.toml +++ b/ethcore/snapshot/snapshot-tests/Cargo.toml @@ -28,8 +28,8 @@ kvdb = "0.1" kvdb-rocksdb = { version = "0.1.5" } log = "0.4.8" parking_lot = "0.9" -rand = "0.6" -rand_xorshift = "0.1.1" +rand = "0.7" +rand_xorshift = "0.2" rlp = "0.4.2" snappy = { package = "parity-snappy", version ="0.1.0" } snapshot = { path = "../../snapshot", features = ["test-helpers"] } diff --git a/ethcore/snapshot/src/consensus/work.rs b/ethcore/snapshot/src/consensus/work.rs index eb035fb7734..fede7e9d624 100644 --- a/ethcore/snapshot/src/consensus/work.rs +++ b/ethcore/snapshot/src/consensus/work.rs @@ -222,7 +222,7 @@ impl PowRebuilder { Ok(PowRebuilder { chain, db, - rng: OsRng::new().map_err(|e| format!("{}", e))?, + rng: OsRng, disconnected: Vec::new(), best_number: manifest.block_number, best_hash: manifest.block_hash, diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 30c5ba02080..795a0e6deaf 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -469,7 +469,7 @@ impl Importer { { trace_time!("import_old_block"); // verify the block, passing the chain for updating the epoch verifier. - let mut rng = OsRng::new().map_err(|e| format!("{}", e))?; + let mut rng = OsRng; self.ancient_verifier.verify(&mut rng, &unverified.header, &chain)?; // Commit results diff --git a/ethcore/sync/Cargo.toml b/ethcore/sync/Cargo.toml index 7ec854f03b8..f8018599abb 100644 --- a/ethcore/sync/Cargo.toml +++ b/ethcore/sync/Cargo.toml @@ -27,8 +27,8 @@ macros = { path = "../../util/macros" } network = { package = "ethcore-network", path = "../../util/network" } parity-runtime = { path = "../../util/runtime" } parity-util-mem = "0.2.0" +rand = "0.7" parking_lot = "0.9" -rand = "0.6" rlp = "0.4.0" snapshot = { path = "../snapshot" } trace-time = "0.1" @@ -41,6 +41,6 @@ ethcore = { path = "..", features = ["test-helpers"] } ethcore-io = { path = "../../util/io", features = ["mio"] } kvdb-memorydb = "0.1.2" machine = { path = "../machine" } -rand_xorshift = "0.1.1" +rand_xorshift = "0.2" rustc-hex = "1.0" spec = { path = "../spec" } diff --git a/ethcore/sync/src/light_sync/mod.rs b/ethcore/sync/src/light_sync/mod.rs index 2de8003d697..a7d415d3f04 100644 --- a/ethcore/sync/src/light_sync/mod.rs +++ b/ethcore/sync/src/light_sync/mod.rs @@ -716,7 +716,7 @@ impl LightSync { peers: RwLock::new(HashMap::new()), pending_reqs: Mutex::new(HashMap::new()), client: client, - rng: Mutex::new(OsRng::new()?), + rng: Mutex::new(OsRng), senders: RwLock::new(Vec::new()), state: Mutex::new(SyncStateWrapper::idle()), is_idle: Mutex::new(true), diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index f8bc69f76ed..761808084de 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -14,14 +14,14 @@ futures = "0.1.6" log = "0.4" multihash = "0.8" order-stat = "0.1" -parking_lot = "0.9" -rand = "0.6" -rand_xorshift = "0.1.1" +rand = "0.7" +rand_xorshift = "0.2" rustc-hex = "1.0" semver = "0.9" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" +parking_lot = "0.9" tempdir = "0.3" tiny-keccak = "1.4" tokio-timer = "0.1" diff --git a/rpc/src/authcodes.rs b/rpc/src/authcodes.rs index a4f440a71a5..4c3e905e650 100644 --- a/rpc/src/authcodes.rs +++ b/rpc/src/authcodes.rs @@ -173,7 +173,7 @@ impl AuthCodes { /// Generates and returns a new code that can be used by `SignerUIs` pub fn generate_new(&mut self) -> io::Result { - let mut rng = OsRng::new()?; + let rng = OsRng; let code = rng.sample_iter(&Alphanumeric).take(TOKEN_LENGTH).collect::(); let readable_code = code.as_bytes() .chunks(4) diff --git a/rpc/src/v1/helpers/secretstore.rs b/rpc/src/v1/helpers/secretstore.rs index 6b90246cde3..3db4578eb2f 100644 --- a/rpc/src/v1/helpers/secretstore.rs +++ b/rpc/src/v1/helpers/secretstore.rs @@ -118,7 +118,7 @@ fn into_document_key(key: Bytes) -> Result { fn initialization_vector() -> [u8; INIT_VEC_LEN] { let mut result = [0u8; INIT_VEC_LEN]; - let mut rng = OsRng::new().unwrap(); + let mut rng = OsRng; rng.fill_bytes(&mut result); result } diff --git a/rpc/src/v1/helpers/subscribers.rs b/rpc/src/v1/helpers/subscribers.rs index 2c75ed5004f..b07000bcabe 100644 --- a/rpc/src/v1/helpers/subscribers.rs +++ b/rpc/src/v1/helpers/subscribers.rs @@ -18,7 +18,7 @@ use std::{ops, str}; use std::collections::HashMap; -use rand::RngCore; + use jsonrpc_pubsub::{typed::{Subscriber, Sink}, SubscriptionId}; use ethereum_types::H64; @@ -44,11 +44,11 @@ impl Id { #[cfg(not(test))] mod random { - use rand; + use rand::rngs::OsRng; pub type Rng = rand::rngs::OsRng; - pub fn new() -> Rng { Rng::new().expect("Valid random source is required.") } + pub fn new() -> Rng { OsRng } } #[cfg(test)] @@ -79,9 +79,7 @@ impl Default for Subscribers { impl Subscribers { fn next_id(&mut self) -> Id { - let mut data = H64::default(); - // TODO [grbIzl] rework with proper H64::random_using with rand 0.7 - self.rand.fill_bytes(&mut data.as_bytes_mut()); + let data = H64::random_using(&mut self.rand); Id(data) } diff --git a/rpc/src/v1/helpers/subscription_manager.rs b/rpc/src/v1/helpers/subscription_manager.rs index 597a08f33eb..b2dacba882b 100644 --- a/rpc/src/v1/helpers/subscription_manager.rs +++ b/rpc/src/v1/helpers/subscription_manager.rs @@ -165,7 +165,7 @@ mod tests { let mut el = Runtime::new().unwrap(); let mut poll_manager = poll_manager(); let (id, rx) = poll_manager.subscribe(Default::default(), "hello".into(), Params::None); - assert_eq!(id, SubscriptionId::String("0x4333966aca52ad0b".into())); + assert_eq!(id, SubscriptionId::String("0x43ca64edf03768e1".into())); // then poll_manager.tick().wait().unwrap(); diff --git a/rpc/src/v1/tests/mocked/eth_pubsub.rs b/rpc/src/v1/tests/mocked/eth_pubsub.rs index 86938d8f470..7aee32307e9 100644 --- a/rpc/src/v1/tests/mocked/eth_pubsub.rs +++ b/rpc/src/v1/tests/mocked/eth_pubsub.rs @@ -62,13 +62,13 @@ fn should_subscribe_to_new_heads() { // Subscribe let request = r#"{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["newHeads"], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":"0x4333966aca52ad0b","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); // Check notifications handler.new_blocks(NewBlocks::new(vec![], vec![], ChainRoute::new(vec![(h1, ChainRouteType::Enacted)]), vec![], vec![], DURATION_ZERO, true)); let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x1","parentHash":"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x4333966aca52ad0b"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x1","parentHash":"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // Notify about two blocks @@ -76,14 +76,14 @@ fn should_subscribe_to_new_heads() { // Receive both let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x2","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x2","parentHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x4333966aca52ad0b"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x2","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x2","parentHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x3","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0xdf04a98bb0c6fa8441bd429822f65a46d0cb553f6bcef602b973e65c81497f8e","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x3","parentHash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x4333966aca52ad0b"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x3","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0xdf04a98bb0c6fa8441bd429822f65a46d0cb553f6bcef602b973e65c81497f8e","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x3","parentHash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // And unsubscribe - let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x4333966aca52ad0b"], "id": 1}"#; + let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x43ca64edf03768e1"], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned())); @@ -132,7 +132,7 @@ fn should_subscribe_to_logs() { // Subscribe let request = r#"{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["logs", {}], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":"0x4333966aca52ad0b","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); // Check notifications (enacted) @@ -140,7 +140,7 @@ fn should_subscribe_to_logs() { let (res, receiver) = receiver.into_future().wait().unwrap(); let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","removed":false,"topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned() + &format!("0x{:x}", tx_hash) - + r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"},"subscription":"0x4333966aca52ad0b"}}"#; + + r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // Check notifications (retracted) @@ -148,11 +148,11 @@ fn should_subscribe_to_logs() { let (res, receiver) = receiver.into_future().wait().unwrap(); let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","removed":true,"topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned() + &format!("0x{:x}", tx_hash) - + r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"removed"},"subscription":"0x4333966aca52ad0b"}}"#; + + r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"removed"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // And unsubscribe - let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x4333966aca52ad0b"], "id": 1}"#; + let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x43ca64edf03768e1"], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned())); @@ -185,22 +185,22 @@ fn should_subscribe_to_pending_transactions() { // Subscribe let request = r#"{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["newPendingTransactions"], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":"0x4333966aca52ad0b","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); // Send new transactions pool_sender.unbounded_send(Arc::new(vec![H256::from_low_u64_be(5), H256::from_low_u64_be(7)])).unwrap(); let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"0x0000000000000000000000000000000000000000000000000000000000000005","subscription":"0x4333966aca52ad0b"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"0x0000000000000000000000000000000000000000000000000000000000000005","subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"0x0000000000000000000000000000000000000000000000000000000000000007","subscription":"0x4333966aca52ad0b"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"0x0000000000000000000000000000000000000000000000000000000000000007","subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // And unsubscribe - let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x4333966aca52ad0b"], "id": 1}"#; + let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x43ca64edf03768e1"], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned())); @@ -224,8 +224,7 @@ fn eth_subscribe_syncing() { let (sender, _receiver) = futures::sync::mpsc::channel(8); metadata.session = Some(Arc::new(Session::new(sender))); - // Subscribe - let response = r#"{"jsonrpc":"2.0","result":"0x4333966aca52ad0b","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; let request = r#"{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["syncing"], "id": 1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); } diff --git a/rpc/src/v1/tests/mocked/pubsub.rs b/rpc/src/v1/tests/mocked/pubsub.rs index 077e69e5a11..a0fafa4ba74 100644 --- a/rpc/src/v1/tests/mocked/pubsub.rs +++ b/rpc/src/v1/tests/mocked/pubsub.rs @@ -53,22 +53,22 @@ fn should_subscribe_to_a_method() { // Subscribe let request = r#"{"jsonrpc": "2.0", "method": "parity_subscribe", "params": ["hello", []], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":"0x4333966aca52ad0b","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); // Check notifications let (res, receiver) = receiver.into_future().wait().unwrap(); let response = - r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"hello","subscription":"0x4333966aca52ad0b"}}"#; + r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"hello","subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); let (res, receiver) = receiver.into_future().wait().unwrap(); let response = - r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"world","subscription":"0x4333966aca52ad0b"}}"#; + r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"world","subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // And unsubscribe - let request = r#"{"jsonrpc": "2.0", "method": "parity_unsubscribe", "params": ["0x4333966aca52ad0b"], "id": 1}"#; + let request = r#"{"jsonrpc": "2.0", "method": "parity_unsubscribe", "params": ["0x43ca64edf03768e1"], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned())); diff --git a/updater/Cargo.toml b/updater/Cargo.toml index 31ddb463a59..90ff44c9af0 100644 --- a/updater/Cargo.toml +++ b/updater/Cargo.toml @@ -21,8 +21,8 @@ parity-bytes = "0.1" parity-hash-fetch = { path = "hash-fetch" } parity-path = "0.1" parity-version = { path = "../util/version" } +rand = "0.7" parking_lot = "0.9" -rand = "0.6" semver = "0.9" target_info = "0.1" diff --git a/updater/hash-fetch/Cargo.toml b/updater/hash-fetch/Cargo.toml index b3781ec788f..0aaca33e77e 100644 --- a/updater/hash-fetch/Cargo.toml +++ b/updater/hash-fetch/Cargo.toml @@ -12,7 +12,7 @@ futures = "0.1" log = "0.4" mime = "0.3" mime_guess = "2.0.0-alpha.2" -rand = "0.6" +rand = "0.7" rustc-hex = "1.0" fetch = { path = "../../util/fetch" } parity-bytes = "0.1" diff --git a/updater/hash-fetch/src/client.rs b/updater/hash-fetch/src/client.rs index a5bd577c208..a12dc29c258 100644 --- a/updater/hash-fetch/src/client.rs +++ b/updater/hash-fetch/src/client.rs @@ -178,9 +178,9 @@ impl HashFetch for Client { fn random_temp_path() -> PathBuf { use rand::{Rng, rngs::OsRng, distributions::Alphanumeric}; - use ::std::env; + use std::env; - let mut rng = OsRng::new().expect("Reliable random source is required to work."); + let rng = OsRng; let file: String = rng.sample_iter(&Alphanumeric).take(12).collect(); let mut path = env::temp_dir(); diff --git a/util/network-devp2p/Cargo.toml b/util/network-devp2p/Cargo.toml index 9df85ee13a7..bc9ead6b3f0 100644 --- a/util/network-devp2p/Cargo.toml +++ b/util/network-devp2p/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" log = "0.4" mio = "0.6.8" bytes = "0.4" -rand = "0.6" +rand = "0.7" tiny-keccak = "1.4" slab = "0.2" igd = "0.9" diff --git a/util/network-devp2p/src/node_table.rs b/util/network-devp2p/src/node_table.rs index 6d68a7fd21d..4242dad981a 100644 --- a/util/network-devp2p/src/node_table.rs +++ b/util/network-devp2p/src/node_table.rs @@ -26,7 +26,7 @@ use std::time::{self, Duration, SystemTime}; use ethereum_types::H512; use log::{debug, warn}; -use rand::{self, Rng}; +use rand::seq::SliceRandom; use rlp::{DecoderError, Rlp, RlpStream}; use serde::{Deserialize, Serialize}; use serde_json; @@ -373,7 +373,8 @@ impl NodeTable { a.time().cmp(&b.time()) }); - rand::thread_rng().shuffle(&mut unknown); + let mut rng = rand::thread_rng(); + unknown.shuffle(&mut rng); success.append(&mut unknown); success.append(&mut failures); From c8b4373e13c83b26dee2c8f4ac6967260c4cd43b Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 18 Oct 2019 18:12:02 +0200 Subject: [PATCH 08/13] [receipt]: add `sender` & `receiver` to `RichReceipts` (#11179) * [receipts]: add `to` & `from` to `RichReceipts` * [rpc]: add test for `pending_receipt` * docs(common_types/receipt): add note Option field --- ethcore/src/miner/miner.rs | 5 +++++ ethcore/types/src/receipt.rs | 8 ++++++++ rpc/src/v1/tests/mocked/eth.rs | 32 +++++++++++++++++++++++++++++-- rpc/src/v1/tests/mocked/parity.rs | 2 +- rpc/src/v1/types/receipt.rs | 10 ++++++---- 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index d97b1170266..3d55f88eea1 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -1236,6 +1236,11 @@ impl miner::MinerService for Miner { let prev_gas = if index == 0 { Default::default() } else { receipts[index - 1].gas_used }; let receipt = &receipts[index]; RichReceipt { + from: tx.sender(), + to: match tx.action { + Action::Create => None, + Action::Call(ref address) => Some(*address), + }, transaction_hash: tx.hash(), transaction_index: index, cumulative_gas_used: receipt.gas_used, diff --git a/ethcore/types/src/receipt.rs b/ethcore/types/src/receipt.rs index 95b39e7de4b..9f53a43354b 100644 --- a/ethcore/types/src/receipt.rs +++ b/ethcore/types/src/receipt.rs @@ -122,6 +122,7 @@ pub struct RichReceipt { /// The gas used in the execution of the transaction. Note the difference of meaning to `Receipt::gas_used`. pub gas_used: U256, /// Contract address. + /// NOTE: It is an Option because only `Action::Create` transactions has a contract address pub contract_address: Option
, /// Logs pub logs: Vec, @@ -129,6 +130,11 @@ pub struct RichReceipt { pub log_bloom: Bloom, /// Transaction outcome. pub outcome: TransactionOutcome, + /// Receiver address + /// NOTE: It is an Option because only `Action::Call` transactions has a receiver address + pub to: Option, + /// Sender + pub from: H160 } /// Receipt with additional info. @@ -147,6 +153,7 @@ pub struct LocalizedReceipt { /// The gas used in the execution of the transaction. Note the difference of meaning to `Receipt::gas_used`. pub gas_used: U256, /// Contract address. + /// NOTE: It is an Option because only `Action::Create` transactions has a contract address pub contract_address: Option
, /// Logs pub logs: Vec, @@ -155,6 +162,7 @@ pub struct LocalizedReceipt { /// Transaction outcome. pub outcome: TransactionOutcome, /// Receiver address + /// NOTE: It is an Option because only `Action::Call` transactions has a receiver address pub to: Option, /// Sender pub from: H160 diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index bb6cb6b67ce..0f4342e4bbe 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -35,7 +35,7 @@ use types::{ ids::{BlockId, TransactionId}, transaction::{Transaction, Action}, log_entry::{LocalizedLogEntry, LogEntry}, - receipt::{LocalizedReceipt, TransactionOutcome}, + receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome}, snapshot::RestorationStatus, }; @@ -971,7 +971,7 @@ fn rpc_eth_transaction_receipt() { "params": ["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"], "id": 1 }"#; - let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","removed":false,"topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","status":null,"to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","removed":false,"topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#; assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned())); } @@ -991,6 +991,34 @@ fn rpc_eth_transaction_receipt_null() { assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned())); } +#[test] +fn rpc_eth_pending_receipt() { + let pending = RichReceipt { + from: H160::from_str("b60e8dd61c5d32be8058bb8eb970870f07233155").unwrap(), + to: Some(H160::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()), + transaction_hash: H256::from_str("b903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238").unwrap(), + transaction_index: 0, + cumulative_gas_used: U256::from(0x20), + gas_used: U256::from(0x10), + contract_address: None, + logs: Vec::new(), + log_bloom: Bloom::zero(), + outcome: TransactionOutcome::Unknown, + }; + let tester = EthTester::default(); + + tester.miner.pending_receipts.lock().push(pending); + + let request = r#"{ + "jsonrpc": "2.0", + "method": "eth_getTransactionReceipt", + "params": ["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"], + "id": 1 + }"#; + let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"contractAddress":null,"cumulativeGasUsed":"0x20","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238","transactionIndex":"0x0"},"id":1}"#; + assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned())); +} + // These tests are incorrect: their output is undefined as long as eth_getCompilers is []. // Will ignore for now, but should probably be replaced by more substantial tests which check // the output of eth_getCompilers to determine whether to test. CI systems can then be preinstalled diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index 9439164ee61..85f80350337 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -510,7 +510,7 @@ fn rpc_parity_block_receipts() { "params": [], "id": 1 }"#; - let response = r#"{"jsonrpc":"2.0","result":[{"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000003","blockNumber":"0x0","contractAddress":null,"cumulativeGasUsed":"0x5208","from":"0x0000000000000000000000000000000000000009","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","root":null,"status":null,"to":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000001","transactionIndex":"0x0"}],"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":[{"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000003","blockNumber":"0x0","contractAddress":null,"cumulativeGasUsed":"0x5208","from":"0x0000000000000000000000000000000000000009","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","to":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000001","transactionIndex":"0x0"}],"id":1}"#; assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); } diff --git a/rpc/src/v1/types/receipt.rs b/rpc/src/v1/types/receipt.rs index 9e5b5e3a686..727b4ce6e90 100644 --- a/rpc/src/v1/types/receipt.rs +++ b/rpc/src/v1/types/receipt.rs @@ -43,12 +43,14 @@ pub struct Receipt { /// Logs pub logs: Vec, /// State Root - #[serde(rename = "root")] + // NOTE(niklasad1): EIP98 makes this optional field, if it's missing then skip serializing it + #[serde(skip_serializing_if = "Option::is_none", rename = "root")] pub state_root: Option, /// Logs bloom pub logs_bloom: H2048, /// Status code - #[serde(rename = "status")] + // NOTE(niklasad1): Unknown after EIP98 rules, if it's missing then skip serializing it + #[serde(skip_serializing_if = "Option::is_none", rename = "status")] pub status_code: Option, } @@ -91,8 +93,8 @@ impl From for Receipt { impl From for Receipt { fn from(r: RichReceipt) -> Self { Receipt { - from: None, - to: None, + from: Some(r.from), + to: r.to.map(Into::into), transaction_hash: Some(r.transaction_hash), transaction_index: Some(r.transaction_index.into()), block_hash: None, From 6960d35abb9f11c27b47226e402ec617bfe585f1 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Sat, 19 Oct 2019 14:14:25 +0200 Subject: [PATCH 09/13] [dependencies]: jsonrpc `14.0.1` (#11183) Closing #11169 --- Cargo.lock | 92 +++++++++++++------------- Cargo.toml | 2 +- cli-signer/rpc-client/Cargo.toml | 4 +- ipfs/Cargo.toml | 4 +- miner/stratum/Cargo.toml | 4 +- rpc/Cargo.toml | 12 ++-- rpc/src/v1/traits/eth.rs | 64 +++++++++--------- rpc/src/v1/traits/eth_pubsub.rs | 10 ++- rpc/src/v1/traits/eth_signing.rs | 6 +- rpc/src/v1/traits/parity.rs | 36 +++++----- rpc/src/v1/traits/parity_accounts.rs | 42 ++++++------ rpc/src/v1/traits/parity_set.rs | 30 ++++----- rpc/src/v1/traits/parity_signing.rs | 10 +-- rpc/src/v1/traits/personal.rs | 18 ++--- rpc/src/v1/traits/private.rs | 16 +++-- rpc/src/v1/traits/pubsub.rs | 4 +- rpc/src/v1/traits/secretstore.rs | 12 ++-- rpc/src/v1/traits/signer.rs | 17 +++-- rpc/src/v1/traits/traces.rs | 22 +++--- rpc/src/v1/traits/transactions_pool.rs | 4 +- rpc/src/v1/traits/web3.rs | 2 +- secret-store/Cargo.toml | 2 +- 22 files changed, 220 insertions(+), 193 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e13978c9396..b00c3553702 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1425,7 +1425,7 @@ dependencies = [ "ethkey 0.3.0", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-server-utils 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-server-utils 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1478,8 +1478,8 @@ version = "1.12.0" dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-tcp-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-tcp-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2252,7 +2252,7 @@ dependencies = [ [[package]] name = "jsonrpc-core" -version = "14.0.0" +version = "14.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2264,23 +2264,23 @@ dependencies = [ [[package]] name = "jsonrpc-derive" -version = "14.0.0" +version = "14.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "jsonrpc-http-server" -version = "14.0.0" +version = "14.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-server-utils 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-server-utils 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2289,11 +2289,11 @@ dependencies = [ [[package]] name = "jsonrpc-ipc-server" -version = "14.0.0" +version = "14.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-server-utils 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-server-utils 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-tokio-ipc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2302,10 +2302,10 @@ dependencies = [ [[package]] name = "jsonrpc-pubsub" -version = "14.0.0" +version = "14.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2313,12 +2313,12 @@ dependencies = [ [[package]] name = "jsonrpc-server-utils" -version = "14.0.0" +version = "14.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2328,11 +2328,11 @@ dependencies = [ [[package]] name = "jsonrpc-tcp-server" -version = "14.0.0" +version = "14.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-server-utils 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-server-utils 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2340,11 +2340,11 @@ dependencies = [ [[package]] name = "jsonrpc-ws-server" -version = "14.0.0" +version = "14.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-server-utils 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-server-utils 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3000,7 +3000,7 @@ dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3077,8 +3077,8 @@ dependencies = [ "common-types 0.1.0", "ethcore 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-http-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-http-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "multihash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3157,12 +3157,12 @@ dependencies = [ "fetch 0.1.0", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-derive 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-http-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-ipc-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-pubsub 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-ws-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-derive 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-http-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-ipc-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-pubsub 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-ws-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "machine 0.1.0", @@ -3203,8 +3203,8 @@ version = "1.4.0" dependencies = [ "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-ws-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-ws-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3596,7 +3596,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4444,7 +4444,7 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5481,14 +5481,14 @@ dependencies = [ "checksum jemallocator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9f0cd42ac65f758063fea55126b0148b1ce0a6354ff78e07a4d6806bc65c4ab3" "checksum jni 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "294eca097d1dc0bf59de5ab9f7eafa5f77129e9f6464c957ed3ddeb705fb4292" "checksum jni-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" -"checksum jsonrpc-core 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf34414fdf9d843f2fd39557ffe7cbf75b53a2cf308e2b69af2ce86f23fd426d" -"checksum jsonrpc-derive 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f1b217357876c9f55d3237fafaebab1e3925d53a2c2508df05ea15c02ddbb8bc" -"checksum jsonrpc-http-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc653fb90f38cd203d756557426e87980a7329c4ac19360e7bd167d9f416f36e" -"checksum jsonrpc-ipc-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "deebb0b7d4a59898fb0738756a78d4e31d6afb84471aa75d6fb9b041f88a7ed2" -"checksum jsonrpc-pubsub 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db22ae4d04d336fea4378ad4ad87c29563d983fe98c04319c173817a4fd9891f" -"checksum jsonrpc-server-utils 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "56ca64eeb4463722c49dd526e0a87dfc0cdecda9348a4b6f5720f25abc4fcc89" -"checksum jsonrpc-tcp-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d38d09a7b9eaec3789b63cfa7cb48b290377776b78f42084099f66e9542825ab" -"checksum jsonrpc-ws-server 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f1cdf74f56227cf10ab22c64fd73b730d59b6217cd598b63883d07bd4b8de7c8" +"checksum jsonrpc-core 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9b392c9e8e43a12e6b21160903f473b1066e57fe18477394a93a1efd25654003" +"checksum jsonrpc-derive 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f79f30bf70049564c507b968162b8fd4bf114514bdacc1e90f9d891f8a66fce3" +"checksum jsonrpc-http-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dd3d54c822dc67707f21b15f13995b24eb090501c8ad67782b5484c9be36255b" +"checksum jsonrpc-ipc-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bed0288dfe341a68a5a54d824db5db0cbb9acb8f642cc5e1ac3e58239f24baed" +"checksum jsonrpc-pubsub 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe9faf8ba7ea28c58937cfbca538db1af11a9e72eae1aa8e6a83926b6b4dc46" +"checksum jsonrpc-server-utils 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "629792d44acc93f39800cd4c6524d7f33b30d66f24d3a9374af7ecbe71a4f8bf" +"checksum jsonrpc-tcp-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad0831b17761fa226e54d36284977cab07a29153242e41f67b7fdb2bfd147d5" +"checksum jsonrpc-ws-server 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "338664631e75cf752468a0d8ec3ba82df4caaacd942b4c34ea67db2556308e20" "checksum keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e563fa6fe52b2686094846118bf2cb2e6f75e6b8cec6c3aba09be8e835c7f998" "checksum keccak-hasher 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bf18164fd7ce989041f8fc4a1ae72a8bd1bec3575f2aeaf1d4968fc053aabef" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" @@ -5659,7 +5659,7 @@ dependencies = [ "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829" "checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" -"checksum syn 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "158521e6f544e7e3dcfc370ac180794aa38cb34a1b1e07609376d4adcf429b93" +"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c63f48baada5c52e65a29eef93ab4f8982681b67f9e8d29c7b05abcfec2b9ffe" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" diff --git a/Cargo.toml b/Cargo.toml index 62ac230140d..407f0aa4a69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ ethstore = { path = "accounts/ethstore" } fdlimit = "0.1" futures = "0.1" journaldb = { path = "util/journaldb" } -jsonrpc-core = "14.0.0" +jsonrpc-core = "14.0.1" keccak-hash = "0.4.0" kvdb = "0.1" kvdb-rocksdb = "0.1.5" diff --git a/cli-signer/rpc-client/Cargo.toml b/cli-signer/rpc-client/Cargo.toml index 2a881ec868d..224ba3bcb6c 100644 --- a/cli-signer/rpc-client/Cargo.toml +++ b/cli-signer/rpc-client/Cargo.toml @@ -15,7 +15,7 @@ serde_json = "1.0" url = "2.1.0" matches = "0.1" parking_lot = "0.9" -jsonrpc-core = "14.0.0" -jsonrpc-ws-server = "14.0.0" +jsonrpc-core = "14.0.1" +jsonrpc-ws-server = "14.0.1" parity-rpc = { path = "../../rpc" } keccak-hash = "0.4.0" diff --git a/ipfs/Cargo.toml b/ipfs/Cargo.toml index 6ed1e18065b..79ad7e26c93 100644 --- a/ipfs/Cargo.toml +++ b/ipfs/Cargo.toml @@ -12,8 +12,8 @@ common-types = { path = "../ethcore/types" } ethcore = { path = "../ethcore" } bytes = { package = "parity-bytes", version = "0.1"} ethereum-types = "0.8.0" -jsonrpc-core = "14.0.0" -http = { package = "jsonrpc-http-server", version = "14.0.0"} +jsonrpc-core = "14.0.1" +http = { package = "jsonrpc-http-server", version = "14.0.1"} rlp = "0.4.0" cid = "0.3" multihash = "0.8" diff --git a/miner/stratum/Cargo.toml b/miner/stratum/Cargo.toml index 6a796f36584..9fbb54f937d 100644 --- a/miner/stratum/Cargo.toml +++ b/miner/stratum/Cargo.toml @@ -8,8 +8,8 @@ authors = ["Parity Technologies "] [dependencies] ethereum-types = "0.8.0" keccak-hash = "0.4.0" -jsonrpc-core = "14.0.0" -jsonrpc-tcp-server = "14.0.0" +jsonrpc-core = "14.0.1" +jsonrpc-tcp-server = "14.0.1" log = "0.4" parking_lot = "0.9" diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 761808084de..b392c6f61fd 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -28,12 +28,12 @@ tokio-timer = "0.1" transient-hashmap = "0.4" itertools = "0.5" -jsonrpc-core = "14.0.0" -jsonrpc-derive = "14.0.0" -jsonrpc-http-server = "14.0.0" -jsonrpc-ws-server = "14.0.0" -jsonrpc-ipc-server = "14.0.0" -jsonrpc-pubsub = "14.0.0" +jsonrpc-core = "14.0.1" +jsonrpc-derive = "14.0.1" +jsonrpc-http-server = "14.0.1" +jsonrpc-ws-server = "14.0.1" +jsonrpc-ipc-server = "14.0.1" +jsonrpc-pubsub = "14.0.1" client-traits = { path = "../ethcore/client-traits" } common-types = { path = "../ethcore/types" } diff --git a/rpc/src/v1/traits/eth.rs b/rpc/src/v1/traits/eth.rs index a3bedc091eb..6add37b3f3d 100644 --- a/rpc/src/v1/traits/eth.rs +++ b/rpc/src/v1/traits/eth.rs @@ -68,87 +68,87 @@ pub trait Eth { /// Returns balance of the given account. #[rpc(name = "eth_getBalance")] - fn balance(&self, H160, Option) -> BoxFuture; + fn balance(&self, _: H160, _: Option) -> BoxFuture; /// Returns the account- and storage-values of the specified account including the Merkle-proof #[rpc(name = "eth_getProof")] - fn proof(&self, H160, Vec, Option) -> BoxFuture; + fn proof(&self, _: H160, _: Vec, _: Option) -> BoxFuture; /// Returns content of the storage at given address. #[rpc(name = "eth_getStorageAt")] - fn storage_at(&self, H160, U256, Option) -> BoxFuture; + fn storage_at(&self, _: H160, _: U256, _: Option) -> BoxFuture; /// Returns block with given hash. #[rpc(name = "eth_getBlockByHash")] - fn block_by_hash(&self, H256, bool) -> BoxFuture>; + fn block_by_hash(&self, _: H256, _: bool) -> BoxFuture>; /// Returns block with given number. #[rpc(name = "eth_getBlockByNumber")] - fn block_by_number(&self, BlockNumber, bool) -> BoxFuture>; + fn block_by_number(&self, _: BlockNumber, _: bool) -> BoxFuture>; /// Returns the number of transactions sent from given address at given time (block number). #[rpc(name = "eth_getTransactionCount")] - fn transaction_count(&self, H160, Option) -> BoxFuture; + fn transaction_count(&self, _: H160, _: Option) -> BoxFuture; /// Returns the number of transactions in a block with given hash. #[rpc(name = "eth_getBlockTransactionCountByHash")] - fn block_transaction_count_by_hash(&self, H256) -> BoxFuture>; + fn block_transaction_count_by_hash(&self, _: H256) -> BoxFuture>; /// Returns the number of transactions in a block with given block number. #[rpc(name = "eth_getBlockTransactionCountByNumber")] - fn block_transaction_count_by_number(&self, BlockNumber) -> BoxFuture>; + fn block_transaction_count_by_number(&self, _: BlockNumber) -> BoxFuture>; /// Returns the number of uncles in a block with given hash. #[rpc(name = "eth_getUncleCountByBlockHash")] - fn block_uncles_count_by_hash(&self, H256) -> BoxFuture>; + fn block_uncles_count_by_hash(&self, _: H256) -> BoxFuture>; /// Returns the number of uncles in a block with given block number. #[rpc(name = "eth_getUncleCountByBlockNumber")] - fn block_uncles_count_by_number(&self, BlockNumber) -> BoxFuture>; + fn block_uncles_count_by_number(&self, _: BlockNumber) -> BoxFuture>; /// Returns the code at given address at given time (block number). #[rpc(name = "eth_getCode")] - fn code_at(&self, H160, Option) -> BoxFuture; + fn code_at(&self, _: H160, _: Option) -> BoxFuture; /// Sends signed transaction, returning its hash. #[rpc(name = "eth_sendRawTransaction")] - fn send_raw_transaction(&self, Bytes) -> Result; + fn send_raw_transaction(&self, _: Bytes) -> Result; /// @alias of `eth_sendRawTransaction`. #[rpc(name = "eth_submitTransaction")] - fn submit_transaction(&self, Bytes) -> Result; + fn submit_transaction(&self, _: Bytes) -> Result; /// Call contract, returning the output data. #[rpc(name = "eth_call")] - fn call(&self, CallRequest, Option) -> BoxFuture; + fn call(&self, _: CallRequest, _: Option) -> BoxFuture; /// Estimate gas needed for execution of given contract. #[rpc(name = "eth_estimateGas")] - fn estimate_gas(&self, CallRequest, Option) -> BoxFuture; + fn estimate_gas(&self, _: CallRequest, _: Option) -> BoxFuture; /// Get transaction by its hash. #[rpc(name = "eth_getTransactionByHash")] - fn transaction_by_hash(&self, H256) -> BoxFuture>; + fn transaction_by_hash(&self, _: H256) -> BoxFuture>; /// Returns transaction at given block hash and index. #[rpc(name = "eth_getTransactionByBlockHashAndIndex")] - fn transaction_by_block_hash_and_index(&self, H256, Index) -> BoxFuture>; + fn transaction_by_block_hash_and_index(&self, _: H256, _: Index) -> BoxFuture>; /// Returns transaction by given block number and index. #[rpc(name = "eth_getTransactionByBlockNumberAndIndex")] - fn transaction_by_block_number_and_index(&self, BlockNumber, Index) -> BoxFuture>; + fn transaction_by_block_number_and_index(&self, _: BlockNumber, _: Index) -> BoxFuture>; /// Returns transaction receipt by transaction hash. #[rpc(name = "eth_getTransactionReceipt")] - fn transaction_receipt(&self, H256) -> BoxFuture>; + fn transaction_receipt(&self, _: H256) -> BoxFuture>; /// Returns an uncles at given block and index. #[rpc(name = "eth_getUncleByBlockHashAndIndex")] - fn uncle_by_block_hash_and_index(&self, H256, Index) -> BoxFuture>; + fn uncle_by_block_hash_and_index(&self, _: H256, _: Index) -> BoxFuture>; /// Returns an uncles at given block and index. #[rpc(name = "eth_getUncleByBlockNumberAndIndex")] - fn uncle_by_block_number_and_index(&self, BlockNumber, Index) -> BoxFuture>; + fn uncle_by_block_number_and_index(&self, _: BlockNumber, _: Index) -> BoxFuture>; /// Returns available compilers. /// @deprecated @@ -158,33 +158,33 @@ pub trait Eth { /// Compiles lll code. /// @deprecated #[rpc(name = "eth_compileLLL")] - fn compile_lll(&self, String) -> Result; + fn compile_lll(&self, _: String) -> Result; /// Compiles solidity. /// @deprecated #[rpc(name = "eth_compileSolidity")] - fn compile_solidity(&self, String) -> Result; + fn compile_solidity(&self, _: String) -> Result; /// Compiles serpent. /// @deprecated #[rpc(name = "eth_compileSerpent")] - fn compile_serpent(&self, String) -> Result; + fn compile_serpent(&self, _: String) -> Result; /// Returns logs matching given filter object. #[rpc(name = "eth_getLogs")] - fn logs(&self, Filter) -> BoxFuture>; + fn logs(&self, _: Filter) -> BoxFuture>; /// Returns the hash of the current block, the seedHash, and the boundary condition to be met. #[rpc(name = "eth_getWork")] - fn work(&self, Option) -> Result; + fn work(&self, _: Option) -> Result; /// Used for submitting a proof-of-work solution. #[rpc(name = "eth_submitWork")] - fn submit_work(&self, H64, H256, H256) -> Result; + fn submit_work(&self, _: H64, _: H256, _: H256) -> Result; /// Used for submitting mining hashrate. #[rpc(name = "eth_submitHashrate")] - fn submit_hashrate(&self, U256, H256) -> Result; + fn submit_hashrate(&self, _: U256, _: H256) -> Result; } /// Eth filters rpc api (polling). @@ -193,7 +193,7 @@ pub trait Eth { pub trait EthFilter { /// Returns id of new filter. #[rpc(name = "eth_newFilter")] - fn new_filter(&self, Filter) -> Result; + fn new_filter(&self, _: Filter) -> Result; /// Returns id of new block filter. #[rpc(name = "eth_newBlockFilter")] @@ -205,13 +205,13 @@ pub trait EthFilter { /// Returns filter changes since last poll. #[rpc(name = "eth_getFilterChanges")] - fn filter_changes(&self, Index) -> BoxFuture; + fn filter_changes(&self, _: Index) -> BoxFuture; /// Returns all logs matching given filter (in a range 'from' - 'to'). #[rpc(name = "eth_getFilterLogs")] - fn filter_logs(&self, Index) -> BoxFuture>; + fn filter_logs(&self, _: Index) -> BoxFuture>; /// Uninstalls filter. #[rpc(name = "eth_uninstallFilter")] - fn uninstall_filter(&self, Index) -> Result; + fn uninstall_filter(&self, _: Index) -> Result; } diff --git a/rpc/src/v1/traits/eth_pubsub.rs b/rpc/src/v1/traits/eth_pubsub.rs index 1f4c3e6e662..f35d5b26a41 100644 --- a/rpc/src/v1/traits/eth_pubsub.rs +++ b/rpc/src/v1/traits/eth_pubsub.rs @@ -30,9 +30,15 @@ pub trait EthPubSub { /// Subscribe to Eth subscription. #[pubsub(subscription = "eth_subscription", subscribe, name = "eth_subscribe")] - fn subscribe(&self, Self::Metadata, typed::Subscriber, pubsub::Kind, Option); + fn subscribe( + &self, + _: Self::Metadata, + _: typed::Subscriber, + _: pubsub::Kind, + _: Option, + ); /// Unsubscribe from existing Eth subscription. #[pubsub(subscription = "eth_subscription", unsubscribe, name = "eth_unsubscribe")] - fn unsubscribe(&self, Option, SubscriptionId) -> Result; + fn unsubscribe(&self, _: Option, _: SubscriptionId) -> Result; } diff --git a/rpc/src/v1/traits/eth_signing.rs b/rpc/src/v1/traits/eth_signing.rs index 7c1fbc8da51..5dc5c37d920 100644 --- a/rpc/src/v1/traits/eth_signing.rs +++ b/rpc/src/v1/traits/eth_signing.rs @@ -30,17 +30,17 @@ pub trait EthSigning { /// Signs the hash of data with given address signature. #[rpc(meta, name = "eth_sign")] - fn sign(&self, Self::Metadata, H160, Bytes) -> BoxFuture; + fn sign(&self, _: Self::Metadata, _: H160, _: Bytes) -> BoxFuture; /// Sends transaction; will block waiting for signer to return the /// transaction hash. /// If Signer is disable it will require the account to be unlocked. #[rpc(meta, name = "eth_sendTransaction")] - fn send_transaction(&self, Self::Metadata, TransactionRequest) -> BoxFuture; + fn send_transaction(&self, _: Self::Metadata, _: TransactionRequest) -> BoxFuture; /// Signs transactions without dispatching it to the network. /// Returns signed transaction RLP representation and the transaction itself. /// It can be later submitted using `eth_sendRawTransaction/eth_submitTransaction`. #[rpc(meta, name = "eth_signTransaction")] - fn sign_transaction(&self, Self::Metadata, TransactionRequest) -> BoxFuture; + fn sign_transaction(&self, _: Self::Metadata, _: TransactionRequest) -> BoxFuture; } diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index 6cd09e43289..c1fb8b4937a 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -104,7 +104,7 @@ pub trait Parity { /// Returns whatever address would be derived from the given phrase if it were to seed a brainwallet. #[rpc(name = "parity_phraseToAddress")] - fn phrase_to_address(&self, String) -> Result; + fn phrase_to_address(&self, _: String) -> Result; /// Returns the value of the registrar for this network. #[rpc(name = "parity_registryAddress")] @@ -112,21 +112,27 @@ pub trait Parity { /// Returns all addresses if Fat DB is enabled (`--fat-db`), or null if not. #[rpc(name = "parity_listAccounts")] - fn list_accounts(&self, u64, Option, Option) -> Result>>; + fn list_accounts(&self, _: u64, _: Option, _: Option) -> Result>>; /// Returns all storage keys of the given address (first parameter) if Fat DB is enabled (`--fat-db`), /// or null if not. #[rpc(name = "parity_listStorageKeys")] - fn list_storage_keys(&self, H160, Option, Option, Option) -> Result>>; + fn list_storage_keys( + &self, + _: H160, + _: Option, + _: Option, + _: Option, + ) -> Result>>; /// Encrypt some data with a public key under ECIES. /// First parameter is the 512-byte destination public key, second is the message. #[rpc(name = "parity_encryptMessage")] - fn encrypt_message(&self, H512, Bytes) -> Result; + fn encrypt_message(&self, _: H512, _: Bytes) -> Result; /// Returns all pending transactions from transaction queue. #[rpc(name = "parity_pendingTransactions")] - fn pending_transactions(&self, Option, Option) -> Result>; + fn pending_transactions(&self, _: Option, _: Option) -> Result>; /// Returns all transactions from transaction queue. /// @@ -156,7 +162,7 @@ pub trait Parity { /// Returns next nonce for particular sender. Should include all transactions in the queue. #[rpc(name = "parity_nextNonce")] - fn next_nonce(&self, H160) -> BoxFuture; + fn next_nonce(&self, _: H160) -> BoxFuture; /// Get the mode. Returns one of: "active", "passive", "dark", "offline". #[rpc(name = "parity_mode")] @@ -193,26 +199,26 @@ pub trait Parity { /// Get block header. /// Same as `eth_getBlockByNumber` but without uncles and transactions. #[rpc(name = "parity_getBlockHeaderByNumber")] - fn block_header(&self, Option) -> BoxFuture; + fn block_header(&self, _: Option) -> BoxFuture; /// Get block receipts. /// Allows you to fetch receipts from the entire block at once. /// If no parameter is provided defaults to `latest`. #[rpc(name = "parity_getBlockReceipts")] - fn block_receipts(&self, Option) -> BoxFuture>; + fn block_receipts(&self, _: Option) -> BoxFuture>; /// Get IPFS CIDv0 given protobuf encoded bytes. #[rpc(name = "parity_cidV0")] - fn ipfs_cid(&self, Bytes) -> Result; + fn ipfs_cid(&self, _: Bytes) -> Result; /// Call contract, returning the output data. #[rpc(name = "parity_call")] - fn call(&self, Vec, Option) -> Result>; + fn call(&self, _: Vec, _: Option) -> Result>; /// Used for submitting a proof-of-work solution (similar to `eth_submitWork`, /// but returns block hash on success, and returns an explicit error message on failure). #[rpc(name = "parity_submitWorkDetail")] - fn submit_work_detail(&self, H64, H256, H256) -> Result; + fn submit_work_detail(&self, _: H64, _: H256, _: H256) -> Result; /// Returns the status of the node. Used as the health endpoint. /// @@ -227,18 +233,18 @@ pub trait Parity { /// Extracts Address and public key from signature using the r, s and v params. Equivalent to Solidity erecover /// as well as checks the signature for chain replay protection #[rpc(name = "parity_verifySignature")] - fn verify_signature(&self, bool, Bytes, H256, H256, U64) -> Result; + fn verify_signature(&self, _: bool, _: Bytes, _: H256, _: H256, _: U64) -> Result; /// Returns logs matching given filter object. /// Is allowed to skip filling transaction hash for faster query. #[rpc(name = "parity_getLogsNoTransactionHash")] - fn logs_no_tx_hash(&self, Filter) -> BoxFuture>; + fn logs_no_tx_hash(&self, _: Filter) -> BoxFuture>; /// Returns raw block RLP with given number. #[rpc(name = "parity_getRawBlockByNumber")] - fn get_raw_block_by_number(&self, BlockNumber) -> BoxFuture>; + fn get_raw_block_by_number(&self, _: BlockNumber) -> BoxFuture>; /// Submit raw block to be published to the network #[rpc(name = "parity_submitRawBlock")] - fn submit_raw_block(&self, Bytes) -> Result; + fn submit_raw_block(&self, _: Bytes) -> Result; } diff --git a/rpc/src/v1/traits/parity_accounts.rs b/rpc/src/v1/traits/parity_accounts.rs index ecfc8cbb0fb..35874e6fe02 100644 --- a/rpc/src/v1/traits/parity_accounts.rs +++ b/rpc/src/v1/traits/parity_accounts.rs @@ -47,49 +47,49 @@ pub trait ParityAccounts { /// Creates new account from the given phrase using standard brainwallet mechanism. /// Second parameter is password for the new account. #[rpc(name = "parity_newAccountFromPhrase")] - fn new_account_from_phrase(&self, String, Password) -> Result; + fn new_account_from_phrase(&self, _: String, _: Password) -> Result; /// Creates new account from the given JSON wallet. /// Second parameter is password for the wallet and the new account. #[rpc(name = "parity_newAccountFromWallet")] - fn new_account_from_wallet(&self, String, Password) -> Result; + fn new_account_from_wallet(&self, _: String, _: Password) -> Result; /// Creates new account from the given raw secret. /// Second parameter is password for the new account. #[rpc(name = "parity_newAccountFromSecret")] - fn new_account_from_secret(&self, H256, Password) -> Result; + fn new_account_from_secret(&self, _: H256, _: Password) -> Result; /// Returns true if given `password` would unlock given `account`. /// Arguments: `account`, `password`. #[rpc(name = "parity_testPassword")] - fn test_password(&self, H160, Password) -> Result; + fn test_password(&self, _: H160, _: Password) -> Result; /// Changes an account's password. /// Arguments: `account`, `password`, `new_password`. #[rpc(name = "parity_changePassword")] - fn change_password(&self, H160, Password, Password) -> Result; + fn change_password(&self, _: H160, _: Password, _: Password) -> Result; /// Permanently deletes an account. /// Arguments: `account`, `password`. #[rpc(name = "parity_killAccount")] - fn kill_account(&self, H160, Password) -> Result; + fn kill_account(&self, _: H160, _: Password) -> Result; /// Permanently deletes an address from the addressbook /// Arguments: `address` #[rpc(name = "parity_removeAddress")] - fn remove_address(&self, H160) -> Result; + fn remove_address(&self, _: H160) -> Result; /// Set an account's name. #[rpc(name = "parity_setAccountName")] - fn set_account_name(&self, H160, String) -> Result; + fn set_account_name(&self, _: H160, _: String) -> Result; /// Set an account's metadata string. #[rpc(name = "parity_setAccountMeta")] - fn set_account_meta(&self, H160, String) -> Result; + fn set_account_meta(&self, _: H160, _: String) -> Result; /// Imports a number of Geth accounts, with the list provided as the argument. #[rpc(name = "parity_importGethAccounts")] - fn import_geth_accounts(&self, Vec) -> Result>; + fn import_geth_accounts(&self, _: Vec) -> Result>; /// Returns the accounts available for importing from Geth. #[rpc(name = "parity_listGethAccounts")] @@ -97,15 +97,15 @@ pub trait ParityAccounts { /// Create new vault. #[rpc(name = "parity_newVault")] - fn create_vault(&self, String, Password) -> Result; + fn create_vault(&self, _: String, _: Password) -> Result; /// Open existing vault. #[rpc(name = "parity_openVault")] - fn open_vault(&self, String, Password) -> Result; + fn open_vault(&self, _: String, _: Password) -> Result; /// Close previously opened vault. #[rpc(name = "parity_closeVault")] - fn close_vault(&self, String) -> Result; + fn close_vault(&self, _: String) -> Result; /// List all vaults. #[rpc(name = "parity_listVaults")] @@ -117,36 +117,36 @@ pub trait ParityAccounts { /// Change vault password. #[rpc(name = "parity_changeVaultPassword")] - fn change_vault_password(&self, String, Password) -> Result; + fn change_vault_password(&self, _: String, _: Password) -> Result; /// Change vault of the given address. #[rpc(name = "parity_changeVault")] - fn change_vault(&self, H160, String) -> Result; + fn change_vault(&self, _: H160, _: String) -> Result; /// Get vault metadata string. #[rpc(name = "parity_getVaultMeta")] - fn get_vault_meta(&self, String) -> Result; + fn get_vault_meta(&self, _: String) -> Result; /// Set vault metadata string. #[rpc(name = "parity_setVaultMeta")] - fn set_vault_meta(&self, String, String) -> Result; + fn set_vault_meta(&self, _: String, _: String) -> Result; /// Derive new address from given account address using specific hash. /// Resulting address can be either saved as a new account (with the same password). #[rpc(name = "parity_deriveAddressHash")] - fn derive_key_hash(&self, H160, Password, DeriveHash, bool) -> Result; + fn derive_key_hash(&self, _: H160, _: Password, _: DeriveHash, _: bool) -> Result; /// Derive new address from given account address using /// hierarchical derivation (sequence of 32-bit integer indices). /// Resulting address can be either saved as a new account (with the same password). #[rpc(name = "parity_deriveAddressIndex")] - fn derive_key_index(&self, H160, Password, DeriveHierarchical, bool) -> Result; + fn derive_key_index(&self, _: H160, _: Password, _: DeriveHierarchical, _: bool) -> Result; /// Exports an account with given address if provided password matches. #[rpc(name = "parity_exportAccount")] - fn export_account(&self, H160, Password) -> Result; + fn export_account(&self, _: H160, _: Password) -> Result; /// Sign raw hash with the key corresponding to address and password. #[rpc(name = "parity_signMessage")] - fn sign_message(&self, H160, Password, H256) -> Result; + fn sign_message(&self, _: H160, _: Password, _: H256) -> Result; } diff --git a/rpc/src/v1/traits/parity_set.rs b/rpc/src/v1/traits/parity_set.rs index 94fe9fa386f..96d71d33611 100644 --- a/rpc/src/v1/traits/parity_set.rs +++ b/rpc/src/v1/traits/parity_set.rs @@ -27,7 +27,7 @@ use v1::types::{Bytes, ReleaseInfo, Transaction}; pub trait ParitySetAccounts { /// Sets account for signing consensus messages. #[rpc(name = "parity_setEngineSigner")] - fn set_engine_signer(&self, H160, String) -> Result; + fn set_engine_signer(&self, _: H160, _: String) -> Result; } /// Parity-specific rpc interface for operations altering the settings. @@ -35,27 +35,27 @@ pub trait ParitySetAccounts { pub trait ParitySet { /// Sets new minimal gas price for mined blocks. #[rpc(name = "parity_setMinGasPrice")] - fn set_min_gas_price(&self, U256) -> Result; + fn set_min_gas_price(&self, _: U256) -> Result; /// Sets new gas floor target for mined blocks. #[rpc(name = "parity_setGasFloorTarget")] - fn set_gas_floor_target(&self, U256) -> Result; + fn set_gas_floor_target(&self, _: U256) -> Result; /// Sets new gas ceiling target for mined blocks. #[rpc(name = "parity_setGasCeilTarget")] - fn set_gas_ceil_target(&self, U256) -> Result; + fn set_gas_ceil_target(&self, _: U256) -> Result; /// Sets new extra data for mined blocks. #[rpc(name = "parity_setExtraData")] - fn set_extra_data(&self, Bytes) -> Result; + fn set_extra_data(&self, _: Bytes) -> Result; /// Sets new author for mined block. #[rpc(name = "parity_setAuthor")] - fn set_author(&self, H160) -> Result; + fn set_author(&self, _: H160) -> Result; /// Sets the secret of engine signer account. #[rpc(name = "parity_setEngineSignerSecret")] - fn set_engine_signer_secret(&self, H256) -> Result; + fn set_engine_signer_secret(&self, _: H256) -> Result; /// Unsets the engine signer account address. #[rpc(name = "parity_clearEngineSigner")] @@ -63,19 +63,19 @@ pub trait ParitySet { /// Sets the limits for transaction queue. #[rpc(name = "parity_setTransactionsLimit")] - fn set_transactions_limit(&self, usize) -> Result; + fn set_transactions_limit(&self, _: usize) -> Result; /// Sets the maximum amount of gas a single transaction may consume. #[rpc(name = "parity_setMaxTransactionGas")] - fn set_tx_gas_limit(&self, U256) -> Result; + fn set_tx_gas_limit(&self, _: U256) -> Result; /// Add a reserved peer. #[rpc(name = "parity_addReservedPeer")] - fn add_reserved_peer(&self, String) -> Result; + fn add_reserved_peer(&self, _: String) -> Result; /// Remove a reserved peer. #[rpc(name = "parity_removeReservedPeer")] - fn remove_reserved_peer(&self, String) -> Result; + fn remove_reserved_peer(&self, _: String) -> Result; /// Drop all non-reserved peers. #[rpc(name = "parity_dropNonReservedPeers")] @@ -99,15 +99,15 @@ pub trait ParitySet { /// Set the mode. Argument must be one of: "active", "passive", "dark", "offline". #[rpc(name = "parity_setMode")] - fn set_mode(&self, String) -> Result; + fn set_mode(&self, _: String) -> Result; /// Set the network spec. Argument must be one of pre-configured chains or a filename. #[rpc(name = "parity_setChain")] - fn set_spec_name(&self, String) -> Result; + fn set_spec_name(&self, _: String) -> Result; /// Hash a file content under given URL. #[rpc(name = "parity_hashContent")] - fn hash_content(&self, String) -> BoxFuture; + fn hash_content(&self, _: String) -> BoxFuture; /// Is there a release ready for install? #[rpc(name = "parity_upgradeReady")] @@ -124,5 +124,5 @@ pub trait ParitySet { /// or excessive gas limit that are not accepted by other peers whp. /// Returns `true` when transaction was removed, `false` if it was not found. #[rpc(name = "parity_removeTransaction")] - fn remove_transaction(&self, H256) -> Result>; + fn remove_transaction(&self, _: H256) -> Result>; } diff --git a/rpc/src/v1/traits/parity_signing.rs b/rpc/src/v1/traits/parity_signing.rs index 23099ff8248..941ff08ba6b 100644 --- a/rpc/src/v1/traits/parity_signing.rs +++ b/rpc/src/v1/traits/parity_signing.rs @@ -30,25 +30,25 @@ pub trait ParitySigning { /// Given partial transaction request produces transaction with all fields filled in. /// Such transaction can be then signed externally. #[rpc(meta, name = "parity_composeTransaction")] - fn compose_transaction(&self, Self::Metadata, TransactionRequest) -> BoxFuture; + fn compose_transaction(&self, _: Self::Metadata, _: TransactionRequest) -> BoxFuture; /// Posts sign request asynchronously. /// Will return a confirmation ID for later use with check_transaction. #[rpc(meta, name = "parity_postSign")] - fn post_sign(&self, Self::Metadata, H160, Bytes) -> BoxFuture>; + fn post_sign(&self, _: Self::Metadata, _: H160, _: Bytes) -> BoxFuture>; /// Posts transaction asynchronously. /// Will return a transaction ID for later use with check_transaction. #[rpc(meta, name = "parity_postTransaction")] - fn post_transaction(&self, Self::Metadata, TransactionRequest) -> BoxFuture>; + fn post_transaction(&self, _: Self::Metadata, _: TransactionRequest) -> BoxFuture>; /// Checks the progress of a previously posted request (transaction/sign). /// Should be given a valid send_transaction ID. #[rpc(name = "parity_checkRequest")] - fn check_request(&self, U256) -> Result>; + fn check_request(&self, _: U256) -> Result>; /// Decrypt some ECIES-encrypted message. /// First parameter is the address with which it is encrypted, second is the ciphertext. #[rpc(meta, name = "parity_decryptMessage")] - fn decrypt_message(&self, Self::Metadata, H160, Bytes) -> BoxFuture; + fn decrypt_message(&self, _: Self::Metadata, _: H160, _: Bytes) -> BoxFuture; } diff --git a/rpc/src/v1/traits/personal.rs b/rpc/src/v1/traits/personal.rs index 5a615208ab4..ec18a10e1a6 100644 --- a/rpc/src/v1/traits/personal.rs +++ b/rpc/src/v1/traits/personal.rs @@ -35,40 +35,40 @@ pub trait Personal { /// Creates new account (it becomes new current unlocked account) /// Param is the password for the account. #[rpc(name = "personal_newAccount")] - fn new_account(&self, String) -> Result; + fn new_account(&self, _: String) -> Result; /// Unlocks specified account for use (can only be one unlocked account at one moment) #[rpc(name = "personal_unlockAccount")] - fn unlock_account(&self, H160, String, Option) -> Result; + fn unlock_account(&self, _: H160, _: String, _: Option) -> Result; /// Signs the hash of data with given account signature using the given password to unlock the account during /// the request. #[rpc(name = "personal_sign")] - fn sign(&self, Bytes, H160, String) -> BoxFuture; + fn sign(&self, _: Bytes, _: H160, _: String) -> BoxFuture; /// Produces an EIP-712 compliant signature with given account using the given password to unlock the /// account during the request. #[rpc(name = "personal_signTypedData")] - fn sign_typed_data(&self, EIP712, H160, String) -> BoxFuture; + fn sign_typed_data(&self, _: EIP712, _: H160, _: String) -> BoxFuture; /// Signs an arbitrary message based on the version specified #[rpc(name = "personal_sign191")] - fn sign_191(&self, EIP191Version, Value, H160, String) -> BoxFuture; + fn sign_191(&self, _: EIP191Version, _: Value, _: H160, _: String) -> BoxFuture; /// Returns the account associated with the private key that was used to calculate the signature in /// `personal_sign`. #[rpc(name = "personal_ecRecover")] - fn ec_recover(&self, Bytes, H520) -> BoxFuture; + fn ec_recover(&self, _: Bytes, _: H520) -> BoxFuture; /// Signs transaction. The account is not unlocked in such case. #[rpc(meta, name = "personal_signTransaction")] - fn sign_transaction(&self, Self::Metadata, TransactionRequest, String) -> BoxFuture; + fn sign_transaction(&self, _: Self::Metadata, _: TransactionRequest, _: String) -> BoxFuture; /// Sends transaction and signs it in single call. The account is not unlocked in such case. #[rpc(meta, name = "personal_sendTransaction")] - fn send_transaction(&self, Self::Metadata, TransactionRequest, String) -> BoxFuture; + fn send_transaction(&self, _: Self::Metadata, _: TransactionRequest, _: String) -> BoxFuture; /// @deprecated alias for `personal_sendTransaction`. #[rpc(meta, name = "personal_signAndSendTransaction")] - fn sign_and_send_transaction(&self, Self::Metadata, TransactionRequest, String) -> BoxFuture; + fn sign_and_send_transaction(&self, _: Self::Metadata, _: TransactionRequest, _: String) -> BoxFuture; } diff --git a/rpc/src/v1/traits/private.rs b/rpc/src/v1/traits/private.rs index 1cb100d09f9..97bd7edd54d 100644 --- a/rpc/src/v1/traits/private.rs +++ b/rpc/src/v1/traits/private.rs @@ -31,21 +31,27 @@ pub trait Private { /// Sends private transaction; Transaction will be added to the validation queue and sent out when ready. #[rpc(name = "private_sendTransaction")] - fn send_transaction(&self, Bytes) -> Result; + fn send_transaction(&self, _: Bytes) -> Result; /// Creates a transaction for contract's deployment from origin (signed transaction) #[rpc(name = "private_composeDeploymentTransaction")] - fn compose_deployment_transaction(&self, BlockNumber, Bytes, Vec, U256) -> Result; + fn compose_deployment_transaction( + &self, + _: BlockNumber, + _: Bytes, + _: Vec, + _: U256 + ) -> Result; /// Make a call to the private contract #[rpc(name = "private_call")] - fn private_call(&self, BlockNumber, CallRequest) -> Result; + fn private_call(&self, _: BlockNumber, _: CallRequest) -> Result; /// Retrieve the id of the key associated with the contract #[rpc(name = "private_contractKey")] - fn private_contract_key(&self, H160) -> Result; + fn private_contract_key(&self, _: H160) -> Result; /// Retrieve log information about private transaction #[rpc(name = "private_log")] - fn private_log(&self, H256) -> Result; + fn private_log(&self, _: H256) -> Result; } diff --git a/rpc/src/v1/traits/pubsub.rs b/rpc/src/v1/traits/pubsub.rs index 6d75cecda8c..6cb97ec3a86 100644 --- a/rpc/src/v1/traits/pubsub.rs +++ b/rpc/src/v1/traits/pubsub.rs @@ -28,9 +28,9 @@ pub trait PubSub { /// Subscribe to changes of any RPC method in Parity. #[pubsub(subscription = "parity_subscription", subscribe, name = "parity_subscribe")] - fn parity_subscribe(&self, Self::Metadata, Subscriber, String, Option); + fn parity_subscribe(&self, _: Self::Metadata, _: Subscriber, _: String, _: Option); /// Unsubscribe from existing Parity subscription. #[pubsub(subscription = "parity_subscription", unsubscribe, name = "parity_unsubscribe")] - fn parity_unsubscribe(&self, Option, SubscriptionId) -> Result; + fn parity_unsubscribe(&self, _: Option, _: SubscriptionId) -> Result; } diff --git a/rpc/src/v1/traits/secretstore.rs b/rpc/src/v1/traits/secretstore.rs index e5ff3c502d7..2e355dd5641 100644 --- a/rpc/src/v1/traits/secretstore.rs +++ b/rpc/src/v1/traits/secretstore.rs @@ -30,32 +30,32 @@ pub trait SecretStore { /// Generate document key to store in secret store. /// Arguments: `account`, `password`, `server_key_public`. #[rpc(name = "secretstore_generateDocumentKey")] - fn generate_document_key(&self, H160, Password, H512) -> Result; + fn generate_document_key(&self, _: H160, _: Password, _: H512) -> Result; /// Encrypt data with key, received from secret store. /// Arguments: `account`, `password`, `key`, `data`. #[rpc(name = "secretstore_encrypt")] - fn encrypt(&self, H160, Password, Bytes, Bytes) -> Result; + fn encrypt(&self, _: H160, _: Password, _: Bytes, _: Bytes) -> Result; /// Decrypt data with key, received from secret store. /// Arguments: `account`, `password`, `key`, `data`. #[rpc(name = "secretstore_decrypt")] - fn decrypt(&self, H160, Password, Bytes, Bytes) -> Result; + fn decrypt(&self, _: H160, _: Password, _: Bytes, _: Bytes) -> Result; /// Decrypt data with shadow key, received from secret store. /// Arguments: `account`, `password`, `decrypted_secret`, `common_point`, `decrypt_shadows`, `data`. #[rpc(name = "secretstore_shadowDecrypt")] - fn shadow_decrypt(&self, H160, Password, H512, H512, Vec, Bytes) -> Result; + fn shadow_decrypt(&self, _: H160, _: Password, _: H512, _: H512, _: Vec, _: Bytes) -> Result; /// Calculates the hash (keccak256) of servers set for using in ServersSetChange session. /// Returned hash must be signed later by using `secretstore_signRawHash` method. /// Arguments: `servers_set`. #[rpc(name = "secretstore_serversSetHash")] - fn servers_set_hash(&self, BTreeSet) -> Result; + fn servers_set_hash(&self, _: BTreeSet) -> Result; /// Generate recoverable ECDSA signature of raw hash. /// Passed hash is treated as an input to the `sign` function (no prefixes added, no hash function is applied). /// Arguments: `account`, `password`, `raw_hash`. #[rpc(name = "secretstore_signRawHash")] - fn sign_raw_hash(&self, H160, Password, H256) -> Result; + fn sign_raw_hash(&self, _: H160, _: Password, _: H256) -> Result; } diff --git a/rpc/src/v1/traits/signer.rs b/rpc/src/v1/traits/signer.rs index 5a913779006..0fa7e862753 100644 --- a/rpc/src/v1/traits/signer.rs +++ b/rpc/src/v1/traits/signer.rs @@ -35,19 +35,24 @@ pub trait Signer { /// Confirm specific request. #[rpc(name = "signer_confirmRequest")] - fn confirm_request(&self, U256, TransactionModification, String) -> BoxFuture; + fn confirm_request(&self, _: U256, _: TransactionModification, _: String) -> BoxFuture; /// Confirm specific request with token. #[rpc(name = "signer_confirmRequestWithToken")] - fn confirm_request_with_token(&self, U256, TransactionModification, String) -> BoxFuture; + fn confirm_request_with_token( + &self, + _: U256, + _: TransactionModification, + _: String + ) -> BoxFuture; /// Confirm specific request with already signed data. #[rpc(name = "signer_confirmRequestRaw")] - fn confirm_request_raw(&self, U256, Bytes) -> Result; + fn confirm_request_raw(&self, _: U256, _: Bytes) -> Result; /// Reject the confirmation request. #[rpc(name = "signer_rejectRequest")] - fn reject_request(&self, U256) -> Result; + fn reject_request(&self, _: U256) -> Result; /// Generates new authorization token. #[rpc(name = "signer_generateAuthorizationToken")] @@ -55,9 +60,9 @@ pub trait Signer { /// Subscribe to new pending requests on signer interface. #[pubsub(subscription = "signer_pending", subscribe, name = "signer_subscribePending")] - fn subscribe_pending(&self, Self::Metadata, Subscriber>); + fn subscribe_pending(&self, _: Self::Metadata, _: Subscriber>); /// Unsubscribe from pending requests subscription. #[pubsub(subscription = "signer_pending", unsubscribe, name = "signer_unsubscribePending")] - fn unsubscribe_pending(&self, Option, SubscriptionId) -> Result; + fn unsubscribe_pending(&self, _: Option, _: SubscriptionId) -> Result; } diff --git a/rpc/src/v1/traits/traces.rs b/rpc/src/v1/traits/traces.rs index 00a38d71fd5..bff77c3a056 100644 --- a/rpc/src/v1/traits/traces.rs +++ b/rpc/src/v1/traits/traces.rs @@ -30,37 +30,41 @@ pub trait Traces { /// Returns traces matching given filter. #[rpc(name = "trace_filter")] - fn filter(&self, TraceFilter) -> Result>>; + fn filter(&self, _: TraceFilter) -> Result>>; /// Returns transaction trace at given index. #[rpc(name = "trace_get")] - fn trace(&self, H256, Vec) -> Result>; + fn trace(&self, _: H256, _: Vec) -> Result>; /// Returns all traces of given transaction. #[rpc(name = "trace_transaction")] - fn transaction_traces(&self, H256) -> Result>>; + fn transaction_traces(&self, _: H256) -> Result>>; /// Returns all traces produced at given block. #[rpc(name = "trace_block")] - fn block_traces(&self, BlockNumber) -> Result>>; + fn block_traces(&self, _: BlockNumber) -> Result>>; /// Executes the given call and returns a number of possible traces for it. #[rpc(name = "trace_call")] - fn call(&self, CallRequest, TraceOptions, Option) -> Result; + fn call(&self, _: CallRequest, _: TraceOptions, _: Option) -> Result; /// Executes all given calls and returns a number of possible traces for each of it. #[rpc(name = "trace_callMany")] - fn call_many(&self, Vec<(CallRequest, TraceOptions)>, Option) -> Result>; + fn call_many(&self, _: Vec<(CallRequest, TraceOptions)>, _: Option) -> Result>; /// Executes the given raw transaction and returns a number of possible traces for it. #[rpc(name = "trace_rawTransaction")] - fn raw_transaction(&self, Bytes, TraceOptions, Option) -> Result; + fn raw_transaction(&self, _: Bytes, _: TraceOptions, _: Option) -> Result; /// Executes the transaction with the given hash and returns a number of possible traces for it. #[rpc(name = "trace_replayTransaction")] - fn replay_transaction(&self, H256, TraceOptions) -> Result; + fn replay_transaction(&self, _: H256, _: TraceOptions) -> Result; /// Executes all the transactions at the given block and returns a number of possible traces for each transaction. #[rpc(name = "trace_replayBlockTransactions")] - fn replay_block_transactions(&self, BlockNumber, TraceOptions) -> Result>; + fn replay_block_transactions( + &self, + _: BlockNumber, + _: TraceOptions + ) -> Result>; } diff --git a/rpc/src/v1/traits/transactions_pool.rs b/rpc/src/v1/traits/transactions_pool.rs index 5184bf5ad09..1eb19ca1622 100644 --- a/rpc/src/v1/traits/transactions_pool.rs +++ b/rpc/src/v1/traits/transactions_pool.rs @@ -15,9 +15,9 @@ pub trait TransactionsPool { /// Subscribe to Transactions Pool subscription. #[pubsub(subscription = "parity_watchTransactionsPool", subscribe, name = "parity_watchTransactionsPool")] - fn subscribe(&self, Self::Metadata, typed::Subscriber<(H256, TxStatus)>); + fn subscribe(&self, _: Self::Metadata, _: typed::Subscriber<(H256, TxStatus)>); /// Unsubscribe from existing Transactions Pool subscription. #[pubsub(subscription = "parity_watchTransactionsPool", unsubscribe, name = "parity_unwatchTransactionsPool")] - fn unsubscribe(&self, Option, SubscriptionId) -> Result; + fn unsubscribe(&self, _: Option, _: SubscriptionId) -> Result; } diff --git a/rpc/src/v1/traits/web3.rs b/rpc/src/v1/traits/web3.rs index d039d362317..cdeab6d7c47 100644 --- a/rpc/src/v1/traits/web3.rs +++ b/rpc/src/v1/traits/web3.rs @@ -30,5 +30,5 @@ pub trait Web3 { /// Returns sha3 of the given data #[rpc(name = "web3_sha3")] - fn sha3(&self, Bytes) -> Result; + fn sha3(&self, _: Bytes) -> Result; } diff --git a/secret-store/Cargo.toml b/secret-store/Cargo.toml index a956a0edce1..9402a163188 100644 --- a/secret-store/Cargo.toml +++ b/secret-store/Cargo.toml @@ -39,7 +39,7 @@ tokio = "0.1.22" tokio-io = "0.1" tokio-service = "0.1" url = "2.1.0" -jsonrpc-server-utils = "14.0.0" +jsonrpc-server-utils = "14.0.1" [dev-dependencies] env_logger = "0.5" From 20bd1fa789b29824b617e74867b5f4182cc011ae Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Tue, 22 Oct 2019 15:59:58 +0200 Subject: [PATCH 10/13] Remove unused macro_use. (#11191) --- secret-store/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/secret-store/src/lib.rs b/secret-store/src/lib.rs index 23a3e7e3dd4..bdf3f638d28 100644 --- a/secret-store/src/lib.rs +++ b/secret-store/src/lib.rs @@ -42,7 +42,6 @@ extern crate tokio_service; extern crate url; extern crate jsonrpc_server_utils; -#[macro_use] extern crate ethabi_derive; #[macro_use] extern crate ethabi_contract; From 81ca599f2adf7737c4c57f49fce94a304c6fc242 Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Tue, 22 Oct 2019 22:03:52 +0200 Subject: [PATCH 11/13] Made ecrecover implementation trait public (#11188) * Made ecrecover Implementation trait public * Make all builtin contract types public This ensure the API is consistent in terms of visibility. --- ethcore/builtin/src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ethcore/builtin/src/lib.rs b/ethcore/builtin/src/lib.rs index 78633a12ef7..3ecc1499fab 100644 --- a/ethcore/builtin/src/lib.rs +++ b/ethcore/builtin/src/lib.rs @@ -37,7 +37,7 @@ use parity_crypto::digest; use eip_152::compress; /// Native implementation of a built-in contract. -trait Implementation: Send + Sync { +pub trait Implementation: Send + Sync { /// execute this built-in on the given input, writing to the given output. fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), &'static str>; } @@ -305,31 +305,31 @@ fn ethereum_builtin(name: &str) -> Result, EthcoreError> // - blake2_f (The Blake2 compression function F, EIP-152) #[derive(Debug)] -struct Identity; +pub struct Identity; #[derive(Debug)] -struct EcRecover; +pub struct EcRecover; #[derive(Debug)] -struct Sha256; +pub struct Sha256; #[derive(Debug)] -struct Ripemd160; +pub struct Ripemd160; #[derive(Debug)] -struct Modexp; +pub struct Modexp; #[derive(Debug)] -struct Bn128Add; +pub struct Bn128Add; #[derive(Debug)] -struct Bn128Mul; +pub struct Bn128Mul; #[derive(Debug)] -struct Bn128Pairing; +pub struct Bn128Pairing; #[derive(Debug)] -struct Blake2F; +pub struct Blake2F; impl Implementation for Identity { fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), &'static str> { From 834585d61b79fad42c2eab8c0023b7ee60a531fd Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Wed, 23 Oct 2019 13:03:46 +0200 Subject: [PATCH 12/13] Crypto primitives removed from ethkey (#11174) * Crypto utils removed from ethkey * Fix ethkey lib * Switch ethsore to new crypto * Accounts crate fixed * Secret store crate switched to new crypto * Ethcore builtin fixed * Accounts crate fixed * Ethcore crate fixed * Util network fixed * Util network-devp2p fixed * Private tx fixed * Ethcore sync fixed * Secret store fixed * Rpc fixed * Parity fixed * Ethkey cli fixed * Local store fixed * Ethcore blockchain fixed * Cargo.lock pushed; doc comment added for reversed nonce * Ethstore tests fixed * Ethstore cli fixed * Miner fixed * Snapshot tests are fixed * Single brackets removed * Machine fixed * Verification fixed * Executive state fixed * More single brackets removed * Update version of parity-crypto * Use published version 0.4.2 of parity-crypto * New test in tx_filter fixed --- Cargo.lock | 174 +++--- Cargo.toml | 1 + accounts/Cargo.toml | 1 + accounts/ethkey/Cargo.toml | 14 +- accounts/ethkey/cli/Cargo.toml | 1 + accounts/ethkey/cli/src/main.rs | 10 +- accounts/ethkey/src/brain.rs | 12 +- accounts/ethkey/src/brain_prefix.rs | 6 +- accounts/ethkey/src/brain_recover.rs | 3 +- accounts/ethkey/src/crypto.rs | 189 ------- accounts/ethkey/src/error.rs | 81 --- accounts/ethkey/src/extended.rs | 517 ------------------ accounts/ethkey/src/keccak.rs | 31 -- accounts/ethkey/src/keypair.rs | 114 ---- accounts/ethkey/src/lib.rs | 49 +- accounts/ethkey/src/math.rs | 129 ----- accounts/ethkey/src/prefix.rs | 5 +- accounts/ethkey/src/random.rs | 42 -- accounts/ethkey/src/secret.rs | 304 ---------- accounts/ethkey/src/signature.rs | 314 ----------- accounts/ethstore/Cargo.toml | 2 +- accounts/ethstore/cli/Cargo.toml | 2 + accounts/ethstore/cli/src/crack.rs | 3 +- accounts/ethstore/cli/src/main.rs | 5 +- accounts/ethstore/src/account/crypto.rs | 7 +- accounts/ethstore/src/account/safe_account.rs | 9 +- accounts/ethstore/src/accounts_dir/disk.rs | 2 +- accounts/ethstore/src/accounts_dir/memory.rs | 2 +- accounts/ethstore/src/error.rs | 24 +- accounts/ethstore/src/ethkey.rs | 41 -- accounts/ethstore/src/ethstore.rs | 17 +- accounts/ethstore/src/import.rs | 2 +- accounts/ethstore/src/lib.rs | 31 +- accounts/ethstore/src/presale.rs | 5 +- accounts/ethstore/src/secret_store.rs | 5 +- accounts/ethstore/tests/api.rs | 3 +- accounts/src/account_data.rs | 3 +- accounts/src/lib.rs | 6 +- accounts/src/stores.rs | 2 +- ethcore/Cargo.toml | 6 +- ethcore/blockchain/Cargo.toml | 2 +- ethcore/blockchain/src/blockchain.rs | 2 +- ethcore/builtin/Cargo.toml | 3 +- ethcore/builtin/src/lib.rs | 2 +- ethcore/engine/Cargo.toml | 6 +- ethcore/engine/src/engine.rs | 2 +- ethcore/engine/src/signer.rs | 12 +- ethcore/engine/src/test_helpers.rs | 15 +- ethcore/engines/authority-round/Cargo.toml | 2 +- ethcore/engines/authority-round/src/lib.rs | 16 +- ethcore/engines/basic-authority/Cargo.toml | 2 +- ethcore/engines/basic-authority/src/lib.rs | 6 +- ethcore/engines/clique/Cargo.toml | 2 +- ethcore/engines/clique/src/lib.rs | 2 +- ethcore/engines/clique/src/tests.rs | 4 +- ethcore/engines/clique/src/util.rs | 2 +- ethcore/engines/validator-set/Cargo.toml | 2 +- ethcore/engines/validator-set/src/multi.rs | 2 +- .../validator-set/src/safe_contract.rs | 2 +- ethcore/executive-state/Cargo.toml | 2 +- ethcore/executive-state/src/lib.rs | 2 +- ethcore/machine/Cargo.toml | 2 +- ethcore/machine/src/executive.rs | 2 +- ethcore/machine/src/machine.rs | 2 +- ethcore/machine/src/tx_filter.rs | 26 +- ethcore/private-tx/Cargo.toml | 3 +- ethcore/private-tx/src/encryptor.rs | 2 +- ethcore/private-tx/src/error.rs | 13 +- ethcore/private-tx/src/key_server_keys.rs | 5 +- ethcore/private-tx/src/lib.rs | 19 +- ethcore/private-tx/src/messages.rs | 2 +- .../private-tx/src/private_transactions.rs | 2 +- ethcore/private-tx/tests/private_contract.rs | 27 +- ethcore/snapshot/snapshot-tests/Cargo.toml | 2 +- .../snapshot-tests/src/proof_of_authority.rs | 2 +- ethcore/src/client/client.rs | 2 +- ethcore/src/lib.rs | 2 +- ethcore/src/miner/miner.rs | 2 +- ethcore/src/test_helpers/mod.rs | 2 +- ethcore/src/test_helpers/test_client.rs | 2 +- ethcore/src/tests/client.rs | 2 +- ethcore/src/tests/trace.rs | 2 +- ethcore/sync/Cargo.toml | 2 +- ethcore/sync/src/api.rs | 2 +- ethcore/sync/src/block_sync.rs | 2 +- ethcore/sync/src/chain/mod.rs | 2 +- ethcore/sync/src/tests/consensus.rs | 2 +- ethcore/sync/src/tests/private.rs | 2 +- ethcore/types/Cargo.toml | 2 +- ethcore/types/src/errors/ethcore_error.rs | 4 +- ethcore/types/src/lib.rs | 2 +- ethcore/types/src/transaction/error.rs | 6 +- ethcore/types/src/transaction/transaction.rs | 26 +- ethcore/verification/Cargo.toml | 2 +- ethcore/verification/src/verification.rs | 4 +- miner/Cargo.toml | 2 +- miner/local-store/Cargo.toml | 1 + miner/local-store/src/lib.rs | 3 +- miner/src/lib.rs | 2 +- miner/src/pool/local_transactions.rs | 2 +- miner/src/pool/replace.rs | 2 +- miner/src/pool/tests/tx.rs | 2 +- parity/account_utils.rs | 6 +- parity/configuration.rs | 4 +- parity/lib.rs | 1 + parity/presale.rs | 4 +- parity/secretstore.rs | 5 +- rpc/Cargo.toml | 2 +- rpc/src/v1/helpers/dispatch/mod.rs | 3 +- rpc/src/v1/helpers/dispatch/signing.rs | 2 +- rpc/src/v1/helpers/engine_signer.rs | 7 +- rpc/src/v1/helpers/secretstore.rs | 16 +- rpc/src/v1/helpers/signature.rs | 8 +- rpc/src/v1/impls/light/parity.rs | 3 +- rpc/src/v1/impls/parity.rs | 3 +- rpc/src/v1/impls/parity_accounts.rs | 6 +- rpc/src/v1/impls/parity_set.rs | 4 +- rpc/src/v1/impls/personal.rs | 2 +- rpc/src/v1/impls/secretstore.rs | 4 +- rpc/src/v1/impls/signer.rs | 9 +- rpc/src/v1/tests/mocked/parity.rs | 2 +- rpc/src/v1/tests/mocked/personal.rs | 2 +- rpc/src/v1/tests/mocked/secretstore.rs | 2 +- rpc/src/v1/tests/mocked/signing.rs | 3 +- secret-store/Cargo.toml | 4 +- secret-store/src/key_server.rs | 54 +- .../key_version_negotiation_session.rs | 4 +- .../servers_set_change_session.rs | 4 +- .../admin_sessions/share_add_session.rs | 4 +- .../admin_sessions/share_change_session.rs | 2 +- .../client_sessions/decryption_session.rs | 26 +- .../client_sessions/encryption_session.rs | 2 +- .../client_sessions/generation_session.rs | 4 +- .../client_sessions/signing_session_ecdsa.rs | 6 +- .../signing_session_schnorr.rs | 8 +- .../src/key_server_cluster/cluster.rs | 4 +- .../cluster_connections_net.rs | 2 +- .../key_server_cluster/cluster_sessions.rs | 4 +- .../cluster_sessions_creator.rs | 2 +- .../key_server_cluster/connection_trigger.rs | 4 +- .../connection_trigger_with_migration.rs | 2 +- .../src/key_server_cluster/io/handshake.rs | 6 +- .../src/key_server_cluster/io/message.rs | 12 +- .../src/key_server_cluster/io/read_message.rs | 2 +- .../src/key_server_cluster/io/read_payload.rs | 2 +- .../key_server_cluster/io/write_message.rs | 2 +- .../jobs/consensus_session.rs | 2 +- .../key_server_cluster/jobs/decryption_job.rs | 4 +- .../key_server_cluster/jobs/job_session.rs | 2 +- .../jobs/servers_set_change_access_job.rs | 2 +- .../jobs/signing_job_ecdsa.rs | 6 +- .../jobs/signing_job_schnorr.rs | 2 +- secret-store/src/key_server_cluster/math.rs | 79 ++- .../src/key_server_cluster/message.rs | 6 +- .../src/key_server_cluster/net/connection.rs | 2 +- secret-store/src/key_server_set.rs | 4 +- secret-store/src/key_storage.rs | 4 +- secret-store/src/lib.rs | 3 +- secret-store/src/listener/http_listener.rs | 2 +- secret-store/src/listener/service_contract.rs | 4 +- .../listener/service_contract_aggregate.rs | 2 +- .../src/listener/service_contract_listener.rs | 4 +- secret-store/src/node_key_pair.rs | 4 +- secret-store/src/serialization.rs | 18 +- secret-store/src/traits.rs | 2 +- secret-store/src/types/all.rs | 30 +- secret-store/src/types/error.rs | 12 +- util/network-devp2p/Cargo.toml | 3 +- util/network-devp2p/src/connection.rs | 8 +- util/network-devp2p/src/discovery.rs | 4 +- util/network-devp2p/src/handshake.rs | 5 +- util/network-devp2p/src/host.rs | 2 +- util/network-devp2p/tests/tests.rs | 2 +- util/network/Cargo.toml | 3 +- util/network/src/error.rs | 14 +- util/network/src/lib.rs | 3 +- 176 files changed, 579 insertions(+), 2376 deletions(-) delete mode 100644 accounts/ethkey/src/crypto.rs delete mode 100644 accounts/ethkey/src/error.rs delete mode 100644 accounts/ethkey/src/extended.rs delete mode 100644 accounts/ethkey/src/keccak.rs delete mode 100644 accounts/ethkey/src/keypair.rs delete mode 100644 accounts/ethkey/src/math.rs delete mode 100644 accounts/ethkey/src/random.rs delete mode 100644 accounts/ethkey/src/secret.rs delete mode 100644 accounts/ethkey/src/signature.rs delete mode 100644 accounts/ethstore/src/ethkey.rs diff --git a/Cargo.lock b/Cargo.lock index b00c3553702..291ba89d3ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,6 +130,11 @@ dependencies = [ "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ascii" version = "0.7.1" @@ -174,7 +179,6 @@ dependencies = [ "ethcore-io 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -182,6 +186,7 @@ dependencies = [ "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "machine 0.1.0", "macros 0.1.0", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -203,7 +208,7 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -214,7 +219,7 @@ name = "backtrace-sys" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -251,10 +256,10 @@ dependencies = [ "ethcore-accounts 0.1.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "machine 0.1.0", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "spec 0.1.0", @@ -440,7 +445,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.28" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -450,7 +455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -535,13 +540,13 @@ dependencies = [ "ethcore 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "machine 0.1.0", "macros 0.1.0", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -564,7 +569,7 @@ name = "cmake" version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -588,9 +593,9 @@ dependencies = [ "ethcore-io 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", @@ -658,7 +663,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -683,7 +688,7 @@ name = "crossbeam-utils" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -878,10 +883,11 @@ dependencies = [ "ethcore-blockchain 0.1.0", "ethcore-builtin 0.1.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", + "ethkey 0.4.0", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "machine 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "vm 0.1.0", ] @@ -925,17 +931,6 @@ dependencies = [ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "eth-secp256k1" -version = "0.5.7" -source = "git+https://github.com/paritytech/rust-secp256k1#246aefeef6337d208d820936e8e868f11d80e98c" -dependencies = [ - "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ethabi" version = "9.0.1" @@ -1044,7 +1039,6 @@ dependencies = [ "ethcore-stratum 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", "evm 0.1.0", "executive-state 0.1.0", "fetch 0.1.0", @@ -1062,6 +1056,7 @@ dependencies = [ "macros 0.1.0", "memory-cache 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", @@ -1097,9 +1092,10 @@ name = "ethcore-accounts" version = "0.1.0" dependencies = [ "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", + "ethkey 0.4.0", "ethstore 0.2.1", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1117,13 +1113,13 @@ dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-db 0.1.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1153,13 +1149,12 @@ dependencies = [ "eip-152 0.1.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1278,13 +1273,13 @@ dependencies = [ "ethash 1.12.0", "ethcore-call-contract 0.1.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", "fetch 0.1.0", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1308,11 +1303,10 @@ dependencies = [ "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-io 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1331,7 +1325,6 @@ dependencies = [ "ethcore-io 1.12.0", "ethcore-network 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", "igd 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1340,7 +1333,7 @@ dependencies = [ "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-path 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1373,7 +1366,6 @@ dependencies = [ "ethcore-miner 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", "fetch 0.1.0", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1384,7 +1376,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "machine 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", @@ -1422,7 +1414,7 @@ dependencies = [ "ethcore-call-contract 0.1.0", "ethcore-sync 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", + "ethkey 0.4.0", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-server-utils 14.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1432,7 +1424,7 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1503,7 +1495,6 @@ dependencies = [ "ethcore-network-devp2p 1.12.0", "ethcore-private-tx 1.0.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", "fastmap 0.1.0", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1512,6 +1503,7 @@ dependencies = [ "machine 0.1.0", "macros 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1551,22 +1543,14 @@ dependencies = [ [[package]] name = "ethkey" -version = "0.3.0" +version = "0.4.0" dependencies = [ "edit-distance 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)", - "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wordlist 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "zeroize 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1575,8 +1559,9 @@ version = "0.1.0" dependencies = [ "docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", + "ethkey 0.4.0", "panic_hook 0.1.0", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wordlist 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1590,12 +1575,12 @@ version = "0.2.1" dependencies = [ "dir 0.1.2", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", + "ethkey 0.4.0", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wordlist 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1616,9 +1601,11 @@ dependencies = [ "dir 0.1.2", "docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", + "ethkey 0.4.0", "ethstore 0.2.1", "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "panic_hook 0.1.0", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1680,7 +1667,6 @@ dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", "evm 0.1.0", "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1689,6 +1675,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "machine 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "pod 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1881,7 +1868,7 @@ name = "getrandom" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "wasi 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2198,7 +2185,7 @@ name = "jemalloc-sys" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2450,7 +2437,7 @@ name = "libloading" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2491,7 +2478,7 @@ name = "log" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2548,13 +2535,13 @@ dependencies = [ "ethcore-io 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", "evm 0.1.0", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "macros 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2633,11 +2620,6 @@ name = "memory_units" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "memzero" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "migration-rocksdb" version = "0.1.0" @@ -2765,7 +2747,7 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2935,21 +2917,26 @@ dependencies = [ [[package]] name = "parity-crypto" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "block-modes 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memzero 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-secp256k1 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "ripemd160 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "scrypt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2993,7 +2980,7 @@ dependencies = [ "ethcore-service 0.1.0", "ethcore-sync 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", + "ethkey 0.4.0", "ethstore 0.2.1", "fake-fetch 0.0.1", "fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3011,6 +2998,7 @@ dependencies = [ "number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "panic_hook 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-daemonize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-hash-fetch 1.12.0", "parity-ipfs-api 1.12.0", @@ -3091,10 +3079,11 @@ version = "0.1.0" dependencies = [ "common-types 0.1.0", "ethcore-io 1.12.0", - "ethkey 0.3.0", + "ethkey 0.4.0", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3150,7 +3139,7 @@ dependencies = [ "ethcore-sync 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", + "ethkey 0.4.0", "ethstore 0.2.1", "fake-fetch 0.0.1", "fastmap 0.1.0", @@ -3170,7 +3159,7 @@ dependencies = [ "multihash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "order-stat 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parity-updater 1.12.0", "parity-version 2.7.0", @@ -3234,6 +3223,17 @@ dependencies = [ "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parity-secp256k1" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parity-snappy" version = "0.1.0" @@ -3301,7 +3301,7 @@ name = "parity-util-mem" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "jemallocator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3376,7 +3376,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3929,7 +3929,7 @@ name = "ring" version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4229,7 +4229,7 @@ dependencies = [ "ethcore-db 0.1.0", "ethcore-io 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", + "ethkey 0.4.0", "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", @@ -4276,7 +4276,6 @@ dependencies = [ "ethcore-db 0.1.0", "ethcore-io 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4286,6 +4285,7 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", @@ -4305,7 +4305,7 @@ name = "socket2" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5057,7 +5057,6 @@ dependencies = [ "ethcore-call-contract 0.1.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "ethkey 0.3.0", "executive-state 0.1.0", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5066,6 +5065,7 @@ dependencies = [ "machine 0.1.0", "memory-cache 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5118,7 +5118,6 @@ dependencies = [ "ethcore-call-contract 0.1.0", "ethcore-io 1.12.0", "ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethkey 0.3.0", "keccak-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "len-caching-lock 0.1.1", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5126,6 +5125,7 @@ dependencies = [ "null-engine 0.1.0", "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5322,15 +5322,15 @@ dependencies = [ [[package]] name = "zeroize" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "zeroize_derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize_derive 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "zeroize_derive" -version = "0.9.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5350,6 +5350,7 @@ dependencies = [ "checksum app_dirs 1.2.1 (git+https://github.com/paritytech/app-dirs-rs)" = "" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" +"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" "checksum ascii 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae7d751998c189c1d4468cf0a39bb2eae052a9c58d50ebb3b9591ee3813ad50" "checksum assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7deb0a829ca7bcfaf5da70b073a8d128619259a7be8216a355e23f00763059e5" "checksum attohttpc 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eaf0ec4b0e00f61ee75556ca027485b7b354f4a714d88cc03f4468abd9378c86" @@ -5380,9 +5381,9 @@ dependencies = [ "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" "checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" -"checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749" +"checksum cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)" = "0213d356d3c4ea2c18c40b037c3be23cd639825c18f25ee670ac7813beeef99c" "checksum cesu8 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" -"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0e37fba0087d9f3f4e269827a55dc511abf3e440cc097a0c154ff4e6584f988" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" @@ -5418,7 +5419,6 @@ dependencies = [ "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" -"checksum eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)" = "" "checksum ethabi 9.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "965126c64662832991f5a748893577630b558e47fa94e7f35aefcd20d737cef7" "checksum ethabi-contract 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf407dce0290374bfbb1528493bc14320e663f75856b73a5b76262d8e2cec3c9" "checksum ethabi-derive 9.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bd0753d4f9e1dba99450da5f2400b20527702ae8ce0309a5f7c239d305539884" @@ -5515,7 +5515,6 @@ dependencies = [ "checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f" "checksum memory-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a688133a81c915553c1dd9c3e859949f43a854cb8f8773e690e849b53b1f89f0" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" -"checksum memzero 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "93c0d11ac30a033511ae414355d80f70d9f29a44a49140face477117a1ee90db" "checksum mime 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0a907b83e7b9e987032439a387e187119cddafc92d5c2aaeb1d92580a793f630" "checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed" "checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" @@ -5543,12 +5542,13 @@ dependencies = [ "checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5168b4cf41f3835e4bc6ffb32f51bc9365dc50cb351904595b3931d917fd0c" -"checksum parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ded773d0b20caeb099708dcfddf85d75d34ecdba80fcdb573a69af334535d51d" +"checksum parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27a9c2b525c93d717a234eb220c26474f8d97b08ac50d79faeac4cb6c74bf0b9" "checksum parity-daemonize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "69b1910b2793ff52713fca0a4ee92544ebec59ccd218ea74560be6f947b4ca77" "checksum parity-path 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5962540f99d3895d9addf535f37ab1397886bc2c68e59efd040ef458e5f8c3f7" "checksum parity-rocksdb 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d17caf6640e24b70242f3f48615e3f0764f98871e8c7aea25584e29833eb5a8" "checksum parity-rocksdb-sys 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9581e6b8c63f3808500638372ee56faaaffb57c4d349974bff591606b94d5f57" "checksum parity-scale-codec 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "65582b5c02128a4b0fa60fb3e070216e9c84be3e4a8f1b74bc37e15a25e58daf" +"checksum parity-secp256k1 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4fca4f82fccae37e8bbdaeb949a4a218a1bbc485d11598f193d2a908042e5fc1" "checksum parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2c5f9d149b13134b8b354d93a92830efcbee6fe5b73a2e6e540fe70d4dd8a63" "checksum parity-snappy-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1a413d51e5e1927320c9de992998e4a279dffb8c8a7363570198bd8383e66f1b" "checksum parity-tokio-ipc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8281bf4f1d6429573f89589bf68d89451c46750977a8264f8ea3edbabeba7947" @@ -5741,5 +5741,5 @@ dependencies = [ "checksum xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a66b7c2281ebde13cf4391d70d4c7e5946c3c25e72a7b859ca8f677dcd0b0c61" "checksum xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c1cb601d29fe2c2ac60a2b2e5e293994d87a1f6fa9687a31a15270f909be9c2" "checksum xmltree 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff8eaee9d17062850f1e6163b509947969242990ee59a35801af437abe041e70" -"checksum zeroize 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e2ea4afc22e9497e26b42bf047083c30f7e3ca566f3bcd7187f83d18b327043" -"checksum zeroize_derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afd1469e4bbca3b96606d26ba6e9bd6d3aed3b1299c82b92ec94377d22d78dbc" +"checksum zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86" +"checksum zeroize_derive 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "080616bd0e31f36095288bb0acdf1f78ef02c2fa15527d7e993f2a6c7591643e" diff --git a/Cargo.toml b/Cargo.toml index 407f0aa4a69..7783237f054 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ num_cpus = "1.2" number_prefix = "0.2" panic_hook = { path = "util/panic-hook" } parity-bytes = "0.1" +parity-crypto = { version = "0.4.2", features = ["publickey"] } parity-daemonize = "0.3" parity-hash-fetch = { path = "updater/hash-fetch" } parity-ipfs-api = { path = "ipfs" } diff --git a/accounts/Cargo.toml b/accounts/Cargo.toml index a15c5124b04..7e63f9f584c 100644 --- a/accounts/Cargo.toml +++ b/accounts/Cargo.toml @@ -11,6 +11,7 @@ edition = "2018" ethkey = { path = "ethkey" } ethstore = { path = "ethstore" } log = "0.4" +parity-crypto = { version = "0.4.2", features = ["publickey"] } parking_lot = "0.9" serde = "1.0" serde_derive = "1.0" diff --git a/accounts/ethkey/Cargo.toml b/accounts/ethkey/Cargo.toml index fb3716ad08a..8118ad16372 100644 --- a/accounts/ethkey/Cargo.toml +++ b/accounts/ethkey/Cargo.toml @@ -1,21 +1,13 @@ [package] description = "Parity Ethereum Keys Generator" name = "ethkey" -version = "0.3.0" +version = "0.4.0" authors = ["Parity Technologies "] [dependencies] edit-distance = "2.0" -parity-crypto = "0.4.0" -eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" } -ethereum-types = "0.8.0" -lazy_static = "1.0" log = "0.4" -parity-wordlist = "1.3" -quick-error = "1.2.2" -rand = "0.7" -rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" -tiny-keccak = "1.4" -zeroize = "0.9.1" +parity-crypto = { version = "0.4.2", features = ["publickey"] } +parity-wordlist = "1.3" diff --git a/accounts/ethkey/cli/Cargo.toml b/accounts/ethkey/cli/Cargo.toml index cb57f05053f..f9e616ce9a5 100644 --- a/accounts/ethkey/cli/Cargo.toml +++ b/accounts/ethkey/cli/Cargo.toml @@ -9,6 +9,7 @@ docopt = "1.0" env_logger = "0.5" ethkey = { path = "../" } panic_hook = { path = "../../../util/panic-hook" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } parity-wordlist="1.2" rustc-hex = "1.0" serde = "1.0" diff --git a/accounts/ethkey/cli/src/main.rs b/accounts/ethkey/cli/src/main.rs index 759f5f484c1..fb87a3dc5fa 100644 --- a/accounts/ethkey/cli/src/main.rs +++ b/accounts/ethkey/cli/src/main.rs @@ -19,6 +19,7 @@ extern crate env_logger; extern crate ethkey; extern crate panic_hook; extern crate parity_wordlist; +extern crate parity_crypto; extern crate rustc_hex; extern crate serde; extern crate threadpool; @@ -30,7 +31,8 @@ use std::num::ParseIntError; use std::{env, fmt, process, io, sync}; use docopt::Docopt; -use ethkey::{KeyPair, Random, Brain, BrainPrefix, Prefix, Error as EthkeyError, Generator, sign, verify_public, verify_address, brain_recover}; +use ethkey::{Brain, BrainPrefix, Prefix, brain_recover}; +use parity_crypto::publickey::{KeyPair, Random, Error as EthkeyError, Generator, sign, verify_public, verify_address}; use rustc_hex::{FromHex, FromHexError}; const USAGE: &'static str = r#" @@ -200,7 +202,7 @@ fn execute(command: I) -> Result where I: IntoIterator(command: I) -> Result where I: IntoIterator(command: I) -> Result where I: IntoIterator. -use keccak::Keccak256; -use super::{KeyPair, Generator, Secret}; +use std::convert::Infallible; +use parity_crypto::publickey::{KeyPair, Generator, Secret}; +use parity_crypto::Keccak256; use parity_wordlist; /// Simple brainwallet. @@ -32,7 +33,7 @@ impl Brain { } impl Generator for Brain { - type Error = ::Void; + type Error = Infallible; fn generate(&mut self) -> Result { let seed = self.0.clone(); @@ -45,7 +46,7 @@ impl Generator for Brain { match i > 16384 { false => i += 1, true => { - if let Ok(pair) = Secret::from_unsafe_slice(&secret) + if let Ok(pair) = Secret::import_key(&secret) .and_then(KeyPair::from_secret) { if pair.address()[0] == 0 { @@ -61,7 +62,8 @@ impl Generator for Brain { #[cfg(test)] mod tests { - use {Brain, Generator}; + use Brain; + use parity_crypto::publickey::Generator; #[test] fn test_brain() { diff --git a/accounts/ethkey/src/brain_prefix.rs b/accounts/ethkey/src/brain_prefix.rs index 436a6594f62..3974d399612 100644 --- a/accounts/ethkey/src/brain_prefix.rs +++ b/accounts/ethkey/src/brain_prefix.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use super::{Generator, KeyPair, Error, Brain}; +use super::Brain; +use parity_crypto::publickey::{Generator, KeyPair, Error}; use parity_wordlist as wordlist; /// Tries to find brain-seed keypair with address starting with given prefix. @@ -59,7 +60,8 @@ impl Generator for BrainPrefix { #[cfg(test)] mod tests { - use {Generator, BrainPrefix}; + use BrainPrefix; + use parity_crypto::publickey::Generator; #[test] fn prefix_generator() { diff --git a/accounts/ethkey/src/brain_recover.rs b/accounts/ethkey/src/brain_recover.rs index f9922fae97f..e5745d8a4ea 100644 --- a/accounts/ethkey/src/brain_recover.rs +++ b/accounts/ethkey/src/brain_recover.rs @@ -19,7 +19,8 @@ use std::collections::HashSet; use edit_distance::edit_distance; use parity_wordlist; -use super::{Address, Brain, Generator}; +use super::Brain; +use parity_crypto::publickey::{Address, Generator}; /// Tries to find a phrase for address, given the number /// of expected words and a partial phrase. diff --git a/accounts/ethkey/src/crypto.rs b/accounts/ethkey/src/crypto.rs deleted file mode 100644 index c2da84ecb87..00000000000 --- a/accounts/ethkey/src/crypto.rs +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -use secp256k1; -use std::io; -use parity_crypto::error::SymmError; - -quick_error! { - #[derive(Debug)] - pub enum Error { - Secp(e: secp256k1::Error) { - display("secp256k1 error: {}", e) - cause(e) - from() - } - Io(e: io::Error) { - display("i/o error: {}", e) - cause(e) - from() - } - InvalidMessage { - display("invalid message") - } - Symm(e: SymmError) { - cause(e) - from() - } - } -} - -/// ECDH functions -pub mod ecdh { - use secp256k1::{self, ecdh, key}; - use super::Error; - use {Secret, Public, SECP256K1}; - - /// Agree on a shared secret - pub fn agree(secret: &Secret, public: &Public) -> Result { - let context = &SECP256K1; - let pdata = { - let mut temp = [4u8; 65]; - (&mut temp[1..65]).copy_from_slice(&public[0..64]); - temp - }; - - let publ = key::PublicKey::from_slice(context, &pdata)?; - let sec = key::SecretKey::from_slice(context, secret.as_bytes())?; - let shared = ecdh::SharedSecret::new_raw(context, &publ, &sec); - - Secret::from_unsafe_slice(&shared[0..32]) - .map_err(|_| Error::Secp(secp256k1::Error::InvalidSecretKey)) - } -} - -/// ECIES function -pub mod ecies { - use parity_crypto::{aes, digest, hmac, is_equal}; - use ethereum_types::H128; - use super::{ecdh, Error}; - use {Random, Generator, Public, Secret}; - - /// Encrypt a message with a public key, writing an HMAC covering both - /// the plaintext and authenticated data. - /// - /// Authenticated data may be empty. - pub fn encrypt(public: &Public, auth_data: &[u8], plain: &[u8]) -> Result, Error> { - let r = Random.generate()?; - let z = ecdh::agree(r.secret(), public)?; - let mut key = [0u8; 32]; - kdf(&z, &[0u8; 0], &mut key); - - let ekey = &key[0..16]; - let mkey = hmac::SigKey::sha256(&digest::sha256(&key[16..32])); - - let mut msg = vec![0u8; 1 + 64 + 16 + plain.len() + 32]; - msg[0] = 0x04u8; - { - let msgd = &mut msg[1..]; - msgd[0..64].copy_from_slice(r.public().as_bytes()); - let iv = H128::random(); - msgd[64..80].copy_from_slice(iv.as_bytes()); - { - let cipher = &mut msgd[(64 + 16)..(64 + 16 + plain.len())]; - aes::encrypt_128_ctr(ekey, iv.as_bytes(), plain, cipher)?; - } - let mut hmac = hmac::Signer::with(&mkey); - { - let cipher_iv = &msgd[64..(64 + 16 + plain.len())]; - hmac.update(cipher_iv); - } - hmac.update(auth_data); - let sig = hmac.sign(); - msgd[(64 + 16 + plain.len())..].copy_from_slice(&sig); - } - Ok(msg) - } - - /// Decrypt a message with a secret key, checking HMAC for ciphertext - /// and authenticated data validity. - pub fn decrypt(secret: &Secret, auth_data: &[u8], encrypted: &[u8]) -> Result, Error> { - let meta_len = 1 + 64 + 16 + 32; - if encrypted.len() < meta_len || encrypted[0] < 2 || encrypted[0] > 4 { - return Err(Error::InvalidMessage); //invalid message: publickey - } - - let e = &encrypted[1..]; - let p = Public::from_slice(&e[0..64]); - let z = ecdh::agree(secret, &p)?; - let mut key = [0u8; 32]; - kdf(&z, &[0u8; 0], &mut key); - - let ekey = &key[0..16]; - let mkey = hmac::SigKey::sha256(&digest::sha256(&key[16..32])); - - let clen = encrypted.len() - meta_len; - let cipher_with_iv = &e[64..(64+16+clen)]; - let cipher_iv = &cipher_with_iv[0..16]; - let cipher_no_iv = &cipher_with_iv[16..]; - let msg_mac = &e[(64+16+clen)..]; - - // Verify tag - let mut hmac = hmac::Signer::with(&mkey); - hmac.update(cipher_with_iv); - hmac.update(auth_data); - let mac = hmac.sign(); - - if !is_equal(&mac.as_ref()[..], msg_mac) { - return Err(Error::InvalidMessage); - } - - let mut msg = vec![0u8; clen]; - aes::decrypt_128_ctr(ekey, cipher_iv, cipher_no_iv, &mut msg[..])?; - Ok(msg) - } - - fn kdf(secret: &Secret, s1: &[u8], dest: &mut [u8]) { - // SEC/ISO/Shoup specify counter size SHOULD be equivalent - // to size of hash output, however, it also notes that - // the 4 bytes is okay. NIST specifies 4 bytes. - let mut ctr = 1u32; - let mut written = 0usize; - while written < dest.len() { - let mut hasher = digest::Hasher::sha256(); - let ctrs = [(ctr >> 24) as u8, (ctr >> 16) as u8, (ctr >> 8) as u8, ctr as u8]; - hasher.update(&ctrs); - hasher.update(secret.as_bytes()); - hasher.update(s1); - let d = hasher.finish(); - &mut dest[written..(written + 32)].copy_from_slice(&d); - written += 32; - ctr += 1; - } - } -} - -#[cfg(test)] -mod tests { - use super::ecies; - use {Random, Generator}; - - #[test] - fn ecies_shared() { - let kp = Random.generate().unwrap(); - let message = b"So many books, so little time"; - - let shared = b"shared"; - let wrong_shared = b"incorrect"; - let encrypted = ecies::encrypt(kp.public(), shared, message).unwrap(); - assert!(encrypted[..] != message[..]); - assert_eq!(encrypted[0], 0x04); - - assert!(ecies::decrypt(kp.secret(), wrong_shared, &encrypted).is_err()); - let decrypted = ecies::decrypt(kp.secret(), shared, &encrypted).unwrap(); - assert_eq!(decrypted[..message.len()], message[..]); - } -} diff --git a/accounts/ethkey/src/error.rs b/accounts/ethkey/src/error.rs deleted file mode 100644 index ee191157453..00000000000 --- a/accounts/ethkey/src/error.rs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -use std::{fmt, error}; - -#[derive(Debug)] -/// Crypto error -pub enum Error { - /// Invalid secret key - InvalidSecret, - /// Invalid public key - InvalidPublic, - /// Invalid address - InvalidAddress, - /// Invalid EC signature - InvalidSignature, - /// Invalid AES message - InvalidMessage, - /// IO Error - Io(::std::io::Error), - /// Custom - Custom(String), -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let msg = match *self { - Error::InvalidSecret => "Invalid secret".into(), - Error::InvalidPublic => "Invalid public".into(), - Error::InvalidAddress => "Invalid address".into(), - Error::InvalidSignature => "Invalid EC signature".into(), - Error::InvalidMessage => "Invalid AES message".into(), - Error::Io(ref err) => format!("I/O error: {}", err), - Error::Custom(ref s) => s.clone(), - }; - - f.write_fmt(format_args!("Crypto error ({})", msg)) - } -} - -impl error::Error for Error { - fn description(&self) -> &str { - "Crypto error" - } -} - -impl Into for Error { - fn into(self) -> String { - format!("{}", self) - } -} - -impl From<::secp256k1::Error> for Error { - fn from(e: ::secp256k1::Error) -> Error { - match e { - ::secp256k1::Error::InvalidMessage => Error::InvalidMessage, - ::secp256k1::Error::InvalidPublicKey => Error::InvalidPublic, - ::secp256k1::Error::InvalidSecretKey => Error::InvalidSecret, - _ => Error::InvalidSignature, - } - } -} - -impl From<::std::io::Error> for Error { - fn from(err: ::std::io::Error) -> Error { - Error::Io(err) - } -} diff --git a/accounts/ethkey/src/extended.rs b/accounts/ethkey/src/extended.rs deleted file mode 100644 index 005f4ba6616..00000000000 --- a/accounts/ethkey/src/extended.rs +++ /dev/null @@ -1,517 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Extended keys - -use secret::Secret; -use Public; -use ethereum_types::H256; -pub use self::derivation::Error as DerivationError; - -/// Represents label that can be stored as a part of key derivation -pub trait Label { - /// Length of the data that label occupies - fn len() -> usize; - - /// Store label data to the key derivation sequence - /// Must not use more than `len()` bytes from slice - fn store(&self, target: &mut [u8]); -} - -impl Label for u32 { - fn len() -> usize { 4 } - - fn store(&self, target: &mut [u8]) { - let bytes = self.to_be_bytes(); - target[0..4].copy_from_slice(&bytes); - } -} - -/// Key derivation over generic label `T` -pub enum Derivation { - /// Soft key derivation (allow proof of parent) - Soft(T), - /// Hard key derivation (does not allow proof of parent) - Hard(T), -} - -impl From for Derivation { - fn from(index: u32) -> Self { - if index < (2 << 30) { - Derivation::Soft(index) - } - else { - Derivation::Hard(index) - } - } -} - -impl Label for H256 { - fn len() -> usize { 32 } - - fn store(&self, target: &mut [u8]) { - (&mut target[0..32]).copy_from_slice(self.as_bytes()); - } -} - -/// Extended secret key, allows deterministic derivation of subsequent keys. -pub struct ExtendedSecret { - secret: Secret, - chain_code: H256, -} - -impl ExtendedSecret { - /// New extended key from given secret and chain code. - pub fn with_code(secret: Secret, chain_code: H256) -> ExtendedSecret { - ExtendedSecret { - secret: secret, - chain_code: chain_code, - } - } - - /// New extended key from given secret with the random chain code. - pub fn new_random(secret: Secret) -> ExtendedSecret { - ExtendedSecret::with_code(secret, H256::random()) - } - - /// New extended key from given secret. - /// Chain code will be derived from the secret itself (in a deterministic way). - pub fn new(secret: Secret) -> ExtendedSecret { - let chain_code = derivation::chain_code(*secret); - ExtendedSecret::with_code(secret, chain_code) - } - - /// Derive new private key - pub fn derive(&self, index: Derivation) -> ExtendedSecret where T: Label { - let (derived_key, next_chain_code) = derivation::private(*self.secret, self.chain_code, index); - - let derived_secret = Secret::from(derived_key.0); - - ExtendedSecret::with_code(derived_secret, next_chain_code) - } - - /// Private key component of the extended key. - pub fn as_raw(&self) -> &Secret { - &self.secret - } -} - -/// Extended public key, allows deterministic derivation of subsequent keys. -pub struct ExtendedPublic { - public: Public, - chain_code: H256, -} - -impl ExtendedPublic { - /// New extended public key from known parent and chain code - pub fn new(public: Public, chain_code: H256) -> Self { - ExtendedPublic { public: public, chain_code: chain_code } - } - - /// Create new extended public key from known secret - pub fn from_secret(secret: &ExtendedSecret) -> Result { - Ok( - ExtendedPublic::new( - derivation::point(**secret.as_raw())?, - secret.chain_code.clone(), - ) - ) - } - - /// Derive new public key - /// Operation is defined only for index belongs [0..2^31) - pub fn derive(&self, index: Derivation) -> Result where T: Label { - let (derived_key, next_chain_code) = derivation::public(self.public, self.chain_code, index)?; - Ok(ExtendedPublic::new(derived_key, next_chain_code)) - } - - pub fn public(&self) -> &Public { - &self.public - } -} - -pub struct ExtendedKeyPair { - secret: ExtendedSecret, - public: ExtendedPublic, -} - -impl ExtendedKeyPair { - pub fn new(secret: Secret) -> Self { - let extended_secret = ExtendedSecret::new(secret); - let extended_public = ExtendedPublic::from_secret(&extended_secret) - .expect("Valid `Secret` always produces valid public; qed"); - ExtendedKeyPair { - secret: extended_secret, - public: extended_public, - } - } - - pub fn with_code(secret: Secret, public: Public, chain_code: H256) -> Self { - ExtendedKeyPair { - secret: ExtendedSecret::with_code(secret, chain_code.clone()), - public: ExtendedPublic::new(public, chain_code), - } - } - - pub fn with_secret(secret: Secret, chain_code: H256) -> Self { - let extended_secret = ExtendedSecret::with_code(secret, chain_code); - let extended_public = ExtendedPublic::from_secret(&extended_secret) - .expect("Valid `Secret` always produces valid public; qed"); - ExtendedKeyPair { - secret: extended_secret, - public: extended_public, - } - } - - pub fn with_seed(seed: &[u8]) -> Result { - let (master_key, chain_code) = derivation::seed_pair(seed); - Ok(ExtendedKeyPair::with_secret( - Secret::from_unsafe_slice(master_key.as_bytes()).map_err(|_| DerivationError::InvalidSeed)?, - chain_code, - )) - } - - pub fn secret(&self) -> &ExtendedSecret { - &self.secret - } - - pub fn public(&self) -> &ExtendedPublic { - &self.public - } - - pub fn derive(&self, index: Derivation) -> Result where T: Label { - let derived = self.secret.derive(index); - - Ok(ExtendedKeyPair { - public: ExtendedPublic::from_secret(&derived)?, - secret: derived, - }) - } -} - -// Derivation functions for private and public keys -// Work is based on BIP0032 -// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki -mod derivation { - use parity_crypto::hmac; - use ethereum_types::{BigEndianHash, U256, U512, H512, H256}; - use secp256k1::key::{SecretKey, PublicKey}; - use SECP256K1; - use keccak; - use math::curve_order; - use super::{Label, Derivation}; - use std::convert::TryInto; - - #[derive(Debug)] - pub enum Error { - InvalidHardenedUse, - InvalidPoint, - MissingIndex, - InvalidSeed, - } - - // Deterministic derivation of the key using secp256k1 elliptic curve. - // Derivation can be either hardened or not. - // For hardened derivation, pass u32 index at least 2^31 or custom Derivation::Hard(T) enum - // - // Can panic if passed `private_key` is not a valid secp256k1 private key - // (outside of (0..curve_order()]) field - pub fn private(private_key: H256, chain_code: H256, index: Derivation) -> (H256, H256) where T: Label { - match index { - Derivation::Soft(index) => private_soft(private_key, chain_code, index), - Derivation::Hard(index) => private_hard(private_key, chain_code, index), - } - } - - fn hmac_pair(data: &[u8], private_key: H256, chain_code: H256) -> (H256, H256) { - let private: U256 = private_key.into_uint(); - - // produces 512-bit derived hmac (I) - let skey = hmac::SigKey::sha512(chain_code.as_bytes()); - let i_512 = hmac::sign(&skey, &data[..]); - - // left most 256 bits are later added to original private key - let hmac_key: U256 = H256::from_slice(&i_512[0..32]).into_uint(); - // right most 256 bits are new chain code for later derivations - let next_chain_code = H256::from_slice(&i_512[32..64]); - - let child_key = BigEndianHash::from_uint(&private_add(hmac_key, private)); - (child_key, next_chain_code) - } - - // Can panic if passed `private_key` is not a valid secp256k1 private key - // (outside of (0..curve_order()]) field - fn private_soft(private_key: H256, chain_code: H256, index: T) -> (H256, H256) where T: Label { - let mut data = vec![0u8; 33 + T::len()]; - - let sec_private = SecretKey::from_slice(&SECP256K1, private_key.as_bytes()) - .expect("Caller should provide valid private key"); - let sec_public = PublicKey::from_secret_key(&SECP256K1, &sec_private) - .expect("Caller should provide valid private key"); - let public_serialized = sec_public.serialize_vec(&SECP256K1, true); - - // curve point (compressed public key) -- index - // 0.33 -- 33..end - data[0..33].copy_from_slice(&public_serialized); - index.store(&mut data[33..]); - - hmac_pair(&data, private_key, chain_code) - } - - // Deterministic derivation of the key using secp256k1 elliptic curve - // This is hardened derivation and does not allow to associate - // corresponding public keys of the original and derived private keys - fn private_hard(private_key: H256, chain_code: H256, index: T) -> (H256, H256) where T: Label { - let mut data: Vec = vec![0u8; 33 + T::len()]; - let private: U256 = private_key.into_uint(); - - // 0x00 (padding) -- private_key -- index - // 0 -- 1..33 -- 33..end - private.to_big_endian(&mut data[1..33]); - index.store(&mut data[33..(33 + T::len())]); - - hmac_pair(&data, private_key, chain_code) - } - - fn private_add(k1: U256, k2: U256) -> U256 { - let sum = U512::from(k1) + U512::from(k2); - modulo(sum, curve_order()) - } - - // todo: surely can be optimized - fn modulo(u1: U512, u2: U256) -> U256 { - let m = u1 % U512::from(u2); - m.try_into().expect("U512 modulo U256 should fit into U256; qed") - } - - pub fn public(public_key: H512, chain_code: H256, derivation: Derivation) -> Result<(H512, H256), Error> where T: Label { - let index = match derivation { - Derivation::Soft(index) => index, - Derivation::Hard(_) => { return Err(Error::InvalidHardenedUse); } - }; - - let mut public_sec_raw = [0u8; 65]; - public_sec_raw[0] = 4; - public_sec_raw[1..65].copy_from_slice(public_key.as_bytes()); - let public_sec = PublicKey::from_slice(&SECP256K1, &public_sec_raw).map_err(|_| Error::InvalidPoint)?; - let public_serialized = public_sec.serialize_vec(&SECP256K1, true); - - let mut data = vec![0u8; 33 + T::len()]; - // curve point (compressed public key) -- index - // 0.33 -- 33..end - data[0..33].copy_from_slice(&public_serialized); - index.store(&mut data[33..(33 + T::len())]); - - // HMAC512SHA produces [derived private(256); new chain code(256)] - let skey = hmac::SigKey::sha512(chain_code.as_bytes()); - let i_512 = hmac::sign(&skey, &data[..]); - - let new_private = H256::from_slice(&i_512[0..32]); - let new_chain_code = H256::from_slice(&i_512[32..64]); - - // Generated private key can (extremely rarely) be out of secp256k1 key field - if curve_order() <= new_private.into_uint() { return Err(Error::MissingIndex); } - let new_private_sec = SecretKey::from_slice(&SECP256K1, new_private.as_bytes()) - .expect("Private key belongs to the field [0..CURVE_ORDER) (checked above); So initializing can never fail; qed"); - let mut new_public = PublicKey::from_secret_key(&SECP256K1, &new_private_sec) - .expect("Valid private key produces valid public key"); - - // Adding two points on the elliptic curves (combining two public keys) - new_public.add_assign(&SECP256K1, &public_sec) - .expect("Addition of two valid points produce valid point"); - - let serialized = new_public.serialize_vec(&SECP256K1, false); - - Ok(( - H512::from_slice(&serialized[1..65]), - new_chain_code, - )) - } - - fn sha3(slc: &[u8]) -> H256 { - keccak::Keccak256::keccak256(slc).into() - } - - pub fn chain_code(secret: H256) -> H256 { - // 10,000 rounds of sha3 - let mut running_sha3 = sha3(secret.as_bytes()); - for _ in 0..99999 { running_sha3 = sha3(running_sha3.as_bytes()); } - running_sha3 - } - - pub fn point(secret: H256) -> Result { - let sec = SecretKey::from_slice(&SECP256K1, secret.as_bytes()) - .map_err(|_| Error::InvalidPoint)?; - let public_sec = PublicKey::from_secret_key(&SECP256K1, &sec) - .map_err(|_| Error::InvalidPoint)?; - let serialized = public_sec.serialize_vec(&SECP256K1, false); - Ok(H512::from_slice(&serialized[1..65])) - } - - pub fn seed_pair(seed: &[u8]) -> (H256, H256) { - let skey = hmac::SigKey::sha512(b"Bitcoin seed"); - let i_512 = hmac::sign(&skey, seed); - - let master_key = H256::from_slice(&i_512[0..32]); - let chain_code = H256::from_slice(&i_512[32..64]); - - (master_key, chain_code) - } -} - -#[cfg(test)] -mod tests { - use super::{ExtendedSecret, ExtendedPublic, ExtendedKeyPair}; - use secret::Secret; - use std::str::FromStr; - use ethereum_types::{H128, H256, H512}; - use super::{derivation, Derivation}; - - fn master_chain_basic() -> (H256, H256) { - let seed = H128::from_str("000102030405060708090a0b0c0d0e0f") - .expect("Seed should be valid H128") - .as_bytes() - .to_vec(); - - derivation::seed_pair(&*seed) - } - - fn test_extended(f: F, test_private: H256) where F: Fn(ExtendedSecret) -> ExtendedSecret { - let (private_seed, chain_code) = master_chain_basic(); - let extended_secret = ExtendedSecret::with_code(Secret::from(private_seed.0), chain_code); - let derived = f(extended_secret); - assert_eq!(**derived.as_raw(), test_private); - } - - #[test] - fn smoky() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::zero()); - - // hardened - assert_eq!(&**extended_secret.as_raw(), &*secret); - assert_eq!( - **extended_secret.derive(2147483648.into()).as_raw(), - H256::from_str("0927453daed47839608e414a3738dfad10aed17c459bbd9ab53f89b026c834b6").unwrap(), - ); - assert_eq!( - **extended_secret.derive(2147483649.into()).as_raw(), - H256::from_str("44238b6a29c6dcbe9b401364141ba11e2198c289a5fed243a1c11af35c19dc0f").unwrap(), - ); - - // normal - assert_eq!(**extended_secret.derive(0.into()).as_raw(), H256::from_str("bf6a74e3f7b36fc4c96a1e12f31abc817f9f5904f5a8fc27713163d1f0b713f6").unwrap()); - assert_eq!(**extended_secret.derive(1.into()).as_raw(), H256::from_str("bd4fca9eb1f9c201e9448c1eecd66e302d68d4d313ce895b8c134f512205c1bc").unwrap()); - assert_eq!(**extended_secret.derive(2.into()).as_raw(), H256::from_str("86932b542d6cab4d9c65490c7ef502d89ecc0e2a5f4852157649e3251e2a3268").unwrap()); - - let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); - let derived_public = extended_public.derive(0.into()).expect("First derivation of public should succeed"); - assert_eq!( - *derived_public.public(), - H512::from_str("f7b3244c96688f92372bfd4def26dc4151529747bab9f188a4ad34e141d47bd66522ff048bc6f19a0a4429b04318b1a8796c000265b4fa200dae5f6dda92dd94").unwrap(), - ); - - let keypair = ExtendedKeyPair::with_secret( - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(), - H256::from_low_u64_be(64), - ); - assert_eq!( - **keypair.derive(2147483648u32.into()).expect("Derivation of keypair should succeed").secret().as_raw(), - H256::from_str("edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c").unwrap(), - ); - } - - #[test] - fn h256_soft_match() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let derivation_secret = H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015").unwrap(); - - let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::zero()); - let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); - - let derived_secret0 = extended_secret.derive(Derivation::Soft(derivation_secret)); - let derived_public0 = extended_public.derive(Derivation::Soft(derivation_secret)).expect("First derivation of public should succeed"); - - let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0).expect("Extended public should be created"); - - assert_eq!(public_from_secret0.public(), derived_public0.public()); - } - - #[test] - fn h256_hard() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let derivation_secret = H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015").unwrap(); - let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::from_low_u64_be(1)); - - assert_eq!( - **extended_secret.derive(Derivation::Hard(derivation_secret)).as_raw(), - H256::from_str("2bc2d696fb744d77ff813b4a1ef0ad64e1e5188b622c54ba917acc5ebc7c5486").unwrap(), - ); - } - - #[test] - fn match_() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::from_low_u64_be(1)); - let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); - - let derived_secret0 = extended_secret.derive(0.into()); - let derived_public0 = extended_public.derive(0.into()).expect("First derivation of public should succeed"); - - let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0).expect("Extended public should be created"); - - assert_eq!(public_from_secret0.public(), derived_public0.public()); - } - - #[test] - fn test_seeds() { - let seed = H128::from_str("000102030405060708090a0b0c0d0e0f") - .expect("Seed should be valid H128") - .as_bytes() - .to_vec(); - - // private key from bitcoin test vector - // xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs - let test_private = H256::from_str("e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35") - .expect("Private should be decoded ok"); - - let (private_seed, _) = derivation::seed_pair(&*seed); - - assert_eq!(private_seed, test_private); - } - - #[test] - fn test_vector_1() { - // xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7 - // H(0) - test_extended( - |secret| secret.derive(2147483648.into()), - H256::from_str("edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea") - .expect("Private should be decoded ok") - ); - } - - #[test] - fn test_vector_2() { - // xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs - // H(0)/1 - test_extended( - |secret| secret.derive(2147483648.into()).derive(1.into()), - H256::from_str("3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368") - .expect("Private should be decoded ok") - ); - } -} diff --git a/accounts/ethkey/src/keccak.rs b/accounts/ethkey/src/keccak.rs deleted file mode 100644 index 202c211933c..00000000000 --- a/accounts/ethkey/src/keccak.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -use tiny_keccak::Keccak; - -pub trait Keccak256 { - fn keccak256(&self) -> T where T: Sized; -} - -impl Keccak256<[u8; 32]> for [u8] { - fn keccak256(&self) -> [u8; 32] { - let mut keccak = Keccak::new_keccak256(); - let mut result = [0u8; 32]; - keccak.update(self); - keccak.finalize(&mut result); - result - } -} diff --git a/accounts/ethkey/src/keypair.rs b/accounts/ethkey/src/keypair.rs deleted file mode 100644 index 7b350788bb5..00000000000 --- a/accounts/ethkey/src/keypair.rs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -use std::fmt; -use secp256k1::key; -use super::{Secret, Public, Address, SECP256K1, Error}; -use parity_crypto::Keccak256 as _; - -pub fn public_to_address(public: &Public) -> Address { - let hash = public.keccak256(); - let mut result = Address::zero(); - result.as_bytes_mut().copy_from_slice(&hash[12..]); - result -} - -#[derive(Debug, Clone, PartialEq)] -/// secp256k1 key pair -pub struct KeyPair { - secret: Secret, - public: Public, -} - -impl fmt::Display for KeyPair { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - writeln!(f, "secret: {:x}", self.secret)?; - writeln!(f, "public: {:x}", self.public)?; - write!(f, "address: {:x}", self.address()) - } -} - -impl KeyPair { - /// Create a pair from secret key - pub fn from_secret(secret: Secret) -> Result { - let context = &SECP256K1; - let s: key::SecretKey = key::SecretKey::from_slice(context, &secret[..])?; - let pub_key = key::PublicKey::from_secret_key(context, &s)?; - let serialized = pub_key.serialize_vec(context, false); - - let mut public = Public::default(); - public.as_bytes_mut().copy_from_slice(&serialized[1..65]); - - let keypair = KeyPair { - secret: secret, - public: public, - }; - - Ok(keypair) - } - - pub fn from_secret_slice(slice: &[u8]) -> Result { - Self::from_secret(Secret::from_unsafe_slice(slice)?) - } - - pub fn from_keypair(sec: key::SecretKey, publ: key::PublicKey) -> Self { - let context = &SECP256K1; - let serialized = publ.serialize_vec(context, false); - let secret = Secret::from(sec); - let mut public = Public::default(); - public.as_bytes_mut().copy_from_slice(&serialized[1..65]); - - KeyPair { - secret: secret, - public: public, - } - } - - pub fn secret(&self) -> &Secret { - &self.secret - } - - pub fn public(&self) -> &Public { - &self.public - } - - pub fn address(&self) -> Address { - public_to_address(&self.public) - } -} - -#[cfg(test)] -mod tests { - use std::str::FromStr; - use {KeyPair, Secret}; - - #[test] - fn from_secret() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let _ = KeyPair::from_secret(secret).unwrap(); - } - - #[test] - fn keypair_display() { - let expected = -"secret: a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65 -public: 8ce0db0b0359ffc5866ba61903cc2518c3675ef2cf380a7e54bde7ea20e6fa1ab45b7617346cd11b7610001ee6ae5b0155c41cad9527cbcdff44ec67848943a4 -address: 5b073e9233944b5e729e46d618f0d8edf3d9c34a".to_owned(); - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let kp = KeyPair::from_secret(secret).unwrap(); - assert_eq!(format!("{}", kp), expected); - } -} diff --git a/accounts/ethkey/src/lib.rs b/accounts/ethkey/src/lib.rs index 4f55f056d07..185d254ba67 100644 --- a/accounts/ethkey/src/lib.rs +++ b/accounts/ethkey/src/lib.rs @@ -18,19 +18,9 @@ extern crate edit_distance; extern crate parity_crypto; -extern crate ethereum_types; extern crate parity_wordlist; -#[macro_use] -extern crate quick_error; -extern crate rand; -extern crate rustc_hex; -extern crate secp256k1; extern crate serde; -extern crate tiny_keccak; -extern crate zeroize; -#[macro_use] -extern crate lazy_static; #[macro_use] extern crate log; #[macro_use] @@ -38,50 +28,13 @@ extern crate serde_derive; mod brain; mod brain_prefix; -mod error; -mod keypair; -mod keccak; mod password; mod prefix; -mod random; -mod signature; -mod secret; -mod extended; pub mod brain_recover; -pub mod crypto; -pub mod math; pub use self::parity_wordlist::Error as WordlistError; pub use self::brain::Brain; pub use self::brain_prefix::BrainPrefix; -pub use self::error::Error; -pub use self::keypair::{KeyPair, public_to_address}; -pub use self::math::public_is_valid; pub use self::password::Password; -pub use self::prefix::Prefix; -pub use self::random::Random; -pub use self::signature::{sign, verify_public, verify_address, recover, Signature}; -pub use self::secret::Secret; -pub use self::extended::{ExtendedPublic, ExtendedSecret, ExtendedKeyPair, DerivationError, Derivation}; - -use ethereum_types::H256; - -pub use ethereum_types::{Address, Public}; -pub type Message = H256; - -lazy_static! { - pub static ref SECP256K1: secp256k1::Secp256k1 = secp256k1::Secp256k1::new(); -} - -/// Uninstantiatable error type for infallible generators. -#[derive(Debug)] -pub enum Void {} - -/// Generates new keypair. -pub trait Generator { - type Error; - - /// Should be called to generate new keypair. - fn generate(&mut self) -> Result; -} +pub use self::prefix::Prefix; \ No newline at end of file diff --git a/accounts/ethkey/src/math.rs b/accounts/ethkey/src/math.rs deleted file mode 100644 index 5025efeb654..00000000000 --- a/accounts/ethkey/src/math.rs +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -use super::{SECP256K1, Public, Secret, Error}; -use secp256k1::key; -use secp256k1::constants::{GENERATOR_X, GENERATOR_Y, CURVE_ORDER}; -use ethereum_types::{BigEndianHash as _, U256, H256}; - -/// Whether the public key is valid. -pub fn public_is_valid(public: &Public) -> bool { - to_secp256k1_public(public).ok() - .map_or(false, |p| p.is_valid()) -} - -/// Inplace multiply public key by secret key (EC point * scalar) -pub fn public_mul_secret(public: &mut Public, secret: &Secret) -> Result<(), Error> { - let key_secret = secret.to_secp256k1_secret()?; - let mut key_public = to_secp256k1_public(public)?; - key_public.mul_assign(&SECP256K1, &key_secret)?; - set_public(public, &key_public); - Ok(()) -} - -/// Inplace add one public key to another (EC point + EC point) -pub fn public_add(public: &mut Public, other: &Public) -> Result<(), Error> { - let mut key_public = to_secp256k1_public(public)?; - let other_public = to_secp256k1_public(other)?; - key_public.add_assign(&SECP256K1, &other_public)?; - set_public(public, &key_public); - Ok(()) -} - -/// Inplace sub one public key from another (EC point - EC point) -pub fn public_sub(public: &mut Public, other: &Public) -> Result<(), Error> { - let mut key_neg_other = to_secp256k1_public(other)?; - key_neg_other.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; - - let mut key_public = to_secp256k1_public(public)?; - key_public.add_assign(&SECP256K1, &key_neg_other)?; - set_public(public, &key_public); - Ok(()) -} - -/// Replace public key with its negation (EC point = - EC point) -pub fn public_negate(public: &mut Public) -> Result<(), Error> { - let mut key_public = to_secp256k1_public(public)?; - key_public.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; - set_public(public, &key_public); - Ok(()) -} - -/// Return base point of secp256k1 -pub fn generation_point() -> Public { - let mut public_sec_raw = [0u8; 65]; - public_sec_raw[0] = 4; - public_sec_raw[1..33].copy_from_slice(&GENERATOR_X); - public_sec_raw[33..65].copy_from_slice(&GENERATOR_Y); - - let public_key = key::PublicKey::from_slice(&SECP256K1, &public_sec_raw) - .expect("constructing using predefined constants; qed"); - let mut public = Public::default(); - set_public(&mut public, &public_key); - public -} - -/// Return secp256k1 elliptic curve order -pub fn curve_order() -> U256 { - H256::from_slice(&CURVE_ORDER).into_uint() -} - -fn to_secp256k1_public(public: &Public) -> Result { - let public_data = { - let mut temp = [4u8; 65]; - (&mut temp[1..65]).copy_from_slice(&public[0..64]); - temp - }; - - Ok(key::PublicKey::from_slice(&SECP256K1, &public_data)?) -} - -fn set_public(public: &mut Public, key_public: &key::PublicKey) { - let key_public_serialized = key_public.serialize_vec(&SECP256K1, false); - public.as_bytes_mut().copy_from_slice(&key_public_serialized[1..65]); -} - -#[cfg(test)] -mod tests { - use super::super::{Random, Generator}; - use super::{public_add, public_sub}; - - #[test] - fn public_addition_is_commutative() { - let public1 = Random.generate().unwrap().public().clone(); - let public2 = Random.generate().unwrap().public().clone(); - - let mut left = public1.clone(); - public_add(&mut left, &public2).unwrap(); - - let mut right = public2.clone(); - public_add(&mut right, &public1).unwrap(); - - assert_eq!(left, right); - } - - #[test] - fn public_addition_is_reversible_with_subtraction() { - let public1 = Random.generate().unwrap().public().clone(); - let public2 = Random.generate().unwrap().public().clone(); - - let mut sum = public1.clone(); - public_add(&mut sum, &public2).unwrap(); - public_sub(&mut sum, &public2).unwrap(); - - assert_eq!(sum, public1); - } -} diff --git a/accounts/ethkey/src/prefix.rs b/accounts/ethkey/src/prefix.rs index 32d92c1862c..0a595de42c3 100644 --- a/accounts/ethkey/src/prefix.rs +++ b/accounts/ethkey/src/prefix.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use super::{Random, Generator, KeyPair, Error}; +use parity_crypto::publickey::{Random, Generator, KeyPair, Error}; /// Tries to find keypair with address starting with given prefix. pub struct Prefix { @@ -48,7 +48,8 @@ impl Generator for Prefix { #[cfg(test)] mod tests { - use {Generator, Prefix}; + use Prefix; + use parity_crypto::publickey::Generator; #[test] fn prefix_generator() { diff --git a/accounts/ethkey/src/random.rs b/accounts/ethkey/src/random.rs deleted file mode 100644 index 08ccd2624c4..00000000000 --- a/accounts/ethkey/src/random.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -use rand::rngs::OsRng; -use super::{Generator, KeyPair, SECP256K1}; - -/// Randomly generates new keypair, instantiating the RNG each time. -pub struct Random; - -impl Generator for Random { - type Error = std::io::Error; - - fn generate(&mut self) -> Result { - Generator::generate(&mut OsRng).map_err(|void| { - match void {} // LLVM unreachable - }) - } -} - -impl Generator for OsRng { - type Error = ::Void; - - fn generate(&mut self) -> Result { - let (sec, publ) = SECP256K1.generate_keypair(self) - .expect("context always created with full capabilities; qed"); - - Ok(KeyPair::from_keypair(sec, publ)) - } -} diff --git a/accounts/ethkey/src/secret.rs b/accounts/ethkey/src/secret.rs deleted file mode 100644 index c850fa70ee8..00000000000 --- a/accounts/ethkey/src/secret.rs +++ /dev/null @@ -1,304 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -use std::fmt; -use std::ops::Deref; -use std::str::FromStr; -use rustc_hex::ToHex; -use secp256k1::constants::{SECRET_KEY_SIZE as SECP256K1_SECRET_KEY_SIZE}; -use secp256k1::key; -use ethereum_types::H256; -use zeroize::Zeroize; -use {Error, SECP256K1}; - -#[derive(Clone, PartialEq, Eq)] -pub struct Secret { - inner: H256, -} - -impl Drop for Secret { - fn drop(&mut self) { - self.inner.0.zeroize() - } -} - -impl ToHex for Secret { - fn to_hex(&self) -> String { - format!("{:x}", self.inner) - } -} - -impl fmt::LowerHex for Secret { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - self.inner.fmt(fmt) - } -} - -impl fmt::Debug for Secret { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - self.inner.fmt(fmt) - } -} - -impl fmt::Display for Secret { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "Secret: 0x{:x}{:x}..{:x}{:x}", self.inner[0], self.inner[1], self.inner[30], self.inner[31]) - } -} - -impl Secret { - /// Creates a `Secret` from the given slice, returning `None` if the slice length != 32. - pub fn from_slice(key: &[u8]) -> Option { - if key.len() != 32 { - return None - } - let mut h = H256::zero(); - h.as_bytes_mut().copy_from_slice(&key[0..32]); - Some(Secret { inner: h }) - } - - /// Creates zero key, which is invalid for crypto operations, but valid for math operation. - pub fn zero() -> Self { - Secret { inner: H256::zero() } - } - - /// Imports and validates the key. - pub fn from_unsafe_slice(key: &[u8]) -> Result { - let secret = key::SecretKey::from_slice(&super::SECP256K1, key)?; - Ok(secret.into()) - } - - /// Checks validity of this key. - pub fn check_validity(&self) -> Result<(), Error> { - self.to_secp256k1_secret().map(|_| ()) - } - - /// Inplace add one secret key to another (scalar + scalar) - pub fn add(&mut self, other: &Secret) -> Result<(), Error> { - match (self.is_zero(), other.is_zero()) { - (true, true) | (false, true) => Ok(()), - (true, false) => { - *self = other.clone(); - Ok(()) - }, - (false, false) => { - let mut key_secret = self.to_secp256k1_secret()?; - let other_secret = other.to_secp256k1_secret()?; - key_secret.add_assign(&SECP256K1, &other_secret)?; - - *self = key_secret.into(); - Ok(()) - }, - } - } - - /// Inplace subtract one secret key from another (scalar - scalar) - pub fn sub(&mut self, other: &Secret) -> Result<(), Error> { - match (self.is_zero(), other.is_zero()) { - (true, true) | (false, true) => Ok(()), - (true, false) => { - *self = other.clone(); - self.neg() - }, - (false, false) => { - let mut key_secret = self.to_secp256k1_secret()?; - let mut other_secret = other.to_secp256k1_secret()?; - other_secret.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; - key_secret.add_assign(&SECP256K1, &other_secret)?; - - *self = key_secret.into(); - Ok(()) - }, - } - } - - /// Inplace decrease secret key (scalar - 1) - pub fn dec(&mut self) -> Result<(), Error> { - match self.is_zero() { - true => { - *self = key::MINUS_ONE_KEY.into(); - Ok(()) - }, - false => { - let mut key_secret = self.to_secp256k1_secret()?; - key_secret.add_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; - - *self = key_secret.into(); - Ok(()) - }, - } - } - - /// Inplace multiply one secret key to another (scalar * scalar) - pub fn mul(&mut self, other: &Secret) -> Result<(), Error> { - match (self.is_zero(), other.is_zero()) { - (true, true) | (true, false) => Ok(()), - (false, true) => { - *self = Self::zero(); - Ok(()) - }, - (false, false) => { - let mut key_secret = self.to_secp256k1_secret()?; - let other_secret = other.to_secp256k1_secret()?; - key_secret.mul_assign(&SECP256K1, &other_secret)?; - - *self = key_secret.into(); - Ok(()) - }, - } - } - - /// Inplace negate secret key (-scalar) - pub fn neg(&mut self) -> Result<(), Error> { - match self.is_zero() { - true => Ok(()), - false => { - let mut key_secret = self.to_secp256k1_secret()?; - key_secret.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; - - *self = key_secret.into(); - Ok(()) - }, - } - } - - /// Inplace inverse secret key (1 / scalar) - pub fn inv(&mut self) -> Result<(), Error> { - let mut key_secret = self.to_secp256k1_secret()?; - key_secret.inv_assign(&SECP256K1)?; - - *self = key_secret.into(); - Ok(()) - } - - /// Compute power of secret key inplace (secret ^ pow). - /// This function is not intended to be used with large powers. - pub fn pow(&mut self, pow: usize) -> Result<(), Error> { - if self.is_zero() { - return Ok(()); - } - - match pow { - 0 => *self = key::ONE_KEY.into(), - 1 => (), - _ => { - let c = self.clone(); - for _ in 1..pow { - self.mul(&c)?; - } - }, - } - - Ok(()) - } - - /// Create `secp256k1::key::SecretKey` based on this secret - pub fn to_secp256k1_secret(&self) -> Result { - Ok(key::SecretKey::from_slice(&SECP256K1, &self[..])?) - } -} - -impl FromStr for Secret { - type Err = Error; - fn from_str(s: &str) -> Result { - Ok(H256::from_str(s).map_err(|e| Error::Custom(format!("{:?}", e)))?.into()) - } -} - -impl From<[u8; 32]> for Secret { - fn from(k: [u8; 32]) -> Self { - Secret { inner: H256(k) } - } -} - -impl From for Secret { - fn from(s: H256) -> Self { - s.0.into() - } -} - -impl From<&'static str> for Secret { - fn from(s: &'static str) -> Self { - s.parse().expect(&format!("invalid string literal for {}: '{}'", stringify!(Self), s)) - } -} - -impl From for Secret { - fn from(key: key::SecretKey) -> Self { - let mut a = [0; SECP256K1_SECRET_KEY_SIZE]; - a.copy_from_slice(&key[0 .. SECP256K1_SECRET_KEY_SIZE]); - a.into() - } -} - -impl Deref for Secret { - type Target = H256; - - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -#[cfg(test)] -mod tests { - use std::str::FromStr; - use super::super::{Random, Generator}; - use super::Secret; - - #[test] - fn multiplicating_secret_inversion_with_secret_gives_one() { - let secret = Random.generate().unwrap().secret().clone(); - let mut inversion = secret.clone(); - inversion.inv().unwrap(); - inversion.mul(&secret).unwrap(); - assert_eq!(inversion, Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap()); - } - - #[test] - fn secret_inversion_is_reversible_with_inversion() { - let secret = Random.generate().unwrap().secret().clone(); - let mut inversion = secret.clone(); - inversion.inv().unwrap(); - inversion.inv().unwrap(); - assert_eq!(inversion, secret); - } - - #[test] - fn secret_pow() { - let secret = Random.generate().unwrap().secret().clone(); - - let mut pow0 = secret.clone(); - pow0.pow(0).unwrap(); - assert_eq!(pow0, Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap()); - - let mut pow1 = secret.clone(); - pow1.pow(1).unwrap(); - assert_eq!(pow1, secret); - - let mut pow2 = secret.clone(); - pow2.pow(2).unwrap(); - let mut pow2_expected = secret.clone(); - pow2_expected.mul(&secret).unwrap(); - assert_eq!(pow2, pow2_expected); - - let mut pow3 = secret.clone(); - pow3.pow(3).unwrap(); - let mut pow3_expected = secret.clone(); - pow3_expected.mul(&secret).unwrap(); - pow3_expected.mul(&secret).unwrap(); - assert_eq!(pow3, pow3_expected); - } -} diff --git a/accounts/ethkey/src/signature.rs b/accounts/ethkey/src/signature.rs deleted file mode 100644 index c4c4bfd9e63..00000000000 --- a/accounts/ethkey/src/signature.rs +++ /dev/null @@ -1,314 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -use std::ops::{Deref, DerefMut}; -use std::cmp::PartialEq; -use std::fmt; -use std::str::FromStr; -use std::hash::{Hash, Hasher}; -use secp256k1::{Message as SecpMessage, RecoverableSignature, RecoveryId, Error as SecpError}; -use secp256k1::key::{SecretKey, PublicKey}; -use rustc_hex::{ToHex, FromHex}; -use ethereum_types::{H520, H256}; -use {Secret, Public, SECP256K1, Error, Message, public_to_address, Address}; - -/// Signature encoded as RSV components -#[repr(C)] -pub struct Signature([u8; 65]); - -impl Signature { - /// Get a slice into the 'r' portion of the data. - pub fn r(&self) -> &[u8] { - &self.0[0..32] - } - - /// Get a slice into the 's' portion of the data. - pub fn s(&self) -> &[u8] { - &self.0[32..64] - } - - /// Get the recovery byte. - pub fn v(&self) -> u8 { - self.0[64] - } - - /// Encode the signature into RSV array (V altered to be in "Electrum" notation). - pub fn into_electrum(mut self) -> [u8; 65] { - self.0[64] += 27; - self.0 - } - - /// Parse bytes as a signature encoded as RSV (V in "Electrum" notation). - /// May return empty (invalid) signature if given data has invalid length. - pub fn from_electrum(data: &[u8]) -> Self { - if data.len() != 65 || data[64] < 27 { - // fallback to empty (invalid) signature - return Signature::default(); - } - - let mut sig = [0u8; 65]; - sig.copy_from_slice(data); - sig[64] -= 27; - Signature(sig) - } - - /// Create a signature object from the sig. - pub fn from_rsv(r: &H256, s: &H256, v: u8) -> Self { - let mut sig = [0u8; 65]; - sig[0..32].copy_from_slice(r.as_ref()); - sig[32..64].copy_from_slice(s.as_ref()); - sig[64] = v; - Signature(sig) - } - - /// Check if this is a "low" signature. - pub fn is_low_s(&self) -> bool { - // "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0" - const MASK: H256 = H256([ - 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x5D, 0x57, 0x6E, 0x73, 0x57, 0xA4, 0x50, 0x1D, - 0xDF, 0xE9, 0x2F, 0x46, 0x68, 0x1B, 0x20, 0xA0, - ]); - H256::from_slice(self.s()) <= MASK - } - - /// Check if each component of the signature is in range. - pub fn is_valid(&self) -> bool { - // "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141" - const MASK: H256 = H256([ - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, - 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, - 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, - ]); - const ONE: H256 = H256([ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - ]); - let r = H256::from_slice(self.r()); - let s = H256::from_slice(self.s()); - self.v() <= 1 && - r < MASK && r >= ONE && - s < MASK && s >= ONE - } -} - -// manual implementation large arrays don't have trait impls by default. -// remove when integer generics exist -impl PartialEq for Signature { - fn eq(&self, other: &Self) -> bool { - &self.0[..] == &other.0[..] - } -} - -// manual implementation required in Rust 1.13+, see `std::cmp::AssertParamIsEq`. -impl Eq for Signature { } - -// also manual for the same reason, but the pretty printing might be useful. -impl fmt::Debug for Signature { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - f.debug_struct("Signature") - .field("r", &self.0[0..32].to_hex()) - .field("s", &self.0[32..64].to_hex()) - .field("v", &self.0[64..65].to_hex()) - .finish() - } -} - -impl fmt::Display for Signature { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "{}", self.to_hex()) - } -} - -impl FromStr for Signature { - type Err = Error; - - fn from_str(s: &str) -> Result { - match s.from_hex() { - Ok(ref hex) if hex.len() == 65 => { - let mut data = [0; 65]; - data.copy_from_slice(&hex[0..65]); - Ok(Signature(data)) - }, - _ => Err(Error::InvalidSignature) - } - } -} - -impl Default for Signature { - fn default() -> Self { - Signature([0; 65]) - } -} - -impl Hash for Signature { - fn hash(&self, state: &mut H) { - H520::from(self.0).hash(state); - } -} - -impl Clone for Signature { - fn clone(&self) -> Self { - Signature(self.0) - } -} - -impl From<[u8; 65]> for Signature { - fn from(s: [u8; 65]) -> Self { - Signature(s) - } -} - -impl Into<[u8; 65]> for Signature { - fn into(self) -> [u8; 65] { - self.0 - } -} - -impl From for H520 { - fn from(s: Signature) -> Self { - H520::from(s.0) - } -} - -impl From for Signature { - fn from(bytes: H520) -> Self { - Signature(bytes.into()) - } -} - -impl Deref for Signature { - type Target = [u8; 65]; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for Signature { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -pub fn sign(secret: &Secret, message: &Message) -> Result { - let context = &SECP256K1; - let sec = SecretKey::from_slice(context, secret.as_ref())?; - let s = context.sign_recoverable(&SecpMessage::from_slice(&message[..])?, &sec)?; - let (rec_id, data) = s.serialize_compact(context); - let mut data_arr = [0; 65]; - - // no need to check if s is low, it always is - data_arr[0..64].copy_from_slice(&data[0..64]); - data_arr[64] = rec_id.to_i32() as u8; - Ok(Signature(data_arr)) -} - -pub fn verify_public(public: &Public, signature: &Signature, message: &Message) -> Result { - let context = &SECP256K1; - let rsig = RecoverableSignature::from_compact(context, &signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; - let sig = rsig.to_standard(context); - - let pdata: [u8; 65] = { - let mut temp = [4u8; 65]; - temp[1..65].copy_from_slice(public.as_bytes()); - temp - }; - - let publ = PublicKey::from_slice(context, &pdata)?; - match context.verify(&SecpMessage::from_slice(&message[..])?, &sig, &publ) { - Ok(_) => Ok(true), - Err(SecpError::IncorrectSignature) => Ok(false), - Err(x) => Err(Error::from(x)) - } -} - -pub fn verify_address(address: &Address, signature: &Signature, message: &Message) -> Result { - let public = recover(signature, message)?; - let recovered_address = public_to_address(&public); - Ok(address == &recovered_address) -} - -pub fn recover(signature: &Signature, message: &Message) -> Result { - let context = &SECP256K1; - let rsig = RecoverableSignature::from_compact(context, &signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; - let pubkey = context.recover(&SecpMessage::from_slice(&message[..])?, &rsig)?; - let serialized = pubkey.serialize_vec(context, false); - - let mut public = Public::default(); - public.as_bytes_mut().copy_from_slice(&serialized[1..65]); - Ok(public) -} - -#[cfg(test)] -mod tests { - use std::str::FromStr; - use {Generator, Random, Message}; - use super::{sign, verify_public, verify_address, recover, Signature}; - - #[test] - fn vrs_conversion() { - // given - let keypair = Random.generate().unwrap(); - let message = Message::default(); - let signature = sign(keypair.secret(), &message).unwrap(); - - // when - let vrs = signature.clone().into_electrum(); - let from_vrs = Signature::from_electrum(&vrs); - - // then - assert_eq!(signature, from_vrs); - } - - #[test] - fn signature_to_and_from_str() { - let keypair = Random.generate().unwrap(); - let message = Message::default(); - let signature = sign(keypair.secret(), &message).unwrap(); - let string = format!("{}", signature); - let deserialized = Signature::from_str(&string).unwrap(); - assert_eq!(signature, deserialized); - } - - #[test] - fn sign_and_recover_public() { - let keypair = Random.generate().unwrap(); - let message = Message::default(); - let signature = sign(keypair.secret(), &message).unwrap(); - assert_eq!(keypair.public(), &recover(&signature, &message).unwrap()); - } - - #[test] - fn sign_and_verify_public() { - let keypair = Random.generate().unwrap(); - let message = Message::default(); - let signature = sign(keypair.secret(), &message).unwrap(); - assert!(verify_public(keypair.public(), &signature, &message).unwrap()); - } - - #[test] - fn sign_and_verify_address() { - let keypair = Random.generate().unwrap(); - let message = Message::default(); - let signature = sign(keypair.secret(), &message).unwrap(); - assert!(verify_address(&keypair.address(), &signature, &message).unwrap()); - } -} diff --git a/accounts/ethstore/Cargo.toml b/accounts/ethstore/Cargo.toml index 99943611c54..ac343b6efce 100644 --- a/accounts/ethstore/Cargo.toml +++ b/accounts/ethstore/Cargo.toml @@ -17,7 +17,7 @@ tiny-keccak = "1.4" time = "0.1.34" itertools = "0.5" parking_lot = "0.9" -parity-crypto = "0.4.0" +parity-crypto = { version = "0.4.2", features = ["publickey"] } ethereum-types = "0.8.0" dir = { path = "../../util/dir" } smallvec = "0.6" diff --git a/accounts/ethstore/cli/Cargo.toml b/accounts/ethstore/cli/Cargo.toml index 2793acc6e21..f6d12e67fee 100644 --- a/accounts/ethstore/cli/Cargo.toml +++ b/accounts/ethstore/cli/Cargo.toml @@ -13,6 +13,8 @@ serde = "1.0" serde_derive = "1.0" parking_lot = "0.9" ethstore = { path = "../" } +ethkey = { path = "../../ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } dir = { path = '../../../util/dir' } panic_hook = { path = "../../../util/panic-hook" } diff --git a/accounts/ethstore/cli/src/crack.rs b/accounts/ethstore/cli/src/crack.rs index abe171c3560..8e65b02193c 100644 --- a/accounts/ethstore/cli/src/crack.rs +++ b/accounts/ethstore/cli/src/crack.rs @@ -19,7 +19,8 @@ use std::sync::Arc; use std::collections::VecDeque; use parking_lot::Mutex; -use ethstore::{ethkey::Password, PresaleWallet, Error}; +use ethstore::{PresaleWallet, Error}; +use ethkey::Password; use num_cpus; pub fn run(passwords: VecDeque, wallet_path: &str) -> Result<(), Error> { diff --git a/accounts/ethstore/cli/src/main.rs b/accounts/ethstore/cli/src/main.rs index 8fc0054be7f..7c7011837d4 100644 --- a/accounts/ethstore/cli/src/main.rs +++ b/accounts/ethstore/cli/src/main.rs @@ -17,9 +17,11 @@ extern crate dir; extern crate docopt; extern crate ethstore; +extern crate ethkey; extern crate num_cpus; extern crate panic_hook; extern crate parking_lot; +extern crate parity_crypto; extern crate rustc_hex; extern crate serde; @@ -34,7 +36,8 @@ use std::{env, process, fs, fmt}; use docopt::Docopt; use ethstore::accounts_dir::{KeyDirectory, RootDiskDirectory}; -use ethstore::ethkey::{Address, Password}; +use ethkey::Password; +use parity_crypto::publickey::Address; use ethstore::{EthStore, SimpleSecretStore, SecretStore, import_accounts, PresaleWallet, SecretVaultRef, StoreAccountRef}; mod crack; diff --git a/accounts/ethstore/src/account/crypto.rs b/accounts/ethstore/src/account/crypto.rs index de5b4d8572f..8abe799bc7b 100644 --- a/accounts/ethstore/src/account/crypto.rs +++ b/accounts/ethstore/src/account/crypto.rs @@ -15,7 +15,8 @@ // along with Parity Ethereum. If not, see . use std::str; -use ethkey::{Password, Secret}; +use crypto::publickey::Secret; +use ethkey::Password; use {json, Error, crypto}; use crypto::Keccak256; use random::Random; @@ -120,7 +121,7 @@ impl Crypto { } let secret = self.do_decrypt(password, 32)?; - Ok(Secret::from_unsafe_slice(&secret)?) + Ok(Secret::import_key(&secret)?) } /// Try to decrypt and return result as is @@ -158,7 +159,7 @@ impl Crypto { #[cfg(test)] mod tests { - use ethkey::{Generator, Random}; + use crypto::publickey::{Generator, Random}; use super::{Crypto, Error}; #[test] diff --git a/accounts/ethstore/src/account/safe_account.rs b/accounts/ethstore/src/account/safe_account.rs index 7a38e79fa26..4bd393fac45 100644 --- a/accounts/ethstore/src/account/safe_account.rs +++ b/accounts/ethstore/src/account/safe_account.rs @@ -14,8 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use ethkey::{self, KeyPair, sign, Address, Password, Signature, Message, Public, Secret}; -use ethkey::crypto::ecdh::agree; +use crypto::publickey::{KeyPair, sign, Address, Signature, Message, Public, Secret}; +use ethkey::Password; +use crypto::publickey::ecdh::agree; use {json, Error}; use account::Version; use crypto; @@ -161,7 +162,7 @@ impl SafeAccount { /// Decrypt a message. pub fn decrypt(&self, password: &Password, shared_mac: &[u8], message: &[u8]) -> Result, Error> { let secret = self.crypto.secret(password)?; - ethkey::crypto::ecies::decrypt(&secret, shared_mac, message).map_err(From::from) + crypto::publickey::ecies::decrypt(&secret, shared_mac, message).map_err(From::from) } /// Agree on shared key. @@ -199,7 +200,7 @@ impl SafeAccount { #[cfg(test)] mod tests { - use ethkey::{Generator, Random, verify_public, Message}; + use crypto::publickey::{Generator, Random, verify_public, Message}; use super::SafeAccount; #[test] diff --git a/accounts/ethstore/src/accounts_dir/disk.rs b/accounts/ethstore/src/accounts_dir/disk.rs index b70029785e7..10e88095c73 100644 --- a/accounts/ethstore/src/accounts_dir/disk.rs +++ b/accounts/ethstore/src/accounts_dir/disk.rs @@ -356,7 +356,7 @@ mod test { use std::{env, fs}; use super::{KeyDirectory, RootDiskDirectory, VaultKey}; use account::SafeAccount; - use ethkey::{Random, Generator}; + use crypto::publickey::{Random, Generator}; use self::tempdir::TempDir; #[test] diff --git a/accounts/ethstore/src/accounts_dir/memory.rs b/accounts/ethstore/src/accounts_dir/memory.rs index 7f623aa3a14..a1403e240f5 100644 --- a/accounts/ethstore/src/accounts_dir/memory.rs +++ b/accounts/ethstore/src/accounts_dir/memory.rs @@ -17,7 +17,7 @@ use std::collections::HashMap; use parking_lot::RwLock; use itertools; -use ethkey::Address; +use crypto::publickey::Address; use {SafeAccount, Error}; use super::KeyDirectory; diff --git a/accounts/ethstore/src/error.rs b/accounts/ethstore/src/error.rs index fceaf16768b..9798b5cc12f 100644 --- a/accounts/ethstore/src/error.rs +++ b/accounts/ethstore/src/error.rs @@ -16,9 +16,8 @@ use std::fmt; use std::io::Error as IoError; -use ethkey::{self, Error as EthKeyError}; use crypto::{self, Error as EthCryptoError}; -use ethkey::DerivationError; +use crypto::publickey::{Error as EthPublicKeyCryptoError, DerivationError}; /// Account-related errors. #[derive(Debug)] @@ -47,12 +46,10 @@ pub enum Error { VaultNotFound, /// Account creation failed. CreationFailed, - /// `EthKey` error - EthKey(EthKeyError), - /// `ethkey::crypto::Error` - EthKeyCrypto(ethkey::crypto::Error), /// `EthCrypto` error EthCrypto(EthCryptoError), + /// `EthPublicKeyCryptoError` error + EthPublicKeyCrypto(EthPublicKeyCryptoError), /// Derivation error Derivation(DerivationError), /// Custom error @@ -74,9 +71,8 @@ impl fmt::Display for Error { Error::InvalidVaultName => "Invalid vault name".into(), Error::VaultNotFound => "Vault not found".into(), Error::CreationFailed => "Account creation failed".into(), - Error::EthKey(ref err) => err.to_string(), - Error::EthKeyCrypto(ref err) => err.to_string(), Error::EthCrypto(ref err) => err.to_string(), + Error::EthPublicKeyCrypto(ref err) => err.to_string(), Error::Derivation(ref err) => format!("Derivation error: {:?}", err), Error::Custom(ref s) => s.clone(), }; @@ -91,15 +87,9 @@ impl From for Error { } } -impl From for Error { - fn from(err: EthKeyError) -> Self { - Error::EthKey(err) - } -} - -impl From for Error { - fn from(err: ethkey::crypto::Error) -> Self { - Error::EthKeyCrypto(err) +impl From for Error { + fn from(err: EthPublicKeyCryptoError) -> Self { + Error::EthPublicKeyCrypto(err) } } diff --git a/accounts/ethstore/src/ethkey.rs b/accounts/ethstore/src/ethkey.rs deleted file mode 100644 index 8cd2c533adc..00000000000 --- a/accounts/ethstore/src/ethkey.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! ethkey reexport to make documentation look pretty. -pub use _ethkey::*; -use json; - -impl Into for Address { - fn into(self) -> json::H160 { - let a: [u8; 20] = self.into(); - From::from(a) - } -} - -impl From for Address { - fn from(json: json::H160) -> Self { - let a: [u8; 20] = json.into(); - From::from(a) - } -} - -impl<'a> From<&'a json::H160> for Address { - fn from(json: &'a json::H160) -> Self { - let mut a = [0u8; 20]; - a.copy_from_slice(json); - From::from(a) - } -} diff --git a/accounts/ethstore/src/ethstore.rs b/accounts/ethstore/src/ethstore.rs index 36416c5e79f..ab8d4644f89 100644 --- a/accounts/ethstore/src/ethstore.rs +++ b/accounts/ethstore/src/ethstore.rs @@ -22,7 +22,8 @@ use std::time::{Instant, Duration}; use crypto::KEY_ITERATIONS; use random::Random; -use ethkey::{self, Signature, Password, Address, Message, Secret, Public, KeyPair, ExtendedKeyPair}; +use crypto::publickey::{Signature, Address, Message, Secret, Public, KeyPair, ExtendedKeyPair}; +use ethkey::Password; use accounts_dir::{KeyDirectory, VaultKeyDirectory, VaultKey, SetKeyError}; use account::SafeAccount; use presale::PresaleWallet; @@ -442,13 +443,13 @@ impl EthMultiStore { Derivation::Hierarchical(path) => { for path_item in path { extended = extended.derive( - if path_item.soft { ethkey::Derivation::Soft(path_item.index) } - else { ethkey::Derivation::Hard(path_item.index) } + if path_item.soft { crypto::publickey::Derivation::Soft(path_item.index) } + else { crypto::publickey::Derivation::Hard(path_item.index) } )?; } }, - Derivation::SoftHash(h256) => { extended = extended.derive(ethkey::Derivation::Soft(h256))?; } - Derivation::HardHash(h256) => { extended = extended.derive(ethkey::Derivation::Hard(h256))?; } + Derivation::SoftHash(h256) => { extended = extended.derive(crypto::publickey::Derivation::Soft(h256))?; } + Derivation::HardHash(h256) => { extended = extended.derive(crypto::publickey::Derivation::Hard(h256))?; } } Ok(extended) } @@ -479,7 +480,7 @@ impl SimpleSecretStore for EthMultiStore { let accounts = self.get_matching(&account_ref, password)?; for account in accounts { let extended = self.generate(account.crypto.secret(password)?, derivation)?; - return Ok(ethkey::public_to_address(extended.public().public())); + return Ok(crypto::publickey::public_to_address(extended.public().public())); } Err(Error::InvalidPassword) } @@ -491,7 +492,7 @@ impl SimpleSecretStore for EthMultiStore { for account in accounts { let extended = self.generate(account.crypto.secret(password)?, derivation)?; let secret = extended.secret().as_raw(); - return Ok(ethkey::sign(&secret, message)?) + return Ok(crypto::publickey::sign(&secret, message)?) } Err(Error::InvalidPassword) } @@ -690,7 +691,7 @@ mod tests { extern crate tempdir; use accounts_dir::{KeyDirectory, MemoryDirectory, RootDiskDirectory}; - use ethkey::{Random, Generator, KeyPair}; + use crypto::publickey::{Random, Generator, KeyPair}; use secret_store::{SimpleSecretStore, SecretStore, SecretVaultRef, StoreAccountRef, Derivation}; use super::{EthStore, EthMultiStore}; use self::tempdir::TempDir; diff --git a/accounts/ethstore/src/import.rs b/accounts/ethstore/src/import.rs index 3fe9763e8f2..abf8572446a 100644 --- a/accounts/ethstore/src/import.rs +++ b/accounts/ethstore/src/import.rs @@ -18,7 +18,7 @@ use std::collections::HashSet; use std::path::Path; use std::fs; -use ethkey::Address; +use crypto::publickey::Address; use accounts_dir::{KeyDirectory, RootDiskDirectory, DiskKeyFileManager, KeyFileManager}; use dir; use Error; diff --git a/accounts/ethstore/src/lib.rs b/accounts/ethstore/src/lib.rs index aa2bb86a471..ddd1d4bb8ca 100644 --- a/accounts/ethstore/src/lib.rs +++ b/accounts/ethstore/src/lib.rs @@ -33,7 +33,7 @@ extern crate tempdir; extern crate parity_crypto as crypto; extern crate ethereum_types; -extern crate ethkey as _ethkey; +extern crate ethkey as ethkey; extern crate parity_wordlist; #[macro_use] @@ -46,7 +46,6 @@ extern crate serde_derive; extern crate matches; pub mod accounts_dir; -pub mod ethkey; mod account; mod json; @@ -72,4 +71,30 @@ pub use self::random::random_string; pub use self::parity_wordlist::random_phrase; /// An opaque wrapper for secret. -pub struct OpaqueSecret(::ethkey::Secret); +pub struct OpaqueSecret(crypto::publickey::Secret); + +// Additional converters for Address +use crypto::publickey::Address; + +impl Into for Address { + fn into(self) -> json::H160 { + let a: [u8; 20] = self.into(); + From::from(a) + } +} + +impl From for Address { + fn from(json: json::H160) -> Self { + let a: [u8; 20] = json.into(); + From::from(a) + } +} + +impl<'a> From<&'a json::H160> for Address { + fn from(json: &'a json::H160) -> Self { + let mut a = [0u8; 20]; + a.copy_from_slice(json); + From::from(a) + } +} + diff --git a/accounts/ethstore/src/presale.rs b/accounts/ethstore/src/presale.rs index c1be05f0f02..a050fbf237b 100644 --- a/accounts/ethstore/src/presale.rs +++ b/accounts/ethstore/src/presale.rs @@ -17,7 +17,8 @@ use std::fs; use std::path::Path; use json; -use ethkey::{Address, Secret, KeyPair, Password}; +use crypto::publickey::{Address, Secret, KeyPair}; +use ethkey::Password; use crypto::{Keccak256, pbkdf2}; use {crypto, Error}; @@ -65,7 +66,7 @@ impl PresaleWallet { .map_err(|_| Error::InvalidPassword)?; let unpadded = &key[..len]; - let secret = Secret::from_unsafe_slice(&unpadded.keccak256())?; + let secret = Secret::import_key(&unpadded.keccak256())?; if let Ok(kp) = KeyPair::from_secret(secret) { if kp.address() == self.address { return Ok(kp) diff --git a/accounts/ethstore/src/secret_store.rs b/accounts/ethstore/src/secret_store.rs index d3ca1a12fba..aa619be41c5 100644 --- a/accounts/ethstore/src/secret_store.rs +++ b/accounts/ethstore/src/secret_store.rs @@ -17,7 +17,8 @@ use std::hash::{Hash, Hasher}; use std::path::PathBuf; use std::cmp::Ordering; -use ethkey::{Address, Message, Signature, Secret, Password, Public}; +use crypto::publickey::{Address, Message, Signature, Secret, Public}; +use ethkey::Password; use Error; use json::{Uuid, OpaqueKeyFile}; use ethereum_types::H256; @@ -110,7 +111,7 @@ pub trait SecretStore: SimpleSecretStore { /// Signs a message with raw secret. fn sign_with_secret(&self, secret: &OpaqueSecret, message: &Message) -> Result { - Ok(::ethkey::sign(&secret.0, message)?) + Ok(crypto::publickey::sign(&secret.0, message)?) } /// Imports presale wallet diff --git a/accounts/ethstore/tests/api.rs b/accounts/ethstore/tests/api.rs index 74d66a66665..6554c4da796 100644 --- a/accounts/ethstore/tests/api.rs +++ b/accounts/ethstore/tests/api.rs @@ -17,11 +17,12 @@ extern crate rand; extern crate ethstore; extern crate ethereum_types; +extern crate parity_crypto; mod util; use ethstore::{EthStore, SimpleSecretStore, SecretVaultRef, StoreAccountRef}; -use ethstore::ethkey::{Random, Generator, Secret, KeyPair, verify_address}; +use parity_crypto::publickey::{Random, Generator, Secret, KeyPair, verify_address}; use ethstore::accounts_dir::RootDiskDirectory; use util::TransientDir; use ethereum_types::Address; diff --git a/accounts/src/account_data.rs b/accounts/src/account_data.rs index a36d38740e4..3f874c41da5 100644 --- a/accounts/src/account_data.rs +++ b/accounts/src/account_data.rs @@ -21,7 +21,8 @@ use std::{ time::Instant, }; -use ethkey::{Address, Password}; +use parity_crypto::publickey::Address; +use ethkey::Password; use serde_derive::{Serialize, Deserialize}; use serde_json; diff --git a/accounts/src/lib.rs b/accounts/src/lib.rs index ac87a2ee332..29b8c303945 100644 --- a/accounts/src/lib.rs +++ b/accounts/src/lib.rs @@ -28,7 +28,8 @@ use self::stores::AddressBook; use std::collections::HashMap; use std::time::{Instant, Duration}; -use ethkey::{Address, Message, Public, Secret, Password, Random, Generator}; +use ethkey::Password; +use parity_crypto::publickey::{Address, Message, Public, Secret, Random, Generator, Signature}; use ethstore::accounts_dir::MemoryDirectory; use ethstore::{ SimpleSecretStore, SecretStore, EthStore, EthMultiStore, @@ -37,7 +38,6 @@ use ethstore::{ use log::warn; use parking_lot::RwLock; -pub use ethkey::Signature; pub use ethstore::{Derivation, IndexDerivation, KeyFile, Error}; pub use self::account_data::AccountMeta; @@ -503,7 +503,7 @@ impl AccountProvider { mod tests { use super::{AccountProvider, Unlock}; use std::time::{Duration, Instant}; - use ethkey::{Generator, Random, Address}; + use parity_crypto::publickey::{Generator, Random, Address}; use ethstore::{StoreAccountRef, Derivation}; use ethereum_types::H256; diff --git a/accounts/src/stores.rs b/accounts/src/stores.rs index 90e36374e09..72d0a7df7d5 100644 --- a/accounts/src/stores.rs +++ b/accounts/src/stores.rs @@ -20,7 +20,7 @@ use std::{fs, fmt, hash, ops}; use std::collections::HashMap; use std::path::{Path, PathBuf}; -use ethkey::Address; +use parity_crypto::publickey::Address; use log::{trace, warn}; use crate::AccountMeta; diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index aca6a924319..f036010c5ac 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -17,7 +17,6 @@ engine = { path = "./engine" } env_logger = { version = "0.5", optional = true } ethash = { path = "../ethash", optional = true } ethjson = { path = "../json", optional = true } -ethkey = { path = "../accounts/ethkey", optional = true } ethcore-blockchain = { path = "./blockchain" } ethcore-call-contract = { path = "./call-contract" } ethcore-db = { path = "./db" } @@ -44,6 +43,7 @@ parity-bytes = "0.1" parking_lot = "0.9" pod = { path = "pod", optional = true } trie-db = "0.15.0" +parity-crypto = { version = "0.4.2", features = ["publickey"], optional = true } patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" } rand = "0.7" rand_xorshift = "0.2" @@ -76,7 +76,7 @@ ethash = { path = "../ethash" } ethcore-accounts = { path = "../accounts" } ethcore-builtin = { path = "./builtin" } ethjson = { path = "../json", features = ["test-helpers"] } -ethkey = { path = "../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } fetch = { path = "../util/fetch" } kvdb-memorydb = "0.1.2" kvdb-rocksdb = "0.1.5" @@ -124,7 +124,7 @@ test-heavy = [] test-helpers = [ "blooms-db", "ethjson/test-helpers", - "ethkey", + "parity-crypto", "kvdb-memorydb", "kvdb-rocksdb", "macros", diff --git a/ethcore/blockchain/Cargo.toml b/ethcore/blockchain/Cargo.toml index 5552e966fcd..3eb0b2ecb3e 100644 --- a/ethcore/blockchain/Cargo.toml +++ b/ethcore/blockchain/Cargo.toml @@ -29,7 +29,7 @@ triehash-ethereum = { version = "0.2", path = "../../util/triehash-ethereum" } [dev-dependencies] env_logger = "0.5" -ethkey = { path = "../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } rustc-hex = "1.0" tempdir = "0.3" kvdb-memorydb = "0.1.2" diff --git a/ethcore/blockchain/src/blockchain.rs b/ethcore/blockchain/src/blockchain.rs index 870a29de6b1..efafef7a44c 100644 --- a/ethcore/blockchain/src/blockchain.rs +++ b/ethcore/blockchain/src/blockchain.rs @@ -1625,7 +1625,7 @@ mod tests { use common_types::receipt::{Receipt, TransactionOutcome}; use common_types::transaction::{Transaction, Action}; use crate::generator::{BlockGenerator, BlockBuilder, BlockOptions}; - use ethkey::Secret; + use parity_crypto::publickey::Secret; use keccak_hash::keccak; use rustc_hex::FromHex; use tempdir::TempDir; diff --git a/ethcore/builtin/Cargo.toml b/ethcore/builtin/Cargo.toml index 441e68a954e..f69b65d974b 100644 --- a/ethcore/builtin/Cargo.toml +++ b/ethcore/builtin/Cargo.toml @@ -10,13 +10,12 @@ bn = { git = "https://github.com/paritytech/bn", default-features = false } common-types = { path = "../types" } ethereum-types = "0.8.0" ethjson = { path = "../../json" } -ethkey = { path = "../../accounts/ethkey" } keccak-hash = "0.4.0" log = "0.4" num = { version = "0.1", default-features = false, features = ["bigint"] } parity-bytes = "0.1" eip-152 = { path = "../../util/EIP-152" } -parity-crypto = "0.4.0" +parity-crypto = { version = "0.4.2", features = ["publickey"] } byteorder = "1.3.2" [dev-dependencies] diff --git a/ethcore/builtin/src/lib.rs b/ethcore/builtin/src/lib.rs index 3ecc1499fab..d0b0e93ec4b 100644 --- a/ethcore/builtin/src/lib.rs +++ b/ethcore/builtin/src/lib.rs @@ -28,7 +28,7 @@ use byteorder::{BigEndian, LittleEndian, ReadBytesExt}; use common_types::errors::EthcoreError; use ethereum_types::{H256, U256}; use ethjson; -use ethkey::{Signature, recover as ec_recover}; +use parity_crypto::publickey::{Signature, recover as ec_recover}; use keccak_hash::keccak; use log::{warn, trace}; use num::{BigUint, Zero, One}; diff --git a/ethcore/engine/Cargo.toml b/ethcore/engine/Cargo.toml index 6165ef85806..fe527ade8be 100644 --- a/ethcore/engine/Cargo.toml +++ b/ethcore/engine/Cargo.toml @@ -13,17 +13,19 @@ bytes = { package = "parity-bytes", version = "0.1.0" } client-traits = { path = "../client-traits" } common-types = { path = "../types" } ethereum-types = "0.8.0" -ethkey = { path = "../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } machine = { path = "../machine" } vm = { path = "../vm" } # used from test-helpers accounts = { package = "ethcore-accounts", path = "../../accounts", optional = true } log = { version = "0.4.8", optional = true } +ethkey = { path = "../../accounts/ethkey", optional = true } [dev-dependencies] accounts = { package = "ethcore-accounts", path = "../../accounts" } +ethkey = { path = "../../accounts/ethkey" } log = "0.4.8" [features] -test-helpers = ["accounts", "log"] +test-helpers = ["accounts", "log", "ethkey"] diff --git a/ethcore/engine/src/engine.rs b/ethcore/engine/src/engine.rs index 357a184c7af..f5e90234319 100644 --- a/ethcore/engine/src/engine.rs +++ b/ethcore/engine/src/engine.rs @@ -37,7 +37,7 @@ use common_types::{ use client_traits::EngineClient; use ethereum_types::{H256, U256, Address}; -use ethkey::Signature; +use parity_crypto::publickey::Signature; use machine::{ Machine, executed_block::ExecutedBlock, diff --git a/ethcore/engine/src/signer.rs b/ethcore/engine/src/signer.rs index 1e932feefc3..baacf7c0984 100644 --- a/ethcore/engine/src/signer.rs +++ b/ethcore/engine/src/signer.rs @@ -17,27 +17,27 @@ //! A signer used by Engines which need to sign messages. use ethereum_types::{H256, Address}; -use ethkey::{self, Signature}; +use parity_crypto::publickey::{Signature, KeyPair, Error}; /// Everything that an Engine needs to sign messages. pub trait EngineSigner: Send + Sync { /// Sign a consensus message hash. - fn sign(&self, hash: H256) -> Result; + fn sign(&self, hash: H256) -> Result; /// Signing address fn address(&self) -> Address; } /// Creates a new `EngineSigner` from given key pair. -pub fn from_keypair(keypair: ethkey::KeyPair) -> Box { +pub fn from_keypair(keypair: KeyPair) -> Box { Box::new(Signer(keypair)) } -struct Signer(ethkey::KeyPair); +struct Signer(KeyPair); impl EngineSigner for Signer { - fn sign(&self, hash: H256) -> Result { - ethkey::sign(self.0.secret(), &hash) + fn sign(&self, hash: H256) -> Result { + parity_crypto::publickey::sign(self.0.secret(), &hash) } fn address(&self) -> Address { diff --git a/ethcore/engine/src/test_helpers.rs b/ethcore/engine/src/test_helpers.rs index 92ba66ff480..6423590b3a3 100644 --- a/ethcore/engine/src/test_helpers.rs +++ b/ethcore/engine/src/test_helpers.rs @@ -19,25 +19,26 @@ use std::sync::Arc; use ethereum_types::{Address, H256}; -use ethkey::{Password, Signature}; +use ethkey::Password; +use parity_crypto::publickey::{Signature, Error}; use log::warn; use accounts::{self, AccountProvider, SignError}; use crate::signer::EngineSigner; impl EngineSigner for (Arc, Address, Password) { - fn sign(&self, hash: H256) -> Result { + fn sign(&self, hash: H256) -> Result { match self.0.sign(self.1, Some(self.2.clone()), hash) { Err(SignError::NotUnlocked) => unreachable!(), - Err(SignError::NotFound) => Err(ethkey::Error::InvalidAddress), - Err(SignError::SStore(accounts::Error::EthKey(err))) => Err(err), - Err(SignError::SStore(accounts::Error::EthKeyCrypto(err))) => { + Err(SignError::NotFound) => Err(Error::InvalidAddress), + Err(SignError::SStore(accounts::Error::EthCrypto(err))) => Err(Error::Custom(err.to_string())), + Err(SignError::SStore(accounts::Error::EthPublicKeyCrypto(err))) => { warn!("Low level crypto error: {:?}", err); - Err(ethkey::Error::InvalidSecret) + Err(Error::InvalidSecretKey) }, Err(SignError::SStore(err)) => { warn!("Error signing for engine: {:?}", err); - Err(ethkey::Error::InvalidSignature) + Err(Error::InvalidSignature) }, Ok(ok) => Ok(ok), } diff --git a/ethcore/engines/authority-round/Cargo.toml b/ethcore/engines/authority-round/Cargo.toml index 79083299adb..5bca87fb806 100644 --- a/ethcore/engines/authority-round/Cargo.toml +++ b/ethcore/engines/authority-round/Cargo.toml @@ -12,7 +12,7 @@ client-traits = { path = "../../client-traits" } common-types = { path = "../../types" } ethereum-types = "0.8.0" ethjson = { path = "../../../json" } -ethkey = { path = "../../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } engine = { path = "../../engine" } io = { package = "ethcore-io", path = "../../../util/io" } itertools = "0.5" diff --git a/ethcore/engines/authority-round/src/lib.rs b/ethcore/engines/authority-round/src/lib.rs index 2f4202f168e..fd3585fc72c 100644 --- a/ethcore/engines/authority-round/src/lib.rs +++ b/ethcore/engines/authority-round/src/lib.rs @@ -51,7 +51,7 @@ use macros::map; use keccak_hash::keccak; use log::{info, debug, error, trace, warn}; use engine::signer::EngineSigner; -use ethkey::{self, Signature}; +use parity_crypto::publickey::Signature; use io::{IoContext, IoHandler, TimerToken, IoService}; use itertools::{self, Itertools}; use rlp::{encode, Decodable, DecoderError, Encodable, RlpStream, Rlp}; @@ -385,14 +385,14 @@ impl EmptyStep { let message = keccak(empty_step_rlp(self.step, &self.parent_hash)); let correct_proposer = step_proposer(validators, &self.parent_hash, self.step); - ethkey::verify_address(&correct_proposer, &self.signature.into(), &message) + parity_crypto::publickey::verify_address(&correct_proposer, &self.signature.into(), &message) .map_err(|e| e.into()) } fn author(&self) -> Result { let message = keccak(empty_step_rlp(self.step, &self.parent_hash)); - let public = ethkey::recover(&self.signature.into(), &message)?; - Ok(ethkey::public_to_address(&public)) + let public = parity_crypto::publickey::recover(&self.signature.into(), &message)?; + Ok(parity_crypto::publickey::public_to_address(&public)) } fn sealed(&self) -> SealedEmptyStep { @@ -673,7 +673,7 @@ fn verify_external(header: &Header, validators: &dyn ValidatorSet, empty_steps_t }; let header_seal_hash = header_seal_hash(header, empty_steps_rlp); - !ethkey::verify_address(&correct_proposer, &proposer_signature, &header_seal_hash)? + !parity_crypto::publickey::verify_address(&correct_proposer, &proposer_signature, &header_seal_hash)? }; if is_invalid_proposer { @@ -1663,7 +1663,7 @@ impl Engine for AuthorityRound { fn sign(&self, hash: H256) -> Result { Ok(self.signer.read() .as_ref() - .ok_or(ethkey::Error::InvalidAddress)? + .ok_or(parity_crypto::publickey::Error::InvalidAddress)? .sign(hash)? ) } @@ -1703,7 +1703,7 @@ mod tests { use keccak_hash::keccak; use accounts::AccountProvider; use ethereum_types::{Address, H520, H256, U256}; - use ethkey::Signature; + use parity_crypto::publickey::Signature; use common_types::{ header::Header, engines::{Seal, params::CommonParams}, @@ -2112,7 +2112,7 @@ mod tests { SealedEmptyStep { signature, step } } - fn set_empty_steps_seal(header: &mut Header, step: u64, block_signature: ðkey::Signature, empty_steps: &[SealedEmptyStep]) { + fn set_empty_steps_seal(header: &mut Header, step: u64, block_signature: &Signature, empty_steps: &[SealedEmptyStep]) { header.set_seal(vec![ encode(&(step as usize)), encode(&(&**block_signature as &[u8])), diff --git a/ethcore/engines/basic-authority/Cargo.toml b/ethcore/engines/basic-authority/Cargo.toml index 9c04fa37c79..849014aec49 100644 --- a/ethcore/engines/basic-authority/Cargo.toml +++ b/ethcore/engines/basic-authority/Cargo.toml @@ -12,7 +12,7 @@ common-types = { path = "../../types" } engine = { path = "../../engine" } ethereum-types = "0.8.0" ethjson = { path = "../../../json" } -ethkey = { path = "../../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } log = "0.4.8" machine = { path = "../../machine" } parking_lot = "0.9" diff --git a/ethcore/engines/basic-authority/src/lib.rs b/ethcore/engines/basic-authority/src/lib.rs index bae548781b4..2587d598697 100644 --- a/ethcore/engines/basic-authority/src/lib.rs +++ b/ethcore/engines/basic-authority/src/lib.rs @@ -34,7 +34,7 @@ use client_traits::EngineClient; use ethereum_types::{H256, H520}; use parking_lot::RwLock; use engine::{Engine, ConstructedVerifier, signer::EngineSigner}; -use ethkey::{self, Signature}; +use parity_crypto::publickey::Signature; use ethjson; use log::trace; use machine::{Machine, executed_block::ExecutedBlock}; @@ -69,7 +69,7 @@ impl engine::EpochVerifier for EpochVerifier { fn verify_external(header: &Header, validators: &dyn ValidatorSet) -> Result<(), Error> { // Check if the signature belongs to a validator, can depend on parent state. let sig = Rlp::new(&header.seal()[0]).as_val::()?; - let signer = ethkey::public_to_address(ðkey::recover(&sig.into(), &header.bare_hash())?); + let signer = parity_crypto::publickey::public_to_address(&parity_crypto::publickey::recover(&sig.into(), &header.bare_hash())?); if *header.author() != signer { return Err(EngineError::NotAuthorized(*header.author()).into()) @@ -201,7 +201,7 @@ impl Engine for BasicAuthority { fn sign(&self, hash: H256) -> Result { Ok(self.signer.read() .as_ref() - .ok_or_else(|| ethkey::Error::InvalidAddress)? + .ok_or_else(|| parity_crypto::publickey::Error::InvalidAddress)? .sign(hash)? ) } diff --git a/ethcore/engines/clique/Cargo.toml b/ethcore/engines/clique/Cargo.toml index 2c831813c83..7a73f04c815 100644 --- a/ethcore/engines/clique/Cargo.toml +++ b/ethcore/engines/clique/Cargo.toml @@ -11,7 +11,7 @@ client-traits = { path = "../../client-traits" } common-types = { path = "../../types" } ethereum-types = "0.8.0" ethjson = { path = "../../../json" } -ethkey = { path = "../../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } engine = { path = "../../engine" } keccak-hash = "0.4.0" lazy_static = "1.3.0" diff --git a/ethcore/engines/clique/src/lib.rs b/ethcore/engines/clique/src/lib.rs index ac8ed4b86d2..50dad03acc7 100644 --- a/ethcore/engines/clique/src/lib.rs +++ b/ethcore/engines/clique/src/lib.rs @@ -72,7 +72,7 @@ use engine::{ signer::EngineSigner, }; use ethereum_types::{Address, H64, H160, H256, U256}; -use ethkey::Signature; +use parity_crypto::publickey::Signature; use keccak_hash::KECCAK_EMPTY_LIST_RLP; use log::{trace, warn}; use lru_cache::LruCache; diff --git a/ethcore/engines/clique/src/tests.rs b/ethcore/engines/clique/src/tests.rs index 90ed67fcf58..084758c4399 100644 --- a/ethcore/engines/clique/src/tests.rs +++ b/ethcore/engines/clique/src/tests.rs @@ -26,7 +26,7 @@ use ethcore::{ }; use engine::Engine; use ethereum_types::{Address, H256}; -use ethkey::{Secret, KeyPair}; +use parity_crypto::publickey::{Secret, KeyPair}; use state_db::StateDB; use super::*; @@ -183,7 +183,7 @@ impl CliqueTester { b.header.set_difficulty(difficulty); b.header.set_seal(seal); - let sign = ethkey::sign(self.signers[&signer].secret(), &b.header.hash()).unwrap(); + let sign = parity_crypto::publickey::sign(self.signers[&signer].secret(), &b.header.hash()).unwrap(); let mut extra_data = b.header.extra_data().clone(); extra_data.extend_from_slice(&*sign); b.header.set_extra_data(extra_data); diff --git a/ethcore/engines/clique/src/util.rs b/ethcore/engines/clique/src/util.rs index 007f49a2c21..a18fb21a6e7 100644 --- a/ethcore/engines/clique/src/util.rs +++ b/ethcore/engines/clique/src/util.rs @@ -21,7 +21,7 @@ use common_types::{ errors::{EthcoreError as Error, EngineError}, }; use ethereum_types::{Address, H256}; -use ethkey::{public_to_address, recover as ec_recover, Signature}; +use parity_crypto::publickey::{public_to_address, recover as ec_recover, Signature}; use lazy_static::lazy_static; use lru_cache::LruCache; use parking_lot::RwLock; diff --git a/ethcore/engines/validator-set/Cargo.toml b/ethcore/engines/validator-set/Cargo.toml index 9dfd33c2c01..958ea4b480d 100644 --- a/ethcore/engines/validator-set/Cargo.toml +++ b/ethcore/engines/validator-set/Cargo.toml @@ -36,7 +36,7 @@ call-contract = { package = "ethcore-call-contract", path = "../../call-contract engine = { path = "../../engine", features = ["test-helpers"] } env_logger = "0.6.2" ethcore = { path = "../..", features = ["test-helpers"] } -ethkey = { path = "../../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } keccak-hash = "0.4.0" rustc-hex = "1.0" spec = { path = "../../spec" } diff --git a/ethcore/engines/validator-set/src/multi.rs b/ethcore/engines/validator-set/src/multi.rs index 72b653041c6..76b3e9a1c83 100644 --- a/ethcore/engines/validator-set/src/multi.rs +++ b/ethcore/engines/validator-set/src/multi.rs @@ -168,7 +168,7 @@ mod tests { test_helpers::{generate_dummy_client_with_spec, generate_dummy_client_with_spec_and_data}, }; use ethereum_types::Address; - use ethkey::Secret; + use parity_crypto::publickey::Secret; use keccak_hash::keccak; use spec; diff --git a/ethcore/engines/validator-set/src/safe_contract.rs b/ethcore/engines/validator-set/src/safe_contract.rs index 666d43eac56..cf1a23b1aab 100644 --- a/ethcore/engines/validator-set/src/safe_contract.rs +++ b/ethcore/engines/validator-set/src/safe_contract.rs @@ -470,7 +470,7 @@ mod tests { miner::{self, MinerService}, test_helpers::{generate_dummy_client_with_spec, generate_dummy_client_with_spec_and_data} }; - use ethkey::Secret; + use parity_crypto::publickey::Secret; use ethereum_types::Address; use keccak_hash::keccak; use rustc_hex::FromHex; diff --git a/ethcore/executive-state/Cargo.toml b/ethcore/executive-state/Cargo.toml index 590334e1c58..311d99ecc9b 100644 --- a/ethcore/executive-state/Cargo.toml +++ b/ethcore/executive-state/Cargo.toml @@ -24,7 +24,7 @@ vm = { path = "../vm" } [dev-dependencies] env_logger = "0.5" ethcore = { path = "..", features = ["test-helpers"] } -ethkey = { path = "../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } evm = { path = "../evm" } keccak-hash = "0.4.0" pod = { path = "../pod" } diff --git a/ethcore/executive-state/src/lib.rs b/ethcore/executive-state/src/lib.rs index 29b4cd78395..b9468a7a750 100644 --- a/ethcore/executive-state/src/lib.rs +++ b/ethcore/executive-state/src/lib.rs @@ -270,7 +270,7 @@ mod tests { use account_state::{Account, CleanupMode}; use common_types::transaction::*; use keccak_hash::{keccak, KECCAK_NULL_RLP}; - use ethkey::Secret; + use parity_crypto::publickey::Secret; use ethereum_types::{H256, U256, Address, BigEndianHash}; use ethcore::{ test_helpers::{get_temp_state, get_temp_state_db} diff --git a/ethcore/machine/Cargo.toml b/ethcore/machine/Cargo.toml index 92df515db5d..dc33e75a968 100644 --- a/ethcore/machine/Cargo.toml +++ b/ethcore/machine/Cargo.toml @@ -37,7 +37,7 @@ common-types = { path = "../types", features = ["test-helpers"] } ethcore = { path = "../", features = ["test-helpers"] } ethcore-io = { path = "../../util/io" } ethjson = { path = "../../json" } -ethkey = { path = "../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } macros = { path = "../../util/macros" } rustc-hex = "1.0" spec = { path = "../spec" } diff --git a/ethcore/machine/src/executive.rs b/ethcore/machine/src/executive.rs index 44de252a980..e473ec3f20f 100644 --- a/ethcore/machine/src/executive.rs +++ b/ethcore/machine/src/executive.rs @@ -1233,7 +1233,7 @@ mod tests { errors::ExecutionError, transaction::{Action, Transaction}, }; - use ethkey::{Generator, Random}; + use parity_crypto::publickey::{Generator, Random}; use evm::{Factory, VMType, evm_test, evm_test_ignore}; use macros::vec_into; use vm::{ActionParams, ActionValue, CallType, EnvInfo, CreateContractAddress}; diff --git a/ethcore/machine/src/machine.rs b/ethcore/machine/src/machine.rs index 5006ac26f1f..144320acbf3 100644 --- a/ethcore/machine/src/machine.rs +++ b/ethcore/machine/src/machine.rs @@ -435,7 +435,7 @@ mod tests { header.set_number(15); let res = machine.verify_transaction_basic(&transaction, &header); - assert_eq!(res, Err(transaction::Error::InvalidSignature("Crypto error (Invalid EC signature)".into()))); + assert_eq!(res, Err(transaction::Error::InvalidSignature("invalid EC signature".into()))); } #[test] diff --git a/ethcore/machine/src/tx_filter.rs b/ethcore/machine/src/tx_filter.rs index 18074330ed6..1a02a0071cc 100644 --- a/ethcore/machine/src/tx_filter.rs +++ b/ethcore/machine/src/tx_filter.rs @@ -178,7 +178,7 @@ mod test { miner::Miner, test_helpers, }; - use ethkey::{Secret, KeyPair}; + use parity_crypto::publickey::{Secret, KeyPair}; use ethcore_io::IoChannel; use spec::Spec; @@ -200,13 +200,13 @@ mod test { Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), ).unwrap(); - let key1 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000001")).unwrap(); - let key2 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000002")).unwrap(); - let key3 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000003")).unwrap(); - let key4 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000004")).unwrap(); - let key5 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000005")).unwrap(); - let key6 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000006")).unwrap(); - let key7 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000007")).unwrap(); + let key1 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap()).unwrap(); + let key2 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000002").unwrap()).unwrap(); + let key3 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000003").unwrap()).unwrap(); + let key4 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000004").unwrap()).unwrap(); + let key5 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000005").unwrap()).unwrap(); + let key6 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000006").unwrap()).unwrap(); + let key7 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000007").unwrap()).unwrap(); let filter = TransactionFilter::from_params(spec.params()).unwrap(); let mut basic_tx = Transaction::default(); @@ -279,7 +279,7 @@ mod test { Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), ).unwrap(); - let key1 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000001")).unwrap(); + let key1 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap()).unwrap(); // The only difference to version 2 is that the contract now knows the transaction's gas price and data. // So we only test those: The contract allows only transactions with either nonzero gas price or short data. @@ -321,10 +321,10 @@ mod test { Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), ).unwrap(); - let key1 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000001")).unwrap(); - let key2 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000002")).unwrap(); - let key3 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000003")).unwrap(); - let key4 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000004")).unwrap(); + let key1 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap()).unwrap(); + let key2 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000002").unwrap()).unwrap(); + let key3 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000003").unwrap()).unwrap(); + let key4 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000004").unwrap()).unwrap(); let filter = TransactionFilter::from_params(spec.params()).unwrap(); let mut basic_tx = Transaction::default(); diff --git a/ethcore/private-tx/Cargo.toml b/ethcore/private-tx/Cargo.toml index e3fae4e6139..6cc26383b3d 100644 --- a/ethcore/private-tx/Cargo.toml +++ b/ethcore/private-tx/Cargo.toml @@ -20,7 +20,6 @@ ethcore-io = { path = "../../util/io" } ethcore-miner = { path = "../../miner" } ethereum-types = "0.8.0" ethjson = { path = "../../json" } -ethkey = { path = "../../accounts/ethkey" } fetch = { path = "../../util/fetch" } futures = "0.1" parity-util-mem = "0.2.0" @@ -32,7 +31,7 @@ log = "0.4" machine = { path = "../machine" } journaldb = { path = "../../util/journaldb" } parity-bytes = "0.1" -parity-crypto = "0.4.0" +parity-crypto = { version = "0.4.2", features = ["publickey"] } parking_lot = "0.9" trie-db = "0.15.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } diff --git a/ethcore/private-tx/src/encryptor.rs b/ethcore/private-tx/src/encryptor.rs index d62ba546b6a..682c99c345d 100644 --- a/ethcore/private-tx/src/encryptor.rs +++ b/ethcore/private-tx/src/encryptor.rs @@ -26,7 +26,7 @@ use std::collections::hash_map::Entry; use parking_lot::Mutex; use ethereum_types::{H128, H256, Address}; use ethjson; -use ethkey::{Signature, Public}; +use crypto::publickey::{Signature, Public}; use crypto; use futures::Future; use fetch::{Fetch, Client as FetchClient, Method, BodyReader, Request}; diff --git a/ethcore/private-tx/src/error.rs b/ethcore/private-tx/src/error.rs index b9167675ff0..b249b417326 100644 --- a/ethcore/private-tx/src/error.rs +++ b/ethcore/private-tx/src/error.rs @@ -23,8 +23,7 @@ use types::{ errors::{EthcoreError, ExecutionError}, transaction::Error as TransactionError, }; -use ethkey::Error as KeyError; -use ethkey::crypto::Error as CryptoError; +use crypto::publickey::Error as CryptoError; use txpool::VerifiedTransaction; use private_transactions::VerifiedPrivateTransaction; use serde_json::{Error as SerdeError}; @@ -123,9 +122,6 @@ pub enum Error { /// VM execution error. #[display(fmt = "VM execution error {}", _0)] Execution(ExecutionError), - /// General signing error. - #[display(fmt = "General signing error {}", _0)] - Key(KeyError), /// Error of transactions processing. #[display(fmt = "Error of transactions processing {}", _0)] Transaction(TransactionError), @@ -147,7 +143,6 @@ impl error::Error for Error { Error::Json(e) => Some(e), Error::Crypto(e) => Some(e), Error::Execution(e) => Some(e), - Error::Key(e) => Some(e), Error::Transaction(e) => Some(e), Error::Ethcore(e) => Some(e), _ => None, @@ -167,12 +162,6 @@ impl From for Error { } } -impl From for Error { - fn from(err: KeyError) -> Self { - Error::Key(err).into() - } -} - impl From for Error { fn from(err: CryptoError) -> Self { Error::Crypto(err).into() diff --git a/ethcore/private-tx/src/key_server_keys.rs b/ethcore/private-tx/src/key_server_keys.rs index b0ac9353fca..26fe6a6a79c 100644 --- a/ethcore/private-tx/src/key_server_keys.rs +++ b/ethcore/private-tx/src/key_server_keys.rs @@ -145,7 +145,8 @@ impl KeyProvider for StoringKeyProvider { #[cfg(test)] mod tests { use std::sync::Arc; - use ethkey::{Secret, KeyPair}; + use std::str::FromStr; + use crypto::publickey::{Secret, KeyPair}; use bytes::Bytes; use super::*; use registrar::RegistrarClient; @@ -185,7 +186,7 @@ mod tests { #[test] fn should_update_acl_contract() { - let key = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000011")).unwrap(); + let key = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000011").unwrap()).unwrap(); let client = DummyRegistryClient::new(Some(key.address())); let keys_data = SecretStoreKeys::new(Arc::new(client), None); keys_data.update_acl_contract(); diff --git a/ethcore/private-tx/src/lib.rs b/ethcore/private-tx/src/lib.rs index a1caf5d9b34..712c19afe8e 100644 --- a/ethcore/private-tx/src/lib.rs +++ b/ethcore/private-tx/src/lib.rs @@ -36,7 +36,6 @@ extern crate ethcore_io as io; extern crate ethcore_miner; extern crate ethereum_types; extern crate ethjson; -extern crate ethkey; extern crate fetch; extern crate futures; extern crate parity_util_mem; @@ -95,7 +94,7 @@ use hash::keccak; use rlp::*; use parking_lot::RwLock; use bytes::Bytes; -use ethkey::{Signature, recover, public_to_address}; +use crypto::publickey::{Signature, recover, public_to_address, Message, KeyPair}; use io::{IoChannel, IoHandler, IoContext, TimerToken}; use machine::{ executive::{Executive, TransactOptions, contract_address as ethcore_contract_address}, @@ -172,7 +171,7 @@ pub trait Signer: Send + Sync { /// Decrypt payload using private key of given address. fn decrypt(&self, account: Address, shared_mac: &[u8], payload: &[u8]) -> Result, Error>; /// Sign given hash using provided account. - fn sign(&self, account: Address, hash: ethkey::Message) -> Result; + fn sign(&self, account: Address, hash: Message) -> Result; } /// Signer implementation that errors on any request. @@ -182,22 +181,22 @@ impl Signer for DummySigner { Err("Decrypting is not supported.".to_owned())? } - fn sign(&self, _account: Address, _hash: ethkey::Message) -> Result { + fn sign(&self, _account: Address, _hash: Message) -> Result { Err("Signing is not supported.".to_owned())? } } /// Signer implementation using multiple keypairs -pub struct KeyPairSigner(pub Vec); +pub struct KeyPairSigner(pub Vec); impl Signer for KeyPairSigner { fn decrypt(&self, account: Address, shared_mac: &[u8], payload: &[u8]) -> Result, Error> { - let kp = self.0.iter().find(|k| k.address() == account).ok_or(ethkey::Error::InvalidAddress)?; - Ok(ethkey::crypto::ecies::decrypt(kp.secret(), shared_mac, payload)?) + let kp = self.0.iter().find(|k| k.address() == account).ok_or(crypto::publickey::Error::InvalidAddress)?; + Ok(crypto::publickey::ecies::decrypt(kp.secret(), shared_mac, payload)?) } - fn sign(&self, account: Address, hash: ethkey::Message) -> Result { - let kp = self.0.iter().find(|k| k.address() == account).ok_or(ethkey::Error::InvalidAddress)?; - Ok(ethkey::sign(kp.secret(), &hash)?) + fn sign(&self, account: Address, hash: Message) -> Result { + let kp = self.0.iter().find(|k| k.address() == account).ok_or(crypto::publickey::Error::InvalidAddress)?; + Ok(crypto::publickey::sign(kp.secret(), &hash)?) } } diff --git a/ethcore/private-tx/src/messages.rs b/ethcore/private-tx/src/messages.rs index 5130b83e534..c2bc43b34fd 100644 --- a/ethcore/private-tx/src/messages.rs +++ b/ethcore/private-tx/src/messages.rs @@ -18,7 +18,7 @@ use ethereum_types::{H256, U256, Address, BigEndianHash}; use bytes::Bytes; use hash::keccak; use rlp::Encodable; -use ethkey::Signature; +use crypto::publickey::Signature; use types::transaction::signature::{add_chain_replay_protection, check_replay_protection}; /// Message with private transaction encrypted diff --git a/ethcore/private-tx/src/private_transactions.rs b/ethcore/private-tx/src/private_transactions.rs index b9108289135..48335eda0a4 100644 --- a/ethcore/private-tx/src/private_transactions.rs +++ b/ethcore/private-tx/src/private_transactions.rs @@ -22,7 +22,7 @@ use bytes::Bytes; use ethcore_miner::pool; use ethereum_types::{H256, U256, Address}; use parity_util_mem::MallocSizeOfExt; -use ethkey::Signature; +use crypto::publickey::Signature; use messages::PrivateTransaction; use parking_lot::RwLock; use types::transaction::{UnverifiedTransaction, SignedTransaction}; diff --git a/ethcore/private-tx/tests/private_contract.rs b/ethcore/private-tx/tests/private_contract.rs index 6c3e57a095e..f7514c456d3 100644 --- a/ethcore/private-tx/tests/private_contract.rs +++ b/ethcore/private-tx/tests/private_contract.rs @@ -22,7 +22,7 @@ extern crate env_logger; extern crate ethcore; extern crate ethcore_io; extern crate ethcore_private_tx; -extern crate ethkey; +extern crate parity_crypto; extern crate keccak_hash as hash; extern crate rustc_hex; extern crate machine; @@ -32,6 +32,7 @@ extern crate spec; extern crate log; use std::sync::Arc; +use std::str::FromStr; use rustc_hex::{FromHex, ToHex}; use types::ids::BlockId; use types::transaction::{Transaction, Action}; @@ -40,7 +41,7 @@ use ethcore::{ miner::Miner, }; use client_traits::BlockChainClient; -use ethkey::{Secret, KeyPair, Signature}; +use parity_crypto::publickey::{Secret, KeyPair, Signature}; use machine::executive::contract_address; use hash::keccak; @@ -52,10 +53,10 @@ fn private_contract() { let _ = ::env_logger::try_init(); let client = generate_dummy_client(0); let chain_id = client.signing_chain_id(); - let key1 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000011")).unwrap(); - let _key2 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000012")).unwrap(); - let key3 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000013")).unwrap(); - let key4 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000014")).unwrap(); + let key1 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000011").unwrap()).unwrap(); + let _key2 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000012").unwrap()).unwrap(); + let key3 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000013").unwrap()).unwrap(); + let key4 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000014").unwrap()).unwrap(); let signer = Arc::new(ethcore_private_tx::KeyPairSigner(vec![key1.clone(), key3.clone(), key4.clone()])); @@ -118,7 +119,7 @@ fn private_contract() { let private_state = pm.execute_private_transaction(BlockId::Latest, &private_tx).unwrap(); let nonced_state_hash = pm.calculate_state_hash(&private_state, private_contract_nonce); let signatures: Vec<_> = [&key3, &key4].iter().map(|k| - Signature::from(::ethkey::sign(&k.secret(), &nonced_state_hash).unwrap().into_electrum())).collect(); + Signature::from(parity_crypto::publickey::sign(&k.secret(), &nonced_state_hash).unwrap().into_electrum())).collect(); let public_tx = pm.public_transaction(private_state, &private_tx, &signatures, 1.into(), 0.into()).unwrap(); let public_tx = public_tx.sign(&key1.secret(), chain_id); push_block_with_transactions(&client, &[public_tx]); @@ -145,7 +146,7 @@ fn private_contract() { let private_state = pm.execute_private_transaction(BlockId::Latest, &private_tx).unwrap(); let private_state_hash = keccak(&private_state); let signatures: Vec<_> = [&key4].iter().map(|k| - Signature::from(::ethkey::sign(&k.secret(), &private_state_hash).unwrap().into_electrum())).collect(); + Signature::from(parity_crypto::publickey::sign(&k.secret(), &private_state_hash).unwrap().into_electrum())).collect(); let public_tx = pm.public_transaction(private_state, &private_tx, &signatures, 2.into(), 0.into()).unwrap(); let public_tx = public_tx.sign(&key1.secret(), chain_id); push_block_with_transactions(&client, &[public_tx]); @@ -191,10 +192,10 @@ fn call_other_private_contract() { // Create client and provider let client = generate_dummy_client(0); let chain_id = client.signing_chain_id(); - let key1 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000011")).unwrap(); - let _key2 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000012")).unwrap(); - let key3 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000013")).unwrap(); - let key4 = KeyPair::from_secret(Secret::from("0000000000000000000000000000000000000000000000000000000000000014")).unwrap(); + let key1 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000011").unwrap()).unwrap(); + let _key2 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000012").unwrap()).unwrap(); + let key3 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000013").unwrap()).unwrap(); + let key4 = KeyPair::from_secret(Secret::from_str("0000000000000000000000000000000000000000000000000000000000000014").unwrap()).unwrap(); let signer = Arc::new(ethcore_private_tx::KeyPairSigner(vec![key1.clone(), key3.clone(), key4.clone()])); let config = ProviderConfig{ @@ -268,7 +269,7 @@ fn call_other_private_contract() { let private_state = pm.execute_private_transaction(BlockId::Latest, &private_tx).unwrap(); let nonced_state_hash = pm.calculate_state_hash(&private_state, private_contract_nonce); let signatures: Vec<_> = [&key3, &key4].iter().map(|k| - Signature::from(::ethkey::sign(&k.secret(), &nonced_state_hash).unwrap().into_electrum())).collect(); + Signature::from(parity_crypto::publickey::sign(&k.secret(), &nonced_state_hash).unwrap().into_electrum())).collect(); let public_tx = pm.public_transaction(private_state, &private_tx, &signatures, 2.into(), 0.into()).unwrap(); let public_tx = public_tx.sign(&key1.secret(), chain_id); push_block_with_transactions(&client, &[public_tx]); diff --git a/ethcore/snapshot/snapshot-tests/Cargo.toml b/ethcore/snapshot/snapshot-tests/Cargo.toml index efe6ec190d3..fbdfc2e7072 100644 --- a/ethcore/snapshot/snapshot-tests/Cargo.toml +++ b/ethcore/snapshot/snapshot-tests/Cargo.toml @@ -18,7 +18,6 @@ ethcore = { path = "../..", features = ["test-helpers"] } ethcore-db = { path = "../../db" } ethcore-io = { path = "../../../util/io" } ethereum-types = "0.8.0" -ethkey = { path = "../../../accounts/ethkey" } ethtrie = { package = "patricia-trie-ethereum", path = "../../../util/patricia-trie-ethereum" } hash-db = "0.15.0" journaldb = { path = "../../../util/journaldb" } @@ -28,6 +27,7 @@ kvdb = "0.1" kvdb-rocksdb = { version = "0.1.5" } log = "0.4.8" parking_lot = "0.9" +parity-crypto = { version = "0.4.2", features = ["publickey"] } rand = "0.7" rand_xorshift = "0.2" rlp = "0.4.2" diff --git a/ethcore/snapshot/snapshot-tests/src/proof_of_authority.rs b/ethcore/snapshot/snapshot-tests/src/proof_of_authority.rs index b36ab4674dd..976d747e593 100644 --- a/ethcore/snapshot/snapshot-tests/src/proof_of_authority.rs +++ b/ethcore/snapshot/snapshot-tests/src/proof_of_authority.rs @@ -30,7 +30,7 @@ use ethcore::{ miner::{self, MinerService}, }; use ethereum_types::Address; -use ethkey::Secret; +use parity_crypto::publickey::Secret; use keccak_hash::keccak; use lazy_static::lazy_static; use log::trace; diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 795a0e6deaf..4527dba8152 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -2785,7 +2785,7 @@ mod tests { use blockchain::{ExtrasInsert, BlockProvider}; use client_traits::{BlockChainClient, ChainInfo}; - use ethkey::KeyPair; + use parity_crypto::publickey::KeyPair; use types::{ encoded, engines::ForkChoice, diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 500bf20688d..f573da498fa 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -73,7 +73,7 @@ extern crate ethcore_stratum; extern crate ethash; #[cfg(any(test, feature = "test-helpers"))] -extern crate ethkey; +extern crate parity_crypto; #[cfg(any(test, feature = "test-helpers"))] extern crate ethjson; #[cfg(any(test, feature = "test-helpers"))] diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 3d55f88eea1..96e5d760b17 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -1509,7 +1509,7 @@ mod tests { use super::*; use accounts::AccountProvider; - use ethkey::{Generator, Random}; + use parity_crypto::publickey::{Generator, Random}; use hash::keccak; use rustc_hex::FromHex; diff --git a/ethcore/src/test_helpers/mod.rs b/ethcore/src/test_helpers/mod.rs index 44b298cdbe1..4c427afcd80 100644 --- a/ethcore/src/test_helpers/mod.rs +++ b/ethcore/src/test_helpers/mod.rs @@ -36,7 +36,7 @@ use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler, Config as BlockC use blooms_db; use bytes::Bytes; use ethereum_types::{H256, U256, Address}; -use ethkey::KeyPair; +use parity_crypto::publickey::KeyPair; use evm::Factory as EvmFactory; use hash::keccak; use io::IoChannel; diff --git a/ethcore/src/test_helpers/test_client.rs b/ethcore/src/test_helpers/test_client.rs index 0409e8249d4..683b08dda1a 100644 --- a/ethcore/src/test_helpers/test_client.rs +++ b/ethcore/src/test_helpers/test_client.rs @@ -28,7 +28,7 @@ use bytes::Bytes; use db::{NUM_COLUMNS, COL_STATE}; use ethcore_miner::pool::VerifiedTransaction; use ethereum_types::{H256, U256, Address}; -use ethkey::{Generator, Random}; +use parity_crypto::publickey::{Generator, Random}; use ethtrie; use hash::keccak; use itertools::Itertools; diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 3fb946e0154..ea5675705ef 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use account_state::state::StateInfo; use ethereum_types::{U256, Address}; -use ethkey::KeyPair; +use parity_crypto::publickey::KeyPair; use hash::keccak; use io::IoChannel; use tempdir::TempDir; diff --git a/ethcore/src/tests/trace.rs b/ethcore/src/tests/trace.rs index 76d7234d176..ad6f9bbf90a 100644 --- a/ethcore/src/tests/trace.rs +++ b/ethcore/src/tests/trace.rs @@ -16,7 +16,7 @@ //! Client tests of tracing -use ethkey::KeyPair; +use parity_crypto::publickey::KeyPair; use hash::keccak; use block::*; use ethereum_types::{U256, Address}; diff --git a/ethcore/sync/Cargo.toml b/ethcore/sync/Cargo.toml index f8018599abb..8356249d914 100644 --- a/ethcore/sync/Cargo.toml +++ b/ethcore/sync/Cargo.toml @@ -17,7 +17,6 @@ enum_primitive = "0.1.1" ethcore-io = { path = "../../util/io" } ethcore-private-tx = { path = "../private-tx" } ethereum-types = "0.8.0" -ethkey = { path = "../../accounts/ethkey" } fastmap = { path = "../../util/fastmap" } futures = "0.1" keccak-hash = "0.4.0" @@ -26,6 +25,7 @@ log = "0.4" macros = { path = "../../util/macros" } network = { package = "ethcore-network", path = "../../util/network" } parity-runtime = { path = "../../util/runtime" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } parity-util-mem = "0.2.0" rand = "0.7" parking_lot = "0.9" diff --git a/ethcore/sync/src/api.rs b/ethcore/sync/src/api.rs index d8d20bad3aa..17c32eca5de 100644 --- a/ethcore/sync/src/api.rs +++ b/ethcore/sync/src/api.rs @@ -39,7 +39,7 @@ use devp2p::NetworkService; use ethcore_io::TimerToken; use ethcore_private_tx::PrivateStateDB; use ethereum_types::{H256, H512, U256}; -use ethkey::Secret; +use parity_crypto::publickey::Secret; use futures::sync::mpsc as futures_mpsc; use futures::Stream; use light::client::AsLightClient; diff --git a/ethcore/sync/src/block_sync.rs b/ethcore/sync/src/block_sync.rs index 126799a3dd0..8c9ede44767 100644 --- a/ethcore/sync/src/block_sync.rs +++ b/ethcore/sync/src/block_sync.rs @@ -647,7 +647,7 @@ mod tests { use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; use ethcore::test_helpers::TestBlockChainClient; - use ethkey::{Random, Generator}; + use parity_crypto::publickey::{Random, Generator}; use keccak_hash::keccak; use parking_lot::RwLock; use rlp::{encode_list, RlpStream}; diff --git a/ethcore/sync/src/chain/mod.rs b/ethcore/sync/src/chain/mod.rs index 780bda34d66..c37a7a6a04a 100644 --- a/ethcore/sync/src/chain/mod.rs +++ b/ethcore/sync/src/chain/mod.rs @@ -1616,7 +1616,7 @@ pub mod tests { #[test] fn should_add_transactions_to_queue() { fn sender(tx: &UnverifiedTransaction) -> Address { - ethkey::public_to_address(&tx.recover_public().unwrap()) + parity_crypto::publickey::public_to_address(&tx.recover_public().unwrap()) } // given diff --git a/ethcore/sync/src/tests/consensus.rs b/ethcore/sync/src/tests/consensus.rs index 6c444a27889..9ee42441b6d 100644 --- a/ethcore/sync/src/tests/consensus.rs +++ b/ethcore/sync/src/tests/consensus.rs @@ -27,7 +27,7 @@ use ethcore::client::Client; use ethcore::miner::{self, MinerService}; use ethcore_io::{IoHandler, IoChannel}; use ethereum_types::{U256, Address}; -use ethkey::{KeyPair, Secret}; +use parity_crypto::publickey::{KeyPair, Secret}; use keccak_hash::keccak; use common_types::{ io_message::ClientIoMessage, diff --git a/ethcore/sync/src/tests/private.rs b/ethcore/sync/src/tests/private.rs index 2a71973326e..7b5f6a36cce 100644 --- a/ethcore/sync/src/tests/private.rs +++ b/ethcore/sync/src/tests/private.rs @@ -37,7 +37,7 @@ use ethcore_io::{IoHandler, IoChannel}; use ethcore_private_tx::{ Provider, ProviderConfig, NoopEncryptor, Importer, SignedPrivateTransaction, StoringKeyProvider }; -use ethkey::KeyPair; +use parity_crypto::publickey::KeyPair; use keccak_hash::keccak; use machine::executive::contract_address; use rustc_hex::FromHex; diff --git a/ethcore/types/Cargo.toml b/ethcore/types/Cargo.toml index 4aa5d8b5dba..509b9d13dd7 100644 --- a/ethcore/types/Cargo.toml +++ b/ethcore/types/Cargo.toml @@ -10,9 +10,9 @@ ethbloom = "0.8.0" ethcore-io = { path = "../../util/io" } ethereum-types = "0.8.0" ethjson = { path = "../../json" } -ethkey = { path = "../../accounts/ethkey" } keccak-hash = "0.4.0" parity-bytes = "0.1" +parity-crypto = { version = "0.4.2", features = ["publickey"] } parity-util-mem = "0.2.0" parity-snappy = "0.1" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } diff --git a/ethcore/types/src/errors/ethcore_error.rs b/ethcore/types/src/errors/ethcore_error.rs index f7b5abc9ef9..e995dab430a 100644 --- a/ethcore/types/src/errors/ethcore_error.rs +++ b/ethcore/types/src/errors/ethcore_error.rs @@ -21,7 +21,7 @@ use derive_more::{Display, From}; use ethereum_types::{U256, U512}; use ethtrie::TrieError; use parity_snappy::InvalidInput; -use ethkey::Error as EthkeyError; +use parity_crypto::publickey::{Error as EthPublicKeyCryptoError}; use errors::{BlockError, EngineError, ImportError, SnapshotError}; use transaction::Error as TransactionError; @@ -64,7 +64,7 @@ pub enum EthcoreError { Engine(EngineError), /// Ethkey error." #[display(fmt = "Ethkey error: {}", _0)] - Ethkey(EthkeyError), + Ethkey(EthPublicKeyCryptoError), /// RLP decoding errors #[display(fmt = "Decoder error: {}", _0)] Decoder(rlp::DecoderError), diff --git a/ethcore/types/src/lib.rs b/ethcore/types/src/lib.rs index d78995d0c15..58ca86cae94 100644 --- a/ethcore/types/src/lib.rs +++ b/ethcore/types/src/lib.rs @@ -36,7 +36,7 @@ extern crate ethbloom; extern crate ethereum_types; extern crate ethjson; -extern crate ethkey; +extern crate parity_crypto; #[macro_use] extern crate derive_more; extern crate keccak_hash as hash; diff --git a/ethcore/types/src/transaction/error.rs b/ethcore/types/src/transaction/error.rs index 1ad9d535803..1e27b63375c 100644 --- a/ethcore/types/src/transaction/error.rs +++ b/ethcore/types/src/transaction/error.rs @@ -17,7 +17,7 @@ use std::{fmt, error}; use ethereum_types::U256; -use ethkey; +use parity_crypto::publickey::{Error as EthPublicKeyCryptoError}; use rlp; use unexpected::OutOfBounds; @@ -88,8 +88,8 @@ pub enum Error { InvalidRlp(String), } -impl From for Error { - fn from(err: ethkey::Error) -> Self { +impl From for Error { + fn from(err: EthPublicKeyCryptoError) -> Self { Error::InvalidSignature(format!("{}", err)) } } diff --git a/ethcore/types/src/transaction/transaction.rs b/ethcore/types/src/transaction/transaction.rs index bdbc302fcc6..aaa0da216cb 100644 --- a/ethcore/types/src/transaction/transaction.rs +++ b/ethcore/types/src/transaction/transaction.rs @@ -20,7 +20,7 @@ use std::ops::Deref; use ethereum_types::{H256, H160, Address, U256, BigEndianHash}; use ethjson; -use ethkey::{self, Signature, Secret, Public, recover, public_to_address}; +use parity_crypto::publickey::{Signature, Secret, Public, recover, public_to_address}; use hash::keccak; use parity_util_mem::MallocSizeOf; @@ -193,7 +193,7 @@ impl Transaction { /// Signs the transaction as coming from `sender`. pub fn sign(self, secret: &Secret, chain_id: Option) -> SignedTransaction { - let sig = ::ethkey::sign(secret, &self.hash(chain_id)) + let sig = parity_crypto::publickey::sign(secret, &self.hash(chain_id)) .expect("data is valid and context has signing capabilities; qed"); SignedTransaction::new(self.with_signature(sig, chain_id)) .expect("secret is valid so it's recoverable") @@ -367,9 +367,9 @@ impl UnverifiedTransaction { } /// Checks whether the signature has a low 's' value. - pub fn check_low_s(&self) -> Result<(), ethkey::Error> { + pub fn check_low_s(&self) -> Result<(), parity_crypto::publickey::Error> { if !self.signature().is_low_s() { - Err(ethkey::Error::InvalidSignature.into()) + Err(parity_crypto::publickey::Error::InvalidSignature.into()) } else { Ok(()) } @@ -381,7 +381,7 @@ impl UnverifiedTransaction { } /// Recovers the public key of the sender. - pub fn recover_public(&self) -> Result { + pub fn recover_public(&self) -> Result { Ok(recover(&self.signature(), &self.unsigned.hash(self.chain_id()))?) } @@ -392,11 +392,11 @@ impl UnverifiedTransaction { } // Disallow unsigned transactions in case EIP-86 is disabled. if !allow_empty_signature && self.is_unsigned() { - return Err(ethkey::Error::InvalidSignature.into()); + return Err(parity_crypto::publickey::Error::InvalidSignature.into()); } // EIP-86: Transactions of this form MUST have gasprice = 0, nonce = 0, value = 0, and do NOT increment the nonce of account 0. if allow_empty_signature && self.is_unsigned() && !(self.gas_price.is_zero() && self.value.is_zero() && self.nonce.is_zero()) { - return Err(ethkey::Error::InvalidSignature.into()) + return Err(parity_crypto::publickey::Error::InvalidSignature.into()) } match (self.chain_id(), chain_id) { (None, _) => {}, @@ -407,7 +407,7 @@ impl UnverifiedTransaction { } /// Try to verify transaction and recover sender. - pub fn verify_unordered(self) -> Result { + pub fn verify_unordered(self) -> Result { SignedTransaction::new(self) } } @@ -439,7 +439,7 @@ impl From for UnverifiedTransaction { impl SignedTransaction { /// Try to verify transaction and recover sender. - pub fn new(transaction: UnverifiedTransaction) -> Result { + pub fn new(transaction: UnverifiedTransaction) -> Result { if transaction.is_unsigned() { Ok(SignedTransaction { transaction: transaction, @@ -591,7 +591,7 @@ mod tests { #[test] fn signing_eip155_zero_chainid() { - use ethkey::{Random, Generator}; + use parity_crypto::publickey::{Random, Generator}; let key = Random.generate().unwrap(); let t = Transaction { @@ -604,7 +604,7 @@ mod tests { }; let hash = t.hash(Some(0)); - let sig = ::ethkey::sign(&key.secret(), &hash).unwrap(); + let sig = parity_crypto::publickey::sign(&key.secret(), &hash).unwrap(); let u = t.with_signature(sig, Some(0)); assert!(SignedTransaction::new(u).is_ok()); @@ -612,7 +612,7 @@ mod tests { #[test] fn signing() { - use ethkey::{Random, Generator}; + use parity_crypto::publickey::{Random, Generator}; let key = Random.generate().unwrap(); let t = Transaction { @@ -647,7 +647,7 @@ mod tests { #[test] fn should_recover_from_chain_specific_signing() { - use ethkey::{Random, Generator}; + use parity_crypto::publickey::{Random, Generator}; let key = Random.generate().unwrap(); let t = Transaction { action: Action::Create, diff --git a/ethcore/verification/Cargo.toml b/ethcore/verification/Cargo.toml index 41a020e0693..ef86ab86137 100644 --- a/ethcore/verification/Cargo.toml +++ b/ethcore/verification/Cargo.toml @@ -34,7 +34,7 @@ unexpected = { path = "../../util/unexpected" } [dev-dependencies] criterion = "0.3" ethcore = { path = "../", features = ["test-helpers"] } -ethkey = { path = "../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } machine = { path = "../machine" } null-engine = { path = "../engines/null-engine" } spec = { path = "../spec" } diff --git a/ethcore/verification/src/verification.rs b/ethcore/verification/src/verification.rs index 8cf152b4af7..3f06c39ad66 100644 --- a/ethcore/verification/src/verification.rs +++ b/ethcore/verification/src/verification.rs @@ -375,7 +375,7 @@ mod tests { use parity_bytes::Bytes; use keccak_hash::keccak; use engine::Engine; - use ethkey::{Random, Generator}; + use parity_crypto::publickey::{Random, Generator}; use spec; use ethcore::test_helpers::{ create_test_block_with_data, create_test_block, TestBlockChainClient @@ -587,7 +587,7 @@ mod tests { bad_header.set_transactions_root(eip86_transactions_root.clone()); bad_header.set_uncles_hash(good_uncles_hash.clone()); match basic_test(&create_test_block_with_data(&bad_header, &eip86_transactions, &good_uncles), engine) { - Err(Error::Transaction(ref e)) if e == &::ethkey::Error::InvalidSignature.into() => (), + Err(Error::Transaction(ref e)) if e == &parity_crypto::publickey::Error::InvalidSignature.into() => (), e => panic!("Block verification failed.\nExpected: Transaction Error (Invalid Signature)\nGot: {:?}", e), } diff --git a/miner/Cargo.toml b/miner/Cargo.toml index 297c8a64a57..4cb90abdf30 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -39,7 +39,7 @@ transaction-pool = "2.0.1" [dev-dependencies] env_logger = "0.5" -ethkey = { path = "../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } rustc-hex = "1.0" [features] diff --git a/miner/local-store/Cargo.toml b/miner/local-store/Cargo.toml index 45ec72a671d..6af34096696 100644 --- a/miner/local-store/Cargo.toml +++ b/miner/local-store/Cargo.toml @@ -17,4 +17,5 @@ serde_json = "1.0" [dev-dependencies] ethkey = { path = "../../accounts/ethkey" } +parity-crypto = { version = "0.4.2", features = ["publickey"] } kvdb-memorydb = "0.1.2" diff --git a/miner/local-store/src/lib.rs b/miner/local-store/src/lib.rs index 7c3a12776b3..6782bf447f6 100644 --- a/miner/local-store/src/lib.rs +++ b/miner/local-store/src/lib.rs @@ -201,7 +201,8 @@ mod tests { use std::sync::Arc; use common_types::transaction::{Transaction, Condition, PendingTransaction}; - use ethkey::{Brain, Generator}; + use ethkey::Brain; + use parity_crypto::publickey::Generator; // we want to test: round-trip of good transactions. // failure to roundtrip bad transactions (but that it doesn't panic) diff --git a/miner/src/lib.rs b/miner/src/lib.rs index f67c437708d..ce9a5ceee60 100644 --- a/miner/src/lib.rs +++ b/miner/src/lib.rs @@ -50,7 +50,7 @@ extern crate trace_time; #[cfg(test)] extern crate rustc_hex; #[cfg(test)] -extern crate ethkey; +extern crate parity_crypto; #[cfg(test)] extern crate env_logger; diff --git a/miner/src/pool/local_transactions.rs b/miner/src/pool/local_transactions.rs index a83af5b72e4..e18c0a4d7b1 100644 --- a/miner/src/pool/local_transactions.rs +++ b/miner/src/pool/local_transactions.rs @@ -235,7 +235,7 @@ impl txpool::Listener for LocalTransactionsList { mod tests { use super::*; use ethereum_types::U256; - use ethkey::{Random, Generator}; + use parity_crypto::publickey::{Random, Generator}; use types::transaction; use txpool::Listener; diff --git a/miner/src/pool/replace.rs b/miner/src/pool/replace.rs index 9ed15bad26a..6b60b562e54 100644 --- a/miner/src/pool/replace.rs +++ b/miner/src/pool/replace.rs @@ -119,7 +119,7 @@ mod tests { use super::*; use std::sync::Arc; - use ethkey::{Random, Generator, KeyPair}; + use parity_crypto::publickey::{Random, Generator, KeyPair}; use pool::tests::tx::{Tx, TxExt}; use pool::tests::client::TestClient; use pool::scoring::*; diff --git a/miner/src/pool/tests/tx.rs b/miner/src/pool/tests/tx.rs index b8f6dca676d..69ba0863db6 100644 --- a/miner/src/pool/tests/tx.rs +++ b/miner/src/pool/tests/tx.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use ethereum_types::{U256, H256}; -use ethkey::{Random, Generator}; +use parity_crypto::publickey::{Random, Generator}; use rustc_hex::FromHex; use types::transaction::{self, Transaction, SignedTransaction, UnverifiedTransaction}; diff --git a/parity/account_utils.rs b/parity/account_utils.rs index 4f65336315d..727bb875222 100644 --- a/parity/account_utils.rs +++ b/parity/account_utils.rs @@ -166,7 +166,7 @@ mod accounts { mod private_tx { use super::*; - use ethkey::{Signature, Message}; + use parity_crypto::publickey::{Signature, Message}; use ethcore_private_tx::{Error}; pub struct AccountSigner { @@ -211,8 +211,8 @@ mod accounts { } fn insert_dev_account(account_provider: &AccountProvider) { - let secret: ethkey::Secret = "4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7".into(); - let dev_account = ethkey::KeyPair::from_secret(secret.clone()).expect("Valid secret produces valid key;qed"); + let secret = parity_crypto::publickey::Secret::from_str("4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7".into()).expect("Valid account;qed"); + let dev_account = parity_crypto::publickey::KeyPair::from_secret(secret.clone()).expect("Valid secret produces valid key;qed"); if !account_provider.has_account(dev_account.address()) { match account_provider.insert_account(secret, &Password::from(String::new())) { Err(e) => warn!("Unable to add development account: {}", e), diff --git a/parity/configuration.rs b/parity/configuration.rs index 9fe6c879229..4c99e51c35d 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -28,7 +28,7 @@ use parity_version::{version_data, version}; use bytes::Bytes; use ansi_term::Colour; use sync::{NetworkConfiguration, validate_node_url, self}; -use ethkey::{Secret, Public}; +use parity_crypto::publickey::{Secret, Public}; use ethcore::client::VMType; use ethcore::miner::{stratum, MinerOptions}; use snapshot::SnapshotConfiguration; @@ -749,7 +749,7 @@ impl Configuration { ret.listen_address = Some(format!("{}", listen)); ret.public_address = public.map(|p| format!("{}", p)); ret.use_secret = match self.args.arg_node_key.as_ref() - .map(|s| s.parse::().or_else(|_| Secret::from_unsafe_slice(keccak(s).as_bytes())).map_err(|e| format!("Invalid key: {:?}", e)) + .map(|s| s.parse::().or_else(|_| Secret::import_key(keccak(s).as_bytes())).map_err(|e| format!("Invalid key: {:?}", e)) ) { None => None, Some(Ok(key)) => Some(key), diff --git a/parity/lib.rs b/parity/lib.rs index 492c3187515..7e856505374 100644 --- a/parity/lib.rs +++ b/parity/lib.rs @@ -63,6 +63,7 @@ extern crate keccak_hash as hash; extern crate kvdb; extern crate node_filter; extern crate parity_bytes as bytes; +extern crate parity_crypto; extern crate parity_hash_fetch as hash_fetch; extern crate parity_ipfs_api; extern crate parity_local_store as local_store; diff --git a/parity/presale.rs b/parity/presale.rs index 9940fb50c64..a09e05d8c17 100644 --- a/parity/presale.rs +++ b/parity/presale.rs @@ -43,7 +43,7 @@ pub fn execute(cmd: ImportWallet) -> Result { } #[cfg(feature = "accounts")] -pub fn import_account(cmd: &ImportWallet, kp: ethkey::KeyPair, password: Password) { +pub fn import_account(cmd: &ImportWallet, kp: parity_crypto::publickey::KeyPair, password: Password) { use accounts::{AccountProvider, AccountProviderSettings}; use ethstore::EthStore; use ethstore::accounts_dir::RootDiskDirectory; @@ -55,4 +55,4 @@ pub fn import_account(cmd: &ImportWallet, kp: ethkey::KeyPair, password: Passwor } #[cfg(not(feature = "accounts"))] -pub fn import_account(_cmd: &ImportWallet, _kp: ethkey::KeyPair, _password: Password) {} +pub fn import_account(_cmd: &ImportWallet, _kp: parity_crypto::publickey::KeyPair, _password: Password) {} diff --git a/parity/secretstore.rs b/parity/secretstore.rs index 27424e2752b..f4af29e67b4 100644 --- a/parity/secretstore.rs +++ b/parity/secretstore.rs @@ -21,7 +21,8 @@ use dir::default_data_path; use dir::helpers::replace_home; use ethcore::client::Client; use ethcore::miner::Miner; -use ethkey::{Secret, Public, Password}; +use ethkey::Password; +use parity_crypto::publickey::{Secret, Public}; use sync::SyncProvider; use ethereum_types::Address; use parity_runtime::Executor; @@ -121,7 +122,7 @@ mod server { mod server { use std::sync::Arc; use ethcore_secretstore; - use ethkey::KeyPair; + use parity_crypto::publickey::KeyPair; use ansi_term::Colour::{Red, White}; use db; use super::{Configuration, Dependencies, NodeSecretKey, ContractAddress, Executor}; diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index b392c6f61fd..3e927f699b0 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -51,7 +51,7 @@ ethereum-types = "0.8.0" fastmap = { path = "../util/fastmap" } machine = { path = "../ethcore/machine" } parity-bytes = "0.1" -parity-crypto = "0.4.0" +parity-crypto = { version = "0.4.2", features = ["publickey"] } eip-712 = { path = "../util/EIP-712" } ethjson = { path = "../json" } diff --git a/rpc/src/v1/helpers/dispatch/mod.rs b/rpc/src/v1/helpers/dispatch/mod.rs index 81a865f0fba..f9eee8d0a38 100644 --- a/rpc/src/v1/helpers/dispatch/mod.rs +++ b/rpc/src/v1/helpers/dispatch/mod.rs @@ -78,7 +78,8 @@ use bytes::Bytes; use client_traits::BlockChainClient; use ethcore::miner::MinerService; use ethereum_types::{H520, H256, U256, Address}; -use ethkey::{Password, Signature}; +use ethkey::Password; +use crypto::publickey::Signature; use hash::keccak; use types::transaction::{SignedTransaction, PendingTransaction}; diff --git a/rpc/src/v1/helpers/dispatch/signing.rs b/rpc/src/v1/helpers/dispatch/signing.rs index 8f16bb78ae1..db9cab09590 100644 --- a/rpc/src/v1/helpers/dispatch/signing.rs +++ b/rpc/src/v1/helpers/dispatch/signing.rs @@ -20,7 +20,7 @@ use accounts::AccountProvider; use bytes::Bytes; use crypto::DEFAULT_MAC; use ethereum_types::{H256, U256, Address}; -use ethkey::{Signature}; +use crypto::publickey::Signature; use types::transaction::{Transaction, Action, SignedTransaction}; use jsonrpc_core::Result; diff --git a/rpc/src/v1/helpers/engine_signer.rs b/rpc/src/v1/helpers/engine_signer.rs index fd40dc95e24..c6b86a01a79 100644 --- a/rpc/src/v1/helpers/engine_signer.rs +++ b/rpc/src/v1/helpers/engine_signer.rs @@ -17,7 +17,8 @@ use std::sync::Arc; use accounts::AccountProvider; -use ethkey::{self, Address, Password}; +use ethkey::Password; +use crypto::publickey::{Address, Message, Signature, Error}; /// An implementation of EngineSigner using internal account management. pub struct EngineSigner { @@ -34,10 +35,10 @@ impl EngineSigner { } impl engine::signer::EngineSigner for EngineSigner { - fn sign(&self, message: ethkey::Message) -> Result { + fn sign(&self, message: Message) -> Result { match self.accounts.sign(self.address, Some(self.password.clone()), message) { Ok(ok) => Ok(ok), - Err(_) => Err(ethkey::Error::InvalidSecret), + Err(_) => Err(Error::InvalidSecretKey), } } diff --git a/rpc/src/v1/helpers/secretstore.rs b/rpc/src/v1/helpers/secretstore.rs index 3db4578eb2f..ba93c7d2c25 100644 --- a/rpc/src/v1/helpers/secretstore.rs +++ b/rpc/src/v1/helpers/secretstore.rs @@ -17,7 +17,7 @@ use std::collections::BTreeSet; use rand::{RngCore, rngs::OsRng}; use ethereum_types::{H256, H512}; -use ethkey::{self, Public, Secret, Random, Generator, math}; +use crypto::publickey::{Public, Secret, Random, Generator, ec_math_utils}; use crypto; use bytes::Bytes; use jsonrpc_core::Error; @@ -37,7 +37,7 @@ pub fn generate_document_key(account_public: Public, server_key_public: Public) let (common_point, encrypted_point) = encrypt_secret(document_key.public(), &server_key_public)?; // ..and now encrypt document key with account public - let encrypted_key = ethkey::crypto::ecies::encrypt( + let encrypted_key = crypto::publickey::ecies::encrypt( &account_public, &crypto::DEFAULT_MAC, document_key.public().as_bytes(), @@ -130,9 +130,9 @@ fn decrypt_with_shadow_coefficients(mut decrypted_shadow: Public, mut common_sha .map_err(errors::encryption)?; } - math::public_mul_secret(&mut common_shadow_point, &shadow_coefficients_sum) + ec_math_utils::public_mul_secret(&mut common_shadow_point, &shadow_coefficients_sum) .map_err(errors::encryption)?; - math::public_add(&mut decrypted_shadow, &common_shadow_point) + ec_math_utils::public_add(&mut decrypted_shadow, &common_shadow_point) .map_err(errors::encryption)?; Ok(decrypted_shadow) } @@ -145,15 +145,15 @@ fn encrypt_secret(secret: &Public, joint_public: &Public) -> Result<(Public, Pub .map_err(errors::encryption)?; // k * T - let mut common_point = math::generation_point(); - math::public_mul_secret(&mut common_point, key_pair.secret()) + let mut common_point = ec_math_utils::generation_point(); + ec_math_utils::public_mul_secret(&mut common_point, key_pair.secret()) .map_err(errors::encryption)?; // M + k * y let mut encrypted_point = joint_public.clone(); - math::public_mul_secret(&mut encrypted_point, key_pair.secret()) + ec_math_utils::public_mul_secret(&mut encrypted_point, key_pair.secret()) .map_err(errors::encryption)?; - math::public_add(&mut encrypted_point, secret) + ec_math_utils::public_add(&mut encrypted_point, secret) .map_err(errors::encryption)?; Ok((common_point, encrypted_point)) diff --git a/rpc/src/v1/helpers/signature.rs b/rpc/src/v1/helpers/signature.rs index b191a3737e8..f9ca0ea2e8c 100644 --- a/rpc/src/v1/helpers/signature.rs +++ b/rpc/src/v1/helpers/signature.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use ethkey::{recover, public_to_address, Signature}; +use crypto::publickey::{recover, public_to_address, Signature}; use ethereum_types::{H256, U64}; use jsonrpc_core::Result; use v1::types::{Bytes, RecoveredAccount}; @@ -54,7 +54,7 @@ pub fn verify_signature( #[cfg(test)] mod tests { use super::*; - use ethkey::Generator; + use crypto::publickey::{Generator, Random}; use ethereum_types::{H160, U64}; pub fn add_chain_replay_protection(v: u64, chain_id: Option) -> u64 { @@ -71,9 +71,9 @@ mod tests { /// mocked signer fn sign(should_prefix: bool, data: Vec, signing_chain_id: Option) -> (H160, [u8; 32], [u8; 32], U64) { let hash = if should_prefix { eth_data_hash(data) } else { keccak(data) }; - let account = ethkey::Random.generate().unwrap(); + let account = Random.generate().unwrap(); let address = account.address(); - let sig = ethkey::sign(account.secret(), &hash).unwrap(); + let sig = crypto::publickey::sign(account.secret(), &hash).unwrap(); let (r, s, v) = (sig.r(), sig.s(), sig.v()); let v = add_chain_replay_protection(v as u64, signing_chain_id); let (r_buf, s_buf) = { diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index 4171df78dd6..9f929ee3f55 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -21,7 +21,8 @@ use std::collections::BTreeMap; use version::version_data; use crypto::DEFAULT_MAC; -use ethkey::{crypto::ecies, Brain, Generator}; +use ethkey::Brain; +use crypto::publickey::{Generator, ecies}; use ethstore::random_phrase; use sync::{LightSyncInfo, LightSyncProvider, LightNetworkDispatcher, ManageNetwork}; use updater::VersionInfo as UpdaterVersionInfo; diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 2151ecc9419..83ea0e799fd 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -26,7 +26,8 @@ use ethcore::miner::{self, MinerService, FilterOptions}; use snapshot::SnapshotService; use account_state::state::StateInfo; use ethcore_logger::RotatingLogger; -use ethkey::{crypto::ecies, Brain, Generator}; +use ethkey::Brain; +use crypto::publickey::{ecies, Generator}; use ethstore::random_phrase; use jsonrpc_core::futures::future; use jsonrpc_core::{BoxFuture, Result}; diff --git a/rpc/src/v1/impls/parity_accounts.rs b/rpc/src/v1/impls/parity_accounts.rs index 62bc6d1ccef..c0549282666 100644 --- a/rpc/src/v1/impls/parity_accounts.rs +++ b/rpc/src/v1/impls/parity_accounts.rs @@ -22,7 +22,8 @@ use std::collections::{ }; use ethereum_types::{Address, H160, H256, H520}; -use ethkey::{Brain, Generator, Secret}; +use ethkey::{Brain, Password}; +use crypto::publickey::{Generator, Secret}; use ethstore::KeyFile; use accounts::AccountProvider; use jsonrpc_core::Result; @@ -30,7 +31,6 @@ use v1::helpers::deprecated::{self, DeprecationNotice}; use v1::helpers::errors; use v1::traits::{ParityAccounts, ParityAccountsInfo}; use v1::types::{Derive, DeriveHierarchical, DeriveHash, ExtAccountInfo, AccountInfo}; -use ethkey::Password; /// Account management (personal) rpc implementation. pub struct ParityAccountsClient { @@ -134,7 +134,7 @@ impl ParityAccounts for ParityAccountsClient { fn new_account_from_secret(&self, secret: H256, pass: Password) -> Result { self.deprecation_notice("parity_newAccountFromSecret"); - let secret = Secret::from_unsafe_slice(&secret.0) + let secret = Secret::import_key(&secret.0) .map_err(|e| errors::account("Could not create account.", e))?; self.accounts.insert_account(secret, &pass) .map(Into::into) diff --git a/rpc/src/v1/impls/parity_set.rs b/rpc/src/v1/impls/parity_set.rs index 0db3c99ca27..84b335cb96a 100644 --- a/rpc/src/v1/impls/parity_set.rs +++ b/rpc/src/v1/impls/parity_set.rs @@ -23,7 +23,7 @@ use client_traits::BlockChainClient; use types::client_types::Mode; use ethcore::miner::{self, MinerService}; use ethereum_types::{H160, H256, U256}; -use ethkey; +use crypto::publickey::KeyPair; use fetch::{self, Fetch}; use hash::keccak_buffer; use sync::ManageNetwork; @@ -161,7 +161,7 @@ impl ParitySet for ParitySetClient where } fn set_engine_signer_secret(&self, secret: H256) -> Result { - let keypair = ethkey::KeyPair::from_secret(secret.into()).map_err(|e| errors::account("Invalid secret", e))?; + let keypair = KeyPair::from_secret(secret.into()).map_err(|e| errors::account("Invalid secret", e))?; self.miner.set_author(miner::Author::Sealer(engine::signer::from_keypair(keypair))); Ok(true) } diff --git a/rpc/src/v1/impls/personal.rs b/rpc/src/v1/impls/personal.rs index e0d6a97fe28..458154a9965 100644 --- a/rpc/src/v1/impls/personal.rs +++ b/rpc/src/v1/impls/personal.rs @@ -22,7 +22,7 @@ use accounts::AccountProvider; use bytes::Bytes; use eip_712::{EIP712, hash_structured_data}; use ethereum_types::{H160, H256, H520, U128, Address}; -use ethkey::{public_to_address, recover, Signature}; +use crypto::publickey::{public_to_address, recover, Signature}; use types::transaction::{PendingTransaction, SignedTransaction}; use jsonrpc_core::futures::{future, Future}; diff --git a/rpc/src/v1/impls/secretstore.rs b/rpc/src/v1/impls/secretstore.rs index b6526b85d5f..3e5ed0a8112 100644 --- a/rpc/src/v1/impls/secretstore.rs +++ b/rpc/src/v1/impls/secretstore.rs @@ -22,7 +22,7 @@ use std::sync::Arc; use accounts::AccountProvider; use crypto::DEFAULT_MAC; use ethereum_types::{H160, H256, H512}; -use ethkey::Secret; +use crypto::publickey::Secret; use jsonrpc_core::Result; use v1::helpers::errors; @@ -54,7 +54,7 @@ impl SecretStoreClient { /// Decrypt secret key using account' private key fn decrypt_secret(&self, address: H160, password: Password, key: Bytes) -> Result { self.decrypt_key(address, password, key) - .and_then(|s| Secret::from_unsafe_slice(&s).map_err(|e| errors::account("invalid secret", e))) + .and_then(|s| Secret::import_key(&s).map_err(|e| errors::account("invalid secret", e))) } } diff --git a/rpc/src/v1/impls/signer.rs b/rpc/src/v1/impls/signer.rs index b135a1fbaa4..a115ab531a8 100644 --- a/rpc/src/v1/impls/signer.rs +++ b/rpc/src/v1/impls/signer.rs @@ -19,7 +19,6 @@ use std::sync::Arc; use ethereum_types::{U256, H520}; -use ethkey; use parity_runtime::Executor; use parking_lot::Mutex; use rlp::Rlp; @@ -216,16 +215,16 @@ impl Signer for SignerClient { }, ConfirmationPayload::EthSignMessage(address, data) => { let expected_hash = eth_data_hash(data); - let signature = ethkey::Signature::from_electrum(&bytes.0); - match ethkey::verify_address(&address, &signature, &expected_hash) { + let signature = crypto::publickey::Signature::from_electrum(&bytes.0); + match crypto::publickey::verify_address(&address, &signature, &expected_hash) { Ok(true) => Ok(ConfirmationResponse::Signature(H520::from_slice(bytes.0.as_slice()))), Ok(false) => Err(errors::invalid_params("Sender address does not match the signature.", ())), Err(err) => Err(errors::invalid_params("Invalid signature received.", err)), } }, ConfirmationPayload::SignMessage(address, hash) => { - let signature = ethkey::Signature::from_electrum(&bytes.0); - match ethkey::verify_address(&address, &signature, &hash) { + let signature = crypto::publickey::Signature::from_electrum(&bytes.0); + match crypto::publickey::verify_address(&address, &signature, &hash) { Ok(true) => Ok(ConfirmationResponse::Signature(H520::from_slice(bytes.0.as_slice()))), Ok(false) => Err(errors::invalid_params("Sender address does not match the signature.", ())), Err(err) => Err(errors::invalid_params("Invalid signature received.", err)), diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index 85f80350337..06da1861e4a 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use ethcore::test_helpers::TestBlockChainClient; use ethcore_logger::RotatingLogger; use ethereum_types::{Address, U256, H256, BigEndianHash, Bloom}; -use ethstore::ethkey::{Generator, Random}; +use crypto::publickey::{Generator, Random}; use machine::executed::Executed; use miner::pool::local_transactions::Status as LocalTransactionStatus; use sync::ManageNetwork; diff --git a/rpc/src/v1/tests/mocked/personal.rs b/rpc/src/v1/tests/mocked/personal.rs index b9c3cb6d77d..5e6d3a1c394 100644 --- a/rpc/src/v1/tests/mocked/personal.rs +++ b/rpc/src/v1/tests/mocked/personal.rs @@ -34,7 +34,7 @@ use v1::tests::helpers::TestMinerService; use v1::types::{EIP191Version, PresignedTransaction}; use rustc_hex::ToHex; use serde_json::to_value; -use ethkey::Secret; +use crypto::publickey::Secret; struct PersonalTester { _runtime: Runtime, diff --git a/rpc/src/v1/tests/mocked/secretstore.rs b/rpc/src/v1/tests/mocked/secretstore.rs index 96e20d0028b..386a2455f72 100644 --- a/rpc/src/v1/tests/mocked/secretstore.rs +++ b/rpc/src/v1/tests/mocked/secretstore.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use crypto::DEFAULT_MAC; use accounts::AccountProvider; use ethereum_types::H256; -use ethkey::{KeyPair, Signature, verify_public}; +use crypto::publickey::{KeyPair, Signature, verify_public}; use serde_json; use jsonrpc_core::{IoHandler, Success}; diff --git a/rpc/src/v1/tests/mocked/signing.rs b/rpc/src/v1/tests/mocked/signing.rs index cf7da360e68..184d3d8b6ec 100644 --- a/rpc/src/v1/tests/mocked/signing.rs +++ b/rpc/src/v1/tests/mocked/signing.rs @@ -35,8 +35,7 @@ use accounts::AccountProvider; use bytes::ToPretty; use ethcore::test_helpers::TestBlockChainClient; use ethereum_types::{U256, Address, Signature, H256}; -use ethkey::Secret; -use ethstore::ethkey::{Generator, Random}; +use crypto::publickey::{Generator, Random, Secret}; use parity_runtime::{Runtime, Executor}; use parking_lot::Mutex; use serde_json; diff --git a/secret-store/Cargo.toml b/secret-store/Cargo.toml index 9402a163188..24af2a798f6 100644 --- a/secret-store/Cargo.toml +++ b/secret-store/Cargo.toml @@ -17,7 +17,6 @@ ethcore-accounts = { path = "../accounts", optional = true} ethcore-call-contract = { path = "../ethcore/call-contract" } ethcore-sync = { path = "../ethcore/sync" } ethereum-types = "0.8.0" -ethkey = { path = "../accounts/ethkey" } futures = "0.1" hyper = { version = "0.12", default-features = false } keccak-hash = "0.4.0" @@ -25,7 +24,7 @@ kvdb = "0.1" lazy_static = "1.0" log = "0.4" parity-bytes = "0.1" -parity-crypto = "0.4.0" +parity-crypto = { version = "0.4.2", features = ["publickey"] } parity-runtime = { path = "../util/runtime" } parking_lot = "0.9" percent-encoding = "2.1.0" @@ -43,6 +42,7 @@ jsonrpc-server-utils = "14.0.1" [dev-dependencies] env_logger = "0.5" +ethkey = { path = "../accounts/ethkey" } ethcore = { path = "../ethcore", features = ["test-helpers"] } tempdir = "0.3" kvdb-rocksdb = "0.1.5" diff --git a/secret-store/src/key_server.rs b/secret-store/src/key_server.rs index 233a9b3db4f..bbb45b5afdd 100644 --- a/secret-store/src/key_server.rs +++ b/secret-store/src/key_server.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use futures::{future::{err, result}, Future}; use parking_lot::Mutex; use crypto::DEFAULT_MAC; -use ethkey::{crypto, public_to_address}; +use crypto::publickey::public_to_address; use parity_runtime::Executor; use super::acl_storage::AclStorage; use super::key_storage::KeyStorage; @@ -164,7 +164,7 @@ impl DocumentKeyServer for KeyServerImpl { // encrypt document key with requestor public key let encrypted_document_key = stored_document_key - .and_then(|(public, document_key)| crypto::ecies::encrypt(&public, &DEFAULT_MAC, document_key.as_bytes()) + .and_then(|(public, document_key)| crypto::publickey::ecies::encrypt(&public, &DEFAULT_MAC, document_key.as_bytes()) .map_err(|err| Error::Internal(format!("Error encrypting document key: {}", err)))); Box::new(encrypted_document_key) @@ -190,7 +190,7 @@ impl DocumentKeyServer for KeyServerImpl { // encrypt document key with requestor public key let encrypted_document_key = stored_document_key .and_then(|(public, document_key)| - crypto::ecies::encrypt(&public, &DEFAULT_MAC, document_key.decrypted_secret.as_bytes()) + crypto::publickey::ecies::encrypt(&public, &DEFAULT_MAC, document_key.decrypted_secret.as_bytes()) .map_err(|err| Error::Internal(format!("Error encrypting document key: {}", err)))); Box::new(encrypted_document_key) @@ -235,7 +235,7 @@ impl MessageSigner for KeyServerImpl { // encrypt signature with requestor public key let encrypted_signature = combined_signature - .and_then(|(public, combined_signature)| crypto::ecies::encrypt(&public, &DEFAULT_MAC, &combined_signature) + .and_then(|(public, combined_signature)| crypto::publickey::ecies::encrypt(&public, &DEFAULT_MAC, &combined_signature) .map_err(|err| Error::Internal(format!("Error encrypting message signature: {}", err)))); Box::new(encrypted_signature) @@ -261,7 +261,7 @@ impl MessageSigner for KeyServerImpl { // encrypt combined signature with requestor public key let encrypted_signature = signature - .and_then(|(public, signature)| crypto::ecies::encrypt(&public, &DEFAULT_MAC, &*signature) + .and_then(|(public, signature)| crypto::publickey::ecies::encrypt(&public, &DEFAULT_MAC, &*signature) .map_err(|err| Error::Internal(format!("Error encrypting message signature: {}", err)))); Box::new(encrypted_signature) @@ -314,7 +314,7 @@ pub mod tests { use std::collections::BTreeMap; use futures::Future; use crypto::DEFAULT_MAC; - use ethkey::{self, crypto, Secret, Random, Generator, verify_public}; + use crypto::publickey::{Secret, Random, Generator, verify_public}; use acl_storage::DummyAclStorage; use key_storage::KeyStorage; use key_storage::tests::DummyKeyStorage; @@ -489,13 +489,13 @@ pub mod tests { let threshold = 0; let document = Random.generate().unwrap().secret().clone(); let secret = Random.generate().unwrap().secret().clone(); - let signature: Requester = ethkey::sign(&secret, &document).unwrap().into(); + let signature: Requester = crypto::publickey::sign(&secret, &document).unwrap().into(); let generated_key = key_servers[0].generate_document_key( *document, signature.clone(), threshold, ).wait().unwrap(); - let generated_key = crypto::ecies::decrypt(&secret, &DEFAULT_MAC, &generated_key).unwrap(); + let generated_key = crypto::publickey::ecies::decrypt(&secret, &DEFAULT_MAC, &generated_key).unwrap(); // now let's try to retrieve key back for key_server in key_servers.iter() { @@ -503,7 +503,7 @@ pub mod tests { *document, signature.clone(), ).wait().unwrap(); - let retrieved_key = crypto::ecies::decrypt(&secret, &DEFAULT_MAC, &retrieved_key).unwrap(); + let retrieved_key = crypto::publickey::ecies::decrypt(&secret, &DEFAULT_MAC, &retrieved_key).unwrap(); assert_eq!(retrieved_key, generated_key); } drop(runtime); @@ -519,13 +519,13 @@ pub mod tests { // generate document key let document = Random.generate().unwrap().secret().clone(); let secret = Random.generate().unwrap().secret().clone(); - let signature: Requester = ethkey::sign(&secret, &document).unwrap().into(); + let signature: Requester = crypto::publickey::sign(&secret, &document).unwrap().into(); let generated_key = key_servers[0].generate_document_key( *document, signature.clone(), *threshold, ).wait().unwrap(); - let generated_key = crypto::ecies::decrypt(&secret, &DEFAULT_MAC, &generated_key).unwrap(); + let generated_key = crypto::publickey::ecies::decrypt(&secret, &DEFAULT_MAC, &generated_key).unwrap(); // now let's try to retrieve key back for (i, key_server) in key_servers.iter().enumerate() { @@ -533,7 +533,7 @@ pub mod tests { *document, signature.clone(), ).wait().unwrap(); - let retrieved_key = crypto::ecies::decrypt(&secret, &DEFAULT_MAC, &retrieved_key).unwrap(); + let retrieved_key = crypto::publickey::ecies::decrypt(&secret, &DEFAULT_MAC, &retrieved_key).unwrap(); assert_eq!(retrieved_key, generated_key); let key_share = key_storages[i].get(&document).unwrap().unwrap(); @@ -554,7 +554,7 @@ pub mod tests { // generate server key let server_key_id = Random.generate().unwrap().secret().clone(); let requestor_secret = Random.generate().unwrap().secret().clone(); - let signature: Requester = ethkey::sign(&requestor_secret, &server_key_id).unwrap().into(); + let signature: Requester = crypto::publickey::sign(&requestor_secret, &server_key_id).unwrap().into(); let server_public = key_servers[0].generate_key( *server_key_id, signature.clone(), @@ -572,7 +572,7 @@ pub mod tests { // now let's try to retrieve key back for key_server in key_servers.iter() { let retrieved_key = key_server.restore_document_key(*server_key_id, signature.clone()).wait().unwrap(); - let retrieved_key = crypto::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &retrieved_key).unwrap(); + let retrieved_key = crypto::publickey::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &retrieved_key).unwrap(); let retrieved_key = Public::from_slice(&retrieved_key); assert_eq!(retrieved_key, generated_key); } @@ -590,7 +590,7 @@ pub mod tests { // generate server key let server_key_id = Random.generate().unwrap().secret().clone(); let requestor_secret = Random.generate().unwrap().secret().clone(); - let signature: Requester = ethkey::sign(&requestor_secret, &server_key_id).unwrap().into(); + let signature: Requester = crypto::publickey::sign(&requestor_secret, &server_key_id).unwrap().into(); let server_public = key_servers[0].generate_key( *server_key_id, signature.clone(), @@ -604,9 +604,9 @@ pub mod tests { signature, message_hash, ).wait().unwrap(); - let combined_signature = crypto::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &combined_signature).unwrap(); - let signature_c = Secret::from_slice(&combined_signature[..32]).unwrap(); - let signature_s = Secret::from_slice(&combined_signature[32..]).unwrap(); + let combined_signature = crypto::publickey::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &combined_signature).unwrap(); + let signature_c = Secret::copy_from_slice(&combined_signature[..32]).unwrap(); + let signature_s = Secret::copy_from_slice(&combined_signature[32..]).unwrap(); // check signature assert_eq!(math::verify_schnorr_signature(&server_public, &(signature_c, signature_s), &message_hash), Ok(true)); @@ -623,20 +623,20 @@ pub mod tests { let threshold = 0; let document = Random.generate().unwrap().secret().clone(); let secret = Random.generate().unwrap().secret().clone(); - let signature: Requester = ethkey::sign(&secret, &document).unwrap().into(); + let signature: Requester = crypto::publickey::sign(&secret, &document).unwrap().into(); let generated_key = key_servers[0].generate_document_key( *document, signature.clone(), threshold, ).wait().unwrap(); - let generated_key = crypto::ecies::decrypt(&secret, &DEFAULT_MAC, &generated_key).unwrap(); + let generated_key = crypto::publickey::ecies::decrypt(&secret, &DEFAULT_MAC, &generated_key).unwrap(); // remove key from node0 key_storages[0].remove(&document).unwrap(); // now let's try to retrieve key back by requesting it from node0, so that session must be delegated let retrieved_key = key_servers[0].restore_document_key(*document, signature).wait().unwrap(); - let retrieved_key = crypto::ecies::decrypt(&secret, &DEFAULT_MAC, &retrieved_key).unwrap(); + let retrieved_key = crypto::publickey::ecies::decrypt(&secret, &DEFAULT_MAC, &retrieved_key).unwrap(); assert_eq!(retrieved_key, generated_key); drop(runtime); } @@ -650,7 +650,7 @@ pub mod tests { // generate server key let server_key_id = Random.generate().unwrap().secret().clone(); let requestor_secret = Random.generate().unwrap().secret().clone(); - let signature: Requester = ethkey::sign(&requestor_secret, &server_key_id).unwrap().into(); + let signature: Requester = crypto::publickey::sign(&requestor_secret, &server_key_id).unwrap().into(); let server_public = key_servers[0].generate_key(*server_key_id, signature.clone(), threshold).wait().unwrap(); // remove key from node0 @@ -663,9 +663,9 @@ pub mod tests { signature, message_hash, ).wait().unwrap(); - let combined_signature = crypto::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &combined_signature).unwrap(); - let signature_c = Secret::from_slice(&combined_signature[..32]).unwrap(); - let signature_s = Secret::from_slice(&combined_signature[32..]).unwrap(); + let combined_signature = crypto::publickey::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &combined_signature).unwrap(); + let signature_c = Secret::copy_from_slice(&combined_signature[..32]).unwrap(); + let signature_s = Secret::copy_from_slice(&combined_signature[32..]).unwrap(); // check signature assert_eq!(math::verify_schnorr_signature(&server_public, &(signature_c, signature_s), &message_hash), Ok(true)); @@ -681,7 +681,7 @@ pub mod tests { // generate server key let server_key_id = Random.generate().unwrap().secret().clone(); let requestor_secret = Random.generate().unwrap().secret().clone(); - let signature = ethkey::sign(&requestor_secret, &server_key_id).unwrap(); + let signature = crypto::publickey::sign(&requestor_secret, &server_key_id).unwrap(); let server_public = key_servers[0].generate_key( *server_key_id, signature.clone().into(), @@ -698,7 +698,7 @@ pub mod tests { signature.clone().into(), message_hash, ).wait().unwrap(); - let signature = crypto::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &signature).unwrap(); + let signature = crypto::publickey::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &signature).unwrap(); let signature = H520::from_slice(&signature[0..65]); // check signature diff --git a/secret-store/src/key_server_cluster/admin_sessions/key_version_negotiation_session.rs b/secret-store/src/key_server_cluster/admin_sessions/key_version_negotiation_session.rs index 841aa889e5c..2790f9da174 100644 --- a/secret-store/src/key_server_cluster/admin_sessions/key_version_negotiation_session.rs +++ b/secret-store/src/key_server_cluster/admin_sessions/key_version_negotiation_session.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use std::collections::{BTreeSet, BTreeMap}; use ethereum_types::{Address, H256}; -use ethkey::Secret; +use crypto::publickey::Secret; use futures::Oneshot; use parking_lot::Mutex; use key_server_cluster::{Error, SessionId, NodeId, DocumentKeyShare}; @@ -617,7 +617,7 @@ mod tests { use std::sync::Arc; use std::collections::{VecDeque, BTreeMap, BTreeSet}; use ethereum_types::{H512, H160, Address}; - use ethkey::public_to_address; + use crypto::publickey::public_to_address; use key_server_cluster::{NodeId, SessionId, Error, KeyStorage, DummyKeyStorage, DocumentKeyShare, DocumentKeyShareVersion}; use key_server_cluster::math; diff --git a/secret-store/src/key_server_cluster/admin_sessions/servers_set_change_session.rs b/secret-store/src/key_server_cluster/admin_sessions/servers_set_change_session.rs index 5dcc7ea7093..9bc6d1df81f 100644 --- a/secret-store/src/key_server_cluster/admin_sessions/servers_set_change_session.rs +++ b/secret-store/src/key_server_cluster/admin_sessions/servers_set_change_session.rs @@ -20,7 +20,7 @@ use std::collections::btree_map::Entry; use futures::Oneshot; use parking_lot::Mutex; use ethereum_types::H256; -use ethkey::{Public, Signature}; +use crypto::publickey::{Public, Signature}; use key_server_cluster::{Error, NodeId, SessionId, KeyStorage}; use key_server_cluster::math; use key_server_cluster::cluster::Cluster; @@ -1050,7 +1050,7 @@ pub mod tests { use std::sync::Arc; use std::collections::{VecDeque, BTreeMap, BTreeSet}; use ethereum_types::H256; - use ethkey::{Random, Generator, Public, Signature, KeyPair, sign}; + use crypto::publickey::{Random, Generator, Public, Signature, KeyPair, sign}; use key_server_cluster::{NodeId, SessionId, Error, KeyStorage, NodeKeyPair, PlainNodeKeyPair}; use key_server_cluster::cluster_sessions::ClusterSession; use key_server_cluster::cluster::tests::MessageLoop as ClusterMessageLoop; diff --git a/secret-store/src/key_server_cluster/admin_sessions/share_add_session.rs b/secret-store/src/key_server_cluster/admin_sessions/share_add_session.rs index c190396a507..94e6e989379 100644 --- a/secret-store/src/key_server_cluster/admin_sessions/share_add_session.rs +++ b/secret-store/src/key_server_cluster/admin_sessions/share_add_session.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use std::collections::{BTreeSet, BTreeMap}; use ethereum_types::{H256, Address}; -use ethkey::{Public, Secret, Signature}; +use crypto::publickey::{Public, Secret, Signature}; use futures::Oneshot; use parking_lot::Mutex; use key_server_cluster::{Error, SessionId, NodeId, DocumentKeyShare, DocumentKeyShareVersion, KeyStorage}; @@ -888,7 +888,7 @@ impl SessionTransport for IsolatedSessionTransport { #[cfg(test)] pub mod tests { use std::collections::BTreeSet; - use ethkey::{Random, Generator, Public}; + use crypto::publickey::{Random, Generator, Public}; use key_server_cluster::{NodeId, Error, KeyStorage, NodeKeyPair}; use key_server_cluster::cluster::tests::MessageLoop as ClusterMessageLoop; use key_server_cluster::servers_set_change_session::tests::{MessageLoop, AdminSessionAdapter, generate_key}; diff --git a/secret-store/src/key_server_cluster/admin_sessions/share_change_session.rs b/secret-store/src/key_server_cluster/admin_sessions/share_change_session.rs index 18d2671f569..d69c29b30d2 100644 --- a/secret-store/src/key_server_cluster/admin_sessions/share_change_session.rs +++ b/secret-store/src/key_server_cluster/admin_sessions/share_change_session.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use std::collections::{BTreeSet, BTreeMap}; use ethereum_types::H256; -use ethkey::Secret; +use crypto::publickey::Secret; use key_server_cluster::{Error, NodeId, SessionId, ServerKeyId, KeyStorage}; use key_server_cluster::cluster::Cluster; use key_server_cluster::cluster_sessions::ClusterSession; diff --git a/secret-store/src/key_server_cluster/client_sessions/decryption_session.rs b/secret-store/src/key_server_cluster/client_sessions/decryption_session.rs index 46691f58b40..ce6e2a1492f 100644 --- a/secret-store/src/key_server_cluster/client_sessions/decryption_session.rs +++ b/secret-store/src/key_server_cluster/client_sessions/decryption_session.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use futures::Oneshot; use parking_lot::Mutex; use ethereum_types::{Address, H256}; -use ethkey::Secret; +use crypto::publickey::Secret; use key_server_cluster::{Error, AclStorage, DocumentKeyShare, NodeId, SessionId, Requester, EncryptedDocumentKeyShadow, SessionMeta}; use key_server_cluster::cluster::Cluster; @@ -846,7 +846,7 @@ mod tests { use std::sync::Arc; use std::collections::{BTreeMap, VecDeque}; use acl_storage::DummyAclStorage; - use ethkey::{self, KeyPair, Random, Generator, Public, Secret, public_to_address}; + use crypto::publickey::{KeyPair, Random, Generator, Public, Secret, public_to_address}; use key_server_cluster::{NodeId, DocumentKeyShare, DocumentKeyShareVersion, SessionId, Requester, Error, EncryptedDocumentKeyShadow, SessionMeta}; use key_server_cluster::cluster::tests::DummyCluster; @@ -906,7 +906,7 @@ mod tests { cluster }).collect(); let requester = Random.generate().unwrap(); - let signature = Some(ethkey::sign(requester.secret(), &SessionId::default()).unwrap()); + let signature = Some(crypto::publickey::sign(requester.secret(), &SessionId::default()).unwrap()); let sessions: Vec<_> = (0..5).map(|i| SessionImpl::new(SessionParams { meta: SessionMeta { id: session_id.clone(), @@ -997,7 +997,7 @@ mod tests { acl_storage: Arc::new(DummyAclStorage::default()), cluster: Arc::new(DummyCluster::new(self_node_id.clone())), nonce: 0, - }, Some(Requester::Signature(ethkey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()))) { + }, Some(Requester::Signature(crypto::publickey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()))) { Ok(_) => (), _ => panic!("unexpected"), } @@ -1021,7 +1021,7 @@ mod tests { cluster: Arc::new(DummyCluster::new(self_node_id.clone())), nonce: 0, }, Some(Requester::Signature( - ethkey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap() + crypto::publickey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap() ))).unwrap().0; assert_eq!(session.initialize(Default::default(), Default::default(), false, false), Err(Error::InvalidMessage)); } @@ -1058,7 +1058,7 @@ mod tests { cluster: Arc::new(DummyCluster::new(self_node_id.clone())), nonce: 0, }, Some(Requester::Signature( - ethkey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap() + crypto::publickey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap() ))).unwrap().0; assert_eq!(session.initialize(Default::default(), Default::default(), false, false), Err(Error::ConsensusUnreachable)); } @@ -1080,7 +1080,7 @@ mod tests { session_nonce: 0, origin: None, message: message::ConsensusMessage::InitializeConsensusSession(message::InitializeConsensusSession { - requester: Requester::Signature(ethkey::sign( + requester: Requester::Signature(crypto::publickey::sign( Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(), version: Default::default(), }), @@ -1096,7 +1096,7 @@ mod tests { session_nonce: 0, origin: None, message: message::ConsensusMessage::InitializeConsensusSession(message::InitializeConsensusSession { - requester: Requester::Signature(ethkey::sign(Random.generate().unwrap().secret(), + requester: Requester::Signature(crypto::publickey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(), version: Default::default(), }), @@ -1121,7 +1121,7 @@ mod tests { session_nonce: 0, origin: None, message: message::ConsensusMessage::InitializeConsensusSession(message::InitializeConsensusSession { - requester: Requester::Signature(ethkey::sign(Random.generate().unwrap().secret(), + requester: Requester::Signature(crypto::publickey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(), version: Default::default(), }), @@ -1314,9 +1314,9 @@ mod tests { assert!(decrypted_secret.decrypt_shadows.is_some()); // check that KS client is able to restore original secret use crypto::DEFAULT_MAC; - use ethkey::crypto::ecies::decrypt; + use crypto::publickey::ecies::decrypt; let decrypt_shadows: Vec<_> = decrypted_secret.decrypt_shadows.unwrap().into_iter() - .map(|c| Secret::from_slice(&decrypt(key_pair.secret(), &DEFAULT_MAC, &c).unwrap()).unwrap()) + .map(|c| Secret::copy_from_slice(&decrypt(key_pair.secret(), &DEFAULT_MAC, &c).unwrap()).unwrap()) .collect(); let decrypted_secret = math::decrypt_with_shadow_coefficients(decrypted_secret.decrypted_secret, decrypted_secret.common_point.unwrap(), decrypt_shadows).unwrap(); assert_eq!(decrypted_secret, H512::from_str(SECRET_PLAIN).unwrap()); @@ -1458,11 +1458,11 @@ mod tests { // 4 nodes must be able to recover original secret use crypto::DEFAULT_MAC; - use ethkey::crypto::ecies::decrypt; + use crypto::publickey::ecies::decrypt; let result = sessions[0].decrypted_secret().unwrap().unwrap(); assert_eq!(3, sessions.iter().skip(1).filter(|s| s.decrypted_secret() == Some(Ok(result.clone()))).count()); let decrypt_shadows: Vec<_> = result.decrypt_shadows.unwrap().into_iter() - .map(|c| Secret::from_slice(&decrypt(key_pair.secret(), &DEFAULT_MAC, &c).unwrap()).unwrap()) + .map(|c| Secret::copy_from_slice(&decrypt(key_pair.secret(), &DEFAULT_MAC, &c).unwrap()).unwrap()) .collect(); let decrypted_secret = math::decrypt_with_shadow_coefficients(result.decrypted_secret, result.common_point.unwrap(), decrypt_shadows).unwrap(); assert_eq!(decrypted_secret, H512::from_str(SECRET_PLAIN).unwrap()); diff --git a/secret-store/src/key_server_cluster/client_sessions/encryption_session.rs b/secret-store/src/key_server_cluster/client_sessions/encryption_session.rs index 46181001394..6d0f52540c2 100644 --- a/secret-store/src/key_server_cluster/client_sessions/encryption_session.rs +++ b/secret-store/src/key_server_cluster/client_sessions/encryption_session.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use futures::Oneshot; use parking_lot::Mutex; use ethereum_types::Address; -use ethkey::Public; +use crypto::publickey::Public; use key_server_cluster::{Error, NodeId, SessionId, Requester, KeyStorage, DocumentKeyShare, ServerKeyId}; use key_server_cluster::cluster::Cluster; diff --git a/secret-store/src/key_server_cluster/client_sessions/generation_session.rs b/secret-store/src/key_server_cluster/client_sessions/generation_session.rs index 806173854a3..b81cbfeac92 100644 --- a/secret-store/src/key_server_cluster/client_sessions/generation_session.rs +++ b/secret-store/src/key_server_cluster/client_sessions/generation_session.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use futures::Oneshot; use parking_lot::Mutex; use ethereum_types::Address; -use ethkey::{Public, Secret}; +use crypto::publickey::{Public, Secret}; use key_server_cluster::{Error, NodeId, SessionId, KeyStorage, DocumentKeyShare, DocumentKeyShareVersion}; use key_server_cluster::math; use key_server_cluster::cluster::Cluster; @@ -951,7 +951,7 @@ fn check_threshold(threshold: usize, nodes: &BTreeSet) -> Result<(), Err pub mod tests { use std::sync::Arc; use ethereum_types::H256; - use ethkey::{Random, Generator, KeyPair, Secret}; + use crypto::publickey::{Random, Generator, KeyPair, Secret}; use key_server_cluster::{NodeId, Error, KeyStorage}; use key_server_cluster::message::{self, Message, GenerationMessage, KeysDissemination, PublicKeyShare, ConfirmInitialization}; diff --git a/secret-store/src/key_server_cluster/client_sessions/signing_session_ecdsa.rs b/secret-store/src/key_server_cluster/client_sessions/signing_session_ecdsa.rs index 4f913a53602..70f40c3d890 100644 --- a/secret-store/src/key_server_cluster/client_sessions/signing_session_ecdsa.rs +++ b/secret-store/src/key_server_cluster/client_sessions/signing_session_ecdsa.rs @@ -19,7 +19,7 @@ use std::collections::btree_map::Entry; use std::sync::Arc; use futures::Oneshot; use parking_lot::Mutex; -use ethkey::{Public, Secret, Signature, sign}; +use crypto::publickey::{Public, Secret, Signature, sign}; use ethereum_types::H256; use key_server_cluster::{Error, NodeId, SessionId, SessionMeta, AclStorage, DocumentKeyShare, Requester}; use key_server_cluster::cluster::{Cluster}; @@ -1070,7 +1070,7 @@ impl JobTransport for SigningJobTransport { mod tests { use std::sync::Arc; use ethereum_types::H256; - use ethkey::{self, Random, Generator, Public, verify_public, public_to_address}; + use crypto::publickey::{Random, Generator, Public, verify_public, public_to_address}; use key_server_cluster::{SessionId, Error, KeyStorage}; use key_server_cluster::cluster::tests::{MessageLoop as ClusterMessageLoop}; use key_server_cluster::signing_session_ecdsa::SessionImpl; @@ -1090,7 +1090,7 @@ mod tests { pub fn init_with_version(self, key_version: Option) -> Result<(Self, Public, H256), Error> { let message_hash = H256::random(); let requester = Random.generate().unwrap(); - let signature = ethkey::sign(requester.secret(), &SessionId::default()).unwrap(); + let signature = crypto::publickey::sign(requester.secret(), &SessionId::default()).unwrap(); self.0.cluster(0).client() .new_ecdsa_signing_session(Default::default(), signature.into(), key_version, message_hash) .map(|_| (self, *requester.public(), message_hash)) diff --git a/secret-store/src/key_server_cluster/client_sessions/signing_session_schnorr.rs b/secret-store/src/key_server_cluster/client_sessions/signing_session_schnorr.rs index ae0aa69d462..023e5132068 100644 --- a/secret-store/src/key_server_cluster/client_sessions/signing_session_schnorr.rs +++ b/secret-store/src/key_server_cluster/client_sessions/signing_session_schnorr.rs @@ -18,7 +18,7 @@ use std::collections::BTreeSet; use std::sync::Arc; use futures::Oneshot; use parking_lot::Mutex; -use ethkey::{Public, Secret}; +use crypto::publickey::{Public, Secret}; use ethereum_types::H256; use key_server_cluster::{Error, NodeId, SessionId, Requester, SessionMeta, AclStorage, DocumentKeyShare}; use key_server_cluster::cluster::{Cluster}; @@ -819,7 +819,7 @@ mod tests { use std::str::FromStr; use std::collections::BTreeMap; use ethereum_types::{Address, H256}; - use ethkey::{self, Random, Generator, Public, Secret, public_to_address}; + use crypto::publickey::{Random, Generator, Public, Secret, public_to_address}; use acl_storage::DummyAclStorage; use key_server_cluster::{SessionId, Requester, SessionMeta, Error, KeyStorage}; use key_server_cluster::cluster::tests::MessageLoop as ClusterMessageLoop; @@ -842,7 +842,7 @@ mod tests { } pub fn into_session(&self, at_node: usize) -> SessionImpl { - let requester = Some(Requester::Signature(ethkey::sign(Random.generate().unwrap().secret(), + let requester = Some(Requester::Signature(crypto::publickey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap())); SessionImpl::new(SessionParams { meta: SessionMeta { @@ -864,7 +864,7 @@ mod tests { pub fn init_with_version(self, key_version: Option) -> Result<(Self, Public, H256), Error> { let message_hash = H256::random(); let requester = Random.generate().unwrap(); - let signature = ethkey::sign(requester.secret(), &SessionId::default()).unwrap(); + let signature = crypto::publickey::sign(requester.secret(), &SessionId::default()).unwrap(); self.0.cluster(0).client().new_schnorr_signing_session( Default::default(), signature.into(), diff --git a/secret-store/src/key_server_cluster/cluster.rs b/secret-store/src/key_server_cluster/cluster.rs index f1d34709119..44e6a22fed4 100644 --- a/secret-store/src/key_server_cluster/cluster.rs +++ b/secret-store/src/key_server_cluster/cluster.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use std::collections::{BTreeMap, BTreeSet}; use parking_lot::RwLock; -use ethkey::{Public, Signature, Random, Generator}; +use crypto::publickey::{Public, Signature, Random, Generator}; use ethereum_types::{Address, H256}; use parity_runtime::Executor; use key_server_cluster::{Error, NodeId, SessionId, Requester, AclStorage, KeyStorage, KeyServerSet, NodeKeyPair}; @@ -655,7 +655,7 @@ pub mod tests { use futures::Future; use parking_lot::{Mutex, RwLock}; use ethereum_types::{Address, H256}; - use ethkey::{Random, Generator, Public, Signature, sign}; + use crypto::publickey::{Random, Generator, Public, Signature, sign}; use key_server_cluster::{NodeId, SessionId, Requester, Error, DummyAclStorage, DummyKeyStorage, MapKeyServerSet, PlainNodeKeyPair, NodeKeyPair}; use key_server_cluster::message::Message; diff --git a/secret-store/src/key_server_cluster/cluster_connections_net.rs b/secret-store/src/key_server_cluster/cluster_connections_net.rs index 155c0604d23..b402d001875 100644 --- a/secret-store/src/key_server_cluster/cluster_connections_net.rs +++ b/secret-store/src/key_server_cluster/cluster_connections_net.rs @@ -25,7 +25,7 @@ use parking_lot::{Mutex, RwLock}; use tokio::net::{TcpListener, TcpStream}; use tokio::timer::{Interval, timeout::Error as TimeoutError}; use tokio_io::IoFuture; -use ethkey::KeyPair; +use crypto::publickey::KeyPair; use parity_runtime::Executor; use key_server_cluster::{Error, NodeId, ClusterConfiguration, NodeKeyPair}; use key_server_cluster::cluster_connections::{ConnectionProvider, Connection, ConnectionManager}; diff --git a/secret-store/src/key_server_cluster/cluster_sessions.rs b/secret-store/src/key_server_cluster/cluster_sessions.rs index 3db72395d28..1e5a046b993 100644 --- a/secret-store/src/key_server_cluster/cluster_sessions.rs +++ b/secret-store/src/key_server_cluster/cluster_sessions.rs @@ -21,7 +21,7 @@ use std::collections::{VecDeque, BTreeMap, BTreeSet}; use futures::{oneshot, Oneshot, Complete, Future}; use parking_lot::{Mutex, RwLock, Condvar}; use ethereum_types::H256; -use ethkey::Secret; +use crypto::publickey::Secret; use key_server_cluster::{Error, NodeId, SessionId, NodeKeyPair}; use key_server_cluster::cluster::{Cluster, ClusterConfiguration, ClusterView}; use key_server_cluster::cluster_connections::ConnectionProvider; @@ -668,7 +668,7 @@ pub fn create_cluster_view(self_key_pair: Arc, connections: Arc mod tests { use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; - use ethkey::{Random, Generator}; + use crypto::publickey::{Random, Generator}; use key_server_cluster::{Error, DummyAclStorage, DummyKeyStorage, MapKeyServerSet, PlainNodeKeyPair}; use key_server_cluster::cluster::ClusterConfiguration; use key_server_cluster::connection_trigger::SimpleServersSetChangeSessionCreatorConnector; diff --git a/secret-store/src/key_server_cluster/cluster_sessions_creator.rs b/secret-store/src/key_server_cluster/cluster_sessions_creator.rs index d0559be4852..0bdf0ccd481 100644 --- a/secret-store/src/key_server_cluster/cluster_sessions_creator.rs +++ b/secret-store/src/key_server_cluster/cluster_sessions_creator.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::collections::BTreeMap; use parking_lot::RwLock; -use ethkey::Public; +use crypto::publickey::Public; use key_server_cluster::{Error, NodeId, SessionId, Requester, AclStorage, KeyStorage, DocumentKeyShare, SessionMeta}; use key_server_cluster::cluster::{Cluster, ClusterConfiguration}; use key_server_cluster::connection_trigger::ServersSetChangeSessionCreatorConnector; diff --git a/secret-store/src/key_server_cluster/connection_trigger.rs b/secret-store/src/key_server_cluster/connection_trigger.rs index d8ad995a922..40d415dffe0 100644 --- a/secret-store/src/key_server_cluster/connection_trigger.rs +++ b/secret-store/src/key_server_cluster/connection_trigger.rs @@ -19,7 +19,7 @@ use std::collections::btree_map::Entry; use std::net::SocketAddr; use std::sync::Arc; use ethereum_types::H256; -use ethkey::Public; +use crypto::publickey::Public; use key_server_cluster::{KeyServerSet, KeyServerSetSnapshot}; use key_server_cluster::cluster::{ClusterConfiguration, ServersSetChangeParams}; use key_server_cluster::cluster_sessions::AdminSession; @@ -215,7 +215,7 @@ fn select_nodes_to_disconnect(current_set: &BTreeMap, new_se mod tests { use std::collections::BTreeSet; use std::sync::Arc; - use ethkey::{Random, Generator}; + use crypto::publickey::{Random, Generator}; use key_server_cluster::{MapKeyServerSet, PlainNodeKeyPair, KeyServerSetSnapshot, KeyServerSetMigration}; use key_server_cluster::cluster_connections_net::NetConnectionsContainer; use super::{Maintain, TriggerConnections, ConnectionsAction, ConnectionTrigger, SimpleConnectionTrigger, diff --git a/secret-store/src/key_server_cluster/connection_trigger_with_migration.rs b/secret-store/src/key_server_cluster/connection_trigger_with_migration.rs index 00ea42571c0..92db652d5ec 100644 --- a/secret-store/src/key_server_cluster/connection_trigger_with_migration.rs +++ b/secret-store/src/key_server_cluster/connection_trigger_with_migration.rs @@ -18,7 +18,7 @@ use std::collections::{BTreeSet, BTreeMap}; use std::net::SocketAddr; use std::sync::Arc; use ethereum_types::H256; -use ethkey::Public; +use crypto::publickey::Public; use parking_lot::Mutex; use key_server_cluster::{KeyServerSet, KeyServerSetSnapshot, KeyServerSetMigration, is_migration_required}; use key_server_cluster::cluster::{ClusterConfiguration, ServersSetChangeParams}; diff --git a/secret-store/src/key_server_cluster/io/handshake.rs b/secret-store/src/key_server_cluster/io/handshake.rs index b266d8681e1..a09e035e43a 100644 --- a/secret-store/src/key_server_cluster/io/handshake.rs +++ b/secret-store/src/key_server_cluster/io/handshake.rs @@ -37,8 +37,8 @@ use std::sync::Arc; use std::collections::BTreeSet; use futures::{Future, Poll, Async}; use tokio_io::{AsyncRead, AsyncWrite}; -use ethkey::crypto::ecdh::agree; -use ethkey::{Random, Generator, KeyPair, Public, Signature, verify_public, sign, recover}; +use crypto::publickey::ecdh::agree; +use crypto::publickey::{Random, Generator, KeyPair, Public, Signature, verify_public, sign, recover}; use ethereum_types::H256; use key_server_cluster::{NodeId, Error, NodeKeyPair}; use key_server_cluster::message::{Message, ClusterMessage, NodePublicKey, NodePrivateKeySignature}; @@ -317,7 +317,7 @@ mod tests { use std::sync::Arc; use std::collections::BTreeSet; use futures::Future; - use ethkey::{Random, Generator, sign}; + use crypto::publickey::{Random, Generator, sign}; use ethereum_types::H256; use key_server_cluster::PlainNodeKeyPair; use key_server_cluster::io::message::tests::TestIo; diff --git a/secret-store/src/key_server_cluster/io/message.rs b/secret-store/src/key_server_cluster/io/message.rs index 5707bd809f2..b45e4f062e3 100644 --- a/secret-store/src/key_server_cluster/io/message.rs +++ b/secret-store/src/key_server_cluster/io/message.rs @@ -19,9 +19,9 @@ use std::u16; use std::ops::Deref; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use serde_json; -use ethkey::crypto::ecies; -use ethkey::{Secret, KeyPair}; -use ethkey::math::curve_order; +use crypto::publickey::ecies; +use crypto::publickey::{Secret, KeyPair}; +use crypto::publickey::ec_math_utils::CURVE_ORDER; use ethereum_types::{H256, U256, BigEndianHash}; use key_server_cluster::Error; use key_server_cluster::message::{Message, ClusterMessage, GenerationMessage, EncryptionMessage, DecryptionMessage, @@ -258,7 +258,7 @@ pub fn fix_shared_key(shared_secret: &Secret) -> Result { // => let's do it manually let shared_secret: H256 = (**shared_secret).into(); let shared_secret: U256 = shared_secret.into_uint(); - let shared_secret: H256 = BigEndianHash::from_uint(&(shared_secret % curve_order())); + let shared_secret: H256 = BigEndianHash::from_uint(&(shared_secret % *CURVE_ORDER)); let shared_key_pair = KeyPair::from_secret_slice(shared_secret.as_bytes())?; Ok(shared_key_pair) } @@ -305,8 +305,8 @@ pub mod tests { use std::io; use futures::Poll; use tokio_io::{AsyncRead, AsyncWrite}; - use ethkey::{Random, Generator, KeyPair}; - use ethkey::crypto::ecdh::agree; + use crypto::publickey::{Random, Generator, KeyPair}; + use crypto::publickey::ecdh::agree; use key_server_cluster::Error; use key_server_cluster::message::Message; use super::{MESSAGE_HEADER_SIZE, CURRENT_HEADER_VERSION, MessageHeader, fix_shared_key, encrypt_message, diff --git a/secret-store/src/key_server_cluster/io/read_message.rs b/secret-store/src/key_server_cluster/io/read_message.rs index e16de57a36e..0549dd23a67 100644 --- a/secret-store/src/key_server_cluster/io/read_message.rs +++ b/secret-store/src/key_server_cluster/io/read_message.rs @@ -17,7 +17,7 @@ use std::io; use futures::{Poll, Future, Async}; use tokio_io::AsyncRead; -use ethkey::KeyPair; +use crypto::publickey::KeyPair; use key_server_cluster::Error; use key_server_cluster::message::Message; use key_server_cluster::io::{read_header, ReadHeader, read_payload, read_encrypted_payload, ReadPayload}; diff --git a/secret-store/src/key_server_cluster/io/read_payload.rs b/secret-store/src/key_server_cluster/io/read_payload.rs index 9f3a47f6624..9fbde6815f5 100644 --- a/secret-store/src/key_server_cluster/io/read_payload.rs +++ b/secret-store/src/key_server_cluster/io/read_payload.rs @@ -18,7 +18,7 @@ use std::io; use futures::{Poll, Future}; use tokio_io::AsyncRead; use tokio_io::io::{read_exact, ReadExact}; -use ethkey::KeyPair; +use crypto::publickey::KeyPair; use key_server_cluster::Error; use key_server_cluster::message::Message; use key_server_cluster::io::message::{MessageHeader, deserialize_message, decrypt_message}; diff --git a/secret-store/src/key_server_cluster/io/write_message.rs b/secret-store/src/key_server_cluster/io/write_message.rs index 15823730a24..771451e2d89 100644 --- a/secret-store/src/key_server_cluster/io/write_message.rs +++ b/secret-store/src/key_server_cluster/io/write_message.rs @@ -18,7 +18,7 @@ use std::io; use futures::{Future, Poll}; use tokio_io::AsyncWrite; use tokio_io::io::{WriteAll, write_all}; -use ethkey::KeyPair; +use crypto::publickey::KeyPair; use key_server_cluster::message::Message; use key_server_cluster::io::{serialize_message, encrypt_message}; diff --git a/secret-store/src/key_server_cluster/jobs/consensus_session.rs b/secret-store/src/key_server_cluster/jobs/consensus_session.rs index 7f293387084..597484321f8 100644 --- a/secret-store/src/key_server_cluster/jobs/consensus_session.rs +++ b/secret-store/src/key_server_cluster/jobs/consensus_session.rs @@ -367,7 +367,7 @@ impl) -> Error { pub mod tests { use std::collections::{VecDeque, BTreeMap, BTreeSet}; use parking_lot::Mutex; - use ethkey::Public; + use crypto::publickey::Public; use key_server_cluster::{Error, NodeId, SessionId, SessionMeta}; use super::{JobPartialResponseAction, JobPartialRequestAction, JobExecutor, JobTransport, JobSession, JobSessionState}; diff --git a/secret-store/src/key_server_cluster/jobs/servers_set_change_access_job.rs b/secret-store/src/key_server_cluster/jobs/servers_set_change_access_job.rs index a37e0749972..e31add62ee7 100644 --- a/secret-store/src/key_server_cluster/jobs/servers_set_change_access_job.rs +++ b/secret-store/src/key_server_cluster/jobs/servers_set_change_access_job.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use std::collections::{BTreeSet, BTreeMap}; -use ethkey::{Public, Signature, recover}; +use crypto::publickey::{Public, Signature, recover}; use tiny_keccak::Keccak; use key_server_cluster::{Error, NodeId, SessionId}; use key_server_cluster::message::{InitializeConsensusSessionWithServersSet, InitializeConsensusSessionOfShareAdd}; diff --git a/secret-store/src/key_server_cluster/jobs/signing_job_ecdsa.rs b/secret-store/src/key_server_cluster/jobs/signing_job_ecdsa.rs index 0628b1e75cb..9fa8959b3fe 100644 --- a/secret-store/src/key_server_cluster/jobs/signing_job_ecdsa.rs +++ b/secret-store/src/key_server_cluster/jobs/signing_job_ecdsa.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use std::collections::{BTreeSet, BTreeMap}; -use ethkey::{Public, Secret, Signature}; +use crypto::publickey::{Public, Secret, Signature}; use ethereum_types::H256; use key_server_cluster::{Error, NodeId, DocumentKeyShare}; use key_server_cluster::math; @@ -33,7 +33,7 @@ pub struct EcdsaSigningJob { nonce_public: Public, /// Request id. request_id: Option, - /// + /// ECDSA reversed-nonce coefficient inversed_nonce_coeff: Option, /// Message hash. message_hash: Option, @@ -43,7 +43,7 @@ pub struct EcdsaSigningJob { pub struct EcdsaPartialSigningRequest { /// Request id. pub id: Secret, - /// + /// ECDSA reversed-nonce coefficient pub inversed_nonce_coeff: Secret, /// Message hash to sign. pub message_hash: H256, diff --git a/secret-store/src/key_server_cluster/jobs/signing_job_schnorr.rs b/secret-store/src/key_server_cluster/jobs/signing_job_schnorr.rs index 7e41dce47ce..31fc1b8c7c2 100644 --- a/secret-store/src/key_server_cluster/jobs/signing_job_schnorr.rs +++ b/secret-store/src/key_server_cluster/jobs/signing_job_schnorr.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use std::collections::{BTreeSet, BTreeMap}; -use ethkey::{Public, Secret}; +use crypto::publickey::{Public, Secret}; use ethereum_types::H256; use key_server_cluster::{Error, NodeId, DocumentKeyShare}; use key_server_cluster::math; diff --git a/secret-store/src/key_server_cluster/math.rs b/secret-store/src/key_server_cluster/math.rs index 99340e492ff..3ba0298d530 100644 --- a/secret-store/src/key_server_cluster/math.rs +++ b/secret-store/src/key_server_cluster/math.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use ethkey::{Public, Secret, Signature, Random, Generator, math}; +use crypto::publickey::{Public, Secret, Signature, Random, Generator, ec_math_utils}; use ethereum_types::{H256, U256, BigEndianHash}; use hash::keccak; use key_server_cluster::Error; @@ -36,7 +36,7 @@ pub fn zero_scalar() -> Secret { /// Convert hash to EC scalar (modulo curve order). pub fn to_scalar(hash: H256) -> Result { let scalar: U256 = hash.into_uint(); - let scalar: H256 = BigEndianHash::from_uint(&(scalar % math::curve_order())); + let scalar: H256 = BigEndianHash::from_uint(&(scalar % *ec_math_utils::CURVE_ORDER)); let scalar = Secret::from(scalar.0); scalar.check_validity()?; Ok(scalar) @@ -66,7 +66,7 @@ fn public_y(public: &Public) -> H256 { pub fn compute_public_sum<'a, I>(mut publics: I) -> Result where I: Iterator { let mut sum = publics.next().expect("compute_public_sum is called when there's at least one public; qed").clone(); while let Some(public) = publics.next() { - math::public_add(&mut sum, &public)?; + ec_math_utils::public_add(&mut sum, &public)?; } Ok(sum) } @@ -113,7 +113,7 @@ pub fn compute_shadow_mul<'a, I>(coeff: &Secret, self_secret: &Secret, mut other /// Update point by multiplying to random scalar pub fn update_random_point(point: &mut Public) -> Result<(), Error> { - Ok(math::public_mul_secret(point, &generate_random_scalar()?)?) + Ok(ec_math_utils::public_mul_secret(point, &generate_random_scalar()?)?) } /// Generate random polynom of threshold degree @@ -153,14 +153,14 @@ pub fn public_values_generation(threshold: usize, derived_point: &Public, polyno for i in 0..threshold + 1 { let coeff1 = &polynom1[i]; - let mut multiplication1 = math::generation_point(); - math::public_mul_secret(&mut multiplication1, &coeff1)?; + let mut multiplication1 = ec_math_utils::generation_point(); + ec_math_utils::public_mul_secret(&mut multiplication1, &coeff1)?; let coeff2 = &polynom2[i]; let mut multiplication2 = derived_point.clone(); - math::public_mul_secret(&mut multiplication2, &coeff2)?; + ec_math_utils::public_mul_secret(&mut multiplication2, &coeff2)?; - math::public_add(&mut multiplication1, &multiplication2)?; + ec_math_utils::public_add(&mut multiplication1, &multiplication2)?; publics.push(multiplication1); } @@ -172,13 +172,13 @@ pub fn public_values_generation(threshold: usize, derived_point: &Public, polyno /// Check keys passed by other participants. pub fn keys_verification(threshold: usize, derived_point: &Public, number_id: &Secret, secret1: &Secret, secret2: &Secret, publics: &[Public]) -> Result { // calculate left part - let mut multiplication1 = math::generation_point(); - math::public_mul_secret(&mut multiplication1, secret1)?; + let mut multiplication1 = ec_math_utils::generation_point(); + ec_math_utils::public_mul_secret(&mut multiplication1, secret1)?; let mut multiplication2 = derived_point.clone(); - math::public_mul_secret(&mut multiplication2, secret2)?; + ec_math_utils::public_mul_secret(&mut multiplication2, secret2)?; - math::public_add(&mut multiplication1, &multiplication2)?; + ec_math_utils::public_add(&mut multiplication1, &multiplication2)?; let left = multiplication1; // calculate right part @@ -188,9 +188,9 @@ pub fn keys_verification(threshold: usize, derived_point: &Public, number_id: &S secret_pow.pow(i)?; let mut public_k = publics[i].clone(); - math::public_mul_secret(&mut public_k, &secret_pow)?; + ec_math_utils::public_mul_secret(&mut public_k, &secret_pow)?; - math::public_add(&mut right, &public_k)?; + ec_math_utils::public_add(&mut right, &public_k)?; } Ok(left == right) @@ -213,8 +213,8 @@ pub fn compute_secret_share<'a, I>(secret_values: I) -> Result wh /// Compute public key share. pub fn compute_public_share(self_secret_value: &Secret) -> Result { - let mut public_share = math::generation_point(); - math::public_mul_secret(&mut public_share, self_secret_value)?; + let mut public_share = ec_math_utils::generation_point(); + ec_math_utils::public_mul_secret(&mut public_share, self_secret_value)?; Ok(public_share) } @@ -256,13 +256,13 @@ pub fn encrypt_secret(secret: &Public, joint_public: &Public) -> Result(access_key: &Secret, common_point: joint_shadow.mul(access_key)?; let mut joint_shadow_point = common_point.clone(); - math::public_mul_secret(&mut joint_shadow_point, &joint_shadow)?; + ec_math_utils::public_mul_secret(&mut joint_shadow_point, &joint_shadow)?; Ok(joint_shadow_point) } @@ -318,13 +318,13 @@ pub fn decrypt_with_joint_shadow(threshold: usize, access_key: &Secret, encrypte inv_access_key.inv()?; let mut mul = joint_shadow_point.clone(); - math::public_mul_secret(&mut mul, &inv_access_key)?; + ec_math_utils::public_mul_secret(&mut mul, &inv_access_key)?; let mut decrypted_point = encrypted_point.clone(); if threshold % 2 != 0 { - math::public_add(&mut decrypted_point, &mul)?; + ec_math_utils::public_add(&mut decrypted_point, &mul)?; } else { - math::public_sub(&mut decrypted_point, &mul)?; + ec_math_utils::public_sub(&mut decrypted_point, &mul)?; } Ok(decrypted_point) @@ -335,7 +335,7 @@ pub fn make_common_shadow_point(threshold: usize, mut common_point: Public) -> R if threshold % 2 != 1 { Ok(common_point) } else { - math::public_negate(&mut common_point)?; + ec_math_utils::public_negate(&mut common_point)?; Ok(common_point) } } @@ -344,8 +344,8 @@ pub fn make_common_shadow_point(threshold: usize, mut common_point: Public) -> R #[cfg(test)] pub fn decrypt_with_shadow_coefficients(mut decrypted_shadow: Public, mut common_shadow_point: Public, shadow_coefficients: Vec) -> Result { let shadow_coefficients_sum = compute_secret_sum(shadow_coefficients.iter())?; - math::public_mul_secret(&mut common_shadow_point, &shadow_coefficients_sum)?; - math::public_add(&mut decrypted_shadow, &common_shadow_point)?; + ec_math_utils::public_mul_secret(&mut common_shadow_point, &shadow_coefficients_sum)?; + ec_math_utils::public_add(&mut decrypted_shadow, &common_shadow_point)?; Ok(decrypted_shadow) } @@ -353,10 +353,10 @@ pub fn decrypt_with_shadow_coefficients(mut decrypted_shadow: Public, mut common #[cfg(test)] pub fn decrypt_with_joint_secret(encrypted_point: &Public, common_point: &Public, joint_secret: &Secret) -> Result { let mut common_point_mul = common_point.clone(); - math::public_mul_secret(&mut common_point_mul, joint_secret)?; + ec_math_utils::public_mul_secret(&mut common_point_mul, joint_secret)?; let mut decrypted_point = encrypted_point.clone(); - math::public_sub(&mut decrypted_point, &common_point_mul)?; + ec_math_utils::public_sub(&mut decrypted_point, &common_point_mul)?; Ok(decrypted_point) } @@ -417,8 +417,8 @@ pub fn compute_schnorr_signature<'a, I>(signature_shares: I) -> Result Result<(Secret, Secret), Error> { - let mut nonce_public = math::generation_point(); - math::public_mul_secret(&mut nonce_public, &nonce).unwrap(); + let mut nonce_public = ec_math_utils::generation_point(); + ec_math_utils::public_mul_secret(&mut nonce_public, &nonce).unwrap(); let combined_hash = combine_message_hash_with_public(message_hash, &nonce_public)?; @@ -433,11 +433,11 @@ pub fn local_compute_schnorr_signature(nonce: &Secret, secret: &Secret, message_ /// Verify Schnorr signature as described in https://en.wikipedia.org/wiki/Schnorr_signature#Verifying. #[cfg(test)] pub fn verify_schnorr_signature(public: &Public, signature: &(Secret, Secret), message_hash: &H256) -> Result { - let mut addendum = math::generation_point(); - math::public_mul_secret(&mut addendum, &signature.1)?; + let mut addendum = ec_math_utils::generation_point(); + ec_math_utils::public_mul_secret(&mut addendum, &signature.1)?; let mut nonce_public = public.clone(); - math::public_mul_secret(&mut nonce_public, &signature.0)?; - math::public_add(&mut nonce_public, &addendum)?; + ec_math_utils::public_mul_secret(&mut nonce_public, &signature.0)?; + ec_math_utils::public_add(&mut nonce_public, &addendum)?; let combined_hash = combine_message_hash_with_public(message_hash, &nonce_public)?; Ok(combined_hash == signature.0) @@ -486,11 +486,10 @@ pub fn serialize_ecdsa_signature(nonce_public: &Public, signature_r: Secret, mut }; // fix high S - let curve_order = math::curve_order(); - let curve_order_half = curve_order / 2; + let curve_order_half = *ec_math_utils::CURVE_ORDER / 2; let s_numeric: U256 = (*signature_s).into_uint(); if s_numeric > curve_order_half { - let signature_s_hash: H256 = BigEndianHash::from_uint(&(curve_order - s_numeric)); + let signature_s_hash: H256 = BigEndianHash::from_uint(&(*ec_math_utils::CURVE_ORDER - s_numeric)); signature_s = signature_s_hash.into(); signature_v ^= 1; } @@ -534,7 +533,7 @@ pub fn compute_ecdsa_inversed_secret_coeff_from_shares(t: usize, id_numbers: &[S #[cfg(test)] pub mod tests { use std::iter::once; - use ethkey::{KeyPair, recover, verify_public}; + use crypto::publickey::{KeyPair, recover, verify_public}; use super::*; #[derive(Clone)] diff --git a/secret-store/src/key_server_cluster/message.rs b/secret-store/src/key_server_cluster/message.rs index 98520564fe8..1f21a7caf14 100644 --- a/secret-store/src/key_server_cluster/message.rs +++ b/secret-store/src/key_server_cluster/message.rs @@ -16,7 +16,7 @@ use std::fmt; use std::collections::{BTreeSet, BTreeMap}; -use ethkey::Secret; +use crypto::publickey::Secret; use key_server_cluster::SessionId; use super::{Error, SerializableH256, SerializablePublic, SerializableSecret, SerializableSignature, SerializableMessageHash, SerializableRequester, SerializableAddress}; @@ -240,7 +240,7 @@ pub enum KeyVersionNegotiationMessage { pub struct NodePublicKey { /// Node identifier (aka node public key). pub node_id: MessageNodeId, - /// Random data, which must be signed by peer to prove that he owns the corresponding private key. + /// Random data, which must be signed by peer to prove that he owns the corresponding private key. pub confirmation_plain: SerializableH256, /// The same random `confirmation_plain`, signed with one-time session key. pub confirmation_signed_session: SerializableSignature, @@ -633,7 +633,7 @@ pub struct EcdsaRequestPartialSignature { pub session_nonce: u64, /// Request id. pub request_id: SerializableSecret, - /// + /// ECDSA reversed-nonce coefficient pub inversed_nonce_coeff: SerializableSecret, /// Message hash. pub message_hash: SerializableMessageHash, diff --git a/secret-store/src/key_server_cluster/net/connection.rs b/secret-store/src/key_server_cluster/net/connection.rs index 8688db2897c..cc7e882b090 100644 --- a/secret-store/src/key_server_cluster/net/connection.rs +++ b/secret-store/src/key_server_cluster/net/connection.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use std::net; -use ethkey::KeyPair; +use crypto::publickey::KeyPair; use key_server_cluster::NodeId; use key_server_cluster::io::SharedTcpStream; diff --git a/secret-store/src/key_server_set.rs b/secret-store/src/key_server_set.rs index 2ced583c68c..4b09e69cab1 100644 --- a/secret-store/src/key_server_set.rs +++ b/secret-store/src/key_server_set.rs @@ -27,7 +27,7 @@ use common_types::{ ids::BlockId, }; use ethereum_types::{H256, Address}; -use ethkey::public_to_address; +use crypto::publickey::public_to_address; use bytes::Bytes; use types::{Error, Public, NodeAddress, NodeId}; use trusted_client::TrustedClient; @@ -592,7 +592,7 @@ pub mod tests { use std::collections::BTreeMap; use std::net::SocketAddr; use ethereum_types::{H256, H512}; - use ethkey::Public; + use crypto::publickey::Public; use super::{update_future_set, update_number_of_confirmations, FutureNewSet, KeyServerSet, KeyServerSetSnapshot, MIGRATION_CONFIRMATIONS_REQUIRED}; diff --git a/secret-store/src/key_storage.rs b/secret-store/src/key_storage.rs index d670417f9bb..088adc4f44b 100644 --- a/secret-store/src/key_storage.rs +++ b/secret-store/src/key_storage.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use serde_json; use tiny_keccak::Keccak; use ethereum_types::{H256, Address}; -use ethkey::{Secret, Public}; +use crypto::publickey::{Secret, Public}; use kvdb::KeyValueDB; use types::{Error, ServerKeyId, NodeId}; use serialization::{SerializablePublic, SerializableSecret, SerializableH256, SerializableAddress}; @@ -296,7 +296,7 @@ pub mod tests { use std::sync::Arc; use parking_lot::RwLock; use self::tempdir::TempDir; - use ethkey::{Random, Generator, Public}; + use crypto::publickey::{Random, Generator, Public}; use kvdb_rocksdb::Database; use types::{Error, ServerKeyId}; use super::{KeyStorage, PersistentKeyStorage, DocumentKeyShare, DocumentKeyShareVersion}; diff --git a/secret-store/src/lib.rs b/secret-store/src/lib.rs index bdf3f638d28..e4d521cc007 100644 --- a/secret-store/src/lib.rs +++ b/secret-store/src/lib.rs @@ -22,7 +22,6 @@ extern crate ethcore; extern crate ethcore_call_contract as call_contract; extern crate ethcore_sync as sync; extern crate ethereum_types; -extern crate ethkey; extern crate hyper; extern crate keccak_hash as hash; extern crate kvdb; @@ -54,6 +53,8 @@ extern crate lazy_static; #[macro_use] extern crate log; +#[cfg(test)] +extern crate ethkey; #[cfg(test)] extern crate env_logger; #[cfg(test)] diff --git a/secret-store/src/listener/http_listener.rs b/secret-store/src/listener/http_listener.rs index 93dbed7c4db..91102bc6081 100644 --- a/secret-store/src/listener/http_listener.rs +++ b/secret-store/src/listener/http_listener.rs @@ -452,7 +452,7 @@ mod tests { use std::sync::Arc; use std::str::FromStr; use hyper::Method as HttpMethod; - use ethkey::Public; + use crypto::publickey::Public; use traits::KeyServer; use key_server::tests::DummyKeyServer; use types::NodeAddress; diff --git a/secret-store/src/listener/service_contract.rs b/secret-store/src/listener/service_contract.rs index f286a1f090a..78acdaf582e 100644 --- a/secret-store/src/listener/service_contract.rs +++ b/secret-store/src/listener/service_contract.rs @@ -23,7 +23,7 @@ use call_contract::CallContract; use ethcore::client::Client; use client_traits::BlockChainClient; use common_types::ids::BlockId; -use ethkey::{Public, public_to_address}; +use crypto::publickey::{Public, public_to_address}; use hash::keccak; use bytes::Bytes; use ethereum_types::{H256, U256, Address, H512}; @@ -754,7 +754,7 @@ fn serialize_threshold(threshold: usize) -> Result { pub mod tests { use parking_lot::Mutex; use bytes::Bytes; - use ethkey::Public; + use crypto::publickey::Public; use ethereum_types::Address; use listener::service_contract_listener::ServiceTask; use {ServerKeyId}; diff --git a/secret-store/src/listener/service_contract_aggregate.rs b/secret-store/src/listener/service_contract_aggregate.rs index 13e1a79687e..8916a13d823 100644 --- a/secret-store/src/listener/service_contract_aggregate.rs +++ b/secret-store/src/listener/service_contract_aggregate.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use bytes::Bytes; use ethereum_types::Address; -use ethkey::Public; +use crypto::publickey::Public; use listener::service_contract::ServiceContract; use listener::service_contract_listener::ServiceTask; use {ServerKeyId}; diff --git a/secret-store/src/listener/service_contract_listener.rs b/secret-store/src/listener/service_contract_listener.rs index c5d540224ff..63cacf01de2 100644 --- a/secret-store/src/listener/service_contract_listener.rs +++ b/secret-store/src/listener/service_contract_listener.rs @@ -21,7 +21,7 @@ use std::thread; use client_traits::ChainNotify; use common_types::chain_notify::NewBlocks; use bytes::Bytes; -use ethkey::{Public, public_to_address}; +use crypto::publickey::{Public, public_to_address}; use ethereum_types::{H256, U256, Address, BigEndianHash as _}; use key_server_set::KeyServerSet; use key_server_cluster::{NodeId, ClusterClient, ClusterSessionsListener, ClusterSession}; @@ -587,7 +587,7 @@ fn is_processed_by_this_key_server(key_server_set: &dyn KeyServerSet, node: &Nod mod tests { use std::sync::Arc; use std::sync::atomic::Ordering; - use ethkey::{Random, Generator, KeyPair}; + use crypto::publickey::{Random, Generator, KeyPair}; use listener::service_contract::ServiceContract; use listener::service_contract::tests::DummyServiceContract; use key_server_cluster::DummyClusterClient; diff --git a/secret-store/src/node_key_pair.rs b/secret-store/src/node_key_pair.rs index f50f75ad1b9..ecf950d7f51 100644 --- a/secret-store/src/node_key_pair.rs +++ b/secret-store/src/node_key_pair.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use ethkey::crypto::ecdh::agree; -use ethkey::{KeyPair, Public, Signature, Error as EthKeyError, sign, public_to_address}; +use crypto::publickey::ecdh::agree; +use crypto::publickey::{KeyPair, Public, Signature, Error as EthKeyError, sign, public_to_address}; use ethereum_types::{H256, Address}; use traits::NodeKeyPair; diff --git a/secret-store/src/serialization.rs b/secret-store/src/serialization.rs index c75d0992faa..ee49bf6b8ea 100644 --- a/secret-store/src/serialization.rs +++ b/secret-store/src/serialization.rs @@ -19,35 +19,35 @@ use std::ops::Deref; use rustc_hex::{self, FromHex}; use serde::{Serialize, Deserialize, Serializer, Deserializer}; use serde::de::{Visitor, Error as SerdeError}; -use ethkey::{Public, Secret, Signature}; +use crypto::publickey::{Public, Secret, Signature}; use ethereum_types::{H160, H256}; use bytes::Bytes; use types::Requester; trait ToHex { - fn to_hex(&self) -> String; + fn to_hex(&self) -> String; } impl ToHex for Bytes { - fn to_hex(&self) -> String { + fn to_hex(&self) -> String { format!("0x{}", rustc_hex::ToHex::to_hex(&self[..])) } } impl ToHex for Signature { - fn to_hex(&self) -> String { + fn to_hex(&self) -> String { format!("0x{}", self) } } impl ToHex for Secret { - fn to_hex(&self) -> String { - format!("0x{}", rustc_hex::ToHex::to_hex(self)) + fn to_hex(&self) -> String { + format!("0x{}", self.to_hex()) } } macro_rules! impl_to_hex { - ($name: ident) => ( + ($name: ident) => ( impl ToHex for $name { fn to_hex(&self) -> String { format!("{:#x}", self) @@ -92,7 +92,7 @@ macro_rules! impl_bytes { impl Serialize for $name { fn serialize(&self, serializer: S) -> Result where S: Serializer { - serializer.serialize_str(self.0.to_hex().as_ref()) + serializer.serialize_str(<$other as ToHex>::to_hex(&self.0).as_ref()) } } @@ -228,7 +228,7 @@ mod tests { #[test] fn serialize_and_deserialize_secret() { let s = "5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae"; - let secret = SerializableSecret(Secret::from(s)); + let secret = SerializableSecret(Secret::from_str(s).unwrap()); do_test!(secret, format!("\"0x{}\"", s), SerializableSecret); } diff --git a/secret-store/src/traits.rs b/secret-store/src/traits.rs index 149087d6339..d62210ed1e0 100644 --- a/secret-store/src/traits.rs +++ b/secret-store/src/traits.rs @@ -16,7 +16,7 @@ use std::collections::BTreeSet; use futures::Future; -use ethkey::{KeyPair, Signature, Error as EthKeyError}; +use crypto::publickey::{KeyPair, Signature, Error as EthKeyError}; use ethereum_types::{H256, Address}; use types::{Error, Public, ServerKeyId, MessageHash, EncryptedMessageSignature, RequestSignature, Requester, EncryptedDocumentKey, EncryptedDocumentKeyShadow, NodeId}; diff --git a/secret-store/src/types/all.rs b/secret-store/src/types/all.rs index 1cacb75507b..65ebbbc96da 100644 --- a/secret-store/src/types/all.rs +++ b/secret-store/src/types/all.rs @@ -16,10 +16,10 @@ use std::collections::BTreeMap; -use {ethkey, bytes, ethereum_types}; +use {bytes, ethereum_types}; /// Node id. -pub type NodeId = ethkey::Public; +pub type NodeId = crypto::publickey::Public; /// Server key id. When key is used to encrypt document, it could be document contents hash. pub type ServerKeyId = ethereum_types::H256; /// Encrypted document key type. @@ -29,9 +29,9 @@ pub type MessageHash = ethereum_types::H256; /// Message signature. pub type EncryptedMessageSignature = bytes::Bytes; /// Request signature type. -pub type RequestSignature = ethkey::Signature; +pub type RequestSignature = crypto::publickey::Signature; /// Public key type. -pub use ethkey::Public; +pub use crypto::publickey::Public; /// Secret store configuration #[derive(Debug, Clone)] @@ -48,7 +48,7 @@ pub enum ContractAddress { /// Address is read from registry. Registry, /// Address is specified. - Address(ethkey::Address), + Address(crypto::publickey::Address), } /// Secret store configuration @@ -80,7 +80,7 @@ pub struct ClusterConfiguration { /// This node address. pub listener_address: NodeAddress, /// All cluster nodes addresses. - pub nodes: BTreeMap, + pub nodes: BTreeMap, /// Key Server Set contract address. If None, servers from 'nodes' map are used. pub key_server_set_contract_address: Option, /// Allow outbound connections to 'higher' nodes. @@ -97,9 +97,9 @@ pub struct ClusterConfiguration { #[derive(Clone, Debug, PartialEq)] pub struct EncryptedDocumentKeyShadow { /// Decrypted secret point. It is partially decrypted if shadow decryption was requested. - pub decrypted_secret: ethkey::Public, + pub decrypted_secret: crypto::publickey::Public, /// Shared common point. - pub common_point: Option, + pub common_point: Option, /// If shadow decryption was requested: shadow decryption coefficients, encrypted with requestor public. pub decrypt_shadows: Option>>, } @@ -108,9 +108,9 @@ pub struct EncryptedDocumentKeyShadow { #[derive(Debug, Clone)] pub enum Requester { /// Requested with server key id signature. - Signature(ethkey::Signature), + Signature(crypto::publickey::Signature), /// Requested with public key. - Public(ethkey::Public), + Public(crypto::publickey::Public), /// Requested with verified address. Address(ethereum_types::Address), } @@ -124,21 +124,21 @@ impl Default for Requester { impl Requester { pub fn public(&self, server_key_id: &ServerKeyId) -> Result { match *self { - Requester::Signature(ref signature) => ethkey::recover(signature, server_key_id) + Requester::Signature(ref signature) => crypto::publickey::recover(signature, server_key_id) .map_err(|e| format!("bad signature: {}", e)), Requester::Public(ref public) => Ok(public.clone()), Requester::Address(_) => Err("cannot recover public from address".into()), } } - pub fn address(&self, server_key_id: &ServerKeyId) -> Result { + pub fn address(&self, server_key_id: &ServerKeyId) -> Result { self.public(server_key_id) - .map(|p| ethkey::public_to_address(&p)) + .map(|p| crypto::publickey::public_to_address(&p)) } } -impl From for Requester { - fn from(signature: ethkey::Signature) -> Requester { +impl From for Requester { + fn from(signature: crypto::publickey::Signature) -> Requester { Requester::Signature(signature) } } diff --git a/secret-store/src/types/error.rs b/secret-store/src/types/error.rs index 72dfded78e2..64cc1228e3d 100644 --- a/secret-store/src/types/error.rs +++ b/secret-store/src/types/error.rs @@ -18,7 +18,7 @@ use std::fmt; use std::net; use std::io::Error as IoError; -use {ethkey, crypto}; +use crypto; /// Secret store error. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -162,18 +162,12 @@ impl fmt::Display for Error { } } -impl From for Error { - fn from(err: ethkey::Error) -> Self { +impl From for Error { + fn from(err: crypto::publickey::Error) -> Self { Error::EthKey(err.into()) } } -impl From for Error { - fn from(err: ethkey::crypto::Error) -> Self { - Error::EthKey(err.to_string()) - } -} - impl From for Error { fn from(err: crypto::Error) -> Self { Error::EthKey(err.to_string()) diff --git a/util/network-devp2p/Cargo.toml b/util/network-devp2p/Cargo.toml index bc9ead6b3f0..f019334b97b 100644 --- a/util/network-devp2p/Cargo.toml +++ b/util/network-devp2p/Cargo.toml @@ -21,10 +21,9 @@ ansi_term = "0.11" rustc-hex = "1.0" ethcore-io = { path = "../io", features = ["mio"] } parity-bytes = "0.1" -crypto = { package = "parity-crypto", version = "0.4.0"} +parity-crypto = { version = "0.4.2", features = ["publickey"] } network = { package = "ethcore-network", path = "../network" } ethereum-types = "0.8.0" -ethkey = { path = "../../accounts/ethkey" } rlp = "0.4.0" parity-path = "0.1" ipnetwork = "0.12.6" diff --git a/util/network-devp2p/src/connection.rs b/util/network-devp2p/src/connection.rs index 4892d0be6e3..f77094e9f0c 100644 --- a/util/network-devp2p/src/connection.rs +++ b/util/network-devp2p/src/connection.rs @@ -21,7 +21,8 @@ use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering}; use std::time::Duration; use bytes::{Buf, BufMut}; -use crypto::aes::{AesCtr256, AesEcb256}; +use parity_crypto::aes::{AesCtr256, AesEcb256}; +use parity_crypto::publickey::Secret; use ethereum_types::{H128, H256, H512}; use keccak_hash::{keccak, write_keccak}; use log::{debug, trace, warn}; @@ -33,7 +34,6 @@ use rlp::{Rlp, RlpStream}; use tiny_keccak::Keccak; use ethcore_io::{IoContext, StreamToken}; -use ethkey::{crypto as ethcrypto, Secret}; use network::Error; use crate::handshake::Handshake; @@ -302,7 +302,7 @@ const NULL_IV : [u8; 16] = [0;16]; impl EncryptedConnection { /// Create an encrypted connection out of the handshake. pub fn new(handshake: &mut Handshake) -> Result { - let shared = ethcrypto::ecdh::agree(handshake.ecdhe.secret(), &handshake.remote_ephemeral)?; + let shared = parity_crypto::publickey::ecdh::agree(handshake.ecdhe.secret(), &handshake.remote_ephemeral)?; let mut nonce_material = H512::default(); if handshake.originated { (&mut nonce_material[0..32]).copy_from_slice(handshake.remote_nonce.as_bytes()); @@ -328,7 +328,7 @@ impl EncryptedConnection { let decoder = AesCtr256::new(&key_material[32..64], &NULL_IV)?; let key_material_keccak = keccak(&key_material); (&mut key_material[32..64]).copy_from_slice(key_material_keccak.as_bytes()); - let mac_encoder_key: Secret = Secret::from_slice(&key_material[32..64]).expect("can create Secret from 32 bytes; qed"); + let mac_encoder_key: Secret = Secret::copy_from_slice(&key_material[32..64]).expect("can create Secret from 32 bytes; qed"); let mut egress_mac = Keccak::new_keccak256(); let mut mac_material = H256::from_slice(&key_material[32..64]) ^ handshake.remote_nonce; diff --git a/util/network-devp2p/src/discovery.rs b/util/network-devp2p/src/discovery.rs index 392c67b8a98..aa76e32f872 100644 --- a/util/network-devp2p/src/discovery.rs +++ b/util/network-devp2p/src/discovery.rs @@ -27,7 +27,7 @@ use lru_cache::LruCache; use parity_bytes::Bytes; use rlp::{Rlp, RlpStream}; -use ethkey::{KeyPair, recover, Secret, sign}; +use parity_crypto::publickey::{KeyPair, recover, Secret, sign}; use network::Error; use network::IpFilter; @@ -901,7 +901,7 @@ mod tests { use rustc_hex::FromHex; - use ethkey::{Generator, Random}; + use parity_crypto::publickey::{Generator, Random}; use crate::node_table::{Node, NodeEndpoint, NodeId}; diff --git a/util/network-devp2p/src/handshake.rs b/util/network-devp2p/src/handshake.rs index d0aadd313df..4534a660db2 100644 --- a/util/network-devp2p/src/handshake.rs +++ b/util/network-devp2p/src/handshake.rs @@ -25,8 +25,7 @@ use rand::random; use rlp::{Rlp, RlpStream}; use ethcore_io::{IoContext, StreamToken}; -use ethkey::{Generator, KeyPair, Public, Random, recover, Secret, sign}; -use ethkey::crypto::{ecdh, ecies}; +use parity_crypto::publickey::{Generator, KeyPair, Public, Random, recover, Secret, sign, ecdh, ecies}; use network::Error; use crate::connection::Connection; @@ -329,7 +328,7 @@ mod test { use rustc_hex::FromHex; use ethcore_io::*; - use ethkey::Public; + use parity_crypto::publickey::Public; use super::*; diff --git a/util/network-devp2p/src/host.rs b/util/network-devp2p/src/host.rs index 27949839f41..dba69e33773 100644 --- a/util/network-devp2p/src/host.rs +++ b/util/network-devp2p/src/host.rs @@ -40,7 +40,7 @@ use rlp::{Encodable, RlpStream}; use rustc_hex::ToHex; use ethcore_io::{IoContext, IoHandler, IoManager, StreamToken, TimerToken}; -use ethkey::{Generator, KeyPair, Random, Secret}; +use parity_crypto::publickey::{Generator, KeyPair, Random, Secret}; use network::{ client_version::ClientVersion, ConnectionDirection, ConnectionFilter, DisconnectReason, Error, NetworkConfiguration, NetworkContext as NetworkContextTrait, NetworkIoMessage, NetworkProtocolHandler, diff --git a/util/network-devp2p/tests/tests.rs b/util/network-devp2p/tests/tests.rs index 9a0fc72d595..a3b51ff7494 100644 --- a/util/network-devp2p/tests/tests.rs +++ b/util/network-devp2p/tests/tests.rs @@ -26,7 +26,7 @@ use parking_lot::Mutex; use network::{PeerId, NetworkContext, NetworkProtocolHandler, NetworkConfiguration}; use ethcore_network_devp2p::NetworkService; -use ethkey::{Generator, Random}; +use parity_crypto::publickey::{Generator, Random}; use ethcore_io::TimerToken; pub struct TestProtocol { diff --git a/util/network/Cargo.toml b/util/network/Cargo.toml index ea3e6e99e2b..8b71a3e7e68 100644 --- a/util/network/Cargo.toml +++ b/util/network/Cargo.toml @@ -8,10 +8,9 @@ authors = ["Parity Technologies "] [dependencies] derive_more = "0.14.0" -parity-crypto = "0.4.0" +parity-crypto = { version = "0.4.2", features = ["publickey"] } ethcore-io = { path = "../io" } ethereum-types = "0.8.0" -ethkey = { path = "../../accounts/ethkey" } ipnetwork = "0.12.6" lazy_static = "1.0" rlp = "0.4.0" diff --git a/util/network/src/error.rs b/util/network/src/error.rs index c43de6b8d58..ec0c57941db 100644 --- a/util/network/src/error.rs +++ b/util/network/src/error.rs @@ -17,7 +17,7 @@ use std::{error, io, net, fmt}; use libc::{ENFILE, EMFILE}; use io::IoError; -use {rlp, ethkey, crypto, snappy}; +use {rlp, crypto, snappy}; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum DisconnectReason @@ -182,14 +182,8 @@ impl From for Error { } } -impl From for Error { - fn from(_err: ethkey::Error) -> Self { - Error::Auth - } -} - -impl From for Error { - fn from(_err: ethkey::crypto::Error) -> Self { +impl From for Error { + fn from(_err: crypto::publickey::Error) -> Self { Error::Auth } } @@ -218,7 +212,7 @@ fn test_errors() { _ => panic!("Unexpected error"), } - match >::from(ethkey::crypto::Error::InvalidMessage) { + match >::from(crypto::publickey::Error::InvalidMessage) { Error::Auth => {}, _ => panic!("Unexpected error"), } diff --git a/util/network/src/lib.rs b/util/network/src/lib.rs index e94d35ba193..42bc8d6c3ee 100644 --- a/util/network/src/lib.rs +++ b/util/network/src/lib.rs @@ -19,7 +19,6 @@ extern crate parity_crypto as crypto; extern crate ethcore_io as io; extern crate ethereum_types; -extern crate ethkey; extern crate rlp; extern crate ipnetwork; extern crate parity_snappy as snappy; @@ -54,7 +53,7 @@ use std::str::{self, FromStr}; use std::sync::Arc; use std::time::Duration; use ipnetwork::{IpNetwork, IpNetworkError}; -use ethkey::Secret; +use crypto::publickey::Secret; use ethereum_types::H512; use rlp::{Decodable, DecoderError, Rlp}; From acf7c48d7e0fcd67a6a409e47827febcd330ac69 Mon Sep 17 00:00:00 2001 From: Fabio Lama Date: Wed, 23 Oct 2019 14:20:47 +0200 Subject: [PATCH 13/13] Type annotation for next_key() matching of json filter options (#11192) * type annotation for next_key matching of json filter options * rpc tests for pending transactions * mention git submodules in the readme --- README.md | 2 +- ethcore/src/miner/filter_options.rs | 8 +++---- rpc/src/v1/tests/mocked/parity.rs | 35 ++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3b79d295fad..be31c49243e 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ To start Parity Ethereum as a regular user using `systemd` init: ## 4. Testing -You can run tests with the following commands: +Download the required test files: `git submodule update --init --recursive`. You can run tests with the following commands: * **All** packages ``` diff --git a/ethcore/src/miner/filter_options.rs b/ethcore/src/miner/filter_options.rs index db0e67378ad..ae1a206b01a 100644 --- a/ethcore/src/miner/filter_options.rs +++ b/ethcore/src/miner/filter_options.rs @@ -160,8 +160,8 @@ impl<'de> Deserialize<'de> for FilterOptions { M: MapAccess<'de>, { let mut filter = FilterOptions::default(); - while let Some(key) = map.next_key()? { - match key { + while let Some(key) = map.next_key::()? { + match key.as_str() { "from" => { filter.from = map.validate_from()?; }, @@ -221,8 +221,8 @@ impl<'de> Deserialize<'de> for FilterOptions { let mut counter = 0; let mut f_op = Wrapper::O(FilterOperator::Any); - while let Some(key) = map.next_key()? { - match key { + while let Some(key) = map.next_key::()? { + match key.as_str() { "eq" => f_op = W::O(FilterOperator::Eq(map.next_value()?)), "gt" => f_op = W::O(FilterOperator::GreaterThan(map.next_value()?)), "lt" => f_op = W::O(FilterOperator::LessThan(map.next_value()?)), diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index 06da1861e4a..05c9c97d77c 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -316,7 +316,7 @@ fn rpc_parity_unsigned_transactions_count_when_signer_disabled() { } #[test] -fn rpc_parity_pending_transactions() { +fn rpc_parity_pending_transactions_without_limit_without_filter() { let deps = Dependencies::new(); let io = deps.default_client(); @@ -326,6 +326,39 @@ fn rpc_parity_pending_transactions() { assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); } +#[test] +fn rpc_parity_pending_transactions_with_limit_without_filter() { + let deps = Dependencies::new(); + let io = deps.default_client(); + + let request = r#"{"jsonrpc": "2.0", "method": "parity_pendingTransactions", "params":[5], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#; + + assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); +} + +#[test] +fn rpc_parity_pending_transactions_without_limit_with_filter() { + let deps = Dependencies::new(); + let io = deps.default_client(); + + let request = r#"{"jsonrpc": "2.0", "method": "parity_pendingTransactions", "params":[null,{"to":{"eq":"0xe8b2d01ffa0a15736b2370b6e5064f9702c891b6"},"gas":{"gt":"0x493e0"}}], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#; + + assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); +} + +#[test] +fn rpc_parity_pending_transactions_with_limit_with_filter() { + let deps = Dependencies::new(); + let io = deps.default_client(); + + let request = r#"{"jsonrpc": "2.0", "method": "parity_pendingTransactions", "params":[5,{"to":{"eq":"0xe8b2d01ffa0a15736b2370b6e5064f9702c891b6"},"gas":{"gt":"0x493e0"}}], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#; + + assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); +} + #[test] fn rpc_parity_encrypt() { let deps = Dependencies::new();