-
Notifications
You must be signed in to change notification settings - Fork 735
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
19598a8
feat: implements `registerDeviceToken` in `Echo`
5b78ef9
feat: export session store from sign
2e6a0a2
feat: implements static `decrypt notifications` & `getMetadata` utils
3f9b900
feat: tests
cab479a
chore: rm unused import
b230e71
chore: merge v2.0
269c09c
chore: remove logs
9e086ab
refactor: types
2b9483a
refactor: renames `echo` to `echoClient`
7391142
fix: polyfill `fetch`
1dcfece
Revert "fix: polyfill `fetch`"
195a003
fix: uses `[email protected]`
74e8658
refactor: restructure exports
1f03e09
feat: clear class instances after work done
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const ECHO_CONTEXT = "echo"; | ||
|
||
export const ECHO_URL = "https://echo.walletconnect.com"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { generateChildLogger, Logger } from "@walletconnect/logger"; | ||
import { IEchoClient } from "@walletconnect/types"; | ||
import { ECHO_CONTEXT, ECHO_URL } from "../constants"; | ||
import fetch from "isomorphic-unfetch"; | ||
|
||
export class EchoClient extends IEchoClient { | ||
public readonly context = ECHO_CONTEXT; | ||
constructor(public projectId: string, public logger: Logger) { | ||
super(projectId, logger); | ||
this.logger = generateChildLogger(logger, this.context); | ||
} | ||
|
||
public registerDeviceToken: IEchoClient["registerDeviceToken"] = async (params) => { | ||
const { clientId, token, notificationType, enableEncrypted = false } = params; | ||
|
||
const echoUrl = `${ECHO_URL}/${this.projectId}/clients`; | ||
|
||
await fetch(echoUrl, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
client_id: clientId, | ||
type: notificationType, | ||
token, | ||
always_raw: enableEncrypted, | ||
}), | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { SignClient as Client } from "./client"; | ||
|
||
import { Session } from "./controllers/session"; | ||
export * from "./constants"; | ||
|
||
export const SessionStore = Session; | ||
export const SignClient = Client; | ||
export default Client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Logger } from "@walletconnect/logger"; | ||
|
||
export declare namespace EchoClientTypes { | ||
type RegisterDeviceTokenParams = { | ||
clientId: string; | ||
token: string; | ||
notificationType: "fcm" | "apns" | "apns-sandbox" | "noop"; | ||
enableEncrypted?: boolean; | ||
}; | ||
} | ||
export abstract class IEchoClient { | ||
public abstract readonly context: string; | ||
constructor(public projectId: string, public logger: Logger) {} | ||
|
||
public abstract registerDeviceToken( | ||
params: EchoClientTypes.RegisterDeviceTokenParams, | ||
): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -98,6 +98,11 @@ export class Engine extends IWeb3WalletEngine { | |||||
return this.authClient.formatMessage(params, iss); | ||||||
}; | ||||||
|
||||||
// Push // | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
public registerDeviceToken: IWeb3WalletEngine["registerDeviceToken"] = (params) => { | ||||||
return this.client.core.echoClient.registerDeviceToken(params); | ||||||
}; | ||||||
|
||||||
// ---------- Private ----------------------------------------------- // | ||||||
|
||||||
private onSessionRequest = (event: Web3WalletTypes.SessionRequest) => { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./notifications"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Core } from "@walletconnect/core"; | ||
import { Web3WalletTypes } from "../types"; | ||
import { SessionStore } from "@walletconnect/sign-client"; | ||
|
||
export const Notifications: Web3WalletTypes.INotifications = { | ||
decryptMessage: async (params) => { | ||
const instance = { | ||
core: new Core({ | ||
storageOptions: params.storageOptions, | ||
storage: params.storage, | ||
}), | ||
} as any; | ||
await instance.core.crypto.init(); | ||
const decoded = instance.core.crypto.decode(params.topic, params.encryptedMessage); | ||
instance.core = null; | ||
return decoded; | ||
}, | ||
getMetadata: async (params) => { | ||
ganchoradkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const instances = { | ||
core: new Core({ | ||
storageOptions: params.storageOptions, | ||
storage: params.storage, | ||
}), | ||
sessionStore: null, | ||
} as any; | ||
instances.sessionStore = new SessionStore(instances.core, instances.core.logger); | ||
await instances.sessionStore.init(); | ||
const session = instances.sessionStore.get(params.topic); | ||
const metadata = session?.peer.metadata; | ||
instances.core = null; | ||
instances.sessionStore = null; | ||
return metadata; | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 polyfilledThere was a problem hiding this comment.
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#L103Is the
Verify
controller called only in browsers?