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: decrypted notifications #3997

Merged
merged 14 commits into from
Dec 19, 2023
Merged

feat: decrypted notifications #3997

merged 14 commits into from
Dec 19, 2023

Conversation

ganchoradkov
Copy link
Member

@ganchoradkov ganchoradkov commented Nov 29, 2023

Description

This includes

  • new Echo controller in Core that allows devices to be registered with Echo server
  • new static property in Web3Wallet called notifications that allows for decrypting push payloads & getting the peer's metadata without initializing the whole client

Usage

  • Registering device
    core.echo.registerDeviceToken(params) or shorthand web3wallet.registerDeviceToken(params)

  • Decrypting notification payload

 // handling firebase remote notificaiton
  messaging().setBackgroundMessageHandler(async notification => {
    const { topic, message } = notification.data;
    // decrypt the payload
    const decrypted = await Web3Wallet.notifications.decryptMessage({ topic, encryptedMessage: message })
    // get metadata (name, description, icons, etc) of the sender
    const metadata = await Web3Wallet.notifications.getMetadata({ topic })
    
    // emit local notification
    ...
  });

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Draft PR (breaking/non-breaking change which needs more work for having a proper functionality [Mark this PR as ready to review only when completely ready])
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

tests
dogfooding

Checklist

  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Additional Information (Optional)

specs WalletConnect/walletconnect-specs#147

@arein arein added the accepted label Nov 29, 2023
@ganchoradkov ganchoradkov marked this pull request as ready for review December 1, 2023 14:06
Copy link
Contributor

@devceline devceline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - left questions and nits. All non blocking

packages/core/src/controllers/echo.ts Outdated Show resolved Hide resolved
import { IEcho } from "@walletconnect/types";
import { ECHO_CONTEXT, ECHO_URL } from "../constants";

export class Echo extends IEcho {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Why did we make an entire class for this? Couldn't we have just had a function defined somewhere to register the token? I feel like it's just extra complexity and more state to store needlessly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is to have dedicated handling allowing functionality to be reused and expanded as needed in the future

@@ -98,6 +98,11 @@ export class Engine extends IWeb3WalletEngine {
return this.authClient.formatMessage(params, iss);
};

// Push //
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Push //
// ---------- Push -------------------------------------------------- //

@@ -77,6 +78,7 @@ export class Core extends ICore {
});
this.pairing = new Pairing(this, this.logger);
this.verify = new Verify(this.projectId || "", this.logger);
this.echo = new Echo(this.projectId || "", this.logger);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we putting this in core? Sign/Auth/Chat won't make a use of this, no?


const echoUrl = `${ECHO_URL}/${this.projectId}/clients`;

await fetch(echoUrl, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to use isomorphic-unfetch or something here? Or is it already polyfilled

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually kind of surprised this hasn't come up before here where there's already a fetch call: https://github.com/WalletConnect/walletconnect-monorepo/blob/v2.0/packages/core/src/controllers/verify.ts#L103

Is the Verify controller called only in browsers?

Copy link
Member

@bkrem bkrem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 🔥


const echoUrl = `${ECHO_URL}/${this.projectId}/clients`;

await fetch(echoUrl, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually kind of surprised this hasn't come up before here where there's already a fetch call: https://github.com/WalletConnect/walletconnect-monorepo/blob/v2.0/packages/core/src/controllers/verify.ts#L103

Is the Verify controller called only in browsers?

packages/sign-client/src/index.ts Outdated Show resolved Hide resolved
packages/web3wallet/src/types/client.ts Show resolved Hide resolved

export const Notifications: Web3WalletTypes.INotifications = {
decryptMessage: async (params) => {
const core = new Core({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit concerned regarding memory and creating a new Core reference on every decryptMessage call. Is there any way to avoid this and init the Core once? Guessing this may have to be stateless right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have a way around this because our modules are not stateless/pure - crypto depends on core and having a store AFAIK

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 💯 I will thinker a solution as we do need to reinitialize to update the data

@ganchoradkov ganchoradkov merged commit 51c3a97 into v2.0 Dec 19, 2023
9 checks passed
@ganchoradkov ganchoradkov deleted the feat/echo branch December 19, 2023 09:49
@ganchoradkov ganchoradkov mentioned this pull request Dec 21, 2023
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants