Skip to content

Commit

Permalink
remove hash did from ws request interface
Browse files Browse the repository at this point in the history
  • Loading branch information
YoussefAWasfy committed Sep 27, 2024
1 parent ef9ecbf commit ca6ab07
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 1 addition & 3 deletions affinidi-did-resolver-cache-sdk/src/networking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ mod request_queue;

/// WSRequest is the request format to the websocket connection
/// did: DID to resolve
/// hash: SHA256 Hash of the DID
#[derive(Debug, Deserialize, Serialize)]
pub struct WSRequest {
pub did: String,
pub hash: String,
}

/// WSResponse is the response format from the websocket connection
Expand Down Expand Up @@ -85,7 +83,7 @@ impl DIDCacheClient {

// 1. Send the request to the network task, which will then send via websocket to the remote server
network_task_tx
.send(WSCommands::Send(tx, unique_id.clone(), WSRequest { did: did.into(), hash: did_hash.into() }))
.send(WSCommands::Send(tx, unique_id.clone(), WSRequest { did: did.into() }))
.await
.map_err(|e| {
DIDCacheError::TransportError(format!(
Expand Down
4 changes: 2 additions & 2 deletions affinidi-did-resolver-cache-sdk/src/networking/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::time::Duration;

use crate::{config::ClientConfig, errors::DIDCacheError, WSRequest};
use futures_util::{SinkExt, StreamExt};
use ssi::dids::Document;
use ssi::{crypto::hashes::sha256, dids::Document};
use tokio::{
net::TcpStream,
select,
Expand Down Expand Up @@ -101,7 +101,7 @@ impl NetworkTask {
if let Some(cmd) = value {
match cmd {
WSCommands::Send(channel, uid, request) => {
if network_task.cache.insert(request.hash.clone(), &uid, channel) {
if network_task.cache.insert(String::from_utf8(sha256::sha256(request.did.as_bytes()).to_vec()).unwrap(), &uid, channel) {
let _ = network_task.ws_send(&mut websocket, &request).await;
}
}
Expand Down
4 changes: 3 additions & 1 deletion affinidi-did-resolver-cache-server/src/handlers/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use axum::{
},
response::IntoResponse,
};
use ssi::crypto::hashes::sha256;
use tokio::select;
use tracing::{debug, info, span, warn, Instrument};

Expand Down Expand Up @@ -82,9 +83,10 @@ async fn handle_socket(mut socket: WebSocket, state: SharedData) {
}
Err(e) => {
// Couldn't resolve the DID, send an error back
let did_hash = String::from_utf8(sha256::sha256(request.did.as_bytes()).to_vec()).unwrap();
warn!("Couldn't resolve DID: ({}) Reason: {}", &request.did, e);
state.stats().await.increment_resolver_error();
if let Err(e) = socket.send(Message::Text(serde_json::to_string(&WSResponseType::Error(WSResponseError {did: request.did, hash: request.hash, error: e.to_string()})).unwrap())).await {
if let Err(e) = socket.send(Message::Text(serde_json::to_string(&WSResponseType::Error(WSResponseError {did: request.did, hash: did_hash, error: e.to_string()})).unwrap())).await {
warn!("ws: Error sending error response: {:?}", e);
break;
}
Expand Down

0 comments on commit ca6ab07

Please sign in to comment.