From 792b4581abb76e76e93a07cbb5ee38cb4fff21d7 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 12 Sep 2022 14:26:54 +0200 Subject: [PATCH] feat(crypto-js): Implement `Qr.reciprocate` and `.confirm_scanning`. --- .../matrix-sdk-crypto-js/src/verification.rs | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/bindings/matrix-sdk-crypto-js/src/verification.rs b/bindings/matrix-sdk-crypto-js/src/verification.rs index 1950ed061..0ee9dca9d 100644 --- a/bindings/matrix-sdk-crypto-js/src/verification.rs +++ b/bindings/matrix-sdk-crypto-js/src/verification.rs @@ -235,7 +235,7 @@ impl Sas { pub fn accept(&self) -> Result { self.inner .accept() - .map(OutgoingVerificationRequest) + .map(OutgoingVerificationRequest::from) .map(JsValue::try_from) .transpose() .map(JsValue::from) @@ -256,7 +256,7 @@ impl Sas { let (outgoing_verification_requests, signature_upload_request) = me.confirm().await?; let outgoing_verification_requests = outgoing_verification_requests .into_iter() - .map(OutgoingVerificationRequest) + .map(OutgoingVerificationRequest::from) .map(JsValue::try_from) .collect::>()?; @@ -482,12 +482,37 @@ impl Qr { Ok(self.inner.to_bytes()?.into_iter().map(JsValue::from).collect()) } + /// Notify the other side that we have successfully scanned the QR + /// code and that the QR verification flow can start. + /// + /// This will return some OutgoingContent if the object is in the + /// correct state to start the verification flow, otherwise None. + pub fn reciprocate(&self) -> Result { + self.inner + .reciprocate() + .map(OutgoingVerificationRequest::from) + .map(JsValue::try_from) + .transpose() + .map(JsValue::from) + .map_err(Into::into) + } + + /// Confirm that the other side has scanned our QR code. + #[wasm_bindgen(js_name = "confirmScanning")] + pub fn confirm_scanning(&self) -> Result { + self.inner + .confirm_scanning() + .map(OutgoingVerificationRequest::from) + .map(JsValue::try_from) + .transpose() + .map(JsValue::from) + .map_err(Into::into) + } + /* /// Cancel the verification flow. pub fn cancel(&self) -> … {} pub fn cancel_with_code(&self, code: …) -> … {} - pub fn reciprocate(&self) -> … {} - pub fn confirm_scanning(&self) -> … {} */ } @@ -891,7 +916,7 @@ impl VerificationRequest { self.inner .accept_with_methods(methods) - .map(OutgoingVerificationRequest) + .map(OutgoingVerificationRequest::from) .map(JsValue::try_from) .transpose() .map(JsValue::from) @@ -915,7 +940,7 @@ impl VerificationRequest { pub fn accept(&self) -> Result { self.inner .accept() - .map(OutgoingVerificationRequest) + .map(OutgoingVerificationRequest::from) .map(JsValue::try_from) .transpose() .map(JsValue::from) @@ -929,7 +954,7 @@ impl VerificationRequest { pub fn cancel(&self) -> Result { self.inner .cancel() - .map(OutgoingVerificationRequest) + .map(OutgoingVerificationRequest::from) .map(JsValue::try_from) .transpose() .map(JsValue::from)