diff --git a/electron/ipcHandlers.ts b/electron/ipcHandlers.ts index 4ea0842..1fb2ed4 100644 --- a/electron/ipcHandlers.ts +++ b/electron/ipcHandlers.ts @@ -78,7 +78,7 @@ ipcMain.handle('wallet:checkKeystore', async () => { fs.statSync(path.join(walletDir, a)).mtime.getTime() )[0] - if (!newestFile) return { exists: false, filePath: null } + if (!newestFile?.length) return { exists: false, filePath: null } const resolvedPath = path.join(walletDir, newestFile) let minBlockHeight: number | null = null @@ -88,11 +88,10 @@ ipcMain.handle('wallet:checkKeystore', async () => { const data = JSON.parse(json) const height = data?.minBlockHeight - if (typeof height === 'number' && Number.isFinite(height)) { - minBlockHeight = height - } + if (Number.isFinite(height)) minBlockHeight = height } catch (error) { console.warn('Unable to read minBlockHeight from keystore:', error) + return { exists: true, filePath: resolvedPath } } return { exists: true, filePath: resolvedPath, minBlockHeight } @@ -137,37 +136,34 @@ ipcMain.handle( } ) -ipcMain.handle( - 'wallet:getMinBlockHeight', - async (_event, filePath: string | null) => { - if (!filePath) { - return { success: false, error: 'No keystore file path provided.', minBlockHeight: null } - } - - try { - const normalizedPath = path.isAbsolute(filePath) - ? filePath - : path.join(process.cwd(), filePath) - - if (!fs.existsSync(normalizedPath)) { - return { success: false, error: 'Keystore file not found.', minBlockHeight: null } - } - - const fileContents = fs.readFileSync(normalizedPath, 'utf-8') - const walletJson = JSON.parse(fileContents) - const height = walletJson?.minBlockHeight - - if (typeof height === 'number' && Number.isFinite(height)) { - return { success: true, minBlockHeight: height } - } - - return { success: true, minBlockHeight: null } - } catch (error) { - console.error('Error reading min block height:', error) - return { success: false, error: String(error), minBlockHeight: null } - } +ipcMain.handle('wallet:getMinBlockHeight', async (_event, filePath: string | null) => { + if (!filePath) { + return { success: false, error: 'No keystore file path provided.', minBlockHeight: null } } -) + + try { + const normalizedPath = path.isAbsolute(filePath) + ? filePath + : path.join(process.cwd(), filePath) + + if (!fs.existsSync(normalizedPath)) { + return { success: false, error: 'Keystore file not found.', minBlockHeight: null } + } + + const fileContents = fs.readFileSync(normalizedPath, 'utf-8') + const walletJson = JSON.parse(fileContents) + const height = walletJson?.minBlockHeight + + if (Number.isFinite(height)) { + return { success: true, minBlockHeight: height } + } + + return { success: true, minBlockHeight: null } + } catch (error) { + console.error('Error reading min block height:', error) + return { success: false, error: String(error), minBlockHeight: null } + } +}) ipcMain.handle('wallet:generateKeysFromSeed', async (_event, seedPhrase: string[]) => { try { @@ -188,7 +184,6 @@ ipcMain.handle('wallet:buildTransaction', async (_event, args) => { import.meta.env.VITE_APP_API, spendingKeyHex, inputAdditionRecords, - // pass minBlockHeight from args if provided, default 0 typeof args?.minBlockHeight === 'number' && Number.isFinite(args.minBlockHeight) ? args.minBlockHeight : 0, diff --git a/electron/utils/keystore.ts b/electron/utils/keystore.ts index ec17d98..aef9d3e 100644 --- a/electron/utils/keystore.ts +++ b/electron/utils/keystore.ts @@ -4,7 +4,6 @@ export async function encrypt(seed: string, password: string) { const salt = crypto.randomBytes(16) const iv = crypto.randomBytes(12) - // derive 32-byte key từ password const key = await new Promise((resolve, reject) => { crypto.scrypt(password, salt, 32, { N: 16384, r: 8, p: 1 }, (err, derivedKey) => { if (err) reject(err) diff --git a/packages/neptune-native-0.1.0.tgz b/packages/neptune-native-0.1.0.tgz deleted file mode 100644 index 7089c75..0000000 Binary files a/packages/neptune-native-0.1.0.tgz and /dev/null differ diff --git a/packages/neptune-native/neptune-native.win32-x64-msvc.node b/packages/neptune-native/neptune-native.win32-x64-msvc.node index 2ec83cf..c6188c4 100644 Binary files a/packages/neptune-native/neptune-native.win32-x64-msvc.node and b/packages/neptune-native/neptune-native.win32-x64-msvc.node differ diff --git a/src/App.vue b/src/App.vue index a06885c..66a2a72 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,4 @@