Skip to content

Commit eb00b95

Browse files
committed
Implement vrf random hash in the keystore
1 parent d1c9314 commit eb00b95

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

keystore/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ parking_lot = "0.6.0"
1919
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
2020
smallvec = "0.4"
2121
tempdir = "0.3"
22+
vrf = { git = "https://github.com/CodeChain-io/vrf-rs.git" }
2223

2324
[dev-dependencies]
2425
matches = "0.1"

keystore/src/account/decrypted_account.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use ckey::{
1818
sign, sign_schnorr, Error as KeyError, KeyPair, Message, Private, Public, SchnorrSignature, Secret, Signature,
1919
};
20+
use vrf::openssl::{Error as VRFError, ECVRF};
21+
use vrf::VRF;
2022

2123
/// An opaque wrapper for secret.
2224
pub struct DecryptedAccount {
@@ -40,6 +42,11 @@ impl DecryptedAccount {
4042
sign_schnorr(&Private::from(self.secret), message)
4143
}
4244

45+
/// Generate VRF random hash output.
46+
pub fn vrf_hash(&self, message: &Message, vrf_inst: &mut ECVRF) -> Result<Vec<u8>, VRFError> {
47+
vrf_inst.prove(&Private::from(self.secret), message).and_then(|proof| vrf_inst.proof_to_hash(&proof))
48+
}
49+
4350
/// Derive public key.
4451
pub fn public(&self) -> Result<Public, KeyError> {
4552
Ok(*KeyPair::from_private(Private::from(self.secret))?.public())

keystore/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern crate serde_json;
4141
extern crate smallvec;
4242
extern crate tempdir;
4343
extern crate time;
44+
extern crate vrf;
4445

4546
extern crate codechain_crypto as ccrypto;
4647
extern crate codechain_json as cjson;

0 commit comments

Comments
 (0)