diff --git a/affinidi-did-resolver-cache-sdk/src/networking/network.rs b/affinidi-did-resolver-cache-sdk/src/networking/network.rs index 3d62526..e41a69f 100644 --- a/affinidi-did-resolver-cache-sdk/src/networking/network.rs +++ b/affinidi-did-resolver-cache-sdk/src/networking/network.rs @@ -9,8 +9,9 @@ use std::time::Duration; use crate::{config::ClientConfig, errors::DIDCacheError, WSRequest}; +use blake2::{Blake2s256, Digest}; use futures_util::{SinkExt, StreamExt}; -use ssi::{crypto::hashes::sha256, dids::Document}; +use ssi::dids::Document; use tokio::{ net::TcpStream, select, @@ -101,7 +102,10 @@ impl NetworkTask { if let Some(cmd) = value { match cmd { WSCommands::Send(channel, uid, request) => { - if network_task.cache.insert(String::from_utf8(sha256::sha256(request.did.as_bytes()).to_vec()).unwrap(), &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 899a47b..42bb750 100644 --- a/affinidi-did-resolver-cache-server/src/handlers/websocket.rs +++ b/affinidi-did-resolver-cache-server/src/handlers/websocket.rs @@ -8,7 +8,7 @@ use axum::{ }, response::IntoResponse, }; -use ssi::crypto::hashes::sha256; +use blake2::{Blake2s256, Digest}; use tokio::select; use tracing::{debug, info, span, warn, Instrument}; @@ -83,7 +83,9 @@ 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(); + 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: did_hash, error: e.to_string()})).unwrap())).await {