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