swactor/crates/node/src/names.rs
Zachery Aaron Shores-Chmielewski 3cf0ae5947 refactor: consolidate crate functions (#50)
Remove co-dependencies for different modules found in `crates` and migrate the development history to a new repository. The docs were stale, and largely not getting used, so simply deleted for now. When code stabilizes more, they will become useful again.
Co-authored-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
Co-committed-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-24 09:12:28 +00:00

43 lines
1.7 KiB
Rust

//! Human-readable name generation for swactor nodes.
//!
//! Produces deterministic `adjective-animal` names from a keypair's
//! public key bytes, so the same identity always gets the same default name.
use swactor_transport::crypto::Keypair;
const ADJECTIVES: &[&str] = &[
"bold", "brave", "bright", "calm", "clever",
"cool", "crisp", "deft", "eager", "fair",
"fast", "fierce", "fleet", "fond", "frank",
"free", "fresh", "glad", "grand", "green",
"happy", "hardy", "keen", "kind", "light",
"live", "lucky", "merry", "mild", "neat",
"noble", "pale", "plain", "prime", "proud",
"pure", "quick", "quiet", "rapid", "ready",
"rich", "sharp", "sleek", "smart", "solid",
"sound", "stout", "sure", "swift", "wise",
];
const ANIMALS: &[&str] = &[
"badger", "bear", "bison", "bobcat", "crane",
"crow", "deer", "dove", "eagle", "elk",
"falcon", "finch", "fox", "frog", "goose",
"hare", "hawk", "heron", "horse", "ibis",
"jackal", "jay", "kite", "lark", "lion",
"lynx", "marten", "mink", "moose", "newt",
"otter", "owl", "panda", "pike", "puma",
"quail", "raven", "robin", "salmon", "seal",
"shrike", "snake", "sparrow", "stork", "swan",
"tiger", "toad", "trout", "viper", "wolf",
];
/// Generate a deterministic human-readable name from a keypair.
///
/// Uses the first two bytes of the public key (node ID) to index into
/// the adjective and animal word lists.
pub fn generate_name(keypair: &Keypair) -> String {
let id = keypair.node_id();
let adj_idx = id.0[0] as usize % ADJECTIVES.len();
let animal_idx = id.0[1] as usize % ANIMALS.len();
format!("{}-{}", ADJECTIVES[adj_idx], ANIMALS[animal_idx])
}