From 32fffcb947512531bd227caa347515cd3429ce99 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Tue, 23 Apr 2024 02:03:06 +0300 Subject: [PATCH] all events of wallet creation (3P site) sent to broker --- Cargo.lock | 2 +- nextgraph/examples/open.rs | 4 +- nextgraph/src/local_broker.rs | 60 +- ng-app/src/routes/WalletCreate.svelte | 13 +- ng-broker/src/broker_storage/invitation.rs | 2 +- ng-broker/src/server_storage.rs | 24 +- ng-client-ws/src/remote_ws.rs | 5 +- ng-client-ws/src/remote_ws_wasm.rs | 2 +- ng-net/Cargo.toml | 1 - ng-net/src/actor.rs | 36 +- ng-net/src/actors/add_invitation.rs | 6 +- ng-net/src/actors/add_user.rs | 6 +- ng-net/src/actors/client/event.rs | 82 +++ ng-net/src/actors/client/mod.rs | 2 + ng-net/src/actors/client/pin_repo.rs | 21 +- ng-net/src/actors/client/repo_pin_status.rs | 16 +- ng-net/src/actors/client/topic_sub.rs | 19 +- ng-net/src/actors/connecting.rs | 7 +- ng-net/src/actors/del_user.rs | 5 +- ng-net/src/actors/list_invitations.rs | 6 +- ng-net/src/actors/list_users.rs | 6 +- ng-net/src/actors/noise.rs | 3 +- ng-net/src/actors/probe.rs | 3 +- ng-net/src/actors/start.rs | 9 +- ng-net/src/broker.rs | 17 +- ng-net/src/broker_connection.rs | 343 ------------ ng-net/src/connection.rs | 20 +- ng-net/src/errors.rs | 154 +---- ng-net/src/server_storage.rs | 12 +- ng-net/src/types.rs | 64 ++- ng-repo/Cargo.toml | 1 + ng-repo/src/branch.rs | 18 +- ng-repo/src/commit.rs | 15 - ng-repo/src/errors.rs | 178 +++++- ng-repo/src/file.rs | 15 - ng-repo/src/repo.rs | 11 + ng-repo/src/store.rs | 365 ++++++++---- ng-repo/src/types.rs | 50 +- ng-storage-rocksdb/src/kcv_storage.rs | 15 +- ng-verifier/src/site.rs | 116 +++- ng-verifier/src/types.rs | 3 +- ng-verifier/src/user_storage/branch.rs | 39 +- ng-verifier/src/user_storage/repo.rs | 77 ++- ng-verifier/src/verifier.rs | 139 +++-- ngcli/src/main.rs | 2 +- ngcli/src/old.rs | 587 -------------------- 46 files changed, 1148 insertions(+), 1433 deletions(-) create mode 100644 ng-net/src/actors/client/event.rs delete mode 100644 ng-net/src/broker_connection.rs delete mode 100644 ngcli/src/old.rs diff --git a/Cargo.lock b/Cargo.lock index 829a076..806147a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3326,7 +3326,6 @@ dependencies = [ "ng-repo", "noise-protocol", "noise-rust-crypto", - "num_enum", "once_cell", "reqwest", "serde", @@ -3355,6 +3354,7 @@ dependencies = [ "gloo-timers", "hex", "log", + "num_enum", "once_cell", "os_info", "rand 0.7.3", diff --git a/nextgraph/examples/open.rs b/nextgraph/examples/open.rs index 6c3cefc..8bc6293 100644 --- a/nextgraph/examples/open.rs +++ b/nextgraph/examples/open.rs @@ -37,7 +37,7 @@ async fn main() -> std::io::Result<()> { })) .await; - let wallet_name = "hQK0RBKua5TUm2jqeSGPOMMzqplllAkbUgEh5P6Otf4".to_string(); + let wallet_name = "9ivXl3TpgcQlDKTmR9NOipjhPWxQw6Yg5jkWBTlJuXw".to_string(); // as we have previously saved the wallet, // we can retrieve it, display the security phrase and image to the user, ask for the pazzle or mnemonic, and then open the wallet @@ -48,7 +48,7 @@ async fn main() -> std::io::Result<()> { // now let's open the wallet, by providing the pazzle and PIN code let opened_wallet = wallet_open_with_pazzle( &wallet, - vec![134, 54, 112, 46, 94, 65, 20, 2, 99], + vec![110, 139, 115, 94, 9, 40, 74, 25, 52], [2, 3, 2, 3], )?; diff --git a/nextgraph/src/local_broker.rs b/nextgraph/src/local_broker.rs index e21c3c2..78764a3 100644 --- a/nextgraph/src/local_broker.rs +++ b/nextgraph/src/local_broker.rs @@ -12,7 +12,6 @@ use async_std::sync::{Arc, Mutex, RwLock, RwLockReadGuard}; use core::fmt; use ng_net::actor::EActor; use ng_net::connection::{ClientConfig, IConnect, NoiseFSM, StartConfig}; -use ng_net::errors::ProtocolError; use ng_net::types::{ClientInfo, ClientType, ProtocolMessage}; use ng_net::utils::{Receiver, Sender}; use ng_repo::block_storage::HashMapBlockStorage; @@ -30,7 +29,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop}; use ng_net::broker::*; use ng_repo::block_storage::BlockStorage; -use ng_repo::errors::NgError; +use ng_repo::errors::{NgError, ProtocolError}; use ng_repo::log::*; use ng_repo::types::*; use ng_repo::utils::derive_key; @@ -1424,6 +1423,7 @@ mod test { }; use ng_net::types::BootstrapContentV0; use ng_wallet::{display_mnemonic, emojis::display_pazzle}; + use std::env::current_dir; use std::fs::read_to_string; use std::fs::{create_dir_all, File}; use std::io::BufReader; @@ -1537,6 +1537,62 @@ mod test { file.write_all(&ser).expect("write of opened_wallet file"); } + #[async_std::test] + async fn gen_opened_wallet_file_for_test_with_pazzle_array() { + let wallet_file = read("tests/wallet.ngw").expect("read wallet file"); + + init_local_broker(Box::new(|| LocalBrokerConfig::InMemory)).await; + + let wallet = wallet_read_file(wallet_file) + .await + .expect("wallet_read_file"); + + let pazzle = vec![114, 45, 86, 104, 1, 135, 17, 50, 65]; + let opened_wallet = + wallet_open_with_pazzle(&wallet, pazzle, [2, 3, 2, 3]).expect("opening of wallet"); + + let mut file = + File::create("tests/opened_wallet.ngw").expect("open for write opened_wallet file"); + let ser = serde_bare::to_vec(&opened_wallet).expect("serialization of opened wallet"); + + file.write_all(&ser).expect("write of opened_wallet file"); + } + + #[async_std::test] + async fn import_session_for_test_to_disk() { + let wallet_file = read("tests/wallet.ngw").expect("read wallet file"); + let opened_wallet_file = read("tests/opened_wallet.ngw").expect("read opened_wallet file"); + let opened_wallet: SensitiveWallet = + serde_bare::from_slice(&opened_wallet_file).expect("deserialization of opened_wallet"); + + let mut current_path = current_dir().expect("cur_dir"); + current_path.push(".."); + current_path.push(".ng"); + current_path.push("example"); + create_dir_all(current_path.clone()).expect("create_dir"); + + // initialize the local_broker with config to save to disk in a folder called `.ng/example` in the current directory + init_local_broker(Box::new(move || { + LocalBrokerConfig::BasePath(current_path.clone()) + })) + .await; + + let wallet = wallet_read_file(wallet_file) + .await + .expect("wallet_read_file"); + + let wallet_name = wallet.name(); + let user_id = opened_wallet.personal_identity(); + + let _client = wallet_import(wallet, opened_wallet, false) + .await + .expect("wallet_import"); + + let _session = session_start(SessionConfig::new_in_memory(&user_id, &wallet_name)) + .await + .expect(""); + } + async fn import_session_for_test() -> (UserId, String) { let wallet_file = read("tests/wallet.ngw").expect("read wallet file"); let opened_wallet_file = read("tests/opened_wallet.ngw").expect("read opened_wallet file"); diff --git a/ng-app/src/routes/WalletCreate.svelte b/ng-app/src/routes/WalletCreate.svelte index 480da94..feaa396 100644 --- a/ng-app/src/routes/WalletCreate.svelte +++ b/ng-app/src/routes/WalletCreate.svelte @@ -245,7 +245,7 @@ window.wallet_channel.postMessage(new_in_mem, location.href); } } - + console.log(ready.pazzle); console.log(display_pazzle(ready.pazzle)); download_name = "wallet-" + ready.wallet_name + ".ngw"; if (options.cloud) { @@ -1207,10 +1207,12 @@ would be the victim of a phishing attempt.

-

+

Here are the rules for the security phrase and image :

-