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
use crate::*;
use rand_core::{CryptoRng, RngCore};
use signature_core::{error::Error, lib::*};
pub struct Issuer;
impl Issuer {
pub fn new_keys(
count: usize,
rng: impl RngCore + CryptoRng,
) -> Result<(PublicKey, SecretKey), Error> {
SecretKey::random(count, rng)
.map(|sk| {
let pk = PublicKey::from(&sk);
(pk, sk)
})
.ok_or_else(|| Error::new(1, "invalid length to generate keys"))
}
pub fn sign<M>(sk: &SecretKey, msgs: M) -> Result<Signature, Error>
where
M: AsRef<[Message]>,
{
Signature::new(sk, msgs)
}
pub fn blind_sign(
ctx: &BlindSignatureContext,
sk: &SecretKey,
msgs: &[(usize, Message)],
nonce: Nonce,
) -> Result<BlindSignature, Error> {
let tv1 = msgs.iter().map(|(i, _)| *i).collect::<Vec<usize, 128>>();
if ctx.verify(tv1.as_ref(), sk, nonce)? {
BlindSignature::new(ctx.commitment, sk, msgs)
} else {
Err(Error::new(1, "invalid proof of committed messages"))
}
}
pub fn generate_signing_nonce(rng: impl RngCore + CryptoRng) -> Nonce {
Nonce::random(rng)
}
}