|
@@ -8,6 +8,12 @@ pub use contract::{
|
8
|
8
|
view_moderator_account,
|
9
|
9
|
};
|
10
|
10
|
|
|
11
|
+use near_client::{
|
|
12
|
+ core::{hash::CryptoHash, types::Nonce},
|
|
13
|
+ prelude::*,
|
|
14
|
+};
|
|
15
|
+
|
|
16
|
+use base64::prelude::*;
|
11
|
17
|
use common_api::api::{ApiResponse, Data, ExchangeMessage};
|
12
|
18
|
use crypto::{decrypt, encrypt, secret};
|
13
|
19
|
use error::ApiError;
|
|
@@ -17,8 +23,6 @@ use gloo_timers::future::TimeoutFuture;
|
17
|
23
|
use itertools::Itertools;
|
18
|
24
|
use js_sys::Promise;
|
19
|
25
|
use log::{info, warn};
|
20
|
|
-use near_client::prelude::*;
|
21
|
|
-use near_primitives_core::{account::id::AccountId, hash::CryptoHash, types::Nonce};
|
22
|
26
|
use serde::{Deserialize, Serialize};
|
23
|
27
|
use std::{collections::HashSet, str::FromStr, sync::Arc};
|
24
|
28
|
use url::Url;
|
|
@@ -142,6 +146,7 @@ impl KeyProvisioner {
|
142
|
146
|
///
|
143
|
147
|
/// - participants_set - The [`js_sys::Set`] represents hash set of participants' keys
|
144
|
148
|
/// - timeout_ms - The [`u32`] that represents milliseconds that were given not to be exceeded
|
|
149
|
+ #[wasm_bindgen(js_name = initMeeting)]
|
145
|
150
|
pub fn init_meeting(&self, participants_set: js_sys::Set, timeout_ms: u32) -> Promise {
|
146
|
151
|
let handler = self.handler();
|
147
|
152
|
let signer = self.signer();
|
|
@@ -178,12 +183,38 @@ impl KeyProvisioner {
|
178
|
183
|
})
|
179
|
184
|
}
|
180
|
185
|
|
|
186
|
+ /// Add a participant to the current session
|
|
187
|
+ ///
|
|
188
|
+ /// Arguments
|
|
189
|
+ ///
|
|
190
|
+ /// - meeting_id - The [`String`] that indicates ID of the meeting room
|
|
191
|
+ /// - participant - [`AccountId`] of a desired participant
|
|
192
|
+ ///
|
|
193
|
+ /// Returns
|
|
194
|
+ ///
|
|
195
|
+ /// Transaction ID
|
|
196
|
+ #[wasm_bindgen(js_name = addParticipant)]
|
|
197
|
+ pub fn add_participant(&self, meeting_id: String, participant: String) -> Promise {
|
|
198
|
+ let handler = self.handler();
|
|
199
|
+ let signer = self.signer();
|
|
200
|
+ wasm_bindgen_futures::future_to_promise(async move {
|
|
201
|
+ let account_id = AccountId::from_str(&participant)
|
|
202
|
+ .map_err(|err| ApiError::InvalidAccountId(err.to_string()))?;
|
|
203
|
+ let meeting_id = uuid::Uuid::from_str(&meeting_id)
|
|
204
|
+ .map_err(|err| ApiError::InvalidSessionUuid(err.to_string()))?;
|
|
205
|
+ let transaction_id = add_participant(&handler, &signer, meeting_id, account_id).await?;
|
|
206
|
+
|
|
207
|
+ Ok(to_value(&transaction_id.to_string()))
|
|
208
|
+ })
|
|
209
|
+ }
|
|
210
|
+
|
181
|
211
|
/// Sends participants' keys to the keys exchange server
|
182
|
212
|
///
|
183
|
213
|
/// Arguments
|
184
|
214
|
///
|
185
|
215
|
/// - meeting_id - The [`String`] that indicates ID of the meeting room
|
186
|
216
|
/// - timeout_ms - The [`u32`] that represents milliseconds that were given not to be exceeded
|
|
217
|
+ #[wasm_bindgen(js_name = sendKeys)]
|
187
|
218
|
pub fn send_keys(&self, meeting_id: String, timeout_ms: u32) -> Promise {
|
188
|
219
|
let handler = self.handler();
|
189
|
220
|
let signer = self.signer();
|
|
@@ -239,7 +270,9 @@ impl KeyProvisioner {
|
239
|
270
|
exchange(&handler, &signer, meet_id, messages).await?;
|
240
|
271
|
}
|
241
|
272
|
|
242
|
|
- Ok(JsValue::from_str(&base64::encode(handler.secret)))
|
|
273
|
+ Ok(JsValue::from_str(
|
|
274
|
+ &BASE64_STANDARD_NO_PAD.encode(handler.secret),
|
|
275
|
+ ))
|
243
|
276
|
};
|
244
|
277
|
|
245
|
278
|
wasm_bindgen_futures::future_to_promise(async move {
|
|
@@ -258,6 +291,7 @@ impl KeyProvisioner {
|
258
|
291
|
///
|
259
|
292
|
/// - meeting_id - The [`String`] that indicates ID of the meeting room
|
260
|
293
|
/// - timeout_ms - The [`u32`] that represents milliseconds that were given not to be exceeded
|
|
294
|
+ #[wasm_bindgen(js_name = getKey)]
|
261
|
295
|
pub fn get_key(&self, meeting_id: String, timeout_ms: u32) -> Promise {
|
262
|
296
|
let handler = self.handler();
|
263
|
297
|
let signer = self.signer();
|
|
@@ -269,7 +303,7 @@ impl KeyProvisioner {
|
269
|
303
|
if let ApiResponse::Success(data) = receive(&handler, &signer, meet_id).await? {
|
270
|
304
|
let secret =
|
271
|
305
|
decrypt(signer.secret_key(), data.moderator_pk, meet_id, data.data)?;
|
272
|
|
- return Ok(JsValue::from_str(&base64::encode(secret)));
|
|
306
|
+ return Ok(JsValue::from_str(&BASE64_STANDARD_NO_PAD.encode(secret)));
|
273
|
307
|
}
|
274
|
308
|
}
|
275
|
309
|
};
|