get_device_name

pull/31/head
Niko PLP 4 months ago
parent a29db952e2
commit ee385cbdfe
  1. 27
      Cargo.lock
  2. 1
      nextgraph/Cargo.toml
  3. 31
      nextgraph/src/lib.rs
  4. 11
      ng-app/src-tauri/src/lib.rs
  5. 1
      ng-app/src/api.ts
  6. 13
      ng-app/src/lib/Login.svelte
  7. 5
      ng-app/src/locales/en.json
  8. 13
      ng-app/src/routes/WalletCreate.svelte
  9. 5
      ng-sdk-js/src/lib.rs

27
Cargo.lock generated

@ -3274,6 +3274,7 @@ dependencies = [
"serde_bare", "serde_bare",
"serde_json", "serde_json",
"web-time", "web-time",
"whoami",
"zeroize", "zeroize",
] ]
@ -4608,6 +4609,15 @@ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
] ]
[[package]]
name = "redox_syscall"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags 1.3.2",
]
[[package]] [[package]]
name = "redox_users" name = "redox_users"
version = "0.4.3" version = "0.4.3"
@ -6325,6 +6335,12 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasite"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.87" version = "0.2.87"
@ -6540,6 +6556,17 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
[[package]]
name = "whoami"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9"
dependencies = [
"redox_syscall 0.4.1",
"wasite",
"web-sys",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

@ -26,6 +26,7 @@ async-std = { version = "1.12.0", features = [ "attributes", "unstable" ] }
async-trait = "0.1.64" async-trait = "0.1.64"
async-once-cell = "0.5.3" async-once-cell = "0.5.3"
web-time = "0.2.0" web-time = "0.2.0"
whoami = "1.5.1"
ng-repo = { path = "../ng-repo", version = "0.1.0-preview.1" } ng-repo = { path = "../ng-repo", version = "0.1.0-preview.1" }
ng-net = { path = "../ng-net", version = "0.1.0-preview.1" } ng-net = { path = "../ng-net", version = "0.1.0-preview.1" }
ng-wallet = { path = "../ng-wallet", version = "0.1.0-preview.5" } ng-wallet = { path = "../ng-wallet", version = "0.1.0-preview.5" }

@ -98,3 +98,34 @@ pub mod verifier {
pub mod wallet { pub mod wallet {
pub use ng_wallet::*; pub use ng_wallet::*;
} }
pub fn get_device_name() -> String {
let mut list: Vec<String> = Vec::with_capacity(3);
#[cfg(not(target_arch = "wasm32"))]
if let Ok(realname) = whoami::fallible::realname() {
list.push(realname);
} else {
#[cfg(not(target_arch = "wasm32"))]
if let Ok(username) = whoami::fallible::username() {
list.push(username);
}
}
if let Ok(devicename) = whoami::fallible::devicename() {
list.push(devicename);
} else {
#[cfg(not(target_arch = "wasm32"))]
if let Ok(hostname) = whoami::fallible::hostname() {
list.push(hostname);
} else {
if let Ok(distro) = whoami::fallible::distro() {
list.push(distro);
}
}
}
#[cfg(target_arch = "wasm32")]
if let Ok(distro) = whoami::fallible::distro() {
list.push(distro);
}
list.join(" ")
}

@ -127,8 +127,9 @@ async fn wallet_open_with_mnemonic_words(
pin: [u8; 4], pin: [u8; 4],
_app: tauri::AppHandle, _app: tauri::AppHandle,
) -> Result<SensitiveWallet, String> { ) -> Result<SensitiveWallet, String> {
let wallet = nextgraph::local_broker::wallet_open_with_mnemonic_words(&wallet, &mnemonic_words, pin) let wallet =
.map_err(|e| e.to_string())?; nextgraph::local_broker::wallet_open_with_mnemonic_words(&wallet, &mnemonic_words, pin)
.map_err(|e| e.to_string())?;
Ok(wallet) Ok(wallet)
} }
@ -491,6 +492,11 @@ fn client_info_rust() -> Result<Value, String> {
Ok(ng_repo::os_info::get_os_info()) Ok(ng_repo::os_info::get_os_info())
} }
#[tauri::command(rename_all = "snake_case")]
fn get_device_name() -> Result<String, String> {
Ok(nextgraph::get_device_name())
}
#[derive(Default)] #[derive(Default)]
pub struct AppBuilder { pub struct AppBuilder {
setup: Option<SetupHook>, setup: Option<SetupHook>,
@ -565,6 +571,7 @@ impl AppBuilder {
app_request_stream, app_request_stream,
app_request, app_request,
upload_chunk, upload_chunk,
get_device_name,
]) ])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");

