Proper signature management
This commit is contained in:
+23
-1
@@ -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"))?,
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user