mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-14 11:05:32 -04:00
feat(crypto-js): Implement VerificationRequest.start_sas.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
//! Different verification types.
|
||||
|
||||
use js_sys::{Array, JsString};
|
||||
use js_sys::{Array, JsString, Promise};
|
||||
use ruma::events::key::verification::{
|
||||
cancel::CancelCode as RumaCancelCode, VerificationMethod as RumaVerificationMethod,
|
||||
};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use crate::{
|
||||
future::future_to_promise,
|
||||
identifiers::{DeviceId, RoomId, UserId},
|
||||
requests,
|
||||
};
|
||||
@@ -130,6 +131,12 @@ pub struct Sas {
|
||||
inner: matrix_sdk_crypto::Sas,
|
||||
}
|
||||
|
||||
impl From<matrix_sdk_crypto::Sas> for Sas {
|
||||
fn from(inner: matrix_sdk_crypto::Sas) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Sas {
|
||||
/// Get our own user ID.
|
||||
@@ -872,7 +879,36 @@ impl VerificationRequest {
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
// start_sas
|
||||
/// Transition from this verification request into a SAS verification flow.
|
||||
#[wasm_bindgen(js_name = "startSas")]
|
||||
pub fn start_sas(&self) -> Promise {
|
||||
let me = self.inner.clone();
|
||||
|
||||
future_to_promise(async move {
|
||||
match me
|
||||
.start_sas()
|
||||
.await?
|
||||
.map(|(sas, outgoing_verification_request)| -> Result<Array, JsError> {
|
||||
let tuple = Array::new();
|
||||
|
||||
tuple.set(0, Sas::from(sas).into());
|
||||
tuple.set(
|
||||
1,
|
||||
OutgoingVerificationRequest::from(outgoing_verification_request)
|
||||
.try_into()?,
|
||||
);
|
||||
|
||||
Ok(tuple)
|
||||
})
|
||||
.transpose()
|
||||
{
|
||||
Ok(a) => Ok(a),
|
||||
Err(_) => {
|
||||
Err(anyhow::Error::msg("Failed to build the outgoing verification request"))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
// generate_qr_code if `qrcode`
|
||||
// scan_qr_code if `qrcode`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user