@ -34,6 +34,7 @@ const mapping = {
"user_disconnect": ["user_id"], "user_disconnect": ["user_id"],
"app_request": ["request"], "app_request": ["request"],
"test": [ ], "test": [ ],
"get_device_name": [],
"doc_fetch_private_subscribe": [], "doc_fetch_private_subscribe": [],
"doc_fetch_repo_subscribe": ["repo_id"], "doc_fetch_repo_subscribe": ["repo_id"],
} }

@ -47,9 +47,13 @@
onMount(async () => { onMount(async () => {
loaded = false; loaded = false;
if (for_import) {
device_name = await ng.get_device_name();
}
load_svg(); load_svg();
//console.log(wallet); //console.log(wallet);
await init(); await init();
}); });
async function init() { async function init() {
@ -123,9 +127,6 @@
let device_name; let device_name;
// TODO: @niko Implement API
// ng.get_device_name().then((name) => (device_name = name));
function order() { function order() {
step = "order"; step = "order";
ordered = []; ordered = [];
@ -412,12 +413,10 @@
</label> </label>
<input <input
id="device-name-input" id="device-name-input"
disabled
bind:value={device_name} bind:value={device_name}
placeholder={$t("pages.login.device_name_placeholder")} placeholder={$t("pages.login.device_name_placeholder")}
type="text" type="text"
autocomplete="device-name" class="w-full mb-10 lg:px-8 mx-auto px-4 bg-gray-50 border border-gray-300 text-xs rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
class="w-full mb-4 lg:px-8 mx-auto px-4 cursor-not-allowed opacity-50 bg-gray-50 border border-gray-300 text-gray-900 text-xs rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
/> />
{/if} {/if}
@ -449,7 +448,7 @@
on:keypress={start_with_mnemonic} on:keypress={start_with_mnemonic}
role="link" role="link"
tabindex="0" tabindex="0"
class="mt-1 text-lg px-5 py-2.5 text-center inline-flex items-center mb-2 underline cursor-pointer" class="mt-1 text-lg px-5 py-2.5 text-center inline-flex items-center mb-10 underline cursor-pointer"
> >
{$t("pages.login.open_with_mnemonic")} {$t("pages.login.open_with_mnemonic")}
</span> </span>

@ -84,8 +84,8 @@
}, },
"trust_device_allow_cookies": "By selecting this option, you agree to saving some cookies on your browser.", "trust_device_allow_cookies": "By selecting this option, you agree to saving some cookies on your browser.",
"trust_device_yes": "Yes, save my wallet on this device", "trust_device_yes": "Yes, save my wallet on this device",
"device_name_label": "Name of device as seen on your other devices", "device_name_label": "Name of this device. You can edit it now",
"device_name_placeholder": "Display name of this device", "device_name_placeholder": "Enter name of this device",
"loading_pazzle": "Loading Pazzle", "loading_pazzle": "Loading Pazzle",
"open_with_pazzle": "Open With Pazzle", "open_with_pazzle": "Open With Pazzle",
"login_cancel": "Cancel Login", "login_cancel": "Cancel Login",
@ -194,7 +194,6 @@
"trust_description": "If you do, if this device is yours, or it is used by a few trusted persons of your family or workplace, and you would like to login again from this device in the future, then you can save your wallet on this device. To the contrary, if this device is public and shared by strangers, do not save your wallet here.", "trust_description": "If you do, if this device is yours, or it is used by a few trusted persons of your family or workplace, and you would like to login again from this device in the future, then you can save your wallet on this device. To the contrary, if this device is public and shared by strangers, do not save your wallet here.",
"trust_toggle": "Save my wallet on this device?", "trust_toggle": "Save my wallet on this device?",
"device_name_description": "To see which devices you are connected with, every device should have a name (e.g. Bob's laptop). Please enter it here.", "device_name_description": "To see which devices you are connected with, every device should have a name (e.g. Bob's laptop). Please enter it here.",
"device_name_placeholder": "Display name of this device",
"cloud": "Keep a copy in the cloud?", "cloud": "Keep a copy in the cloud?",
"cloud_description": "Are you afraid that you will loose the file containing your wallet? If this would happen, your wallet would be lost forever, together with all your documents. We can keep an encrypted copy of your wallet in our cloud. Only you will be able to download it with a special link. You would have to keep this link safely though. By selecting this option, you agree to the", "cloud_description": "Are you afraid that you will loose the file containing your wallet? If this would happen, your wallet would be lost forever, together with all your documents. We can keep an encrypted copy of your wallet in our cloud. Only you will be able to download it with a special link. You would have to keep this link safely though. By selecting this option, you agree to the",
"cloud_toggle": "Save my wallet in the cloud?", "cloud_toggle": "Save my wallet in the cloud?",

@ -141,9 +141,6 @@
let confirm_modal_open = false; let confirm_modal_open = false;
let device_name; let device_name;
// TODO @niko add API
// ng.get_device_name().then((name) => (device_name = name));
function scrollToTop() { function scrollToTop() {
top.scrollIntoView(); top.scrollIntoView();
} }
@ -226,6 +223,8 @@
} }
async function save_security() { async function save_security() {
device_name = await ng.get_device_name();
options = { options = {
trusted: true, trusted: true,
cloud: false, cloud: false,
@ -259,7 +258,7 @@
core_bootstrap: invitation.V0.bootstrap, core_bootstrap: invitation.V0.bootstrap,
core_registration, core_registration,
additional_bootstrap, additional_bootstrap,
device_name, //TODO: device_name,
}; };
//console.log("do wallet with params", params); //console.log("do wallet with params", params);
try { try {
@ -1441,14 +1440,12 @@
</p> </p>
<input <input
id="device-name-input" id="device-name-input"
disabled class="mt-2 bg-gray-50 border border-gray-300 text-xs rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
class="cursor-not-allowed opacity-50 mt-2 bg-gray-50 border border-gray-300 text-gray-900 text-xs rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
bind:value={device_name} bind:value={device_name}
placeholder={$t( placeholder={$t(
"pages.wallet_create.save_wallet_options.device_name_placeholder" "pages.login.device_name_placeholder"
)} )}
type="text" type="text"
autocomplete="device-name"
/> />
{/if} {/if}
<p class="max-w-xl md:mx-auto mt-10 lg:max-w-2xl text-left"> <p class="max-w-xl md:mx-auto mt-10 lg:max-w-2xl text-left">

@ -60,6 +60,11 @@ pub async fn locales() -> Result<JsValue, JsValue> {
Ok(serde_wasm_bindgen::to_value(&get_locales().collect::<Vec<_>>()).unwrap()) Ok(serde_wasm_bindgen::to_value(&get_locales().collect::<Vec<_>>()).unwrap())
} }
#[wasm_bindgen]
pub async fn get_device_name() -> Result<JsValue, JsValue> {
Ok(serde_wasm_bindgen::to_value(&nextgraph::get_device_name()).unwrap())
}
#[wasm_bindgen] #[wasm_bindgen]
pub async fn get_local_bootstrap(location: String, invite: JsValue) -> JsValue { pub async fn get_local_bootstrap(location: String, invite: JsValue) -> JsValue {
let res = retrieve_local_bootstrap(location, invite.as_string(), false).await; let res = retrieve_local_bootstrap(location, invite.as_string(), false).await;

Loading…
Cancel
Save