Skip to content

Commit

Permalink
Add API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xevisalle authored Nov 23, 2023
1 parent 0e11207 commit 7a7889a
Show file tree
Hide file tree
Showing 27 changed files with 124 additions and 96 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
# Moat: The Citadel SDK

[![CI](https://github.com/dusk-network/moat/actions/workflows/dusk_ci.yml/badge.svg)](https://github.com/dusk-network/moat/actions/workflows/dusk_ci.yml)
[![Repository](https://img.shields.io/badge/github-moat-blueviolet?logo=github)](https://github.com/dusk-network/moat)

**Moat** (a.k.a. the Citadel SDK) contains all the required tools for using and implementing self-sovereign identity systems using the Citadel protocol integrated into the Blockchain of Dusk.
**Moat** (a.k.a. the Citadel SDK) contains all the required tools for using and implementing self-sovereign identity systems using the Citadel protocol integrated into the Dusk Blockchain.

## Prerequisites

**Moat** requires a reachable Rusk node installed and running, or selecting a trusted one. You can set up a node as explained [here](https://wiki.dusk.network/en/setting-up-node). It also requires an installed wallet connected to the given Rusk node, as explained [here](https://github.com/dusk-network/wallet-cli/blob/main/src/bin/README.md). Then you should specify the Rusk node address in `config.toml`.
**Moat** requires a reachable Rusk node installed and running, or selecting a trusted one. You can set up a node as explained [here](https://wiki.dusk.network/en/setting-up-node). It also requires an installed wallet connected to the given Rusk node, as explained [here](https://github.com/dusk-network/wallet-cli/blob/main/src/bin/README.md).

## Testing the environment

You can test if the environment you set up and the library are working properly by specifying the testing Rusk node address in `integration-tests/tests/config/config.toml`, and executing the following (note that the wallet needs to use `password` as password for the tests to succeed):
You can test if the environment you set up and the library are working properly by specifying the testing Rusk node address in `integration-tests/config.toml`, and executing the following (note that the wallet needs to use `password` as password for the tests to succeed):

```
cargo t --release --features="exp_tests" -- --test-threads=1
cargo t --release --features="int_tests" -- --test-threads=1
```

## Usage
## Moat CLI

The moat-cli utility can be used from the POV of any of the parties involved in the Citadel protocol, let them be:
The `moat-cli` utility can be used from the POV of any of the parties involved in the Citadel protocol, let them be:
- **User:** A party requesting licenses onchain to LPs, and being able to use the licenses onchain as well.
- **License Provider (LP):** A party receiving onchain requests from users to issue licenses onchain addressed to them.
- **Service Provider (SP):** A party receiving offchain requests from users to grant services.

To use the CLI, you should 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

Expand All @@ -48,3 +50,7 @@ SPs can get requests from users to grant their services, and accept or deny them
```sh
cargo r --release --bin moat-cli-sp -- --wallet-pass <PASSWORD>
```

## Moat API

An API meant for developers willing to integrate Citadel in their code is available [here](https://github.com/dusk-network/moat/blob/main/moat-core/src/api.rs). You can find an example on how to use the API into `moat-example`.
6 changes: 3 additions & 3 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ version = "0.1.0"
edition = "2021"

[dependencies]
moat={ path = "../moat-core" }
moat = { path = "../moat-core" }

[dev-dependencies]
dusk-wallet = "0.20.1-rc.0"
dusk-wallet = "0.20.1"
dusk-jubjub = { version = "0.13", default-features = false }
zk-citadel = "0.6.0-rc.0"
zk-citadel = "0.6.0"
phoenix-core = { version = "0.21", features = ["alloc"] }
poseidon-merkle = { version = "0.3", features = ["rkyv-impl"] }
dusk-pki = { version = "0.13", default-features = false, features = ["rkyv-impl"] }
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions integration-tests/tests/blockchain/get_crs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const MIN_CRS_SIZE: usize = 10 * 1024 * 1024;
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn get_crs() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let cfg = BlockchainAccessConfig::load_path(config_path)?;

Expand Down
12 changes: 4 additions & 8 deletions integration-tests/tests/blockchain/retrieve_txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use tracing::trace;
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn retrieve_txs_from_block() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let cfg = BlockchainAccessConfig::load_path(config_path)?;

Expand All @@ -32,8 +31,7 @@ async fn retrieve_txs_from_block() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn retrieve_txs_from_block_range() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let cfg = BlockchainAccessConfig::load_path(config_path)?;

Expand All @@ -58,8 +56,7 @@ async fn retrieve_txs_from_block_range() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn retrieve_txs_from_last_n_blocks() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let cfg = BlockchainAccessConfig::load_path(config_path)?;

Expand All @@ -79,8 +76,7 @@ async fn retrieve_tx_by_id() -> Result<(), Error> {
const TXID: &str =
"44fe2c6407fc400a2dee6e30c62a02b82f3980da18d3b6306e80f9f83730520d";

let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let config = BlockchainAccessConfig::load_path(config_path)?;

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/blockchain/stake_add_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const ADD_OWNER_METHOD_NAME: &str = "add_owner";
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn stake_add_owner() -> Result<(), Error> {
let blockchain_config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let blockchain_config =
BlockchainAccessConfig::load_path(blockchain_config_path)?;
Expand Down
14 changes: 7 additions & 7 deletions integration-tests/tests/citadel/int_test_lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use toml_base_config::BaseConfig;
#[cfg_attr(not(feature = "exp_tests"), ignore)]
async fn lp_scan() -> Result<(), Error> {
let blockchain_config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");
let lp_config_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/config/test_keys_lp.json"
"/tests/test_keys/test_keys_lp.json"
);

let blockchain_config =
Expand All @@ -32,10 +32,10 @@ async fn lp_scan() -> Result<(), Error> {
#[cfg_attr(not(feature = "exp_tests"), ignore)]
async fn lp_scan_last_blocks() -> Result<(), Error> {
let blockchain_config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");
let lp_config_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/config/test_keys_lp_2.json"
"/tests/test_keys/test_keys_lp_2.json"
);

let blockchain_config =
Expand All @@ -53,14 +53,14 @@ async fn lp_scan_last_blocks() -> Result<(), Error> {
#[cfg_attr(not(feature = "exp_tests"), ignore)]
async fn lp_scan_2_lps() -> Result<(), Error> {
let blockchain_config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");
let lp1_config_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/config/test_keys_lp.json"
"/tests/test_keys/test_keys_lp.json"
);
let lp2_config_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/config/test_keys_lp_2.json"
"/tests/test_keys/test_keys_lp_2.json"
);

let blockchain_config =
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/citadel/int_test_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async fn user_round_trip() -> Result<(), Error> {
let mut rng = StdRng::seed_from_u64(0xbeef);

let blockchain_config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let blockchain_config =
BlockchainAccessConfig::load_path(blockchain_config_path)?;
Expand All @@ -153,7 +153,7 @@ async fn user_round_trip() -> Result<(), Error> {

let lp_config_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/config/test_keys_lp_2.json"
"/tests/test_keys/test_keys_lp_2.json"
);

let reference_lp = ReferenceLP::create(&lp_config_path)?;
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/citadel/issue_license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ async fn issue_license() -> Result<(), Error> {
"/tests/request/test_request.json"
);
let blockchain_config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let lp_config_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/config/test_keys_lp_2.json"
"/tests/test_keys/test_keys_lp_2.json"
);

let reference_lp = ReferenceLP::create(&lp_config_path)?;
Expand Down
12 changes: 4 additions & 8 deletions integration-tests/tests/citadel/license_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use tracing::trace;
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn call_get_licenses() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");
let config = BlockchainAccessConfig::load_path(config_path)?;

let client = RuskHttpClient::new(config.rusk_address);
Expand All @@ -33,8 +32,7 @@ async fn call_get_licenses() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn call_get_merkle_opening() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");
let config = BlockchainAccessConfig::load_path(config_path)?;

let client = RuskHttpClient::new(config.rusk_address);
Expand All @@ -49,8 +47,7 @@ async fn call_get_merkle_opening() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn call_get_session() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");
let config = BlockchainAccessConfig::load_path(config_path)?;

let client = RuskHttpClient::new(config.rusk_address);
Expand All @@ -69,8 +66,7 @@ async fn call_get_session() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn call_get_info() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");
let config = BlockchainAccessConfig::load_path(config_path)?;

let client = RuskHttpClient::new(config.rusk_address);
Expand Down
12 changes: 4 additions & 8 deletions integration-tests/tests/citadel/retrieve_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ async fn retrieve_payload() -> Result<(), Error> {
const TXID: &str =
"8d45a9fb7196f322282d522ff4bb2d2e926ddd96b858b91d59f228b27250ef03";

let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let config = BlockchainAccessConfig::load_path(config_path)?;
let client = RuskHttpClient::new(config.rusk_address);
Expand All @@ -32,8 +31,7 @@ async fn retrieve_payload() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "exp_tests"), ignore)]
async fn scan_all_requests() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");
let cfg = BlockchainAccessConfig::load_path(config_path)?;
let mut height = 0;
loop {
Expand All @@ -58,8 +56,7 @@ async fn scan_all_requests() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn scan_requests_in_last_blocks() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let cfg = BlockchainAccessConfig::load_path(config_path)?;

Expand All @@ -77,8 +74,7 @@ async fn scan_requests_in_last_blocks() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn scan_requests_in_block_range() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let cfg = BlockchainAccessConfig::load_path(config_path)?;

Expand Down
3 changes: 1 addition & 2 deletions integration-tests/tests/citadel/send_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ async fn send_request() -> Result<(), Error> {
env!("CARGO_MANIFEST_DIR"),
"/tests/request/test_request.json"
);
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml");

let request_json: RequestJson = RequestJson::from_file(request_path)?;

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
moat = { path = "../../moat-core" }
dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] }
dusk-wallet = "0.20.1-rc.0"
dusk-wallet = "0.20.1"
clap = { version = "4.0", features = ["derive", "env"] }
requestty = "0.4.1"
thiserror = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions moat-cli/moat-cli-lp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ version = "0.1.0"
edition = "2021"

[dependencies]
dusk-wallet = "0.20.1-rc.0"
dusk-wallet = "0.20.1"
dusk-jubjub = { version = "0.13", default-features = false }
moat = { path = "../../moat-core" }
moat-cli-common = { path = "../moat-cli-common" }
dusk-pki = "0.13"
zk-citadel = "0.6.0-rc.0"
zk-citadel = "0.6.0"
rkyv = { version = "=0.7.39" }
toml-base-config = "0.1"
clap = { version = "4.0", features = ["derive", "env"] }
Expand Down
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-lp/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Args {
pub wallet_path: PathBuf,

/// Blockchain access config directory
#[clap(short, long, default_value = "./config.toml")]
#[clap(short, long, default_value = "moat-cli/config.toml")]
pub config_path: PathBuf,

/// Password for the wallet
Expand Down
4 changes: 2 additions & 2 deletions moat-cli/moat-cli-sp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version = "0.1.0"
edition = "2021"

[dependencies]
dusk-wallet = "0.20.1-rc.0"
dusk-wallet = "0.20.1"
moat = { path = "../../moat-core" }
moat-cli-common = { path = "../moat-cli-common" }
zk-citadel = "0.6.0-rc.0"
zk-citadel = "0.6.0"
rkyv = { version = "=0.7.39" }
dusk-bls12_381 = "0.12"
dusk-jubjub = { version = "0.13", default-features = false, features = ["rkyv-impl", "alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-sp/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Args {
pub wallet_path: PathBuf,

/// Blockchain access config directory
#[clap(short, long, default_value = "./config.toml")]
#[clap(short, long, default_value = "moat-cli/config.toml")]
pub config_path: PathBuf,

/// Password for the wallet
Expand Down
4 changes: 2 additions & 2 deletions moat-cli/moat-cli-user/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version = "0.1.0"
edition = "2021"

[dependencies]
dusk-wallet = "0.20.1-rc.0"
dusk-wallet = "0.20.1"
moat = { path = "../../moat-core" }
moat-cli-common = { path = "../moat-cli-common" }
zk-citadel = "0.6.0-rc.0"
zk-citadel = "0.6.0"
dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] }
rkyv = { version = "=0.7.39" }
dusk-pki = "0.13"
Expand Down
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-user/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Args {
pub wallet_path: PathBuf,

/// Blockchain access config directory
#[clap(short, long, default_value = "./config.toml")]
#[clap(short, long, default_value = "moat-cli/config.toml")]
pub config_path: PathBuf,

/// Password for the wallet
Expand Down
6 changes: 3 additions & 3 deletions moat-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ futures = "0.3"
futures-core = "0.3"
dusk-wallet-core = "0.22.0-plonk.0.16"
futures-util = { version = "0.3.28", default-features = false, features = ["sink", "std"] }
dusk-wallet = "0.20.1-rc.0"
zk-citadel = "0.6.0-rc.0"
dusk-wallet = "0.20.1"
zk-citadel = "0.6.0"
dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] }
phoenix-core = { version = "0.21", features = ["alloc"] }
dusk-poseidon = { version = "0.31", default-features = false, features = ["rkyv-impl", "alloc"] }
Expand All @@ -33,7 +33,7 @@ hex = "0.4"
rand = "0.8"
dusk-bytes = "0.1"
blake3 = "1.4"
code-hasher={ path = "../macros/code-hasher" }
code-hasher = { path = "../macros/code-hasher" }
tracing = "0.1"
bytes = "1.4"
reqwest = "0.11"
Expand Down
Loading

0 comments on commit 7a7889a

Please sign in to comment.