Skip to content

Commit d74c6f4

Browse files
committed
Reduce cognitive complexity
1 parent d4e1c9f commit d74c6f4

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/rendezvous/MSC3906Rendezvous.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export class MSC3906Rendezvous {
134134
this._code = JSON.stringify(raw);
135135
}
136136

137+
/**
138+
*
139+
* @returns the checksum of the secure channel if the rendezvous set up was successful, otherwise undefined
140+
*/
137141
public async startAfterShowingCode(): Promise<string | undefined> {
138142
const checksum = await this.channel.connect();
139143

@@ -157,6 +161,16 @@ export class MSC3906Rendezvous {
157161
protocols: [LOGIN_TOKEN_PROTOCOL.name],
158162
});
159163

164+
const receivedValidProtocolResponse = await this.waitForAndHandleProtocolPayload();
165+
166+
return receivedValidProtocolResponse ? checksum : undefined;
167+
}
168+
169+
/**
170+
*
171+
* @returns true if the protocol was received successfully, false otherwise
172+
*/
173+
private async waitForAndHandleProtocolPayload(): Promise<boolean> {
160174
logger.info("Waiting for other device to chose protocol");
161175
const { type, protocol, outcome, reason, intent } = await this.receive();
162176

@@ -182,7 +196,7 @@ export class MSC3906Rendezvous {
182196
reason = RendezvousFailureReason.Unknown;
183197
}
184198
await this.cancel(reason);
185-
return undefined;
199+
return false;
186200
}
187201

188202
// v2 flow
@@ -206,28 +220,28 @@ export class MSC3906Rendezvous {
206220
failureReason = RendezvousFailureReason.Unknown;
207221
}
208222
await this.cancel(failureReason);
209-
return undefined;
223+
return false;
210224
}
211225

212226
// v1 unexpected payload
213227
if (this.v1FallbackEnabled && type !== PayloadType.Progress) {
214228
await this.cancel(RendezvousFailureReason.Unknown);
215-
return undefined;
229+
return false;
216230
}
217231

218232
// v2 unexpected payload
219233
if (!this.v1FallbackEnabled && type !== PayloadType.Protocol) {
220234
await this.cancel(RendezvousFailureReason.Unknown);
221-
return undefined;
235+
return false;
222236
}
223237

224238
// invalid protocol
225239
if (!protocol || !LOGIN_TOKEN_PROTOCOL.matches(protocol)) {
226240
await this.cancel(RendezvousFailureReason.UnsupportedAlgorithm);
227-
return undefined;
241+
return false;
228242
}
229243

230-
return checksum;
244+
return true;
231245
}
232246

233247
private async receive(): Promise<MSC3906RendezvousPayload> {

0 commit comments

Comments
 (0)