Ver código fonte

Merge pull request #106 from Relayz-io/silvestr/bump-up-dependencies-version

Bump up outdated dependencies
develop
Predko Silvestr 2 anos atrás
pai
commit
fb40b81ce8
Nenhuma conta vinculada ao e-mail do autor do commit

+ 5
- 2
.github/workflows/ci.yml Ver arquivo

@@ -9,7 +9,7 @@ on:
9 9
     branches:
10 10
       - develop
11 11
   pull_request:
12
-    types: [opened, reopened, edited, synchronize]
12
+    types: [opened, reopened, synchronize]
13 13
     branches:
14 14
       - develop
15 15
 
@@ -56,10 +56,11 @@ jobs:
56 56
     needs: [clippy, fmt]
57 57
     runs-on: ubuntu-latest
58 58
     permissions:
59
+      contents: read
59 60
       packages: read
60 61
     steps:
61 62
       - name: Log in to the Container registry
62
-        uses: docker/login-action@v2.0.0
63
+        uses: docker/login-action@v2
63 64
         with:
64 65
           registry: ${{ env.REGISTRY }}
65 66
           username: ${{ github.actor }}
@@ -75,6 +76,8 @@ jobs:
75 76
         run: |
76 77
           docker pull ${{ env.REGISTRY }}/relayz-io/key-exchange:latest
77 78
           docker tag ${{ env.REGISTRY }}/relayz-io/key-exchange:latest key-exchange:latest
79
+          docker pull ${{ env.REGISTRY }}/relayz-io/cache:latest
80
+          docker tag ${{ env.REGISTRY }}/relayz-io/cache:latest cache:latest
78 81
           git clone git@github.com:Relayz-io/key-exchange-server.git
79 82
           (cd key-exchange-server && docker compose up -d --no-build)
80 83
       - name: Clone near-smartcontracts and deploy

+ 8
- 1
README.md Ver arquivo

@@ -8,7 +8,14 @@ Commonly used **API** among different dependencies. For example **key-exchange-s
8 8
 
9 9
 ## Web-Client 🦘
10 10
 
