Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
19d857d
wip: skeleton in place
ntn-x2 Jun 9, 2022
98c24ce
wip: trying to fight with rust-analyzer
ntn-x2 Jun 10, 2022
8704a4d
wip: FFS
ntn-x2 Jun 10, 2022
39691f2
Merge commit '52a47659becda33033a269c7d8152dcf5493d0b9' into aa/publi…
ntn-x2 Jun 13, 2022
323296d
wip: tests for the new pallet
ntn-x2 Jun 13, 2022
b586fb2
test: add unit tests for the new pallet
ntn-x2 Jun 14, 2022
d01497b
chore: fmt
ntn-x2 Jun 14, 2022
e2d56a2
fix: restore toolchain to nightly
ntn-x2 Jun 14, 2022
7bc2e70
core: clippy
ntn-x2 Jun 14, 2022
f98c1e7
wip: minor chores
ntn-x2 Jun 14, 2022
21aeb3a
test: add hcecks for deposit reservations
ntn-x2 Jun 15, 2022
bb4d421
test: add InvalidInput test case
ntn-x2 Jun 15, 2022
c16dd8d
feat: working on parsing the right chain_id information
ntn-x2 Jun 15, 2022
6d07577
feat: add dotsama and solana chains
ntn-x2 Jun 16, 2022
1ca4a9e
feat: generic chain support
ntn-x2 Jun 16, 2022
bc3b0c6
feat: add utility functions for chain IDs
ntn-x2 Jun 16, 2022
ba3fb49
chore: clippy + fmt
ntn-x2 Jun 16, 2022
f9878c9
fix: uncomment remaining test functions
ntn-x2 Jun 16, 2022
18c7326
wip: first version of new pallet
ntn-x2 Jun 16, 2022
eed9719
feat: new pallet for chain IDs
ntn-x2 Jun 16, 2022
918fff0
wip: fixing last issues
ntn-x2 Jun 16, 2022
b9ae971
fix: chain ids now working fine
ntn-x2 Jun 17, 2022
a43f2af
feat: asset id complete (untested)
ntn-x2 Jun 17, 2022
df4f1aa
most of unit tests for asset IDs in
ntn-x2 Jun 17, 2022
cd0748b
test: unit tests passing
ntn-x2 Jun 17, 2022
948832a
wip: almost complete
ntn-x2 Jun 17, 2022
031e851
chore: small improvements
ntn-x2 Jun 17, 2022
f38741f
feat: default implementations of important traits
ntn-x2 Jun 20, 2022
dc49855
chore: few needed adjustments
ntn-x2 Jun 20, 2022
feb4759
test: add test for too long credentials
ntn-x2 Jun 20, 2022
144e325
chore: mashnet-node-runtime compiling
ntn-x2 Jun 20, 2022
5a95626
Merge commit '40c48d5f89aacac2971ddede247561fd9073a218' into aa/publi…
ntn-x2 Jun 30, 2022
05b498d
chore: minor refinements
ntn-x2 Jun 30, 2022
5b2426c
chore: remove asset transfer feature
ntn-x2 Jul 1, 2022
ea03307
chore: add test cases for smart contract addresses without leading
ntn-x2 Jul 4, 2022
5835b00
Merge commit '2b576fd6fd568de9b1ef38670aea547251e34173' into aa/publi…
ntn-x2 Jul 5, 2022
d38cab2
fix: dependencies in mashnet-node compilation
ntn-x2 Jul 5, 2022
2cc096e
chore: re-organize imports
ntn-x2 Jul 5, 2022
6f9c328
chore: last cleanups for chain asset DID stuff
ntn-x2 Jul 5, 2022
d5d42b7
fix: adjust asset DID definition in code
ntn-x2 Jul 5, 2022
0623037
wip: whole project compiling
ntn-x2 Jul 5, 2022
22a4690
wip: benchmarking refactoring
ntn-x2 Jul 6, 2022
6c9999a
chore: refactored the default implementation for AssetDid
ntn-x2 Jul 6, 2022
4a048db
wip: refactor almost completed
ntn-x2 Jul 6, 2022
9e521ed
wip: first benchmark case compiling
ntn-x2 Jul 6, 2022
acc061e
wip: refactoring before review
ntn-x2 Jul 8, 2022
5d0c04f
wip: refactoring pt. 2
ntn-x2 Jul 8, 2022
9317196
wip: refactoring pt. 3
ntn-x2 Jul 8, 2022
3946a45
chore: optimise eip155 chain reference
ntn-x2 Jul 11, 2022
f2f477c
wip: optimizing storage
ntn-x2 Jul 11, 2022
39b9630
wip: tests failing
ntn-x2 Jul 11, 2022
888eabb
chore: completed
ntn-x2 Jul 11, 2022
bdd5990
wip: switch to hex_literal
ntn-x2 Jul 11, 2022
c0c6863
chore: refactor complete
ntn-x2 Jul 11, 2022
334a8d6
chore: final chores for the asset DID crate
ntn-x2 Jul 12, 2022
2cca385
bench: setup for public-credentials pallet complete
ntn-x2 Jul 12, 2022
bedf0cd
wip: implementing the Display trait for the AssetDID type
ntn-x2 Jul 12, 2022
cae0846
test: unit tests for ChainID Display implementation working
ntn-x2 Jul 12, 2022
dc4ad62
test: unit tests completed for asset DID crate
ntn-x2 Jul 12, 2022
3b4d125
feat: whole project compiling after implementing Display
ntn-x2 Jul 12, 2022
80dbba5
chore: fmt
ntn-x2 Jul 12, 2022
f8dc617
chore: update benchmarking script for new pallet
ntn-x2 Jul 12, 2022
ba95ca3
chore: update benchmark scripts and weights
ntn-x2 Jul 12, 2022
e68d0f1
chore: update weights
ntn-x2 Jul 12, 2022
31a7de8
Merge commit 'c8f45771eb3f87c2617f925a7ee088a68fcc4990' into aa/publi…
ntn-x2 Jul 12, 2022
5e12525
fix: correct signature verification weight
ntn-x2 Jul 12, 2022
db9eaa5
chore: address TODO
ntn-x2 Jul 12, 2022
616e745
chore: update test script to use --all-targets and check for test tar…
ntn-x2 Jul 12, 2022
a52e26d
test: storage deposit test for runtimes
ntn-x2 Jul 12, 2022
1e4ccd4
chore: address last TODOs
ntn-x2 Jul 12, 2022
705c093
chore: fmt
ntn-x2 Jul 12, 2022
3bcb397
chore: factor everything out into variables
ntn-x2 Jul 13, 2022
9acde1e
fix: clippy issues
ntn-x2 Jul 13, 2022
964613e
fix: checks for asset DID length bounds
ntn-x2 Jul 13, 2022
30fb527
Merge commit 'd8af5d12531d1e2681c5038490958bfb08536a84' into aa/publi…
ntn-x2 Jul 15, 2022
ff7cebd
chore: make failing clearer for decimal references
ntn-x2 Jul 15, 2022
7189465
chore: factor out bounds checking function
ntn-x2 Jul 15, 2022
3413d2b
fix: max line length limit
ntn-x2 Jul 15, 2022
b4140b7
chore: factor out split function
ntn-x2 Jul 15, 2022
606ac15
chore: right syntax for generics
ntn-x2 Jul 15, 2022
9059733
chore: typo
ntn-x2 Jul 15, 2022
8483968
chore: factor out credential retrieval in public credentials pallet
ntn-x2 Jul 15, 2022
61bfdb1
feat: add public credentials runtime API definition
ntn-x2 Jul 18, 2022
ba6dca4
feat: add public credentials runtime API implementation for standalone
ntn-x2 Jul 18, 2022
bdad321
wip: only need to add the RPC to the node executable
ntn-x2 Jul 18, 2022
ded3efd
wip: add serialization support
ntn-x2 Jul 18, 2022
721ed4d
feat: compiling
ntn-x2 Jul 19, 2022
b6dbe2a
fix: compiling with one generic added
ntn-x2 Jul 19, 2022
7e49dbb
fix: compiling with second argument
ntn-x2 Jul 19, 2022
ef844d5
COMPILING
ntn-x2 Jul 19, 2022
85f0b45
chore: qol improvements
ntn-x2 Jul 20, 2022
91fd513
feat: add key to return value of get_credentials
ntn-x2 Jul 20, 2022
ff83e98
chore: remove unneded serde support
ntn-x2 Jul 20, 2022
0001d8c
deps: remove unnecessary serde deps
ntn-x2 Jul 20, 2022
e2b553e
wip: refactoring
ntn-x2 Jul 20, 2022
026b2d0
almost there
ntn-x2 Jul 20, 2022
378d745
feat: add runtime api implementation for parachain runtimes
ntn-x2 Jul 20, 2022
ddd4cdc
chore: remove InputError type from public-credentials pallet
ntn-x2 Jul 21, 2022
34d4332
fix: change TryFrom requirement for SubjectId
ntn-x2 Jul 21, 2022
cc47d5e
chore: remove unused deps
ntn-x2 Jul 21, 2022
80b98b8
chore: update repo links
ntn-x2 Jul 21, 2022
23103ad
chore: move errors in their own module
ntn-x2 Jul 21, 2022
750b3b9
chore: comments
ntn-x2 Jul 21, 2022
5b7d2a8
chore: split components into its own struct
ntn-x2 Jul 21, 2022
a9a3891
chore: add link to const generics
ntn-x2 Jul 21, 2022
17e1fcc
chore: replace switch with if let
ntn-x2 Jul 21, 2022
74526d7
chore: replace matches! with contains
ntn-x2 Jul 21, 2022
0329cf8
chore: make comment a doc comment
ntn-x2 Jul 21, 2022
ae42b32
chore: revert Eq derive for DidDetails
ntn-x2 Jul 21, 2022
a3d1ed8
chore: attestation namespace not needed
ntn-x2 Jul 21, 2022
68c5851
chore: re-add commented out pallets in bench script
ntn-x2 Jul 21, 2022
fc6c7d1
chore: add some logging to the InvalidFormat error cases
ntn-x2 Jul 22, 2022
a6c6954
chore: move serde import up again
ntn-x2 Jul 22, 2022
e43cff7
chore: replace From<Error> for i32 with repr(i32)
ntn-x2 Jul 22, 2022
e8aaa0a
chore: improve efficienct of Display
ntn-x2 Jul 22, 2022
c580520
fix: changes to public credentials based on feedback (#392)
ntn-x2 Aug 8, 2022
79bade8
merge origin/develop into current branch
ntn-x2 Aug 8, 2022
127f8c1
Fix clone runtime for public credentials RPC
ntn-x2 Aug 8, 2022
a734eb9
Remove unused deps
ntn-x2 Aug 8, 2022
58b218c
Remove most of the unrelated changes
ntn-x2 Aug 8, 2022
89c8ce0
Last chores
ntn-x2 Aug 8, 2022
9265b3a
Remove non_exhaustive from all structs
ntn-x2 Aug 9, 2022
e34a900
Add comments to Cargo.toml
ntn-x2 Aug 10, 2022
7fa209a
Switch ordering in Cargo.toml
ntn-x2 Aug 10, 2022
5b31ced
Switch ordering in Cargo.toml
ntn-x2 Aug 10, 2022
8931f71
Cargo.toml fixes
ntn-x2 Aug 10, 2022
57baf68
Refactor benchmarking helper function
ntn-x2 Aug 10, 2022
295b816
Update public credentials pallet description
ntn-x2 Aug 10, 2022
36ca6a2
Update comments in pallet
ntn-x2 Aug 10, 2022
88a3aaf
Update description of the reclaim_deposit extrinsic
ntn-x2 Aug 10, 2022
98a4531
More comments
ntn-x2 Aug 10, 2022
5144705
Add case for invalid input
ntn-x2 Aug 10, 2022
d054cb1
remove unused variable in benchmarks
ntn-x2 Aug 10, 2022
4acf61c
Merge branch origin/develop into aa/public-credentials-v2
ntn-x2 Aug 10, 2022
7fe38a0
Make comment a doc comment
ntn-x2 Aug 10, 2022
175ed43
fmt
ntn-x2 Aug 12, 2022
6e54dd9
Fix match case
ntn-x2 Sep 19, 2022
29f5a4c
Fix import
ntn-x2 Sep 19, 2022
9ebcd05
Fix single match case
ntn-x2 Sep 19, 2022
2508c30
Fix new line
ntn-x2 Sep 19, 2022
88b034c
Fix access control file
ntn-x2 Sep 19, 2022
bc96327
Fix more matches
ntn-x2 Sep 19, 2022
9e43b3e
Fix proxy type
ntn-x2 Sep 19, 2022
4a310fb
Fmt
ntn-x2 Sep 19, 2022
69fa1c0
Merge commit 'a7b2c43a7c02b4d3a51f895655c37e2a78412abd' into aa/publi…
ntn-x2 Sep 19, 2022
3b1ab07
Fix repo links
ntn-x2 Sep 20, 2022
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
wip: FFS
  • Loading branch information
ntn-x2 committed Jun 10, 2022
commit 8704a4dbf0227c30e037fbb8c78ab76437cf9835
28 changes: 17 additions & 11 deletions pallets/attestation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,8 @@ pub mod pallet {
#[pallet::weight(<T as pallet::Config>::WeightInfo::reclaim_deposit())]
pub fn reclaim_deposit(origin: OriginFor<T>, claim_hash: ClaimHashOf<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let attestation = Attestations::<T>::get(&claim_hash).ok_or(Error::<T>::AttestationNotFound)?;

ensure!(attestation.deposit.owner == who, Error::<T>::Unauthorized);

// *** No Fail beyond this point ***

log::debug!("removing Attestation");

Self::remove_attestation_entry(attestation, claim_hash);
Self::deposit_event(Event::DepositReclaimed(who, claim_hash));

Ok(())
Self::reclaim_dep(who, claim_hash)
}
}

Expand Down Expand Up @@ -466,6 +456,22 @@ pub mod pallet {
Ok(Some(<T as pallet::Config>::WeightInfo::remove()).into())
}

// TODO: Change naming
pub fn reclaim_dep(sender: AccountIdOf<T>, claim_hash: ClaimHashOf<T>) -> DispatchResult {
let attestation = Attestations::<T>::get(&claim_hash).ok_or(Error::<T>::AttestationNotFound)?;

ensure!(attestation.deposit.owner == sender, Error::<T>::Unauthorized);

// *** No Fail beyond this point ***

log::debug!("removing Attestation");

Self::remove_attestation_entry(attestation, claim_hash);
Self::deposit_event(Event::DepositReclaimed(sender, claim_hash));

Ok(())
}

/// Reserve the deposit and record the deposit on chain.
///
/// Fails if the `payer` has a balance less than deposit.
Expand Down
17 changes: 12 additions & 5 deletions pallets/public-credentials/src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,29 @@ use scale_info::TypeInfo;

use frame_support::RuntimeDebug;

#[derive(Encode, Decode, Clone, MaxEncodedLen, RuntimeDebug, PartialEq, Eq, PartialOrd, Ord, TypeInfo)]
use kilt_support::deposit::Deposit;

use crate::{AccountIdOf, BalanceOf, Config};

#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, PartialOrd, Ord, TypeInfo)]
pub struct Claim<CtypeHash, SubjectIdentifier, Content> {
pub ctype_hash: CtypeHash,
pub subject: SubjectIdentifier,
pub contents: Content,
}

// TODO: Add support for delegation and claimer's signature.
#[derive(Encode, Decode, Clone, MaxEncodedLen, RuntimeDebug, PartialEq, Eq, PartialOrd, Ord, TypeInfo)]
#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, PartialOrd, Ord, TypeInfo)]
pub struct Credential<CtypeHash, SubjectIdentifier, ClaimContent, ClaimHash, Nonce> {
pub claim: Claim<CtypeHash, SubjectIdentifier, ClaimContent>,
pub nonce: Nonce,
pub claim_hash: ClaimHash,
}

pub struct CredentialEntry<BlockNumber, Deposit> {
pub block_number: BlockNumber,
pub deposit: Deposit
#[derive(Encode, Decode, Clone, MaxEncodedLen, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct CredentialEntry<T: Config> {
pub block_number: T::BlockNumber,
pub deposit: Deposit<AccountIdOf<T>, BalanceOf<T>>,
}
85 changes: 60 additions & 25 deletions pallets/public-credentials/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod pallet {

use attestation::{AttesterOf, ClaimHashOf};
use ctype::CtypeHashOf;
use kilt_support::traits::CallSources;
use kilt_support::{deposit::Deposit, traits::CallSources};

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
Expand All @@ -57,6 +57,7 @@ pub mod pallet {
// TODO: Replace with an enum that includes KILT DIDs and asset DIDs.
pub(crate) type SubjectIdOf<T> = AccountIdOf<T>;
pub(crate) type BalanceOf<T> = <<T as attestation::Config>::Currency as Currency<AccountIdOf<T>>>::Balance;
pub(crate) type CurrencyOf<T> = <T as attestation::Config>::Currency;

pub type CredentialOf<T> = Credential<
CtypeHashOf<T>,
Expand Down Expand Up @@ -90,11 +91,16 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}


#[pallet::storage]
#[pallet::getter(fn get_credential_info)]
pub type Credentials<T> =
StorageDoubleMap<_, Twox64Concat, SubjectIdOf<T>, Blake2_128Concat, ClaimHashOf<T>, CredentialEntry<BlockNumberFor<T>, Deposit<AccountIdOf<T>, BalanceOf<T>>>>;
pub type Credentials<T> = StorageDoubleMap<
_,
Twox64Concat,
SubjectIdOf<T>,
Blake2_128Concat,
ClaimHashOf<T>,
CredentialEntry<T>,
>;

// Reverse map to make sure that the same claim hash cannot be issued to two
// different subjects by issuing it to subject #1, then removing it only from
Expand All @@ -113,6 +119,10 @@ pub mod pallet {
claim_hash: ClaimHashOf<T>,
block_number: BlockNumberFor<T>,
},
CredentialRemoved {
subject_id: SubjectIdOf<T>,
claim_hash: ClaimHashOf<T>,
},
}

#[pallet::error]
Expand Down Expand Up @@ -145,7 +155,7 @@ pub mod pallet {
// (potentially to a different subject)
ensure!(
!CredentialsUnicityIndex::<T>::contains_key(&claim_hash),
Error::<T>::AttestationCreated
Error::<T>::CredentialIssued
);

// Check that enough funds can be reserved to pay for both attestation and
Expand All @@ -163,10 +173,11 @@ pub mod pallet {
// reserve its part of the deposit
attestation::Pallet::<T>::write_attestation(ctype_hash, claim_hash, attester, payer.clone(), None)?;

// Take the rest of the deposit
let deposit = Self::reserve_deposit(payer, deposit_amount)?;

// *** No Fail beyond this point ***

// Take the rest of the deposit
let deposit = Self::reserve_deposit(payer, deposit_amount)
let block_number = frame_system::Pallet::<T>::block_number();

Credentials::<T>::insert(&subject, &claim_hash, CredentialEntry { deposit, block_number });
Expand All @@ -182,39 +193,48 @@ pub mod pallet {
}

#[pallet::weight(0)]
pub fn revoke(origin: OriginFor<T>, claim_hash: ClaimHashOf<T>) -> DispatchResult {
pub fn remove(origin: OriginFor<T>, claim_hash: ClaimHashOf<T>) -> DispatchResultWithPostInfo {
let source = <T as Config>::EnsureOrigin::ensure_origin(origin)?;
let attester = source.subject();

// Verifies that the credential exists.
ensure!(
CredentialsUnicityIndex::<T>::contains_key(&claim_hash),
Error::<T>::CredentialNotFound
);
let credential_subject =
CredentialsUnicityIndex::<T>::get(&claim_hash).ok_or(Error::<T>::CredentialNotFound)?;
// Should never happen if the line above succeeds.
let credential_entry =
Credentials::<T>::get(&credential_subject, &claim_hash).ok_or(Error::<T>::CredentialNotFound)?;

// Delegate to the attestation pallet the revocation logic.
// Delegate to the attestation pallet the removal logic.
// This guarantees that the owner is calling this function.
attestation::Pallet::<T>::revoke_attestation(attester, claim_hash, None)?;
let result = attestation::Pallet::<T>::remove_attestation(attester, claim_hash, None)?;

// *** No Fail beyond this point ***
Self::remove_credential_entry(credential_subject, claim_hash, credential_entry);

// Take the rest of the deposit
<T as attestation::Config>::Currency::reserve(&payer, deposit_amount)?;
Ok(result)
}

let block_number = frame_system::Pallet::<T>::block_number();
#[pallet::weight(0)]
pub fn reclaim_deposit(origin: OriginFor<T>, claim_hash: ClaimHashOf<T>) -> DispatchResult {
let who = ensure_signed(origin)?;

Credentials::<T>::insert(&subject, &claim_hash, block_number);
CredentialsUnicityIndex::<T>::insert(&claim_hash, subject.clone());
// Verifies that the credential exists.
let credential_subject =
CredentialsUnicityIndex::<T>::get(&claim_hash).ok_or(Error::<T>::CredentialNotFound)?;
// Should never happen if the line above succeeds.
let credential_entry =
Credentials::<T>::get(&credential_subject, &claim_hash).ok_or(Error::<T>::CredentialNotFound)?;

Self::deposit_event(Event::CredentialStored {
subject_id: subject,
claim_hash,
block_number,
});
// Delegate to the attestation pallet the removal logic.
// This guarantees that the owner is calling this function.
attestation::Pallet::<T>::reclaim_dep(who, claim_hash)?;

Self::remove_credential_entry(credential_subject, claim_hash, credential_entry);

Ok(())
}
}

impl<T: Config> Pallet<T> {
pub(crate) fn reserve_deposit(
payer: AccountIdOf<T>,
deposit: BalanceOf<T>,
Expand All @@ -226,5 +246,20 @@ pub mod pallet {
amount: deposit,
})
}

pub(crate) fn remove_credential_entry(
credential_subject: SubjectIdOf<T>,
claim_hash: ClaimHashOf<T>,
credential: CredentialEntry<T>,
) {
kilt_support::free_deposit::<AccountIdOf<T>, CurrencyOf<T>>(&credential.deposit);
Credentials::<T>::remove(&credential_subject, &claim_hash);
CredentialsUnicityIndex::<T>::remove(&claim_hash);

Self::deposit_event(Event::CredentialRemoved {
subject_id: credential_subject,
claim_hash,
});
}
}
}
2 changes: 1 addition & 1 deletion runtimes/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use opaque::*;
pub use frame_support::weights::constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use frame_support::{
parameter_types,
traits::{Contains, ContainsLengthBound, Currency, Get, OnRuntimeUpgrade, SortedMembers},
traits::{Contains, ContainsLengthBound, Currency, Get, SortedMembers},
weights::DispatchClass,
};
use frame_system::limits;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2022-05-11"
channel = "stable"
targets = [ "wasm32-unknown-unknown" ]