Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
445 changes: 244 additions & 201 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ ws = { version = "0.9.1", optional = true, features = ["ssl"] }
codec = { package = 'parity-scale-codec', version = "2.0.0", default-features = false, features = ['derive']}

# Substrate dependencies
sp-core = { version = "4.1.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master", features = ["full_crypto"] }
sp-core = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master", features = ["full_crypto"] }
sp-version = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master", package = "sp-version", optional = true }
balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master", package = "pallet-balances", optional = true }
staking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master", package = "pallet-staking", optional = true }
system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master", package = "frame-system", optional = true }
transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master", package = "pallet-transaction-payment", optional = true }
sp-rpc = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master", optional = true }
sp-runtime = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-rpc = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master", optional = true }
sp-runtime = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", package = "frame-support", branch = "master" }
sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
# new parity repository
metadata = { version = "14.0.0", default-features = false, git = "https://github.com/paritytech/frame-metadata.git", branch = "main", package = "frame-metadata", features = ["v13"] }
# need to add this for the app_crypto macro
sp-application-crypto = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master", features = ["full_crypto"] }
sp-application-crypto = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master", features = ["full_crypto"] }

# local deps
ac-compose-macros = { path = "compose-macros", default-features = false }
Expand All @@ -48,7 +48,7 @@ ac-primitives = { path = "primitives", default-features = false }
[dev-dependencies]
env_logger = "0.9"
node-template-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
keyring = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master", package = "sp-keyring" }
keyring = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master", package = "sp-keyring" }
clap = { version = "2.33", features = ["yaml"] }


Expand Down
8 changes: 4 additions & 4 deletions client-keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ hex = "0.4"
serde_json = "1.0"

# Substrate dependencies
sp-core = { version = "4.1.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keystore = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keystore = { version = "0.11.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-keystore = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-application-crypto = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-application-crypto = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }

