Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
afe92fd
Update dependencies
ntn-x2 Feb 24, 2023
2538942
Update node side
ntn-x2 Feb 24, 2023
c585f30
Peregrine runtime compiling
ntn-x2 Feb 24, 2023
bc1da7a
Spiritnet runtime compiling
ntn-x2 Feb 24, 2023
b427a6d
Everything compiling
ntn-x2 Feb 24, 2023
d865e0f
All fixes
ntn-x2 Feb 24, 2023
0cd10f7
Compiles
ntn-x2 Feb 24, 2023
8a43ba1
Last fixes
ntn-x2 Feb 24, 2023
23ac524
More
ntn-x2 Feb 24, 2023
71732cc
fmt
ntn-x2 Feb 24, 2023
bb58447
Add pallet-xcm to runtime bench script
ntn-x2 Feb 24, 2023
f5bc271
Clippy
ntn-x2 Feb 27, 2023
a266edc
New pallet skeleton
ntn-x2 Feb 27, 2023
12b4fc9
First iteration
ntn-x2 Feb 27, 2023
39f5696
Test setup
ntn-x2 Feb 28, 2023
fb69836
Before switching to the Parity example
ntn-x2 Feb 28, 2023
6e6c59a
Integrate Parity example
ntn-x2 Feb 28, 2023
11d6fcf
Parity example refactoring in progress
ntn-x2 Feb 28, 2023
a3b9236
Test setup refactoring complete
ntn-x2 Mar 1, 2023
ff76493
Test environment compiling successfully
ntn-x2 Mar 1, 2023
7fc85c6
Messages going from parachain A to parachain B
ntn-x2 Mar 1, 2023
873c2d9
Transact works! Must add WithdrawAsset instruction first
ntn-x2 Mar 2, 2023
708f249
E2e flow works
ntn-x2 Mar 3, 2023
e0fe62a
More progress on the receiver side
ntn-x2 Mar 3, 2023
7760d02
Compiling
ntn-x2 Mar 3, 2023
53c04b7
IT WORKS
ntn-x2 Mar 3, 2023
10faad2
Working again
ntn-x2 Mar 3, 2023
6c0518b
Add support for additional details
ntn-x2 Mar 3, 2023
8646bbc
Add error handling
ntn-x2 Mar 3, 2023
b2b0d72
Change Transact origin to be the parachain itself
ntn-x2 Mar 6, 2023
b7bd163
Refactoring complete
ntn-x2 Mar 6, 2023
77e7b61
All working again
ntn-x2 Mar 6, 2023
c0bf753
Better refactoring
ntn-x2 Mar 6, 2023
845cf6b
Fix some features
ntn-x2 Mar 6, 2023
e8591b3
Merge commit '4eb94ef8e66343af651942653f25b939cfbf044e' into aa/dip-t…
ntn-x2 Mar 6, 2023
bef19d9
Fix compilation mess
ntn-x2 Mar 6, 2023
3c08a7d
Fix dip-receiver feature
ntn-x2 Mar 6, 2023
b3bf93f
Template node compiling
ntn-x2 Mar 8, 2023
cc4e907
Setup for local rococo 0.9.38
ntn-x2 Mar 8, 2023
17e5517
Minor runtime fixes WIP
ntn-x2 Mar 10, 2023
2bdd304
Add Parity feature flag fix
ntn-x2 Mar 10, 2023
fdc3981
Merge commit '2bdd304e09a3fe3ec1bb92e1d7b99cbe516232bb' into aa/dip-t…
ntn-x2 Mar 10, 2023
f31c2fc
Temporary fixes
ntn-x2 Mar 10, 2023
f825b95
More demo fixes
ntn-x2 Mar 10, 2023
a32f292
Fixes pt. 2
ntn-x2 Mar 10, 2023
b5fd68f
More fixess
ntn-x2 Mar 10, 2023
a7a022d
WORKING
ntn-x2 Mar 13, 2023
9609da4
Remove debug prints
ntn-x2 Mar 13, 2023
831c874
Revert test change
ntn-x2 Mar 13, 2023
4d2385c
Clean up dip-sender pallet
ntn-x2 Mar 14, 2023
6695380
Refactor dip-receiver
ntn-x2 Mar 14, 2023
97f8289
Rename dip pallets
ntn-x2 Mar 14, 2023
12ab8ee
Refactor dip-support
ntn-x2 Mar 14, 2023
09c0f5f
Refactor dip-sender and dip-receiver pallets
ntn-x2 Mar 14, 2023
89c6e0a
Merge commit '3f67a3192e75e181e1bf366748eb1b3e22bde18e' into aa/dip-t…
ntn-x2 Mar 14, 2023
6b44010
More refactoring
ntn-x2 Mar 14, 2023
fd2e1e9
Mid refactoring dip-sender template runtime
ntn-x2 Mar 14, 2023
9c83152
Complete refactor for dip-sender runtime template
ntn-x2 Mar 14, 2023
d02475b
receiver runtime template refactor
ntn-x2 Mar 15, 2023
9be02a9
One more refactoring complete
ntn-x2 Mar 15, 2023
9606829
XCM integration tests refactored
ntn-x2 Mar 15, 2023
4e704be
Almost there
ntn-x2 Mar 15, 2023
d45ed6f
Template nodes compiling
ntn-x2 Mar 15, 2023
c40af4d
Remove unused deps
ntn-x2 Mar 15, 2023
e9b49c4
Last fixes
ntn-x2 Mar 15, 2023
3fc04ce
Merge commit 'c6d5e7e9a08cef8697dfe37dd96dd5633a639c1d' into aa/dip-t…
ntn-x2 Mar 15, 2023
dd03b0c
Feature fixed
ntn-x2 Mar 15, 2023
2097d27
Add XCM pallet to template runtimes
ntn-x2 Mar 16, 2023
22ffcc9
Merge commit '7234aee203bc488b7e4bef7cc9cf69bfb1ba3ea4' into aa/dip-t…
ntn-x2 Mar 28, 2023
41d5538
Merge commit 'df9cef8e473a0512c17954baa6e2363ce8c65231' into aa/dip-t…
ntn-x2 Mar 28, 2023
4d8f14d
Remove unnecessary code duplication
ntn-x2 Mar 30, 2023
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
Prev Previous commit
Next Next commit
Working again
  • Loading branch information
