From 9480b7ba3240d3230ff3409e44c800e0a3f71205 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Tue, 3 Oct 2023 12:27:50 +0100 Subject: [PATCH] Refactor --- src/rendezvous/MSC3906Rendezvous.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/rendezvous/MSC3906Rendezvous.ts b/src/rendezvous/MSC3906Rendezvous.ts index c93b4eee41c..8dffda0e246 100644 --- a/src/rendezvous/MSC3906Rendezvous.ts +++ b/src/rendezvous/MSC3906Rendezvous.ts @@ -212,12 +212,14 @@ export class MSC3906Rendezvous { const masterPublicKey = (await crypto.getCrossSigningKeyId(CrossSigningKey.Master)) ?? undefined; + const ourDeviceId = this.client.getDeviceId(); + const ourDevice = ourDeviceId ? await this.getOwnDevice(ourDeviceId) : undefined; + await this.send({ type: PayloadType.Finish, outcome: Outcome.Verified, - verifying_device_id: this.client.getDeviceId()!, - // FIXME: this needs fixing too - verifying_device_key: this.client.crypto!.getDeviceEd25519Key()!, + verifying_device_id: ourDevice?.deviceId, + verifying_device_key: ourDevice?.getFingerprint(), master_key: masterPublicKey, }); @@ -252,16 +254,12 @@ export class MSC3906Rendezvous { throw new Error("No user ID set"); } - // TODO: is this correct? - let deviceInfo: Device | undefined = (await crypto.getUserDeviceInfo([userId], true)) - .get(userId) - ?.get(this.newDeviceId); + let deviceInfo = await this.getOwnDevice(this.newDeviceId); if (!deviceInfo) { logger.info("Going to wait for new device to be online"); await sleep(timeout); - // TODO: is this correct? - deviceInfo = (await crypto.getUserDeviceInfo([userId], true)).get(userId)?.get(this.newDeviceId); + deviceInfo = await this.getOwnDevice(this.newDeviceId); } if (deviceInfo) { @@ -271,6 +269,14 @@ export class MSC3906Rendezvous { throw new Error("Device not online within timeout"); } + private async getOwnDevice(deviceId: string): Promise { + const userId = this.client.getUserId(); + if (!userId) { + return undefined; + } + return (await this.client.getCrypto()?.getUserDeviceInfo([userId], true))?.get(userId)?.get(deviceId); + } + public async cancel(reason: RendezvousFailureReason): Promise { this.onFailure?.(reason); await this.channel.cancel(reason);