From 3fb85ea8c7318659b50211c8d60e60b09329bd31 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Sun, 14 Jul 2024 19:44:40 +0300 Subject: [PATCH] error handling and sanitizing of string input for mnemonic and TextCode --- nextgraph/src/local_broker.rs | 2 +- ng-app/src/api.ts | 6 ++++-- ng-app/src/lib/Login.svelte | 2 +- ng-app/src/locales/en.json | 2 +- ng-app/src/routes/WalletLoginTextCode.svelte | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/nextgraph/src/local_broker.rs b/nextgraph/src/local_broker.rs index dac2265..23498e1 100644 --- a/nextgraph/src/local_broker.rs +++ b/nextgraph/src/local_broker.rs @@ -1728,7 +1728,7 @@ lazy_static! { /// with the help of the function [wallet_open_with_pazzle_words] /// followed by [wallet_import] pub async fn wallet_import_from_code(code: String) -> Result { - let qr = NgQRCode::from_code(code)?; + let qr = NgQRCode::from_code(code.trim().to_string())?; match qr { NgQRCode::WalletTransferV0(NgQRCodeWalletTransferV0 { broker, diff --git a/ng-app/src/api.ts b/ng-app/src/api.ts index e5db6e9..05e13d2 100644 --- a/ng-app/src/api.ts +++ b/ng-app/src/api.ts @@ -215,11 +215,13 @@ const handler = { return await tauri.invoke(path[0],arg) } }catch (e) { + let error; try { - throw JSON.parse(e); + error = JSON.parse(e); } catch (f) { - throw e; + error = e; } + throw error; } } }, diff --git a/ng-app/src/lib/Login.svelte b/ng-app/src/lib/Login.svelte index 9afdc07..2a563a4 100644 --- a/ng-app/src/lib/Login.svelte +++ b/ng-app/src/lib/Login.svelte @@ -169,7 +169,7 @@ pazzle.push((emoji.cat << 4) + emoji.index); } - const mnemonic_words = mnemonic.split(" "); + const mnemonic_words = mnemonic.split(" ").filter((t) => t !== ""); // open the wallet try { diff --git a/ng-app/src/locales/en.json b/ng-app/src/locales/en.json index cc992e4..5611913 100644 --- a/ng-app/src/locales/en.json +++ b/ng-app/src/locales/en.json @@ -297,7 +297,7 @@ "AlreadyExists": "The user is already registered with the selected broker.
Try logging in instead.", "InvalidSignature": "The signature is invalid.", "IncompleteSignature": "The signature is incomplete.", - "SerializationError": "The object could not be serialized.", + "SerializationError": "The data could not be serialized.", "EncryptionError": "Your wallet could not be opened. You probably did a mistake.", "DecryptionError": "Error with decryption.", "InvalidValue": "The value is invalid.", diff --git a/ng-app/src/routes/WalletLoginTextCode.svelte b/ng-app/src/routes/WalletLoginTextCode.svelte index 38c6982..ff29c1d 100644 --- a/ng-app/src/routes/WalletLoginTextCode.svelte +++ b/ng-app/src/routes/WalletLoginTextCode.svelte @@ -99,7 +99,7 @@