1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Add async method for generating a QR code (#3562)

The api to generate a QR code is async in rust, and the easiest way to deal
with it is to make a new method.
This commit is contained in:
Richard van der Hoff
2023-07-10 14:22:10 +01:00
committed by GitHub
parent 2751e191d3
commit e42dd74426
4 changed files with 35 additions and 5 deletions

View File

@@ -414,7 +414,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
expect(request.phase).toEqual(VerificationPhase.Ready); expect(request.phase).toEqual(VerificationPhase.Ready);
// we should now have QR data we can display // we should now have QR data we can display
const qrCodeBuffer = request.getQRCodeBytes()!; const qrCodeBuffer = (await request.generateQRCode())!;
expect(qrCodeBuffer).toBeTruthy(); expect(qrCodeBuffer).toBeTruthy();
// https://spec.matrix.org/v1.7/client-server-api/#qr-code-format // https://spec.matrix.org/v1.7/client-server-api/#qr-code-format

View File

@@ -152,9 +152,19 @@ export interface VerificationRequest
* Get the data for a QR code allowing the other device to verify this one, if it supports it. * Get the data for a QR code allowing the other device to verify this one, if it supports it.
* *
* Only set after a .ready if the other party can scan a QR code, otherwise undefined. * Only set after a .ready if the other party can scan a QR code, otherwise undefined.
*
* @deprecated Not supported in Rust Crypto. Use {@link VerificationRequest#generateQRCode} instead.
*/ */
getQRCodeBytes(): Buffer | undefined; getQRCodeBytes(): Buffer | undefined;
/**
* Generate the data for a QR code allowing the other device to verify this one, if it supports it.
*
* Only returns data once `phase` is {@link VerificationPhase.Ready} and the other party can scan a QR code;
* otherwise returns `undefined`.
*/
generateQRCode(): Promise<Buffer | undefined>;
/** /**
* If this request has been cancelled, the cancellation code (e.g `m.user`) which is responsible for cancelling * If this request has been cancelled, the cancellation code (e.g `m.user`) which is responsible for cancelling
* this verification. * this verification.

View File

@@ -268,7 +268,7 @@ export class VerificationRequest<C extends IVerificationChannel = IVerificationC
/** Only set after a .ready if the other party can scan a QR code /** Only set after a .ready if the other party can scan a QR code
* *
* @deprecated Prefer `getQRCodeBytes`. * @deprecated Prefer `generateQRCode`.
*/ */
public get qrCodeData(): QRCodeData | null { public get qrCodeData(): QRCodeData | null {
return this._qrCodeData; return this._qrCodeData;
@@ -278,11 +278,23 @@ export class VerificationRequest<C extends IVerificationChannel = IVerificationC
* Get the data for a QR code allowing the other device to verify this one, if it supports it. * Get the data for a QR code allowing the other device to verify this one, if it supports it.
* *
* Only set after a .ready if the other party can scan a QR code, otherwise undefined. * Only set after a .ready if the other party can scan a QR code, otherwise undefined.
*
* @deprecated Prefer `generateQRCode`.
*/ */
public getQRCodeBytes(): Buffer | undefined { public getQRCodeBytes(): Buffer | undefined {
return this._qrCodeData?.getBuffer(); return this._qrCodeData?.getBuffer();
} }
/**
* Generate the data for a QR code allowing the other device to verify this one, if it supports it.
*
* Only returns data once `phase` is `Ready` and the other party can scan a QR code;
* otherwise returns `undefined`.
*/
public async generateQRCode(): Promise<Buffer | undefined> {
return this.getQRCodeBytes();
}
/** Checks whether the other party supports a given verification method. /** Checks whether the other party supports a given verification method.
* This is useful when setting up the QR code UI, as it is somewhat asymmetrical: * This is useful when setting up the QR code UI, as it is somewhat asymmetrical:
* if the other party supports SCAN_QR, we should show a QR code in the UI, and vice versa. * if the other party supports SCAN_QR, we should show a QR code in the UI, and vice versa.

View File

@@ -322,15 +322,23 @@ export class RustVerificationRequest
} }
/** /**
* Get the data for a QR code allowing the other device to verify this one, if it supports it. * Stub implementation of {@link Crypto.VerificationRequest#getQRCodeBytes}.
*
* Only set after a .ready if the other party can scan a QR code, otherwise undefined.
*/ */
public getQRCodeBytes(): Buffer | undefined { public getQRCodeBytes(): Buffer | undefined {
// TODO // TODO
return undefined; return undefined;
} }
/**
* Generate the data for a QR code allowing the other device to verify this one, if it supports it.
*
* Implementation of {@link Crypto.VerificationRequest#generateQRCode}.
*/
public async generateQRCode(): Promise<Buffer | undefined> {
// TODO
return undefined;
}
/** /**
* If this request has been cancelled, the cancellation code (e.g `m.user`) which is responsible for cancelling * If this request has been cancelled, the cancellation code (e.g `m.user`) which is responsible for cancelling
* this verification. * this verification.