Skip to content

Commit

Permalink
crypto-js: Simplify response type of Sas::confirm (matrix-org#2066)
Browse files Browse the repository at this point in the history
On the javascript side, everything is just an `OutgoingRequest`, so we may
as well return a single array rather than a tuple.
  • Loading branch information
richvdh authored Jun 16, 2023
1 parent bddc884 commit ef0c230
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 174 deletions.
1 change: 1 addition & 0 deletions bindings/matrix-sdk-crypto-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# v0.1.0-alpha.11

- Simplify the response type of `Sas.confirm()`.
- Add `VerificationRequest.registerChangesCallback()`,
`Sas.registerChangesCallback()`, and `Qr.registerChangesCallback()`.
- Add `VerificationRequest.phase()` and `VerificationRequest.getVerification()`.
Expand Down
24 changes: 11 additions & 13 deletions bindings/matrix-sdk-crypto-js/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ impl Sas {
/// This confirms that the short auth strings match on both sides.
///
/// Does nothing if we’re not in a state where we can confirm the
/// short auth string, otherwise returns a `MacEventContent` that
/// needs to be sent to the server.
/// short auth string.
///
/// Returns a `Promise` for an array of `OutgoingRequest`s.
pub fn confirm(&self) -> Promise {
let me = self.inner.clone();

Expand All @@ -262,17 +263,14 @@ impl Sas {
.map(JsValue::try_from)
.collect::<Result<Array, _>>()?;

let tuple = Array::new();
tuple.set(0, outgoing_verification_requests.into());
tuple.set(
1,
signature_upload_request
.map(|request| requests::SignatureUploadRequest::try_from(&request))
.transpose()?
.into(),
);

Ok(tuple)
// if a signature upload request was returned, push it onto the end of the array
// of OutgoingRequests we just built.
if let Some(sig_rq) = signature_upload_request {
outgoing_verification_requests
.push(&requests::SignatureUploadRequest::try_from(&sig_rq)?.into());
}

Ok(outgoing_verification_requests)
})
}

Expand Down
Loading

0 comments on commit ef0c230

Please sign in to comment.