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

Switch to using ss58-registry crate #9755

Merged
merged 33 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b90ebf2
Switch to using ss58-registry crate
gilescope Sep 11, 2021
ca992a0
cargo fmt
gilescope Sep 11, 2021
1d83da4
putting Default back in its rightful place again.
gilescope Sep 13, 2021
03d225d
Merge branch 'master' into giles-use-ss58-crate
gilescope Sep 13, 2021
0cdcf00
Point to official repo
gilescope Sep 13, 2021
26ad354
Merge branch 'giles-use-ss58-crate' of github.com:gilescope/substrate…
gilescope Sep 13, 2021
029df8a
default
gilescope Sep 13, 2021
1c91881
Tidying
gilescope Sep 14, 2021
5818927
Using latest version
gilescope Sep 16, 2021
59b1d48
Merge branch 'master' into giles-use-ss58-crate
gilescope Sep 17, 2021
9405402
Merge branch 'master' into giles-use-ss58-crate
gilescope Sep 28, 2021
2d067e4
no dep on debug derive
gilescope Sep 28, 2021
80a988e
Rename
gilescope Sep 28, 2021
6695493
cargo fmt
gilescope Sep 28, 2021
c238a69
Updating due to rename
gilescope Oct 1, 2021
0da6f7d
point to main again
gilescope Oct 4, 2021
ecf7207
cargo fmt
gilescope Oct 4, 2021
107669e
Merge branch 'master' into giles-use-ss58-crate
gilescope Oct 4, 2021
075e3be
Don't re-export ss58registry types.
gilescope Oct 4, 2021
c8b5cfb
Revert "Don't re-export ss58registry types."
gilescope Oct 6, 2021
661eec9
Merge branch 'master' into giles-use-ss58-crate
gilescope Oct 6, 2021
bf54d99
Update primitives/core/src/crypto.rs
gilescope Oct 6, 2021
ae9fe51
reference crates.io
gilescope Oct 7, 2021
06c6649
Merge branch 'giles-use-ss58-crate' of github.com:gilescope/substrate…
gilescope Oct 7, 2021
4d2f4aa
bump ss58-registry version
gilescope Oct 8, 2021
0943458
updating lock file
gilescope Oct 8, 2021
8eaf3d2
Merge branch 'master' into giles-use-ss58-crate
gilescope Oct 8, 2021
879ea51
Merge branch 'master' into giles-use-ss58-crate
gilescope Oct 9, 2021
64ecffa
Update primitives/core/src/crypto.rs
gilescope Oct 11, 2021
8dc2772
Update primitives/core/src/crypto.rs
gilescope Oct 11, 2021
3334062
Update primitives/core/src/crypto.rs
gilescope Oct 11, 2021
a7ecede
Update primitives/core/src/crypto.rs
gilescope Oct 11, 2021
6c7e95f
Update primitives/core/src/crypto.rs
gilescope Oct 11, 2021
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
15 changes: 15 additions & 0 deletions Cargo.lock

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

11 changes: 7 additions & 4 deletions client/cli/src/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use crate::{
};
use serde_json::json;
use sp_core::{
crypto::{ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec, Zeroize},
crypto::{
unwrap_or_default_ss58_version, ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec,
Zeroize,
},
hexdisplay::HexDisplay,
Pair,
};
Expand Down Expand Up @@ -72,7 +75,7 @@ pub fn print_from_uri<Pair>(
let password = password.as_ref().map(|s| s.expose_secret().as_str());
if let Ok((pair, seed)) = Pair::from_phrase(uri, password.clone()) {
let public_key = pair.public();
let network_override = network_override.unwrap_or_default();
let network_override = unwrap_or_default_ss58_version(network_override);

match output {
OutputType::Json => {
Expand Down Expand Up @@ -108,7 +111,7 @@ pub fn print_from_uri<Pair>(
}
} else if let Ok((pair, seed)) = Pair::from_string_with_seed(uri, password.clone()) {
let public_key = pair.public();
let network_override = network_override.unwrap_or_default();
let network_override = unwrap_or_default_ss58_version(network_override);

match output {
OutputType::Json => {
Expand Down Expand Up @@ -198,7 +201,7 @@ where
let public_key = Pair::Public::try_from(&public)
.map_err(|_| "Failed to construct public key from given hex")?;

let network_override = network_override.unwrap_or_default();
let network_override = unwrap_or_default_ss58_version(network_override);

match output {
OutputType::Json => {
Expand Down
20 changes: 14 additions & 6 deletions client/cli/src/commands/vanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
error, utils, with_crypto_scheme, CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag,
};
use rand::{rngs::OsRng, RngCore};
use sp_core::crypto::{Ss58AddressFormat, Ss58Codec};
use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec};
use sp_runtime::traits::IdentifyAccount;
use structopt::StructOpt;
use utils::print_from_uri;
Expand Down Expand Up @@ -53,7 +53,10 @@ impl VanityCmd {
pub fn run(&self) -> error::Result<()> {
let formated_seed = with_crypto_scheme!(
self.crypto_scheme.scheme,
generate_key(&self.pattern, self.network_scheme.network.clone().unwrap_or_default()),
generate_key(
&self.pattern,
unwrap_or_default_ss58_version(self.network_scheme.network)
),
)?;

with_crypto_scheme!(
Expand Down Expand Up @@ -159,7 +162,10 @@ fn assert_non_empty_string(pattern: &str) -> Result<String, &'static str> {
#[cfg(test)]
mod tests {
use super::*;
use sp_core::{crypto::Ss58Codec, sr25519, Pair};
use sp_core::{
crypto::{default_ss58_version, Ss58AddressFormatRegistry, Ss58Codec},
sr25519, Pair,
};
use structopt::StructOpt;
#[cfg(feature = "bench")]
use test::Bencher;
Expand All @@ -172,7 +178,7 @@ mod tests {

#[test]
fn test_generation_with_single_char() {
let seed = generate_key::<sr25519::Pair>("ab", Default::default()).unwrap();
let seed = generate_key::<sr25519::Pair>("ab", default_ss58_version()).unwrap();
assert!(sr25519::Pair::from_seed_slice(&hex::decode(&seed[2..]).unwrap())
.unwrap()
.public()
Expand All @@ -182,11 +188,13 @@ mod tests {

#[test]
fn generate_key_respects_network_override() {
let seed = generate_key::<sr25519::Pair>("ab", Ss58AddressFormat::PolkadotAccount).unwrap();
let seed =
generate_key::<sr25519::Pair>("ab", Ss58AddressFormatRegistry::PolkadotAccount.into())
.unwrap();
assert!(sr25519::Pair::from_seed_slice(&hex::decode(&seed[2..]).unwrap())
.unwrap()
.public()
.to_ss58check_with_version(Ss58AddressFormat::PolkadotAccount)
.to_ss58check_with_version(Ss58AddressFormatRegistry::PolkadotAccount.into())
.contains("ab"));
}

Expand Down
2 changes: 1 addition & 1 deletion primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ hex = { version = "0.4", default-features = false, optional = true }
twox-hash = { version = "1.6.1", default-features = false, optional = true }
libsecp256k1 = { version = "0.6", default-features = false, features = ["hmac", "static-context"], optional = true }
merlin = { version = "2.0", default-features = false, optional = true }

ss58-registry = "1.0.0"
sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" }

[dev-dependencies]
Expand Down
Loading