-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add merkleization of DID documents (#492)
Fixes KILTprotocol/ticket#2557 and fixes KILTprotocol/ticket#2556. This PR builds on top of the shell PR, and adds support for Merkle proof for DID documents. ## Merkle proof structure A DID merkle proof is, at the core, an order set of (key, value) pairs, on which proof-of-inclusion and proof-of-non-inclusion can be performed. This PR generates and validates merkle proofs where leaves are of two types: - a DID key reference leave, whose key is the tuple (key ID, key relationship) and the value is an empty tuple - a DID key details leave, whose key is the key ID and the value is the key details For each key reference leaf with a given key ID, the proof also has to contain a key details leaf whose key is the key ID. Multiple reference leaves can reference the same key details leaf, optimising the storage size. ## New runtime APIs There is a new runtime API which the DIP sender would expose, and that allows anyone to generate a merkle proof for a given DID identifier and set of key IDs. The result contains the merkle root (which must match what other chains have stored in their `pallet-dip-receiver` map), and a merkle proof, which includes blinded values and a set of key reference and key details leaves for the keys identified by the provided key IDs. ## How to test The setup flow is similar to that of #489. Specifically: - Set up the local Rococo network onboarding the sender and receiver chains with para IDs 2_000 and 2_001 respectively - Open an HRMP channel from sender 2_000 to receiver 2_001 - Create a DID on the sender chain, e.g., using the [kilt-did-utilities](https://github.com/KILTprotocol/kilt-did-utilities) tool ![Screenshot 2023-03-27 at 10 00 48](https://user-images.githubusercontent.com/6704504/227900994-41f0f355-84bd-4b8a-a2a8-3a9c74447e59.png) - Push the identity of the DID to the receiver chain via the `pallet-dip-sender` extrinsic ![Screenshot 2023-03-27 at 10 01 13](https://user-images.githubusercontent.com/6704504/227901150-7e8c9c9d-8aac-4739-8ad3-fad4ba6ff5f8.png) - Call the runtime API to generate a proof for the created DID with some keys revealed ![Screenshot 2023-03-27 at 10 01 40](https://user-images.githubusercontent.com/6704504/227901309-94b4dbc9-ca83-4541-820d-d1bec6adc6f0.png) - Use the generated proof to dispatch an extrinsic on the receiving chain ### How to use the runtime API with polkadot apps There is currently no support for the new runtime API in the public polkadot apps instance. To use the runtime APIs from UI, please use [our fork from the aa/dip-sender-template branch](https://github.com/KILTprotocol/polkadot-apps/tree/aa/dip-sender-template), by running `yarn && yarn build && yarn start`, then connecting to the sender node WS socket. For runtime augmentation within a Node script, please use our [SDK repo from the aa/dip-merkle-proof branch](https://github.com/KILTprotocol/sdk-js/tree/aa/dip-merkle-proof).
- Loading branch information
Showing
29 changed files
with
1,052 additions
and
115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,17 @@ | |
|
||
// If you feel like getting in touch with us, you can do so at [email protected] | ||
|
||
use pallet_dip_receiver::traits::SuccessfulProofVerifier; | ||
use runtime_common::dip::{receiver::DidMerkleProofVerifier, ProofLeaf}; | ||
use sp_std::vec::Vec; | ||
|
||
use crate::{DidIdentifier, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin}; | ||
use crate::{BlockNumber, DidIdentifier, Hash, Hasher, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin}; | ||
|
||
impl pallet_dip_receiver::Config for Runtime { | ||
type BlindedValue = Vec<Vec<u8>>; | ||
type Identifier = DidIdentifier; | ||
// TODO: Change with right one | ||
type ProofDigest = [u8; 32]; | ||
// TODO: Change with right one | ||
type ProofLeafKey = [u8; 4]; | ||
// TODO: Change with right one | ||
type ProofLeafValue = [u8; 4]; | ||
// TODO: Change with right one | ||
type ProofVerifier = SuccessfulProofVerifier<Self::ProofDigest, Self::ProofLeafKey, Self::ProofLeafValue>; | ||
type ProofLeaf = ProofLeaf<Hash, BlockNumber>; | ||
type ProofDigest = Hash; | ||
type ProofVerifier = DidMerkleProofVerifier<Hash, BlockNumber, Hasher>; | ||
type RuntimeCall = RuntimeCall; | ||
type RuntimeEvent = RuntimeEvent; | ||
type RuntimeOrigin = RuntimeOrigin; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,14 @@ | |
|
||
// If you feel like getting in touch with us, you can do so at [email protected] | ||
|
||
use did::did_details::DidDetails; | ||
use dip_support::VersionedIdentityProofAction; | ||
use pallet_dip_sender::traits::{ | ||
DefaultIdentityProofGenerator, DefaultIdentityProvider, TxBuilder, XcmRouterDispatcher, | ||
}; | ||
use pallet_dip_sender::traits::{TxBuilder, XcmRouterDispatcher}; | ||
use parity_scale_codec::{Decode, Encode}; | ||
use runtime_common::dip::sender::{DidIdentityProvider, DidMerkleRootGenerator}; | ||
use xcm::{latest::MultiLocation, DoubleEncoded}; | ||
|
||
use crate::{DidIdentifier, Runtime, RuntimeEvent, XcmRouter}; | ||
use crate::{DidIdentifier, Hash, Runtime, RuntimeEvent, XcmRouter}; | ||
|
||
#[derive(Encode, Decode)] | ||
enum ReceiverParachainCalls { | ||
|
@@ -34,16 +34,16 @@ enum ReceiverParachainCalls { | |
#[derive(Encode, Decode)] | ||
enum ReceiverParachainDipReceiverCalls { | ||
#[codec(index = 0)] | ||
ProcessIdentityAction(VersionedIdentityProofAction<DidIdentifier, [u8; 32]>), | ||
ProcessIdentityAction(VersionedIdentityProofAction<DidIdentifier, Hash>), | ||
} | ||
|
||
pub struct ReceiverParachainTxBuilder; | ||
impl TxBuilder<DidIdentifier, [u8; 32]> for ReceiverParachainTxBuilder { | ||
impl TxBuilder<DidIdentifier, Hash> for ReceiverParachainTxBuilder { | ||
type Error = (); | ||
|
||
fn build( | ||
_dest: MultiLocation, | ||
action: VersionedIdentityProofAction<DidIdentifier, [u8; 32]>, | ||
action: VersionedIdentityProofAction<DidIdentifier, Hash>, | ||
) -> Result<DoubleEncoded<()>, Self::Error> { | ||
let double_encoded: DoubleEncoded<()> = | ||
ReceiverParachainCalls::DipReceiver(ReceiverParachainDipReceiverCalls::ProcessIdentityAction(action)) | ||
|
@@ -55,16 +55,11 @@ impl TxBuilder<DidIdentifier, [u8; 32]> for ReceiverParachainTxBuilder { | |
|
||
impl pallet_dip_sender::Config for Runtime { | ||
type Identifier = DidIdentifier; | ||
// TODO: Change with right one | ||
type Identity = u32; | ||
// TODO: Change with right one | ||
type IdentityProofDispatcher = XcmRouterDispatcher<XcmRouter, DidIdentifier, [u8; 32]>; | ||
// TODO: Change with right one | ||
type IdentityProofGenerator = DefaultIdentityProofGenerator; | ||
// TODO: Change with right one | ||
type IdentityProvider = DefaultIdentityProvider; | ||
// TODO: Change with right one | ||
type ProofOutput = [u8; 32]; | ||
type Identity = DidDetails<Runtime>; | ||
type IdentityProofDispatcher = XcmRouterDispatcher<XcmRouter, DidIdentifier, Hash>; | ||
type IdentityProofGenerator = DidMerkleRootGenerator<Runtime>; | ||
type IdentityProvider = DidIdentityProvider<Runtime>; | ||
type ProofOutput = Hash; | ||
type RuntimeEvent = RuntimeEvent; | ||
type TxBuilder = ReceiverParachainTxBuilder; | ||
} |
Oops, something went wrong.