diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 11f294f..bc0895c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1998,12 +1998,6 @@ dependencies = [ "opaque-debug", ] -[[package]] -name = "md5" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" - [[package]] name = "memchr" version = "2.5.0" @@ -4361,7 +4355,6 @@ dependencies = [ "coingecko", "lazy_static", "magic-crypt", - "md5", "okex", "rand 0.3.23", "reqwest", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c97e71f..0202afd 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -27,7 +27,6 @@ tauri = {version = "1.2", features = ["app-all", "dialog-open", "dialog-save", " tokio = {version = "1", features = ["sync"] } uuid = "1.3.3" tauri-plugin-aptabase = "0.3" -md5 = "0.7.0" reqwest = "0.11.22" [features] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 938c0db..b588f04 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,6 +1,6 @@ #[macro_use] extern crate lazy_static; -use std::{collections::HashMap, fs}; +use std::{collections::HashMap}; use tauri::Manager; use track3::{ @@ -131,16 +131,6 @@ fn decrypt(data: String) -> Result { } } -#[cfg_attr( - all(not(debug_assertions), target_os = "windows"), - windows_subsystem = "windows" -)] -#[tauri::command] -fn md5(data: String) -> Result { - let digest = md5::compute(data.as_bytes()); - Ok(format!("{:x}", digest)) -} - #[cfg_attr( all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows" @@ -225,7 +215,6 @@ fn main() { query_okex_balance, encrypt, decrypt, - md5, download_coins_logos, open_debank_window_in_background, close_debank_window, diff --git a/src/middlelayers/data.ts b/src/middlelayers/data.ts index 6d523eb..34dad51 100644 --- a/src/middlelayers/data.ts +++ b/src/middlelayers/data.ts @@ -16,12 +16,13 @@ import { AssetPriceModel, ExportAssetModel, HistoricalData } from './types' import { exportConfigurationString, importRawConfiguration } from './configuration' import { ASSET_HANDLER } from './entities/assets' import { ASSET_PRICE_HANDLER } from './entities/asset-prices' +import md5 from 'md5' type ExportData = { exportAt: string configuration?: string historicalData: Pick[] - md5: string + md5V2: string } // TODO: query by token address not symbol, because there are multiple coins with same symbol @@ -102,9 +103,11 @@ export async function exportHistoricalData(exportConfiguration = false): Promise configuration: cfg } + const md5Payload = { data: JSON.stringify(exportData) } + const content = JSON.stringify({ ...exportData, - md5: await invoke("md5", { data: JSON.stringify(exportData) }), + md5V2: md5(JSON.stringify(md5Payload)), } as ExportData) // save to filePath @@ -126,14 +129,15 @@ export async function importHistoricalData(): Promise { } const contents = await readTextFile(selected as string) - const { exportAt, md5, configuration, historicalData } = JSON.parse(contents) as ExportData + const { exportAt, md5V2: md5Str, configuration, historicalData } = JSON.parse(contents) as ExportData // !compatible with older versions logic ( before 0.3.3 ) - if (md5) { + if (md5Str) { // verify md5 // todo: use md5 in typescript - const currentMd5 = await invoke("md5", { data: JSON.stringify({ exportAt, historicalData, configuration }) }) - if (currentMd5 !== md5) { + const md5Payload = { data: JSON.stringify({ exportAt, historicalData, configuration }) } + const currentMd5 = md5(JSON.stringify(md5Payload)) + if (currentMd5 !== md5Str) { throw new Error("invalid data, md5 check failed: errorCode 000") } }