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
6 changes: 0 additions & 6 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions pallets/did/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ substrate-wasm-builder = {git = "https://github.com/paritytech/substrate", branc

[dev-dependencies]
env_logger = "0.9.0"
serde = "1.0.144"

ctype = {features = ["mock"], path = "../ctype"}

Expand All @@ -27,7 +26,6 @@ sp-keystore = {branch = "polkadot-v0.9.29", git = "https://github.com/paritytech
ctype = {path = "../ctype", optional = true}
kilt-support = {default-features = false, path = "../../support"}
log = "0.4.17"
serde = {version = "1.0.142", optional = true, features = ["derive"]}

codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]}
frame-support = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"}
Expand Down Expand Up @@ -67,7 +65,6 @@ std = [
"log/std",
"pallet-balances/std",
"scale-info/std",
"serde",
"sp-core/std",
"sp-io/std",
"sp-keystore/std",
Expand Down
4 changes: 0 additions & 4 deletions pallets/did/src/did_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use crate::{

/// Types of verification keys a DID can control.
#[derive(Clone, Decode, RuntimeDebug, Encode, Eq, Ord, PartialEq, PartialOrd, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum DidVerificationKey {
/// An Ed25519 public key.
Ed25519(ed25519::Public),
Expand Down Expand Up @@ -90,15 +89,13 @@ impl From<ecdsa::Public> for DidVerificationKey {

/// Types of encryption keys a DID can control.
#[derive(Clone, Copy, Decode, RuntimeDebug, Encode, Eq, Ord, PartialEq, PartialOrd, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum DidEncryptionKey {
/// An X25519 public key.
X25519([u8; 32]),
}

/// A general public key under the control of the DID.
#[derive(Clone, Decode, RuntimeDebug, Encode, Eq, Ord, PartialEq, PartialOrd, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum DidPublicKey {
/// A verification key, used to generate and verify signatures.
PublicVerificationKey(DidVerificationKey),
Expand Down Expand Up @@ -237,7 +234,6 @@ impl<I: AsRef<[u8; 32]>> DidVerifiableIdentifier for I {
#[derive(Clone, RuntimeDebug, Decode, Encode, PartialEq, Ord, PartialOrd, Eq, TypeInfo, MaxEncodedLen)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct DidPublicKeyDetails<BlockNumber: MaxEncodedLen> {
/// A public key the DID controls.
pub key: DidPublicKey,
Expand Down
6 changes: 0 additions & 6 deletions pallets/pallet-did-lookup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ sp-std = {branch = "polkadot-v0.9.29", default-features = false, git = "https://
# benchmarking
frame-benchmarking = {branch = "polkadot-v0.9.29", optional = true, default-features = false, git = "https://github.com/paritytech/substrate"}

# optional dependencies
impl-serde = {version = "0.3.1", optional = true}
serde = {version = "1.0.101", optional = true}

[features]
default = ["std"]

Expand All @@ -59,10 +55,8 @@ std = [
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"impl-serde",
"log/std",
"scale-info/std",
"serde",
"sha3/std",
"sp-core/std",
"sp-io/std",
Expand Down
8 changes: 0 additions & 8 deletions pallets/pallet-did-lookup/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,13 @@ use scale_info::TypeInfo;
use sha3::{Digest, Keccak256};
use sp_core::{ecdsa, H160, H256};

#[cfg(feature = "std")]
pub use serde::{de::DeserializeOwned, Deserialize, Serialize};

/// The AccountId20 type.
/// It is a 20-byte Ethereum address.
#[derive(
Eq, PartialEq, Copy, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Default, PartialOrd, Ord, RuntimeDebug,
)]
pub struct AccountId20(pub [u8; 20]);

#[cfg(feature = "std")]
impl_serde::impl_fixed_hash_serde!(AccountId20, 20);

#[cfg(feature = "std")]
impl std::fmt::Display for AccountId20 {
//TODO This is a pretty quck-n-dirty implementation. Perhaps we should add
Expand Down Expand Up @@ -88,7 +82,6 @@ impl std::str::FromStr for AccountId20 {

/// Public key for an Ethereum / Moonbeam compatible account
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct EthereumSigner([u8; 20]);

impl sp_runtime::traits::IdentifyAccount for EthereumSigner {
Expand Down Expand Up @@ -130,7 +123,6 @@ impl std::fmt::Display for EthereumSigner {
}
}

#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(Eq, PartialEq, Clone, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub struct EthereumSignature(ecdsa::Signature);

Expand Down
2 changes: 0 additions & 2 deletions pallets/pallet-did-lookup/src/linkable_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use sp_runtime::AccountId32;

use crate::account::AccountId20;

#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub enum LinkableAccountId {
AccountId20(AccountId20),
Expand Down
2 changes: 1 addition & 1 deletion pallets/parachain-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.
[dependencies]
log = "0.4.17"
parity-scale-codec = {version = "3.1.5", default-features = false, features = ["derive"]}
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
scale-info = {version = "2.1.1", default-features = false, features = ["derive", "serde"]}
serde = {version = "1.0.144", optional = true}

frame-support = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false}
Expand Down
2 changes: 0 additions & 2 deletions rpc/did/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ version = "1.8.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0.142", optional = true, features = ["derive"] }

sp-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29"}
sp-std = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29"}
Expand All @@ -19,7 +18,6 @@ kilt-support = {path = "../../../support", default-features = false}
[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sp-api/std",
"sp-std/std",
Expand Down
13 changes: 1 addition & 12 deletions rpc/did/runtime-api/src/did_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,21 @@

// If you feel like getting in touch with us, you can do so at info@botlabs.org

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet};

use did::{did_details::DidPublicKeyDetails, AccountIdOf, BalanceOf, BlockNumberOf, KeyIdOf};
use kilt_support::deposit::Deposit;

#[derive(Encode, Decode, TypeInfo, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, TypeInfo, Clone, Debug, Eq, PartialEq, MaxEncodedLen)]
pub struct DidDetails<Key: Ord, BlockNumber: MaxEncodedLen, AccountId, Balance> {
pub authentication_key: Key,
pub key_agreement_keys: BTreeSet<Key>,
pub delegation_key: Option<Key>,
pub attestation_key: Option<Key>,
pub public_keys: BTreeMap<Key, DidPublicKeyDetails<BlockNumber>>,
pub last_tx_counter: u64,
#[cfg_attr(
feature = "std",
serde(bound(
serialize = "Deposit<AccountId, Balance>: Serialize",
deserialize = "Deposit<AccountId, Balance>: Deserialize<'de>"
))
)]
pub deposit: Deposit<AccountId, Balance>,
}

Expand Down
38 changes: 0 additions & 38 deletions rpc/did/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
// If you feel like getting in touch with us, you can do so at info@botlabs.org
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

use codec::{Codec, Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_std::vec::Vec;
Expand All @@ -31,34 +28,6 @@ pub use did_details::*;
pub use service_endpoint::*;

#[derive(Encode, Decode, TypeInfo, Eq, PartialEq)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "std",
serde(bound(
serialize = "
Balance: std::fmt::Display,
AccountId: Serialize,
LinkableAccountId: Serialize,
Key: Serialize,
BlockNumber: Serialize,
DidIdentifier: Serialize,
Type: Serialize,
Url: Serialize,
Id: Serialize,
Web3Name: Serialize,",
deserialize = "
Balance: std::str::FromStr,
AccountId: Deserialize<'de>,
LinkableAccountId: Deserialize<'de>,
Key: Deserialize<'de>,
BlockNumber: Deserialize<'de>,
DidIdentifier: Deserialize<'de>,
Type: Deserialize<'de>,
Url: Deserialize<'de>,
Id: Deserialize<'de>,
Web3Name: Deserialize<'de>,"
))
)]
pub struct DidLinkedInfo<
DidIdentifier,
AccountId,
Expand All @@ -75,13 +44,6 @@ pub struct DidLinkedInfo<
pub accounts: Vec<LinkableAccountId>,
pub w3n: Option<Web3Name>,
pub service_endpoints: Vec<ServiceEndpoint<Id, Type, Url>>,
#[cfg_attr(
feature = "std",
serde(bound(
serialize = "DidDetails<Key, BlockNumber, AccountId, Balance>: Serialize",
deserialize = "DidDetails<Key, BlockNumber, AccountId, Balance>: Deserialize<'de>"
))
)]
pub details: DidDetails<Key, BlockNumber, AccountId, Balance>,
}

