@@ -134,6 +134,10 @@ export class MSC3906Rendezvous {
134
134
this . _code = JSON . stringify ( raw ) ;
135
135
}
136
136
137
+ /**
138
+ *
139
+ * @returns the checksum of the secure channel if the rendezvous set up was successful, otherwise undefined
140
+ */
137
141
public async startAfterShowingCode ( ) : Promise < string | undefined > {
138
142
const checksum = await this . channel . connect ( ) ;
139
143
@@ -157,6 +161,16 @@ export class MSC3906Rendezvous {
157
161
protocols : [ LOGIN_TOKEN_PROTOCOL . name ] ,
158
162
} ) ;
159
163
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 > {
160
174
logger . info ( "Waiting for other device to chose protocol" ) ;
161
175
const { type, protocol, outcome, reason, intent } = await this . receive ( ) ;
162
176
@@ -182,7 +196,7 @@ export class MSC3906Rendezvous {
182
196
reason = RendezvousFailureReason . Unknown ;
183
197
}
184
198
await this . cancel ( reason ) ;
185
- return undefined ;
199
+ return false ;
186
200
}
187
201
188
202
// v2 flow
@@ -206,28 +220,28 @@ export class MSC3906Rendezvous {
206
220
failureReason = RendezvousFailureReason . Unknown ;
207
221
}
208
222
await this . cancel ( failureReason ) ;
209
- return undefined ;
223
+ return false ;
210
224
}
211
225
212
226
// v1 unexpected payload
213
227
if ( this . v1FallbackEnabled && type !== PayloadType . Progress ) {
214
228
await this . cancel ( RendezvousFailureReason . Unknown ) ;
215
- return undefined ;
229
+ return false ;
216
230
}
217
231
218
232
// v2 unexpected payload
219
233
if ( ! this . v1FallbackEnabled && type !== PayloadType . Protocol ) {
220
234
await this . cancel ( RendezvousFailureReason . Unknown ) ;
221
- return undefined ;
235
+ return false ;
222
236
}
223
237
224
238
// invalid protocol
225
239
if ( ! protocol || ! LOGIN_TOKEN_PROTOCOL . matches ( protocol ) ) {
226
240
await this . cancel ( RendezvousFailureReason . UnsupportedAlgorithm ) ;
227
- return undefined ;
241
+ return false ;
228
242
}
229
243
230
- return checksum ;
244
+ return true ;
231
245
}
232
246
233
247
private async receive ( ) : Promise < MSC3906RendezvousPayload > {
0 commit comments