Skip to content

Commit

Permalink
- feature: galxe add desktop validation (#301)
Browse files Browse the repository at this point in the history
* WIP

* - feature: added galxe validation page

* - refactor: installation validation workflow

* - fix: backend url

* - fix: toast error
  • Loading branch information
agallardol authored Jun 6, 2024
1 parent 55cf3ce commit a58a258
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 2 deletions.
158 changes: 157 additions & 1 deletion apps/shinkai-desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions apps/shinkai-desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ regex = "1.10.4"
once_cell = "1.19.0"
wgpu = "0.20.0"
sysinfo = "0.30.12"
ed25519-dalek = { version = "2.1.1", features = ["rand_core"] }
blake3 = "1.5.1"
hex = "0.4.3"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
6 changes: 6 additions & 0 deletions apps/shinkai-desktop/src-tauri/src/commands/galxe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::galxe;

#[tauri::command]
pub fn galxe_generate_desktop_installation_proof() -> Result<(String, String), String> {
galxe::generate_desktop_installation_proof()
}
3 changes: 2 additions & 1 deletion apps/shinkai-desktop/src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod shinkai_node_manager_commands;
pub mod hardware;
pub mod hardware;
pub mod galxe;
44 changes: 44 additions & 0 deletions apps/shinkai-desktop/src-tauri/src/galxe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use blake3::Hasher;
use ed25519_dalek::{Signer, SigningKey, VerifyingKey};

pub fn unsafe_deterministic_signature_keypair(n: u32) -> (SigningKey, VerifyingKey) {
let mut hasher = blake3::Hasher::new();
hasher.update(&n.to_le_bytes());
let hash = hasher.finalize();

let secret_key = SigningKey::from_bytes(hash.as_bytes());
let public_key = VerifyingKey::from(&secret_key);
(secret_key, public_key)
}

pub fn generate_desktop_installation_proof() -> Result<(String, String), String> {
let secret_desktop_key: &str = option_env!("SECRET_DESKTOP_INSTALLATION_PROOF_KEY").unwrap_or("Dc9{3R9JmXe7£w9Fs](7");
let (secret_key, public_key) = unsafe_deterministic_signature_keypair(42);
// Convert the public key to hex
let public_key_hex = hex::encode(public_key.to_bytes());

// Combine the public key hex and the secret desktop key
let combined = format!("{}{}", public_key_hex, secret_desktop_key);

// Hash the combined value and take the last 4 characters
let mut hasher = Hasher::new();
hasher.update(combined.as_bytes());
let hash_result = hasher.finalize();
let hash_str = hex::encode(hash_result.as_bytes());
let last_8_chars = &hash_str[hash_str.len() - 8..];

// Concatenate the public key hex with the last 4 characters using :::
let concatenated = format!("{}:::{}", public_key_hex, last_8_chars);

// Hash the concatenated string
let mut hasher = Hasher::new();
hasher.update(concatenated.as_bytes());
let final_hash_result = hasher.finalize();
let final_hash_bytes = final_hash_result.as_bytes();

// Sign the final hash
let signature = secret_key.sign(final_hash_bytes);

// Return the signature as a hexadecimal string and the concatenated string
Ok((hex::encode(signature.to_bytes()), concatenated))
}
4 changes: 4 additions & 0 deletions apps/shinkai-desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::commands::shinkai_node_manager_commands::{
shinkai_node_is_running, shinkai_node_kill, shinkai_node_remove_storage,
shinkai_node_set_default_options, shinkai_node_set_options, shinkai_node_spawn, shinkai_node_get_default_model
};
use crate::commands::galxe::galxe_generate_desktop_installation_proof;

use globals::SHINKAI_NODE_MANAGER_INSTANCE;
use local_shinkai_node::shinkai_node_manager::ShinkaiNodeManager;
use tauri::GlobalShortcutManager;
Expand All @@ -21,6 +23,7 @@ mod commands;
mod globals;
mod local_shinkai_node;
mod hardware;
mod galxe;

fn main() {
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
Expand Down Expand Up @@ -56,6 +59,7 @@ fn main() {
shinkai_node_get_ollama_api_url,
shinkai_node_get_default_model,
hardware_get_summary,
galxe_generate_desktop_installation_proof
])
.setup(|app| {
let app_clone = app.app_handle();
Expand Down
Binary file added apps/shinkai-desktop/src/assets/galxe-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a58a258

Please sign in to comment.