Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Upgrade ethereum types #10670

Merged
merged 96 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
69b36a7
cargo upgrade "ethereum-types" --all --allow-prerelease
ordian May 8, 2019
cad3e17
[ethash] fix compilation errors
ordian May 8, 2019
68916b9
[ethkey] fix compilation errors
ordian May 10, 2019
3523b24
[journaldb] fix compilation errors
ordian May 10, 2019
fdd6da4
[dir] fix compilation errors
ordian May 10, 2019
f889d7b
[ethabi] update to 0.7
ordian May 13, 2019
2a28200
wip
ordian May 14, 2019
86f16f6
[eip-712] fix compilation errors
ordian May 14, 2019
7583780
[ethjson] fix compilation errors
ordian May 16, 2019
fa9ef81
[Cargo.toml] add TODO to remove patches
ordian May 16, 2019
f8ce152
[ethstore] fix compilation errors
ordian May 16, 2019
c7b4527
use patched keccak-hash with new primitive-types
ordian May 16, 2019
09c92c2
wip
ordian May 16, 2019
ab906ca
[ethcore-network-devp2p] fix compilation errors
ordian May 16, 2019
c974f92
[vm] fix compilation errors
ordian May 16, 2019
17e8e52
[common-types, evm, wasm] fix compilation errors
ordian May 16, 2019
c188f13
[ethcore-db] Require AsRef instead of Deref for keys
ordian May 16, 2019
1fca62e
[ethcore-blockchain] fix some compilation errors
ordian May 16, 2019
a377aee
Merge branch 'master' into ao-upgrade-ethereum-types
ordian May 16, 2019
8bfc263
[blooms-db] fix compilation errors
ordian May 16, 2019
9bcb992
we don't need no rlp ethereum feature
ordian May 17, 2019
4bb39c5
[ethcore] fix some compilation errors
ordian May 17, 2019
46e3b2d
[parity-ipfs-api] fix compilation error
ordian May 17, 2019
dce478f
[ethcore-light] fix compilation errors
ordian May 17, 2019
657afa3
[Cargo.lock] update parity-common
ordian May 17, 2019
3478523
[ethcore-private-tx] fix some compilation errors
ordian May 17, 2019
ad28077
wip
ordian May 20, 2019
40240cb
Merge branch 'master' into ao-upgrade-ethereum-types
ordian May 20, 2019
1de3635
[ethcore-private-tx] fix compilation errors
ordian May 21, 2019
73c2c71
[parity-updater] fix compilation errors
ordian May 22, 2019
7485575
[parity-rpc] fix compilation errors
ordian May 22, 2019
8e504a0
[parity-bin] fix other compilation errors
ordian May 22, 2019
847c5f1
Merge branch 'master' into ao-upgrade-ethereum-types
ordian May 22, 2019
82dc3eb
update to new ethereum-types
ordian May 23, 2019
3b9f715
Merge branch 'master' into ao-upgrade-ethereum-types
ordian May 23, 2019
1db5897
update keccak-hash
ordian May 23, 2019
a6089c8
[fastmap] fix compilation in tests
ordian May 23, 2019
1ccc757
[blooms-db] fix compilation in tests
ordian May 24, 2019
d501445
[common-types] fix compilation in tests
ordian May 24, 2019
eae4a64
[triehash-ethereum] fix compilation in tests
ordian May 24, 2019
dbb0b50
[ethkey] fix compilation in tests
ordian May 24, 2019
76438f7
[pwasm-run-test] fix compilation errors
ordian May 24, 2019
9292132
[wasm] fix compilation errors
ordian May 24, 2019
6cfc144
[ethjson] fix compilation in tests
ordian May 24, 2019
8c3180e
[eip-712] fix compilation in tests
ordian May 24, 2019
ba13bc2
[ethcore-blockchain] fix compilation in tests
ordian May 24, 2019
410e9c0
[ethstore] fix compilation in tests
ordian May 24, 2019
b0a4651
[ethstore-accounts] fix compilation in tests
ordian May 24, 2019
e368698
[parity-hash-fetch] fix compilation in tests
ordian May 24, 2019
3ff1368
[parity-whisper] fix compilation in tests
ordian May 24, 2019
96453bd
[ethcore-miner] fix compilation in tests
ordian May 24, 2019
5d7dfa3
[ethcore-network-devp2p] fix compilation in tests
ordian May 24, 2019
14ba9f7
[*] upgrade rand to 0.6
ordian May 24, 2019
47f3dbd
[evm] get rid of num-bigint conversions
ordian May 24, 2019
3abcbc2
[ethcore] downgrade trie-standardmap and criterion
ordian May 24, 2019
cde92b8
[ethcore] fix some warnings
ordian May 24, 2019
f4d16d7
[ethcore] fix compilation in tests
ordian May 27, 2019
7f566ba
[evmbin] fix compilation in tests
ordian May 27, 2019
446aea9
[updater] fix compilation in tests
ordian May 27, 2019
1a4afdf
[ethash] fix compilation in tests
ordian May 27, 2019
8918fc9
[ethcore-secretstore] fix compilation in tests
ordian May 27, 2019
7f40a1a
[ethcore-sync] fix compilation in tests
ordian May 27, 2019
3b03980
[parity-rpc] fix compilation in tests
ordian May 27, 2019
348984b
[ethcore] finally fix compilation in tests
ordian May 28, 2019
4f398f4
Merge branch 'master' into ao-upgrade-ethereum-types
ordian May 28, 2019
8a91a6e
[ethstore] lazy_static is unused
ordian May 28, 2019
c2c935f
[ethcore] fix test
ordian May 28, 2019
a654c15
fix up bad merge
ordian May 28, 2019
a618804
[Cargo.toml] remove unused patches
ordian May 28, 2019
d14d0dd
[*] replace some git dependencies with crates.io
ordian May 28, 2019
86410dd
[Cargo.toml] remove unused lazy_static
ordian May 28, 2019
98ff9a2
[*] clean up
ordian May 28, 2019
7e236f3
[ethcore] fix transaction_filter_deprecated test
ordian May 28, 2019
44ce143
[private-tx] fix serialization tests
ordian May 28, 2019
87f14c9
fix more serialization tests
ordian May 28, 2019
7dc2d7c
[ethkey] fix smoky test
ordian May 28, 2019
86ee880
[rpc] fix tests, please?
ordian May 28, 2019
ae63d72
[ethcore] remove commented out code
ordian May 28, 2019
39a45f2
Apply suggestions from code review
ordian May 29, 2019
6c0189a
[ethstore] remove unused dev-dependency
ordian May 29, 2019
09cb8b7
[ethcore] remove resolved TODO
ordian May 29, 2019
73e4cae
[*] resolve keccak-hash TODO
ordian May 29, 2019
7ed62da
[*] s/Address::default()/Address::zero()
ordian May 29, 2019
a9cca6e
[rpc] remove Subscribers::new_test
ordian May 29, 2019
d22a478
[rpc] remove EthPubSubClient::new_test
ordian May 29, 2019
57787b8
[ethcore] use trie-standardmap from crates.io
ordian May 29, 2019
b7a700d
[dir] fix db_root_path
ordian May 29, 2019
8264f90
[ethcore] simplify snapshot::tests::helpers::fill_storage
ordian May 29, 2019
b349df9
Apply suggestions from code review
ordian May 29, 2019
016d682
[ethcore-secretstore] resolve TODO in serialization
ordian May 29, 2019
4dbba7e
[ethcore-network-devp2p] resolve TODO in save_key
ordian May 29, 2019
e479218
[Cargo.lock] update triehash
ordian May 29, 2019
9181be7
[*] use ethabi from crates.io
ordian Jun 3, 2019
722971b
[ethkey] use secp256k1 from master branch
ordian Jun 3, 2019
94db3a0
Merge branch 'master' into ao-upgrade-ethereum-types
ordian Jun 3, 2019
72d9b6e
[Cargo.lock] update eth-secp256k1
ordian Jun 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
580 changes: 367 additions & 213 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ ethcore-network = { path = "util/network" }
ethcore-private-tx = { path = "ethcore/private-tx" }
ethcore-service = { path = "ethcore/service" }
ethcore-sync = { path = "ethcore/sync" }
ethereum-types = "0.4"
ethereum-types = "0.6.0"

