Proper signature management

This commit is contained in:
2026-08-11 23:43:56 -04:00
parent aacb11bc01
commit 019c2888cb
6 changed files with 80 additions and 11 deletions
+23 -1
View File
@@ -1,6 +1,6 @@
use std::path::PathBuf;
use ed25519_dalek::SigningKey;
use ed25519_dalek::{Signature, SigningKey, VerifyingKey};
use rand::rngs::OsRng;
pub async fn get() -> anyhow::Result<SigningKey> {
@@ -19,3 +19,25 @@ pub async fn get() -> anyhow::Result<SigningKey> {
))
}
}
pub fn to_string(key: &VerifyingKey) -> String {
bs58::encode(key.to_bytes()).into_string()
}
pub fn from_string(key: &str) -> anyhow::Result<VerifyingKey> {
Ok(VerifyingKey::from_bytes(
&bs58::decode(key)
.into_vec()?
.try_into()
.map_err(|_| anyhow::anyhow!("Invalid public key"))?,
)?)
}
pub fn from_string_sig(signature: &str) -> anyhow::Result<Signature> {
Ok(Signature::from_bytes(
&bs58::decode(signature)
.into_vec()?
.try_into()
.map_err(|_| anyhow::anyhow!("Invalid public key"))?,
))
}