Skip to content
This repository was archived by the owner on Jul 4, 2022. It is now read-only.

Attestation

Hoani Bryson edited this page May 6, 2020 · 9 revisions

The Attestation protocol provides an on-chain claim registry that aims to make sharing attested identity claims simple and cost efficient.

Claims are made by an issuer (an address) about a holder (an address) regarding a topic (e.g. a passport document) with a value.

Key Features

  • Verify identity without exposing the user’s personal identifiable information
  • Attested claims are easily queried and shared between parties
  • High speed onboarding allows you to perform a KYC (know your customer) more efficiently

Bringing the Attestation Runtime Module into your Blockchain

After following the new project getting started guide, we will need to add the Attestation runtime module to your blockchain node.

Add attestation to the cargo.toml

Open bin/node-template/runtime/Cargo.toml.

Under dependencies, add the attestation module:

[dependencies]
# ...
prml-attestation = { path = "../../../prml/attestation", default-features = false }

Under features, add the attestation to the std list:

[features]
# ...
std = [
# ...
  "prml-attestation/std",
]

Save and close the Cargo.toml file.

Adding Attestation to the runtime library

Open bin/node-template/runtime/src/lib.rs.

We need to implement the Attestation Trait for the Runtime. A good place to add this is straight after implementing the DoughnutRuntime. This will set up any specific Types that the attestation depends on:

impl DoughnutRuntime for Runtime {
    //...
}

impl prml_attestation::Trait for Runtime {
    type Event = Event;
}

Now, we need to add the Attestation as a member of the Runtime enum:

construct_runtime!(
    pub enum Runtime where
        Block = Block,
        NodeBlock = opaque::Block,
        UncheckedExtrinsic = UncheckedExtrinsic
    {
        // ...
        Attestation: prml_attestation::{Module, Call, Storage, Event<T>},
    }
);

Save and close the lib.rs file.

Build it and Run it!

Macros within the Plug codebase will automatically generate a new version of JS API, which has the attestation module added.

cargo build -p awesome-node
.target/debug/awesome-node purge-chain
./target/debug/awesome-node --chain=dev --validator --alice --unsafe-ws-external --ws-port=9944 --rpc-cors=all

Accessing Attestation with the API

The javascript API provides the following interfaces

/// Extrinsics
api.tx.attestation.setClaim(holder, topic, value)
api.tx.attestation.removeClaim(holder, topic)

/// Queries
/// - Gives a list of `issuers` who have made claims about a `holder`
api.query.attestation.issuers(holder); 
/// - Gives a list of `topics` and `issuer` has claimed about a `holder`
api.query.attestation.topics([holder, issuer]);
/// - Gives the claim made on a `topic` by an `issuer` about a `holder`
api.query.attestation.values([holder, issuer, topic]);

About topics and values

Both topics and values are represented as U256 - which is a container for up to 32-bytes of data.

How this data is encoded and used is up to the D'App developers to determine. Some sensible encoding schemes are:

  • to encode topics and values as utf-8 strings with 32 characters, and zero pad (/0) unused characters.
  • encode values as a hash of an off-chain document

When sending these values over the API, they should be sent as stringified integers. For example, if:

  • the topic is 0x0000000000000000000000000000000000000000000000000000000000000100
  • the value is 0x0000000000000000000000000000000000000000000000000000000000010000

Then the claim should be sent as:

api.tx.attestation.setClaim(
  holder, 
  '0x0000000000000000000000000000000000000000000000000000000000000100', 
  '0x0000000000000000000000000000000000000000000000000000000000010000'
)