[dev-dependencies]
tempfile = "3.2.0"
84 changes: 62 additions & 22 deletions client-keystore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use async_trait::async_trait;
use parking_lot::RwLock;
use sp_application_crypto::{ecdsa, ed25519, sr25519, AppKey, AppPair, AppPublic, IsWrappedBy};
use sp_core::{
crypto::{CryptoTypePublicPair, ExposeSecret, KeyTypeId, Pair as PairT, Public, SecretString},
crypto::{
ByteArray, CryptoTypePublicPair, ExposeSecret, KeyTypeId, Pair as PairT, SecretString,
},
sr25519::{Pair as Sr25519Pair, Public as Sr25519Public},
Encode,
};
Expand Down Expand Up @@ -86,7 +88,7 @@ impl KeystoreExt for LocalKeystore {
fn public_keys<Public: AppPublic>(&self) -> Result<Vec<Public>> {
self.0.read().raw_public_keys(Public::ID).map(|v| {
v.into_iter()
.map(|k| Public::from_slice(k.as_slice()))
.filter_map(|k| Public::from_slice(k.as_slice()).ok())
.collect()
})
}
Expand Down Expand Up @@ -219,7 +221,9 @@ impl SyncCryptoStore for LocalKeystore {
) -> std::result::Result<Option<Vec<u8>>, TraitError> {
match key.0 {
ed25519::CRYPTO_ID => {
let pub_key = ed25519::Public::from_slice(key.1.as_slice());
let pub_key = ed25519::Public::from_slice(key.1.as_slice()).map_err(|()| {
TraitError::Other("Corrupted public key - Invalid size".into())
})?;
let key_pair = self
.0
.read()
Expand All @@ -228,7 +232,9 @@ impl SyncCryptoStore for LocalKeystore {
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
}
sr25519::CRYPTO_ID => {
let pub_key = sr25519::Public::from_slice(key.1.as_slice());
let pub_key = sr25519::Public::from_slice(key.1.as_slice()).map_err(|()| {
TraitError::Other("Corrupted public key - Invalid size".into())
})?;
let key_pair = self
.0
.read()
Expand All @@ -237,7 +243,9 @@ impl SyncCryptoStore for LocalKeystore {
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
}
ecdsa::CRYPTO_ID => {
let pub_key = ecdsa::Public::from_slice(key.1.as_slice());
let pub_key = ecdsa::Public::from_slice(key.1.as_slice()).map_err(|()| {
TraitError::Other("Corrupted public key - Invalid size".into())
})?;
let key_pair = self
.0
.read()
Expand All @@ -255,7 +263,7 @@ impl SyncCryptoStore for LocalKeystore {
.raw_public_keys(key_type)
.map(|v| {
v.into_iter()
.map(|k| sr25519::Public::from_slice(k.as_slice()))
.filter_map(|k| sr25519::Public::from_slice(k.as_slice()).ok())
.collect()
})
.unwrap_or_default()
Expand Down Expand Up @@ -284,7 +292,7 @@ impl SyncCryptoStore for LocalKeystore {
.raw_public_keys(key_type)
.map(|v| {
v.into_iter()
.map(|k| ed25519::Public::from_slice(k.as_slice()))
.filter_map(|k| ed25519::Public::from_slice(k.as_slice()).ok())
.collect()
})
.unwrap_or_default()
Expand Down Expand Up @@ -313,7 +321,7 @@ impl SyncCryptoStore for LocalKeystore {
.raw_public_keys(key_type)
.map(|v| {
v.into_iter()
.map(|k| ecdsa::Public::from_slice(k.as_slice()))
.filter_map(|k| ecdsa::Public::from_slice(k.as_slice()).ok())
.collect()
})
.unwrap_or_default()
Expand Down Expand Up @@ -428,12 +436,11 @@ impl KeystoreInner {
let path = path.into();
fs::create_dir_all(&path)?;

let instance = Self {
Ok(Self {
path: Some(path),
additional: HashMap::new(),
password,
};
Ok(instance)
})
}

/// Get the password for this store.
Expand Down Expand Up @@ -472,10 +479,9 @@ impl KeystoreInner {
/// Places it into the file system store, if a path is configured.
fn insert_unknown(&self, key_type: KeyTypeId, suri: &str, public: &[u8]) -> Result<()> {
if let Some(path) = self.key_file_path(public, key_type) {
let mut file = File::create(path).map_err(Error::Io)?;
serde_json::to_writer(&file, &suri).map_err(Error::Json)?;
file.flush().map_err(Error::Io)?;
Self::write_to_file(path, suri)?;
}

Ok(())
}

Expand All @@ -486,15 +492,29 @@ impl KeystoreInner {
fn generate_by_type<Pair: PairT>(&mut self, key_type: KeyTypeId) -> Result<Pair> {
let (pair, phrase, _) = Pair::generate_with_phrase(self.password());
if let Some(path) = self.key_file_path(pair.public().as_slice(), key_type) {
let mut file = File::create(path)?;
serde_json::to_writer(&file, &phrase)?;
file.flush()?;
Self::write_to_file(path, &phrase)?;
} else {
self.insert_ephemeral_pair(&pair, &phrase, key_type);
}

Ok(pair)
}

/// Write the given `data` to `file`.
fn write_to_file(file: PathBuf, data: &str) -> Result<()> {
let mut file = File::create(file)?;

#[cfg(target_family = "unix")]
{
use std::os::unix::fs::PermissionsExt;
file.set_permissions(fs::Permissions::from_mode(0o600))?;
}

serde_json::to_writer(&file, data)?;
file.flush()?;
Ok(())
}

/// Create a new key from seed.
///
/// Does not place it into the file system store.
Expand Down Expand Up @@ -546,7 +566,7 @@ impl KeystoreInner {
if &pair.public() == public {
Ok(Some(pair))
} else {
Err(Error::InvalidPassword)
Err(Error::PublicKeyMismatch)
}
}

Expand Down Expand Up @@ -596,8 +616,8 @@ impl KeystoreInner {

/// Get a key pair for the given public key.
///
/// Returns `Ok(None)` if the key doesn't exist, `Ok(Some(_))` if the key exists or `Err(_)` when
/// something failed.
/// Returns `Ok(None)` if the key doesn't exist, `Ok(Some(_))` if the key exists or `Err(_)`
/// when something failed.
pub fn key_pair<Pair: AppPair>(
&self,
public: &<Pair as AppKey>::Public,
Expand Down Expand Up @@ -626,7 +646,7 @@ mod tests {
fn public_keys<Public: AppPublic>(&self) -> Result<Vec<Public>> {
self.raw_public_keys(Public::ID).map(|v| {
v.into_iter()
.map(|k| Public::from_slice(k.as_slice()))
.filter_map(|k| Public::from_slice(k.as_slice()).ok())
.collect()
})
}
Expand Down Expand Up @@ -805,7 +825,7 @@ mod tests {
let file_name = temp_dir.path().join(hex::encode(&SR25519.0[..2]));
fs::write(file_name, "test").expect("Invalid file is written");

assert!(SyncCryptoStore::sr25519_public_keys(&store, SR25519).is_empty(),);
assert!(SyncCryptoStore::sr25519_public_keys(&store, SR25519).is_empty());
}

#[test]
Expand Down Expand Up @@ -843,4 +863,24 @@ mod tests {
2
);
}

#[test]
#[cfg(target_family = "unix")]
fn uses_correct_file_permissions_on_unix() {
use std::os::unix::fs::PermissionsExt;

let temp_dir = TempDir::new().unwrap();
let store = LocalKeystore::open(temp_dir.path(), None).unwrap();

let public = SyncCryptoStore::sr25519_generate_new(&store, TEST_KEY_TYPE, None).unwrap();

let path = store
.0
.read()
.key_file_path(public.as_ref(), TEST_KEY_TYPE)
.unwrap();
let permissions = File::open(path).unwrap().metadata().unwrap().permissions();

assert_eq!(0o100600, permissions.mode());
}
}
4 changes: 2 additions & 2 deletions compose-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ codec = { package = 'parity-scale-codec', version = "2.0.0", default-features =
log = { version = "0.4", default-features = false }

# substrate dependencies
sp-runtime = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }

# local deps
Expand All @@ -23,4 +23,4 @@ std = [
"sp-std/std",
# local crates
"ac-primitives/std",
]
]
4 changes: 2 additions & 2 deletions node-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ ac-primitives = { path = "../primitives" }
# substrate deps
frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }

# new parity repo
frame-metadata = { version = "14.0.0", git = "https://github.com/paritytech/frame-metadata.git", branch = "main", features = ["v14"] }
6 changes: 3 additions & 3 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"
codec = { package = 'parity-scale-codec', version = "2.0.0", default-features = false, features = ['derive']}
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }

sp-core = { version = "4.1.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }

[features]
Expand All @@ -19,4 +19,4 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
]
]
12 changes: 10 additions & 2 deletions primitives/src/extrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,22 @@ fn encode_with_vec_prefix<T: Encode, F: Fn(&mut Vec<u8>)>(encoder: F) -> Vec<u8>
#[cfg(test)]
mod tests {
use super::*;
use sp_core::Pair;
use sp_runtime::testing::sr25519;
use sp_runtime::MultiSignature;

#[test]
fn encode_decode_roundtrip_works() {
let msg = &b"test-message"[..];
let (pair, _) = sr25519::Pair::generate();
let signature = pair.sign(&msg);
let multi_sig = MultiSignature::from(signature);
let account: AccountId = pair.public().into();

let xt = UncheckedExtrinsicV4::new_signed(
vec![1, 1, 1],
GenericAddress::default(),
MultiSignature::default(),
account.into(),
multi_sig,
GenericExtra::default(),
);

Expand Down
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2021-12-22"
channel = "nightly-2022-02-02"
targets = ["wasm32-unknown-unknown"]
profile = "default" # include rustfmt, clippy
profile = "default" # include rustfmt, clippy
2 changes: 1 addition & 1 deletion test-no-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ libc = { version = "0.2", default-features = false }
substrate-api-client = { path = "..", default-features = false }

# substrate dependencies
sp-io = { version = "4.0.0-dev", default-features = false, features = ["disable_oom", "disable_panic_handler"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-io = { version = "5.0.0", default-features = false, features = ["disable_oom", "disable_panic_handler"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
4 changes: 2 additions & 2 deletions tutorials/api-client-tutorial/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ edition = "2021"
substrate-api-client = { path = "../.." }
codec = { package = "parity-scale-codec", features = ["derive"], version = "2.0.0" }

sp-core = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }