This commit is contained in:
rj
2025-10-24 16:59:59 +08:00
commit e463293b81
38 changed files with 10384 additions and 0 deletions

7
src-tauri/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas

7710
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

26
src-tauri/Cargo.toml Normal file
View File

@@ -0,0 +1,26 @@
[package]
name = "wallet-project"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "wallet_project_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
alloy = { version="1.0.41" ,features = ["full"] }
anyhow = "1.0.52"

3
src-tauri/build.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() {
// tauri_build::build()
}

View File

@@ -0,0 +1,10 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"opener:default"
],
}

BIN
src-tauri/icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

47
src-tauri/src/lib.rs Normal file
View File

@@ -0,0 +1,47 @@
mod pri_key;
mod task;
use alloy::network::{AnyNetwork, EthereumWallet, NetworkWallet};
use alloy::signers::local::PrivateKeySigner;
use serde::Serializer;
pub type AppResult<T> =Result<T,AppError>;
#[derive(Debug)]
pub struct AppError(anyhow::Error);
impl serde::Serialize for AppError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer
{
serializer.serialize_str(self.0.to_string().as_ref())
}
}
impl<E> From<E> for AppError
where
E: Into<anyhow::Error>,
{
fn from(err: E) -> Self {
Self(err.into())
}
}
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[tauri::command]
async fn test(key:&str) -> AppResult<String> {
let signer: PrivateKeySigner = key.parse()?;
let ethereum_wallet = EthereumWallet::from(signer);
let bytes = <EthereumWallet as NetworkWallet<AnyNetwork>>::default_signer_address(&ethereum_wallet);
Ok(format!("address:{}", bytes.to_string()))
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![greet,test])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
src-tauri/src/main.rs Normal file
View File

@@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
wallet_project_lib::run()
}

59
src-tauri/src/pri_key.rs Normal file
View File

@@ -0,0 +1,59 @@
use crate::AppResult;
use alloy::network::{AnyNetwork, EthereumWallet, NetworkWallet};
use alloy::signers::local::PrivateKeySigner;
use std::fmt::{Debug, Display};
pub struct PriKey {
pub keys: [u8;64],
}
impl PriKey {
pub fn change_value(&mut self, position: usize, value: u8) {
self.keys[position] = value;
}
pub fn get_address(&self) ->AppResult<String>{
let signer: PrivateKeySigner = self.to_string().parse()?;
let ethereum_wallet = EthereumWallet::from(signer);
let bytes = <EthereumWallet as NetworkWallet<AnyNetwork>>::default_signer_address(&ethereum_wallet);
Ok(bytes.to_string())
}
}
impl Debug for PriKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", String::from_utf8_lossy(&self.keys))
}
}
impl Display for PriKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", String::from_utf8_lossy(&self.keys))
}
}
impl From<String> for PriKey{
fn from(key: String) -> Self {
let x: [u8; 64] = key.into_bytes().try_into().unwrap();
PriKey{
keys: x
}
}
}
impl From<&str> for PriKey{
fn from(key: &str) -> Self {
let x: [u8; 64] = key.as_bytes().try_into().unwrap();
PriKey{
keys: x
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_pri_key() {
let mut key = PriKey::from("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
println!("{}", key);
println!("{}", key.get_address().unwrap());
}
}

23
src-tauri/src/task.rs Normal file
View File

@@ -0,0 +1,23 @@
use crate::pri_key::PriKey;
use std::collections::HashMap;
use std::sync::LazyLock;
const LOOP_NUMBERS: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 97, 98, 99, 100, 101, 102];
static mut TASK_MAP: LazyLock<HashMap<u32, Task>> = LazyLock::new(|| {
HashMap::new()
});
pub fn add_task(task: Task) {
unsafe { TASK_MAP.insert(task.id, task); }
}
#[derive(Debug)]
pub struct Task {
id: u32,
pub pri_key: PriKey,
pub target_addr: String,
pub stop: bool,
}
impl Task {
pub fn new(id:u32,pri_key: PriKey, target_addr: String) -> Self {
Task { id, pri_key, target_addr,stop: false }
}
}

35
src-tauri/tauri.conf.json Normal file
View File

@@ -0,0 +1,35 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "wallet-project",
"version": "0.1.0",
"identifier": "com.vicro.wallet",
"build": {
"beforeDevCommand": "npm run dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "npm run build",
"frontendDist": "../dist"
},
"app": {
"windows": [
{
"title": "wallet-project",
"width": 800,
"height": 600
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}