Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
PR fixes and moving from sr25519 to ed25519 for account signatures
  • Loading branch information
bekolb committed Apr 1, 2019
commit 542d00073cb2ce6c8fda33336b2d40016d840db6
32 changes: 16 additions & 16 deletions runtime/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod tests {
use super::*;
use system;
use runtime_io::with_externalities;
use primitives::{H256, Blake2Hasher, sr25519};
use primitives::{H256, Blake2Hasher, ed25519 as x25519};
use primitives::*;
use support::{impl_outer_origin, assert_ok, assert_err};
use parity_codec::Encode;
Expand All @@ -131,7 +131,7 @@ mod tests {
type Hash = H256;
type Hashing = BlakeTwo256;
type Digest = Digest;
type AccountId = <sr25519::Signature as Verify>::Signer;
type AccountId = <x25519::Signature as Verify>::Signer;
type Header = Header;
type Event = ();
type Log = DigestItem;
Expand All @@ -142,8 +142,8 @@ mod tests {
}

impl delegation::Trait for Test {
type Signature = sr25519::Signature;
type Signer = <sr25519::Signature as Verify>::Signer;
type Signature = x25519::Signature;
type Signer = <x25519::Signature as Verify>::Signer;
type DelegationNodeId = H256;
fn print_hash(hash: Self::Hash) {
::runtime_io::print(&hash.as_bytes()[..]);
Expand All @@ -169,7 +169,7 @@ mod tests {
#[test]
fn check_add_attestation() {
with_externalities(&mut new_test_ext(), || {
let pair = sr25519::Pair::from_seed(*b"Alice ");
let pair = x25519::Pair::from_seed(*b"Alice ");
let hash = H256::from_low_u64_be(1);
let account_hash = pair.public();
assert_ok!(Ctype::add(Origin::signed(account_hash.clone()), hash.clone()));
Expand All @@ -184,7 +184,7 @@ mod tests {
#[test]
fn check_revoke_attestation() {
with_externalities(&mut new_test_ext(), || {
let pair = sr25519::Pair::from_seed(*b"Alice ");
let pair = x25519::Pair::from_seed(*b"Alice ");
let hash = H256::from_low_u64_be(1);
let account_hash = pair.public();
assert_ok!(Ctype::add(Origin::signed(account_hash.clone()), hash.clone()));
Expand All @@ -200,7 +200,7 @@ mod tests {
#[test]
fn check_double_attestation() {
with_externalities(&mut new_test_ext(), || {
let pair = sr25519::Pair::from_seed(*b"Alice ");
let pair = x25519::Pair::from_seed(*b"Alice ");
let hash = H256::from_low_u64_be(1);
let account_hash = pair.public();
assert_ok!(Ctype::add(Origin::signed(account_hash.clone()), hash.clone()));
Expand All @@ -212,7 +212,7 @@ mod tests {
#[test]
fn check_double_revoke_attestation() {
with_externalities(&mut new_test_ext(), || {
let pair = sr25519::Pair::from_seed(*b"Alice ");
let pair = x25519::Pair::from_seed(*b"Alice ");
let hash = H256::from_low_u64_be(1);
let account_hash = pair.public();
assert_ok!(Ctype::add(Origin::signed(account_hash.clone()), hash.clone()));
Expand All @@ -225,7 +225,7 @@ mod tests {
#[test]
fn check_revoke_unknown() {
with_externalities(&mut new_test_ext(), || {
let pair = sr25519::Pair::from_seed(*b"Alice ");
let pair = x25519::Pair::from_seed(*b"Alice ");
let hash = H256::from_low_u64_be(1);
let account_hash = pair.public();
assert_err!(Attestation::revoke(Origin::signed(account_hash.clone()), hash.clone()), "no valid attestation found");
Expand All @@ -235,9 +235,9 @@ mod tests {
#[test]
fn check_revoke_not_permitted() {
with_externalities(&mut new_test_ext(), || {
let pair_alice = sr25519::Pair::from_seed(*b"Alice ");
let pair_alice = x25519::Pair::from_seed(*b"Alice ");
let account_hash_alice = pair_alice.public();
let pair_bob = sr25519::Pair::from_seed(*b"Bob ");
let pair_bob = x25519::Pair::from_seed(*b"Bob ");
let account_hash_bob = pair_bob.public();
let hash = H256::from_low_u64_be(1);
assert_ok!(Ctype::add(Origin::signed(account_hash_alice.clone()), hash.clone()));
Expand All @@ -249,11 +249,11 @@ mod tests {
#[test]
fn check_add_attestation_with_delegation() {
with_externalities(&mut new_test_ext(), || {
let pair_alice = sr25519::Pair::from_seed(*b"Alice ");
let pair_alice = x25519::Pair::from_seed(*b"Alice ");
let account_hash_alice = pair_alice.public();
let pair_bob = sr25519::Pair::from_seed(*b"Bob ");
let pair_bob = x25519::Pair::from_seed(*b"Bob ");
let account_hash_bob = pair_bob.public();
let pair_charlie = sr25519::Pair::from_seed(*b"Charlie ");
let pair_charlie = x25519::Pair::from_seed(*b"Charlie ");
let account_hash_charlie = pair_charlie.public();

let ctype_hash = H256::from_low_u64_be(1);
Expand All @@ -272,11 +272,11 @@ mod tests {
assert_ok!(Delegation::create_root(Origin::signed(account_hash_alice.clone()), delegation_root.clone(), ctype_hash.clone()));
assert_ok!(Delegation::add_delegation(Origin::signed(account_hash_alice.clone()), delegation_1.clone(), delegation_root.clone(),
None, account_hash_bob.clone(), delegation::Permissions::DELEGATE,
sr25519::Signature::from(pair_bob.sign(&hash_to_u8(
x25519::Signature::from(pair_bob.sign(&hash_to_u8(
Delegation::calculate_hash(delegation_1.clone(), delegation_root.clone(), None, delegation::Permissions::DELEGATE))))));
assert_ok!(Delegation::add_delegation(Origin::signed(account_hash_alice.clone()), delegation_2.clone(), delegation_root.clone(),
None, account_hash_bob.clone(), delegation::Permissions::ATTEST,
sr25519::Signature::from(pair_bob.sign(&hash_to_u8(
x25519::Signature::from(pair_bob.sign(&hash_to_u8(
Delegation::calculate_hash(delegation_2.clone(), delegation_root.clone(), None, delegation::Permissions::ATTEST))))));

assert_err!(Attestation::add(Origin::signed(account_hash_bob.clone()), claim_hash.clone(), other_ctype_hash.clone(), Some(delegation_2)),
Expand Down
36 changes: 18 additions & 18 deletions runtime/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ mod tests {
use super::*;
use system;
use runtime_io::with_externalities;
use primitives::{H256, H512, Blake2Hasher, sr25519};
use primitives::{H256, H512, Blake2Hasher, ed25519 as x25519};
use primitives::*;
use support::{impl_outer_origin, assert_ok, assert_err};
use parity_codec::Encode;
Expand All @@ -246,7 +246,7 @@ mod tests {
type Hash = H256;
type Hashing = BlakeTwo256;
type Digest = Digest;
type AccountId = <sr25519::Signature as Verify>::Signer;
type AccountId = <x25519::Signature as Verify>::Signer;
type Header = Header;
type Event = ();
type Log = DigestItem;
Expand All @@ -257,8 +257,8 @@ mod tests {
}

impl Trait for Test {
type Signature = sr25519::Signature;
type Signer = <sr25519::Signature as Verify>::Signer;
type Signature = x25519::Signature;
type Signer = <x25519::Signature as Verify>::Signer;
type DelegationNodeId = H256;

fn print_hash(hash: Self::Hash) {
Expand All @@ -280,11 +280,11 @@ mod tests {
#[test]
fn check_add_and_revoke_delegations() {
with_externalities(&mut new_test_ext(), || {
let pair_alice = sr25519::Pair::from_seed(*b"Alice ");
let pair_alice = x25519::Pair::from_seed(*b"Alice ");
let account_hash_alice = pair_alice.public();
let pair_bob = sr25519::Pair::from_seed(*b"Bob ");
let pair_bob = x25519::Pair::from_seed(*b"Bob ");
let account_hash_bob = pair_bob.public();
let pair_charlie = sr25519::Pair::from_seed(*b"Charlie ");
let pair_charlie = x25519::Pair::from_seed(*b"Charlie ");
let account_hash_charlie = pair_charlie.public();

let ctype_hash = H256::from_low_u64_be(1);
Expand All @@ -304,57 +304,57 @@ mod tests {

assert_ok!(Delegation::add_delegation(Origin::signed(account_hash_alice.clone()), id_level_1.clone(), id_level_0.clone(),
None, account_hash_bob.clone(), Permissions::DELEGATE,
sr25519::Signature::from(pair_bob.sign(&hash_to_u8(
x25519::Signature::from(pair_bob.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_1.clone(), id_level_0.clone(), None, Permissions::DELEGATE))))));
assert_err!(Delegation::add_delegation(Origin::signed(account_hash_alice.clone()), id_level_1.clone(), id_level_0.clone(),
None, account_hash_bob.clone(), Permissions::DELEGATE,
sr25519::Signature::from(pair_bob.sign(&hash_to_u8(
x25519::Signature::from(pair_bob.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_1.clone(), id_level_0.clone(), None, Permissions::DELEGATE))))),
"delegation already exist");
assert_err!(Delegation::add_delegation(Origin::signed(account_hash_bob.clone()), id_level_2_1.clone(), id_level_0.clone(),
Some(id_level_1.clone()), account_hash_charlie.clone(), Permissions::ATTEST, sr25519::Signature::from_h512(H512::from_low_u64_be(0))),
Some(id_level_1.clone()), account_hash_charlie.clone(), Permissions::ATTEST, x25519::Signature::from_h512(H512::from_low_u64_be(0))),
"bad delegate signature");
assert_err!(Delegation::add_delegation(Origin::signed(account_hash_charlie.clone()), id_level_2_1.clone(), id_level_0.clone(),
None, account_hash_bob.clone(), Permissions::DELEGATE,
sr25519::Signature::from(pair_bob.sign(&hash_to_u8(
x25519::Signature::from(pair_bob.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_2_1.clone(), id_level_0.clone(), None, Permissions::DELEGATE))))),
"not owner of root");
assert_err!(Delegation::add_delegation(Origin::signed(account_hash_alice.clone()), id_level_2_1.clone(), id_level_1.clone(),
None, account_hash_bob.clone(), Permissions::DELEGATE,
sr25519::Signature::from(pair_bob.sign(&hash_to_u8(
x25519::Signature::from(pair_bob.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_2_1.clone(), id_level_1.clone(), None, Permissions::DELEGATE))))),
"root not found");


assert_ok!(Delegation::add_delegation(Origin::signed(account_hash_bob.clone()), id_level_2_1.clone(), id_level_0.clone(),
Some(id_level_1.clone()), account_hash_charlie.clone(), Permissions::ATTEST,
sr25519::Signature::from(pair_charlie.sign(&hash_to_u8(
x25519::Signature::from(pair_charlie.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_2_1.clone(), id_level_0.clone(), Some(id_level_1.clone()), Permissions::ATTEST))))));
assert_err!(Delegation::add_delegation(Origin::signed(account_hash_alice.clone()), id_level_2_2.clone(), id_level_0.clone(),
Some(id_level_1.clone()), account_hash_charlie.clone(), Permissions::ATTEST,
sr25519::Signature::from(pair_charlie.sign(&hash_to_u8(
x25519::Signature::from(pair_charlie.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_2_2.clone(), id_level_0.clone(), Some(id_level_1.clone()), Permissions::ATTEST))))),
"not owner of parent");
assert_err!(Delegation::add_delegation(Origin::signed(account_hash_charlie.clone()), id_level_2_2.clone(), id_level_0.clone(),
Some(id_level_2_1.clone()), account_hash_alice.clone(), Permissions::ATTEST,
sr25519::Signature::from(pair_alice.sign(&hash_to_u8(
x25519::Signature::from(pair_alice.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_2_2.clone(), id_level_0.clone(), Some(id_level_2_1.clone()), Permissions::ATTEST))))),
"not authorized to delegate");
assert_err!(Delegation::add_delegation(Origin::signed(account_hash_bob.clone()), id_level_2_2.clone(), id_level_0.clone(),
Some(id_level_0.clone()), account_hash_charlie.clone(), Permissions::ATTEST,
sr25519::Signature::from(pair_charlie.sign(&hash_to_u8(
x25519::Signature::from(pair_charlie.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_2_2.clone(), id_level_0.clone(), Some(id_level_0.clone()), Permissions::ATTEST))))),
"parent not found");

assert_ok!(Delegation::add_delegation(Origin::signed(account_hash_bob.clone()), id_level_2_2.clone(), id_level_0.clone(),
Some(id_level_1.clone()), account_hash_charlie.clone(), Permissions::ATTEST | Permissions::DELEGATE,
sr25519::Signature::from(pair_charlie.sign(&hash_to_u8(
x25519::Signature::from(pair_charlie.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_2_2.clone(), id_level_0.clone(), Some(id_level_1.clone()),
Permissions::ATTEST | Permissions::DELEGATE))))));

assert_ok!(Delegation::add_delegation(Origin::signed(account_hash_charlie.clone()), id_level_2_2_1.clone(), id_level_0.clone(),
Some(id_level_2_2.clone()), account_hash_alice.clone(), Permissions::ATTEST,
sr25519::Signature::from(pair_alice.sign(&hash_to_u8(
x25519::Signature::from(pair_alice.sign(&hash_to_u8(
Delegation::calculate_hash(id_level_2_2_1.clone(), id_level_0.clone(), Some(id_level_2_2.clone()), Permissions::ATTEST))))));


Expand Down
6 changes: 3 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use parity_codec::{Encode, Decode};
use rstd::prelude::*;
#[cfg(feature = "std")]
use primitives::bytes;
use primitives::{ed25519, sr25519, OpaqueMetadata};
use primitives::{ed25519, ed25519 as x25519, OpaqueMetadata};
use runtime_primitives::{
ApplyResult, transaction_validity::TransactionValidity, generic, create_runtime_str,
traits::{self, BlakeTwo256, Block as BlockT, StaticLookup, Verify}
Expand Down Expand Up @@ -51,8 +51,8 @@ pub type AuthoritySignature = ed25519::Signature;
/// Alias to pubkey that identifies an account on the chain.
pub type AccountId = <AccountSignature as Verify>::Signer;

/// The type used by authorities to prove their ID.
pub type AccountSignature = sr25519::Signature;
/// The type used by accounts to prove their ID.
pub type AccountSignature = x25519::Signature;

/// A hash of some data used by the chain.
pub type Hash = primitives::H256;
Expand Down
4 changes: 2 additions & 2 deletions src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use primitives::{ed25519, sr25519, Pair};
use primitives::{ed25519, ed25519 as x25519, Pair};
use node_template_runtime::{
AccountId, GenesisConfig, ConsensusConfig, TimestampConfig, BalancesConfig,
SudoConfig, IndicesConfig,
Expand Down Expand Up @@ -31,7 +31,7 @@ fn authority_key(s: &str) -> AuthorityId {
}

fn account_key(s: &str) -> AccountId {
sr25519::Pair::from_string(&format!("//{}", s), None)
x25519::Pair::from_string(&format!("//{}", s), None)
.expect("static values are valid; qed")
.public()
}
Expand Down