ntn-x2 committed Mar 3, 2023
commit 10faad2267a5f6f23f2e1c7fbb6fc7ff809265fd
2 changes: 2 additions & 0 deletions Cargo.lock

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

38 changes: 36 additions & 2 deletions crates/dip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,43 @@

// If you feel like getting in touch with us, you can do so at [email protected]

pub mod location_conversion;
pub mod v1;
// Export v1 behind a namespace and also as the latest

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;

pub mod v1;
pub mod latest {
pub use crate::v1::*;
}

// Export utility modules without namespacing.
mod location_conversion;
pub use location_conversion::*;

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub enum VersionedIdentityProofAction<Identifier, Proof, Details = ()> {
#[codec(index = 1)]
V1(v1::IdentityProofAction<Identifier, Proof, Details>),
}

impl<Identifier, Proof> From<v1::IdentityProofAction<Identifier, Proof>>
for VersionedIdentityProofAction<Identifier, Proof>
{
fn from(value: v1::IdentityProofAction<Identifier, Proof>) -> Self {
Self::V1(value)
}
}

#[derive(Encode, Decode, RuntimeDebug, Clone, Eq, PartialEq, TypeInfo)]
pub enum VersionedIdentityProof<LeafKey, LeafValue> {
#[codec(index = 1)]
V1(v1::Proof<LeafKey, LeafValue>),
}

impl<LeafKey, LeafValue> From<v1::Proof<LeafKey, LeafValue>> for VersionedIdentityProof<LeafKey, LeafValue> {
fn from(value: v1::Proof<LeafKey, LeafValue>) -> Self {
Self::V1(value)
}
}
147 changes: 1 addition & 146 deletions crates/dip/src/location_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

// From Polkadot open PR https://github.com/paritytech/polkadot/pull/6662

