diff --git a/src/config.rs b/src/config.rs index 91cf5ab..47b42b1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -111,8 +111,6 @@ pub_struct!(Clone, Debug, Deserialize; EvmRecordVerifier { pub_struct!(Clone, Debug, Deserialize; FreeDomains { priv_key: FieldElement, - start_time: i64, - end_time: i64, }); #[derive(Deserialize)] diff --git a/src/ecdsa_sign.rs b/src/ecdsa_sign.rs index 387b249..db5d4f9 100644 --- a/src/ecdsa_sign.rs +++ b/src/ecdsa_sign.rs @@ -6,7 +6,7 @@ use starknet::core::{ }; use starknet_crypto::{rfc6979_generate_k, sign, SignError}; -pub fn ecdsa_sign( +pub fn non_determinist_ecdsa_sign( private_key: &FieldElement, message_hash: &FieldElement, ) -> Result { diff --git a/src/endpoints/campaigns/get_free_domain.rs b/src/endpoints/campaigns/get_free_domain.rs index f1f9726..b0e6203 100644 --- a/src/endpoints/campaigns/get_free_domain.rs +++ b/src/endpoints/campaigns/get_free_domain.rs @@ -1,4 +1,4 @@ -use crate::{ecdsa_sign::ecdsa_sign, models::AppState, utils::get_error}; +use crate::{ecdsa_sign::non_determinist_ecdsa_sign, models::AppState, utils::get_error}; use axum::{ extract::{Query, State}, response::{IntoResponse, Json}, @@ -16,6 +16,7 @@ use std::sync::Arc; pub struct FreeDomainQuery { addr: FieldElement, code: String, + domain: String, } lazy_static::lazy_static! { @@ -32,11 +33,12 @@ pub async fn handler( State(state): State>, Query(query): Query, ) -> impl IntoResponse { - // verify campaign is active - let now = chrono::Utc::now().timestamp(); - if now < state.conf.free_domains.start_time || now > state.conf.free_domains.end_time { - return get_error("Campaign not active".to_string()); + // assert domain is a root domain & get domain length + let domain_parts = query.domain.split('.').collect::>(); + if domain_parts.len() != 2 { + return get_error("Domain must be a root domain".to_string()); } + let domain_len = domain_parts[0].len(); let free_domains = state .starknetid_db @@ -46,7 +48,6 @@ pub async fn handler( doc! { "code" : &query.code, "enabled": true, - "type": "5+letters", }, None, ) @@ -61,9 +62,34 @@ pub async fn handler( return get_error("Error while verifying coupon code availability".to_string()); } + // Check domain length matches the coupon type + if let Ok(coupon_type) = doc.get_str("type") { + if let Some(pos) = coupon_type.find('+') { + if let Ok(domain_min_size) = coupon_type[..pos].parse::() { + if domain_len < domain_min_size { + return get_error(format!( + "Domain length is less than {}", + domain_min_size + )); + } + } else { + return get_error( + "Failed to parse the numeric part of the coupon type".to_string(), + ); + } + } else { + return get_error("Invalid coupon type format".to_string()); + } + } else { + return get_error("Error while verifying coupon code type".to_string()); + } + // generate the signature let message_hash = pedersen_hash(&query.addr, &FREE_DOMAIN_STR); - match ecdsa_sign(&state.conf.free_domains.priv_key.clone(), &message_hash) { + match non_determinist_ecdsa_sign( + &state.conf.free_domains.priv_key.clone(), + &message_hash, + ) { Ok(signature) => { // we blacklist the coupon code match free_domains diff --git a/src/endpoints/crosschain/ethereum/text_records.rs b/src/endpoints/crosschain/ethereum/text_records.rs index 13e10f8..e3d6bc8 100644 --- a/src/endpoints/crosschain/ethereum/text_records.rs +++ b/src/endpoints/crosschain/ethereum/text_records.rs @@ -125,7 +125,8 @@ pub async fn get_verifier_data( id: FieldElement, record_config: &EvmRecordVerifier, ) -> Option { - let mut calls: Vec = vec![FieldElement::from(record_config.verifier_contracts.len())]; + let mut calls: Vec = + vec![FieldElement::from(record_config.verifier_contracts.len())]; for verifier in &record_config.verifier_contracts { calls.push(config.contracts.starknetid); calls.push(selector!("get_verifier_data")); @@ -160,7 +161,6 @@ pub async fn get_verifier_data( None } } - } Err(err) => { println!("Error while fetching balances: {:?}", err);