mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 14:00:31 +08:00
node: Implement signed refs
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
+22
-1
@@ -5,9 +5,17 @@ use ed25519_consensus as ed25519;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
pub use ed25519::Error;
|
||||
pub use ed25519::Signature;
|
||||
|
||||
pub trait Signer: Send + Sync + 'static {
|
||||
/// Verified (used as type witness).
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Verified;
|
||||
/// Unverified (used as type witness).
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Unverified;
|
||||
|
||||
pub trait Signer: Send + Sync {
|
||||
/// Return this signer's public/verification key.
|
||||
fn public_key(&self) -> &PublicKey;
|
||||
/// Sign a message and return the signature.
|
||||
@@ -27,6 +35,19 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Signer for &T
|
||||
where
|
||||
T: Signer + ?Sized,
|
||||
{
|
||||
fn sign(&self, msg: &[u8]) -> Signature {
|
||||
self.deref().sign(msg)
|
||||
}
|
||||
|
||||
fn public_key(&self) -> &PublicKey {
|
||||
self.deref().public_key()
|
||||
}
|
||||
}
|
||||
|
||||
/// The public/verification key.
|
||||
#[derive(Serialize, Deserialize, Eq, Debug, Copy, Clone)]
|
||||
#[serde(transparent)]
|
||||
|
||||
Reference in New Issue
Block a user