Add keygen.
This commit is contained in:
parent
09daa00fdf
commit
52951f7236
|
@ -5,6 +5,7 @@ authors = ["Henry de Valence <hdevalence@hdevalence.ca>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
rand_core = "0.5"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
blake2b_simd = "0.5"
|
blake2b_simd = "0.5"
|
||||||
jubjub = { git = "https://github.com/zkcrypto/jubjub", rev = "e83f7d2bd136498a27f9d943fea635d8682bf2c6" }
|
jubjub = { git = "https://github.com/zkcrypto/jubjub", rev = "e83f7d2bd136498a27f9d943fea635d8682bf2c6" }
|
||||||
|
|
|
@ -2,6 +2,8 @@ use std::{convert::TryFrom, marker::PhantomData};
|
||||||
|
|
||||||
use crate::{Binding, Error, PublicKey, Randomizer, Scalar, SigType, Signature, SpendAuth};
|
use crate::{Binding, Error, PublicKey, Randomizer, Scalar, SigType, Signature, SpendAuth};
|
||||||
|
|
||||||
|
use rand_core::{CryptoRng, RngCore};
|
||||||
|
|
||||||
/// A refinement type indicating that the inner `[u8; 32]` represents an
|
/// A refinement type indicating that the inner `[u8; 32]` represents an
|
||||||
/// encoding of a RedJubJub secret key.
|
/// encoding of a RedJubJub secret key.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
|
@ -63,6 +65,21 @@ impl<T: SigType> TryFrom<SecretKeyBytes<T>> for SecretKey<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<R, T> From<R> for SecretKey<T>
|
||||||
|
where
|
||||||
|
R: RngCore + CryptoRng,
|
||||||
|
T: SigType,
|
||||||
|
{
|
||||||
|
fn from(mut rng: R) -> SecretKey<T> {
|
||||||
|
let mut bytes = [0; 64];
|
||||||
|
rng.fill_bytes(&mut bytes);
|
||||||
|
SecretKey {
|
||||||
|
sk: Scalar::from_bytes_wide(&bytes),
|
||||||
|
_marker: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a SecretKey<SpendAuth>> for PublicKey<SpendAuth> {
|
impl<'a> From<&'a SecretKey<SpendAuth>> for PublicKey<SpendAuth> {
|
||||||
fn from(sk: &'a SecretKey<SpendAuth>) -> PublicKey<SpendAuth> {
|
fn from(sk: &'a SecretKey<SpendAuth>) -> PublicKey<SpendAuth> {
|
||||||
// XXX-jubjub: this is pretty baroque
|
// XXX-jubjub: this is pretty baroque
|
||||||
|
|
Loading…
Reference in New Issue