aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / rad-id-sync / src / identity.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | use serde::{Deserialize, Serialize}; |
| 17 | use std::fs; |
| 18 | use std::path::PathBuf; |
| 19 | |
| 20 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 21 | #[serde(rename_all = "snake_case")] |
| 22 | pub enum EntityType { |
| 23 | AutonomousAgent, |
| 24 | HumanOperator, |
| 25 | NodeBridge, |
| 26 | } |
| 27 | |
| 28 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 29 | pub struct KeyRecord { |
| 30 | pub key_type: String, // e.g. "ssh-ed25519", "radicle-ed25519" |
| 31 | pub public_key: String, |
| 32 | pub finger_print: String, |
| 33 | pub added_at: String, |
| 34 | pub status: String, // "active", "rotated", "revoked" |
| 35 | } |
| 36 | |
| 37 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 38 | pub struct IdentityAnchor { |
| 39 | pub did: String, // e.g. "did:rad:aien:spark-01" |
| 40 | pub name: String, // "AIEN" or "Drake Stapleton" |
| 41 | pub entity_type: EntityType, |
| 42 | pub primary_radicle_key: Option<String>, |
| 43 | pub primary_ssh_key: Option<String>, |
| 44 | pub key_history: Vec<KeyRecord>, |
| 45 | pub last_synced_at: String, |
| 46 | pub metadata: std::collections::HashMap<String, String>, |
| 47 | } |
| 48 | |
| 49 | impl IdentityAnchor { |
| 50 | pub fn default_agent() -> Self { |
| 51 | let mut meta = std::collections::HashMap::new(); |
| 52 | meta.insert("harness".to_string(), "aien-native-1.0".to_string()); |
| 53 | meta.insert("host".to_string(), "spark-gb10".to_string()); |
| 54 | |
| 55 | Self { |
| 56 | did: "did:rad:aien:spark-master".to_string(), |
| 57 | name: "AIEN".to_string(), |
| 58 | entity_type: EntityType::AutonomousAgent, |
| 59 | primary_radicle_key: None, |
| 60 | primary_ssh_key: None, |
| 61 | key_history: Vec::new(), |
| 62 | last_synced_at: chrono::Utc::now().to_rfc3339(), |
| 63 | metadata: meta, |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | pub fn anchor_file_path() -> PathBuf { |
| 68 | let home = std::env::var("HOME") |
| 69 | .or_else(|_| std::env::var("USERPROFILE")) |
| 70 | .unwrap_or_else(|_| ".".to_string()); |
| 71 | PathBuf::from(home) |
| 72 | .join(".radicle") |
| 73 | .join("identity_anchor.json") |
| 74 | } |
| 75 | |
| 76 | pub fn load_or_init() -> Result<Self, String> { |
| 77 | let path = Self::anchor_file_path(); |
| 78 | if path.exists() { |
| 79 | let data = |
| 80 | fs::read_to_string(&path).map_err(|e| format!("Failed to read anchor: {}", e))?; |
| 81 | serde_json::from_str(&data).map_err(|e| format!("Failed to parse anchor: {}", e)) |
| 82 | } else { |
| 83 | let anchor = Self::default_agent(); |
| 84 | anchor.save()?; |
| 85 | Ok(anchor) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | pub fn save(&self) -> Result<(), String> { |
| 90 | let path = Self::anchor_file_path(); |
| 91 | if let Some(parent) = path.parent() { |
| 92 | fs::create_dir_all(parent) |
| 93 | .map_err(|e| format!("Failed to create parent dir: {}", e))?; |
| 94 | } |
| 95 | let data = serde_json::to_string_pretty(self) |
| 96 | .map_err(|e| format!("Failed to serialize: {}", e))?; |
| 97 | fs::write(&path, data).map_err(|e| format!("Failed to write anchor: {}", e)) |
| 98 | } |
| 99 | } |