ordian marked this conversation as resolved.
Show resolved Hide resolved
ethkey = { path = "accounts/ethkey" }
ethstore = { path = "accounts/ethstore" }
node-filter = { path = "ethcore/node-filter" }
rlp = { version = "0.3.0", features = ["ethereum"] }
rlp = "0.4.0"
cli-signer= { path = "cli-signer" }
parity-daemonize = "0.3"
parity-hash-fetch = { path = "updater/hash-fetch" }
Expand All @@ -63,7 +64,7 @@ parity-whisper = { path = "whisper" }
parity-path = "0.1"
dir = { path = "util/dir" }
panic_hook = { path = "util/panic-hook" }
keccak-hash = "0.1"
keccak-hash = "0.2.0"
migration-rocksdb = { path = "util/migration-rocksdb" }
kvdb = "0.1"
kvdb-rocksdb = "0.1.3"
Expand All @@ -81,7 +82,6 @@ pretty_assertions = "0.1"
ipnetwork = "0.12.6"
tempdir = "0.3"
fake-fetch = { path = "util/fake-fetch" }
lazy_static = "1.2.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.4", features = ["winsock2", "winuser", "shellapi"] }
Expand Down
2 changes: 1 addition & 1 deletion accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ serde_derive = "1.0"
serde_json = "1.0"

[dev-dependencies]
ethereum-types = "0.4"
ethereum-types = "0.6.0"
tempdir = "0.3"
7 changes: 4 additions & 3 deletions accounts/ethkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ authors = ["Parity Technologies <admin@parity.io>"]
byteorder = "1.0"
edit-distance = "2.0"
parity-crypto = "0.4.0"
eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" }
ethereum-types = "0.4"
# TODO: use master branch after we switch to rand 0.6
eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", branch = "rand-0.6" }
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
ethereum-types = "0.6.0"
lazy_static = "1.0"
log = "0.4"
memzero = { path = "../../util/memzero" }
parity-wordlist = "1.2"
quick-error = "1.2.2"
rand = "0.4"
rand = "0.6"
rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions accounts/ethkey/src/brain_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Generator for BrainPrefix {
for _ in 0..self.iterations {
let phrase = wordlist::random_phrase(self.no_of_words);
let keypair = Brain::new(phrase.clone()).generate().unwrap();
if keypair.address().starts_with(&self.prefix) {
if keypair.address().as_ref().starts_with(&self.prefix) {
self.last_phrase = phrase;
return Ok(keypair)
}
Expand All @@ -65,6 +65,6 @@ mod tests {
fn prefix_generator() {
let prefix = vec![0x00u8];
let keypair = BrainPrefix::new(prefix.clone(), usize::max_value(), 12).generate().unwrap();
assert!(keypair.address().starts_with(&prefix));
assert!(keypair.address().as_bytes().starts_with(&prefix));
}
}
10 changes: 5 additions & 5 deletions accounts/ethkey/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod ecdh {
};

let publ = key::PublicKey::from_slice(context, &pdata)?;
let sec = key::SecretKey::from_slice(context, &secret)?;
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])
Expand Down Expand Up @@ -89,12 +89,12 @@ pub mod ecies {
msg[0] = 0x04u8;
{
let msgd = &mut msg[1..];
msgd[0..64].copy_from_slice(r.public());
msgd[0..64].copy_from_slice(r.public().as_bytes());
let iv = H128::random();
msgd[64..80].copy_from_slice(&iv);
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, plain, cipher)?;
aes::encrypt_128_ctr(ekey, iv.as_bytes(), plain, cipher)?;
}
let mut hmac = hmac::Signer::with(&mkey);
{
Expand Down Expand Up @@ -156,7 +156,7 @@ pub mod ecies {
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);
hasher.update(secret.as_bytes());
hasher.update(s1);
let d = hasher.finish();
&mut dest[written..(written + 32)].copy_from_slice(&d);
Expand Down
93 changes: 55 additions & 38 deletions accounts/ethkey/src/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Label for H256 {
fn len() -> usize { 32 }

fn store(&self, target: &mut [u8]) {
self.copy_to(&mut target[0..32]);
(&mut target[0..32]).copy_from_slice(self.as_bytes());
}
}

Expand Down Expand Up @@ -180,7 +180,7 @@ impl ExtendedKeyPair {
pub fn with_seed(seed: &[u8]) -> Result<ExtendedKeyPair, DerivationError> {
let (master_key, chain_code) = derivation::seed_pair(seed);
Ok(ExtendedKeyPair::with_secret(
Secret::from_unsafe_slice(&*master_key).map_err(|_| DerivationError::InvalidSeed)?,
Secret::from_unsafe_slice(master_key.as_bytes()).map_err(|_| DerivationError::InvalidSeed)?,
chain_code,
))
}
Expand Down Expand Up @@ -208,12 +208,13 @@ impl ExtendedKeyPair {
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
mod derivation {
use parity_crypto::hmac;
use ethereum_types::{U256, U512, H512, H256};
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 {
Expand All @@ -237,18 +238,18 @@ mod derivation {
}

fn hmac_pair(data: &[u8], private_key: H256, chain_code: H256) -> (H256, H256) {
let private: U256 = private_key.into();
let private: U256 = private_key.into_uint();

// produces 512-bit derived hmac (I)
let skey = hmac::SigKey::sha512(&*chain_code);
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();
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(&i_512[32..64]);
let next_chain_code = H256::from_slice(&i_512[32..64]);

let child_key = private_add(hmac_key, private).into();
let child_key = BigEndianHash::from_uint(&private_add(hmac_key, private));
(child_key, next_chain_code)
}

Expand All @@ -257,7 +258,7 @@ mod derivation {
fn private_soft<T>(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)
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");
Expand All @@ -276,7 +277,7 @@ mod derivation {
// corresponding public keys of the original and derived private keys
fn private_hard<T>(private_key: H256, chain_code: H256, index: T) -> (H256, H256) where T: Label {
let mut data: Vec<u8> = vec![0u8; 33 + T::len()];
let private: U256 = private_key.into();
let private: U256 = private_key.into_uint();

// 0x00 (padding) -- private_key -- index
// 0 -- 1..33 -- 33..end
Expand All @@ -293,9 +294,8 @@ mod derivation {

// todo: surely can be optimized
fn modulo(u1: U512, u2: U256) -> U256 {
let dv = u1 / U512::from(u2);
let md = u1 - (dv * U512::from(u2));
md.into()
let m = u1 % U512::from(u2);
m.try_into().expect("U512 modulo U256 should fit into U256; qed")
}

pub fn public<T>(public_key: H512, chain_code: H256, derivation: Derivation<T>) -> Result<(H512, H256), Error> where T: Label {
Expand All @@ -306,7 +306,7 @@ mod derivation {

let mut public_sec_raw = [0u8; 65];
public_sec_raw[0] = 4;
public_sec_raw[1..65].copy_from_slice(&*public_key);
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);

Expand All @@ -317,15 +317,15 @@ mod derivation {
index.store(&mut data[33..(33 + T::len())]);

// HMAC512SHA produces [derived private(256); new chain code(256)]
let skey = hmac::SigKey::sha512(&*chain_code);
let skey = hmac::SigKey::sha512(chain_code.as_bytes());
let i_512 = hmac::sign(&skey, &data[..]);

let new_private = H256::from(&i_512[0..32]);
let new_chain_code = H256::from(&i_512[32..64]);
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.clone().into() { return Err(Error::MissingIndex); }
let new_private_sec = SecretKey::from_slice(&SECP256K1, &*new_private)
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");
Expand All @@ -337,7 +337,7 @@ mod derivation {
let serialized = new_public.serialize_vec(&SECP256K1, false);

Ok((
H512::from(&serialized[1..65]),
H512::from_slice(&serialized[1..65]),
new_chain_code,
))
}
Expand All @@ -348,18 +348,18 @@ mod derivation {

pub fn chain_code(secret: H256) -> H256 {
// 10,000 rounds of sha3
let mut running_sha3 = sha3(&*secret);
for _ in 0..99999 { running_sha3 = sha3(&*running_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<H512, Error> {
let sec = SecretKey::from_slice(&SECP256K1, &*secret)
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(&serialized[1..65]))
Ok(H512::from_slice(&serialized[1..65]))
}

pub fn seed_pair(seed: &[u8]) -> (H256, H256) {
Expand All @@ -378,12 +378,13 @@ mod tests {
use super::{ExtendedSecret, ExtendedPublic, ExtendedKeyPair};
use secret::Secret;
use std::str::FromStr;
use ethereum_types::{H128, H256};
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)
Expand All @@ -399,35 +400,47 @@ mod tests {
#[test]
fn smoky() {
let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap();
let extended_secret = ExtendedSecret::with_code(secret.clone(), 0u64.into());
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(), &"0927453daed47839608e414a3738dfad10aed17c459bbd9ab53f89b026c834b6".into());
assert_eq!(&**extended_secret.derive(2147483649.into()).as_raw(), &"44238b6a29c6dcbe9b401364141ba11e2198c289a5fed243a1c11af35c19dc0f".into());
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(), &"bf6a74e3f7b36fc4c96a1e12f31abc817f9f5904f5a8fc27713163d1f0b713f6".into());
assert_eq!(&**extended_secret.derive(1.into()).as_raw(), &"bd4fca9eb1f9c201e9448c1eecd66e302d68d4d313ce895b8c134f512205c1bc".into());
assert_eq!(&**extended_secret.derive(2.into()).as_raw(), &"86932b542d6cab4d9c65490c7ef502d89ecc0e2a5f4852157649e3251e2a3268".into());
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(), &"f7b3244c96688f92372bfd4def26dc4151529747bab9f188a4ad34e141d47bd66522ff048bc6f19a0a4429b04318b1a8796c000265b4fa200dae5f6dda92dd94".into());
assert_eq!(
*derived_public.public(),
H512::from_str("f7b3244c96688f92372bfd4def26dc4151529747bab9f188a4ad34e141d47bd66522ff048bc6f19a0a4429b04318b1a8796c000265b4fa200dae5f6dda92dd94").unwrap(),
);

let keypair = ExtendedKeyPair::with_secret(
Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(),
064.into(),
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(),
);
assert_eq!(&**keypair.derive(2147483648u32.into()).expect("Derivation of keypair should succeed").secret().as_raw(), &"edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c".into());
}

#[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(), 0u64.into());
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));
Expand All @@ -442,15 +455,18 @@ mod tests {
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(), 1u64.into());
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(), &"2bc2d696fb744d77ff813b4a1ef0ad64e1e5188b622c54ba917acc5ebc7c5486".into());
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(), 1.into());
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());
Expand All @@ -465,6 +481,7 @@ mod tests {
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
Expand Down
Loading