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

feat: add appAuthenticationKey to NotifyWatchSubscription #151

Merged
merged 1 commit into from
Oct 27, 2023
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
4 changes: 3 additions & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ pub struct WatchSubscriptionsResponseAuth {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NotifyServerSubscription {
/// dApp url that the subscription refers to
/// App domain that the subscription refers to
pub app_domain: String,
/// Authentication key used for authenticating topic JWTs and setting JWT aud field
pub app_authentication_key: String,
/// Symetric key used for notify topic. sha256 to get notify topic to manage
/// the subscription and call wc_notifySubscriptionUpdate and
/// wc_notifySubscriptionDelete
Expand Down
12 changes: 7 additions & 5 deletions src/model/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,10 @@ pub async fn get_subscribers_for_project_in(

#[derive(FromRow)]
pub struct SubscriberWithProject {
/// dApp url that the subscription refers to
/// App domain that the subscription refers to
pub app_domain: String,
/// Authentication key used for authenticating topic JWTs and setting JWT aud field
pub authentication_public_key: String,
/// CAIP-10 account
#[sqlx(try_from = "String")]
pub account: AccountId, // TODO do we need to return this?
Expand All @@ -376,12 +378,12 @@ pub async fn get_subscriptions_by_account(
postgres: &PgPool,
) -> Result<Vec<SubscriberWithProject>, sqlx::error::Error> {
let query: &str = "
SELECT app_domain, account, sym_key, array_agg(subscriber_scope.name) as scope, expiry
SELECT app_domain, project.authentication_public_key, account, sym_key, array_agg(subscriber_scope.name) as scope, expiry
FROM subscriber
JOIN project ON project.id=subscriber.project
JOIN subscriber_scope ON subscriber_scope.subscriber=subscriber.id
WHERE account=$1
GROUP BY app_domain, account, sym_key, expiry
GROUP BY app_domain, project.authentication_public_key, account, sym_key, expiry
";
sqlx::query_as::<Postgres, SubscriberWithProject>(query)
.bind(account.as_ref())
Expand All @@ -397,12 +399,12 @@ pub async fn get_subscriptions_by_account_and_app(
postgres: &PgPool,
) -> Result<Vec<SubscriberWithProject>, sqlx::error::Error> {
let query: &str = "
SELECT app_domain, sym_key, account, array_agg(subscriber_scope.name) as scope, expiry
SELECT app_domain, project.authentication_public_key, sym_key, account, array_agg(subscriber_scope.name) as scope, expiry
FROM subscriber
JOIN project ON project.id=subscriber.project
JOIN subscriber_scope ON subscriber_scope.subscriber=subscriber.id
WHERE account=$1 AND project.app_domain=$2
GROUP BY app_domain, sym_key, account, expiry
GROUP BY app_domain, project.authentication_public_key, sym_key, account, expiry
";
sqlx::query_as::<Postgres, SubscriberWithProject>(query)
.bind(account.as_ref())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub async fn collect_subscriptions(
.into_iter()
.map(|sub| NotifyServerSubscription {
app_domain: sub.app_domain,
app_authentication_key: sub.authentication_public_key,
sym_key: sub.sym_key,
account: sub.account,
scope: sub.scope.into_iter().collect(),
Expand Down