Moat (a.k.a. the Citadel SDK) is a Software Development Kit allowing developers to implement SSI solutions using Citadel and the Dusk Blockchain. In the next subsections we explain how to use it.
You can find the complete API here, and a complete example using such API here.
Prerequisites
Moat requires a reachable Rusk node installed and running, or selecting a trusted one. You can set up a node as explained here. It also requires an installed wallet connected to the given Rusk node, as explained here.
Using the CLI
To use the CLI, you first need to clone the following repository:
Now, specify the Rusk node address in moat-cli/config.toml. Then, you can execute the CLI for any of the involved parties, as follows.
User
License Provider
Service Provider
Import the Required Modules
To use Moat, you need the zk-citadel-moat Rust crate, available here. In order to use it, you are required to add it as a dependency in your Cargo.toml and to use the following modules in your code.
Create a Moat Context
The first thing to do to use the different options given by Moat, is to specify some settings by means of a Moat Context, as follows.
Retrieve Credentials from the Installed Wallet
You can choose to use the same credentials used by the wallet in your Citadel application as well. To get them, you as do as follows.
Request a License
The user can request a license on-chain. In order to create a transaction including that request, it will be necessary to provide the public key psk_lp of the LP, doing as follows.
Get Owned Requests
The LP can retrieve all the requests belonging to them (using their secret key ssk_lp) from the Blockchain, as follows.
Issuing a License
After receiving a request, the LP can issue a license for that given request. First, it is required to set the attribute data as follows.
The LP can now create a transaction which will issue a license, as follows.
Get Owned Licenses
The user can use their secret key to list the owned licenses, as follows.
Use a License
To use a license, the user first needs to set the challenge value c, which allows to use the license under certain conditions specified by the SP. It can be done as follows.
The user can now create a transaction using a given license, providing the public key psk_sp of the SP. In this step, a session will be created in the contract’s state, and a session cookie will be provided in the process.
Verify a Session Cookie
The SP can verify if a given session cookie is correct. Upon success, it will mean that the requested service in such process shall be granted. It can be done as follows.
Additionally, the SP should verify the challenge used by the user, as follows.