From 82b9a2799b8d17567225a3ba3c1d00f0a047f1c1 Mon Sep 17 00:00:00 2001 From: xevisalle <38231508+xevisalle@users.noreply.github.com> Date: Thu, 16 Nov 2023 16:45:17 +0100 Subject: [PATCH] Improve the CLI --- Cargo.toml | 2 +- README.md | 201 +++--------------- config.toml | 2 + integration-tests/Cargo.toml | 2 +- .../tests/blockchain/stake_add_owner.rs | 6 +- .../tests/citadel/int_test_lp.rs | 24 ++- .../tests/citadel/int_test_user.rs | 12 +- .../tests/citadel/issue_license.rs | 12 +- .../tests/citadel/send_request.rs | 6 +- integration-tests/tests/config/config.toml | 2 - .../config/{lp.json => test_keys_lp.json} | 0 .../config/{lp2.json => test_keys_lp_2.json} | 0 .../{request.json => test_request.json} | 0 license-provider/Cargo.toml | 2 +- license-provider/src/reference_lp.rs | 18 +- license-provider/tests/config/lp.json | 4 - .../tests/config/test_keys_lp.json | 5 + license-provider/tests/test_lp.rs | 6 +- moat-cli-lp/Cargo.toml | 3 +- moat-cli-lp/config.toml | 6 - moat-cli-lp/src/args.rs | 4 +- moat-cli-lp/src/command.rs | 23 +- moat-cli-lp/src/config.rs | 2 - moat-cli-lp/src/interactor.rs | 7 +- moat-cli-lp/src/main.rs | 14 +- moat-cli-sp/Cargo.toml | 2 +- moat-cli-user/Cargo.toml | 2 +- moat-cli-user/config.toml | 4 - moat-cli-user/src/args.rs | 7 +- moat-cli-user/src/command.rs | 146 +++++-------- moat-cli-user/src/interactor.rs | 17 +- moat-cli-user/src/main.rs | 18 +- moat-cli-user/src/prompt.rs | 20 ++ moat-cli-user/src/run_result.rs | 20 +- moat-cli/config.toml | 4 - moat-cli/request.json | 4 - moat-cli/request2.json | 4 - moat-core/Cargo.toml | 2 +- .../test-moat-cli}/Cargo.toml | 10 +- .../test-moat-cli}/README.md | 0 .../test-moat-cli}/config.toml | 0 .../test-moat-cli}/lp.json | 0 .../test-moat-cli}/lp2.json | 0 .../test-moat-cli}/request.json | 0 .../test-moat-cli}/request2.json | 0 .../test-moat-cli}/src/args.rs | 0 .../test-moat-cli}/src/command.rs | 0 .../test-moat-cli}/src/error.rs | 0 .../test-moat-cli}/src/interactor.rs | 0 .../test-moat-cli}/src/main.rs | 0 .../test-moat-cli}/src/menu.rs | 0 .../test-moat-cli}/src/prompt.rs | 0 .../test-moat-cli}/src/run_result.rs | 0 .../test-moat-request}/Cargo.toml | 8 +- .../test-moat-request}/config.toml | 0 .../test-moat-request}/request.json | 0 .../test-moat-request}/src/args.rs | 0 .../test-moat-request}/src/main.rs | 0 wallet-accessor/Cargo.toml | 2 +- 59 files changed, 224 insertions(+), 409 deletions(-) create mode 100644 config.toml rename integration-tests/tests/config/{lp.json => test_keys_lp.json} (100%) rename integration-tests/tests/config/{lp2.json => test_keys_lp_2.json} (100%) rename integration-tests/tests/request/{request.json => test_request.json} (100%) delete mode 100644 license-provider/tests/config/lp.json create mode 100644 license-provider/tests/config/test_keys_lp.json delete mode 100644 moat-cli-lp/config.toml delete mode 100644 moat-cli-user/config.toml delete mode 100644 moat-cli/config.toml delete mode 100644 moat-cli/request.json delete mode 100644 moat-cli/request2.json rename {moat-cli => testing-utils/test-moat-cli}/Cargo.toml (74%) rename {moat-cli => testing-utils/test-moat-cli}/README.md (100%) rename {moat-cli-request => testing-utils/test-moat-cli}/config.toml (100%) rename {moat-cli => testing-utils/test-moat-cli}/lp.json (100%) rename {moat-cli => testing-utils/test-moat-cli}/lp2.json (100%) rename {moat-cli-request => testing-utils/test-moat-cli}/request.json (100%) rename {moat-cli-user => testing-utils/test-moat-cli}/request2.json (100%) rename {moat-cli => testing-utils/test-moat-cli}/src/args.rs (100%) rename {moat-cli => testing-utils/test-moat-cli}/src/command.rs (100%) rename {moat-cli => testing-utils/test-moat-cli}/src/error.rs (100%) rename {moat-cli => testing-utils/test-moat-cli}/src/interactor.rs (100%) rename {moat-cli => testing-utils/test-moat-cli}/src/main.rs (100%) rename {moat-cli => testing-utils/test-moat-cli}/src/menu.rs (100%) rename {moat-cli => testing-utils/test-moat-cli}/src/prompt.rs (100%) rename {moat-cli => testing-utils/test-moat-cli}/src/run_result.rs (100%) rename {moat-cli-request => testing-utils/test-moat-request}/Cargo.toml (63%) rename {moat-cli-sp => testing-utils/test-moat-request}/config.toml (100%) rename {moat-cli-user => testing-utils/test-moat-request}/request.json (100%) rename {moat-cli-request => testing-utils/test-moat-request}/src/args.rs (100%) rename {moat-cli-request => testing-utils/test-moat-request}/src/main.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index ebbe7e4..a0940aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["moat-cli", "moat-cli-user", "moat-cli-lp", "moat-cli-sp", "moat-cli-request", "moat-core", "wallet-accessor", "integration-tests", "license-provider", "macros/code-hasher"] +members = ["testing-utils/test-moat-cli", "moat-cli-user", "moat-cli-lp", "moat-cli-sp", "testing-utils/test-moat-request", "moat-core", "wallet-accessor", "integration-tests", "license-provider", "macros/code-hasher"] diff --git a/README.md b/README.md index 535c347..2d4c920 100644 --- a/README.md +++ b/README.md @@ -1,182 +1,41 @@ -# dusk moat +# Moat: The Citadel SDK [![Repository](https://img.shields.io/badge/github-moat-blueviolet?logo=github)](https://github.com/dusk-network/moat) -![Build Status](https://github.com/dusk-network/moat/workflows/dusk_ci/badge.svg) -[![Documentation](https://img.shields.io/badge/docs-moat-blue?logo=rust)](https://docs.rs/moat/) -`moat` is a Rust workspace containing the following crates: +**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-cli`: Command line interface (CLI) for submitting license requests to the Dusk blockchain. -- `moat-core`: Library providing an SDK required for implementing Citadel scenarios with the Dusk blockchain. -- `license-provider`: Reference implementation of a license provider. -- `integration-tests`: Moat library integration tests (test which require access to Dusk Wallet and live Dusk cluster). -- `wallet-accessor`: Library for submitting contract-call transactions to 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-cli +## Testing the environment -moat-cli utility can be used to submit license request to the Dusk blockchain. -Any license provider can then scan the blockchain for requests, filter out relevant requests and process them accordingly. +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): -Example usage of the moat-cli utility: -```sh -cargo r --release --bin moat-cli -- --wallet-path ~/.dusk/rusk-wallet --config-path ./moat-cli/config.toml --password password ./moat-cli/request.json ``` -where: -- `wallet-path`: path to your installed wallet directory -- `config-path`: path to your blockchain access configuration (refer to the configuration section) -- `password`: password for your wallet -- `...request.json`: path to your request json file (as explained in the request section) - -Request sending can also be performed programmatically, using moat-core, described below: -```rust -//... - let request_json: RequestJson = RequestJson::from_file(json_path)?; - let rng = &mut StdRng::seed_from_u64(0xcafe); - let request = RequestCreator::create_from_hex_args( - request_json.user_ssk, - request_json.provider_psk, - rng, - )?; -//... - PayloadSender::send_to_contract_method( - request, - &blockchain_access_config, - &wallet_path, - &psw, - gas_limit, - gas_price, - LICENSE_CONTRACT_ID, - NOOP_METHOD_NAME, - ) - .await?; -//... +cargo t --release --features="exp_tests" -- --test-threads=1 +cargo t --release --features="int_tests" -- --test-threads=1 ``` -In the above example, the user is expected to have a request json file available -at some filesystem path. The code loads contents of the file, extracts request arguments from it and -instantiates a request object. Subsequently, request is being sent to blockchain via -a provided wallet (utilizing wallet path and password, as well as a blockchain access configuration file). - -As the `moat-cli` requires a path to a json request file. An example request json file looks as follows: -```json -{ - "user_ssk": "c6afd78c8b3902b474d4c0972b62888e4b880dccf8da68e86266fefa45ee7505926f06ab82ac200995f1239d518fdb74903f225f4460d8db62f2449f6d4dc402", - "provider_psk": "29c4336ef24e585f4506e32e269c5363a71f7dcd74586b210c56e569ad2644e832c785f102dd3c985c705008ec188be819bac85b65c9f70decb9adcf4a72cc43" -} + +## Usage + +The moat-cli utility can be used from the POV of any of the parties involved in the Citadel protocol, let them be: +- **License Provider (LP):** A party receiving onchain requests from users to issue licenses onchain addressed to them. +- **User:** A party requesting licenses onchain to LPs, and being able to use the licenses onchain as well. + +### License Provider + +LPs can then scan the Blockchain for requests and issue licenses if the requests are valid. To run the LP CLI, simply run: + +```sh +cargo r --release --bin moat-cli-lp -- --wallet-path ~/.dusk/rusk-wallet --wallet-pass ``` -It contains the user secret spend key (user_ssk) and provider public spend key (provider_psk), both in a form of a hexadecimal string. - -## moat-core -Provides an SDK for writing user, LP, and SP applications based on the Dusk blockchain. -It provides the following functionality, related to license contract: -- creating requests -- sending license requests -- scanning blockchain for requests -- performing license contract queries: _get_licenses, get_merkle_opening, get_session, get_info_ - -In addition, it provides the following generic Dusk blockchain functionality, not necessarily related to license contract: -- sending payloads to any method of any contract (e.g., can be used for _issue_license_ and _use_license_) -- retrieving payloads of any type from the blockchain -- performing queries on any method of any contract (with return values passed directly or via a feeder/stream) -- retrieving transactions from blockchain (e.g., by block range) - -In addition, websocket functionality for the queries is also provided. - -## license-provider -Provides functionality needed for implementors of license provider, including: -- license issuer -- blockchain scanner for relevant request -The crate allows for implementation of a license provider, whose task is to periodically check for license requests in the blockchain, and the to process the request and issue licenses. - -## integration-tests -As most of the functionality provided by Moat deals with a blockchain, integration tests play critical role. -As in the case of moat-core functionality, tests include both Citadel-specific tests and blockchain generic test. - -## wallet accessor -This is a low-level crate which provides wallet (Blockchain) connectivity for functions of moat-core. -Users of moat-core do not need to be aware of this crate, yet for maintainers and extenders, the crate -provides a convenient low level interface between the higher-level moat-core library and the blockchain. -Note that this crate deals only with contract method calling, it does not deal with contract queries. - -## moat-core - -### citadel requests - -Class: RequestCreator -Methods: - create, - create_from_hex_args -Both methods allow for creation of a request, given user's secret spend key and license provider's public spend key. -The request can then be sent to license provider, off-chain or on-chain. - -Class: RequestSender -Methods: send_request -Submits the request into blockchain. -It does so by calling a dummy contract method with request as an argument. - -Class: RequestScanner -Methods: - scan_transactions, - scan_last_blocks, - scan_block_range -Scan requests in a given collection of transactions, -contained in a given range of blocks or in a given number of most recent blocks. - -### citadel queries - -Class: CitadelInquirer -Methods: - get_licenses, - get_merkle_opening, - get_session, - get_info -Execute citadel-specific query methods of the license contract method. - -### blockchain payloads - -Class: PayloadExtractor -Methods: payload_from_tx -Extracts a payload from the given transaction, -errors if payload of a given type is not present or the transaction is not a contract calling transaction. - -Class: PayloadRetriever -Methods: retrieve_payload -Retrieves payload of a given transaction id, -errors if transaction is not found, or it does not contain a payload -(for example, given transaction is not a contract calling transaction) - -Class: PayloadSender -Methods: execute_contract_method -Executes given method of a given contract (identified by a contract id), passing to it the payload as an argument. - -### contract queries - -Class: ContractInquirer -Methods: - query_contract, - query_contract_with_feeder -query_contract - accepts a generic argument, contract id and contract query method name, returns a generic value result -query_contract_with_feeder - accepts a generic argument, contract id and method name, returns result as a Stream of bytes - -### blockchain queries - -Class: BcInquirer -Methods: - gql_query, - block_height -gql_query - executes a GQL query and returns result as a vector of bytes -block_height - returns the current block height as u64 - -Class: TxAwaiter -Methods: - wait_for, - wait_for_tx -Waits for a transaction identified by transaction id to be confirmed on the blockchain. - -Class: TxInquirer -Methods: - txs_from_block, - txs_from_block_range, - txs_from_last_n_blocks, - retrieve_tx -Retrieve transaction identified by transaction id, or transactions contained in a given block, or a collection of blocks. + +### User + +Users can request licenses and use them. To run the user CLI, simply run: + +```sh +cargo r --release --bin moat-cli-user -- --wallet-path ~/.dusk/rusk-wallet --wallet-pass +``` + diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..94ab01d --- /dev/null +++ b/config.toml @@ -0,0 +1,2 @@ +rusk_address = "http://127.0.0.1:8080" +prover_address = "http://127.0.0.1:8080" diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index c43a237..d99c861 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -8,7 +8,7 @@ moat-core={ path = "../moat-core" } license-provider = { path = "../license-provider" } [dev-dependencies] -dusk-wallet = "0.20.0-rc.0" +dusk-wallet = "0.20.1-rc.0" zk-citadel = "0.5" phoenix-core = { version = "0.21", features = ["alloc"] } poseidon-merkle = { version = "0.3", features = ["rkyv-impl"] } diff --git a/integration-tests/tests/blockchain/stake_add_owner.rs b/integration-tests/tests/blockchain/stake_add_owner.rs index 5fb098c..01f2fe5 100644 --- a/integration-tests/tests/blockchain/stake_add_owner.rs +++ b/integration-tests/tests/blockchain/stake_add_owner.rs @@ -34,8 +34,10 @@ async fn stake_add_owner() -> Result<(), Error> { let blockchain_config = BlockchainAccessConfig::load_path(blockchain_config_path)?; - let request_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/request/request.json"); + let request_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/request/test_request.json" + ); let request_json: RequestJson = RequestJson::from_file(request_path)?; diff --git a/integration-tests/tests/citadel/int_test_lp.rs b/integration-tests/tests/citadel/int_test_lp.rs index 20474b3..cc82d1c 100644 --- a/integration-tests/tests/citadel/int_test_lp.rs +++ b/integration-tests/tests/citadel/int_test_lp.rs @@ -14,8 +14,10 @@ use wallet_accessor::BlockchainAccessConfig; async fn lp_scan() -> Result<(), Error> { let blockchain_config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml"); - let lp_config_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/lp.json"); + let lp_config_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/config/test_keys_lp.json" + ); let blockchain_config = BlockchainAccessConfig::load_path(blockchain_config_path)?; @@ -31,8 +33,10 @@ async fn lp_scan() -> Result<(), Error> { async fn lp_scan_last_blocks() -> Result<(), Error> { let blockchain_config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml"); - let lp_config_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/lp2.json"); + let lp_config_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/config/test_keys_lp_2.json" + ); let blockchain_config = BlockchainAccessConfig::load_path(blockchain_config_path)?; @@ -50,10 +54,14 @@ async fn lp_scan_last_blocks() -> Result<(), Error> { async fn lp_scan_2_lps() -> Result<(), Error> { let blockchain_config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml"); - let lp1_config_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/lp.json"); - let lp2_config_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/lp2.json"); + let lp1_config_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/config/test_keys_lp.json" + ); + let lp2_config_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/config/test_keys_lp_2.json" + ); let blockchain_config = BlockchainAccessConfig::load_path(blockchain_config_path)?; diff --git a/integration-tests/tests/citadel/int_test_user.rs b/integration-tests/tests/citadel/int_test_user.rs index 1232d61..151c219 100644 --- a/integration-tests/tests/citadel/int_test_user.rs +++ b/integration-tests/tests/citadel/int_test_user.rs @@ -139,11 +139,15 @@ async fn user_round_trip() -> Result<(), Error> { let (prover, verifier) = Compiler::compile::(&pp, LABEL) .expect("Compiling circuit should succeed"); - let request_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/request/request.json"); + let request_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/request/test_request.json" + ); - let lp_config_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/lp2.json"); + let lp_config_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/config/test_keys_lp_2.json" + ); let reference_lp = ReferenceLP::create(&lp_config_path)?; diff --git a/integration-tests/tests/citadel/issue_license.rs b/integration-tests/tests/citadel/issue_license.rs index 6bc913a..7dd5118 100644 --- a/integration-tests/tests/citadel/issue_license.rs +++ b/integration-tests/tests/citadel/issue_license.rs @@ -23,13 +23,17 @@ const GAS_PRICE: u64 = 1; #[tokio::test(flavor = "multi_thread")] #[cfg_attr(not(feature = "int_tests"), ignore)] async fn issue_license() -> Result<(), Error> { - let request_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/request/request.json"); + let request_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/request/test_request.json" + ); let blockchain_config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml"); - let lp_config_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/lp2.json"); + let lp_config_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/config/test_keys_lp_2.json" + ); let reference_lp = ReferenceLP::create(&lp_config_path)?; diff --git a/integration-tests/tests/citadel/send_request.rs b/integration-tests/tests/citadel/send_request.rs index 8b2cf38..e2bdbde 100644 --- a/integration-tests/tests/citadel/send_request.rs +++ b/integration-tests/tests/citadel/send_request.rs @@ -35,8 +35,10 @@ async fn send_request() -> Result<(), Error> { tracing::subscriber::set_global_default(subscriber.finish()) .expect("Setting tracing default should work"); - let request_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/request/request.json"); + let request_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/request/test_request.json" + ); let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml"); diff --git a/integration-tests/tests/config/config.toml b/integration-tests/tests/config/config.toml index f28a088..94ab01d 100644 --- a/integration-tests/tests/config/config.toml +++ b/integration-tests/tests/config/config.toml @@ -1,4 +1,2 @@ rusk_address = "http://127.0.0.1:8080" prover_address = "http://127.0.0.1:8080" -#rusk_address = "http://nodes.dusk.network:8585" -#prover_address = "http://provers.dusk.network:8686" diff --git a/integration-tests/tests/config/lp.json b/integration-tests/tests/config/test_keys_lp.json similarity index 100% rename from integration-tests/tests/config/lp.json rename to integration-tests/tests/config/test_keys_lp.json diff --git a/integration-tests/tests/config/lp2.json b/integration-tests/tests/config/test_keys_lp_2.json similarity index 100% rename from integration-tests/tests/config/lp2.json rename to integration-tests/tests/config/test_keys_lp_2.json diff --git a/integration-tests/tests/request/request.json b/integration-tests/tests/request/test_request.json similarity index 100% rename from integration-tests/tests/request/request.json rename to integration-tests/tests/request/test_request.json diff --git a/license-provider/Cargo.toml b/license-provider/Cargo.toml index 633a957..2b28f85 100644 --- a/license-provider/Cargo.toml +++ b/license-provider/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -dusk-wallet = "0.20.0-rc.0" +dusk-wallet = "0.20.1-rc.0" zk-citadel = "0.5" moat-core={ path = "../moat-core" } wallet-accessor = { path = "../wallet-accessor" } diff --git a/license-provider/src/reference_lp.rs b/license-provider/src/reference_lp.rs index ff23632..c269ccb 100644 --- a/license-provider/src/reference_lp.rs +++ b/license-provider/src/reference_lp.rs @@ -49,19 +49,17 @@ impl ReferenceLP { pub fn create>(lp_config_path: P) -> Result { let lp_config: LPConfig = LPConfig::from_file(lp_config_path)?; - Self::create_with_ssk_psk(lp_config.ssk_lp, lp_config.psk_lp) - } - pub fn create_with_ssk_psk(ssk_lp: S, psk_lp: S) -> Result - where - S: AsRef, - { - let psk_bytes = hex::decode(psk_lp.as_ref())?; - let ssk_bytes = hex::decode(ssk_lp.as_ref())?; - let psk_lp = PublicSpendKey::from_slice(psk_bytes.as_slice())?; + let ssk_bytes = hex::decode(lp_config.ssk_lp)?; let ssk_lp = SecretSpendKey::from_slice(ssk_bytes.as_slice())?; + + Self::create_with_ssk(&ssk_lp) + } + + pub fn create_with_ssk(ssk_lp: &SecretSpendKey) -> Result { + let psk_lp = ssk_lp.public_spend_key(); let vk_lp = ssk_lp.view_key(); - Ok(Self::new(psk_lp, ssk_lp, vk_lp)) + Ok(Self::new(psk_lp, *ssk_lp, vk_lp)) } /// scans the entire blockchain for the requests to process diff --git a/license-provider/tests/config/lp.json b/license-provider/tests/config/lp.json deleted file mode 100644 index 5c6f643..0000000 --- a/license-provider/tests/config/lp.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "psk_lp": "29c4336ef24e585f4506e32e269c5363a71f7dcd74586b210c56e569ad2644e832c785f102dd3c985c705008ec188be819bac85b65c9f70decb9adcf4a72cc43", - "ssk_lp": "530046f569d26740eaa703b7f88bfb82a31aae1cef96732609e4b8f1e59802039f5afb7c1d5576e51c71d5afe8f6e06977c68641fae11abd3ce0b2196d1f3608" -} diff --git a/license-provider/tests/config/test_keys_lp.json b/license-provider/tests/config/test_keys_lp.json new file mode 100644 index 0000000..cbe5e75 --- /dev/null +++ b/license-provider/tests/config/test_keys_lp.json @@ -0,0 +1,5 @@ +{ + "psk_lp": "29c4336ef24e585f4506e32e269c5363a71f7dcd74586b210c56e569ad2644e832c785f102dd3c985c705008ec188be819bac85b65c9f70decb9adcf4a72cc43", + "ssk_lp": "530046f569d26740eaa703b7f88bfb82a31aae1cef96732609e4b8f1e59802039f5afb7c1d5576e51c71d5afe8f6e06977c68641fae11abd3ce0b2196d1f3608" + } + \ No newline at end of file diff --git a/license-provider/tests/test_lp.rs b/license-provider/tests/test_lp.rs index 88f5887..9cb2bc1 100644 --- a/license-provider/tests/test_lp.rs +++ b/license-provider/tests/test_lp.rs @@ -9,8 +9,10 @@ use moat_core::{Error, JsonLoader, RequestScanner, Transactions}; #[test] fn lp_filter_requests() -> Result<(), Error> { - let lp_config_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/lp.json"); + let lp_config_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/config/test_keys_lp.json" + ); let reference_lp = ReferenceLP::create(&lp_config_path)?; let txs_path = diff --git a/moat-cli-lp/Cargo.toml b/moat-cli-lp/Cargo.toml index 0f77e20..b892d57 100644 --- a/moat-cli-lp/Cargo.toml +++ b/moat-cli-lp/Cargo.toml @@ -4,9 +4,10 @@ version = "0.1.0" edition = "2021" [dependencies] -dusk-wallet = "0.20.0-rc.0" +dusk-wallet = "0.20.1-rc.0" wallet-accessor = { path = "../wallet-accessor" } moat-core = { path = "../moat-core" } +dusk-pki = "0.13" license-provider = { path = "../license-provider" } zk-citadel = "0.5" rkyv = { version = "=0.7.39" } diff --git a/moat-cli-lp/config.toml b/moat-cli-lp/config.toml deleted file mode 100644 index 914f8d8..0000000 --- a/moat-cli-lp/config.toml +++ /dev/null @@ -1,6 +0,0 @@ -rusk_address = "http://127.0.0.1:8080" -prover_address = "http://127.0.0.1:8080" -#rusk_address = "http://devnet.nodes.dusk.network:8585" -#prover_address = "http://devnet.provers.dusk.network:8686" -psk_lp = "136d747ff489bd06077f937508b9237ac093ff868dc2e232ab3af0ecd038873288560dbd8aa851e055bc408ebeb89509b26eb6e34b4b43214de467e3ef09594e" -ssk_lp = "fd611dc2cfe15488e3cb94b410fadd3a5e77057be64574eb9b6acaf967a37d0514d0ce88727a24d3756a08bb8ae072d8aaaa88f88768c8a9487fb50678ba5204" diff --git a/moat-cli-lp/src/args.rs b/moat-cli-lp/src/args.rs index 551ebbb..69e82c7 100644 --- a/moat-cli-lp/src/args.rs +++ b/moat-cli-lp/src/args.rs @@ -17,12 +17,12 @@ pub struct Args { pub wallet_path: PathBuf, /// Blockchain access config directory - #[clap(short, long)] + #[clap(short, long, default_value = "./config.toml")] pub config_path: PathBuf, /// Password for the wallet #[clap(long, default_value_t = String::from(""), env = "RUSK_WALLET_PWD")] - pub password: String, + pub wallet_pass: String, /// Hash of the password for the wallet [default: ``] #[clap(short, long, default_value_t = String::from(""))] diff --git a/moat-cli-lp/src/command.rs b/moat-cli-lp/src/command.rs index 816c165..5b0538f 100644 --- a/moat-cli-lp/src/command.rs +++ b/moat-cli-lp/src/command.rs @@ -7,7 +7,8 @@ use crate::run_result::{ IssueLicenseSummary, LicenseContractSummary, RequestsLPSummary, RunResult, }; -use crate::{LPCliConfig, SeedableRng}; +use crate::SeedableRng; +use dusk_pki::SecretSpendKey; use dusk_wallet::{RuskHttpClient, WalletPath}; use license_provider::{LicenseIssuer, ReferenceLP}; use moat_core::{BcInquirer, CitadelInquirer, Error}; @@ -34,20 +35,20 @@ impl Command { wallet_path: &WalletPath, psw: &Password, blockchain_access_config: &BlockchainAccessConfig, - config: &LPCliConfig, + ssk: &SecretSpendKey, gas_limit: u64, gas_price: u64, ) -> Result { let run_result = match self { Command::ListRequestsLP => { - Self::list_requests_lp(blockchain_access_config, config).await? + Self::list_requests_lp(blockchain_access_config, ssk).await? } Command::IssueLicenseLP { request_hash } => { Self::issue_license_lp( wallet_path, psw, blockchain_access_config, - config, + ssk, gas_limit, gas_price, request_hash, @@ -67,12 +68,9 @@ impl Command { /// Command: List Requests LP async fn list_requests_lp( blockchain_access_config: &BlockchainAccessConfig, - config: &LPCliConfig, + ssk: &SecretSpendKey, ) -> Result { - let mut reference_lp = ReferenceLP::create_with_ssk_psk::<&str>( - config.ssk_lp.as_ref(), - config.psk_lp.as_ref(), - )?; + let mut reference_lp = ReferenceLP::create_with_ssk(ssk)?; let (found_total, found_owned) = reference_lp.scan(blockchain_access_config).await?; let summary = RequestsLPSummary { @@ -91,16 +89,13 @@ impl Command { wallet_path: &WalletPath, psw: &Password, blockchain_access_config: &BlockchainAccessConfig, - config: &LPCliConfig, + ssk: &SecretSpendKey, gas_limit: u64, gas_price: u64, request_hash: String, ) -> Result { let mut rng = StdRng::from_entropy(); - let mut reference_lp = ReferenceLP::create_with_ssk_psk::<&str>( - config.ssk_lp.as_ref(), - config.psk_lp.as_ref(), - )?; + let mut reference_lp = ReferenceLP::create_with_ssk(ssk)?; let (_total_count, _this_lp_count) = reference_lp.scan(blockchain_access_config).await?; diff --git a/moat-cli-lp/src/config.rs b/moat-cli-lp/src/config.rs index 16cb84e..cf6e7fb 100644 --- a/moat-cli-lp/src/config.rs +++ b/moat-cli-lp/src/config.rs @@ -11,8 +11,6 @@ use toml_base_config::BaseConfig; pub struct LPCliConfig { pub rusk_address: String, pub prover_address: String, - pub ssk_lp: String, - pub psk_lp: String, } impl BaseConfig for LPCliConfig { diff --git a/moat-cli-lp/src/interactor.rs b/moat-cli-lp/src/interactor.rs index 1f4c587..d282881 100644 --- a/moat-cli-lp/src/interactor.rs +++ b/moat-cli-lp/src/interactor.rs @@ -5,8 +5,9 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use crate::error::CliError; -use crate::{prompt, LPCliConfig}; +use crate::prompt; use crate::{Command, Menu}; +use dusk_pki::SecretSpendKey; use dusk_wallet::WalletPath; use moat_core::Error; use requestty::{ErrorKind, Question}; @@ -66,7 +67,7 @@ pub struct Interactor { pub wallet_path: WalletPath, pub psw: Password, pub blockchain_access_config: BlockchainAccessConfig, - pub config: LPCliConfig, + pub ssk: SecretSpendKey, pub gas_limit: u64, pub gas_price: u64, } @@ -83,7 +84,7 @@ impl Interactor { &self.wallet_path, &self.psw, &self.blockchain_access_config, - &self.config, + &self.ssk, self.gas_limit, self.gas_price, ) diff --git a/moat-cli-lp/src/main.rs b/moat-cli-lp/src/main.rs index d2bea81..39b1a0d 100644 --- a/moat-cli-lp/src/main.rs +++ b/moat-cli-lp/src/main.rs @@ -24,11 +24,11 @@ use clap::Parser; use crate::config::LPCliConfig; use crate::error::CliError; use crate::interactor::Interactor; -use dusk_wallet::WalletPath; +use dusk_wallet::{Wallet, WalletPath}; use rand::SeedableRng; use toml_base_config::BaseConfig; -use wallet_accessor::BlockchainAccessConfig; use wallet_accessor::Password::{Pwd, PwdHash}; +use wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; #[tokio::main] async fn main() -> Result<(), CliError> { @@ -36,7 +36,7 @@ async fn main() -> Result<(), CliError> { let config_path = cli.config_path.as_path(); let wallet_path = cli.wallet_path.as_path(); - let password = cli.password; + let password = cli.wallet_pass; let pwd_hash = cli.pwd_hash; let gas_limit = cli.gas_limit; let gas_price = cli.gas_price; @@ -54,11 +54,17 @@ async fn main() -> Result<(), CliError> { PwdHash(pwd_hash) }; + let wallet_accessor = + WalletAccessor::create(wallet_path.clone(), psw.clone()).unwrap(); + let wallet = Wallet::from_file(wallet_accessor).unwrap(); + + let (_psk, ssk) = wallet.spending_keys(&wallet.default_address()).unwrap(); + let mut interactor = Interactor { wallet_path, psw, blockchain_access_config, - config, + ssk, gas_limit, gas_price, }; diff --git a/moat-cli-sp/Cargo.toml b/moat-cli-sp/Cargo.toml index 8191025..08b112b 100644 --- a/moat-cli-sp/Cargo.toml +++ b/moat-cli-sp/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -dusk-wallet = "0.20.0-rc.0" +dusk-wallet = "0.20.1-rc.0" wallet-accessor = { path = "../wallet-accessor" } moat-core = { path = "../moat-core" } rkyv = { version = "=0.7.39" } diff --git a/moat-cli-user/Cargo.toml b/moat-cli-user/Cargo.toml index aa31482..1fe5992 100644 --- a/moat-cli-user/Cargo.toml +++ b/moat-cli-user/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -dusk-wallet = "0.20.0-rc.0" +dusk-wallet = "0.20.1-rc.0" wallet-accessor = { path = "../wallet-accessor" } moat-core = { path = "../moat-core" } zk-citadel = "0.5" diff --git a/moat-cli-user/config.toml b/moat-cli-user/config.toml deleted file mode 100644 index a413b04..0000000 --- a/moat-cli-user/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -rusk_address = "http://127.0.0.1:8080" -prover_address = "http://127.0.0.1:8080" -#rusk_address = "http://devnet.nodes.dusk.network:8585" -#prover_address = "http://devnet.provers.dusk.network:8686" diff --git a/moat-cli-user/src/args.rs b/moat-cli-user/src/args.rs index 7ed2a27..69e82c7 100644 --- a/moat-cli-user/src/args.rs +++ b/moat-cli-user/src/args.rs @@ -12,20 +12,17 @@ use clap::Parser; #[command(author, version, about, long_about = None)] #[command(propagate_version = true)] pub struct Args { - /// Path of the JSON file to be processed - pub json_path: PathBuf, - /// Wallet directory [default: `$HOME/.dusk/rusk-wallet`] #[clap(short, long)] pub wallet_path: PathBuf, /// Blockchain access config directory - #[clap(short, long)] + #[clap(short, long, default_value = "./config.toml")] pub config_path: PathBuf, /// Password for the wallet #[clap(long, default_value_t = String::from(""), env = "RUSK_WALLET_PWD")] - pub password: String, + pub wallet_pass: String, /// Hash of the password for the wallet [default: ``] #[clap(short, long, default_value_t = String::from(""))] diff --git a/moat-cli-user/src/command.rs b/moat-cli-user/src/command.rs index d69240c..d2a9d2d 100644 --- a/moat-cli-user/src/command.rs +++ b/moat-cli-user/src/command.rs @@ -6,34 +6,33 @@ use crate::interactor::SetupHolder; use crate::run_result::{ - LicenseContractSummary, RequestsSummary, RunResult, SubmitRequestSummary, - UseLicenseSummary, + LicenseContractSummary, RunResult, SubmitRequestSummary, UseLicenseSummary, }; use crate::SeedableRng; use dusk_bls12_381::BlsScalar; -use dusk_bytes::DeserializableSlice; +use dusk_bytes::Serializable; use dusk_pki::{PublicSpendKey, SecretSpendKey}; use dusk_plonk::prelude::*; use dusk_wallet::{RuskHttpClient, WalletPath}; use moat_core::{ BcInquirer, CitadelInquirer, CrsGetter, Error, LicenseCircuit, LicenseUser, - RequestCreator, RequestJson, RequestScanner, RequestSender, TxAwaiter, + RequestCreator, RequestSender, TxAwaiter, }; use rand::rngs::StdRng; -use wallet_accessor::{BlockchainAccessConfig, Password, WalletAccessor}; +use wallet_accessor::{BlockchainAccessConfig, Password}; use zk_citadel::license::{License, SessionCookie}; - /// Commands that can be run against the Moat #[derive(PartialEq, Eq, Hash, Clone, Debug)] pub(crate) enum Command { /// Submit request (User) - SubmitRequest, - /// List requests (User) - ListRequestsUser, + SubmitRequest { psk_lp_bytes: String }, /// List licenses (User) ListLicenses, /// Use license (User) - UseLicense { license_hash: String }, + UseLicense { + license_hash: String, + psk_lp_bytes: String, + }, /// Request Service (User) RequestService { session_cookie: String }, /// Show state @@ -51,37 +50,37 @@ impl Command { blockchain_access_config: &BlockchainAccessConfig, gas_limit: u64, gas_price: u64, - request_json: RequestJson, + ssk: SecretSpendKey, setup_holder: &mut Option, ) -> Result { let run_result = match self { - Command::SubmitRequest => { + Command::SubmitRequest { psk_lp_bytes } => { Self::submit_request( wallet_path, psw, blockchain_access_config, gas_limit, gas_price, - request_json, + ssk, + psk_lp_bytes, ) .await? } - Command::ListRequestsUser => { - Self::list_requests(wallet_path, psw, blockchain_access_config) - .await? - } Command::ListLicenses => { - Self::list_licenses(blockchain_access_config, request_json) - .await? + Self::list_licenses(blockchain_access_config, ssk).await? } - Command::UseLicense { license_hash } => { + Command::UseLicense { + license_hash, + psk_lp_bytes, + } => { Self::use_license( wallet_path, psw, blockchain_access_config, gas_limit, gas_price, - request_json, + psk_lp_bytes, + ssk, setup_holder, license_hash, ) @@ -99,20 +98,26 @@ impl Command { } /// Command: Submit Request + #[allow(non_snake_case)] async fn submit_request( wallet_path: &WalletPath, psw: &Password, blockchain_access_config: &BlockchainAccessConfig, gas_limit: u64, gas_price: u64, - request_json: RequestJson, + ssk: SecretSpendKey, + psk_lp_bytes: String, ) -> Result { + let psk_lp_bytes_formatted: [u8; 64] = + hex::decode(psk_lp_bytes.clone()) + .expect("Decoded.") + .try_into() + .unwrap(); + let psk_lp = + PublicSpendKey::from_bytes(&psk_lp_bytes_formatted).unwrap(); + let rng = &mut StdRng::from_entropy(); // seed_from_u64(0xcafe); - let request = RequestCreator::create_from_hex_args( - request_json.user_ssk, - request_json.provider_psk.clone(), - rng, - )?; + let request = RequestCreator::create(&ssk, &psk_lp, rng)?; let request_hash = RunResult::to_hash_hex(&request); let tx_id = RequestSender::send_request( request, @@ -126,64 +131,19 @@ impl Command { let client = RuskHttpClient::new(blockchain_access_config.rusk_address.clone()); TxAwaiter::wait_for(&client, tx_id).await?; + let summary = SubmitRequestSummary { - psk_lp: request_json.provider_psk, + psk_lp: psk_lp_bytes, tx_id: hex::encode(tx_id.to_bytes()), request_hash, }; Ok(RunResult::SubmitRequest(summary)) } - /// Command: List Requests - async fn list_requests( - wallet_path: &WalletPath, - psw: &Password, - blockchain_access_config: &BlockchainAccessConfig, - ) -> Result { - let wallet_accessor = - WalletAccessor::create(wallet_path.clone(), psw.clone())?; - let note_hashes: Vec = wallet_accessor - .get_notes(blockchain_access_config) - .await? - .iter() - .flat_map(|n| n.nullified_by) - .collect(); - - let mut found_requests = vec![]; - let mut height = 0; - let mut found_total = 0usize; - loop { - let height_end = height + 10000; - let (requests, top, total) = - RequestScanner::scan_related_to_notes_in_block_range( - height, - height_end, - blockchain_access_config, - ¬e_hashes, - ) - .await?; - found_requests.extend(requests); - found_total += total; - if top <= height_end { - height = top; - break; - } - height = height_end; - } - let found_owned = found_requests.len(); - let summary = RequestsSummary { - height, - found_total, - found_owned, - }; - let run_result = RunResult::Requests(summary, found_requests); - Ok(run_result) - } - /// Command: List Licenses async fn list_licenses( blockchain_access_config: &BlockchainAccessConfig, - request_json: RequestJson, + ssk: SecretSpendKey, ) -> Result { let client = RuskHttpClient::new(blockchain_access_config.rusk_address.clone()); @@ -193,9 +153,7 @@ impl Command { let mut licenses_stream = CitadelInquirer::get_licenses(&client, block_range.clone()).await?; - let ssk_user = SecretSpendKey::from_slice( - hex::decode(request_json.user_ssk.clone())?.as_slice(), - )?; + let ssk_user = ssk; let pairs = CitadelInquirer::find_all_licenses(&mut licenses_stream)?; let vk = ssk_user.view_key(); @@ -208,6 +166,7 @@ impl Command { } #[allow(clippy::too_many_arguments)] + #[allow(non_snake_case)] /// Command: Use License async fn use_license( wallet_path: &WalletPath, @@ -215,25 +174,28 @@ impl Command { blockchain_access_config: &BlockchainAccessConfig, gas_limit: u64, gas_price: u64, - request_json: RequestJson, + psk_lp_bytes: String, + ssk: SecretSpendKey, setup_holder: &mut Option, license_hash: String, ) -> Result { let pos_license = Self::get_license_to_use( blockchain_access_config, - Some(&request_json), + ssk, license_hash.clone(), ) .await?; Ok(match pos_license { Some((pos, license)) => { println!("using license: {}", RunResult::to_hash_hex(&license)); - let ssk_user = SecretSpendKey::from_slice( - hex::decode(request_json.user_ssk)?.as_slice(), - )?; - let psk_lp = PublicSpendKey::from_slice( - hex::decode(request_json.provider_psk)?.as_slice(), - )?; + let ssk_user = ssk; + + let psk_lp_bytes: [u8; 64] = hex::decode(&psk_lp_bytes.clone()) + .expect("Decoded.") + .try_into() + .unwrap(); + let psk_lp = PublicSpendKey::from_bytes(&psk_lp_bytes).unwrap(); + let (tx_id, session_cookie) = Self::prove_and_send_use_license( blockchain_access_config, wallet_path, @@ -279,7 +241,7 @@ impl Command { async fn get_license_to_use( blockchain_access_config: &BlockchainAccessConfig, - request_json: Option<&RequestJson>, + ssk: SecretSpendKey, license_hash: String, ) -> Result, Error> { let client = @@ -290,15 +252,7 @@ impl Command { let mut licenses_stream = CitadelInquirer::get_licenses(&client, block_heights).await?; - let ssk_user = SecretSpendKey::from_slice( - hex::decode( - request_json - .expect("request should be provided") - .user_ssk - .clone(), - )? - .as_slice(), - )?; + let ssk_user = ssk; let pairs = CitadelInquirer::find_owned_licenses( ssk_user, diff --git a/moat-cli-user/src/interactor.rs b/moat-cli-user/src/interactor.rs index 15e2b0c..17d61e3 100644 --- a/moat-cli-user/src/interactor.rs +++ b/moat-cli-user/src/interactor.rs @@ -7,9 +7,10 @@ use crate::error::CliError; use crate::prompt; use crate::{Command, Menu}; +use dusk_pki::SecretSpendKey; use dusk_plonk::prelude::{Prover, PublicParameters, Verifier}; use dusk_wallet::WalletPath; -use moat_core::{Error, RequestJson}; +use moat_core::Error; use requestty::{ErrorKind, Question}; use wallet_accessor::{BlockchainAccessConfig, Password}; @@ -22,7 +23,6 @@ enum OpSelection { #[derive(PartialEq, Eq, Hash, Clone, Debug)] enum CommandMenuItem { SubmitRequest, - ListRequestsUser, ListLicenses, UseLicense, RequestService, @@ -33,7 +33,6 @@ enum CommandMenuItem { fn menu_operation() -> Result { let cmd_menu = Menu::new() .add(CommandMenuItem::SubmitRequest, "Submit Request") - .add(CommandMenuItem::ListRequestsUser, "List Requests") .add(CommandMenuItem::ListLicenses, "List Licenses") .add(CommandMenuItem::UseLicense, "Use License") .add( @@ -53,10 +52,9 @@ fn menu_operation() -> Result { let cmd = cmd_menu.answer(&answer).to_owned(); Ok(match cmd { CommandMenuItem::SubmitRequest => { - OpSelection::Run(Box::from(Command::SubmitRequest)) - } - CommandMenuItem::ListRequestsUser => { - OpSelection::Run(Box::from(Command::ListRequestsUser)) + OpSelection::Run(Box::from(Command::SubmitRequest { + psk_lp_bytes: prompt::request_psk_lp_bytes()?, + })) } CommandMenuItem::ListLicenses => { OpSelection::Run(Box::from(Command::ListLicenses)) @@ -64,6 +62,7 @@ fn menu_operation() -> Result { CommandMenuItem::UseLicense => { OpSelection::Run(Box::from(Command::UseLicense { license_hash: prompt::request_license_hash()?, + psk_lp_bytes: prompt::request_psk_lp_bytes()?, })) } CommandMenuItem::RequestService => { @@ -90,7 +89,7 @@ pub struct Interactor { pub blockchain_access_config: BlockchainAccessConfig, pub gas_limit: u64, pub gas_price: u64, - pub request_json: RequestJson, + pub ssk: SecretSpendKey, pub setup_holder: Option, } @@ -108,7 +107,7 @@ impl Interactor { &self.blockchain_access_config, self.gas_limit, self.gas_price, - self.request_json.clone(), + self.ssk, &mut self.setup_holder, ) .await; diff --git a/moat-cli-user/src/main.rs b/moat-cli-user/src/main.rs index 0a73c98..0078f60 100644 --- a/moat-cli-user/src/main.rs +++ b/moat-cli-user/src/main.rs @@ -22,26 +22,24 @@ use clap::Parser; use crate::error::CliError; use crate::interactor::Interactor; -use dusk_wallet::WalletPath; -use moat_core::{JsonLoader, RequestJson}; +use dusk_wallet::{Wallet, WalletPath}; use rand::SeedableRng; use toml_base_config::BaseConfig; -use wallet_accessor::BlockchainAccessConfig; use wallet_accessor::Password::{Pwd, PwdHash}; +use wallet_accessor::{BlockchainAccessConfig, WalletAccessor}; #[tokio::main] +#[allow(non_snake_case)] async fn main() -> Result<(), CliError> { let cli = Args::parse(); - let json_path = cli.json_path.as_path(); let config_path = cli.config_path.as_path(); let wallet_path = cli.wallet_path.as_path(); - let password = cli.password; + let password = cli.wallet_pass; let pwd_hash = cli.pwd_hash; let gas_limit = cli.gas_limit; let gas_price = cli.gas_price; - let request_json: RequestJson = RequestJson::from_file(json_path)?; let wallet_path = WalletPath::from(wallet_path.join("wallet.dat")); let blockchain_access_config = BlockchainAccessConfig::load_path(config_path)?; @@ -51,13 +49,19 @@ async fn main() -> Result<(), CliError> { PwdHash(pwd_hash) }; + let wallet_accessor = + WalletAccessor::create(wallet_path.clone(), psw.clone()).unwrap(); + let wallet = Wallet::from_file(wallet_accessor).unwrap(); + + let (_psk, ssk) = wallet.spending_keys(&wallet.default_address()).unwrap(); + let mut interactor = Interactor { wallet_path, psw, blockchain_access_config, gas_limit, gas_price, - request_json, + ssk, setup_holder: None, }; diff --git a/moat-cli-user/src/prompt.rs b/moat-cli-user/src/prompt.rs index 75a290a..31f0c1f 100644 --- a/moat-cli-user/src/prompt.rs +++ b/moat-cli-user/src/prompt.rs @@ -45,3 +45,23 @@ pub(crate) fn request_license_hash() -> Result { let a_str = a.as_string().expect("answer to be a string").to_string(); Ok(a_str) } + +pub(crate) fn request_psk_lp_bytes() -> Result { + let q = Question::input("psk_lp_bytes") + .message("Please enter the LP public key:".to_string()) + .validate_on_key(|_, _| { + true // todo: add some validation of the license hash + }) + .validate(|psk_lp_bytes, _| { + if psk_lp_bytes.is_empty() { + Err("Please enter a valid LP public key".to_string()) + } else { + Ok(()) + } + }) + .build(); + + let a = requestty::prompt_one(q)?; + let a_str = a.as_string().expect("answer to be a string").to_string(); + Ok(a_str) +} diff --git a/moat-cli-user/src/run_result.rs b/moat-cli-user/src/run_result.rs index 6fab81d..fb44dd8 100644 --- a/moat-cli-user/src/run_result.rs +++ b/moat-cli-user/src/run_result.rs @@ -7,7 +7,7 @@ use rkyv::ser::serializers::AllocSerializer; use std::fmt; use std::ops::Range; -use zk_citadel::license::{License, Request}; +use zk_citadel::license::License; // use rkyv::{check_archived_root, Archive, Deserialize, Infallible, Serialize}; use sha3::{Digest, Sha3_256}; @@ -17,12 +17,6 @@ pub struct SubmitRequestSummary { pub request_hash: String, } -pub struct RequestsSummary { - pub height: u64, - pub found_total: usize, - pub found_owned: usize, -} - pub struct UseLicenseSummary { pub license_blob: Vec, pub tx_id: String, @@ -40,7 +34,6 @@ pub struct LicenseContractSummary { /// Possible results of running a command in interactive mode pub enum RunResult { SubmitRequest(SubmitRequestSummary), - Requests(RequestsSummary, Vec), ListLicenses(Range, Vec<(License, bool)>), UseLicense(Option), ShowState(LicenseContractSummary), @@ -65,17 +58,6 @@ impl fmt::Display for RunResult { writeln!(f, "request submitted: {}", summary.request_hash)?; Ok(()) } - Requests(summary, requests) => { - writeln!( - f, - "scanned {} blocks, found {} requests, {} owned requests:", - summary.height, summary.found_total, summary.found_owned, - )?; - for request in requests.iter() { - writeln!(f, "request: {}", Self::to_hash_hex(request))?; - } - Ok(()) - } ListLicenses(block_range, licenses) => { writeln!( f, diff --git a/moat-cli/config.toml b/moat-cli/config.toml deleted file mode 100644 index a413b04..0000000 --- a/moat-cli/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -rusk_address = "http://127.0.0.1:8080" -prover_address = "http://127.0.0.1:8080" -#rusk_address = "http://devnet.nodes.dusk.network:8585" -#prover_address = "http://devnet.provers.dusk.network:8686" diff --git a/moat-cli/request.json b/moat-cli/request.json deleted file mode 100644 index f678c8b..0000000 --- a/moat-cli/request.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "user_ssk": "c6afd78c8b3902b474d4c0972b62888e4b880dccf8da68e86266fefa45ee7505926f06ab82ac200995f1239d518fdb74903f225f4460d8db62f2449f6d4dc402", - "provider_psk": "136d747ff489bd06077f937508b9237ac093ff868dc2e232ab3af0ecd038873288560dbd8aa851e055bc408ebeb89509b26eb6e34b4b43214de467e3ef09594e" -} diff --git a/moat-cli/request2.json b/moat-cli/request2.json deleted file mode 100644 index bb65dbf..0000000 --- a/moat-cli/request2.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "user_ssk": "45654c72b065e143645ae5877524b96126c222005a8d6a1eca24c99627a45803a48481395dabdbe33cec4f89b36878b3c2f638c9796e34cffac0a02f27c21702", - "provider_psk": "29c4336ef24e585f4506e32e269c5363a71f7dcd74586b210c56e569ad2644e832c785f102dd3c985c705008ec188be819bac85b65c9f70decb9adcf4a72cc43" -} diff --git a/moat-core/Cargo.toml b/moat-core/Cargo.toml index aec3a18..03d0fa7 100644 --- a/moat-core/Cargo.toml +++ b/moat-core/Cargo.toml @@ -9,7 +9,7 @@ tokio-tungstenite = { version = "0.19", default-features = false, features = ["c futures = "0.3" futures-core = "0.3" futures-util = { version = "0.3.28", default-features = false, features = ["sink", "std"] } -dusk-wallet = "0.20.0-rc.0" +dusk-wallet = "0.20.1-rc.0" wallet-accessor = { path = "../wallet-accessor" } zk-citadel = "0.5" dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] } diff --git a/moat-cli/Cargo.toml b/testing-utils/test-moat-cli/Cargo.toml similarity index 74% rename from moat-cli/Cargo.toml rename to testing-utils/test-moat-cli/Cargo.toml index 954c64a..ead93e3 100644 --- a/moat-cli/Cargo.toml +++ b/testing-utils/test-moat-cli/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "moat-cli" +name = "test-moat-cli" version = "0.1.0" edition = "2021" [dependencies] -dusk-wallet = "0.20.0-rc.0" -wallet-accessor = { path = "../wallet-accessor" } -moat-core = { path = "../moat-core" } -license-provider = { path = "../license-provider" } +dusk-wallet = "0.20.1-rc.0" +wallet-accessor = { path = "../../wallet-accessor" } +moat-core = { path = "../../moat-core" } +license-provider = { path = "../../license-provider" } zk-citadel = "0.5" dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] } rkyv = { version = "=0.7.39" } diff --git a/moat-cli/README.md b/testing-utils/test-moat-cli/README.md similarity index 100% rename from moat-cli/README.md rename to testing-utils/test-moat-cli/README.md diff --git a/moat-cli-request/config.toml b/testing-utils/test-moat-cli/config.toml similarity index 100% rename from moat-cli-request/config.toml rename to testing-utils/test-moat-cli/config.toml diff --git a/moat-cli/lp.json b/testing-utils/test-moat-cli/lp.json similarity index 100% rename from moat-cli/lp.json rename to testing-utils/test-moat-cli/lp.json diff --git a/moat-cli/lp2.json b/testing-utils/test-moat-cli/lp2.json similarity index 100% rename from moat-cli/lp2.json rename to testing-utils/test-moat-cli/lp2.json diff --git a/moat-cli-request/request.json b/testing-utils/test-moat-cli/request.json similarity index 100% rename from moat-cli-request/request.json rename to testing-utils/test-moat-cli/request.json diff --git a/moat-cli-user/request2.json b/testing-utils/test-moat-cli/request2.json similarity index 100% rename from moat-cli-user/request2.json rename to testing-utils/test-moat-cli/request2.json diff --git a/moat-cli/src/args.rs b/testing-utils/test-moat-cli/src/args.rs similarity index 100% rename from moat-cli/src/args.rs rename to testing-utils/test-moat-cli/src/args.rs diff --git a/moat-cli/src/command.rs b/testing-utils/test-moat-cli/src/command.rs similarity index 100% rename from moat-cli/src/command.rs rename to testing-utils/test-moat-cli/src/command.rs diff --git a/moat-cli/src/error.rs b/testing-utils/test-moat-cli/src/error.rs similarity index 100% rename from moat-cli/src/error.rs rename to testing-utils/test-moat-cli/src/error.rs diff --git a/moat-cli/src/interactor.rs b/testing-utils/test-moat-cli/src/interactor.rs similarity index 100% rename from moat-cli/src/interactor.rs rename to testing-utils/test-moat-cli/src/interactor.rs diff --git a/moat-cli/src/main.rs b/testing-utils/test-moat-cli/src/main.rs similarity index 100% rename from moat-cli/src/main.rs rename to testing-utils/test-moat-cli/src/main.rs diff --git a/moat-cli/src/menu.rs b/testing-utils/test-moat-cli/src/menu.rs similarity index 100% rename from moat-cli/src/menu.rs rename to testing-utils/test-moat-cli/src/menu.rs diff --git a/moat-cli/src/prompt.rs b/testing-utils/test-moat-cli/src/prompt.rs similarity index 100% rename from moat-cli/src/prompt.rs rename to testing-utils/test-moat-cli/src/prompt.rs diff --git a/moat-cli/src/run_result.rs b/testing-utils/test-moat-cli/src/run_result.rs similarity index 100% rename from moat-cli/src/run_result.rs rename to testing-utils/test-moat-cli/src/run_result.rs diff --git a/moat-cli-request/Cargo.toml b/testing-utils/test-moat-request/Cargo.toml similarity index 63% rename from moat-cli-request/Cargo.toml rename to testing-utils/test-moat-request/Cargo.toml index 9041593..b95546f 100644 --- a/moat-cli-request/Cargo.toml +++ b/testing-utils/test-moat-request/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "moat-cli-request" +name = "test-moat-request" version = "0.1.0" edition = "2021" [dependencies] -dusk-wallet = "0.20.0-rc.0" -wallet-accessor = { path = "../wallet-accessor" } -moat-core = { path = "../moat-core" } +dusk-wallet = "0.20.1-rc.0" +wallet-accessor = { path = "../../wallet-accessor" } +moat-core = { path = "../../moat-core" } toml-base-config = "0.1" clap = { version = "4.0", features = ["derive", "env"] } tokio = { version = "1.21", features = ["full"] } diff --git a/moat-cli-sp/config.toml b/testing-utils/test-moat-request/config.toml similarity index 100% rename from moat-cli-sp/config.toml rename to testing-utils/test-moat-request/config.toml diff --git a/moat-cli-user/request.json b/testing-utils/test-moat-request/request.json similarity index 100% rename from moat-cli-user/request.json rename to testing-utils/test-moat-request/request.json diff --git a/moat-cli-request/src/args.rs b/testing-utils/test-moat-request/src/args.rs similarity index 100% rename from moat-cli-request/src/args.rs rename to testing-utils/test-moat-request/src/args.rs diff --git a/moat-cli-request/src/main.rs b/testing-utils/test-moat-request/src/main.rs similarity index 100% rename from moat-cli-request/src/main.rs rename to testing-utils/test-moat-request/src/main.rs diff --git a/wallet-accessor/Cargo.toml b/wallet-accessor/Cargo.toml index 4367d18..a198722 100644 --- a/wallet-accessor/Cargo.toml +++ b/wallet-accessor/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -dusk-wallet = "0.20.0-rc.0" +dusk-wallet = "0.20.1-rc.0" dusk-wallet-core = "0.22.0-plonk.0.16" phoenix-core = { version = "0.21", features = ["alloc"] } dusk-bls12_381 = "0.12"