diff --git a/Cargo.lock b/Cargo.lock index b00c35537..291ba89d3 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 407f0aa4a..7783237f0 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 a15c5124b..7e63f9f58 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 fb3716ad0..8118ad163 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 cb57f0505..f9e616ce9 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 759f5f484..fb87a3dc5 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 436a6594f..3974d3996 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 f9922fae9..e5745d8a4 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 c2da84ecb..000000000 --- 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 ee1911574..000000000 --- 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 005f4ba66..000000000 --- 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 202c21193..000000000 --- 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 7b350788b..000000000 --- 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 4f55f056d..185d254ba 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 5025efeb6..000000000 --- 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 32d92c186..0a595de42 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 08ccd2624..000000000 --- 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 c850fa70e..000000000 --- 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 c4c4bfd9e..000000000 --- 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 99943611c..ac343b6ef 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 2793acc6e..f6d12e67f 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 abe171c35..8e65b0219 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 8fc0054be..7c7011837 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 de5b4d857..8abe799bc 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 7a38e79fa..4bd393fac 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 b70029785..10e88095c 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 7f623aa3a..a1403e240 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 fceaf1676..9798b5cc1 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 8cd2c533a..000000000 --- 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 36416c5e7..ab8d4644f 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 3fe9763e8..abf857244 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 aa2bb86a4..ddd1d4bb8 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 c1be05f0f..a050fbf23 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 d3ca1a12f..aa619be41 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 74d66a666..6554c4da7 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 a36d38740..3f874c41d 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 ac87a2ee3..29b8c3039 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 90e36374e..72d0a7df7 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 aca6a9243..f036010c5 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 5552e966f..3eb0b2ecb 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 870a29de6..efafef7a4 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 441e68a95..f69b65d97 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 3ecc1499f..d0b0e93ec 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 6165ef858..fe527ade8 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 357a184c7..f5e902343 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 1e932feef..baacf7c09 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 92ba66ff4..6423590b3 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 79083299a..5bca87fb8 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 2f4202f16..fd3585fc7 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 9c04fa37c..849014aec 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 bae548781..2587d5986 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 2c831813c..7a73f04c8 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 ac8ed4b86..50dad03ac 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 90ed67fcf..084758c43 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 007f49a2c..a18fb21a6 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 9dfd33c2c..958ea4b48 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 72b653041..76b3e9a1c 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 666d43eac..cf1a23b1a 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 590334e1c..311d99ecc 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 29b4cd783..b9468a7a7 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 92df515db..dc33e75a9 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 44de252a9..e473ec3f2 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 5006ac26f..144320acb 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 18074330e..1a02a0071 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 e3fae4e61..6cc26383b 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 d62ba546b..682c99c34 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 b9167675f..b249b4173 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 b0ac9353f..26fe6a6a7 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 a1caf5d9b..712c19afe 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 5130b83e5..c2bc43b34 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 b91082891..48335eda0 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 6c3e57a09..f7514c456 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 efe6ec190..fbdfc2e70 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 b36ab4674..976d747e5 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 795a0e6de..4527dba81 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 500bf2068..f573da498 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 3d55f88ee..96e5d760b 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 44b298cdb..4c427afcd 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 0409e8249..683b08dda 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 3fb946e01..ea5675705 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 76d7234d1..ad6f9bbf9 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 f8018599a..8356249d9 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 d8d20bad3..17c32eca5 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 126799a3d..8c9ede447 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 780bda34d..c37a7a6a0 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 6c444a278..9ee42441b 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 2a7197332..7b5f6a36c 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 4aa5d8b5d..509b9d13d 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 f7b5abc9e..e995dab43 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 d78995d0c..58ca86cae 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 1ad9d5358..1e27b6337 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 bdbc302fc..aaa0da216 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 41a020e06..ef86ab861 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 8cf152b4a..3f06c39ad 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 297c8a64a..4cb90abdf 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 45ec72a67..6af340966 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 7c3a12776..6782bf447 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 f67c43770..ce9a5ceee 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 a83af5b72..e18c0a4d7 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 9ed15bad2..6b60b562e 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 b8f6dca67..69ba0863d 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 4f6533631..727bb8752 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 9fe6c8792..4c99e51c3 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 492c31875..7e8565053 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 9940fb50c..a09e05d8c 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 27424e275..f4af29e67 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 b392c6f61..3e927f699 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 81a865f0f..f9eee8d0a 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 8f16bb78a..db9cab095 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 fd40dc95e..c6b86a01a 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 3db4578eb..ba93c7d2c 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 b191a3737..f9ca0ea2e 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 4171df78d..9f929ee3f 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 2151ecc94..83ea0e799 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 62bc6d1cc..c05492826 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 0db3c99ca..84b335cb9 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 e0d6a97fe..458154a99 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 b6526b85d..3e5ed0a81 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 b135a1fba..a115ab531 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 85f803503..06da1861e 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 b9c3cb6d7..5e6d3a1c3 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 96e20d002..386a2455f 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 cf7da360e..184d3d8b6 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 9402a1631..24af2a798 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 233a9b3db..bbb45b5af 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 841aa889e..2790f9da1 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 5dcc7ea70..9bc6d1df8 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 c190396a5..94e6e9893 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 18d2671f5..d69c29b30 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 46691f58b..ce6e2a149 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 461810013..6d0f52540 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 806173854..b81cbfeac 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 4f913a536..70f40c3d8 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 ae0aa69d4..023e51320 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 f1d347091..44e6a22fe 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 155c0604d..b402d0018 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 3db72395d..1e5a046b9 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 d0559be48..0bdf0ccd4 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 d8ad995a9..40d415dff 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 00ea42571..92db652d5 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 b266d8681..a09e035e4 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 5707bd809..b45e4f062 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 e16de57a3..0549dd23a 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 9f3a47f66..9fbde6815 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 15823730a..771451e2d 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 7f2933870..597484321 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 a37e07499..e31add62e 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 0628b1e75..9fa8959b3 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 7e41dce47..31fc1b8c7 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 99340e492..3ba0298d5 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 98520564f..1f21a7caf 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 8688db289..cc7e882b0 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 2ced583c6..4b09e69ca 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 d670417f9..088adc4f4 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 bdf3f638d..e4d521cc0 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 93dbed7c4..91102bc60 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 f286a1f09..78acdaf58 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 13e1a7968..8916a13d8 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 c5d540224..63cacf01d 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 f50f75ad1..ecf950d7f 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 c75d0992f..ee49bf6b8 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 149087d63..d62210ed1 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 1cacb7550..65ebbbc96 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 72dfded78..64cc1228e 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 bc9ead6b3..f019334b9 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 4892d0be6..f77094e9f 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 392c67b8a..aa76e32f8 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 d0aadd313..4534a660d 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 27949839f..dba69e337 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 9a0fc72d5..a3b51ff74 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 ea3e6e99e..8b71a3e7e 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 c43de6b8d..ec0c57941 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 e94d35ba1..42bc8d6c3 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};