Expand Down
1 change: 0 additions & 1 deletion rpc/did/runtime-api/src/service_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use scale_info::TypeInfo;
use sp_std::vec::Vec;

#[derive(Encode, Decode, TypeInfo, Eq, PartialEq)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct ServiceEndpoint<Id, Type, Url> {
pub id: Id,
pub service_types: Vec<Type>,
Expand Down
5 changes: 0 additions & 5 deletions support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ version = "1.8.0"
# External dependencies
codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]}
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
serde = {version = "1.0.142", optional = true, features = ["derive"]}

frame-support = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"}
frame-system = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"}
sp-core = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"}
sp-runtime = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"}
sp-std = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"}

[dev-dependencies]
serde_json = "1.0.83"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

Expand All @@ -37,7 +33,6 @@ std = [
"frame-support/std",
"frame-system/std",
"scale-info/std",
"serde",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
60 changes: 0 additions & 60 deletions support/src/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ use sp_runtime::{traits::Zero, DispatchError};

/// An amount of balance reserved by the specified address.
#[derive(Clone, Debug, Encode, Decode, Eq, PartialEq, Ord, PartialOrd, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct Deposit<Account, Balance> {
pub owner: Account,
#[cfg_attr(
feature = "std",
serde(bound(serialize = "Balance: std::fmt::Display", deserialize = "Balance: std::str::FromStr"))
)]
#[cfg_attr(feature = "std", serde(with = "serde_balance"))]
pub amount: Balance,
}

