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

Overhaul crypto (Schnorr/Ristretto, HDKD, BIP39) #1795

Merged
merged 43 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6ec42d7
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Feb 14, 2019
f774028
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Feb 14, 2019
12f88af
Rijig to Ristretto
gavofyork Feb 14, 2019
8170cc9
Rebuild wasm
gavofyork Feb 14, 2019
ec6c7c9
adds compatibility test with the wasm module
kianenigma Feb 15, 2019
f8f5097
Merge branch 'gav-enable-ristretto' of github.com:paritytech/substrat…
kianenigma Feb 15, 2019
494e05b
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 6, 2019
3491d5b
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 7, 2019
af2061e
Add Ed25519-BIP39 support
gavofyork Mar 7, 2019
d80d906
Bump subkey version
gavofyork Mar 7, 2019
b7ad4f5
Update CLI output
gavofyork Mar 7, 2019
fd5503c
New keys.
gavofyork Mar 7, 2019
72fbadc
Standard phrase/password/path keys.
gavofyork Mar 8, 2019
fb1c40e
Subkey uses S-URI for secrets
gavofyork Mar 8, 2019
ddaffb0
Move everything to use new HDKD crypto.
gavofyork Mar 8, 2019
2142a38
Test fixes
gavofyork Mar 8, 2019
34259d6
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 8, 2019
2ab6e42
Ignore old test vector.
gavofyork Mar 8, 2019
ca9c198
fix the ^^ old test vector.
kianenigma Mar 8, 2019
81b47bf
Fix tests
gavofyork Mar 10, 2019
fab9560
Test fixes
gavofyork Mar 10, 2019
fab1d97
Cleanups
gavofyork Mar 10, 2019
131a349
Fix broken key conversion logic in grandpa
gavofyork Mar 10, 2019
c284b91
Remove legacy Keyring usage
gavofyork Mar 10, 2019
d008f3b
Traitify `Pair`
gavofyork Mar 11, 2019
5dc4442
Replace Ed25519AuthorityId with ed25519::Public
gavofyork Mar 12, 2019
519a80e
Expunge Ed25519AuthorityId type!
gavofyork Mar 12, 2019
c019fa9
Replace Sr25519AuthorityId with sr25519::Public
gavofyork Mar 12, 2019
ab60208
Remove dodgy crypto type-punning conversions
gavofyork Mar 12, 2019
11e053e
Fix some tests
gavofyork Mar 12, 2019
5acdfb9
Avoid trait
gavofyork Mar 12, 2019
9837ddd
Deduplicate DeriveJunction string decode
gavofyork Mar 12, 2019
3e29972
Remove cruft code
gavofyork Mar 12, 2019
9fadc2b
Fix test
gavofyork Mar 12, 2019
c1fec25
Minor removals
gavofyork Mar 12, 2019
5c61823
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 12, 2019
40dbc3f
Build fix
gavofyork Mar 12, 2019
d601233
Subkey supports sign and verify
gavofyork Mar 13, 2019
57de3e1
Inspect works for public key URIs
gavofyork Mar 13, 2019
2982704
Remove more crypto type-punning
gavofyork Mar 13, 2019
8a76fb1
Fix typo
gavofyork Mar 13, 2019
c11b5b5
Fix tests
gavofyork Mar 13, 2019
df6778a
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 13, 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
8 changes: 7 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use vergen::{ConstantsFlags, generate_cargo_keys};

const ERROR_MSG: &'static str = "Failed to generate metadata files";
const ERROR_MSG: &str = "Failed to generate metadata files";

fn main() {
generate_cargo_keys(ConstantsFlags::all()).expect(ERROR_MSG);
Expand Down
7 changes: 3 additions & 4 deletions core/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,16 @@ mod tests {
use codec::Encode;
use std::cell::RefCell;
use consensus_common::{Environment, Proposer};
use test_client::keyring::Keyring;
use test_client::{self, runtime::{Extrinsic, Transfer}};
use test_client::{self, runtime::{Extrinsic, Transfer}, AccountKeyring};

fn extrinsic(nonce: u64) -> Extrinsic {
let tx = Transfer {
amount: Default::default(),
nonce,
from: Keyring::Alice.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: Default::default(),
};
let signature = Keyring::from_raw_public(tx.from.to_fixed_bytes()).unwrap().sign(&tx.encode()).into();
let signature = AccountKeyring::from_public(&tx.from).unwrap().sign(&tx.encode()).into();
Extrinsic::Transfer(tx, signature)
}

Expand Down
5 changes: 4 additions & 1 deletion core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ use substrate_telemetry::TelemetryEndpoints;

const MAX_NODE_NAME_LENGTH: usize = 32;

/// The root phrase for our development network keys.
pub const DEV_PHRASE: &str = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";

/// Executable version. Used to pass version information from the root crate.
pub struct VersionInfo {
/// Implemtation name.
Expand Down Expand Up @@ -387,7 +390,7 @@ where
}

if cli.shared_params.dev {
config.keys.push("Alice".into());
config.keys.push(format!("{}//Alice", DEV_PHRASE));
}

let rpc_interface: &str = if cli.rpc_external { "0.0.0.0" } else { "127.0.0.1" };
Expand Down
75 changes: 37 additions & 38 deletions core/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,11 +1520,10 @@ impl<B, E, Block, RA> backend::AuxStore for Client<B, E, Block, RA>
pub(crate) mod tests {
use std::collections::HashMap;
use super::*;
use keyring::Keyring;
use primitives::twox_128;
use runtime_primitives::traits::DigestItem as DigestItemT;
use runtime_primitives::generic::DigestItem;
use test_client::{self, TestClient};
use test_client::{self, TestClient, AccountKeyring, AuthorityKeyring};
use consensus::BlockOrigin;
use test_client::client::backend::Backend as TestBackend;
use test_client::BlockBuilderExt;
Expand All @@ -1541,10 +1540,10 @@ pub(crate) mod tests {
) {
// prepare block structure
let blocks_transfers = vec![
vec![(Keyring::Alice, Keyring::Dave), (Keyring::Bob, Keyring::Dave)],
vec![(Keyring::Charlie, Keyring::Eve)],
vec![(AccountKeyring::Alice, AccountKeyring::Dave), (AccountKeyring::Bob, AccountKeyring::Dave)],
vec![(AccountKeyring::Charlie, AccountKeyring::Eve)],
vec![],
vec![(Keyring::Alice, Keyring::Dave)],
vec![(AccountKeyring::Alice, AccountKeyring::Dave)],
];

// prepare client ang import blocks
Expand All @@ -1555,8 +1554,8 @@ pub(crate) mod tests {
let mut builder = remote_client.new_block().unwrap();
for (from, to) in block_transfers {
builder.push_transfer(Transfer {
from: from.to_raw_public().into(),
to: to.to_raw_public().into(),
from: from.into(),
to: to.into(),
amount: 1,
nonce: *nonces.entry(from).and_modify(|n| { *n = *n + 1 }).or_default(),
}).unwrap();
Expand All @@ -1571,12 +1570,12 @@ pub(crate) mod tests {
}

// prepare test cases
let alice = twox_128(&runtime::system::balance_of_key(Keyring::Alice.to_raw_public().into())).to_vec();
let bob = twox_128(&runtime::system::balance_of_key(Keyring::Bob.to_raw_public().into())).to_vec();
let charlie = twox_128(&runtime::system::balance_of_key(Keyring::Charlie.to_raw_public().into())).to_vec();
let dave = twox_128(&runtime::system::balance_of_key(Keyring::Dave.to_raw_public().into())).to_vec();
let eve = twox_128(&runtime::system::balance_of_key(Keyring::Eve.to_raw_public().into())).to_vec();
let ferdie = twox_128(&runtime::system::balance_of_key(Keyring::Ferdie.to_raw_public().into())).to_vec();
let alice = twox_128(&runtime::system::balance_of_key(AccountKeyring::Alice.into())).to_vec();
let bob = twox_128(&runtime::system::balance_of_key(AccountKeyring::Bob.into())).to_vec();
let charlie = twox_128(&runtime::system::balance_of_key(AccountKeyring::Charlie.into())).to_vec();
let dave = twox_128(&runtime::system::balance_of_key(AccountKeyring::Dave.into())).to_vec();
let eve = twox_128(&runtime::system::balance_of_key(AccountKeyring::Eve.into())).to_vec();
let ferdie = twox_128(&runtime::system::balance_of_key(AccountKeyring::Ferdie.into())).to_vec();
let test_cases = vec![
(1, 4, alice.clone(), vec![(4, 0), (1, 0)]),
(1, 3, alice.clone(), vec![(1, 0)]),
Expand Down Expand Up @@ -1610,14 +1609,14 @@ pub(crate) mod tests {
assert_eq!(
client.runtime_api().balance_of(
&BlockId::Number(client.info().unwrap().chain.best_number),
Keyring::Alice.to_raw_public().into()
AccountKeyring::Alice.into()
).unwrap(),
1000
);
assert_eq!(
client.runtime_api().balance_of(
&BlockId::Number(client.info().unwrap().chain.best_number),
Keyring::Ferdie.to_raw_public().into()
AccountKeyring::Ferdie.into()
).unwrap(),
0
);
Expand All @@ -1629,9 +1628,9 @@ pub(crate) mod tests {

assert_eq!(client.info().unwrap().chain.best_number, 0);
assert_eq!(client.authorities_at(&BlockId::Number(0)).unwrap(), vec![
Keyring::Alice.to_raw_public().into(),
Keyring::Bob.to_raw_public().into(),
Keyring::Charlie.to_raw_public().into()
AuthorityKeyring::Alice.into(),
AuthorityKeyring::Bob.into(),
AuthorityKeyring::Charlie.into()
]);
}

Expand All @@ -1653,8 +1652,8 @@ pub(crate) mod tests {
let mut builder = client.new_block().unwrap();

builder.push_transfer(Transfer {
from: Keyring::Alice.to_raw_public().into(),
to: Keyring::Ferdie.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 42,
nonce: 0,
}).unwrap();
Expand All @@ -1666,14 +1665,14 @@ pub(crate) mod tests {
assert_eq!(
client.runtime_api().balance_of(
&BlockId::Number(client.info().unwrap().chain.best_number),
Keyring::Alice.to_raw_public().into()
AccountKeyring::Alice.into()
).unwrap(),
958
);
assert_eq!(
client.runtime_api().balance_of(
&BlockId::Number(client.info().unwrap().chain.best_number),
Keyring::Ferdie.to_raw_public().into()
AccountKeyring::Ferdie.into()
).unwrap(),
42
);
Expand All @@ -1695,15 +1694,15 @@ pub(crate) mod tests {
let mut builder = client.new_block().unwrap();

builder.push_transfer(Transfer {
from: Keyring::Alice.to_raw_public().into(),
to: Keyring::Ferdie.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 42,
nonce: 0,
}).unwrap();

assert!(builder.push_transfer(Transfer {
from: Keyring::Eve.to_raw_public().into(),
to: Keyring::Alice.to_raw_public().into(),
from: AccountKeyring::Eve.into(),
to: AccountKeyring::Alice.into(),
amount: 42,
nonce: 0,
}).is_err());
Expand Down Expand Up @@ -1789,8 +1788,8 @@ pub(crate) mod tests {
let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap();
// this push is required as otherwise B2 has the same hash as A2 and won't get imported
builder.push_transfer(Transfer {
from: Keyring::Alice.to_raw_public().into(),
to: Keyring::Ferdie.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 41,
nonce: 0,
}).unwrap();
Expand All @@ -1809,8 +1808,8 @@ pub(crate) mod tests {
let mut builder = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap();
// this push is required as otherwise C3 has the same hash as B3 and won't get imported
builder.push_transfer(Transfer {
from: Keyring::Alice.to_raw_public().into(),
to: Keyring::Ferdie.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 1,
}).unwrap();
Expand All @@ -1821,8 +1820,8 @@ pub(crate) mod tests {
let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap();
// this push is required as otherwise D2 has the same hash as B2 and won't get imported
builder.push_transfer(Transfer {
from: Keyring::Alice.to_raw_public().into(),
to: Keyring::Ferdie.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 0,
}).unwrap();
Expand Down Expand Up @@ -1910,8 +1909,8 @@ pub(crate) mod tests {
let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap();
// this push is required as otherwise B2 has the same hash as A2 and won't get imported
builder.push_transfer(Transfer {
from: Keyring::Alice.to_raw_public().into(),
to: Keyring::Ferdie.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 41,
nonce: 0,
}).unwrap();
Expand All @@ -1930,8 +1929,8 @@ pub(crate) mod tests {
let mut builder = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap();
// this push is required as otherwise C3 has the same hash as B3 and won't get imported
builder.push_transfer(Transfer {
from: Keyring::Alice.to_raw_public().into(),
to: Keyring::Ferdie.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 1,
}).unwrap();
Expand All @@ -1942,8 +1941,8 @@ pub(crate) mod tests {
let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap();
// this push is required as otherwise D2 has the same hash as B2 and won't get imported
builder.push_transfer(Transfer {
from: Keyring::Alice.to_raw_public().into(),
to: Keyring::Ferdie.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 0,
}).unwrap();
Expand Down
Loading