From bfa88bfcfd95d66417ba9444bee9551f87860fa1 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Mon, 3 Jul 2023 23:02:07 +0300 Subject: [PATCH] ClientInfo --- Cargo.lock | 47 + Cargo.toml | 1 + ng-app/README.md | 6 + ng-app/package.json | 1 + ng-app/src-tauri/Cargo.toml | 1 + ng-app/src-tauri/src/lib.rs | 10 +- ng-app/src/api.ts | 49 +- ng-app/src/routes/Grid.svelte | 10 +- ng-app/src/routes/Install.svelte | 10 +- ng-app/src/routes/WalletCreate.svelte | 445 +++- ng-app/src/styles.css | 4 + ng-sdk-js/README.md | 23 +- ng-sdk-js/app-node/index.js | 2 +- ng-sdk-js/js/bowser.js | 2233 +++++++++++++++++++++ ng-sdk-js/js/browser.js | 17 +- ng-sdk-js/js/node.js | 122 +- ng-sdk-js/src/lib.rs | 91 +- ng-wallet/src/lib.rs | 54 +- ng-wallet/src/types.rs | 64 +- ngaccount/Cargo.toml | 28 + ngaccount/README.md | 37 + ngaccount/src/main.rs | 82 + ngaccount/src/types.rs | 30 + ngaccount/web/.gitignore | 24 + ngaccount/web/.vscode/extensions.json | 3 + ngaccount/web/index.html | 61 + ngaccount/web/jsconfig.json | 32 + ngaccount/web/package.json | 27 + ngaccount/web/pnpm-lock.yaml | 1310 ++++++++++++ ngaccount/web/postcss.config.cjs | 13 + ngaccount/web/public/robots.txt | 2 + ngaccount/web/public/vite.svg | 1 + ngaccount/web/src/App.svelte | 26 + ngaccount/web/src/app.postcss | 4 + ngaccount/web/src/assets/EU.svg | 4 + ngaccount/web/src/assets/nextgraph.svg | 16 + ngaccount/web/src/main.js | 9 + ngaccount/web/src/routes/Home.svelte | 27 + ngaccount/web/src/routes/NotFound.svelte | 20 + ngaccount/web/src/vite-env.d.ts | 2 + ngaccount/web/svelte.config.js | 7 + ngaccount/web/tailwind.config.cjs | 23 + ngaccount/web/vite.config.js | 36 + ngd/src/cli.rs | 8 + ngd/src/main.rs | 9 + ngone/README.md | 13 +- ngone/src/main.rs | 5 +- ngone/web/src/routes/WalletCreate.svelte | 6 +- p2p-broker/src/broker_store/account.rs | 186 +- p2p-broker/src/broker_store/invitation.rs | 157 ++ p2p-broker/src/broker_store/mod.rs | 4 +- p2p-broker/src/broker_store/overlay.rs | 4 +- p2p-broker/src/broker_store/topic.rs | 2 +- p2p-broker/src/lib.rs | 2 + p2p-broker/src/server_ws.rs | 83 +- p2p-broker/src/storage.rs | 37 + p2p-broker/src/types.rs | 10 + p2p-net/Cargo.toml | 3 +- p2p-net/src/broker.rs | 7 + p2p-net/src/broker_storage.rs | 17 + p2p-net/src/lib.rs | 4 + p2p-net/src/types.rs | 287 ++- p2p-net/src/utils.rs | 56 + p2p-repo/src/errors.rs | 2 + p2p-repo/src/kcv_store.rs | 2 +- pnpm-lock.yaml | 8 + stores-lmdb/src/kcv_store.rs | 5 +- 67 files changed, 5674 insertions(+), 257 deletions(-) create mode 100644 ng-sdk-js/js/bowser.js create mode 100644 ngaccount/Cargo.toml create mode 100644 ngaccount/README.md create mode 100644 ngaccount/src/main.rs create mode 100644 ngaccount/src/types.rs create mode 100644 ngaccount/web/.gitignore create mode 100644 ngaccount/web/.vscode/extensions.json create mode 100644 ngaccount/web/index.html create mode 100644 ngaccount/web/jsconfig.json create mode 100644 ngaccount/web/package.json create mode 100644 ngaccount/web/pnpm-lock.yaml create mode 100644 ngaccount/web/postcss.config.cjs create mode 100644 ngaccount/web/public/robots.txt create mode 100644 ngaccount/web/public/vite.svg create mode 100644 ngaccount/web/src/App.svelte create mode 100644 ngaccount/web/src/app.postcss create mode 100755 ngaccount/web/src/assets/EU.svg create mode 100644 ngaccount/web/src/assets/nextgraph.svg create mode 100644 ngaccount/web/src/main.js create mode 100644 ngaccount/web/src/routes/Home.svelte create mode 100644 ngaccount/web/src/routes/NotFound.svelte create mode 100644 ngaccount/web/src/vite-env.d.ts create mode 100644 ngaccount/web/svelte.config.js create mode 100644 ngaccount/web/tailwind.config.cjs create mode 100644 ngaccount/web/vite.config.js create mode 100644 p2p-broker/src/broker_store/invitation.rs create mode 100644 p2p-broker/src/storage.rs create mode 100644 p2p-net/src/broker_storage.rs diff --git a/Cargo.lock b/Cargo.lock index cb9e557..928508d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2736,6 +2736,7 @@ dependencies = [ "serde_json", "tauri", "tauri-build", + "tauri-plugin-window", ] [[package]] @@ -2787,6 +2788,30 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ngaccount" +version = "0.1.0" +dependencies = [ + "base64-url", + "bytes", + "env_logger", + "log", + "ng-wallet", + "p2p-net", + "p2p-repo", + "rust-embed", + "serde", + "serde-big-array", + "serde_bare", + "serde_bytes", + "serde_json", + "slice_as_array", + "stores-lmdb", + "tokio", + "warp", + "warp-embed", +] + [[package]] name = "ngcli" version = "0.1.0" @@ -3024,6 +3049,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "111.26.0+1.1.1u" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efc62c9f12b22b8f5208c23a7200a442b2e5999f8bdf80233852122b5a4f6f37" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.90" @@ -3032,6 +3066,7 @@ checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] @@ -3129,6 +3164,7 @@ dependencies = [ "unique_id", "url", "wasm-bindgen", + "web-time", ] [[package]] @@ -4629,6 +4665,17 @@ dependencies = [ "tauri-utils", ] +[[package]] +name = "tauri-plugin-window" +version = "2.0.0-alpha.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "209fef1a00a981949e2440924b4be267c7639daeba51b29179004fa1c6d74900" +dependencies = [ + "serde", + "tauri", + "thiserror", +] + [[package]] name = "tauri-runtime" version = "0.13.0-alpha.6" diff --git a/Cargo.toml b/Cargo.toml index e3b7c21..56d8f5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "ngcli", "ngd", "ngone", + "ngaccount", "ng-sdk-js", "ng-app/src-tauri", "ng-wallet" diff --git a/ng-app/README.md b/ng-app/README.md index 77d2e1a..b7b3309 100644 --- a/ng-app/README.md +++ b/ng-app/README.md @@ -101,6 +101,12 @@ rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-andro - follow the steps for Android in the [Prerquisites guide of Tauri](https://next--tauri.netlify.app/next/guides/getting-started/prerequisites/) +Until I find out how to do this properly, if you are compiling the android app from a macos station, you need to override an env var. this is due to reqwest needing SSL support, and on linux and android it compiles it from source. apparently the compiler (cc-rs) doesn't know that when cross compiling to android targets, the tool ranlib is called llvm-ranlib (and not [target]-ranlib) + +``` +export RANLIB=/Users/[user]/Library/Android/sdk/ndk/[yourNDKversion]/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ranlib +``` + to launch the dev app : ``` diff --git a/ng-app/package.json b/ng-app/package.json index 690b53e..61a2d7b 100644 --- a/ng-app/package.json +++ b/ng-app/package.json @@ -17,6 +17,7 @@ "dependencies": { "@popperjs/core": "^2.11.8", "@tauri-apps/api": "2.0.0-alpha.4", + "@tauri-apps/plugin-window": "2.0.0-alpha.0", "async-proxy": "^0.4.1", "classnames": "^2.3.2", "flowbite": "^1.6.5", diff --git a/ng-app/src-tauri/Cargo.toml b/ng-app/src-tauri/Cargo.toml index b8d82b6..b2f7c6a 100644 --- a/ng-app/src-tauri/Cargo.toml +++ b/ng-app/src-tauri/Cargo.toml @@ -24,6 +24,7 @@ p2p-repo = { path = "../../p2p-repo" } p2p-net = { path = "../../p2p-net" } ng-wallet = { path = "../../ng-wallet" } async-std = { version = "1.12.0", features = ["attributes","unstable"] } +tauri-plugin-window = "2.0.0-alpha" [features] # this feature is used for production builds or when `devPath` points to the filesystem diff --git a/ng-app/src-tauri/src/lib.rs b/ng-app/src-tauri/src/lib.rs index 1e77b6c..d0f62d0 100644 --- a/ng-app/src-tauri/src/lib.rs +++ b/ng-app/src-tauri/src/lib.rs @@ -13,7 +13,7 @@ use p2p_net::broker::*; use p2p_net::utils::{spawn_and_log_error, Receiver, ResultSend}; use p2p_repo::log::*; use p2p_repo::types::*; -use tauri::{App, Manager}; +use tauri::{App, Manager, Window}; #[cfg(mobile)] mod mobile; @@ -78,6 +78,7 @@ async fn wallet_create_wallet(mut params: CreateWalletV0) -> Result Result<(), ()> { log_info!("doc_sync_branch {} {}", nuri, stream_id); + let main_window = app.get_window("main").unwrap(); let mut reader; { @@ -91,10 +92,10 @@ async fn doc_sync_branch(nuri: &str, stream_id: &str, app: tauri::AppHandle) -> async fn inner_task( mut reader: Receiver, stream_id: String, - app: tauri::AppHandle, + main_window: tauri::Window, ) -> ResultSend<()> { while let Some(commit) = reader.next().await { - app.emit_all(&stream_id, commit).unwrap(); + main_window.emit(&stream_id, commit).unwrap(); } BROKER.write().await.tauri_stream_cancel(stream_id); @@ -103,7 +104,7 @@ async fn doc_sync_branch(nuri: &str, stream_id: &str, app: tauri::AppHandle) -> Ok(()) } - spawn_and_log_error(inner_task(reader, stream_id.to_string(), app)); + spawn_and_log_error(inner_task(reader, stream_id.to_string(), main_window)); Ok(()) } @@ -173,6 +174,7 @@ impl AppBuilder { Ok(()) }) + .plugin(tauri_plugin_window::init()) .invoke_handler(tauri::generate_handler![ test, doc_sync_branch, diff --git a/ng-app/src/api.ts b/ng-app/src/api.ts index d187782..9b2d0d4 100644 --- a/ng-app/src/api.ts +++ b/ng-app/src/api.ts @@ -8,6 +8,8 @@ // according to those terms. import {createAsyncProxy} from "async-proxy"; import { writable } from "svelte/store"; +import { Bowser } from "../../ng-sdk-js/js/bowser.js"; +import {version} from '../package.json'; const mapping = { @@ -26,18 +28,51 @@ const handler = { if (import.meta.env.NG_APP_WEB) { let sdk = await import("ng-sdk-js") - return Reflect.apply(sdk[path], caller, args) + if (path[0] === "client_info") { + let client_info = await Reflect.apply(sdk[path], caller, args); + client_info.version=version; + //console.log(client_info); + return client_info; + } else { + return Reflect.apply(sdk[path], caller, args) + } } else { let tauri = await import("@tauri-apps/api/tauri"); + if (path[0] === "client_info") { - if (path[0] === "doc_sync_branch") { + let tauri_platform = import.meta.env.TAURI_PLATFORM; + let client_type; + switch (tauri_platform) { + case 'macos': client_type = "NativeMacOS";break; + case 'linux': client_type = "NativeLinux";break; + case 'windows': client_type = "NativeWindows";break; + case 'android': client_type = "NativeAndroid";break; + case 'ios': client_type = "NativeIos";break; + } + let info = Bowser.parse(window.navigator.userAgent); + info.platform.arch = import.meta.env.TAURI_ARCH; + info.platform.tauri = { + family: import.meta.env.TAURI_FAMILY, + os_version: import.meta.env.TAURI_PLATFORM_VERSION, + type: import.meta.env.TAURI_PLATFORM_TYPE, + debug: import.meta.env.TAURI_DEBUG, + target: import.meta.env.TAURI_TARGET_TRIPLE + }; + info.browser.ua = window.navigator.userAgent; + let res = { + // TODO: install timestamp + ClientInfoV0 : { client_type, details: JSON.stringify(info), version, timestamp_install:0, timestamp_updated:0 } + }; + //console.log(res); + return res; + } else if (path[0] === "doc_sync_branch") { let stream_id = (lastStreamId += 1).toString(); console.log("stream_id",stream_id); - let { listen } = await import("@tauri-apps/api/event"); + let { appWindow } = await import("@tauri-apps/plugin-window"); let nuri = args[0]; let callback = args[1]; - let unlisten = await listen(stream_id, (event) => { + let unlisten = await appWindow.listen(stream_id, (event) => { callback(event.payload).then(()=> {}) }) await tauri.invoke("doc_sync_branch",{nuri, stream_id}); @@ -58,6 +93,8 @@ const handler = { params.result_with_wallet_file = false; params.security_img = Array.from(new Uint8Array(params.security_img)); return await tauri.invoke(path[0],{params}) + } else if (path[0] === "get_local_bootstrap") { + return false; } else { let arg = {}; @@ -70,4 +107,8 @@ const handler = { const api = createAsyncProxy({}, handler); +export const NG_EU_BSP = "https://nextgraph.eu"; + +export const NG_NET_BSP = "https://nextgraph.net"; + export default api; \ No newline at end of file diff --git a/ng-app/src/routes/Grid.svelte b/ng-app/src/routes/Grid.svelte index 235b5ff..87e8312 100644 --- a/ng-app/src/routes/Grid.svelte +++ b/ng-app/src/routes/Grid.svelte @@ -55,16 +55,10 @@ security_txt: " know yourself ", pin: [5, 2, 9, 1], pazzle_length: 9, - send_bootstrap: undefined, + send_bootstrap: false, send_wallet: false, result_with_wallet_file: true, - peer_id: { - Ed25519PubKey: [ - 119, 251, 253, 29, 135, 199, 254, 50, 134, 67, 1, 208, 117, 196, 167, - 107, 2, 113, 98, 243, 49, 90, 7, 0, 157, 58, 14, 187, 14, 3, 116, 86, - ], - }, - nonce: 0, + local_save: false, }; try { diff --git a/ng-app/src/routes/Install.svelte b/ng-app/src/routes/Install.svelte index 5761e9d..df77f23 100644 --- a/ng-app/src/routes/Install.svelte +++ b/ng-app/src/routes/Install.svelte @@ -78,7 +78,7 @@
- +
+ {:else if !invitation} +
+

+ NextGraph is based on an efficient decentralized P2P network, and in + order to join this network and start using the app, you need to first + select a broker server. +

+
+
+
+

+ What is a broker? Please read +

+
    +
  • + + + The broker helps you keep all your data in sync, as it is + connected to the internet 24/7 and keeps a copy of the updates for + you. This way, even if the devices of the other participants are + offline, you can still see their changes +
  • +
  • + + + All your data is secure and end-to-end encrypted, and the + broker cannot see the content of the documents as it does not have + the keys to decrypt them. +
  • +
  • + + + The broker helps you enforce your privacy as it hides your internet + address (IP) from other users you share documents with. +
  • +
  • + + + + It will be possible in the future to use NextGraph without any + broker and to have direct connections between peers, but this will + imply a less smooth experience. +
  • +
  • + + + At anytime you can decide to switch to another broker service + provider or host it yourself. Your data is totally portable + and can freely move to another broker. +
  • +
  • + + + + Very soon we will offer you the opportunity to host your own + broker at home or office. Instead of using a "broker + service provider", you will own a small device that you connect + behind your internet router. It is called NG Box and will be + available soon. +
  • +
  • + + + + Large organizations and companies have the opportunity to host a + broker on-premise or in the cloud, as the software is open + source. Individuals can also self-host a broker on any VPS server + or at home. +
  • +
+

Please choose one broker among the list

+
+
+
+ {#if !tauri_platform} + + + + {:else} + + {/if} +
+ +
+ {#if !tauri_platform} + + + + {:else} + + {/if} +
+ +
+ +
+ {#if mobile} +
+ +
+ {/if} + + {:else if pin.length < 4}

Let's start by choosing a PIN code - We recommend you to choose a PIN code that you already know very well - :
- your credit card PIN, by example, is a good choice + We recommend you to choose a PIN code that you already know very well. +
+ Your credit card PIN, by example, is a good choice. (We at NextGraph will + never see your PIN)

Here are the rules for the PIN :

@@ -610,7 +984,7 @@
- +