Expand All @@ -49,57 +43,3 @@ pub fn free_deposit<Account, Currency: ReservableCurrency<Account>>(deposit: &De
let err_amount = Currency::unreserve(&deposit.owner, deposit.amount);
debug_assert!(err_amount.is_zero());
}

// This code was copied from https://github.com/paritytech/substrate/blob/ded44948e2d5a398abcb4e342b0513cb690961bb/frame/transaction-payment/src/types.rs#L113
// It is needed because u128 cannot be serialized by serde_json out of the box.
#[cfg(feature = "std")]
mod serde_balance {
use serde::{Deserialize, Deserializer, Serializer};

pub fn serialize<S: Serializer, T: std::fmt::Display>(t: &T, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&t.to_string())
}

pub fn deserialize<'de, D: Deserializer<'de>, T: std::str::FromStr>(deserializer: D) -> Result<T, D::Error> {
let s = String::deserialize(deserializer)?;
s.parse::<T>()
.map_err(|_| serde::de::Error::custom("Parse from string failed"))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn should_serialize_and_deserialize_properly_with_string() {
let deposit = Deposit {
owner: 0_u8,
amount: 0_u128,
};

let json_str = r#"{"owner":0,"amount":"0"}"#;

assert_eq!(serde_json::to_string(&deposit).unwrap(), json_str);
assert_eq!(serde_json::from_str::<Deposit<u8, u128>>(json_str).unwrap(), deposit);

// should not panic
serde_json::to_value(&deposit).unwrap();
}

#[test]
fn should_serialize_and_deserialize_properly_large_value() {
let deposit = Deposit {
owner: 0_u8,
amount: u128::MAX,
};

let json_str = r#"{"owner":0,"amount":"340282366920938463463374607431768211455"}"#;

assert_eq!(serde_json::to_string(&deposit).unwrap(), json_str);
assert_eq!(serde_json::from_str::<Deposit<u8, u128>>(json_str).unwrap(), deposit);

// should not panic
serde_json::to_value(&deposit).unwrap();
}
}