aries_bbssignatures/issuer.rs
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
use crate::errors::{BBSError, BBSErrorKind};
use crate::keys::prelude::*;
use crate::signature::prelude::*;
/// The issuer generates keys and uses those to sign
/// credentials. There are two types of public keys:
/// `PublicKey` which generates all generators at random and
/// `DeterministicPublicKey` which only generates the commitment
/// to the secret key. `DeterministicPublicKey` can be converted to a
/// `PublicKey` later. The latter is primarily used for storing a shorter
/// key and looks just like a regular ECC key.
use crate::{BlindSignatureContext, ProofNonce, RandomElem, SignatureMessage};
use std::collections::{BTreeMap, BTreeSet};
/// This struct represents an Issuer of signatures or Signer.
/// Provided are methods for signing regularly where all messages are known
/// and 2PC where some are only known to the holder and a blind signature
/// is created.
pub struct Issuer;
impl Issuer {
/// Create a keypair capable of signing `message_count` messages
pub fn new_keys(message_count: usize) -> Result<(PublicKey, SecretKey), BBSError> {
generate(message_count)
}
/// Create a keypair that uses the short public key
pub fn new_short_keys(
option: Option<KeyGenOption>,
) -> Result<(DeterministicPublicKey, SecretKey), BBSError> {
DeterministicPublicKey::new(option)
}
/// Create a signature with no hidden messages
pub fn sign(
messages: &[SignatureMessage],
signkey: &SecretKey,
verkey: &PublicKey,
) -> Result<Signature, BBSError> {
Signature::new(messages, signkey, verkey)
}
/// Verify a proof of committed messages and generate a blind signature
pub fn blind_sign(
ctx: &BlindSignatureContext,
messages: &BTreeMap<usize, SignatureMessage>,
signkey: &SecretKey,
verkey: &PublicKey,
nonce: &ProofNonce,
) -> Result<BlindSignature, BBSError> {
let revealed_messages: BTreeSet<usize> = messages.keys().copied().collect();
if ctx.verify(&revealed_messages, verkey, nonce)? {
BlindSignature::new(&ctx.commitment, messages, signkey, verkey)
} else {
Err(BBSErrorKind::GeneralError {
msg: "Invalid proof of committed messages".to_string(),
}
.into())
}
}
/// Create a nonce used for the blind signing context
pub fn generate_signing_nonce() -> ProofNonce {
ProofNonce::random()
}
}