radrootsd

JSON-RPC bridge for Radroots event publishing
git clone https://radroots.dev/git/radrootsd.git
Log | Files | Refs | README | LICENSE

commit c30cdf27d47e39a2513282629665822f5a19e4dc
parent ef41bf822c833592e422d5d75b8746ecc2b24798
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Sun, 24 Aug 2025 23:21:16 +0000

Update runtime configuration.

Diffstat:
MCargo.lock | 14++++++++++++++
MCargo.toml | 1+
Mcrates/radrootsd/Cargo.toml | 1+
Mcrates/radrootsd/src/identity.rs | 64++++++++++------------------------------------------------------
Mcrates/radrootsd/src/lib.rs | 7+++++--
5 files changed, 31 insertions(+), 56 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -1780,6 +1780,18 @@ dependencies = [ ] [[package]] +name = "radroots-identity" +version = "0.1.0" +dependencies = [ + "nostr", + "radroots-runtime", + "serde", + "thiserror 1.0.69", + "tracing", + "uuid", +] + +[[package]] name = "radroots-nostr" version = "0.1.0" dependencies = [ @@ -1823,6 +1835,7 @@ dependencies = [ "radroots-core", "radroots-events", "radroots-events-codec", + "radroots-identity", "radroots-nostr", "radroots-runtime", "reqwest", @@ -2877,6 +2890,7 @@ checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" dependencies = [ "getrandom 0.3.3", "js-sys", + "serde", "wasm-bindgen", ] diff --git a/Cargo.toml b/Cargo.toml @@ -14,6 +14,7 @@ license = "AGPL-3.0" radroots-core = { path = "../../crates/crates/core" } radroots-events = { path = "../../crates/crates/events" } radroots-events-codec = { path = "../../crates/crates/events-codec" } +radroots-identity = { path = "../../crates/crates/identity" } radroots-nostr = { path = "../../crates/crates/nostr" } radroots-runtime = { path = "../../crates/crates/runtime" } radroots-trade = { path = "../../crates/crates/trade" } diff --git a/crates/radrootsd/Cargo.toml b/crates/radrootsd/Cargo.toml @@ -11,6 +11,7 @@ description = "The radroots daemon binary" radroots-core = { workspace = true, features = ["std", "serde", "typeshare"] } radroots-events = { workspace = true, features = ["serde"] } radroots-events-codec = { workspace = true, features = ["nostr"] } +radroots-identity = { workspace = true } radroots-nostr = { workspace = true, features = ["sdk", "codec", "http"] } radroots-runtime = { workspace = true, features = ["cli"] } diff --git a/crates/radrootsd/src/identity.rs b/crates/radrootsd/src/identity.rs @@ -1,68 +1,24 @@ -use radroots_runtime::{JsonFile, RuntimeJsonError}; +use radroots_identity::IdentitySpec; use serde::{Deserialize, Serialize}; -use std::{ - path::{Path, PathBuf}, - str::FromStr, -}; -use thiserror::Error; -use tracing::warn; -use uuid::Uuid; - -pub const DEFAULT_IDENTITY_PATH: &str = "identity.json"; +use std::str::FromStr; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Identity { pub key: String, } -#[derive(Debug, Error)] -pub enum IdentityError { - #[error(transparent)] - Store(#[from] RuntimeJsonError), - - #[error("invalid secret key: {0}")] - InvalidSecretKey(String), - - #[error( - "identity file missing at {0} and generation is not permitted (pass --allow-generate-identity)" - )] - GenerationNotAllowed(PathBuf), -} - -impl Identity { - pub fn load_or_generate<P: AsRef<Path>>( - path: Option<P>, - allow_generate: bool, - ) -> Result<JsonFile<Self>, IdentityError> { - let p = path - .map(|p| p.as_ref().to_path_buf()) - .unwrap_or_else(|| PathBuf::from(DEFAULT_IDENTITY_PATH)); +impl IdentitySpec for Identity { + type Keys = nostr::Keys; + type ParseError = nostr::key::Error; - if p.exists() { - let store = JsonFile::load(&p)?; - return Ok(store); + fn generate_new() -> Self { + let keys = nostr::Keys::generate(); + Self { + key: keys.secret_key().to_secret_hex(), } - - if !allow_generate { - return Err(IdentityError::GenerationNotAllowed(p)); - } - - let store = JsonFile::load_or_create_with(&p, || { - let keys = nostr::Keys::generate(); - let secret_hex = keys.secret_key().to_secret_hex(); - let tag = Uuid::new_v4(); - warn!( - "No identity file found at {:?}; generated new secret (tag={tag})", - p - ); - Identity { key: secret_hex } - })?; - - Ok(store) } - pub fn to_keys(&self) -> Result<nostr::Keys, IdentityError> { + fn to_keys(&self) -> Result<Self::Keys, Self::ParseError> { nostr::Keys::from_str(&self.key) - .map_err(|_| IdentityError::InvalidSecretKey(self.key.clone())) } } diff --git a/crates/radrootsd/src/lib.rs b/crates/radrootsd/src/lib.rs @@ -12,8 +12,11 @@ use tracing::info; use crate::{identity::Identity, radrootsd::Radrootsd}; pub async fn run_radrootsd(settings: &config::Settings, args: &cli_args) -> Result<()> { - let store = Identity::load_or_generate(args.identity.as_ref(), args.allow_generate_identity)?; - let keys = store.value.to_keys()?; + let identity = radroots_identity::load_or_generate::<Identity, _>( + args.identity.as_ref(), + args.allow_generate_identity, + )?; + let keys = radroots_identity::to_keys(&identity.value)?; let radrootsd = Radrootsd::new(keys, settings.metadata.clone());