1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
//! Types and traits dealing with identity across the Internet Computer.
use crate::export::Principal;
pub(crate) mod anonymous;
pub(crate) mod basic;
pub(crate) mod secp256k1;
#[cfg(feature = "pem")]
pub(crate) mod error;
pub use anonymous::AnonymousIdentity;
pub use basic::BasicIdentity;
pub use secp256k1::Secp256k1Identity;
#[cfg(feature = "pem")]
pub use error::PemError;
/// A cryptographic signature, signed by an [Identity].
#[derive(Clone, Debug)]
pub struct Signature {
/// This is the DER-encoded public key.
pub public_key: Option<Vec<u8>>,
/// The signature bytes.
pub signature: Option<Vec<u8>>,
}
/// An Identity takes a request id and returns the [Signature]. It knows or
/// represents the Principal of the sender.
///
/// Agents are assigned a single Identity object, but there can be multiple
/// identities used.
pub trait Identity: Send + Sync {
/// Returns a sender, ie. the Principal ID that is used to sign a request.
/// Only one sender can be used per request.
fn sender(&self) -> Result<Principal, String>;
/// Sign a blob, the concatenation of the domain separator & request ID,
/// creating the sender signature.
fn sign(&self, blob: &[u8]) -> Result<Signature, String>;
}