Why Nostr? What is Njump?
2024-06-21 18:08:19

Water Blower on Nostr: mod keys { const BYTE_LEN: usize = 32; #[derive(Debug, PartialEq, Eq, PartialOrd, ...

mod keys {

const BYTE_LEN: usize = 32;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PrivateKey([u8; BYTE_LEN]);

#[derive(Debug)]
pub enum Error {
FromHexError(hex::FromHexError),
Not64Length(usize),
}

impl PrivateKey {
// Public constructor
pub fn new(id: &str) -> Result<PrivateKey, Error> {
if id.starts_with("npub") {}
if id.len() != BYTE_LEN * 2 {
return Result::Err(Error::Not64Length(id.len()));
}
let h = hex::decode(id);
let bytes = match h {
Ok(bytes) => bytes,
Err(err) => return Result::Err(Error::FromHexError(err)),
};
let mut array: [u8; BYTE_LEN] = [0; BYTE_LEN];
for (i, b) in bytes.iter().enumerate() {
array[i] = b.to_owned();
}
Result::Ok(PrivateKey(array))
}

pub fn hex(&self) -> String {
hex::encode(&self.0).clone()
}
}
}

Is this good Rust?
Author Public Key
npub1dww6jgxykmkt7tqjqx985tg58dxlm7v83sa743578xa4j7zpe3hql6pdnf