node: Implement signed refs

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-09-13 10:16:05 +02:00
parent 6e86218c36
commit cd7421eb86
14 changed files with 776 additions and 172 deletions
+22 -1
View File
@@ -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)]