Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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: add initial support for more complex service endpoint structure
  • Loading branch information
ntn-x2 committed Aug 4, 2021
commit 1ea3202d8d6ef4674333c136476af6c3c82bfa28
19 changes: 14 additions & 5 deletions pallets/did/src/did_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// If you feel like getting in touch with us, you can do so at [email protected]

use codec::{Decode, Encode, WrapperTypeEncode};
use frame_support::BoundedVec;
use kilt_primitives::Hash;
use sp_core::{ecdsa, ed25519, sr25519};
use sp_runtime::traits::Verify;
use sp_std::{
Expand Down Expand Up @@ -622,8 +624,8 @@ pub struct DidCreationDetails<T: Config> {
pub new_attestation_key: Option<DidVerificationKey>,
/// \[OPTIONAL\] The new delegation key.
pub new_delegation_key: Option<DidVerificationKey>,
/// \[OPTIONAL\] The URL containing the DID endpoints description.
pub new_endpoint_url: Option<Url>,
/// The service endpoints information action.
pub new_endpoint_url: DidFragmentUpdateAction<ServiceEndpoints<T::MaxUrlLength>>,
}

/// The details to update a DID.
Expand All @@ -642,13 +644,20 @@ pub struct DidUpdateDetails<T: Config> {
/// not be considered for removal in this operation, so it is not
/// possible to specify it for removal in this set.
pub public_keys_to_remove: BTreeSet<KeyIdOf<T>>,
/// \[OPTIONAL\] The new endpoint URL.
pub new_endpoint_url: Option<Url>,
/// The service endpoints information action.
pub new_endpoint_url: DidFragmentUpdateAction<ServiceEndpoints<T::MaxUrlLength>>,
}

#[derive(Clone, Decode, Debug, Encode, PartialEq, Eq)]
pub struct ServiceEndpoints<UrlMaxLength: Get<u32>> {
content_hash: Hash,
urls: BoundedVec<Url, UrlMaxLength>,
content_type: ContentType,
}

/// Possible actions on a DID fragment (e.g, a verification key or the endpoint services) within a
/// [DidUpdateOperation].
#[derive(Clone, Decode, Debug, Encode, Eq, Ord, PartialEq, PartialOrd)]
#[derive(Copy, Clone, Decode, Debug, Encode, Eq, PartialEq)]
pub enum DidFragmentUpdateAction<FragmentType> {
/// Do not change the DID fragment.
Ignore,
Expand Down
17 changes: 13 additions & 4 deletions pallets/did/src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,18 @@ pub const FTPS_URI_SCHEME: &str = "ftps://";
/// The expected URI scheme for IPFS endpoints.
pub const IPFS_URI_SCHEME: &str = "ipfs://";

/// The content type of a resource pointed by a service URL.
#[derive(Clone, Decode, Debug, Encode, PartialEq, Eq)]
pub enum ContentType {
/// application/json
ApplicationJson,
/// application/json+ld
ApplicationJsonLd
}

/// A web URL starting with either http:// or https://
/// and containing only ASCII URL-encoded characters.
#[derive(Clone, Decode, Debug, Encode, PartialEq)]
#[derive(Clone, Decode, Debug, Encode, PartialEq, Eq)]
pub struct HttpUrl {
payload: Vec<u8>,
}
Expand Down Expand Up @@ -62,7 +71,7 @@ impl TryFrom<&[u8]> for HttpUrl {

/// An FTP URL starting with ftp:// or ftps://
/// and containing only ASCII URL-encoded characters.
#[derive(Clone, Decode, Debug, Encode, PartialEq)]
#[derive(Clone, Decode, Debug, Encode, PartialEq, Eq)]
pub struct FtpUrl {
payload: Vec<u8>,
}
Expand All @@ -89,7 +98,7 @@ impl TryFrom<&[u8]> for FtpUrl {
}

/// An IPFS URL starting with ipfs://. Both CIDs v0 and v1 supported.
#[derive(Clone, Decode, Debug, Encode, PartialEq)]
#[derive(Clone, Decode, Debug, Encode, PartialEq, Eq)]
pub struct IpfsUrl {
payload: Vec<u8>,
}
Expand Down Expand Up @@ -123,7 +132,7 @@ impl TryFrom<&[u8]> for IpfsUrl {
}

/// Supported URLs.
#[derive(Clone, Decode, Debug, Encode, PartialEq)]
#[derive(Clone, Decode, Debug, Encode, PartialEq, Eq)]
pub enum Url {
/// See [HttpUrl].
Http(HttpUrl),
Expand Down