Skip to content

Commit

Permalink
Update ed25519-dalek to v2 (paritytech#1446)
Browse files Browse the repository at this point in the history
* Update to ed25519-dalek v2
* Update Cargo.lock
* Remove default features
* Update cumulus/bridges/primitives/test-utils/src/keyring.rs

Co-authored-by: Bastian Köcher <[email protected]>

---------

Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
chevdor and bkchr authored Sep 8, 2023
1 parent bce7c24 commit 92d7751
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 50 deletions.
35 changes: 6 additions & 29 deletions 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 cumulus/bridges/primitives/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bp-parachains = { path = "../parachains", default-features = false }
bp-polkadot-core = { path = "../polkadot-core", default-features = false }
bp-runtime = { path = "../runtime", default-features = false }
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
ed25519-dalek = { version = "1.0", default-features = false, features = ["u64_backend"] }
ed25519-dalek = { version = "2.0", default-features = false }
finality-grandpa = { version = "0.16.2", default-features = false }
sp-application-crypto = { path = "../../../../substrate/primitives/application-crypto", default-features = false }
sp-consensus-grandpa = { path = "../../../../substrate/primitives/consensus/grandpa", default-features = false }
Expand Down
24 changes: 5 additions & 19 deletions cumulus/bridges/primitives/test-utils/src/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use bp_header_chain::{justification::JustificationVerificationContext, AuthoritySet};
use codec::Encode;
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature};
use ed25519_dalek::{Signature, SigningKey, VerifyingKey};
use finality_grandpa::voter_set::VoterSet;
use sp_consensus_grandpa::{AuthorityId, AuthorityList, AuthorityWeight, SetId};
use sp_runtime::RuntimeDebug;
Expand All @@ -37,29 +37,15 @@ pub const FERDIE: Account = Account(5);
pub struct Account(pub u16);

impl Account {
pub fn public(&self) -> PublicKey {
(&self.secret()).into()
pub fn public(&self) -> VerifyingKey {
self.pair().verifying_key()
}

pub fn secret(&self) -> SecretKey {
pub fn pair(&self) -> SigningKey {
let data = self.0.encode();
let mut bytes = [0_u8; 32];
bytes[0..data.len()].copy_from_slice(&data);
SecretKey::from_bytes(&bytes)
.expect("A static array of the correct length is a known good.")
}

pub fn pair(&self) -> Keypair {
let mut pair: [u8; 64] = [0; 64];

let secret = self.secret();
pair[..32].copy_from_slice(&secret.to_bytes());

let public = self.public();
pair[32..].copy_from_slice(&public.to_bytes());

Keypair::from_bytes(&pair)
.expect("We expect the SecretKey to be good, so this must also be good.")
SigningKey::from_bytes(&bytes)
}

pub fn sign(&self, msg: &[u8]) -> Signature {
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tracing = { version = "0.1.29", default-features = false }
tracing-core = { version = "0.1.28", default-features = false}

# Required for backwards compatibility reason, but only used for verifying when `UseDalekExt` is set.
ed25519-dalek = { version = "2.0.0", default-features = false, optional = true }
ed25519-dalek = { version = "2.0", default-features = false, optional = true }

[build-dependencies]
rustversion = "1.0.6"
Expand Down

0 comments on commit 92d7751

Please sign in to comment.