use codec::{Decode, Encode};
use frame_support::traits::Get;
use codec::Encode;
use sp_io::hashing::blake2_256;
use sp_runtime::traits::{AccountIdConversion, TrailingZeroInput};
use sp_std::{borrow::Borrow, marker::PhantomData};
use xcm::latest::prelude::*;
use xcm_executor::traits::Convert;
Expand Down Expand Up @@ -104,146 +102,3 @@ impl<AccountId> ForeignChainAliasAccount<AccountId> {
(FOREIGN_CHAIN_PREFIX_RELAY, id).using_encoded(blake2_256)
}
}

pub struct Account32Hash<Network, AccountId>(PhantomData<(Network, AccountId)>);
impl<Network: Get<Option<NetworkId>>, AccountId: From<[u8; 32]> + Into<[u8; 32]> + Clone>
Convert<MultiLocation, AccountId> for Account32Hash<Network, AccountId>
{
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
Ok(("multiloc", location.borrow()).using_encoded(blake2_256).into())
}

fn reverse_ref(_: impl Borrow<AccountId>) -> Result<MultiLocation, ()> {
Err(())
}
}

/// A [`MultiLocation`] consisting of a single `Parent` [`Junction`] will be
/// converted to the parent `AccountId`.
pub struct ParentIsPreset<AccountId>(PhantomData<AccountId>);
impl<AccountId: Decode + Eq + Clone> Convert<MultiLocation, AccountId> for ParentIsPreset<AccountId> {
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
if location.borrow().contains_parents_only(1) {
Ok(b"Parent"
.using_encoded(|b| AccountId::decode(&mut TrailingZeroInput::new(b)))
.expect("infinite length input; no invalid inputs for type; qed"))
} else {
Err(())
}
}

fn reverse_ref(who: impl Borrow<AccountId>) -> Result<MultiLocation, ()> {
let parent_account = b"Parent"
.using_encoded(|b| AccountId::decode(&mut TrailingZeroInput::new(b)))
.expect("infinite length input; no invalid inputs for type; qed");
if who.borrow() == &parent_account {
Ok(Parent.into())
} else {
Err(())
}
}
}

pub struct ChildParachainConvertsVia<ParaId, AccountId>(PhantomData<(ParaId, AccountId)>);
impl<ParaId: From<u32> + Into<u32> + AccountIdConversion<AccountId>, AccountId: Clone> Convert<MultiLocation, AccountId>
for ChildParachainConvertsVia<ParaId, AccountId>
{
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
match location.borrow() {
MultiLocation {
parents: 0,
interior: X1(Parachain(id)),
} => Ok(ParaId::from(*id).into_account_truncating()),
_ => Err(()),
}
}

fn reverse_ref(who: impl Borrow<AccountId>) -> Result<MultiLocation, ()> {
if let Some(id) = ParaId::try_from_account(who.borrow()) {
Ok(Parachain(id.into()).into())
} else {
Err(())
}
}
}

pub struct SiblingParachainConvertsVia<ParaId, AccountId>(PhantomData<(ParaId, AccountId)>);
impl<ParaId: From<u32> + Into<u32> + AccountIdConversion<AccountId>, AccountId: Clone> Convert<MultiLocation, AccountId>
for SiblingParachainConvertsVia<ParaId, AccountId>
{
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
match location.borrow() {
MultiLocation {
parents: 1,
interior: X1(Parachain(id)),
} => Ok(ParaId::from(*id).into_account_truncating()),
_ => Err(()),
}
}

fn reverse_ref(who: impl Borrow<AccountId>) -> Result<MultiLocation, ()> {
if let Some(id) = ParaId::try_from_account(who.borrow()) {
Ok(MultiLocation::new(1, X1(Parachain(id.into()))))
} else {
Err(())
}
}
}

/// Extracts the `AccountId32` from the passed `location` if the network
/// matches.
pub struct AccountId32Aliases<Network, AccountId>(PhantomData<(Network, AccountId)>);
impl<Network: Get<Option<NetworkId>>, AccountId: From<[u8; 32]> + Into<[u8; 32]> + Clone>
Convert<MultiLocation, AccountId> for AccountId32Aliases<Network, AccountId>
{
fn convert(location: MultiLocation) -> Result<AccountId, MultiLocation> {
let id = match location {
MultiLocation {
parents: 0,
interior: X1(AccountId32 { id, network: None }),
} => id,
MultiLocation {
parents: 0,
interior: X1(AccountId32 { id, network }),
} if network == Network::get() => id,
_ => return Err(location),
};
Ok(id.into())
}

fn reverse(who: AccountId) -> Result<MultiLocation, AccountId> {
Ok(AccountId32 {
id: who.into(),
network: Network::get(),
}
.into())
}
}

