From b90ebf298a94a95b14a4d564fb3932ed60174a2d Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Sat, 11 Sep 2021 12:56:03 +0100 Subject: [PATCH 01/24] Switch to using ss58-registry crate --- Cargo.lock | 12 ++ primitives/core/Cargo.toml | 2 + primitives/core/src/crypto.rs | 279 +--------------------------------- 3 files changed, 19 insertions(+), 274 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 101338f2b274e..040b067e79323 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9017,6 +9017,7 @@ dependencies = [ "sp-serializer", "sp-std", "sp-storage", + "ss58-registry", "substrate-bip39", "thiserror", "tiny-bip39", @@ -9528,6 +9529,17 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "ss58-registry" +version = "0.1.0" +source = "git+https://github.com/gilescope/ss58-registry.git?branch=initial#1a454cc533a4bdda26308ec4c662e85355c850a1" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_json", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index add7da81c3fff..a608f2c951d5d 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -64,6 +64,8 @@ hex = { version = "0.4", default-features = false, optional = true } twox-hash = { version = "1.5.0", 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 = { git = "https://github.com/gilescope/ss58-registry.git", branch = "initial" } +# ss58-registry = { path = "/home/gilescope/git/ss58-registry-fork" } sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" } diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 5346ea66fe8ae..578207398c24e 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -26,8 +26,6 @@ use crate::{ed25519, sr25519}; use base58::{FromBase58, ToBase58}; use codec::{Decode, Encode, MaxEncodedLen}; #[cfg(feature = "std")] -use parking_lot::Mutex; -#[cfg(feature = "std")] use rand::{rngs::OsRng, RngCore}; #[cfg(feature = "std")] use regex::Regex; @@ -37,8 +35,6 @@ pub use secrecy::ExposeSecret; #[cfg(feature = "std")] pub use secrecy::SecretString; use sp_runtime_interface::pass_by::PassByInner; -#[cfg(feature = "std")] -use sp_std::convert::TryInto; #[doc(hidden)] pub use sp_std::ops::Deref; use sp_std::{convert::TryFrom, hash::Hash, str, vec::Vec}; @@ -234,7 +230,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { fn from_ss58check(s: &str) -> Result { Self::from_ss58check_with_version(s).and_then(|(r, v)| match v { v if !v.is_custom() => Ok(r), - v if v == *DEFAULT_VERSION.lock() => Ok(r), + v if v.is_default() => Ok(r), _ => Err(PublicError::UnknownVersion), }) } @@ -269,7 +265,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { if data.len() != prefix_len + body_len + CHECKSUM_LEN { return Err(PublicError::BadLength) } - let format = ident.try_into().map_err(|_: ()| PublicError::UnknownVersion)?; + let format = ident.into(); if !Self::format_is_allowed(format) { return Err(PublicError::FormatNotAllowed) } @@ -290,7 +286,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { fn from_string(s: &str) -> Result { Self::from_string_with_version(s).and_then(|(r, v)| match v { v if !v.is_custom() => Ok(r), - v if v == *DEFAULT_VERSION.lock() => Ok(r), + v if v.is_default() => Ok(r), _ => Err(PublicError::UnknownVersion), }) } @@ -321,7 +317,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { /// Return the ss58-check string for this key. #[cfg(feature = "std")] fn to_ss58check(&self) -> String { - self.to_ss58check_with_version(*DEFAULT_VERSION.lock()) + self.to_ss58check_with_version(Ss58AddressFormat::default()) } /// Some if the string is a properly encoded SS58Check address, optionally with @@ -354,275 +350,10 @@ fn ss58hash(data: &[u8]) -> blake2_rfc::blake2b::Blake2bResult { context.finalize() } -#[cfg(feature = "std")] -lazy_static::lazy_static! { - static ref DEFAULT_VERSION: Mutex - = Mutex::new(Ss58AddressFormat::SubstrateAccount); -} - #[cfg(feature = "full_crypto")] -macro_rules! ss58_address_format { - ( $( $identifier:tt => ($number:expr, $name:expr, $desc:tt) )* ) => ( - /// A known address (sub)format/network ID for SS58. - #[derive(Copy, Clone, PartialEq, Eq, crate::RuntimeDebug)] - pub enum Ss58AddressFormat { - $(#[doc = $desc] $identifier),*, - /// Use a manually provided numeric value as a standard identifier - Custom(u16), - } - - #[cfg(feature = "std")] - impl std::fmt::Display for Ss58AddressFormat { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self { - $( - Ss58AddressFormat::$identifier => write!(f, "{}", $name), - )* - Ss58AddressFormat::Custom(x) => write!(f, "{}", x), - } - - } - } - - static ALL_SS58_ADDRESS_FORMATS: [Ss58AddressFormat; 0 $(+ { let _ = $number; 1})*] = [ - $(Ss58AddressFormat::$identifier),*, - ]; - - impl Ss58AddressFormat { - /// names of all address formats - pub fn all_names() -> &'static [&'static str] { - &[ - $($name),*, - ] - } - /// All known address formats. - pub fn all() -> &'static [Ss58AddressFormat] { - &ALL_SS58_ADDRESS_FORMATS - } - - /// Whether the address is custom. - pub fn is_custom(&self) -> bool { - matches!(self, Self::Custom(_)) - } - } - - impl TryFrom for Ss58AddressFormat { - type Error = (); - - fn try_from(x: u8) -> Result { - Ss58AddressFormat::try_from(x as u16) - } - } - - impl From for u16 { - fn from(x: Ss58AddressFormat) -> u16 { - match x { - $(Ss58AddressFormat::$identifier => $number),*, - Ss58AddressFormat::Custom(n) => n, - } - } - } - - impl TryFrom for Ss58AddressFormat { - type Error = (); - - fn try_from(x: u16) -> Result { - match x { - $($number => Ok(Ss58AddressFormat::$identifier)),*, - _ => Ok(Ss58AddressFormat::Custom(x)), - } - } - } - - /// Error encountered while parsing `Ss58AddressFormat` from &'_ str - /// unit struct for now. - #[derive(Copy, Clone, PartialEq, Eq, crate::RuntimeDebug)] - pub struct ParseError; - - impl<'a> TryFrom<&'a str> for Ss58AddressFormat { - type Error = ParseError; - - fn try_from(x: &'a str) -> Result { - match x { - $($name => Ok(Ss58AddressFormat::$identifier)),*, - a => a.parse::().map(Ss58AddressFormat::Custom).map_err(|_| ParseError), - } - } - } - - #[cfg(feature = "std")] - impl std::str::FromStr for Ss58AddressFormat { - type Err = ParseError; - - fn from_str(data: &str) -> Result { - Self::try_from(data) - } - } - - #[cfg(feature = "std")] - impl std::fmt::Display for ParseError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "failed to parse network value as u8") - } - } +ss58_registry::ss58_registry!(); - #[cfg(feature = "std")] - impl Default for Ss58AddressFormat { - fn default() -> Self { - *DEFAULT_VERSION.lock() - } - } - - #[cfg(feature = "std")] - impl From for String { - fn from(x: Ss58AddressFormat) -> String { - x.to_string() - } - } - ) -} -#[cfg(feature = "full_crypto")] -ss58_address_format!( - PolkadotAccount => - (0, "polkadot", "Polkadot Relay-chain, standard account (*25519).") - BareSr25519 => - (1, "sr25519", "Bare 32-bit Schnorr/Ristretto 25519 (S/R 25519) key.") - KusamaAccount => - (2, "kusama", "Kusama Relay-chain, standard account (*25519).") - BareEd25519 => - (3, "ed25519", "Bare 32-bit Edwards Ed25519 key.") - KatalChainAccount => - (4, "katalchain", "Katal Chain, standard account (*25519).") - PlasmAccount => - (5, "plasm", "Plasm Network, standard account (*25519).") - BifrostAccount => - (6, "bifrost", "Bifrost mainnet, direct checksum, standard account (*25519).") - EdgewareAccount => - (7, "edgeware", "Edgeware mainnet, standard account (*25519).") - KaruraAccount => - (8, "karura", "Acala Karura canary network, standard account (*25519).") - ReynoldsAccount => - (9, "reynolds", "Laminar Reynolds canary network, standard account (*25519).") - AcalaAccount => - (10, "acala", "Acala mainnet, standard account (*25519).") - LaminarAccount => - (11, "laminar", "Laminar mainnet, standard account (*25519).") - PolymathAccount => - (12, "polymath", "Polymath network, standard account (*25519).") - SubstraTeeAccount => - (13, "substratee", "Any SubstraTEE off-chain network private account (*25519).") - TotemAccount => - (14, "totem", "Any Totem Live Accounting network standard account (*25519).") - SynesthesiaAccount => - (15, "synesthesia", "Synesthesia mainnet, standard account (*25519).") - KulupuAccount => - (16, "kulupu", "Kulupu mainnet, standard account (*25519).") - DarkAccount => - (17, "dark", "Dark mainnet, standard account (*25519).") - DarwiniaAccount => - (18, "darwinia", "Darwinia Chain mainnet, standard account (*25519).") - GeekAccount => - (19, "geek", "GeekCash mainnet, standard account (*25519).") - StafiAccount => - (20, "stafi", "Stafi mainnet, standard account (*25519).") - DockTestAccount => - (21, "dock-testnet", "Dock testnet, standard account (*25519).") - DockMainAccount => - (22, "dock-mainnet", "Dock mainnet, standard account (*25519).") - ShiftNrg => - (23, "shift", "ShiftNrg mainnet, standard account (*25519).") - ZeroAccount => - (24, "zero", "ZERO mainnet, standard account (*25519).") - AlphavilleAccount => - (25, "alphaville", "ZERO testnet, standard account (*25519).") - JupiterAccount => - (26, "jupiter", "Jupiter testnet, standard account (*25519).") - SubsocialAccount => - (28, "subsocial", "Subsocial network, standard account (*25519).") - DhiwayAccount => - (29, "cord", "Dhiway CORD network, standard account (*25519).") - PhalaAccount => - (30, "phala", "Phala Network, standard account (*25519).") - LitentryAccount => - (31, "litentry", "Litentry Network, standard account (*25519).") - RobonomicsAccount => - (32, "robonomics", "Any Robonomics network standard account (*25519).") - DataHighwayAccount => - (33, "datahighway", "DataHighway mainnet, standard account (*25519).") - AresAccount => - (34, "ares", "Ares Protocol, standard account (*25519).") - ValiuAccount => - (35, "vln", "Valiu Liquidity Network mainnet, standard account (*25519).") - CentrifugeAccount => - (36, "centrifuge", "Centrifuge Chain mainnet, standard account (*25519).") - NodleAccount => - (37, "nodle", "Nodle Chain mainnet, standard account (*25519).") - KiltAccount => - (38, "kilt", "KILT Chain mainnet, standard account (*25519).") - PolimecAccount => - (41, "poli", "Polimec Chain mainnet, standard account (*25519).") - SubstrateAccount => - (42, "substrate", "Any Substrate network, standard account (*25519).") - BareSecp256k1 => - (43, "secp256k1", "Bare ECDSA SECP256k1 key.") - ChainXAccount => - (44, "chainx", "ChainX mainnet, standard account (*25519).") - UniartsAccount => - (45, "uniarts", "UniArts Chain mainnet, standard account (*25519).") - Reserved46 => - (46, "reserved46", "Reserved for future use (46).") - Reserved47 => - (47, "reserved47", "Reserved for future use (47).") - NeatcoinAccount => - (48, "neatcoin", "Neatcoin mainnet, standard account (*25519).") - HydraDXAccount => - (63, "hydradx", "HydraDX standard account (*25519).") - AventusAccount => - (65, "aventus", "Aventus Chain mainnet, standard account (*25519).") - CrustAccount => - (66, "crust", "Crust Network, standard account (*25519).") - EquilibriumAccount => - (67, "equilibrium", "Equilibrium Network, standard account (*25519).") - SoraAccount => - (69, "sora", "SORA Network, standard account (*25519).") - ZeitgeistAccount => - (73, "zeitgeist", "Zeitgeist network, standard account (*25519).") - MantaAccount => - (77, "manta", "Manta Network, standard account (*25519).") - CalamariAccount => - (78, "calamari", "Manta Canary Network, standard account (*25519).") - PolkaSmith => - (98, "polkasmith", "PolkaSmith Canary Network, standard account (*25519).") - PolkaFoundry => - (99, "polkafoundry", "PolkaFoundry Network, standard account (*25519).") - OriginTrailAccount => - (101, "origintrail-parachain", "OriginTrail Parachain, ethereumm account (ECDSA).") - HeikoAccount => - (110, "heiko", "Heiko, session key (*25519).") - ParallelAccount => - (172, "parallel", "Parallel, session key (*25519).") - SocialAccount => - (252, "social-network", "Social Network, standard account (*25519).") - Moonbeam => - (1284, "moonbeam", "Moonbeam, session key (*25519).") - Moonriver => - (1285, "moonriver", "Moonriver, session key (*25519).") - BasiliskAccount => - (10041, "basilisk", "Basilisk standard account (*25519).") - - // Note: 16384 and above are reserved. -); - -/// Set the default "version" (actually, this is a bit of a misnomer and the version byte is -/// typically used not just to encode format/version but also network identity) that is used for -/// encoding and decoding SS58 addresses. If an unknown version is provided then it fails. -/// -/// See `ss58_address_format!` for all current known "versions". -#[cfg(feature = "std")] -pub fn set_default_ss58_version(version: Ss58AddressFormat) { - *DEFAULT_VERSION.lock() = version -} #[cfg(feature = "std")] lazy_static::lazy_static! { From ca992a0b4e39534dbfc31bcc9e0b0701a850446f Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Sat, 11 Sep 2021 14:41:47 +0100 Subject: [PATCH 02/24] cargo fmt --- primitives/core/src/crypto.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 578207398c24e..9bf3bbdcf7139 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -353,8 +353,6 @@ fn ss58hash(data: &[u8]) -> blake2_rfc::blake2b::Blake2bResult { #[cfg(feature = "full_crypto")] ss58_registry::ss58_registry!(); - - #[cfg(feature = "std")] lazy_static::lazy_static! { static ref SS58_REGEX: Regex = Regex::new(r"^(?P[\w\d ]+)?(?P(//?[^/]+)*)$") From 1d83da49248a35cb01c893c4c532bdeb69edb1e1 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Mon, 13 Sep 2021 11:28:52 +0100 Subject: [PATCH 03/24] putting Default back in its rightful place again. --- Cargo.lock | 2 +- primitives/core/src/crypto.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 040b067e79323..16e0b3b93a234 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9532,7 +9532,7 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" version = "0.1.0" -source = "git+https://github.com/gilescope/ss58-registry.git?branch=initial#1a454cc533a4bdda26308ec4c662e85355c850a1" +source = "git+https://github.com/gilescope/ss58-registry.git?branch=initial#f69aab473e10eee62abcf5f23b5a6930a880b494" dependencies = [ "proc-macro2", "quote", diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 9bf3bbdcf7139..b6dbbe7c749ff 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -353,6 +353,26 @@ fn ss58hash(data: &[u8]) -> blake2_rfc::blake2b::Blake2bResult { #[cfg(feature = "full_crypto")] ss58_registry::ss58_registry!(); +/// Default prefix number +#[cfg(feature = "std")] +static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = core::sync::atomic::AtomicU16::new(42 /*substrate*/); + +#[cfg(feature = "std")] +impl Default for Ss58AddressFormat { + fn default() -> Self { + DEFAULT_VERSION.load(core::sync::atomic::Ordering::Relaxed).into() + } +} + +/// Set the default "version" (actually, this is a bit of a misnomer and the version byte is +/// typically used not just to encode format/version but also network identity) that is used for +/// encoding and decoding SS58 addresses. +#[cfg(feature = "std")] +pub fn set_default_ss58_version(new_default: Ss58AddressFormat) { + let prefix : u16 = new_default.into(); + DEFAULT_VERSION.store(prefix, core::sync::atomic::Ordering::Relaxed); +} + #[cfg(feature = "std")] lazy_static::lazy_static! { static ref SS58_REGEX: Regex = Regex::new(r"^(?P[\w\d ]+)?(?P(//?[^/]+)*)$") From 0cdcf0094c3c9ef068d14403a8c157220f25d17e Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Mon, 13 Sep 2021 14:17:58 +0100 Subject: [PATCH 04/24] Point to official repo --- Cargo.lock | 2 +- primitives/core/Cargo.toml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16e0b3b93a234..c265bab13c3af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9532,7 +9532,7 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" version = "0.1.0" -source = "git+https://github.com/gilescope/ss58-registry.git?branch=initial#f69aab473e10eee62abcf5f23b5a6930a880b494" +source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#eb35165bce10aea8494f26180ad46120d90ec13f" dependencies = [ "proc-macro2", "quote", diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index a608f2c951d5d..4a5dcf41580bb 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -64,8 +64,7 @@ hex = { version = "0.4", default-features = false, optional = true } twox-hash = { version = "1.5.0", 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 = { git = "https://github.com/gilescope/ss58-registry.git", branch = "initial" } -# ss58-registry = { path = "/home/gilescope/git/ss58-registry-fork" } +ss58-registry = { git = "https://github.com/paritytech/ss58-registry.git", branch = "main" } sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" } From 029df8ab40670f4bc935f2108d2f0db85c7701ab Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Mon, 13 Sep 2021 21:25:10 +0100 Subject: [PATCH 05/24] default --- Cargo.lock | 28 ++++++++++++++++--- client/cli/src/commands/utils.rs | 11 +++++--- client/cli/src/commands/vanity.rs | 11 +++++--- primitives/core/src/crypto.rs | 26 ++++++++++------- primitives/core/src/ecdsa.rs | 2 +- .../frame-utilities-cli/src/pallet_id.rs | 4 +-- 6 files changed, 57 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 866fec6d621d0..3b63fe787d669 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8807,7 +8807,7 @@ dependencies = [ "primitive-types", "rand 0.7.3", "serde", - "sp-debug-derive", + "sp-debug-derive 3.0.0", "sp-std", "static_assertions", ] @@ -8991,7 +8991,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.9.3", - "sp-debug-derive", + "sp-debug-derive 3.0.0", "sp-externalities", "sp-runtime-interface", "sp-serializer", @@ -9024,6 +9024,17 @@ dependencies = [ "syn", ] +[[package]] +name = "sp-debug-derive" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e80275f23b4e7ba8f54dec5f90f016530e7307d2ee9445f617ab986cbe97f31e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sp-externalities" version = "0.10.0-dev" @@ -9367,7 +9378,7 @@ dependencies = [ "parity-scale-codec", "ref-cast", "serde", - "sp-debug-derive", + "sp-debug-derive 3.0.0", "sp-std", ] @@ -9511,8 +9522,17 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" +version = "0.0.1" +source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#42cbe266388405fbf6971148328feaf9c13a1f5e" +dependencies = [ + "sp-debug-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ss58-registry-derive", +] + +[[package]] +name = "ss58-registry-derive" version = "0.1.0" -source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#eb35165bce10aea8494f26180ad46120d90ec13f" +source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#42cbe266388405fbf6971148328feaf9c13a1f5e" dependencies = [ "proc-macro2", "quote", diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 864d7e920f81a..3a6f5cd56d76d 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -23,7 +23,10 @@ use crate::{ }; use serde_json::json; use sp_core::{ - crypto::{ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec, Zeroize}, + crypto::{ + unwrap_or_ss58_address_format, ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec, + Zeroize, + }, hexdisplay::HexDisplay, Pair, }; @@ -72,7 +75,7 @@ pub fn print_from_uri( 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_ss58_address_format(network_override); match output { OutputType::Json => { @@ -108,7 +111,7 @@ pub fn print_from_uri( } } 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_ss58_address_format(network_override); match output { OutputType::Json => { @@ -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_ss58_address_format(network_override); match output { OutputType::Json => { diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index daeb81e86a1a1..5997b0b9e341f 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -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_ss58_address_format, Ss58AddressFormat, Ss58Codec}; use sp_runtime::traits::IdentifyAccount; use structopt::StructOpt; use utils::print_from_uri; @@ -53,7 +53,7 @@ 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_ss58_address_format(self.network_scheme.network)), )?; with_crypto_scheme!( @@ -159,7 +159,10 @@ fn assert_non_empty_string(pattern: &str) -> Result { #[cfg(test)] mod tests { use super::*; - use sp_core::{crypto::Ss58Codec, sr25519, Pair}; + use sp_core::{ + crypto::{ss58_address_format, Ss58Codec}, + sr25519, Pair, + }; use structopt::StructOpt; #[cfg(feature = "bench")] use test::Bencher; @@ -172,7 +175,7 @@ mod tests { #[test] fn test_generation_with_single_char() { - let seed = generate_key::("ab", Default::default()).unwrap(); + let seed = generate_key::("ab", ss58_address_format()).unwrap(); assert!(sr25519::Pair::from_seed_slice(&hex::decode(&seed[2..]).unwrap()) .unwrap() .public() diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index b6dbbe7c749ff..1952fbb7c486a 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -230,7 +230,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { fn from_ss58check(s: &str) -> Result { Self::from_ss58check_with_version(s).and_then(|(r, v)| match v { v if !v.is_custom() => Ok(r), - v if v.is_default() => Ok(r), + v if v == ss58_address_format() => Ok(r), _ => Err(PublicError::UnknownVersion), }) } @@ -286,7 +286,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { fn from_string(s: &str) -> Result { Self::from_string_with_version(s).and_then(|(r, v)| match v { v if !v.is_custom() => Ok(r), - v if v.is_default() => Ok(r), + v if v == ss58_address_format() => Ok(r), _ => Err(PublicError::UnknownVersion), }) } @@ -317,7 +317,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { /// Return the ss58-check string for this key. #[cfg(feature = "std")] fn to_ss58check(&self) -> String { - self.to_ss58check_with_version(Ss58AddressFormat::default()) + self.to_ss58check_with_version(ss58_address_format()) } /// Some if the string is a properly encoded SS58Check address, optionally with @@ -351,17 +351,23 @@ fn ss58hash(data: &[u8]) -> blake2_rfc::blake2b::Blake2bResult { } #[cfg(feature = "full_crypto")] -ss58_registry::ss58_registry!(); +pub use ss58_registry::Ss58AddressFormat; /// Default prefix number #[cfg(feature = "std")] -static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = core::sync::atomic::AtomicU16::new(42 /*substrate*/); +static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = + core::sync::atomic::AtomicU16::new(Ss58AddressFormat::Substrate.into()); +/// Returns default(). (can't impl Default due to orphan rules). #[cfg(feature = "std")] -impl Default for Ss58AddressFormat { - fn default() -> Self { - DEFAULT_VERSION.load(core::sync::atomic::Ordering::Relaxed).into() - } +pub fn ss58_address_format() -> Ss58AddressFormat { + DEFAULT_VERSION.load(core::sync::atomic::Ordering::Relaxed).into() +} + +/// Returns either the input address format or the default. +#[cfg(feature = "std")] +pub fn unwrap_or_ss58_address_format(network: Option) -> Ss58AddressFormat { + network.unwrap_or_else(|| DEFAULT_VERSION.load(core::sync::atomic::Ordering::Relaxed).into()) } /// Set the default "version" (actually, this is a bit of a misnomer and the version byte is @@ -369,7 +375,7 @@ impl Default for Ss58AddressFormat { /// encoding and decoding SS58 addresses. #[cfg(feature = "std")] pub fn set_default_ss58_version(new_default: Ss58AddressFormat) { - let prefix : u16 = new_default.into(); + let prefix: u16 = new_default.into(); DEFAULT_VERSION.store(prefix, core::sync::atomic::Ordering::Relaxed); } diff --git a/primitives/core/src/ecdsa.rs b/primitives/core/src/ecdsa.rs index 147569d52b89f..a2132adbbb2f9 100644 --- a/primitives/core/src/ecdsa.rs +++ b/primitives/core/src/ecdsa.rs @@ -804,7 +804,7 @@ mod test { if std::env::var("RUN_CUSTOM_FORMAT_TEST") == Ok("1".into()) { use crate::crypto::Ss58AddressFormat; // temp save default format version - let default_format = Ss58AddressFormat::default(); + let default_format = crate::crypto::ss58_address_format(); // set current ss58 version is custom "200" `Ss58AddressFormat::Custom(200)` set_default_ss58_version(Ss58AddressFormat::Custom(200)); diff --git a/utils/frame/frame-utilities-cli/src/pallet_id.rs b/utils/frame/frame-utilities-cli/src/pallet_id.rs index 2caac7db588a9..e0345a2c4e9cb 100644 --- a/utils/frame/frame-utilities-cli/src/pallet_id.rs +++ b/utils/frame/frame-utilities-cli/src/pallet_id.rs @@ -22,7 +22,7 @@ use sc_cli::{ utils::print_from_uri, with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams, OutputTypeFlag, }; -use sp_core::crypto::{Ss58AddressFormat, Ss58Codec}; +use sp_core::crypto::{unwrap_or_ss58_address_format, Ss58AddressFormat, Ss58Codec}; use sp_runtime::traits::AccountIdConversion; use std::convert::{TryFrom, TryInto}; use structopt::StructOpt; @@ -78,7 +78,7 @@ impl PalletIdCmd { with_crypto_scheme!( self.crypto_scheme.scheme, print_from_uri( - &account_id.to_ss58check_with_version(self.network.clone().unwrap_or_default()), + &account_id.to_ss58check_with_version(unwrap_or_ss58_address_format(self.network)), password, self.network, self.output_scheme.output_type.clone() From 1c918818bc4d22f7a053e16e7dc0d58c531baec5 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Tue, 14 Sep 2021 13:37:19 +0100 Subject: [PATCH 06/24] Tidying --- primitives/core/src/crypto.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 1952fbb7c486a..92be3ff19ae43 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -222,7 +222,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { /// A format filterer, can be used to ensure that `from_ss58check` family only decode for /// allowed identifiers. By default just refuses the two reserved identifiers. fn format_is_allowed(f: Ss58AddressFormat) -> bool { - !matches!(f, Ss58AddressFormat::Reserved46 | Ss58AddressFormat::Reserved47) + !f.is_reserved() } /// Some if the string is a properly encoded SS58Check address. @@ -351,12 +351,12 @@ fn ss58hash(data: &[u8]) -> blake2_rfc::blake2b::Blake2bResult { } #[cfg(feature = "full_crypto")] -pub use ss58_registry::Ss58AddressFormat; +pub use ss58_registry::{from_address_format, Ss58AddressFormat}; /// Default prefix number #[cfg(feature = "std")] static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = - core::sync::atomic::AtomicU16::new(Ss58AddressFormat::Substrate.into()); + core::sync::atomic::AtomicU16::new(from_address_format(Ss58AddressFormat::SubstrateAccount)); /// Returns default(). (can't impl Default due to orphan rules). #[cfg(feature = "std")] From 58189279f9e1eece1d8dbdbefccc40d400c441c8 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Thu, 16 Sep 2021 14:09:22 +0100 Subject: [PATCH 07/24] Using latest version --- Cargo.lock | 13 +++---------- client/cli/src/commands/vanity.rs | 8 +++++--- primitives/core/Cargo.toml | 4 ++-- primitives/core/src/crypto.rs | 7 ++++--- primitives/core/src/ecdsa.rs | 12 ++++++------ 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b63fe787d669..9fe66e054a039 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9523,21 +9523,14 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" version = "0.0.1" -source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#42cbe266388405fbf6971148328feaf9c13a1f5e" -dependencies = [ - "sp-debug-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ss58-registry-derive", -] - -[[package]] -name = "ss58-registry-derive" -version = "0.1.0" -source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#42cbe266388405fbf6971148328feaf9c13a1f5e" +source = "git+https://github.com/paritytech/ss58-registry.git?branch=vNext#a8b5944eaded74b496399d1bbbb3d87d90bd5dad" dependencies = [ + "Inflector", "proc-macro2", "quote", "serde", "serde_json", + "sp-debug-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index 5997b0b9e341f..d3aaf5ac77e9a 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -160,7 +160,7 @@ fn assert_non_empty_string(pattern: &str) -> Result { mod tests { use super::*; use sp_core::{ - crypto::{ss58_address_format, Ss58Codec}, + crypto::{ss58_address_format, KnownSs58AddressFormat, Ss58Codec}, sr25519, Pair, }; use structopt::StructOpt; @@ -185,11 +185,13 @@ mod tests { #[test] fn generate_key_respects_network_override() { - let seed = generate_key::("ab", Ss58AddressFormat::PolkadotAccount).unwrap(); + let seed = + generate_key::("ab", KnownSs58AddressFormat::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(KnownSs58AddressFormat::PolkadotAccount.into()) .contains("ab")); } diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index 4a5dcf41580bb..ea0d52dd1c406 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -64,8 +64,8 @@ hex = { version = "0.4", default-features = false, optional = true } twox-hash = { version = "1.5.0", 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 = { git = "https://github.com/paritytech/ss58-registry.git", branch = "main" } - +ss58-registry = { git = "https://github.com/paritytech/ss58-registry.git", branch = "vNext"} +# ss58-registry = { path = "/home/gilescope/git/ss58-registry-fork"} sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" } [dev-dependencies] diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 92be3ff19ae43..463b1ded2f14c 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -351,12 +351,13 @@ fn ss58hash(data: &[u8]) -> blake2_rfc::blake2b::Blake2bResult { } #[cfg(feature = "full_crypto")] -pub use ss58_registry::{from_address_format, Ss58AddressFormat}; +pub use ss58_registry::{from_known_address_format, KnownSs58AddressFormat, Ss58AddressFormat}; /// Default prefix number #[cfg(feature = "std")] -static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = - core::sync::atomic::AtomicU16::new(from_address_format(Ss58AddressFormat::SubstrateAccount)); +static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = core::sync::atomic::AtomicU16::new( + from_known_address_format(KnownSs58AddressFormat::SubstrateAccount), +); /// Returns default(). (can't impl Default due to orphan rules). #[cfg(feature = "std")] diff --git a/primitives/core/src/ecdsa.rs b/primitives/core/src/ecdsa.rs index a2132adbbb2f9..ff584006ee3d3 100644 --- a/primitives/core/src/ecdsa.rs +++ b/primitives/core/src/ecdsa.rs @@ -771,26 +771,26 @@ mod test { #[test] fn ss58check_format_check_works() { - use crate::crypto::Ss58AddressFormat; + use crate::crypto::KnownSs58AddressFormat; let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); - let format = Ss58AddressFormat::Reserved46; + let format = KnownSs58AddressFormat::Reserved46Account.into(); let s = public.to_ss58check_with_version(format); assert_eq!(Public::from_ss58check_with_version(&s), Err(PublicError::FormatNotAllowed)); } #[test] fn ss58check_full_roundtrip_works() { - use crate::crypto::Ss58AddressFormat; + use crate::crypto::{KnownSs58AddressFormat, Ss58AddressFormat}; let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); - let format = Ss58AddressFormat::PolkadotAccount; + let format = KnownSs58AddressFormat::PolkadotAccount.into(); let s = public.to_ss58check_with_version(format); let (k, f) = Public::from_ss58check_with_version(&s).unwrap(); assert_eq!(k, public); assert_eq!(f, format); - let format = Ss58AddressFormat::Custom(64); + let format = Ss58AddressFormat::custom(64); let s = public.to_ss58check_with_version(format); let (k, f) = Public::from_ss58check_with_version(&s).unwrap(); assert_eq!(k, public); @@ -807,7 +807,7 @@ mod test { let default_format = crate::crypto::ss58_address_format(); // set current ss58 version is custom "200" `Ss58AddressFormat::Custom(200)` - set_default_ss58_version(Ss58AddressFormat::Custom(200)); + set_default_ss58_version(Ss58AddressFormat::custom(200)); // custom addr encoded by version 200 let addr = "4pbsSkWcBaYoFHrKJZp5fDVUKbqSYD9dhZZGvpp3vQ5ysVs5ybV"; Public::from_ss58check(&addr).unwrap(); From 2d067e4c6eb15740705259aa1ab46b99459f9425 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Tue, 28 Sep 2021 13:20:34 +0100 Subject: [PATCH 08/24] no dep on debug derive --- Cargo.lock | 21 +++++---------------- primitives/core/Cargo.toml | 1 - 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4fb7d98da8e77..7e468b3c92586 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9152,7 +9152,7 @@ dependencies = [ "rand 0.7.3", "scale-info", "serde", - "sp-debug-derive 3.0.0", + "sp-debug-derive", "sp-std", "static_assertions", ] @@ -9341,7 +9341,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.9.3", - "sp-debug-derive 3.0.0", + "sp-debug-derive", "sp-externalities", "sp-runtime-interface", "sp-serializer", @@ -9374,17 +9374,6 @@ dependencies = [ "syn", ] -[[package]] -name = "sp-debug-derive" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e80275f23b4e7ba8f54dec5f90f016530e7307d2ee9445f617ab986cbe97f31e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "sp-externalities" version = "0.10.0-dev" @@ -9734,7 +9723,7 @@ dependencies = [ "parity-scale-codec", "ref-cast", "serde", - "sp-debug-derive 3.0.0", + "sp-debug-derive", "sp-std", ] @@ -9882,14 +9871,14 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" version = "0.0.1" -source = "git+https://github.com/paritytech/ss58-registry.git?branch=vNext#a8b5944eaded74b496399d1bbbb3d87d90bd5dad" +source = "git+https://github.com/paritytech/ss58-registry.git?branch=vNext#9817131f32b43e07c722e3b4ba10664a4cbc2b45" dependencies = [ "Inflector", "proc-macro2", "quote", "serde", "serde_json", - "sp-debug-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid", ] [[package]] diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index 30cd535055a03..2ef0fe6ec9c9f 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -67,7 +67,6 @@ twox-hash = { version = "1.5.0", 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 = { git = "https://github.com/paritytech/ss58-registry.git", branch = "vNext"} -# ss58-registry = { path = "/home/gilescope/git/ss58-registry-fork"} sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" } [dev-dependencies] From 80a988e556959e008aafab263ae40cc55e885876 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Tue, 28 Sep 2021 13:28:19 +0100 Subject: [PATCH 09/24] Rename --- client/cli/src/commands/utils.rs | 8 ++++---- client/cli/src/commands/vanity.rs | 8 ++++---- primitives/core/src/crypto.rs | 10 +++++----- primitives/core/src/ecdsa.rs | 2 +- utils/frame/frame-utilities-cli/src/pallet_id.rs | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 3a6f5cd56d76d..39e5149404b29 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -24,7 +24,7 @@ use crate::{ use serde_json::json; use sp_core::{ crypto::{ - unwrap_or_ss58_address_format, ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec, + unwrap_or_default_ss58_version, ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec, Zeroize, }, hexdisplay::HexDisplay, @@ -75,7 +75,7 @@ pub fn print_from_uri( 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 = unwrap_or_ss58_address_format(network_override); + let network_override = unwrap_or_default_ss58_version(network_override); match output { OutputType::Json => { @@ -111,7 +111,7 @@ pub fn print_from_uri( } } else if let Ok((pair, seed)) = Pair::from_string_with_seed(uri, password.clone()) { let public_key = pair.public(); - let network_override = unwrap_or_ss58_address_format(network_override); + let network_override = unwrap_or_default_ss58_version(network_override); match output { OutputType::Json => { @@ -201,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 = unwrap_or_ss58_address_format(network_override); + let network_override = unwrap_or_default_ss58_version(network_override); match output { OutputType::Json => { diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index d3aaf5ac77e9a..f11d7671038f6 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -22,7 +22,7 @@ use crate::{ error, utils, with_crypto_scheme, CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag, }; use rand::{rngs::OsRng, RngCore}; -use sp_core::crypto::{unwrap_or_ss58_address_format, 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; @@ -53,7 +53,7 @@ impl VanityCmd { pub fn run(&self) -> error::Result<()> { let formated_seed = with_crypto_scheme!( self.crypto_scheme.scheme, - generate_key(&self.pattern, unwrap_or_ss58_address_format(self.network_scheme.network)), + generate_key(&self.pattern, unwrap_or_default_ss58_version(self.network_scheme.network)), )?; with_crypto_scheme!( @@ -160,7 +160,7 @@ fn assert_non_empty_string(pattern: &str) -> Result { mod tests { use super::*; use sp_core::{ - crypto::{ss58_address_format, KnownSs58AddressFormat, Ss58Codec}, + crypto::{default_ss58_version, KnownSs58AddressFormat, Ss58Codec}, sr25519, Pair, }; use structopt::StructOpt; @@ -175,7 +175,7 @@ mod tests { #[test] fn test_generation_with_single_char() { - let seed = generate_key::("ab", ss58_address_format()).unwrap(); + let seed = generate_key::("ab", default_ss58_version()).unwrap(); assert!(sr25519::Pair::from_seed_slice(&hex::decode(&seed[2..]).unwrap()) .unwrap() .public() diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 97a850bc54eaa..9d670d68f15c0 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -231,7 +231,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { fn from_ss58check(s: &str) -> Result { Self::from_ss58check_with_version(s).and_then(|(r, v)| match v { v if !v.is_custom() => Ok(r), - v if v == ss58_address_format() => Ok(r), + v if v == default_ss58_version() => Ok(r), _ => Err(PublicError::UnknownVersion), }) } @@ -287,7 +287,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { fn from_string(s: &str) -> Result { Self::from_string_with_version(s).and_then(|(r, v)| match v { v if !v.is_custom() => Ok(r), - v if v == ss58_address_format() => Ok(r), + v if v == default_ss58_version() => Ok(r), _ => Err(PublicError::UnknownVersion), }) } @@ -318,7 +318,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default { /// Return the ss58-check string for this key. #[cfg(feature = "std")] fn to_ss58check(&self) -> String { - self.to_ss58check_with_version(ss58_address_format()) + self.to_ss58check_with_version(default_ss58_version()) } /// Some if the string is a properly encoded SS58Check address, optionally with @@ -362,13 +362,13 @@ static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = core::sync::atomic::Atom /// Returns default(). (can't impl Default due to orphan rules). #[cfg(feature = "std")] -pub fn ss58_address_format() -> Ss58AddressFormat { +pub fn default_ss58_version() -> Ss58AddressFormat { DEFAULT_VERSION.load(core::sync::atomic::Ordering::Relaxed).into() } /// Returns either the input address format or the default. #[cfg(feature = "std")] -pub fn unwrap_or_ss58_address_format(network: Option) -> Ss58AddressFormat { +pub fn unwrap_or_default_ss58_version(network: Option) -> Ss58AddressFormat { network.unwrap_or_else(|| DEFAULT_VERSION.load(core::sync::atomic::Ordering::Relaxed).into()) } diff --git a/primitives/core/src/ecdsa.rs b/primitives/core/src/ecdsa.rs index 02d03cbcf6da3..015ca7b273ea4 100644 --- a/primitives/core/src/ecdsa.rs +++ b/primitives/core/src/ecdsa.rs @@ -805,7 +805,7 @@ mod test { if std::env::var("RUN_CUSTOM_FORMAT_TEST") == Ok("1".into()) { use crate::crypto::Ss58AddressFormat; // temp save default format version - let default_format = crate::crypto::ss58_address_format(); + let default_format = crate::crypto::default_ss58_version(); // set current ss58 version is custom "200" `Ss58AddressFormat::Custom(200)` set_default_ss58_version(Ss58AddressFormat::custom(200)); diff --git a/utils/frame/frame-utilities-cli/src/pallet_id.rs b/utils/frame/frame-utilities-cli/src/pallet_id.rs index e0345a2c4e9cb..d173f52b39cd8 100644 --- a/utils/frame/frame-utilities-cli/src/pallet_id.rs +++ b/utils/frame/frame-utilities-cli/src/pallet_id.rs @@ -22,7 +22,7 @@ use sc_cli::{ utils::print_from_uri, with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams, OutputTypeFlag, }; -use sp_core::crypto::{unwrap_or_ss58_address_format, Ss58AddressFormat, Ss58Codec}; +use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec}; use sp_runtime::traits::AccountIdConversion; use std::convert::{TryFrom, TryInto}; use structopt::StructOpt; @@ -78,7 +78,7 @@ impl PalletIdCmd { with_crypto_scheme!( self.crypto_scheme.scheme, print_from_uri( - &account_id.to_ss58check_with_version(unwrap_or_ss58_address_format(self.network)), + &account_id.to_ss58check_with_version(unwrap_or_default_ss58_version(self.network)), password, self.network, self.output_scheme.output_type.clone() From 66954930846b113173fc2f525f0d73900e286066 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Tue, 28 Sep 2021 13:43:30 +0100 Subject: [PATCH 10/24] cargo fmt --- client/cli/src/commands/vanity.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index f11d7671038f6..c56765367c39d 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -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, unwrap_or_default_ss58_version(self.network_scheme.network)), + generate_key( + &self.pattern, + unwrap_or_default_ss58_version(self.network_scheme.network) + ), )?; with_crypto_scheme!( From c238a695e4ce924c65841058838360f14a9c8f2d Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Fri, 1 Oct 2021 07:10:21 +0100 Subject: [PATCH 11/24] Updating due to rename --- client/cli/src/commands/vanity.rs | 6 +++--- primitives/core/src/crypto.rs | 8 ++++---- primitives/core/src/ecdsa.rs | 8 +++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index c56765367c39d..d2953c8396079 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -163,7 +163,7 @@ fn assert_non_empty_string(pattern: &str) -> Result { mod tests { use super::*; use sp_core::{ - crypto::{default_ss58_version, KnownSs58AddressFormat, Ss58Codec}, + crypto::{default_ss58_version, Ss58AddressFormatRegistry, Ss58Codec}, sr25519, Pair, }; use structopt::StructOpt; @@ -189,12 +189,12 @@ mod tests { #[test] fn generate_key_respects_network_override() { let seed = - generate_key::("ab", KnownSs58AddressFormat::PolkadotAccount.into()) + generate_key::("ab", Ss58AddressFormatRegistry::PolkadotAccount.into()) .unwrap(); assert!(sr25519::Pair::from_seed_slice(&hex::decode(&seed[2..]).unwrap()) .unwrap() .public() - .to_ss58check_with_version(KnownSs58AddressFormat::PolkadotAccount.into()) + .to_ss58check_with_version(Ss58AddressFormatRegistry::PolkadotAccount.into()) .contains("ab")); } diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 9d670d68f15c0..0f60fb4b714b5 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -42,6 +42,9 @@ use sp_std::{convert::TryFrom, hash::Hash, str, vec::Vec}; /// Trait to zeroize a memory buffer. pub use zeroize::Zeroize; +#[cfg(feature = "full_crypto")] +pub use ss58_registry::{from_known_address_format, Ss58AddressFormatRegistry, Ss58AddressFormat}; + /// The root phrase for our publicly known keys. pub const DEV_PHRASE: &str = "bottom drive obey lake curtain smoke basket hold race lonely fit walk"; @@ -351,13 +354,10 @@ fn ss58hash(data: &[u8]) -> blake2_rfc::blake2b::Blake2bResult { context.finalize() } -#[cfg(feature = "full_crypto")] -pub use ss58_registry::{from_known_address_format, KnownSs58AddressFormat, Ss58AddressFormat}; - /// Default prefix number #[cfg(feature = "std")] static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = core::sync::atomic::AtomicU16::new( - from_known_address_format(KnownSs58AddressFormat::SubstrateAccount), + from_known_address_format(Ss58AddressFormatRegistry::SubstrateAccount), ); /// Returns default(). (can't impl Default due to orphan rules). diff --git a/primitives/core/src/ecdsa.rs b/primitives/core/src/ecdsa.rs index 015ca7b273ea4..6f1568158a806 100644 --- a/primitives/core/src/ecdsa.rs +++ b/primitives/core/src/ecdsa.rs @@ -640,7 +640,7 @@ impl CryptoType for Pair { mod test { use super::*; use crate::{ - crypto::{set_default_ss58_version, PublicError, DEV_PHRASE}, + crypto::{set_default_ss58_version, PublicError, DEV_PHRASE, Ss58AddressFormat, Ss58AddressFormatRegistry}, keccak_256, }; use hex_literal::hex; @@ -772,20 +772,18 @@ mod test { #[test] fn ss58check_format_check_works() { - use crate::crypto::KnownSs58AddressFormat; let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); - let format = KnownSs58AddressFormat::Reserved46Account.into(); + let format = Ss58AddressFormatRegistry::Reserved46Account.into(); let s = public.to_ss58check_with_version(format); assert_eq!(Public::from_ss58check_with_version(&s), Err(PublicError::FormatNotAllowed)); } #[test] fn ss58check_full_roundtrip_works() { - use crate::crypto::{KnownSs58AddressFormat, Ss58AddressFormat}; let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); - let format = KnownSs58AddressFormat::PolkadotAccount.into(); + let format = Ss58AddressFormatRegistry::PolkadotAccount.into(); let s = public.to_ss58check_with_version(format); let (k, f) = Public::from_ss58check_with_version(&s).unwrap(); assert_eq!(k, public); From 0da6f7ddf35dc1c7fe485eb38c7245fa8fa3ff2c Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Mon, 4 Oct 2021 10:18:18 +0100 Subject: [PATCH 12/24] point to main again --- Cargo.lock | 2 +- primitives/core/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e468b3c92586..1557bb7a4445a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9871,7 +9871,7 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" version = "0.0.1" -source = "git+https://github.com/paritytech/ss58-registry.git?branch=vNext#9817131f32b43e07c722e3b4ba10664a4cbc2b45" +source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#3327f12c9bbd659636ba7e1e63eeb40e647d550e" dependencies = [ "Inflector", "proc-macro2", diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index 2ef0fe6ec9c9f..e73a4b185ded2 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -66,7 +66,7 @@ hex = { version = "0.4", default-features = false, optional = true } twox-hash = { version = "1.5.0", 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 = { git = "https://github.com/paritytech/ss58-registry.git", branch = "vNext"} +ss58-registry = { git = "https://github.com/paritytech/ss58-registry.git", branch = "main" } sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" } [dev-dependencies] From ecf7207f4755be374add05b761f110e392b8e8c2 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Mon, 4 Oct 2021 10:32:36 +0100 Subject: [PATCH 13/24] cargo fmt --- primitives/core/src/crypto.rs | 2 +- primitives/core/src/ecdsa.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 0f60fb4b714b5..986a4e4d77c18 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -43,7 +43,7 @@ use sp_std::{convert::TryFrom, hash::Hash, str, vec::Vec}; pub use zeroize::Zeroize; #[cfg(feature = "full_crypto")] -pub use ss58_registry::{from_known_address_format, Ss58AddressFormatRegistry, Ss58AddressFormat}; +pub use ss58_registry::{from_known_address_format, Ss58AddressFormat, Ss58AddressFormatRegistry}; /// The root phrase for our publicly known keys. pub const DEV_PHRASE: &str = diff --git a/primitives/core/src/ecdsa.rs b/primitives/core/src/ecdsa.rs index 6f1568158a806..2751a0c40e3e5 100644 --- a/primitives/core/src/ecdsa.rs +++ b/primitives/core/src/ecdsa.rs @@ -640,7 +640,10 @@ impl CryptoType for Pair { mod test { use super::*; use crate::{ - crypto::{set_default_ss58_version, PublicError, DEV_PHRASE, Ss58AddressFormat, Ss58AddressFormatRegistry}, + crypto::{ + set_default_ss58_version, PublicError, Ss58AddressFormat, Ss58AddressFormatRegistry, + DEV_PHRASE, + }, keccak_256, }; use hex_literal::hex; From 075e3bed1620d0d041cf1a92e4abf4d74356ea45 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Mon, 4 Oct 2021 12:03:49 +0100 Subject: [PATCH 14/24] Don't re-export ss58registry types. --- Cargo.lock | 4 +++- client/cli/Cargo.toml | 1 + client/cli/src/commands/utils.rs | 6 ++---- client/cli/src/commands/vanity.rs | 6 ++++-- client/cli/src/params/mod.rs | 2 +- primitives/core/Cargo.toml | 2 +- primitives/core/src/crypto.rs | 2 +- primitives/core/src/ecdsa.rs | 8 +++----- utils/frame/frame-utilities-cli/Cargo.toml | 1 + utils/frame/frame-utilities-cli/src/pallet_id.rs | 3 ++- 10 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7cfc4522012a..f2bc19f0bf410 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7604,6 +7604,7 @@ dependencies = [ "sp-panic-handler", "sp-runtime", "sp-version", + "ss58-registry", "structopt", "tempfile", "thiserror", @@ -9876,7 +9877,7 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" version = "0.0.1" -source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#3327f12c9bbd659636ba7e1e63eeb40e647d550e" +source = "git+https://github.com/paritytech/ss58-registry.git#3327f12c9bbd659636ba7e1e63eeb40e647d550e" dependencies = [ "Inflector", "proc-macro2", @@ -10026,6 +10027,7 @@ dependencies = [ "sc-cli", "sp-core", "sp-runtime", + "ss58-registry", "structopt", ] diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index e7a0330e76e0c..57ccb81c21b98 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -44,6 +44,7 @@ chrono = "0.4.10" serde = "1.0.126" thiserror = "1.0.21" rpassword = "5.0.0" +ss58-registry = { git="https://github.com/paritytech/ss58-registry.git" } [dev-dependencies] tempfile = "3.1.0" diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 39e5149404b29..61aeb4194c375 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -23,14 +23,12 @@ use crate::{ }; use serde_json::json; use sp_core::{ - crypto::{ - unwrap_or_default_ss58_version, ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec, - Zeroize, - }, + crypto::{unwrap_or_default_ss58_version, ExposeSecret, SecretString, Ss58Codec, Zeroize}, hexdisplay::HexDisplay, Pair, }; use sp_runtime::{traits::IdentifyAccount, MultiSigner}; +use ss58_registry::Ss58AddressFormat; use std::{convert::TryFrom, io::Read, path::PathBuf}; /// Public key type for Runtime diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index d2953c8396079..3540a94cff504 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -22,8 +22,9 @@ use crate::{ error, utils, with_crypto_scheme, CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag, }; use rand::{rngs::OsRng, RngCore}; -use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec}; +use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58Codec}; use sp_runtime::traits::IdentifyAccount; +use ss58_registry::Ss58AddressFormat; use structopt::StructOpt; use utils::print_from_uri; @@ -163,9 +164,10 @@ fn assert_non_empty_string(pattern: &str) -> Result { mod tests { use super::*; use sp_core::{ - crypto::{default_ss58_version, Ss58AddressFormatRegistry, Ss58Codec}, + crypto::{default_ss58_version, Ss58Codec}, sr25519, Pair, }; + use ss58_registry::Ss58AddressFormatRegistry; use structopt::StructOpt; #[cfg(feature = "bench")] use test::Bencher; diff --git a/client/cli/src/params/mod.rs b/client/cli/src/params/mod.rs index dac832a1f897c..f8b206216b203 100644 --- a/client/cli/src/params/mod.rs +++ b/client/cli/src/params/mod.rs @@ -26,11 +26,11 @@ mod shared_params; mod transaction_pool_params; use crate::arg_enums::{CryptoScheme, OutputType}; -use sp_core::crypto::Ss58AddressFormat; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, NumberFor}, }; +use ss58_registry::Ss58AddressFormat; use std::{convert::TryFrom, fmt::Debug, str::FromStr}; use structopt::StructOpt; diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index e73a4b185ded2..178d3b4dbe2dd 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -66,7 +66,7 @@ hex = { version = "0.4", default-features = false, optional = true } twox-hash = { version = "1.5.0", 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 = { git = "https://github.com/paritytech/ss58-registry.git", branch = "main" } +ss58-registry = { git = "https://github.com/paritytech/ss58-registry.git" } sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" } [dev-dependencies] diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 986a4e4d77c18..b2ffe32a0a613 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -43,7 +43,7 @@ use sp_std::{convert::TryFrom, hash::Hash, str, vec::Vec}; pub use zeroize::Zeroize; #[cfg(feature = "full_crypto")] -pub use ss58_registry::{from_known_address_format, Ss58AddressFormat, Ss58AddressFormatRegistry}; +use ss58_registry::{from_known_address_format, Ss58AddressFormat, Ss58AddressFormatRegistry}; /// The root phrase for our publicly known keys. pub const DEV_PHRASE: &str = diff --git a/primitives/core/src/ecdsa.rs b/primitives/core/src/ecdsa.rs index 2751a0c40e3e5..b75b9db38c4cc 100644 --- a/primitives/core/src/ecdsa.rs +++ b/primitives/core/src/ecdsa.rs @@ -640,14 +640,12 @@ impl CryptoType for Pair { mod test { use super::*; use crate::{ - crypto::{ - set_default_ss58_version, PublicError, Ss58AddressFormat, Ss58AddressFormatRegistry, - DEV_PHRASE, - }, + crypto::{set_default_ss58_version, PublicError, DEV_PHRASE}, keccak_256, }; use hex_literal::hex; use serde_json; + use ss58_registry::{Ss58AddressFormat, Ss58AddressFormatRegistry}; #[test] fn default_phrase_should_be_used() { @@ -804,7 +802,7 @@ mod test { // We need to run this test in its own process to not interfere with other tests running in // parallel and also relying on the ss58 version. if std::env::var("RUN_CUSTOM_FORMAT_TEST") == Ok("1".into()) { - use crate::crypto::Ss58AddressFormat; + use ss58_registry::Ss58AddressFormat; // temp save default format version let default_format = crate::crypto::default_ss58_version(); // set current ss58 version is custom "200" `Ss58AddressFormat::Custom(200)` diff --git a/utils/frame/frame-utilities-cli/Cargo.toml b/utils/frame/frame-utilities-cli/Cargo.toml index 1b6597fc9f2fc..b5322d6bd381e 100644 --- a/utils/frame/frame-utilities-cli/Cargo.toml +++ b/utils/frame/frame-utilities-cli/Cargo.toml @@ -17,6 +17,7 @@ sp-runtime = { version = "4.0.0-dev", path = "../../../primitives/runtime" } structopt = "0.3.8" frame-system = { version = "4.0.0-dev", path = "../../../frame/system" } frame-support = { version = "4.0.0-dev", path = "../../../frame/support" } +ss58-registry = { git="https://github.com/paritytech/ss58-registry.git" } [dev-dependencies] diff --git a/utils/frame/frame-utilities-cli/src/pallet_id.rs b/utils/frame/frame-utilities-cli/src/pallet_id.rs index d173f52b39cd8..fe131aa2f299a 100644 --- a/utils/frame/frame-utilities-cli/src/pallet_id.rs +++ b/utils/frame/frame-utilities-cli/src/pallet_id.rs @@ -22,8 +22,9 @@ use sc_cli::{ utils::print_from_uri, with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams, OutputTypeFlag, }; -use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec}; +use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58Codec}; use sp_runtime::traits::AccountIdConversion; +use ss58_registry::Ss58AddressFormat; use std::convert::{TryFrom, TryInto}; use structopt::StructOpt; From c8b5cfbff00622798917268f56bafa1cf42cea7a Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Wed, 6 Oct 2021 07:04:25 +0100 Subject: [PATCH 15/24] Revert "Don't re-export ss58registry types." This reverts commit 075e3bed1620d0d041cf1a92e4abf4d74356ea45. --- Cargo.lock | 4 +--- client/cli/Cargo.toml | 1 - client/cli/src/commands/utils.rs | 6 ++++-- client/cli/src/commands/vanity.rs | 6 ++---- client/cli/src/params/mod.rs | 2 +- primitives/core/Cargo.toml | 2 +- primitives/core/src/crypto.rs | 2 +- primitives/core/src/ecdsa.rs | 8 +++++--- utils/frame/frame-utilities-cli/Cargo.toml | 1 - utils/frame/frame-utilities-cli/src/pallet_id.rs | 3 +-- 10 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2bc19f0bf410..c7cfc4522012a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7604,7 +7604,6 @@ dependencies = [ "sp-panic-handler", "sp-runtime", "sp-version", - "ss58-registry", "structopt", "tempfile", "thiserror", @@ -9877,7 +9876,7 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" version = "0.0.1" -source = "git+https://github.com/paritytech/ss58-registry.git#3327f12c9bbd659636ba7e1e63eeb40e647d550e" +source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#3327f12c9bbd659636ba7e1e63eeb40e647d550e" dependencies = [ "Inflector", "proc-macro2", @@ -10027,7 +10026,6 @@ dependencies = [ "sc-cli", "sp-core", "sp-runtime", - "ss58-registry", "structopt", ] diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 57ccb81c21b98..e7a0330e76e0c 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -44,7 +44,6 @@ chrono = "0.4.10" serde = "1.0.126" thiserror = "1.0.21" rpassword = "5.0.0" -ss58-registry = { git="https://github.com/paritytech/ss58-registry.git" } [dev-dependencies] tempfile = "3.1.0" diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 61aeb4194c375..39e5149404b29 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -23,12 +23,14 @@ use crate::{ }; use serde_json::json; use sp_core::{ - crypto::{unwrap_or_default_ss58_version, ExposeSecret, SecretString, Ss58Codec, Zeroize}, + crypto::{ + unwrap_or_default_ss58_version, ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec, + Zeroize, + }, hexdisplay::HexDisplay, Pair, }; use sp_runtime::{traits::IdentifyAccount, MultiSigner}; -use ss58_registry::Ss58AddressFormat; use std::{convert::TryFrom, io::Read, path::PathBuf}; /// Public key type for Runtime diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index 3540a94cff504..d2953c8396079 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -22,9 +22,8 @@ use crate::{ error, utils, with_crypto_scheme, CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag, }; use rand::{rngs::OsRng, RngCore}; -use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58Codec}; +use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec}; use sp_runtime::traits::IdentifyAccount; -use ss58_registry::Ss58AddressFormat; use structopt::StructOpt; use utils::print_from_uri; @@ -164,10 +163,9 @@ fn assert_non_empty_string(pattern: &str) -> Result { mod tests { use super::*; use sp_core::{ - crypto::{default_ss58_version, Ss58Codec}, + crypto::{default_ss58_version, Ss58AddressFormatRegistry, Ss58Codec}, sr25519, Pair, }; - use ss58_registry::Ss58AddressFormatRegistry; use structopt::StructOpt; #[cfg(feature = "bench")] use test::Bencher; diff --git a/client/cli/src/params/mod.rs b/client/cli/src/params/mod.rs index f8b206216b203..dac832a1f897c 100644 --- a/client/cli/src/params/mod.rs +++ b/client/cli/src/params/mod.rs @@ -26,11 +26,11 @@ mod shared_params; mod transaction_pool_params; use crate::arg_enums::{CryptoScheme, OutputType}; +use sp_core::crypto::Ss58AddressFormat; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, NumberFor}, }; -use ss58_registry::Ss58AddressFormat; use std::{convert::TryFrom, fmt::Debug, str::FromStr}; use structopt::StructOpt; diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index 178d3b4dbe2dd..e73a4b185ded2 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -66,7 +66,7 @@ hex = { version = "0.4", default-features = false, optional = true } twox-hash = { version = "1.5.0", 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 = { git = "https://github.com/paritytech/ss58-registry.git" } +ss58-registry = { git = "https://github.com/paritytech/ss58-registry.git", branch = "main" } sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" } [dev-dependencies] diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index b2ffe32a0a613..986a4e4d77c18 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -43,7 +43,7 @@ use sp_std::{convert::TryFrom, hash::Hash, str, vec::Vec}; pub use zeroize::Zeroize; #[cfg(feature = "full_crypto")] -use ss58_registry::{from_known_address_format, Ss58AddressFormat, Ss58AddressFormatRegistry}; +pub use ss58_registry::{from_known_address_format, Ss58AddressFormat, Ss58AddressFormatRegistry}; /// The root phrase for our publicly known keys. pub const DEV_PHRASE: &str = diff --git a/primitives/core/src/ecdsa.rs b/primitives/core/src/ecdsa.rs index b75b9db38c4cc..2751a0c40e3e5 100644 --- a/primitives/core/src/ecdsa.rs +++ b/primitives/core/src/ecdsa.rs @@ -640,12 +640,14 @@ impl CryptoType for Pair { mod test { use super::*; use crate::{ - crypto::{set_default_ss58_version, PublicError, DEV_PHRASE}, + crypto::{ + set_default_ss58_version, PublicError, Ss58AddressFormat, Ss58AddressFormatRegistry, + DEV_PHRASE, + }, keccak_256, }; use hex_literal::hex; use serde_json; - use ss58_registry::{Ss58AddressFormat, Ss58AddressFormatRegistry}; #[test] fn default_phrase_should_be_used() { @@ -802,7 +804,7 @@ mod test { // We need to run this test in its own process to not interfere with other tests running in // parallel and also relying on the ss58 version. if std::env::var("RUN_CUSTOM_FORMAT_TEST") == Ok("1".into()) { - use ss58_registry::Ss58AddressFormat; + use crate::crypto::Ss58AddressFormat; // temp save default format version let default_format = crate::crypto::default_ss58_version(); // set current ss58 version is custom "200" `Ss58AddressFormat::Custom(200)` diff --git a/utils/frame/frame-utilities-cli/Cargo.toml b/utils/frame/frame-utilities-cli/Cargo.toml index b5322d6bd381e..1b6597fc9f2fc 100644 --- a/utils/frame/frame-utilities-cli/Cargo.toml +++ b/utils/frame/frame-utilities-cli/Cargo.toml @@ -17,7 +17,6 @@ sp-runtime = { version = "4.0.0-dev", path = "../../../primitives/runtime" } structopt = "0.3.8" frame-system = { version = "4.0.0-dev", path = "../../../frame/system" } frame-support = { version = "4.0.0-dev", path = "../../../frame/support" } -ss58-registry = { git="https://github.com/paritytech/ss58-registry.git" } [dev-dependencies] diff --git a/utils/frame/frame-utilities-cli/src/pallet_id.rs b/utils/frame/frame-utilities-cli/src/pallet_id.rs index fe131aa2f299a..d173f52b39cd8 100644 --- a/utils/frame/frame-utilities-cli/src/pallet_id.rs +++ b/utils/frame/frame-utilities-cli/src/pallet_id.rs @@ -22,9 +22,8 @@ use sc_cli::{ utils::print_from_uri, with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams, OutputTypeFlag, }; -use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58Codec}; +use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec}; use sp_runtime::traits::AccountIdConversion; -use ss58_registry::Ss58AddressFormat; use std::convert::{TryFrom, TryInto}; use structopt::StructOpt; From bf54d999b4eabf64d55c1fa6062bd366f5bf248f Mon Sep 17 00:00:00 2001 From: Squirrel Date: Wed, 6 Oct 2021 18:37:51 +0100 Subject: [PATCH 16/24] Update primitives/core/src/crypto.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- primitives/core/src/crypto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 986a4e4d77c18..8829239aec72f 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -360,7 +360,7 @@ static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = core::sync::atomic::Atom from_known_address_format(Ss58AddressFormatRegistry::SubstrateAccount), ); -/// Returns default(). (can't impl Default due to orphan rules). +/// Returns default ss58 format used by the current active process. #[cfg(feature = "std")] pub fn default_ss58_version() -> Ss58AddressFormat { DEFAULT_VERSION.load(core::sync::atomic::Ordering::Relaxed).into() From ae9fe5182c91afb09daa60ce24a64854fce017f5 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Thu, 7 Oct 2021 16:45:26 +0100 Subject: [PATCH 17/24] reference crates.io --- Cargo.lock | 3 ++- primitives/core/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e36e45df47821..12ae8717d189b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9877,7 +9877,8 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" version = "0.0.1" -source = "git+https://github.com/paritytech/ss58-registry.git?branch=main#3327f12c9bbd659636ba7e1e63eeb40e647d550e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe299bee3e8a6f5ab5292c2beb24665da10b3e83f4e4a5f2f16bb74b536b01e" dependencies = [ "Inflector", "proc-macro2", diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index ef2f6eeb74715..c07a485bbf35e 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -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 = { git = "https://github.com/paritytech/ss58-registry.git", branch = "main" } +ss58-registry = "0.0.1" sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" } [dev-dependencies] From 4d2f4aac3555028f2819f9f746476df1e6d46340 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Fri, 8 Oct 2021 11:58:59 +0100 Subject: [PATCH 18/24] bump ss58-registry version --- primitives/core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index c07a485bbf35e..69753811ea2f7 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -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 = "0.0.1" +ss58-registry = "1.0.0" sp-runtime-interface = { version = "4.0.0-dev", default-features = false, path = "../runtime-interface" } [dev-dependencies] From 0943458520d7ac34ff622a4b96a7661dc15ec6d3 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Fri, 8 Oct 2021 12:41:34 +0100 Subject: [PATCH 19/24] updating lock file --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12ae8717d189b..bce2e3fb47491 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9876,9 +9876,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" -version = "0.0.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebe299bee3e8a6f5ab5292c2beb24665da10b3e83f4e4a5f2f16bb74b536b01e" +checksum = "ef2413ecc7946ca99368862851dc1359f1477bc654ecfb135cf3efcb85ceca5f" dependencies = [ "Inflector", "proc-macro2", From 64ecffa0605dae2be40aa78970c5e47fa6109144 Mon Sep 17 00:00:00 2001 From: Squirrel Date: Mon, 11 Oct 2021 13:31:04 +0100 Subject: [PATCH 20/24] Update primitives/core/src/crypto.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- primitives/core/src/crypto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 8829239aec72f..b402e4919103c 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -369,7 +369,7 @@ pub fn default_ss58_version() -> Ss58AddressFormat { /// Returns either the input address format or the default. #[cfg(feature = "std")] pub fn unwrap_or_default_ss58_version(network: Option) -> Ss58AddressFormat { - network.unwrap_or_else(|| DEFAULT_VERSION.load(core::sync::atomic::Ordering::Relaxed).into()) + network.unwrap_or_else(|| DEFAULT_VERSION.load(std::sync::atomic::Ordering::Relaxed).into()) } /// Set the default "version" (actually, this is a bit of a misnomer and the version byte is From 8dc277250a8fcac1caf10e2d85b92f6ab4a5da20 Mon Sep 17 00:00:00 2001 From: Squirrel Date: Mon, 11 Oct 2021 13:31:11 +0100 Subject: [PATCH 21/24] Update primitives/core/src/crypto.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- primitives/core/src/crypto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index b402e4919103c..785d73f8965c4 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -356,7 +356,7 @@ fn ss58hash(data: &[u8]) -> blake2_rfc::blake2b::Blake2bResult { /// Default prefix number #[cfg(feature = "std")] -static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = core::sync::atomic::AtomicU16::new( +static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = std::sync::atomic::AtomicU16::new( from_known_address_format(Ss58AddressFormatRegistry::SubstrateAccount), ); From 3334062736e1f67c5093e7c91090cb301e1f40cb Mon Sep 17 00:00:00 2001 From: Squirrel Date: Mon, 11 Oct 2021 13:31:18 +0100 Subject: [PATCH 22/24] Update primitives/core/src/crypto.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- primitives/core/src/crypto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 785d73f8965c4..76a1ee85e82de 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -363,7 +363,7 @@ static DEFAULT_VERSION: core::sync::atomic::AtomicU16 = std::sync::atomic::Atomi /// Returns default ss58 format used by the current active process. #[cfg(feature = "std")] pub fn default_ss58_version() -> Ss58AddressFormat { - DEFAULT_VERSION.load(core::sync::atomic::Ordering::Relaxed).into() + DEFAULT_VERSION.load(std::sync::atomic::Ordering::Relaxed).into() } /// Returns either the input address format or the default. From a7ecedee342330eaabb106f5351ff212261225ac Mon Sep 17 00:00:00 2001 From: Squirrel Date: Mon, 11 Oct 2021 13:32:04 +0100 Subject: [PATCH 23/24] Update primitives/core/src/crypto.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- primitives/core/src/crypto.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 76a1ee85e82de..772ed9e19e9bf 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -377,8 +377,7 @@ pub fn unwrap_or_default_ss58_version(network: Option) -> Ss5 /// encoding and decoding SS58 addresses. #[cfg(feature = "std")] pub fn set_default_ss58_version(new_default: Ss58AddressFormat) { - let prefix: u16 = new_default.into(); - DEFAULT_VERSION.store(prefix, core::sync::atomic::Ordering::Relaxed); + DEFAULT_VERSION.store(new_default.into(), std::sync::atomic::Ordering::Relaxed); } #[cfg(feature = "std")] From 6c7e95f6dfea39c46acdaf6fe654d1e6e9c92d7b Mon Sep 17 00:00:00 2001 From: Squirrel Date: Mon, 11 Oct 2021 18:01:09 +0100 Subject: [PATCH 24/24] Update primitives/core/src/crypto.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> --- primitives/core/src/crypto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 772ed9e19e9bf..21b8520c7780f 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -369,7 +369,7 @@ pub fn default_ss58_version() -> Ss58AddressFormat { /// Returns either the input address format or the default. #[cfg(feature = "std")] pub fn unwrap_or_default_ss58_version(network: Option) -> Ss58AddressFormat { - network.unwrap_or_else(|| DEFAULT_VERSION.load(std::sync::atomic::Ordering::Relaxed).into()) + network.unwrap_or_else(default_ss58_version) } /// Set the default "version" (actually, this is a bit of a misnomer and the version byte is