-
-
Notifications
You must be signed in to change notification settings - Fork 650
Combine QrCodeEvent, SasEvent and VerificationEvent
#3386
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
Changes from all commits
ba16c4e
7de5c6f
32c7ef6
7068fc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| Copyright 2023 The Matrix.org Foundation C.I.C. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import { MatrixEvent } from "../models/event"; | ||
|
|
||
| /** Events emitted by `Verifier`. */ | ||
| export enum VerifierEvent { | ||
| /** | ||
| * The verification has been cancelled, by us or the other side. | ||
| * | ||
| * The payload is either an {@link Error}, or an (incoming or outgoing) {@link MatrixEvent}, depending on | ||
| * unspecified reasons. | ||
| */ | ||
| Cancel = "cancel", | ||
|
|
||
| /** | ||
| * SAS data has been exchanged and should be displayed to the user. | ||
| * | ||
| * The payload is the {@link ShowQrCodeCallbacks} object. | ||
| */ | ||
| ShowSas = "show_sas", | ||
|
|
||
| /** | ||
| * QR code data should be displayed to the user. | ||
| * | ||
| * The payload is the {@link ShowQrCodeCallbacks} object. | ||
| */ | ||
| ShowReciprocateQr = "show_reciprocate_qr", | ||
| } | ||
|
|
||
| /** Listener type map for {@link VerifierEvent}s. */ | ||
| export type VerifierEventHandlerMap = { | ||
| [VerifierEvent.Cancel]: (e: Error | MatrixEvent) => void; | ||
| [VerifierEvent.ShowSas]: (sas: ShowSasCallbacks) => void; | ||
| [VerifierEvent.ShowReciprocateQr]: (qr: ShowQrCodeCallbacks) => void; | ||
| }; | ||
|
|
||
| /** | ||
| * Callbacks for user actions while a QR code is displayed. | ||
| * | ||
| * This is exposed as the payload of a `VerifierEvent.ShowReciprocateQr` event, or can be retrieved directly from the | ||
| * verifier as `reciprocateQREvent`. | ||
| */ | ||
| export interface ShowQrCodeCallbacks { | ||
| /** The user confirms that the verification data matches */ | ||
| confirm(): void; | ||
|
|
||
| /** Cancel the verification flow */ | ||
| cancel(): void; | ||
| } | ||
|
|
||
| /** | ||
| * Callbacks for user actions while a SAS is displayed. | ||
| * | ||
| * This is exposed as the payload of a `VerifierEvent.ShowSas` event, or directly from the verifier as `sasEvent`. | ||
| */ | ||
| export interface ShowSasCallbacks { | ||
| /** The generated SAS to be shown to the user */ | ||
| sas: GeneratedSas; | ||
|
|
||
| /** Function to call if the user confirms that the SAS matches. | ||
| * | ||
| * @returns A Promise that completes once the m.key.verification.mac is queued. | ||
| */ | ||
| confirm(): Promise<void>; | ||
|
|
||
| /** | ||
| * Function to call if the user finds the SAS does not match. | ||
| * | ||
| * Sends an `m.key.verification.cancel` event with a `m.mismatched_sas` error code. | ||
| */ | ||
| mismatch(): void; | ||
|
|
||
| /** Cancel the verification flow */ | ||
| cancel(): void; | ||
| } | ||
|
|
||
| /** A generated SAS to be shown to the user, in alternative formats */ | ||
| export interface GeneratedSas { | ||
| /** | ||
| * The SAS as three numbers between 0 and 8191. | ||
| * | ||
| * Only populated if the `decimal` SAS method was negotiated. | ||
| */ | ||
| decimal?: [number, number, number]; | ||
|
|
||
| /** | ||
| * The SAS as seven emojis. | ||
| * | ||
| * Only populated if the `emoji` SAS method was negotiated. | ||
| */ | ||
| emoji?: EmojiMapping[]; | ||
| } | ||
|
|
||
| /** | ||
| * An emoji for the generated SAS. A tuple `[emoji, name]` where `emoji` is the emoji itself and `name` is the | ||
| * English name. | ||
| */ | ||
| export type EmojiMapping = [emoji: string, name: string]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,8 @@ import { KeysDuringVerification, requestKeysDuringVerification } from "../CrossS | |
| import { IVerificationChannel } from "./request/Channel"; | ||
| import { MatrixClient } from "../../client"; | ||
| import { VerificationRequest } from "./request/VerificationRequest"; | ||
| import { ListenerMap, TypedEventEmitter } from "../../models/typed-event-emitter"; | ||
| import { TypedEventEmitter } from "../../models/typed-event-emitter"; | ||
| import { VerifierEvent, VerifierEventHandlerMap } from "../../crypto-api/verification"; | ||
|
|
||
| const timeoutException = new Error("Verification timed out"); | ||
|
|
||
|
|
@@ -40,18 +41,24 @@ export class SwitchStartEventError extends Error { | |
|
|
||
| export type KeyVerifier = (keyId: string, device: DeviceInfo, keyInfo: string) => void; | ||
|
|
||
| export enum VerificationEvent { | ||
| Cancel = "cancel", | ||
| } | ||
| /** @deprecated use VerifierEvent */ | ||
| export type VerificationEvent = VerifierEvent; | ||
| /** @deprecated use VerifierEvent */ | ||
| export const VerificationEvent = VerifierEvent; | ||
|
|
||
| /** @deprecated use VerifierEventHandlerMap */ | ||
| export type VerificationEventHandlerMap = { | ||
| [VerificationEvent.Cancel]: (e: Error | MatrixEvent) => void; | ||
| }; | ||
|
|
||
| // The type parameters of VerificationBase are no longer used, but we need some placeholders to maintain | ||
| // backwards compatibility with applications that reference the class. | ||
| export class VerificationBase< | ||
| Events extends string, | ||
| Arguments extends ListenerMap<Events | VerificationEvent>, | ||
| > extends TypedEventEmitter<Events | VerificationEvent, Arguments, VerificationEventHandlerMap> { | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| Events extends string = VerifierEvent, | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| Arguments = VerifierEventHandlerMap, | ||
|
Comment on lines
+57
to
+60
Member
Author
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. these type parameters are no longer used, but we need something here to maintain backwards compatibility with applications that reference
Member
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. Could you add that as a comment? |
||
| > extends TypedEventEmitter<VerifierEvent, VerifierEventHandlerMap> { | ||
| private cancelled = false; | ||
| private _done = false; | ||
| private promise: Promise<void> | null = null; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.