Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: continue refactor tests #249

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use {
registry::storage::redis::Redis,
services::websocket_server::{
decode_key, derive_key, handlers::decrypt_message, NotifyRequest, NotifyResponse,
NotifyWatchSubscriptions,
NotifySubscriptionsChanged, NotifyWatchSubscriptions,
},
spec::{
NOTIFY_SUBSCRIPTIONS_CHANGED_METHOD, NOTIFY_SUBSCRIPTIONS_CHANGED_TAG,
Expand Down Expand Up @@ -293,8 +293,10 @@ pub async fn update_subscription_watchers(
let auth = sign_jwt(response_message, authentication_secret)?;
let request = NotifyRequest::new(
NOTIFY_SUBSCRIPTIONS_CHANGED_METHOD,
json!({ "subscriptionsChangedAuth": auth }),
); // TODO use structure
NotifySubscriptionsChanged {
subscriptions_changed_auth: auth,
},
);

let sym_key = decode_key(sym_key)?;
let envelope = Envelope::<EnvelopeType0>::new(&sym_key, request)?;
Expand Down
10 changes: 8 additions & 2 deletions src/services/websocket_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,14 @@ pub struct NotifyWatchSubscriptions {

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct NotifySubscribe {
subscription_auth: String,
pub struct NotifySubscriptionsChanged {
pub subscriptions_changed_auth: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct NotifySubscribe {
pub subscription_auth: String,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
6 changes: 6 additions & 0 deletions src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub const NOTIFY_UPDATE_RESPONSE_TAG: u32 = 4009;
pub const NOTIFY_WATCH_SUBSCRIPTIONS_TAG: u32 = 4010;
pub const NOTIFY_WATCH_SUBSCRIPTIONS_RESPONSE_TAG: u32 = 4011;
pub const NOTIFY_SUBSCRIPTIONS_CHANGED_TAG: u32 = 4012;
pub const NOTIFY_SUBSCRIPTIONS_CHANGED_RESPONSE_TAG: u32 = 4013;
pub const NOTIFY_NOOP_TAG: u32 = 4050;

// TTLs
Expand All @@ -38,11 +39,16 @@ pub const NOTIFY_UPDATE_RESPONSE_TTL: Duration = T2592000;
pub const NOTIFY_WATCH_SUBSCRIPTIONS_TTL: Duration = T300;
pub const NOTIFY_WATCH_SUBSCRIPTIONS_RESPONSE_TTL: Duration = T300;
pub const NOTIFY_SUBSCRIPTIONS_CHANGED_TTL: Duration = T300;
pub const NOTIFY_SUBSCRIPTIONS_CHANGED_RESPONSE_TTL: Duration = T300;

// acts
// https://specs.walletconnect.com/2.0/specs/clients/notify/notify-authentication
pub const NOTIFY_WATCH_SUBSCRIPTIONS_ACT: &str = "notify_watch_subscriptions";
pub const NOTIFY_WATCH_SUBSCRIPTIONS_RESPONSE_ACT: &str = "notify_watch_subscriptions_response";
pub const NOTIFY_SUBSCRIPTIONS_CHANGED_ACT: &str = "notify_subscriptions_changed";
pub const NOTIFY_SUBSCRIPTIONS_CHANGED_RESPONE_ACT: &str = "notify_subscriptions_changed_response";
pub const NOTIFY_SUBSCRIBE_ACT: &str = "notify_subscription";
pub const NOTIFY_SUBSCRIBE_RESPONSE_ACT: &str = "notify_subscription_response";

#[cfg(test)]
mod tests {
Expand Down
6 changes: 5 additions & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ impl Envelope<EnvelopeType0> {
}

impl Envelope<EnvelopeType1> {
pub fn new(encryption_key: &[u8; 32], data: impl Serialize, pubkey: [u8; 32]) -> Result<Self> {
pub fn new(
encryption_key: &[u8; 32],
data: serde_json::Value,
pubkey: [u8; 32],
) -> Result<Self> {
let serialized = serde_json::to_vec(&data)?;
let iv = generate_nonce();

Expand Down
11 changes: 7 additions & 4 deletions tests/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,13 @@ async fn watch_subscriptions(
let response_topic_key =
derive_key(&x25519_dalek::PublicKey::from(key_agreement_key), &secret).unwrap();
let response_topic = sha256::digest(&response_topic_key);
println!("watch_subscriptions response_topic: {response_topic}");

let envelope =
Envelope::<EnvelopeType1>::new(&response_topic_key, message, *public.as_bytes()).unwrap();
let envelope = Envelope::<EnvelopeType1>::new(
&response_topic_key,
serde_json::to_value(message).unwrap(),
*public.as_bytes(),
)
.unwrap();
let message = base64::engine::general_purpose::STANDARD.encode(envelope.to_bytes());

let watch_subscriptions_topic = sha256::digest(&key_agreement_key);
Expand Down Expand Up @@ -514,7 +517,7 @@ async fn run_test(statement: String, watch_subscriptions_all_domains: bool) {

let envelope: Envelope<EnvelopeType1> = Envelope::<EnvelopeType1>::new(
&response_topic_key,
message,
serde_json::to_value(message).unwrap(),
*subscription_public.as_bytes(),
)
.unwrap();
Expand Down
Loading