Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 19eb56a

Browse files
davxymelekeskoute
authored
Bandersnatch VRF (#14412)
* Introduce bandersnatch vrf * Some documentation * Fix tests * Fix docs refs * Some more docs * Comments about key derivation * Make clippy happy * Fix ring context enc/dec test * Fix docs * Switch to upstream ring-vrf * Use sub-domains to construct VrfInput * Bandersnatch VRF experimental feature * Restore upstream dep * Fix feature flags * Apply typo fix Co-authored-by: Anton <[email protected]> * Bump bandersnatch-vrfs * Weiestrass form has been selected * Rename bandersnatch testing app crypto id * Support for seed recovery * Clarified domain size <-> key size relationship * cargo fmt * Trigger CI * Some required tweaks to crypto types * Remove leftovers from Cargo.toml * Remove some TODO notes * Simplification of structs construction * Trigger CI * Apply review suggestion Co-authored-by: Koute <[email protected]> * Docs typo * Fix keystore tests * Consistence * Add ref to git rependency * Static check of MAX_VRF_IOS value * Clarify behavior for out of ring keys signatures * Add test for ring-vrf to the keystore * Fix docs --------- Co-authored-by: Anton <[email protected]> Co-authored-by: Koute <[email protected]>
1 parent 1c9c709 commit 19eb56a

File tree

23 files changed

+1900
-59
lines changed

23 files changed

+1900
-59
lines changed

Cargo.lock

Lines changed: 129 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/keystore/Cargo.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ sp-keystore = { version = "0.27.0", path = "../../primitives/keystore" }
2626
tempfile = "3.1.0"
2727

2828
[features]
29-
# This feature adds BLS crypto primitives. It should not be used in production since
30-
# the BLS implementation and interface may still be subject to significant change.
29+
# This feature adds BLS crypto primitives.
30+
# It should not be used in production since the implementation and interface may still
31+
# be subject to significant changes.
3132
bls-experimental = [
3233
"sp-core/bls-experimental",
3334
"sp-keystore/bls-experimental",
3435
]
36+
37+
# This feature adds Bandersnatch crypto primitives.
38+
# It should not be used in production since the implementation and interface may still
39+
# be subject to significant changes.
40+
bandersnatch-experimental = [
41+
"sp-core/bandersnatch-experimental",
42+
"sp-keystore/bandersnatch-experimental",
43+
]

client/keystore/src/local.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
2020
use parking_lot::RwLock;
2121
use sp_application_crypto::{AppCrypto, AppPair, IsWrappedBy};
22+
#[cfg(feature = "bandersnatch-experimental")]
23+
use sp_core::bandersnatch;
2224
#[cfg(feature = "bls-experimental")]
2325
use sp_core::{bls377, bls381};
2426
use sp_core::{
@@ -234,6 +236,69 @@ impl Keystore for LocalKeystore {
234236
Ok(sig)
235237
}
236238

239+
#[cfg(feature = "bandersnatch-experimental")]
240+
fn bandersnatch_public_keys(&self, key_type: KeyTypeId) -> Vec<bandersnatch::Public> {
241+
self.public_keys::<bandersnatch::Pair>(key_type)
242+
}
243+
244+
/// Generate a new pair compatible with the 'bandersnatch' signature scheme.
245+
///
246+
/// If `[seed]` is `Some` then the key will be ephemeral and stored in memory.
247+
#[cfg(feature = "bandersnatch-experimental")]
248+
fn bandersnatch_generate_new(
249+
&self,
250+
key_type: KeyTypeId,
251+
seed: Option<&str>,
252+
) -> std::result::Result<bandersnatch::Public, TraitError> {
253+
self.generate_new::<bandersnatch::Pair>(key_type, seed)
254+
}
255+
256+
#[cfg(feature = "bandersnatch-experimental")]
257+
fn bandersnatch_sign(
258+
&self,
259+
key_type: KeyTypeId,
260+
public: &bandersnatch::Public,
261+
msg: &[u8],
262+
) -> std::result::Result<Option<bandersnatch::Signature>, TraitError> {
263+
self.sign::<bandersnatch::Pair>(key_type, public, msg)
264+
}
265+
266+
#[cfg(feature = "bandersnatch-experimental")]
267+
fn bandersnatch_vrf_sign(
268+
&self,
269+
key_type: KeyTypeId,
270+
public: &bandersnatch::Public,
271+
data: &bandersnatch::vrf::VrfSignData,
272+
) -> std::result::Result<Option<bandersnatch::vrf::VrfSignature>, TraitError> {
273+
self.vrf_sign::<bandersnatch::Pair>(key_type, public, data)
274+
}
275+
276+
#[cfg(feature = "bandersnatch-experimental")]
277+
fn bandersnatch_vrf_output(
278+
&self,
279+
key_type: KeyTypeId,
280+
public: &bandersnatch::Public,
281+
input: &bandersnatch::vrf::VrfInput,
282+
) -> std::result::Result<Option<bandersnatch::vrf::VrfOutput>, TraitError> {
283+
self.vrf_output::<bandersnatch::Pair>(key_type, public, input)
284+
}
285+
286+
#[cfg(feature = "bandersnatch-experimental")]
287+
fn bandersnatch_ring_vrf_sign(
288+
&self,
289+
key_type: KeyTypeId,
290+
public: &bandersnatch::Public,
291+
data: &bandersnatch::vrf::VrfSignData,
292+
prover: &bandersnatch::ring_vrf::RingProver,
293+
) -> std::result::Result<Option<bandersnatch::ring_vrf::RingVrfSignature>, TraitError> {
294+
let sig = self
295+
.0
296+
.read()
297+
.key_pair_by_type::<bandersnatch::Pair>(public, key_type)?
298+
.map(|pair| pair.ring_vrf_sign(data, prover));
299+
Ok(sig)
300+
}
301+
237302
#[cfg(feature = "bls-experimental")]
238303
fn bls381_public_keys(&self, key_type: KeyTypeId) -> Vec<bls381::Public> {
239304
self.public_keys::<bls381::Pair>(key_type)

primitives/application-crypto/Cargo.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,18 @@ full_crypto = [
5252
"sp-io/disable_oom",
5353
]
5454

55-
# This feature adds BLS crypto primitives. It should not be used in production since
56-
# the BLS implementation and interface may still be subject to significant change.
55+
# This feature adds BLS crypto primitives.
56+
# It should not be used in production since the implementation and interface may still
57+
# be subject to significant changes.
5758
bls-experimental = [
5859
"sp-core/bls-experimental",
5960
"sp-io/bls-experimental",
6061
]
62+
63+
# This feature adds Bandersnatch crypto primitives.
64+
# It should not be used in production since the implementation and interface may still
65+
# be subject to significant changes.
66+
bandersnatch-experimental = [
67+
"sp-core/bandersnatch-experimental",
68+
"sp-io/bandersnatch-experimental",
69+
]

0 commit comments

Comments
 (0)