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
34 changes: 33 additions & 1 deletion pallets/did/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use frame_support::{
codec::{Decode, Encode},
traits::EnsureOrigin,
traits::{EnsureOrigin, EnsureOriginWithArg},
};
use kilt_support::traits::CallSources;
use parity_scale_codec::MaxEncodedLen;
Expand Down Expand Up @@ -66,6 +66,38 @@ where
}
}

impl<OuterOrigin, DidIdentifier, AccountId> EnsureOriginWithArg<OuterOrigin, DidIdentifier>
for EnsureDidOrigin<DidIdentifier, AccountId>
where
OuterOrigin: Into<Result<DidRawOrigin<DidIdentifier, AccountId>, OuterOrigin>>
+ From<DidRawOrigin<DidIdentifier, AccountId>>
+ Clone,
DidIdentifier: PartialEq<DidIdentifier> + Clone,
AccountId: Clone + Decode,
{
type Success = DidRawOrigin<DidIdentifier, AccountId>;

fn try_origin(o: OuterOrigin, a: &DidIdentifier) -> Result<Self::Success, OuterOrigin> {
let did_origin: DidRawOrigin<DidIdentifier, AccountId> = o.clone().into()?;
if did_origin.id == *a {
Ok(did_origin)
} else {
Err(o)
}
}

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(a: &DidIdentifier) -> Result<OuterOrigin, ()> {
let zero_account_id = AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes())
.expect("infinite length input; no invalid inputs for type; qed");

Ok(OuterOrigin::from(DidRawOrigin {
id: a.clone(),
submitter: zero_account_id,
}))
}
}

impl<DidIdentifier: Clone, AccountId: Clone> CallSources<AccountId, DidIdentifier>
for DidRawOrigin<DidIdentifier, AccountId>
{
Expand Down
15 changes: 12 additions & 3 deletions pallets/pallet-dip-consumer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ pub use crate::{origin::*, pallet::*, traits::SuccessfulProofVerifier};
pub mod pallet {
use super::*;

use frame_support::{dispatch::Dispatchable, pallet_prelude::*, traits::Contains, Twox64Concat};
use frame_support::{
dispatch::Dispatchable,
pallet_prelude::*,
traits::{Contains, EnsureOriginWithArg},
Twox64Concat,
};
use frame_system::pallet_prelude::*;
use parity_scale_codec::{FullCodec, MaxEncodedLen};
use scale_info::TypeInfo;
Expand All @@ -56,7 +61,11 @@ pub mod pallet {
/// computations.
type DipCallOriginFilter: Contains<RuntimeCallOf<Self>>;
/// The origin check for the `dispatch_as` call.
type DispatchOriginCheck: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin, Success = Self::AccountId>;
type DispatchOriginCheck: EnsureOriginWithArg<
<Self as frame_system::Config>::RuntimeOrigin,
Self::Identifier,
Success = Self::AccountId,
>;
/// The identifier of a subject, e.g., a DID.
type Identifier: Parameter + MaxEncodedLen;
/// The details stored in this pallet associated with any given subject.
Expand Down Expand Up @@ -98,7 +107,7 @@ pub mod pallet {
proof: IdentityProofOf<T>,
call: Box<RuntimeCallOf<T>>,
) -> DispatchResult {
let submitter = T::DispatchOriginCheck::ensure_origin(origin)?;
let submitter = T::DispatchOriginCheck::ensure_origin(origin, &identifier)?;
ensure!(T::DipCallOriginFilter::contains(&*call), Error::<T>::Filtered);
let mut identity_entry = IdentityEntries::<T>::get(&identifier);
let proof_verification_result = T::ProofVerifier::verify_proof_for_call_against_details(
Expand Down
12 changes: 6 additions & 6 deletions pallets/pallet-dip-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub use crate::{
pub mod pallet {
use super::*;

use frame_support::{pallet_prelude::*, traits::EnsureOrigin};
use frame_support::{pallet_prelude::*, traits::EnsureOriginWithArg};
use frame_system::pallet_prelude::*;

use crate::traits::{IdentityCommitmentGenerator, IdentityProvider, ProviderHooks, SubmitterInfo};
Expand All @@ -47,7 +47,7 @@ pub mod pallet {

#[pallet::config]
pub trait Config: frame_system::Config {
type CommitOriginCheck: EnsureOrigin<Self::RuntimeOrigin, Success = Self::CommitOrigin>;
type CommitOriginCheck: EnsureOriginWithArg<Self::RuntimeOrigin, Self::Identifier, Success = Self::CommitOrigin>;
type CommitOrigin: SubmitterInfo<Submitter = Self::AccountId>;
type Identifier: Parameter + MaxEncodedLen;
type IdentityCommitmentGenerator: IdentityCommitmentGenerator<Self>;
Expand Down Expand Up @@ -103,8 +103,8 @@ pub mod pallet {
identifier: T::Identifier,
version: Option<IdentityCommitmentVersion>,
) -> DispatchResult {
let dispatcher =
T::CommitOriginCheck::ensure_origin(origin).map(|e: <T as Config>::CommitOrigin| e.submitter())?;
let dispatcher = T::CommitOriginCheck::ensure_origin(origin, &identifier)
.map(|e: <T as Config>::CommitOrigin| e.submitter())?;

let commitment_version = version.unwrap_or(LATEST_COMMITMENT_VERSION);
let identity = T::IdentityProvider::retrieve(&identifier)
Expand Down Expand Up @@ -148,8 +148,8 @@ pub mod pallet {
identifier: T::Identifier,
version: Option<IdentityCommitmentVersion>,
) -> DispatchResult {
let dispatcher =
T::CommitOriginCheck::ensure_origin(origin).map(|e: <T as Config>::CommitOrigin| e.submitter())?;
let dispatcher = T::CommitOriginCheck::ensure_origin(origin, &identifier)
.map(|e: <T as Config>::CommitOrigin| e.submitter())?;

let commitment_version = version.unwrap_or(LATEST_COMMITMENT_VERSION);
let commitment = Self::delete_identity_commitment_storage_entry(&identifier, commitment_version)?;
Expand Down