Feature/expose validator cosmos address (#1404)

* Move coconut validator api req out of coconut interface

and expose a new cosmos-address endpoint

* Finish cosmos address endpoint

* Guard under coconut feature gateway & validator-api code

* Update CHANGELOG
This commit is contained in:
Bogdan-Ștefan Neacşu
2022-06-24 18:36:13 +03:00
committed by GitHub
parent fe9cb8a4e6
commit 0df801ab4e
20 changed files with 270 additions and 190 deletions
+2 -1
View File
@@ -3,10 +3,11 @@
use crate::coconut::error::Result;
use multisig_contract_common::msg::ProposalResponse;
use validator_client::nymd::{Fee, TxResponse};
use validator_client::nymd::{AccountId, Fee, TxResponse};
#[async_trait]
pub trait Client {
async fn address(&self) -> AccountId;
async fn get_tx(&self, tx_hash: &str) -> Result<TxResponse>;
async fn get_proposal(&self, proposal_id: u64) -> Result<ProposalResponse>;
async fn propose_release_funds(
+1 -1
View File
@@ -5,10 +5,10 @@ use coconut_bandwidth_contract_common::events::{
DEPOSITED_FUNDS_EVENT_TYPE, DEPOSIT_ENCRYPTION_KEY, DEPOSIT_IDENTITY_KEY, DEPOSIT_INFO,
DEPOSIT_VALUE,
};
use coconut_interface::BlindSignRequestBody;
use credentials::coconut::bandwidth::BandwidthVoucher;
use crypto::asymmetric::encryption;
use crypto::asymmetric::identity::{self, Signature};
use validator_api_requests::coconut::BlindSignRequestBody;
use validator_client::nymd::TxResponse;
use super::error::{CoconutError, Result};
+14 -4
View File
@@ -13,10 +13,7 @@ use crate::coconut::error::{CoconutError, Result};
use crate::ValidatorApiStorage;
use coconut_interface::{
Attribute, BlindSignRequest, BlindSignRequestBody, BlindedSignature, BlindedSignatureResponse,
ExecuteReleaseFundsRequestBody, KeyPair, Parameters, ProposeReleaseFundsRequestBody,
ProposeReleaseFundsResponse, VerificationKey, VerificationKeyResponse, VerifyCredentialBody,
VerifyCredentialResponse,
Attribute, BlindSignRequest, BlindedSignature, KeyPair, Parameters, VerificationKey,
};
use config::defaults::VALIDATOR_API_VERSION;
use credentials::coconut::params::{
@@ -26,6 +23,11 @@ use credentials::obtain_aggregate_verification_key;
use crypto::asymmetric::encryption;
use crypto::shared_key::new_ephemeral_shared_key;
use crypto::symmetric::stream_cipher;
use validator_api_requests::coconut::{
BlindSignRequestBody, BlindedSignatureResponse, CosmosAddressResponse,
ExecuteReleaseFundsRequestBody, ProposeReleaseFundsRequestBody, ProposeReleaseFundsResponse,
VerificationKeyResponse, VerifyCredentialBody, VerifyCredentialResponse,
};
use validator_client::validator_api::routes::{BANDWIDTH, COCONUT_ROUTES};
use getset::{CopyGetters, Getters};
@@ -170,6 +172,7 @@ impl InternalSignRequest {
routes![
post_blind_sign,
get_verification_key,
get_cosmos_address,
post_partial_bandwidth_credential,
verify_bandwidth_credential,
post_propose_release_funds,
@@ -248,6 +251,13 @@ pub async fn get_verification_key(
)))
}
#[get("/cosmos-address")]
pub async fn get_cosmos_address(state: &RocketState<State>) -> Result<Json<CosmosAddressResponse>> {
Ok(Json(CosmosAddressResponse::new(
state.client.address().await,
)))
}
#[post("/verify-bandwidth-credential", data = "<verify_credential_body>")]
pub async fn verify_bandwidth_credential(
verify_credential_body: Json<VerifyCredentialBody>,
+8 -2
View File
@@ -7,7 +7,6 @@ use coconut_bandwidth_contract_common::events::{
DEPOSITED_FUNDS_EVENT_TYPE, DEPOSIT_ENCRYPTION_KEY, DEPOSIT_IDENTITY_KEY, DEPOSIT_INFO,
DEPOSIT_VALUE,
};
use coconut_interface::{BlindSignRequestBody, BlindedSignatureResponse, VerificationKeyResponse};
use config::defaults::VOUCHER_INFO;
use credentials::coconut::bandwidth::BandwidthVoucher;
use credentials::coconut::params::{
@@ -19,7 +18,10 @@ use multisig_contract_common::msg::ProposalResponse;
use nymcoconut::{
prepare_blind_sign, ttp_keygen, Base58, BlindSignRequest, BlindedSignature, KeyPair, Parameters,
};
use validator_client::nymd::{tx::Hash, DeliverTx, Event, Fee, Tag, TxResponse};
use validator_api_requests::coconut::{
BlindSignRequestBody, BlindedSignatureResponse, VerificationKeyResponse,
};
use validator_client::nymd::{tx::Hash, AccountId, DeliverTx, Event, Fee, Tag, TxResponse};
use validator_client::validator_api::routes::{
API_VERSION, BANDWIDTH, COCONUT_BLIND_SIGN, COCONUT_PARTIAL_BANDWIDTH_CREDENTIAL,
COCONUT_ROUTES, COCONUT_VERIFICATION_KEY,
@@ -49,6 +51,10 @@ impl DummyClient {
#[async_trait]
impl super::client::Client for DummyClient {
async fn address(&self) -> AccountId {
todo!()
}
async fn get_tx(&self, tx_hash: &str) -> Result<TxResponse> {
self.db
.read()
+5
View File
@@ -22,6 +22,7 @@ use multisig_contract_common::msg::ProposalResponse;
use validator_client::nymd::{
cosmwasm_client::logs::find_attribute,
traits::{MultisigSigningClient, QueryClient},
AccountId,
};
use validator_client::nymd::{
hash::{Hash, SHA256_HASH_SIZE},
@@ -431,6 +432,10 @@ impl<C> crate::coconut::client::Client for Client<C>
where
C: SigningCosmWasmClient + Sync + Send,
{
async fn address(&self) -> AccountId {
self.0.read().await.nymd.address().clone()
}
async fn get_tx(
&self,
tx_hash: &str,