Skip to content

Conversation

@ntn-x2
Copy link
Contributor

@ntn-x2 ntn-x2 commented Jul 8, 2022

fixes KILTProtocol/ticket#2029

This PR introduces the following components:

  • A new crates folder which contains additional crates we work on and might want to offer to the community. In this case, the hope is that the Asset DID crate would be migrated to the Substrate repo eventually
  • A new public-credentials pallet which stores credentials issued to assets as defined in the draft
  • A new RPC module to fetch either a single credential entry (i.e., block number + deposit info) for a given (subject and root hash), or all credentials (i.e., a vector of(root hash, credential entry) for a given subject.

Pallet

The new pallet exposes the following extrinsics:

// Internally calls authorization::add() and fails if that call fails
fn add(credential: InputCredential);
// Internally calls authorization::remove() and fails if that call fails
fn remove(claim_hash: Hash, ac: Option<AccessControl>);
// Internally calls authorization::reclaim_deposit() and fails if that call fails
fn reclaim_deposit(claim_hash: Hash);

EDIT: with the merge of #392, two new extrinsics will be added, and the claim_hash is replaced by the credential_id:

fn add(credential: InputCredential);
fn remove(credential_id: Hash, ac: Option<AccessControl>);
fn reclaim_deposit(credential_id: Hash);
fn revoke(credential_id: Hash,  ac: Option<AccessControl>);
fn unrevoke(credential_id: Hash,  ac: Option<AccessControl>);

The InputCredential type is the following:

{
    "claim": {
        "ctype_hash": "0ab12...",
        "subject": "did:asset:...",
        "contents": "0ab12...",        // Encoded claims
    },
    "nonce": "0ab12....",
    "claim_hash": "0ab12...",
    // OPTIONAL
    "claimer_signature": {
        "claimer_id": "4fa..."        // Full DID (with no did:kilt: prefix of the claimer)
        "signature_payload": MultiSignature    // The usual signature type we use everywhere else
    },
    // OPTIONAL
    "authorization_info": AuthorizationInfo
}

EDIT: with the merge of #392, the format will be changed to:

{
    "ctype_hash": "0ab12...",
    "subject": "did:asset:...",
    "contents": "0ab12...",        // Encoded claims
    // OPTIONAL
    "authorization_info": AuthorizationInfo
}

RPC

The RPC exposes the following functions:

get_credential(subject_id, root_hash) -> Option<CredentialEntry>
get_credentials(subject_id) -> Vec<(RootHash, CredentialEntry)>

EDIT: with the merge of #392, the RPC endpoints will be:

get_credential(credential_id) -> Option<CredentialEntry>
get_credentials(subject_id, filter) -> Vec<(RootHash, CredentialEntry)>

For update examples see the description of #392.

Copy link
Contributor

@weichweich weichweich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions and some minor comments. But I also think the proxy filter is wrong? That needs to be changed.

Will give it another run after our call, but looks good initially. 🐝

// Input subject ID
String,
// Runtime subject ID
runtime_common::assets::AssetDid,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for using the qualified path here and not simply AssetDid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generic(GenericAssetId),
}

impl From<Slip44Reference> for AssetId {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cherry 🍒 on top: I think there is a way to derive the from impl for each enum variant. You only implemented it for two because those are useful right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good to know, but the problem is that not all references are unambiguous. For instance an EvmSmartContractNonFungibleReference could refer to either an Erc721 or an Erc1155 asset type.

Comment on lines 129 to 136
(Some(SLIP44_NAMESPACE), Some(slip44_reference), identifier) => {
if identifier.is_some() {
log::trace!("Slip44 namespace does not accept an asset identifier.");
Err(Error::InvalidFormat)
} else {
Slip44Reference::from_utf8_encoded(slip44_reference).map(Self::Slip44)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would separate them using a comment but use match through out the whole thing and not nest it with if

Comment on lines 129 to 136
(Some(SLIP44_NAMESPACE), Some(slip44_reference), identifier) => {
if identifier.is_some() {
log::trace!("Slip44 namespace does not accept an asset identifier.");
Err(Error::InvalidFormat)
} else {
Slip44Reference::from_utf8_encoded(slip44_reference).map(Self::Slip44)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternativ: don't use if but something like 'ensure!()'

Comment on lines 145 to 152
match (chain, asset) {
(Some(chain), Some(asset)) => {
let chain_id = ChainId::from_utf8_encoded(chain).map_err(AssetDidError::ChainId)?;
let asset_id = AssetId::from_utf8_encoded(asset).map_err(AssetDidError::AssetId)?;
Ok(Self { chain_id, asset_id })
}
_ => Err(AssetDidError::InvalidFormat),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The easier extend is not an argument IMHO since the work to change a if-else to match is something any future dev can do. 😁 I also think we should stick with the linter rule.

Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

name = "attestation"
repository = "https://github.com/KILTprotocol/kilt-node"
version = "1.7.1"
repository = "https://github.com/KILTprotocol/mashnet-node"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this is an inherent error from my update. There are many more. But we can handle this in a separate PR.

Suggested change
repository = "https://github.com/KILTprotocol/mashnet-node"
repository = "https://github.com/KILTprotocol/kilt-node"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-fixed in 3b1ab07.

Copy link
Contributor

@weichweich weichweich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still loving it

sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28"}

# Internal runtime dependencies
public-credentials-runtime-api = {version = "1.7.2", path = "./runtime-api"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public-credentials-runtime-api = {version = "1.7.2", path = "./runtime-api"}
public-credentials-runtime-api = {path = "./runtime-api"}

@ntn-x2 ntn-x2 merged commit 3290887 into develop Sep 20, 2022
@ntn-x2 ntn-x2 deleted the aa/public-credentials-v2 branch September 20, 2022 13:21
@wischli wischli added this to the 1.8.0 milestone Oct 5, 2022
@ntn-x2 ntn-x2 restored the aa/public-credentials-v2 branch November 29, 2022 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants