diff --git a/affinidi-did-resolver-cache-sdk/src/networking/mod.rs b/affinidi-did-resolver-cache-sdk/src/networking/mod.rs index 99976a8..72a7d53 100644 --- a/affinidi-did-resolver-cache-sdk/src/networking/mod.rs +++ b/affinidi-did-resolver-cache-sdk/src/networking/mod.rs @@ -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 @@ -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!( diff --git a/affinidi-did-resolver-cache-sdk/src/networking/network.rs b/affinidi-did-resolver-cache-sdk/src/networking/network.rs index 58a32f8..e41a69f 100644 --- a/affinidi-did-resolver-cache-sdk/src/networking/network.rs +++ b/affinidi-did-resolver-cache-sdk/src/networking/network.rs @@ -9,6 +9,7 @@ use std::time::Duration; use crate::{config::ClientConfig, errors::DIDCacheError, WSRequest}; +use blake2::{Blake2s256, Digest}; use futures_util::{SinkExt, StreamExt}; use ssi::dids::Document; use tokio::{ @@ -101,7 +102,10 @@ impl NetworkTask { if let Some(cmd) = value { match cmd { WSCommands::Send(channel, uid, request) => { - if network_task.cache.insert(request.hash.clone(), &uid, channel) { + let mut hasher = Blake2s256::new(); + hasher.update(request.did.clone()); + let did_hash = format!("{:x}", hasher.finalize()); + if network_task.cache.insert(did_hash, &uid, channel) { let _ = network_task.ws_send(&mut websocket, &request).await; } } diff --git a/affinidi-did-resolver-cache-server/src/handlers/websocket.rs b/affinidi-did-resolver-cache-server/src/handlers/websocket.rs index a90198b..42bb750 100644 --- a/affinidi-did-resolver-cache-server/src/handlers/websocket.rs +++ b/affinidi-did-resolver-cache-server/src/handlers/websocket.rs @@ -8,6 +8,7 @@ use axum::{ }, response::IntoResponse, }; +use blake2::{Blake2s256, Digest}; use tokio::select; use tracing::{debug, info, span, warn, Instrument}; @@ -82,9 +83,12 @@ async fn handle_socket(mut socket: WebSocket, state: SharedData) { } Err(e) => { // Couldn't resolve the DID, send an error back + let mut hasher = Blake2s256::new(); + hasher.update(request.did.clone()); + let did_hash = format!("{:x}", hasher.finalize()); 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; }