-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3997 from WalletConnect/feat/echo
feat: decrypted notifications
- Loading branch information
Showing
18 changed files
with
390 additions
and
8 deletions.
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
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) => { | ||
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.