From e1fc91e028e89968d525b9dab485a875d86a7f5d Mon Sep 17 00:00:00 2001 From: Milosz Muszynski Date: Fri, 1 Dec 2023 13:44:37 +0100 Subject: [PATCH 1/3] Renamed crate to zk-citadel-moat --- integration-tests/Cargo.toml | 2 +- integration-tests/tests/blockchain/contract_call.rs | 6 +++--- integration-tests/tests/blockchain/get_crs.rs | 4 ++-- integration-tests/tests/blockchain/retrieve_txs.rs | 4 ++-- integration-tests/tests/citadel/int_test_lp.rs | 6 +++--- integration-tests/tests/citadel/int_test_user.rs | 8 ++++---- integration-tests/tests/citadel/issue_license.rs | 8 ++++---- integration-tests/tests/citadel/license_queries.rs | 4 ++-- integration-tests/tests/citadel/retrieve_requests.rs | 4 ++-- integration-tests/tests/citadel/send_request.rs | 6 +++--- integration-tests/tests/websocket/ws_client.rs | 2 +- integration-tests/tests/websocket/ws_queries.rs | 2 +- integration-tests/tests/websocket/ws_server.rs | 2 +- integration-tests/tests/websocket/ws_test.rs | 2 +- moat-cli/moat-cli-common/Cargo.toml | 2 +- moat-cli/moat-cli-common/src/error.rs | 8 ++++---- moat-cli/moat-cli-lp/Cargo.toml | 2 +- moat-cli/moat-cli-lp/src/command.rs | 6 +++--- moat-cli/moat-cli-lp/src/interactor.rs | 2 +- moat-cli/moat-cli-lp/src/main.rs | 4 ++-- moat-cli/moat-cli-sp/Cargo.toml | 2 +- moat-cli/moat-cli-sp/src/command.rs | 4 ++-- moat-cli/moat-cli-sp/src/interactor.rs | 2 +- moat-cli/moat-cli-sp/src/main.rs | 4 ++-- moat-cli/moat-cli-user/Cargo.toml | 2 +- moat-cli/moat-cli-user/src/command.rs | 4 ++-- moat-cli/moat-cli-user/src/interactor.rs | 2 +- moat-cli/moat-cli-user/src/main.rs | 4 ++-- moat-example/Cargo.toml | 2 +- moat-example/src/main.rs | 2 +- moat/Cargo.toml | 2 +- moat/tests/extract_request.rs | 2 +- moat/tests/scan_transactions.rs | 2 +- moat/tests/test_lp.rs | 4 ++-- moat/tests/utils.rs | 2 +- 35 files changed, 62 insertions(+), 62 deletions(-) diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index e16dedd..9613216 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -moat = { path = "../moat" } +zk-citadel-moat = { path = "../moat" } [dev-dependencies] dusk-wallet = "0.20.1" diff --git a/integration-tests/tests/blockchain/contract_call.rs b/integration-tests/tests/blockchain/contract_call.rs index 2b93fcc..d898072 100644 --- a/integration-tests/tests/blockchain/contract_call.rs +++ b/integration-tests/tests/blockchain/contract_call.rs @@ -5,9 +5,9 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::{RuskHttpClient, WalletPath}; -use moat::wallet_accessor::BlockchainAccessConfig; -use moat::wallet_accessor::Password::PwdHash; -use moat::{Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter}; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::wallet_accessor::Password::PwdHash; +use zk_citadel_moat::{Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter}; use phoenix_core::transaction::ModuleId; use std::path::PathBuf; use toml_base_config::BaseConfig; diff --git a/integration-tests/tests/blockchain/get_crs.rs b/integration-tests/tests/blockchain/get_crs.rs index a1ad1f9..50aa463 100644 --- a/integration-tests/tests/blockchain/get_crs.rs +++ b/integration-tests/tests/blockchain/get_crs.rs @@ -5,8 +5,8 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::RuskHttpClient; -use moat::wallet_accessor::BlockchainAccessConfig; -use moat::{CrsGetter, Error}; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::{CrsGetter, Error}; use toml_base_config::BaseConfig; use tracing::trace; diff --git a/integration-tests/tests/blockchain/retrieve_txs.rs b/integration-tests/tests/blockchain/retrieve_txs.rs index 288835c..2695088 100644 --- a/integration-tests/tests/blockchain/retrieve_txs.rs +++ b/integration-tests/tests/blockchain/retrieve_txs.rs @@ -5,8 +5,8 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::RuskHttpClient; -use moat::wallet_accessor::BlockchainAccessConfig; -use moat::{Error, TxInquirer}; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::{Error, TxInquirer}; use toml_base_config::BaseConfig; use tracing::trace; diff --git a/integration-tests/tests/citadel/int_test_lp.rs b/integration-tests/tests/citadel/int_test_lp.rs index fb0542b..6b16a1c 100644 --- a/integration-tests/tests/citadel/int_test_lp.rs +++ b/integration-tests/tests/citadel/int_test_lp.rs @@ -4,9 +4,9 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use moat::license_provider::ReferenceLP; -use moat::wallet_accessor::BlockchainAccessConfig; -use moat::Error; +use zk_citadel_moat::license_provider::ReferenceLP; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::Error; use toml_base_config::BaseConfig; #[tokio::test(flavor = "multi_thread")] diff --git a/integration-tests/tests/citadel/int_test_user.rs b/integration-tests/tests/citadel/int_test_user.rs index 8d79d13..ebd1a57 100644 --- a/integration-tests/tests/citadel/int_test_user.rs +++ b/integration-tests/tests/citadel/int_test_user.rs @@ -24,10 +24,10 @@ use dusk_bytes::DeserializableSlice; use dusk_pki::SecretSpendKey; use dusk_plonk::prelude::*; use dusk_wallet::{RuskHttpClient, WalletPath}; -use moat::license_provider::{LicenseIssuer, ReferenceLP}; -use moat::wallet_accessor::BlockchainAccessConfig; -use moat::wallet_accessor::Password::PwdHash; -use moat::{ +use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP}; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::wallet_accessor::Password::PwdHash; +use zk_citadel_moat::{ BcInquirer, CitadelInquirer, CrsGetter, Error, JsonLoader, LicenseCircuit, LicenseSessionId, LicenseUser, PayloadRetriever, RequestCreator, RequestJson, RequestSender, TxAwaiter, diff --git a/integration-tests/tests/citadel/issue_license.rs b/integration-tests/tests/citadel/issue_license.rs index 7b7ad7a..68313a7 100644 --- a/integration-tests/tests/citadel/issue_license.rs +++ b/integration-tests/tests/citadel/issue_license.rs @@ -6,10 +6,10 @@ use dusk_jubjub::JubJubScalar; use dusk_wallet::WalletPath; -use moat::license_provider::{LicenseIssuer, ReferenceLP}; -use moat::wallet_accessor::BlockchainAccessConfig; -use moat::wallet_accessor::Password::PwdHash; -use moat::{Error, JsonLoader, RequestCreator, RequestJson}; +use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP}; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::wallet_accessor::Password::PwdHash; +use zk_citadel_moat::{Error, JsonLoader, RequestCreator, RequestJson}; use rand::rngs::StdRng; use rand::SeedableRng; use std::path::PathBuf; diff --git a/integration-tests/tests/citadel/license_queries.rs b/integration-tests/tests/citadel/license_queries.rs index 51862de..021429b 100644 --- a/integration-tests/tests/citadel/license_queries.rs +++ b/integration-tests/tests/citadel/license_queries.rs @@ -6,8 +6,8 @@ use dusk_bls12_381::BlsScalar; use dusk_wallet::RuskHttpClient; -use moat::wallet_accessor::BlockchainAccessConfig; -use moat::{CitadelInquirer, Error, LicenseSessionId, StreamAux}; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::{CitadelInquirer, Error, LicenseSessionId, StreamAux}; use toml_base_config::BaseConfig; use tracing::trace; diff --git a/integration-tests/tests/citadel/retrieve_requests.rs b/integration-tests/tests/citadel/retrieve_requests.rs index c80f417..e3ce49d 100644 --- a/integration-tests/tests/citadel/retrieve_requests.rs +++ b/integration-tests/tests/citadel/retrieve_requests.rs @@ -5,8 +5,8 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::RuskHttpClient; -use moat::wallet_accessor::BlockchainAccessConfig; -use moat::{Error, PayloadRetriever, RequestScanner}; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::{Error, PayloadRetriever, RequestScanner}; use toml_base_config::BaseConfig; use tracing::trace; use zk_citadel::license::Request; diff --git a/integration-tests/tests/citadel/send_request.rs b/integration-tests/tests/citadel/send_request.rs index ca4d103..1cdbdad 100644 --- a/integration-tests/tests/citadel/send_request.rs +++ b/integration-tests/tests/citadel/send_request.rs @@ -5,12 +5,12 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::{RuskHttpClient, WalletPath}; -use moat::wallet_accessor::{BlockchainAccessConfig, Password::PwdHash}; -use moat::{ +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password::PwdHash}; +use zk_citadel_moat::{ Error, PayloadExtractor, PayloadRetriever, RequestCreator, RequestJson, RequestSender, TxInquirer, MAX_REQUEST_SIZE, }; -use moat::{JsonLoader, TxAwaiter}; +use zk_citadel_moat::{JsonLoader, TxAwaiter}; use rand::rngs::StdRng; use rand::SeedableRng; use std::path::PathBuf; diff --git a/integration-tests/tests/websocket/ws_client.rs b/integration-tests/tests/websocket/ws_client.rs index 34698e7..1ee33f6 100644 --- a/integration-tests/tests/websocket/ws_client.rs +++ b/integration-tests/tests/websocket/ws_client.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use moat::ContractInquirerWs; +use zk_citadel_moat::ContractInquirerWs; pub async fn send_request_to_ws_server(port: u32) { let url = format!("127.0.0.1:{}", port); diff --git a/integration-tests/tests/websocket/ws_queries.rs b/integration-tests/tests/websocket/ws_queries.rs index 75b1056..84bfc27 100644 --- a/integration-tests/tests/websocket/ws_queries.rs +++ b/integration-tests/tests/websocket/ws_queries.rs @@ -6,7 +6,7 @@ use crate::websocket::ws_license_contract_mock_multi_server; use dusk_bls12_381::BlsScalar; -use moat::{CitadelInquirerWs, Error, LicenseSession, LicenseSessionId}; +use zk_citadel_moat::{CitadelInquirerWs, Error, LicenseSession, LicenseSessionId}; const TEST_DURATION_SECONDS: u64 = 4; const PORT: u32 = 9126; diff --git a/integration-tests/tests/websocket/ws_server.rs b/integration-tests/tests/websocket/ws_server.rs index 51e5a17..40712e5 100644 --- a/integration-tests/tests/websocket/ws_server.rs +++ b/integration-tests/tests/websocket/ws_server.rs @@ -7,7 +7,7 @@ use crate::websocket::ws_common::*; use dusk_bls12_381::BlsScalar; use futures_util::{SinkExt, StreamExt}; -use moat::{Error, LicenseSession, MAX_RESPONSE_SIZE}; +use zk_citadel_moat::{Error, LicenseSession, MAX_RESPONSE_SIZE}; use tokio::net::{TcpListener, TcpStream}; use tokio_tungstenite::tungstenite::Message; use tracing::trace; diff --git a/integration-tests/tests/websocket/ws_test.rs b/integration-tests/tests/websocket/ws_test.rs index 8861973..b097f59 100644 --- a/integration-tests/tests/websocket/ws_test.rs +++ b/integration-tests/tests/websocket/ws_test.rs @@ -7,7 +7,7 @@ use crate::websocket::{ send_request_to_ws_server, ws_license_contract_mock_server, }; -use moat::Error; +use zk_citadel_moat::Error; use tracing::trace; const TEST_DURATION_SECONDS: u64 = 4; diff --git a/moat-cli/moat-cli-common/Cargo.toml b/moat-cli/moat-cli-common/Cargo.toml index c3f4589..d04ab8d 100644 --- a/moat-cli/moat-cli-common/Cargo.toml +++ b/moat-cli/moat-cli-common/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -moat = { path = "../../moat" } +zk-citadel-moat = { path = "../../moat" } dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] } dusk-wallet = "0.20.1" clap = { version = "4.0", features = ["derive", "env"] } diff --git a/moat-cli/moat-cli-common/src/error.rs b/moat-cli/moat-cli-common/src/error.rs index 1e51aa2..41d5d26 100644 --- a/moat-cli/moat-cli-common/src/error.rs +++ b/moat-cli/moat-cli-common/src/error.rs @@ -17,7 +17,7 @@ use thiserror::Error; pub enum Error { /// Moat core error #[error(transparent)] - Moat(Arc), + Moat(Arc), /// Interaction error #[error(transparent)] Interaction(Arc), @@ -41,8 +41,8 @@ pub enum Error { Wallet(Arc), } -impl From for Error { - fn from(e: moat::Error) -> Self { +impl From for Error { + fn from(e: zk_citadel_moat::Error) -> Self { Error::Moat(Arc::from(e)) } } @@ -91,7 +91,7 @@ impl From for Error { impl From for Error { fn from(e: dusk_plonk::error::Error) -> Self { - Error::Moat(Arc::from(moat::Error::Plonk(Arc::from(e)))) + Error::Moat(Arc::from(zk_citadel_moat::Error::Plonk(Arc::from(e)))) } } diff --git a/moat-cli/moat-cli-lp/Cargo.toml b/moat-cli/moat-cli-lp/Cargo.toml index 188c79f..aa58e39 100644 --- a/moat-cli/moat-cli-lp/Cargo.toml +++ b/moat-cli/moat-cli-lp/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] dusk-wallet = "0.20.1" dusk-jubjub = { version = "0.13", default-features = false } -moat = { path = "../../moat" } +zk-citadel-moat = { path = "../../moat" } moat-cli-common = { path = "../moat-cli-common" } dusk-pki = "0.13" zk-citadel = "0.6.0" diff --git a/moat-cli/moat-cli-lp/src/command.rs b/moat-cli/moat-cli-lp/src/command.rs index 93bca93..84ab529 100644 --- a/moat-cli/moat-cli-lp/src/command.rs +++ b/moat-cli/moat-cli-lp/src/command.rs @@ -11,9 +11,9 @@ use crate::SeedableRng; use dusk_jubjub::JubJubScalar; use dusk_pki::SecretSpendKey; use dusk_wallet::{RuskHttpClient, WalletPath}; -use moat::license_provider::{LicenseIssuer, ReferenceLP}; -use moat::wallet_accessor::{BlockchainAccessConfig, Password}; -use moat::{BcInquirer, CitadelInquirer}; +use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; +use zk_citadel_moat::{BcInquirer, CitadelInquirer}; use moat_cli_common::Error; use rand::rngs::StdRng; diff --git a/moat-cli/moat-cli-lp/src/interactor.rs b/moat-cli/moat-cli-lp/src/interactor.rs index 8e97ecb..d271498 100644 --- a/moat-cli/moat-cli-lp/src/interactor.rs +++ b/moat-cli/moat-cli-lp/src/interactor.rs @@ -8,7 +8,7 @@ use crate::prompt; use crate::{Command, Menu}; use dusk_pki::SecretSpendKey; use dusk_wallet::WalletPath; -use moat::wallet_accessor::{BlockchainAccessConfig, Password}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; use moat_cli_common::Error; use requestty::{ErrorKind, Question}; diff --git a/moat-cli/moat-cli-lp/src/main.rs b/moat-cli/moat-cli-lp/src/main.rs index afe9412..5b82509 100644 --- a/moat-cli/moat-cli-lp/src/main.rs +++ b/moat-cli/moat-cli-lp/src/main.rs @@ -24,8 +24,8 @@ use clap::Parser; use crate::config::LPCliConfig; use crate::interactor::Interactor; use dusk_wallet::{Wallet, WalletPath}; -use moat::wallet_accessor::Password::{Pwd, PwdHash}; -use moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; +use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; use moat_cli_common::Error; use rand::SeedableRng; use toml_base_config::BaseConfig; diff --git a/moat-cli/moat-cli-sp/Cargo.toml b/moat-cli/moat-cli-sp/Cargo.toml index dc96081..fba935e 100644 --- a/moat-cli/moat-cli-sp/Cargo.toml +++ b/moat-cli/moat-cli-sp/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] dusk-wallet = "0.20.1" -moat = { path = "../../moat" } +zk-citadel-moat = { path = "../../moat" } moat-cli-common = { path = "../moat-cli-common" } zk-citadel = "0.6.0" rkyv = { version = "=0.7.39" } diff --git a/moat-cli/moat-cli-sp/src/command.rs b/moat-cli/moat-cli-sp/src/command.rs index 89cba93..05d5f3a 100644 --- a/moat-cli/moat-cli-sp/src/command.rs +++ b/moat-cli/moat-cli-sp/src/command.rs @@ -13,8 +13,8 @@ use dusk_bytes::DeserializableSlice; use dusk_jubjub::JubJubAffine; use dusk_pki::PublicSpendKey; use dusk_wallet::RuskHttpClient; -use moat::wallet_accessor::BlockchainAccessConfig; -use moat::{CitadelInquirer, LicenseSessionId}; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::{CitadelInquirer, LicenseSessionId}; use zk_citadel::license::{Session, SessionCookie}; /// Commands that can be run against the Moat diff --git a/moat-cli/moat-cli-sp/src/interactor.rs b/moat-cli/moat-cli-sp/src/interactor.rs index 051b00f..2436078 100644 --- a/moat-cli/moat-cli-sp/src/interactor.rs +++ b/moat-cli/moat-cli-sp/src/interactor.rs @@ -9,7 +9,7 @@ use crate::prompt; use crate::{Command, Menu}; use dusk_pki::PublicSpendKey; use dusk_wallet::WalletPath; -use moat::wallet_accessor::{BlockchainAccessConfig, Password}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; use moat_cli_common::Error; use requestty::{ErrorKind, Question}; diff --git a/moat-cli/moat-cli-sp/src/main.rs b/moat-cli/moat-cli-sp/src/main.rs index d65372b..96f15d7 100644 --- a/moat-cli/moat-cli-sp/src/main.rs +++ b/moat-cli/moat-cli-sp/src/main.rs @@ -23,8 +23,8 @@ use clap::Parser; use crate::config::SPCliConfig; use crate::interactor::Interactor; use dusk_wallet::{Wallet, WalletPath}; -use moat::wallet_accessor::Password::{Pwd, PwdHash}; -use moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; +use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; use moat_cli_common::Error; use toml_base_config::BaseConfig; diff --git a/moat-cli/moat-cli-user/Cargo.toml b/moat-cli/moat-cli-user/Cargo.toml index 5805c74..bba31a1 100644 --- a/moat-cli/moat-cli-user/Cargo.toml +++ b/moat-cli/moat-cli-user/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] dusk-wallet = "0.20.1" -moat = { path = "../../moat" } +zk-citadel-moat = { path = "../../moat" } moat-cli-common = { path = "../moat-cli-common" } zk-citadel = "0.6.0" dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] } diff --git a/moat-cli/moat-cli-user/src/command.rs b/moat-cli/moat-cli-user/src/command.rs index e5031d1..5731886 100644 --- a/moat-cli/moat-cli-user/src/command.rs +++ b/moat-cli/moat-cli-user/src/command.rs @@ -14,8 +14,8 @@ use dusk_bytes::DeserializableSlice; use dusk_pki::{PublicSpendKey, SecretSpendKey}; use dusk_plonk::prelude::*; use dusk_wallet::{RuskHttpClient, WalletPath}; -use moat::wallet_accessor::{BlockchainAccessConfig, Password}; -use moat::{ +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; +use zk_citadel_moat::{ BcInquirer, CitadelInquirer, CrsGetter, LicenseCircuit, LicenseUser, RequestCreator, RequestSender, TxAwaiter, }; diff --git a/moat-cli/moat-cli-user/src/interactor.rs b/moat-cli/moat-cli-user/src/interactor.rs index fcd8deb..fe4121e 100644 --- a/moat-cli/moat-cli-user/src/interactor.rs +++ b/moat-cli/moat-cli-user/src/interactor.rs @@ -9,7 +9,7 @@ use crate::{Command, Menu}; use dusk_pki::SecretSpendKey; use dusk_plonk::prelude::{Prover, Verifier}; use dusk_wallet::WalletPath; -use moat::wallet_accessor::{BlockchainAccessConfig, Password}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; use moat_cli_common::Error; use requestty::{ErrorKind, Question}; diff --git a/moat-cli/moat-cli-user/src/main.rs b/moat-cli/moat-cli-user/src/main.rs index 8c31aa1..7503db4 100644 --- a/moat-cli/moat-cli-user/src/main.rs +++ b/moat-cli/moat-cli-user/src/main.rs @@ -22,8 +22,8 @@ use clap::Parser; use crate::interactor::Interactor; use dusk_wallet::{Wallet, WalletPath}; -use moat::wallet_accessor::Password::{Pwd, PwdHash}; -use moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; +use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; use moat_cli_common::Error; use rand::SeedableRng; use toml_base_config::BaseConfig; diff --git a/moat-example/Cargo.toml b/moat-example/Cargo.toml index d728304..9c49d6d 100644 --- a/moat-example/Cargo.toml +++ b/moat-example/Cargo.toml @@ -5,6 +5,6 @@ edition = "2021" [dependencies] dusk-jubjub = { version = "0.13", default-features = false } -moat = { path = "../moat" } +zk-citadel-moat = { path = "../moat" } tokio = { version = "1.21", features = ["full"] } rand = "0.8" diff --git a/moat-example/src/main.rs b/moat-example/src/main.rs index 5c3e181..521a9b8 100644 --- a/moat-example/src/main.rs +++ b/moat-example/src/main.rs @@ -7,7 +7,7 @@ use dusk_jubjub::JubJubScalar; use rand::rngs::OsRng; -use moat::api::{Error, MoatContext, MoatCore}; +use zk_citadel_moat::api::{Error, MoatContext, MoatCore}; #[tokio::main] #[allow(non_snake_case)] diff --git a/moat/Cargo.toml b/moat/Cargo.toml index 5cb7969..f08ba69 100644 --- a/moat/Cargo.toml +++ b/moat/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "moat" +name = "zk-citadel-moat" version = "0.1.0" edition = "2021" diff --git a/moat/tests/extract_request.rs b/moat/tests/extract_request.rs index b295a78..4eb8de7 100644 --- a/moat/tests/extract_request.rs +++ b/moat/tests/extract_request.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use moat::{Error, JsonLoader, PayloadExtractor, Tx}; +use zk_citadel_moat::{Error, JsonLoader, PayloadExtractor, Tx}; use zk_citadel::license::Request; #[test] diff --git a/moat/tests/scan_transactions.rs b/moat/tests/scan_transactions.rs index b6faf5a..b73b44f 100644 --- a/moat/tests/scan_transactions.rs +++ b/moat/tests/scan_transactions.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use moat::{JsonLoader, RequestScanner, Transactions}; +use zk_citadel_moat::{JsonLoader, RequestScanner, Transactions}; #[test] fn scan_transactions() { diff --git a/moat/tests/test_lp.rs b/moat/tests/test_lp.rs index 1803c1b..b7b90a2 100644 --- a/moat/tests/test_lp.rs +++ b/moat/tests/test_lp.rs @@ -4,8 +4,8 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use moat::license_provider::ReferenceLP; -use moat::{Error, JsonLoader, RequestScanner, Transactions}; +use zk_citadel_moat::license_provider::ReferenceLP; +use zk_citadel_moat::{Error, JsonLoader, RequestScanner, Transactions}; #[test] fn lp_filter_requests() -> Result<(), Error> { diff --git a/moat/tests/utils.rs b/moat/tests/utils.rs index 373b909..5159c5f 100644 --- a/moat/tests/utils.rs +++ b/moat/tests/utils.rs @@ -6,7 +6,7 @@ use dusk_bytes::{DeserializableSlice, Serializable}; use dusk_pki::SecretSpendKey; -use moat::{Error, RequestCreator, MAX_REQUEST_SIZE}; +use zk_citadel_moat::{Error, RequestCreator, MAX_REQUEST_SIZE}; use rand::rngs::StdRng; use rand::SeedableRng; use sha2::Digest; From c7e3a9941f5028af63194c98f6cf50b0317b16b3 Mon Sep 17 00:00:00 2001 From: Milosz Muszynski Date: Fri, 1 Dec 2023 14:42:01 +0100 Subject: [PATCH 2/3] Corrected comments, printlns, formatting --- .../tests/blockchain/contract_call.rs | 8 ++++--- integration-tests/tests/blockchain/get_crs.rs | 4 ++-- .../tests/blockchain/retrieve_txs.rs | 4 ++-- .../tests/citadel/int_test_lp.rs | 2 +- .../tests/citadel/int_test_user.rs | 12 +++++------ .../tests/citadel/issue_license.rs | 8 +++---- .../tests/citadel/license_queries.rs | 4 ++-- .../tests/citadel/retrieve_requests.rs | 4 ++-- .../tests/citadel/send_request.rs | 14 +++++++------ .../tests/websocket/ws_queries.rs | 4 +++- .../tests/websocket/ws_server.rs | 2 +- integration-tests/tests/websocket/ws_test.rs | 2 +- moat-cli/moat-cli-common/src/error.rs | 3 --- moat-cli/moat-cli-lp/src/command.rs | 4 ++-- moat-cli/moat-cli-lp/src/interactor.rs | 2 +- moat-cli/moat-cli-lp/src/main.rs | 6 ++++-- moat-cli/moat-cli-lp/src/prompt.rs | 8 ++----- moat-cli/moat-cli-sp/src/command.rs | 7 +++---- moat-cli/moat-cli-sp/src/interactor.rs | 2 +- moat-cli/moat-cli-sp/src/main.rs | 6 ++++-- moat-cli/moat-cli-sp/src/prompt.rs | 12 +++-------- moat-cli/moat-cli-sp/src/run_result.rs | 4 ++-- moat-cli/moat-cli-user/src/command.rs | 8 +++---- moat-cli/moat-cli-user/src/interactor.rs | 2 +- moat-cli/moat-cli-user/src/main.rs | 6 ++++-- moat-cli/moat-cli-user/src/prompt.rs | 20 +++++------------- moat-cli/moat-cli-user/src/run_result.rs | 3 +-- moat-example/src/main.rs | 2 +- moat/src/api.rs | 4 ---- moat/src/bc_types.rs | 1 - moat/src/blockchain_queries/tx_inquirer.rs | 1 - moat/src/citadel_queries/citadel_inquirer.rs | 7 ++++++- moat/src/citadel_requests/request_creator.rs | 10 ++++----- moat/src/citadel_requests/request_scanner.rs | 2 +- moat/src/citadel_requests/request_sender.rs | 1 + .../src/contract_queries/contract_inquirer.rs | 3 +++ .../contract_queries/contract_inquirer_ws.rs | 1 + moat/src/contract_queries/ws_types.rs | 2 +- moat/src/license_provider/license_issuer.rs | 2 ++ moat/src/license_provider/reference_lp.rs | 21 +++++++++++-------- moat/src/utils.rs | 5 ----- moat/tests/extract_request.rs | 2 +- moat/tests/utils.rs | 2 +- 43 files changed, 109 insertions(+), 118 deletions(-) diff --git a/integration-tests/tests/blockchain/contract_call.rs b/integration-tests/tests/blockchain/contract_call.rs index d898072..3d2e18e 100644 --- a/integration-tests/tests/blockchain/contract_call.rs +++ b/integration-tests/tests/blockchain/contract_call.rs @@ -5,12 +5,14 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::{RuskHttpClient, WalletPath}; -use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; -use zk_citadel_moat::wallet_accessor::Password::PwdHash; -use zk_citadel_moat::{Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter}; use phoenix_core::transaction::ModuleId; use std::path::PathBuf; use toml_base_config::BaseConfig; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::wallet_accessor::Password::PwdHash; +use zk_citadel_moat::{ + Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter, +}; const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet"); const PWD_HASH: &str = diff --git a/integration-tests/tests/blockchain/get_crs.rs b/integration-tests/tests/blockchain/get_crs.rs index 50aa463..6e0a008 100644 --- a/integration-tests/tests/blockchain/get_crs.rs +++ b/integration-tests/tests/blockchain/get_crs.rs @@ -5,10 +5,10 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::RuskHttpClient; -use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; -use zk_citadel_moat::{CrsGetter, Error}; use toml_base_config::BaseConfig; use tracing::trace; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::{CrsGetter, Error}; const MIN_CRS_SIZE: usize = 10 * 1024 * 1024; diff --git a/integration-tests/tests/blockchain/retrieve_txs.rs b/integration-tests/tests/blockchain/retrieve_txs.rs index 2695088..52d947c 100644 --- a/integration-tests/tests/blockchain/retrieve_txs.rs +++ b/integration-tests/tests/blockchain/retrieve_txs.rs @@ -5,10 +5,10 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::RuskHttpClient; -use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; -use zk_citadel_moat::{Error, TxInquirer}; use toml_base_config::BaseConfig; use tracing::trace; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::{Error, TxInquirer}; #[tokio::test(flavor = "multi_thread")] #[cfg_attr(not(feature = "int_tests"), ignore)] diff --git a/integration-tests/tests/citadel/int_test_lp.rs b/integration-tests/tests/citadel/int_test_lp.rs index 6b16a1c..030b6da 100644 --- a/integration-tests/tests/citadel/int_test_lp.rs +++ b/integration-tests/tests/citadel/int_test_lp.rs @@ -4,10 +4,10 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +use toml_base_config::BaseConfig; use zk_citadel_moat::license_provider::ReferenceLP; use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; use zk_citadel_moat::Error; -use toml_base_config::BaseConfig; #[tokio::test(flavor = "multi_thread")] #[cfg_attr(not(feature = "exp_tests"), ignore)] diff --git a/integration-tests/tests/citadel/int_test_user.rs b/integration-tests/tests/citadel/int_test_user.rs index ebd1a57..24b4e43 100644 --- a/integration-tests/tests/citadel/int_test_user.rs +++ b/integration-tests/tests/citadel/int_test_user.rs @@ -24,6 +24,12 @@ use dusk_bytes::DeserializableSlice; use dusk_pki::SecretSpendKey; use dusk_plonk::prelude::*; use dusk_wallet::{RuskHttpClient, WalletPath}; +use rand::rngs::{OsRng, StdRng}; +use rand::SeedableRng; +use std::path::PathBuf; +use toml_base_config::BaseConfig; +use tracing::{info, Level}; +use zk_citadel::license::Request; use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP}; use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; use zk_citadel_moat::wallet_accessor::Password::PwdHash; @@ -32,12 +38,6 @@ use zk_citadel_moat::{ LicenseSessionId, LicenseUser, PayloadRetriever, RequestCreator, RequestJson, RequestSender, TxAwaiter, }; -use rand::rngs::{OsRng, StdRng}; -use rand::SeedableRng; -use std::path::PathBuf; -use toml_base_config::BaseConfig; -use tracing::{info, Level}; -use zk_citadel::license::Request; const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet"); const PWD_HASH: &str = diff --git a/integration-tests/tests/citadel/issue_license.rs b/integration-tests/tests/citadel/issue_license.rs index 68313a7..ba5a83c 100644 --- a/integration-tests/tests/citadel/issue_license.rs +++ b/integration-tests/tests/citadel/issue_license.rs @@ -6,14 +6,14 @@ use dusk_jubjub::JubJubScalar; use dusk_wallet::WalletPath; -use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP}; -use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; -use zk_citadel_moat::wallet_accessor::Password::PwdHash; -use zk_citadel_moat::{Error, JsonLoader, RequestCreator, RequestJson}; use rand::rngs::StdRng; use rand::SeedableRng; use std::path::PathBuf; use toml_base_config::BaseConfig; +use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP}; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::wallet_accessor::Password::PwdHash; +use zk_citadel_moat::{Error, JsonLoader, RequestCreator, RequestJson}; const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet"); const PWD_HASH: &str = diff --git a/integration-tests/tests/citadel/license_queries.rs b/integration-tests/tests/citadel/license_queries.rs index 021429b..c8703cf 100644 --- a/integration-tests/tests/citadel/license_queries.rs +++ b/integration-tests/tests/citadel/license_queries.rs @@ -6,10 +6,10 @@ use dusk_bls12_381::BlsScalar; use dusk_wallet::RuskHttpClient; -use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; -use zk_citadel_moat::{CitadelInquirer, Error, LicenseSessionId, StreamAux}; use toml_base_config::BaseConfig; use tracing::trace; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::{CitadelInquirer, Error, LicenseSessionId, StreamAux}; #[tokio::test(flavor = "multi_thread")] #[cfg_attr(not(feature = "int_tests"), ignore)] diff --git a/integration-tests/tests/citadel/retrieve_requests.rs b/integration-tests/tests/citadel/retrieve_requests.rs index e3ce49d..bc4b159 100644 --- a/integration-tests/tests/citadel/retrieve_requests.rs +++ b/integration-tests/tests/citadel/retrieve_requests.rs @@ -5,11 +5,11 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::RuskHttpClient; -use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; -use zk_citadel_moat::{Error, PayloadRetriever, RequestScanner}; use toml_base_config::BaseConfig; use tracing::trace; use zk_citadel::license::Request; +use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; +use zk_citadel_moat::{Error, PayloadRetriever, RequestScanner}; #[tokio::test(flavor = "multi_thread")] #[cfg_attr(not(feature = "vol_tests"), ignore)] diff --git a/integration-tests/tests/citadel/send_request.rs b/integration-tests/tests/citadel/send_request.rs index 1cdbdad..50d6a29 100644 --- a/integration-tests/tests/citadel/send_request.rs +++ b/integration-tests/tests/citadel/send_request.rs @@ -5,12 +5,6 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::{RuskHttpClient, WalletPath}; -use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password::PwdHash}; -use zk_citadel_moat::{ - Error, PayloadExtractor, PayloadRetriever, RequestCreator, RequestJson, - RequestSender, TxInquirer, MAX_REQUEST_SIZE, -}; -use zk_citadel_moat::{JsonLoader, TxAwaiter}; use rand::rngs::StdRng; use rand::SeedableRng; use std::path::PathBuf; @@ -19,6 +13,14 @@ use tokio::time::sleep; use toml_base_config::BaseConfig; use tracing::Level; use zk_citadel::license::Request; +use zk_citadel_moat::wallet_accessor::{ + BlockchainAccessConfig, Password::PwdHash, +}; +use zk_citadel_moat::{ + Error, PayloadExtractor, PayloadRetriever, RequestCreator, RequestJson, + RequestSender, TxInquirer, MAX_REQUEST_SIZE, +}; +use zk_citadel_moat::{JsonLoader, TxAwaiter}; const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet"); const PWD_HASH: &str = diff --git a/integration-tests/tests/websocket/ws_queries.rs b/integration-tests/tests/websocket/ws_queries.rs index 84bfc27..e42c9b1 100644 --- a/integration-tests/tests/websocket/ws_queries.rs +++ b/integration-tests/tests/websocket/ws_queries.rs @@ -6,7 +6,9 @@ use crate::websocket::ws_license_contract_mock_multi_server; use dusk_bls12_381::BlsScalar; -use zk_citadel_moat::{CitadelInquirerWs, Error, LicenseSession, LicenseSessionId}; +use zk_citadel_moat::{ + CitadelInquirerWs, Error, LicenseSession, LicenseSessionId, +}; const TEST_DURATION_SECONDS: u64 = 4; const PORT: u32 = 9126; diff --git a/integration-tests/tests/websocket/ws_server.rs b/integration-tests/tests/websocket/ws_server.rs index 40712e5..d8c1d54 100644 --- a/integration-tests/tests/websocket/ws_server.rs +++ b/integration-tests/tests/websocket/ws_server.rs @@ -7,10 +7,10 @@ use crate::websocket::ws_common::*; use dusk_bls12_381::BlsScalar; use futures_util::{SinkExt, StreamExt}; -use zk_citadel_moat::{Error, LicenseSession, MAX_RESPONSE_SIZE}; use tokio::net::{TcpListener, TcpStream}; use tokio_tungstenite::tungstenite::Message; use tracing::trace; +use zk_citadel_moat::{Error, LicenseSession, MAX_RESPONSE_SIZE}; pub async fn ws_license_contract_mock_server( seconds: u64, diff --git a/integration-tests/tests/websocket/ws_test.rs b/integration-tests/tests/websocket/ws_test.rs index b097f59..14f57f1 100644 --- a/integration-tests/tests/websocket/ws_test.rs +++ b/integration-tests/tests/websocket/ws_test.rs @@ -7,8 +7,8 @@ use crate::websocket::{ send_request_to_ws_server, ws_license_contract_mock_server, }; -use zk_citadel_moat::Error; use tracing::trace; +use zk_citadel_moat::Error; const TEST_DURATION_SECONDS: u64 = 4; const PORT: u32 = 9125; diff --git a/moat-cli/moat-cli-common/src/error.rs b/moat-cli/moat-cli-common/src/error.rs index 41d5d26..4e5a2da 100644 --- a/moat-cli/moat-cli-common/src/error.rs +++ b/moat-cli/moat-cli-common/src/error.rs @@ -10,9 +10,6 @@ use std::num::ParseIntError; use std::sync::Arc; use thiserror::Error; -// todo: rename CliError to Error -// todo: make sure it is used in other CLIs as well - #[derive(Error, Debug, Clone)] pub enum Error { /// Moat core error diff --git a/moat-cli/moat-cli-lp/src/command.rs b/moat-cli/moat-cli-lp/src/command.rs index 84ab529..0cfce28 100644 --- a/moat-cli/moat-cli-lp/src/command.rs +++ b/moat-cli/moat-cli-lp/src/command.rs @@ -11,11 +11,11 @@ use crate::SeedableRng; use dusk_jubjub::JubJubScalar; use dusk_pki::SecretSpendKey; use dusk_wallet::{RuskHttpClient, WalletPath}; +use moat_cli_common::Error; +use rand::rngs::StdRng; use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP}; use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; use zk_citadel_moat::{BcInquirer, CitadelInquirer}; -use moat_cli_common::Error; -use rand::rngs::StdRng; /// Commands that can be run against the Moat #[derive(PartialEq, Eq, Hash, Clone, Debug)] diff --git a/moat-cli/moat-cli-lp/src/interactor.rs b/moat-cli/moat-cli-lp/src/interactor.rs index d271498..a5eaed7 100644 --- a/moat-cli/moat-cli-lp/src/interactor.rs +++ b/moat-cli/moat-cli-lp/src/interactor.rs @@ -8,9 +8,9 @@ use crate::prompt; use crate::{Command, Menu}; use dusk_pki::SecretSpendKey; use dusk_wallet::WalletPath; -use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; use moat_cli_common::Error; use requestty::{ErrorKind, Question}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; #[derive(PartialEq, Eq, Hash, Debug, Clone)] enum OpSelection { diff --git a/moat-cli/moat-cli-lp/src/main.rs b/moat-cli/moat-cli-lp/src/main.rs index 5b82509..6c15fae 100644 --- a/moat-cli/moat-cli-lp/src/main.rs +++ b/moat-cli/moat-cli-lp/src/main.rs @@ -24,11 +24,13 @@ use clap::Parser; use crate::config::LPCliConfig; use crate::interactor::Interactor; use dusk_wallet::{Wallet, WalletPath}; -use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash}; -use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; use moat_cli_common::Error; use rand::SeedableRng; use toml_base_config::BaseConfig; +use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash}; +use zk_citadel_moat::wallet_accessor::{ + BlockchainAccessConfig, WalletAccessor, +}; #[tokio::main] async fn main() -> Result<(), Error> { diff --git a/moat-cli/moat-cli-lp/src/prompt.rs b/moat-cli/moat-cli-lp/src/prompt.rs index 69d9b1a..ac59eb1 100644 --- a/moat-cli/moat-cli-lp/src/prompt.rs +++ b/moat-cli/moat-cli-lp/src/prompt.rs @@ -9,9 +9,7 @@ use requestty::{ErrorKind, Question}; pub(crate) fn request_request_hash() -> Result { let q = Question::input("request_hash") .message("Please enter request hash:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of the request hash - }) + .validate_on_key(|_, _| true) .validate(|request_hash, _| { if request_hash.is_empty() { Err("Please enter a valid request hash".to_string()) @@ -29,9 +27,7 @@ pub(crate) fn request_request_hash() -> Result { pub(crate) fn request_attr_data() -> Result { let q = Question::input("attr_data") .message("Please enter the attribute data:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of the attr_data - }) + .validate_on_key(|_, _| true) .validate(|attr_data, _| { if attr_data.is_empty() { Err("Please enter valid attribute data".to_string()) diff --git a/moat-cli/moat-cli-sp/src/command.rs b/moat-cli/moat-cli-sp/src/command.rs index 05d5f3a..0900440 100644 --- a/moat-cli/moat-cli-sp/src/command.rs +++ b/moat-cli/moat-cli-sp/src/command.rs @@ -5,7 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use crate::run_result::{ - LicenseContractSummary, RunResult, ServiceRequestSummery, SessionSummary, + LicenseContractSummary, RunResult, ServiceRequestSummary, SessionSummary, }; use crate::Error; use dusk_bls12_381::BlsScalar; @@ -13,9 +13,9 @@ use dusk_bytes::DeserializableSlice; use dusk_jubjub::JubJubAffine; use dusk_pki::PublicSpendKey; use dusk_wallet::RuskHttpClient; +use zk_citadel::license::{Session, SessionCookie}; use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig; use zk_citadel_moat::{CitadelInquirer, LicenseSessionId}; -use zk_citadel::license::{Session, SessionCookie}; /// Commands that can be run against the Moat #[derive(PartialEq, Eq, Hash, Clone, Debug)] @@ -90,8 +90,7 @@ impl Command { let session = Session::from(&session.public_inputs); let granted = session.verifies_ok(sc, pk_lp, pk_sp); - println!("session id={}", hex::encode(session_id.id.to_bytes())); - let service_request_summary = ServiceRequestSummery { + let service_request_summary = ServiceRequestSummary { service_granted: granted, }; Ok(RunResult::RequestService(service_request_summary)) diff --git a/moat-cli/moat-cli-sp/src/interactor.rs b/moat-cli/moat-cli-sp/src/interactor.rs index 2436078..b5ab6c6 100644 --- a/moat-cli/moat-cli-sp/src/interactor.rs +++ b/moat-cli/moat-cli-sp/src/interactor.rs @@ -9,9 +9,9 @@ use crate::prompt; use crate::{Command, Menu}; use dusk_pki::PublicSpendKey; use dusk_wallet::WalletPath; -use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; use moat_cli_common::Error; use requestty::{ErrorKind, Question}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; #[derive(PartialEq, Eq, Hash, Debug, Clone)] enum OpSelection { diff --git a/moat-cli/moat-cli-sp/src/main.rs b/moat-cli/moat-cli-sp/src/main.rs index 96f15d7..75fdcd5 100644 --- a/moat-cli/moat-cli-sp/src/main.rs +++ b/moat-cli/moat-cli-sp/src/main.rs @@ -23,10 +23,12 @@ use clap::Parser; use crate::config::SPCliConfig; use crate::interactor::Interactor; use dusk_wallet::{Wallet, WalletPath}; -use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash}; -use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; use moat_cli_common::Error; use toml_base_config::BaseConfig; +use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash}; +use zk_citadel_moat::wallet_accessor::{ + BlockchainAccessConfig, WalletAccessor, +}; #[tokio::main] async fn main() -> Result<(), Error> { diff --git a/moat-cli/moat-cli-sp/src/prompt.rs b/moat-cli/moat-cli-sp/src/prompt.rs index 64c204c..c4a510a 100644 --- a/moat-cli/moat-cli-sp/src/prompt.rs +++ b/moat-cli/moat-cli-sp/src/prompt.rs @@ -9,9 +9,7 @@ use requestty::{ErrorKind, Question}; pub(crate) fn request_session_id() -> Result { let q = Question::input("session_id") .message("Please enter session id:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of the session id - }) + .validate_on_key(|_, _| true) .validate(|id, _| { if id.is_empty() { Err("Please enter a valid session id".to_string()) @@ -29,9 +27,7 @@ pub(crate) fn request_session_id() -> Result { pub(crate) fn request_session_cookie() -> Result { let q = Question::input("session_cookie") .message("Please enter session cookie:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of the session id - }) + .validate_on_key(|_, _| true) .validate(|id, _| { if id.is_empty() { Err("Please enter a valid session cookie".to_string()) @@ -49,9 +45,7 @@ pub(crate) fn request_session_cookie() -> Result { pub(crate) fn request_psk_lp() -> Result { let q = Question::input("psk_lp_bytes") .message("Please enter the LP address:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of psk_lp - }) + .validate_on_key(|_, _| true) .validate(|id, _| { if id.is_empty() { Err("Please enter a valid address for the LP".to_string()) diff --git a/moat-cli/moat-cli-sp/src/run_result.rs b/moat-cli/moat-cli-sp/src/run_result.rs index d2dd859..30fe610 100644 --- a/moat-cli/moat-cli-sp/src/run_result.rs +++ b/moat-cli/moat-cli-sp/src/run_result.rs @@ -6,7 +6,7 @@ use std::fmt; -pub struct ServiceRequestSummery { +pub struct ServiceRequestSummary { pub service_granted: bool, } @@ -23,7 +23,7 @@ pub struct LicenseContractSummary { #[allow(clippy::large_enum_variant)] /// Possible results of running a command in interactive mode pub enum RunResult { - RequestService(ServiceRequestSummery), + RequestService(ServiceRequestSummary), GetSession(Option), ShowState(LicenseContractSummary), } diff --git a/moat-cli/moat-cli-user/src/command.rs b/moat-cli/moat-cli-user/src/command.rs index 5731886..40c8e69 100644 --- a/moat-cli/moat-cli-user/src/command.rs +++ b/moat-cli/moat-cli-user/src/command.rs @@ -14,14 +14,14 @@ use dusk_bytes::DeserializableSlice; use dusk_pki::{PublicSpendKey, SecretSpendKey}; use dusk_plonk::prelude::*; use dusk_wallet::{RuskHttpClient, WalletPath}; +use moat_cli_common::Error; +use rand::rngs::{OsRng, StdRng}; +use zk_citadel::license::{License, SessionCookie}; use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; use zk_citadel_moat::{ BcInquirer, CitadelInquirer, CrsGetter, LicenseCircuit, LicenseUser, RequestCreator, RequestSender, TxAwaiter, }; -use moat_cli_common::Error; -use rand::rngs::{OsRng, StdRng}; -use zk_citadel::license::{License, SessionCookie}; use std::fs::File; use std::io::prelude::*; @@ -124,7 +124,7 @@ impl Command { let psk_lp = PublicSpendKey::from_slice(psk_lp_bytes_formatted.as_slice())?; - let rng = &mut StdRng::from_entropy(); // seed_from_u64(0xcafe); + let rng = &mut StdRng::from_entropy(); let request = RequestCreator::create(&ssk, &psk_lp, rng)?; let request_hash = RunResult::to_hash_hex(&request); let tx_id = RequestSender::send_request( diff --git a/moat-cli/moat-cli-user/src/interactor.rs b/moat-cli/moat-cli-user/src/interactor.rs index fe4121e..f8cc614 100644 --- a/moat-cli/moat-cli-user/src/interactor.rs +++ b/moat-cli/moat-cli-user/src/interactor.rs @@ -9,9 +9,9 @@ use crate::{Command, Menu}; use dusk_pki::SecretSpendKey; use dusk_plonk::prelude::{Prover, Verifier}; use dusk_wallet::WalletPath; -use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; use moat_cli_common::Error; use requestty::{ErrorKind, Question}; +use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; #[derive(PartialEq, Eq, Hash, Debug, Clone)] enum OpSelection { diff --git a/moat-cli/moat-cli-user/src/main.rs b/moat-cli/moat-cli-user/src/main.rs index 7503db4..d784c0b 100644 --- a/moat-cli/moat-cli-user/src/main.rs +++ b/moat-cli/moat-cli-user/src/main.rs @@ -22,11 +22,13 @@ use clap::Parser; use crate::interactor::Interactor; use dusk_wallet::{Wallet, WalletPath}; -use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash}; -use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; use moat_cli_common::Error; use rand::SeedableRng; use toml_base_config::BaseConfig; +use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash}; +use zk_citadel_moat::wallet_accessor::{ + BlockchainAccessConfig, WalletAccessor, +}; #[tokio::main] #[allow(non_snake_case)] diff --git a/moat-cli/moat-cli-user/src/prompt.rs b/moat-cli/moat-cli-user/src/prompt.rs index 31d4565..fcc3aea 100644 --- a/moat-cli/moat-cli-user/src/prompt.rs +++ b/moat-cli/moat-cli-user/src/prompt.rs @@ -9,9 +9,7 @@ use requestty::{ErrorKind, Question}; pub(crate) fn request_session_cookie() -> Result { let q = Question::input("session_cookie") .message("Please enter session cookie:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of the session id - }) + .validate_on_key(|_, _| true) .validate(|id, _| { if id.is_empty() { Err("Please enter a valid session cookie".to_string()) @@ -29,9 +27,7 @@ pub(crate) fn request_session_cookie() -> Result { pub(crate) fn request_license_hash() -> Result { let q = Question::input("license_hash") .message("Please enter license hash:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of the license hash - }) + .validate_on_key(|_, _| true) .validate(|license_hash, _| { if license_hash.is_empty() { Err("Please enter a valid license hash".to_string()) @@ -49,9 +45,7 @@ pub(crate) fn request_license_hash() -> Result { pub(crate) fn request_psk_lp_bytes() -> Result { let q = Question::input("psk_lp_bytes") .message("Please enter the address of the LP:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of the psk - }) + .validate_on_key(|_, _| true) .validate(|psk_lp_bytes, _| { if psk_lp_bytes.is_empty() { Err("Please enter a valid LP address".to_string()) @@ -69,9 +63,7 @@ pub(crate) fn request_psk_lp_bytes() -> Result { pub(crate) fn request_psk_sp_bytes() -> Result { let q = Question::input("psk_sp_bytes") .message("Please enter the address of the SP:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of the SP public key - }) + .validate_on_key(|_, _| true) .validate(|psk_sp_bytes, _| { if psk_sp_bytes.is_empty() { Err("Please enter a valid SP address".to_string()) @@ -89,9 +81,7 @@ pub(crate) fn request_psk_sp_bytes() -> Result { pub(crate) fn request_challenge_bytes() -> Result { let q = Question::input("challenge_bytes") .message("Please enter the challenge:".to_string()) - .validate_on_key(|_, _| { - true // todo: add some validation of the challenge - }) + .validate_on_key(|_, _| true) .validate(|challenge_bytes, _| { if challenge_bytes.is_empty() { Err("Please enter a valid challenge".to_string()) diff --git a/moat-cli/moat-cli-user/src/run_result.rs b/moat-cli/moat-cli-user/src/run_result.rs index 6983fde..c2d9b95 100644 --- a/moat-cli/moat-cli-user/src/run_result.rs +++ b/moat-cli/moat-cli-user/src/run_result.rs @@ -5,11 +5,10 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use rkyv::ser::serializers::AllocSerializer; +use sha3::{Digest, Sha3_256}; use std::fmt; use std::ops::Range; use zk_citadel::license::License; -// use rkyv::{check_archived_root, Archive, Deserialize, Infallible, Serialize}; -use sha3::{Digest, Sha3_256}; pub struct SubmitRequestSummary { pub psk_lp: String, diff --git a/moat-example/src/main.rs b/moat-example/src/main.rs index 521a9b8..e95b175 100644 --- a/moat-example/src/main.rs +++ b/moat-example/src/main.rs @@ -68,7 +68,7 @@ async fn main() -> Result<(), Error> { MoatCore::get_owned_licenses(&ssk_user, &moat_context).await?; // Use a license - let psk_sp = psk_lp; // we set the same one than the LP just for testing + let psk_sp = psk_lp; // we set the same key as the one for LP just for testing let challenge = JubJubScalar::from(1234u64); let session_cookie = MoatCore::use_license( &moat_context, diff --git a/moat/src/api.rs b/moat/src/api.rs index fad0bd3..de62612 100644 --- a/moat/src/api.rs +++ b/moat/src/api.rs @@ -34,8 +34,6 @@ impl MoatCore { pub fn get_wallet_keypair( moat_context: &MoatContext, ) -> Result<(PublicSpendKey, SecretSpendKey), Error> { - // We access the wallet to get the key pair - println!("wallet_path={}", &moat_context.wallet_path); let wallet_accessor = WalletAccessor::create( moat_context.wallet_path.clone(), moat_context.wallet_password.clone(), @@ -165,8 +163,6 @@ impl MoatCore { match pos_license { Some((pos, license)) => { - println!("using license: {}", license_hash); - let (_tx_id, session_cookie) = MoatCoreUtils::prove_and_send_use_license( &moat_context.blockchain_access_config, diff --git a/moat/src/bc_types.rs b/moat/src/bc_types.rs index a60373a..d2eb51b 100644 --- a/moat/src/bc_types.rs +++ b/moat/src/bc_types.rs @@ -50,7 +50,6 @@ pub struct QueryResult { pub block_txs: Vec, } -// {"block":{"header":{"height":77065}}} #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] pub struct QueryResult2 { pub block: Block, diff --git a/moat/src/blockchain_queries/tx_inquirer.rs b/moat/src/blockchain_queries/tx_inquirer.rs index d09277a..423288c 100644 --- a/moat/src/blockchain_queries/tx_inquirer.rs +++ b/moat/src/blockchain_queries/tx_inquirer.rs @@ -22,7 +22,6 @@ impl TxInquirer { .map(|(txs, _)| txs) } - // range retrieval seems to have a limit of 10k /// returns transactions in a range and the current top block pub async fn txs_from_block_range( client: &RuskHttpClient, diff --git a/moat/src/citadel_queries/citadel_inquirer.rs b/moat/src/citadel_queries/citadel_inquirer.rs index 3c7b390..59e6fe6 100644 --- a/moat/src/citadel_queries/citadel_inquirer.rs +++ b/moat/src/citadel_queries/citadel_inquirer.rs @@ -24,12 +24,13 @@ use zk_citadel::license::License; pub struct CitadelInquirer {} impl CitadelInquirer { - // vector overhead length is needed as get_licenses returns licenses + // vector overhead length is needed because get_licenses returns licenses // serialized as vector of bytes const VEC_OVERHEAD_LEN: usize = 8; pub const GET_LICENSES_ITEM_LEN: usize = std::mem::size_of::<(u64, License)>() + Self::VEC_OVERHEAD_LEN; + /// Provides licenses issued within a given block height range pub async fn get_licenses( client: &RuskHttpClient, block_heights: Range, @@ -46,6 +47,8 @@ impl CitadelInquirer { .wait() } + /// Provides opening for a given position in the merkle tree, or None if not + /// found. pub async fn get_merkle_opening( client: &RuskHttpClient, pos: u64, @@ -59,6 +62,7 @@ impl CitadelInquirer { .await } + /// Provides session with a given session id, or None if not found. pub async fn get_session( client: &RuskHttpClient, session_id: LicenseSessionId, @@ -72,6 +76,7 @@ impl CitadelInquirer { .await } + /// Provides information about license contract's state. pub async fn get_info( client: &RuskHttpClient, ) -> Result<(u32, u32, u32), Error> { diff --git a/moat/src/citadel_requests/request_creator.rs b/moat/src/citadel_requests/request_creator.rs index 1a69449..1544740 100644 --- a/moat/src/citadel_requests/request_creator.rs +++ b/moat/src/citadel_requests/request_creator.rs @@ -15,8 +15,8 @@ use zk_citadel::license::Request; pub struct RequestCreator; impl RequestCreator { - /// creates request from user's secret spend key - /// and license provider's public spend key + /// Creates request from user's secret spend key + /// and license provider's public spend key. pub fn create( ssk_user: &SecretSpendKey, psk_lp: &PublicSpendKey, @@ -33,9 +33,9 @@ impl RequestCreator { Ok(request) } - /// creates request from user's secret spend key - /// and license provider's public spend key - /// parameters are expected to be hexadecimal strings + /// Creates request from user's secret spend key + /// and license provider's public spend key, + /// parameters are expected to be hexadecimal strings. pub fn create_from_hex_args< R: RngCore + CryptoRng, S: AsRef, diff --git a/moat/src/citadel_requests/request_scanner.rs b/moat/src/citadel_requests/request_scanner.rs index df6c6b7..58b6456 100644 --- a/moat/src/citadel_requests/request_scanner.rs +++ b/moat/src/citadel_requests/request_scanner.rs @@ -16,7 +16,7 @@ use zk_citadel::license::Request; pub struct RequestScanner; impl RequestScanner { - /// Returns requests found in the given collection of transactions + /// Returns requests found in the given collection of transactions. pub fn scan_transactions(txs: Transactions) -> Vec { let mut requests = Vec::new(); for tx in &txs.transactions { diff --git a/moat/src/citadel_requests/request_sender.rs b/moat/src/citadel_requests/request_sender.rs index 643f44d..efdc08c 100644 --- a/moat/src/citadel_requests/request_sender.rs +++ b/moat/src/citadel_requests/request_sender.rs @@ -15,6 +15,7 @@ use zk_citadel::license::Request; pub struct RequestSender; impl RequestSender { + /// Sends (submits) request into the blockchain. pub async fn send_request( request: Request, config: &BlockchainAccessConfig, diff --git a/moat/src/contract_queries/contract_inquirer.rs b/moat/src/contract_queries/contract_inquirer.rs index ff0a797..361193a 100644 --- a/moat/src/contract_queries/contract_inquirer.rs +++ b/moat/src/contract_queries/contract_inquirer.rs @@ -18,6 +18,7 @@ use rkyv::{check_archived_root, Archive, Deserialize, Infallible}; pub struct ContractInquirer {} impl ContractInquirer { + /// Calls a given query method of a given contract. pub async fn query_contract( client: &RuskHttpClient, args: A, @@ -52,6 +53,8 @@ impl ContractInquirer { Ok(r) } + /// Calls a given query method of a given contract. + /// Returns response as a stream to be processed by the caller. pub async fn query_contract_with_feeder( client: &RuskHttpClient, args: A, diff --git a/moat/src/contract_queries/contract_inquirer_ws.rs b/moat/src/contract_queries/contract_inquirer_ws.rs index 522c2dc..8d0878c 100644 --- a/moat/src/contract_queries/contract_inquirer_ws.rs +++ b/moat/src/contract_queries/contract_inquirer_ws.rs @@ -21,6 +21,7 @@ use tokio_tungstenite::tungstenite::Message; pub struct ContractInquirerWs {} impl ContractInquirerWs { + /// Calls a given query method of a given contract. pub async fn query_contract( url: impl AsRef, id: Option, diff --git a/moat/src/contract_queries/ws_types.rs b/moat/src/contract_queries/ws_types.rs index 45ab8bd..eb3d0df 100644 --- a/moat/src/contract_queries/ws_types.rs +++ b/moat/src/contract_queries/ws_types.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; use std::fmt::{Display, Formatter}; -/// A request sent by the websocket client, asking for a specific contract +/// Request sent by the websocket client, asking for a specific contract /// function to be executed with the given arguments. #[serde_with::serde_as] #[derive(Debug, Deserialize, Serialize)] diff --git a/moat/src/license_provider/license_issuer.rs b/moat/src/license_provider/license_issuer.rs index 8a16e92..1b8b34f 100644 --- a/moat/src/license_provider/license_issuer.rs +++ b/moat/src/license_provider/license_issuer.rs @@ -43,6 +43,8 @@ impl LicenseIssuer { } } + /// Issue license for a given request, License Provider SSK, and attribute + /// data. Returns a serialized license. pub async fn issue_license( &self, rng: &mut R, diff --git a/moat/src/license_provider/reference_lp.rs b/moat/src/license_provider/reference_lp.rs index 6b0594a..1406620 100644 --- a/moat/src/license_provider/reference_lp.rs +++ b/moat/src/license_provider/reference_lp.rs @@ -23,6 +23,7 @@ pub struct LPConfig { impl JsonLoader for LPConfig {} const BLOCKS_RANGE_LEN: u64 = 10000; +const MAX_OBJECT_SIZE: usize = 16384; pub struct ReferenceLP { pub psk_lp: PublicSpendKey, @@ -62,9 +63,9 @@ impl ReferenceLP { Ok(Self::new(psk_lp, *ssk_lp, vk_lp)) } - /// scans the entire blockchain for the requests to process - /// returns total number of requests found - /// and number of requests addressed to this LP + /// Scans the entire blockchain for the requests to process. + /// Returns total number of requests found and number of requests addressed + /// to this LP. pub async fn scan( &mut self, cfg: &BlockchainAccessConfig, @@ -91,9 +92,9 @@ impl ReferenceLP { } } - /// scans the last n blocks for the requests to process - /// returns total number of requests found - /// and number of requests addressed to this LP + /// Scans last n blocks for the requests to process. + /// Returns the total number of requests found and the number of requests + /// addressed to this LP. pub async fn scan_last_blocks( &mut self, n: usize, @@ -113,7 +114,7 @@ impl ReferenceLP { } /// Given a collection of requests, retain only those requests - /// in the collection which are owned by 'this' license provider + /// in the collection which are owned by 'this' license provider. pub fn retain_owned_requests( &self, mut requests: Vec, @@ -136,6 +137,7 @@ impl ReferenceLP { } } + /// Take and remove one of the requests to process. pub fn take_request(&mut self) -> Option { self.requests_to_process.pop().map(|request| { self.requests_hashes.remove(&Self::hash_request(&request)); @@ -143,6 +145,7 @@ impl ReferenceLP { }) } + /// Retrieve request with a given request hash, or None if not found. pub fn get_request(&mut self, request_hash: &String) -> Option { for (index, request) in self.requests_to_process.iter().enumerate() { if Self::to_hash_hex(request) == *request_hash { @@ -164,9 +167,9 @@ impl ReferenceLP { fn to_hash_hex(object: &T) -> String where - T: rkyv::Serialize>, + T: rkyv::Serialize>, { - let blob = rkyv::to_bytes::<_, 16386>(object) + let blob = rkyv::to_bytes::<_, MAX_OBJECT_SIZE>(object) .expect("Serializing should be infallible") .to_vec(); Self::blob_to_hash_hex(blob.as_slice()) diff --git a/moat/src/utils.rs b/moat/src/utils.rs index 2ed0579..3e0fcae 100644 --- a/moat/src/utils.rs +++ b/moat/src/utils.rs @@ -128,12 +128,10 @@ impl MoatCoreUtils { *sh_opt = Some(sh); sh_opt.as_ref().expect("setup holder is not empty") } else { - println!("obtaining setup"); let pp_vec = CrsGetter::get_crs(&client).await?; let pp = // SAFETY: CRS vector is checked by the hash check when it is received from the node unsafe { PublicParameters::from_slice_unchecked(pp_vec.as_slice()) }; - println!("compiling circuit"); let (prover, verifier) = Compiler::compile::(&pp, LABEL) .expect("Compiling circuit should succeed"); @@ -155,9 +153,6 @@ impl MoatCoreUtils { .await? .expect("Opening obtained successfully"); - println!( - "calculating proof and calling license contract's use_license" - ); let (tx_id, session_cookie) = LicenseUser::prove_and_use_license( blockchain_access_config, wallet_path, diff --git a/moat/tests/extract_request.rs b/moat/tests/extract_request.rs index 4eb8de7..cef4fdc 100644 --- a/moat/tests/extract_request.rs +++ b/moat/tests/extract_request.rs @@ -4,8 +4,8 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use zk_citadel_moat::{Error, JsonLoader, PayloadExtractor, Tx}; use zk_citadel::license::Request; +use zk_citadel_moat::{Error, JsonLoader, PayloadExtractor, Tx}; #[test] fn extract_request_not_present() -> Result<(), Error> { diff --git a/moat/tests/utils.rs b/moat/tests/utils.rs index 5159c5f..37862d8 100644 --- a/moat/tests/utils.rs +++ b/moat/tests/utils.rs @@ -6,11 +6,11 @@ use dusk_bytes::{DeserializableSlice, Serializable}; use dusk_pki::SecretSpendKey; -use zk_citadel_moat::{Error, RequestCreator, MAX_REQUEST_SIZE}; use rand::rngs::StdRng; use rand::SeedableRng; use sha2::Digest; use sha2::Sha256; +use zk_citadel_moat::{Error, RequestCreator, MAX_REQUEST_SIZE}; #[test] #[ignore] From fe717178a1145c890bb620bacde2728c7f2abd59 Mon Sep 17 00:00:00 2001 From: Milosz Muszynski Date: Fri, 1 Dec 2023 15:10:28 +0100 Subject: [PATCH 3/3] De-duplicated utility functions --- moat-cli/moat-cli-lp/src/run_result.rs | 31 +++------------- moat-cli/moat-cli-user/src/command.rs | 15 +++++--- moat-cli/moat-cli-user/src/run_result.rs | 45 ++--------------------- moat/src/lib.rs | 1 + moat/src/license_provider/reference_lp.rs | 23 +----------- moat/src/utils.rs | 23 +++++++++++- 6 files changed, 42 insertions(+), 96 deletions(-) diff --git a/moat-cli/moat-cli-lp/src/run_result.rs b/moat-cli/moat-cli-lp/src/run_result.rs index 185d288..7bc8fab 100644 --- a/moat-cli/moat-cli-lp/src/run_result.rs +++ b/moat-cli/moat-cli-lp/src/run_result.rs @@ -4,12 +4,10 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use rkyv::ser::serializers::AllocSerializer; use std::fmt; use std::ops::Range; use zk_citadel::license::{License, Request}; -// use rkyv::{check_archived_root, Archive, Deserialize, Infallible, Serialize}; -use sha3::{Digest, Sha3_256}; +use zk_citadel_moat::MoatCoreUtils; pub struct RequestsLPSummary { pub found_total: usize, @@ -50,7 +48,7 @@ impl fmt::Display for RunResult { writeln!( f, "request to process by LP: {}", - RunResult::to_hash_hex(request) + MoatCoreUtils::to_hash_hex(request) )?; } Ok(()) @@ -60,7 +58,7 @@ impl fmt::Display for RunResult { writeln!( f, "issuing license for request: {}", - RunResult::to_hash_hex(&summary.request) + MoatCoreUtils::to_hash_hex(&summary.request) )?; writeln!( f, @@ -70,7 +68,7 @@ impl fmt::Display for RunResult { writeln!( f, "issued license: {}", - RunResult::blob_to_hash_hex( + MoatCoreUtils::blob_to_hash_hex( summary.license_blob.as_slice() ) )?; @@ -94,7 +92,7 @@ impl fmt::Display for RunResult { writeln!( f, "license: {}", - RunResult::to_hash_hex(license), + MoatCoreUtils::to_hash_hex(license), )?; } } @@ -111,22 +109,3 @@ impl fmt::Display for RunResult { } } } - -impl RunResult { - pub fn to_hash_hex(object: &T) -> String - where - T: rkyv::Serialize>, - { - let blob = rkyv::to_bytes::<_, 16386>(object) - .expect("Serializing should be infallible") - .to_vec(); - Self::blob_to_hash_hex(blob.as_slice()) - } - - pub fn blob_to_hash_hex(blob: &[u8]) -> String { - let mut hasher = Sha3_256::new(); - hasher.update(blob); - let result = hasher.finalize(); - hex::encode(result) - } -} diff --git a/moat-cli/moat-cli-user/src/command.rs b/moat-cli/moat-cli-user/src/command.rs index 40c8e69..e72378a 100644 --- a/moat-cli/moat-cli-user/src/command.rs +++ b/moat-cli/moat-cli-user/src/command.rs @@ -20,7 +20,7 @@ use zk_citadel::license::{License, SessionCookie}; use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password}; use zk_citadel_moat::{ BcInquirer, CitadelInquirer, CrsGetter, LicenseCircuit, LicenseUser, - RequestCreator, RequestSender, TxAwaiter, + MoatCoreUtils, RequestCreator, RequestSender, TxAwaiter, }; use std::fs::File; @@ -126,7 +126,7 @@ impl Command { let rng = &mut StdRng::from_entropy(); let request = RequestCreator::create(&ssk, &psk_lp, rng)?; - let request_hash = RunResult::to_hash_hex(&request); + let request_hash = MoatCoreUtils::to_hash_hex(&request); let tx_id = RequestSender::send_request( request, blockchain_access_config, @@ -197,7 +197,10 @@ impl Command { .await?; Ok(match pos_license { Some((pos, license)) => { - println!("using license: {}", RunResult::to_hash_hex(&license)); + println!( + "using license: {}", + MoatCoreUtils::to_hash_hex(&license) + ); let challenge = JubJubScalar::from(challenge_bytes.parse::()?); @@ -225,13 +228,13 @@ impl Command { ) .await?; let summary = UseLicenseSummary { - license_blob: RunResult::to_blob(&license), + license_blob: MoatCoreUtils::to_blob(&license), tx_id: hex::encode(tx_id.to_bytes()), user_attr: hex::encode(session_cookie.attr_data.to_bytes()), session_id: hex::encode( session_cookie.session_id.to_bytes(), ), - session_cookie: RunResult::to_blob_hex(&session_cookie), + session_cookie: MoatCoreUtils::to_blob_hex(&session_cookie), }; RunResult::UseLicense(Some(summary)) } @@ -273,7 +276,7 @@ impl Command { None } else { for (pos, license) in pairs.iter() { - if license_hash == RunResult::to_hash_hex(license) { + if license_hash == MoatCoreUtils::to_hash_hex(license) { return Ok(Some((*pos, license.clone()))); } } diff --git a/moat-cli/moat-cli-user/src/run_result.rs b/moat-cli/moat-cli-user/src/run_result.rs index c2d9b95..24c61ff 100644 --- a/moat-cli/moat-cli-user/src/run_result.rs +++ b/moat-cli/moat-cli-user/src/run_result.rs @@ -4,11 +4,10 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use rkyv::ser::serializers::AllocSerializer; -use sha3::{Digest, Sha3_256}; use std::fmt; use std::ops::Range; use zk_citadel::license::License; +use zk_citadel_moat::MoatCoreUtils; pub struct SubmitRequestSummary { pub psk_lp: String, @@ -70,7 +69,7 @@ impl fmt::Display for RunResult { writeln!( f, "license: {} {}", - RunResult::to_hash_hex(license), + MoatCoreUtils::to_hash_hex(license), if *is_owned { "owned" } else { "" } )?; } @@ -83,7 +82,7 @@ impl fmt::Display for RunResult { writeln!( f, "using license: {}", - Self::blob_to_hash_hex( + MoatCoreUtils::blob_to_hash_hex( summary.license_blob.as_slice() ) )?; @@ -96,7 +95,7 @@ impl fmt::Display for RunResult { writeln!( f, "license {} used", - Self::blob_to_hash_hex( + MoatCoreUtils::blob_to_hash_hex( summary.license_blob.as_slice() ), )?; @@ -128,39 +127,3 @@ impl fmt::Display for RunResult { } } } - -impl RunResult { - pub fn to_hash_hex(object: &T) -> String - where - T: rkyv::Serialize>, - { - let blob = rkyv::to_bytes::<_, 16386>(object) - .expect("Serializing should be infallible") - .to_vec(); - Self::blob_to_hash_hex(blob.as_slice()) - } - - pub fn blob_to_hash_hex(blob: &[u8]) -> String { - let mut hasher = Sha3_256::new(); - hasher.update(blob); - let result = hasher.finalize(); - hex::encode(result) - } - - pub fn to_blob_hex(object: &T) -> String - where - T: rkyv::Serialize>, - { - let blob = Self::to_blob(object); - hex::encode(blob) - } - - pub fn to_blob(object: &T) -> Vec - where - T: rkyv::Serialize>, - { - rkyv::to_bytes::<_, 16386>(object) - .expect("Serializing should be infallible") - .to_vec() - } -} diff --git a/moat/src/lib.rs b/moat/src/lib.rs index 799d081..39a82e6 100644 --- a/moat/src/lib.rs +++ b/moat/src/lib.rs @@ -45,3 +45,4 @@ pub use contract_queries::{ }; pub use error::Error; pub use json_loader::JsonLoader; +pub use utils::MoatCoreUtils; diff --git a/moat/src/license_provider/reference_lp.rs b/moat/src/license_provider/reference_lp.rs index 1406620..2b832f9 100644 --- a/moat/src/license_provider/reference_lp.rs +++ b/moat/src/license_provider/reference_lp.rs @@ -4,13 +4,12 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +use crate::utils::MoatCoreUtils; use crate::wallet_accessor::BlockchainAccessConfig; use crate::{Error, JsonLoader, RequestScanner, MAX_REQUEST_SIZE}; use blake3::OUT_LEN; use dusk_bytes::DeserializableSlice; use dusk_pki::{PublicSpendKey, SecretSpendKey, ViewKey}; -use rkyv::ser::serializers::AllocSerializer; -use sha3::{Digest, Sha3_256}; use std::collections::BTreeSet; use std::path::Path; use zk_citadel::license::Request; @@ -23,7 +22,6 @@ pub struct LPConfig { impl JsonLoader for LPConfig {} const BLOCKS_RANGE_LEN: u64 = 10000; -const MAX_OBJECT_SIZE: usize = 16384; pub struct ReferenceLP { pub psk_lp: PublicSpendKey, @@ -148,7 +146,7 @@ impl ReferenceLP { /// Retrieve request with a given request hash, or None if not found. pub fn get_request(&mut self, request_hash: &String) -> Option { for (index, request) in self.requests_to_process.iter().enumerate() { - if Self::to_hash_hex(request) == *request_hash { + if MoatCoreUtils::to_hash_hex(request) == *request_hash { self.requests_hashes.remove(&Self::hash_request(request)); return Some(self.requests_to_process.remove(index)); } @@ -164,21 +162,4 @@ impl ReferenceLP { ) .as_bytes() } - - fn to_hash_hex(object: &T) -> String - where - T: rkyv::Serialize>, - { - let blob = rkyv::to_bytes::<_, MAX_OBJECT_SIZE>(object) - .expect("Serializing should be infallible") - .to_vec(); - Self::blob_to_hash_hex(blob.as_slice()) - } - - fn blob_to_hash_hex(blob: &[u8]) -> String { - let mut hasher = Sha3_256::new(); - hasher.update(blob); - let result = hasher.finalize(); - hex::encode(result) - } } diff --git a/moat/src/utils.rs b/moat/src/utils.rs index 3e0fcae..2284360 100644 --- a/moat/src/utils.rs +++ b/moat/src/utils.rs @@ -38,12 +38,14 @@ pub struct SetupHolder { pub struct MoatCoreUtils {} +const MAX_OBJECT_SIZE: usize = 16384; + impl MoatCoreUtils { pub fn to_hash_hex(object: &T) -> String where - T: rkyv::Serialize>, + T: rkyv::Serialize>, { - let blob = rkyv::to_bytes::<_, 16386>(object) + let blob = rkyv::to_bytes::<_, MAX_OBJECT_SIZE>(object) .expect("Serializing should be infallible") .to_vec(); Self::blob_to_hash_hex(blob.as_slice()) @@ -56,6 +58,23 @@ impl MoatCoreUtils { hex::encode(result) } + pub fn to_blob_hex(object: &T) -> String + where + T: rkyv::Serialize>, + { + let blob = Self::to_blob(object); + hex::encode(blob) + } + + pub fn to_blob(object: &T) -> Vec + where + T: rkyv::Serialize>, + { + rkyv::to_bytes::<_, MAX_OBJECT_SIZE>(object) + .expect("Serializing should be infallible") + .to_vec() + } + pub async fn get_license_to_use( blockchain_access_config: &BlockchainAccessConfig, ssk: &SecretSpendKey,