Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hughns committed Oct 31, 2023
1 parent 3e21ce9 commit 9480b7b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/rendezvous/MSC3906Rendezvous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down Expand Up @@ -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) {
Expand All @@ -271,6 +269,14 @@ export class MSC3906Rendezvous {
throw new Error("Device not online within timeout");
}

private async getOwnDevice(deviceId: string): Promise<Device | undefined> {
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<void> {
this.onFailure?.(reason);
await this.channel.cancel(reason);
Expand Down

0 comments on commit 9480b7b

Please sign in to comment.