pub struct AccountKey20Aliases<Network, AccountId>(PhantomData<(Network, AccountId)>);
impl<Network: Get<Option<NetworkId>>, AccountId: From<[u8; 20]> + Into<[u8; 20]> + Clone>
Convert<MultiLocation, AccountId> for AccountKey20Aliases<Network, AccountId>
{
fn convert(location: MultiLocation) -> Result<AccountId, MultiLocation> {
let key = match location {
MultiLocation {
parents: 0,
interior: X1(AccountKey20 { key, network: None }),
} => key,
MultiLocation {
parents: 0,
interior: X1(AccountKey20 { key, network }),
} if network == Network::get() => key,
_ => return Err(location),
};
Ok(key.into())
}

fn reverse(who: AccountId) -> Result<MultiLocation, AccountId> {
let j = AccountKey20 {
key: who.into(),
network: Network::get(),
};
Ok(j.into())
}
}
8 changes: 6 additions & 2 deletions crates/dip/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
// If you feel like getting in touch with us, you can do so at [email protected]

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub enum IdentityProofAction<Identifier, Proof> {
Updated(Identifier, Proof),
pub enum IdentityProofAction<Identifier, Proof, Details = ()> {
Updated(Identifier, Proof, Details),
Deleted(Identifier),
}

#[derive(Encode, Decode, RuntimeDebug, Clone, Eq, PartialEq, TypeInfo, Default)]
pub struct Proof<LeafKey, LeafValue>(Vec<(LeafKey, LeafValue)>);
22 changes: 10 additions & 12 deletions pallets/dip-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
mod origin;
pub mod traits;

#[cfg(tests)]
mod tests;

pub use crate::{origin::*, pallet::*};

#[frame_support::pallet]
Expand All @@ -35,13 +32,14 @@ pub mod pallet {
use frame_support::{dispatch::Dispatchable, pallet_prelude::*, traits::EnsureOrigin, Twox64Concat};
use frame_system::pallet_prelude::*;

use dip_support::latest::IdentityProofAction;
use dip_support::{latest::IdentityProofAction, VersionedIdentityProof, VersionedIdentityProofAction};

use crate::traits::{IdentityProofVerifier, Proof};
use crate::traits::IdentityProofVerifier;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);

// TODO: Store also additional details received by the provider
#[pallet::storage]
#[pallet::getter(fn identity_proofs)]
pub(crate) type IdentityProofs<T> =
Expand Down Expand Up @@ -84,25 +82,25 @@ pub mod pallet {
}

#[pallet::origin]
pub type Origin<T> = KiltDidOrigin<<T as Config>::Identifier, <T as frame_system::Config>::AccountId>;
pub type Origin<T> = DipOrigin<<T as Config>::Identifier, <T as frame_system::Config>::AccountId>;

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(0)]
pub fn process_identity_action(
origin: OriginFor<T>,
action: IdentityProofAction<T::Identifier, T::ProofDigest>,
action: VersionedIdentityProofAction<T::Identifier, T::ProofDigest>,
) -> DispatchResult {
T::EnsureSourceXcmOrigin::ensure_origin(origin)?;

let event = match action {
IdentityProofAction::Updated(identifier, proof) => {
VersionedIdentityProofAction::V1(IdentityProofAction::Updated(identifier, proof, _)) => {
println!("DipReceiver::process_identity_action - Action was to update. Writing...");
IdentityProofs::<T>::mutate(&identifier, |entry| *entry = Some(proof.clone()));
Event::<T>::IdentityInfoUpdated(identifier, proof)
}
IdentityProofAction::Deleted(identifier) => {
VersionedIdentityProofAction::V1(IdentityProofAction::Deleted(identifier)) => {
println!("DipReceiver::process_identity_action - Action was to delete. Deleting...");
IdentityProofs::<T>::remove(&identifier);
Event::<T>::IdentityInfoDeleted(identifier)
Expand All @@ -119,15 +117,15 @@ pub mod pallet {
pub fn dispatch_as(
origin: OriginFor<T>,
identifier: T::Identifier,
proof: Proof<T::ProofLeafKey, T::ProofLeafValue>,
proof: VersionedIdentityProof<T::ProofLeafKey, T::ProofLeafValue>,
call: Box<<T as Config>::RuntimeCall>,
) -> DispatchResult {
let submitter = ensure_signed(origin)?;
let proof_digest = IdentityProofs::<T>::get(&identifier).ok_or(Error::<T>::IdentityNotFound)?;
let _ = T::ProofVerifier::verify_proof_against_digest(proof, proof_digest)
.map_err(|_| Error::<T>::InvalidProof)?;
let did_origin = KiltDidOrigin {
did_subject: identifier,
let did_origin = DipOrigin {
did_identifier: identifier,
account_address: submitter,
};
let _ = call
Expand Down
12 changes: 6 additions & 6 deletions pallets/dip-receiver/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ use scale_info::TypeInfo;
use sp_std::marker::PhantomData;

#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct KiltDidOrigin<DidIdentifier, AccountId> {
pub did_subject: DidIdentifier,
pub struct DipOrigin<DidIdentifier, AccountId> {
pub did_identifier: DidIdentifier,
pub account_address: AccountId,
}

pub struct EnsureKiltDidOrigin<DidIdentifier, AccountId>(PhantomData<(DidIdentifier, AccountId)>);
pub struct EnsureDipOrigin<DidIdentifier, AccountId>(PhantomData<(DidIdentifier, AccountId)>);

impl<OuterOrigin, DidIdentifier, AccountId> EnsureOrigin<OuterOrigin> for EnsureKiltDidOrigin<DidIdentifier, AccountId>
impl<OuterOrigin, DidIdentifier, AccountId> EnsureOrigin<OuterOrigin> for EnsureDipOrigin<DidIdentifier, AccountId>
where
OuterOrigin: Into<Result<KiltDidOrigin<DidIdentifier, AccountId>, OuterOrigin>>,
OuterOrigin: Into<Result<DipOrigin<DidIdentifier, AccountId>, OuterOrigin>>,
{
type Success = KiltDidOrigin<DidIdentifier, AccountId>;
type Success = DipOrigin<DidIdentifier, AccountId>;

fn try_origin(o: OuterOrigin) -> Result<Self::Success, OuterOrigin> {
o.into()
Expand Down
17 changes: 0 additions & 17 deletions pallets/dip-receiver/src/tests.rs

This file was deleted.

11 changes: 3 additions & 8 deletions pallets/dip-receiver/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@

// If you feel like getting in touch with us, you can do so at [email protected]

use codec::{Decode, Encode};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;
use dip_support::VersionedIdentityProof;
use sp_std::marker::PhantomData;

#[derive(Encode, Decode, RuntimeDebug, Clone, Eq, PartialEq, TypeInfo, Default)]
pub struct Proof<LeafKey, LeafValue>(Vec<(LeafKey, LeafValue)>);

pub trait IdentityProofVerifier {
type ProofDigest;
type LeafKey;
Expand All @@ -32,7 +27,7 @@ pub trait IdentityProofVerifier {
type Error;

fn verify_proof_against_digest(
proof: Proof<Self::LeafKey, Self::LeafValue>,
proof: VersionedIdentityProof<Self::LeafKey, Self::LeafValue>,
digest: Self::ProofDigest,
) -> Result<Self::VerificationResult, Self::Error>;
}
Expand All @@ -48,7 +43,7 @@ impl<ProofDigest, LeafKey, LeafValue> IdentityProofVerifier
type VerificationResult = ();

fn verify_proof_against_digest(
_proof: Proof<Self::LeafKey, Self::LeafValue>,
_proof: VersionedIdentityProof<Self::LeafKey, Self::LeafValue>,
_digest: Self::ProofDigest,
) -> Result<Self::VerificationResult, Self::Error> {
Ok(())
Expand Down
Loading