Skip to content

Commit

Permalink
Merge pull request #14 from trackback-blockchain/feature/tp-170/capab…
Browse files Browse the repository at this point in the history
…ility-delegation-revocation

Feature/tp 170/capability delegation revocation
  • Loading branch information
Gayan committed Oct 13, 2021
2 parents 6fa10b0 + 65b8b0a commit a4e334e
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 54 deletions.
11 changes: 6 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Purge any existing dev chain state:
Start a dev chain:

```bash
./target/release/trackback-node--dev
./target/release/trackback-node --dev
```

Or, start a dev chain with detailed logging:
Expand Down
Empty file added node/chain_specs/live-net.json
Empty file.
97 changes: 97 additions & 0 deletions node/chain_specs/staging-net.json

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions node/chain_specs/test-net.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{sr25519, Pair, Public};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use sp_runtime::traits::{IdentifyAccount, Verify};
use std::path::PathBuf;

// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
Expand Down Expand Up @@ -76,6 +77,11 @@ pub fn development_config() -> Result<ChainSpec, String> {
))
}

pub fn test_net_config() -> ChainSpec {
// ChainSpec::from_json_file(PathBuf::from("../chain_specs/test-net.json")).unwrap()
ChainSpec::from_json_bytes(&include_bytes!("../chain_specs/staging-net.json")[..]).unwrap()
}

pub fn local_testnet_config() -> Result<ChainSpec, String> {
let wasm_binary =
WASM_BINARY.ok_or_else(|| "Development wasm binary not available".to_string())?;
Expand Down
1 change: 1 addition & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl SubstrateCli for Cli {
Ok(match id {
| "dev" => Box::new(chain_spec::development_config()?),
| "" | "local" => Box::new(chain_spec::local_testnet_config()?),
| "test-net" => Box::new(chain_spec::test_net_config()),
| path => Box::new(chain_spec::ChainSpec::from_json_file(
std::path::PathBuf::from(path),
)?),
Expand Down
1 change: 1 addition & 0 deletions pallets/dids/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
rstest = { version = "0.11.0" }
rand = { version = "0.8.4"}

[lib]
doctest = false
Expand Down
40 changes: 23 additions & 17 deletions pallets/dids/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ pub mod pallet {
type TimeProvider: UnixTime;
}

#[allow(non_camel_case_types)]
pub type didURI = Vec<u8>;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
Expand All @@ -101,7 +98,7 @@ pub mod pallet {
pub(super) type DIDDocument<T: Config> = StorageMap<
_,
Blake2_128Concat,
didURI,
Vec<u8>,
DID<T>
>;

Expand Down Expand Up @@ -217,17 +214,17 @@ pub mod pallet {
/// DID Revocation
/// Throws DoesNotExists for a non existing DID revocation
#[pallet::weight(0)]
pub fn revoke_did(origin: OriginFor<T>, did_hash: Vec<u8>) -> DispatchResultWithPostInfo {
pub fn revoke_did(origin: OriginFor<T>, did_uri: Vec<u8>) -> DispatchResultWithPostInfo {
let origin_account = ensure_signed(origin)?;

ensure!(
DIDDocument::<T>::contains_key(&did_hash),
DIDDocument::<T>::contains_key(&did_uri),
Error::<T>::DIDDoesNotExists
);

DIDDocument::<T>::remove(&did_hash);
DIDDocument::<T>::remove(&did_uri);

Self::deposit_event(Event::DIDDocumentRevoked(did_hash, origin_account));
Self::deposit_event(Event::DIDDocumentRevoked(did_uri, origin_account));

Ok(().into())
}
Expand All @@ -239,8 +236,8 @@ pub mod pallet {
did_uri: Vec<u8>,
did_resolution_metadata: Option<Vec<u8>>,
did_document_metadata: Option<Vec<u8>>,
public_keys: Option<Vec<u8>>,
did_ref: Option<Vec<u8>>
did_ref: Option<Vec<u8>>,
public_keys: Option<Vec<Vec<u8>>>,
) -> DispatchResultWithPostInfo {
let _origin_account = ensure_signed(origin)?;

Expand Down Expand Up @@ -272,8 +269,10 @@ pub mod pallet {
did_document: Vec<u8>,
did_document_metadata: Option<Vec<u8>>,
did_resolution_metadata: Option<Vec<u8>>,
sender_account_id: <T as frame_system::Config>::AccountId,
did_hash: Vec<u8>,
sender_account_id: Vec<u8>,
did_uri: Vec<u8>,
did_ref: Option<Vec<u8>>,
public_keys: Option<Vec<Vec<u8>>>
) -> DispatchResultWithPostInfo {
let origin_account = ensure_signed(origin)?;

Expand All @@ -282,25 +281,32 @@ pub mod pallet {
let time = T::TimeProvider::now().as_secs();

ensure!(
!DIDDocument::<T>::contains_key(&did_hash),
!DIDDocument::<T>::contains_key(&did_uri),
Error::<T>::DIDExists
);

/// Checks the DID document contains the section `Capability Delegation`
/// Reference :- https://www.w3.org/TR/did-core/#capability-delegation

let doc = str::from_utf8(&did_document).unwrap();
let sanitised = doc.replace("\n", "").replace(" ", "");


DIDDocument::<T>::insert(
did_hash.clone(),
did_uri.clone(),
DID {
did_document_metadata,
did_resolution_metadata,
block_number,
block_time_stamp: time.clone(),
updated_timestamp: time,
did_ref: None,
did_ref,
sender_account_id,
public_keys: None
public_keys,
},
);

Self::deposit_event(Event::DIDDocumentCreated(did_hash, origin_account));
Self::deposit_event(Event::DIDDocumentCreated(did_uri, origin_account));

Ok(().into())
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/dids/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub struct DID<T: Config> {
pub did_ref: Option<Vec<u8>>,

// Sender AccountId
pub sender_account_id: <T as frame_system::Config>::AccountId,
pub sender_account_id: Vec<u8>,

// public keys
pub public_keys: Option<Vec<u8>>
pub public_keys: Option<Vec<Vec<u8>>>

}

Expand Down
Loading

0 comments on commit a4e334e

Please sign in to comment.