sp-core: Rename VrfOutput to VrfPreOutput (#2534)

This will make more sense after
https://github.com/paritytech/polkadot-sdk/pull/2524 since the
schnorrkel type for VRF outputs is also renamed in the latest version.
Can be reviewed independently though.

Can be merged after https://github.com/paritytech/polkadot-sdk/pull/1577
so that there is less pain for @davxy.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
André Silva
2023-12-06 00:19:56 +00:00
committed by GitHub
parent 91cbe087de
commit 1f023deab8
19 changed files with 193 additions and 172 deletions
+12 -12
View File
@@ -92,19 +92,19 @@ pub trait Keystore: Send + Sync {
data: &sr25519::vrf::VrfSignData,
) -> Result<Option<sr25519::vrf::VrfSignature>, Error>;
/// Generate an sr25519 VRF output for a given input data.
/// Generate an sr25519 VRF pre-output for a given input data.
///
/// Receives [`KeyTypeId`] and an [`sr25519::Public`] key to be able to map
/// them to a private key that exists in the keystore.
///
/// Returns `None` if the given `key_type` and `public` combination doesn't
/// exist in the keystore or an `Err` when something failed.
fn sr25519_vrf_output(
fn sr25519_vrf_pre_output(
&self,
key_type: KeyTypeId,
public: &sr25519::Public,
input: &sr25519::vrf::VrfInput,
) -> Result<Option<sr25519::vrf::VrfOutput>, Error>;
) -> Result<Option<sr25519::vrf::VrfPreOutput>, Error>;
/// Returns all ed25519 public keys for the given key type.
fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<ed25519::Public>;
@@ -223,7 +223,7 @@ pub trait Keystore: Send + Sync {
input: &bandersnatch::vrf::VrfSignData,
) -> Result<Option<bandersnatch::vrf::VrfSignature>, Error>;
/// Generate a bandersnatch VRF (pre)output for a given input data.
/// Generate a bandersnatch VRF pre-output for a given input data.
///
/// Receives [`KeyTypeId`] and an [`bandersnatch::Public`] key to be able to map
/// them to a private key that exists in the keystore.
@@ -231,12 +231,12 @@ pub trait Keystore: Send + Sync {
/// Returns `None` if the given `key_type` and `public` combination doesn't
/// exist in the keystore or an `Err` when something failed.
#[cfg(feature = "bandersnatch-experimental")]
fn bandersnatch_vrf_output(
fn bandersnatch_vrf_pre_output(
&self,
key_type: KeyTypeId,
public: &bandersnatch::Public,
input: &bandersnatch::vrf::VrfInput,
) -> Result<Option<bandersnatch::vrf::VrfOutput>, Error>;
) -> Result<Option<bandersnatch::vrf::VrfPreOutput>, Error>;
/// Generate a bandersnatch ring-VRF signature for the given data.
///
@@ -474,13 +474,13 @@ impl<T: Keystore + ?Sized> Keystore for Arc<T> {
(**self).sr25519_vrf_sign(key_type, public, data)
}
fn sr25519_vrf_output(
fn sr25519_vrf_pre_output(
&self,
key_type: KeyTypeId,
public: &sr25519::Public,
input: &sr25519::vrf::VrfInput,
) -> Result<Option<sr25519::vrf::VrfOutput>, Error> {
(**self).sr25519_vrf_output(key_type, public, input)
) -> Result<Option<sr25519::vrf::VrfPreOutput>, Error> {
(**self).sr25519_vrf_pre_output(key_type, public, input)
}
fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<ed25519::Public> {
@@ -569,13 +569,13 @@ impl<T: Keystore + ?Sized> Keystore for Arc<T> {
}
#[cfg(feature = "bandersnatch-experimental")]
fn bandersnatch_vrf_output(
fn bandersnatch_vrf_pre_output(
&self,
key_type: KeyTypeId,
public: &bandersnatch::Public,
input: &bandersnatch::vrf::VrfInput,
) -> Result<Option<bandersnatch::vrf::VrfOutput>, Error> {
(**self).bandersnatch_vrf_output(key_type, public, input)
) -> Result<Option<bandersnatch::vrf::VrfPreOutput>, Error> {
(**self).bandersnatch_vrf_pre_output(key_type, public, input)
}
#[cfg(feature = "bandersnatch-experimental")]
+15 -14
View File
@@ -113,14 +113,14 @@ impl MemoryKeystore {
Ok(sig)
}
fn vrf_output<T: Pair + VrfSecret>(
fn vrf_pre_output<T: Pair + VrfSecret>(
&self,
key_type: KeyTypeId,
public: &T::Public,
input: &T::VrfInput,
) -> Result<Option<T::VrfOutput>, Error> {
let preout = self.pair::<T>(key_type, public).map(|pair| pair.vrf_output(input));
Ok(preout)
) -> Result<Option<T::VrfPreOutput>, Error> {
let pre_output = self.pair::<T>(key_type, public).map(|pair| pair.vrf_pre_output(input));
Ok(pre_output)
}
}
@@ -155,13 +155,13 @@ impl Keystore for MemoryKeystore {
self.vrf_sign::<sr25519::Pair>(key_type, public, data)
}
fn sr25519_vrf_output(
fn sr25519_vrf_pre_output(
&self,
key_type: KeyTypeId,
public: &sr25519::Public,
input: &sr25519::vrf::VrfInput,
) -> Result<Option<sr25519::vrf::VrfOutput>, Error> {
self.vrf_output::<sr25519::Pair>(key_type, public, input)
) -> Result<Option<sr25519::vrf::VrfPreOutput>, Error> {
self.vrf_pre_output::<sr25519::Pair>(key_type, public, input)
}
fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<ed25519::Public> {
@@ -265,13 +265,13 @@ impl Keystore for MemoryKeystore {
}
#[cfg(feature = "bandersnatch-experimental")]
fn bandersnatch_vrf_output(
fn bandersnatch_vrf_pre_output(
&self,
key_type: KeyTypeId,
public: &bandersnatch::Public,
input: &bandersnatch::vrf::VrfInput,
) -> Result<Option<bandersnatch::vrf::VrfOutput>, Error> {
self.vrf_output::<bandersnatch::Pair>(key_type, public, input)
) -> Result<Option<bandersnatch::vrf::VrfPreOutput>, Error> {
self.vrf_pre_output::<bandersnatch::Pair>(key_type, public, input)
}
#[cfg(feature = "bls-experimental")]
@@ -443,7 +443,7 @@ mod tests {
}
#[test]
fn sr25519_vrf_output() {
fn sr25519_vrf_pre_output() {
let store = MemoryKeystore::new();
let secret_uri = "//Alice";
@@ -458,16 +458,17 @@ mod tests {
],
);
let result = store.sr25519_vrf_output(SR25519, &pair.public(), &input);
let result = store.sr25519_vrf_pre_output(SR25519, &pair.public(), &input);
assert!(result.unwrap().is_none());
store
.insert(SR25519, secret_uri, pair.public().as_ref())
.expect("Inserts unknown key");
let preout = store.sr25519_vrf_output(SR25519, &pair.public(), &input).unwrap().unwrap();
let pre_output =
store.sr25519_vrf_pre_output(SR25519, &pair.public(), &input).unwrap().unwrap();
let result = preout.make_bytes::<32>(b"rand", &input, &pair.public());
let result = pre_output.make_bytes::<32>(b"rand", &input, &pair.public());
assert!(result.is_ok());
}