From 62663d6d12fad84261c545de277de5372ca5eadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 7 Feb 2024 17:31:30 +0000 Subject: [PATCH] removed nym-api placeholders --- nym-api/nym-api-requests/src/coconut/models.rs | 2 +- nym-api/src/coconut/api_routes/mod.rs | 10 ++++++++-- nym-api/src/coconut/error.rs | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nym-api/nym-api-requests/src/coconut/models.rs b/nym-api/nym-api-requests/src/coconut/models.rs index ce58d8a05e..c4de811281 100644 --- a/nym-api/nym-api-requests/src/coconut/models.rs +++ b/nym-api/nym-api-requests/src/coconut/models.rs @@ -5,7 +5,7 @@ use crate::coconut::helpers::issued_credential_plaintext; use cosmrs::AccountId; use nym_credentials_interface::{ hash_to_scalar, Attribute, BlindSignRequest, BlindedSignature, Bytable, CoconutError, - CredentialSpendingData, Signature, VerificationKey, + CredentialSpendingData, VerificationKey, }; use nym_crypto::asymmetric::identity; use serde::{Deserialize, Serialize}; diff --git a/nym-api/src/coconut/api_routes/mod.rs b/nym-api/src/coconut/api_routes/mod.rs index 8a276d5e2d..b2b2dfc4bc 100644 --- a/nym-api/src/coconut/api_routes/mod.rs +++ b/nym-api/src/coconut/api_routes/mod.rs @@ -100,9 +100,15 @@ pub async fn verify_bandwidth_credential( let theta = &credential_data.verify_credential_request; let voucher_value: u64 = if credential_data.typ.is_voucher() { - todo!() + credential_data + .get_bandwidth_attribute() + .ok_or(CoconutError::MissingBandwidthValue)? + .parse() + .map_err(|source| CoconutError::VoucherValueParsingFailure { source })? } else { - todo!("return error here") + return Err(CoconutError::NotABandwidthVoucher { + typ: credential_data.typ, + }); }; // TODO: introduce a check to make sure we haven't already voted for this proposal to prevent DDOS diff --git a/nym-api/src/coconut/error.rs b/nym-api/src/coconut/error.rs index 4f464ef175..ec43b0d65d 100644 --- a/nym-api/src/coconut/error.rs +++ b/nym-api/src/coconut/error.rs @@ -3,6 +3,7 @@ use crate::node_status_api::models::NymApiStorageError; use nym_coconut_dkg_common::types::{ChunkIndex, DealingIndex, EpochId}; +use nym_credentials::coconut::bandwidth::CredentialType; use nym_crypto::asymmetric::{ encryption::KeyRecoveryError, identity::{Ed25519RecoveryError, SignatureError}, @@ -14,6 +15,7 @@ use rocket::http::{ContentType, Status}; use rocket::response::Responder; use rocket::{response, Request, Response}; use std::io::Cursor; +use std::num::ParseIntError; use thiserror::Error; pub type Result = std::result::Result; @@ -23,6 +25,20 @@ pub enum CoconutError { #[error(transparent)] IOError(#[from] std::io::Error), + #[error("the received bandwidth voucher did not contain deposit value")] + MissingBandwidthValue, + + #[error( + "the received bandwidth credential is not a bandwidth voucher. the encoded type is: {typ}" + )] + NotABandwidthVoucher { typ: CredentialType }, + + #[error("failed to parse the bandwidth voucher value: {source}")] + VoucherValueParsingFailure { + #[source] + source: ParseIntError, + }, + #[error("coconut api query failure: {0}")] CoconutApiError(#[from] CoconutApiError),