11
-Client library for communication from browser and *Near blockchain*. It's a high-level **API**. User doesn't need to understand how blockchain works.
11
+It's a client that exchange keys between meeting moderator and participants.
12
+To achieve solid security used blockchain as a trust point for establishing secure channels between ```moderator``` and ```participant```. Each user in a blockchain has an ```ED25519``` PublicKey. For creating a secure channel **Diffie–Hellman** algorithm is used, provided by [Dalek cryptography](https://github.com/dalek-cryptography). Unfortunately, it's not possible to exchange keys with ```ED25519``` keys, because it is using a ```Edwards``` point, and for algorithm needs a ```Montgomery``` point. For this purpose, conversion happened [here](https://github.com/Relayz-io/near-client/blob/376708def420a158b3ca4e5af2aff2e380fd58af/src/crypto/dhx.rs#L168).
13
+
14
+> NOTE! Used the maximum key length for each algorithm
15
+
16
+Then we have proper keys for the **Diffie–Hellman** exchange. Let's create out secret with [dhx](https://github.com/Relayz-io/key-exchange-client/blob/develop/web-client/src/crypto.rs#LL8C5-L8C5). After we need to provide a uniformly distributed secret key. For this purpose used a ***_KDF_*** algorithm [```blake3```](https://github.com/BLAKE3-team/BLAKE3). [Here](https://github.com/Relayz-io/key-exchange-client/blob/86450c015c2370742c765d94629ae97837224eee/web-client/src/crypto.rs#L18) is an implementation.
17
+
18
+The next stage is to pass a randomly generated key in a secure way for each participant. To do this let's encrypt _generated key_ with a just generated after ***_KDF_*** secure key, that is unique for each ```participant = moderator``` pair. Encrypt randomly generated key by [ChaCha20](https://rust-random.github.io/rand/rand_chacha/struct.ChaCha20Rng.html) with a [AES-GCM](https://github.com/Relayz-io/key-exchange-client/blob/86450c015c2370742c765d94629ae97837224eee/web-client/src/crypto.rs#L30). That's all.
12 19
 
13 20
 ### Usage of web-client library:
14 21
 

+ 1
- 2
common-api/Cargo.toml Ver arquivo

@@ -11,8 +11,7 @@ structures should be serializable with "serde" and "borsh"
11 11
 
12 12
 [dependencies]
13 13
 borsh = "0.9"
14
-near-account-id = { version = "0.15" }
15
-near-client = "0.1"
14
+near-client = { git = "https://github.com/Relayz-io/near-client.git" }
16 15
 serde = { version = "1", default-features = false, features = ["derive"] }
17 16
 
18 17
 [dev-dependencies]

+ 1
- 2
common-api/src/api.rs Ver arquivo

@@ -1,6 +1,5 @@
1 1
 use borsh::{BorshDeserialize, BorshSerialize};
2
-use near_account_id::AccountId;
3
-use near_client::crypto::prelude::*;
2
+use near_client::prelude::*;
4 3
 use serde::{Deserialize, Serialize};
5 4
 use std::{collections::HashSet, time::Duration};
6 5
 

+ 1
- 2
common-api/src/headers.rs Ver arquivo

@@ -1,5 +1,4 @@
1
-use near_account_id::AccountId;
2
-use near_client::crypto::prelude::*;
1
+use near_client::prelude::*;
3 2
 use serde::{Deserialize, Serialize};
4 3
 
5 4
 pub const SIGNATURE_HEADER_NAME: &str = "signature";

+ 4
- 6
web-client/Cargo.toml Ver arquivo

@@ -1,6 +1,6 @@
1 1
 [package]
2 2
 name = "web-client"
3
-version = "0.1.0"
3
+version = "0.1.1"
4 4
 edition = "2021"
5 5
 authors = ["silvestr@relayz.io"]
6 6
 description = """
@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
12 12
 [dependencies]
13 13
 aes-gcm = "0.10"
14 14
 blake3 = "1.3"
15
-base64 = "0.20"
15
+base64 = "0.21"
16 16
 console_error_panic_hook = "0.1"
17 17
 common-api = { path = "../common-api" }
18 18
 console_log = { version = "0.2", features = ["color"] }
@@ -21,13 +21,11 @@ gloo-timers = { version = "0.2", features = ["futures-core", "futures"] }
21 21
 itertools = "0.10"
22 22
 js-sys = "0.3"
23 23
 log = "0.4"
24
-near-client = "0.1"
25
-near-primitives-core = "0.15"
26
-near-units = "0.2"
24
+near-client = { git = "https://github.com/Relayz-io/near-client.git" }
27 25
 rand = { version = "0.8" }
28 26
 rand_chacha = "0.3"
29 27
 reqwest = { version = "0.11", features = ["json"] }
30
-serde-wasm-bindgen = "0.4"
28
+serde-wasm-bindgen = "0.5"
31 29
 serde = { version = "1", default-features = false, features = ["derive"] }
32 30
 serde_json = { version = "1", default-features = false }
33 31
 uuid = { version = "1.1.2", features = ["v4", "serde", "js"] }

+ 1
- 3
web-client/src/contract.rs Ver arquivo

@@ -1,7 +1,5 @@
1 1
 use crate::{error::ApiError, Handler};
2
-use near_client::{crypto::prelude::*, prelude::*, Finality};
3
-use near_primitives_core::{hash::CryptoHash, types::AccountId};
4
-use near_units::parse_gas;
2
+use near_client::{core::hash::CryptoHash, near_units::parse_gas, prelude::*};
5 3
 use std::collections::HashSet;
6 4
 use uuid::Uuid;
7 5
 use wasm_bindgen::prelude::*;

+ 1
- 2
web-client/src/error.rs Ver arquivo

@@ -1,5 +1,4 @@
1
-use near_client::{crypto::Error as CryptoErr, Error};
2
-use near_primitives_core::account::id::ParseAccountError;
1
+use near_client::{core::account::id::ParseAccountError, crypto::Error as CryptoErr, Error};
3 2
 use reqwest::Error as ExchangeError;
4 3
 use serde::{Deserialize, Serialize};
5 4
 use serde_json::Error as SerializationError;

+ 5
- 3
web-client/src/exchange_client.rs Ver arquivo

@@ -9,8 +9,8 @@ use reqwest::{
9 9
 };
10 10
 
11 11
 use crate::{contract::view_server_key, error::ApiError, Handler};
12
+use base64::prelude::*;
12 13
 use near_client::prelude::*;
13
-use near_primitives_core::types::AccountId;
14 14
 use std::{collections::HashSet, time::Duration};
15 15
 use uuid::Uuid;
16 16
 use wasm_bindgen::JsValue;
@@ -138,7 +138,7 @@ fn signature_header<T: serde::Serialize>(value: &T, signer: &Signer) -> Result<S
138 138
 
139 139
             serde_json::to_vec(&header).map_err(|_| ApiError::CreateSignatureHeader.into())
140 140
         })
141
-        .map(base64::encode)
141
+        .map(|it| BASE64_STANDARD_NO_PAD.encode(it))
142 142
 }
143 143
 
144 144
 async fn verify_response(handler: &Handler, response: Response) -> Result<Vec<u8>> {
@@ -150,7 +150,9 @@ async fn verify_response(handler: &Handler, response: Response) -> Result<Vec<u8
150 150
         .to_str()
151 151
         .map_err(|_| ApiError::VerifySignatureHeader)
152 152
         .and_then(|header_str| {
153
-            base64::decode(header_str).map_err(|_| ApiError::VerifySignatureHeader)
153
+            BASE64_STANDARD_NO_PAD
154
+                .decode(header_str)
155
+                .map_err(|_| ApiError::VerifySignatureHeader)
154 156
         })
155 157
         .and_then(|bytes| {
156 158
             serde_json::from_slice::<SignatureHeader>(&bytes)

+ 38
- 4
web-client/src/lib.rs Ver arquivo

@@ -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
         };

+ 1
- 2
web-client/tests/integration.rs Ver arquivo

@@ -1,5 +1,4 @@
1
-use near_client::{crypto::prelude::*, prelude::*, Finality};
2
-use near_primitives_core::account::id::AccountId;
1
+use near_client::{near_units, prelude::*};
3 2
 use serde::{Deserialize, Serialize};
4 3
 use std::str::FromStr;
5 4
 use url::Url;

Carregando…
Cancelar
Salvar