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

Paired-key Crypto Scheme #14705

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions primitives/core/src/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ trait BlsBound: EngineBLS + HardJunctionId + Send + Sync + 'static {}

impl<T: EngineBLS + HardJunctionId + Send + Sync + 'static> BlsBound for T {}

// Secret key serialized size
/// Secret key serialized size
#[cfg(feature = "full_crypto")]
const SECRET_KEY_SERIALIZED_SIZE: usize =
<SecretKey<TinyBLS381> as SerializableToBytes>::SERIALIZED_BYTES_SIZE;

// Public key serialized size
const PUBLIC_KEY_SERIALIZED_SIZE: usize =
/// Public key serialized size
pub const PUBLIC_KEY_SERIALIZED_SIZE: usize =
<DoublePublicKey<TinyBLS381> as SerializableToBytes>::SERIALIZED_BYTES_SIZE;

// Signature serialized size
const SIGNATURE_SERIALIZED_SIZE: usize =
/// Signature serialized size
pub const SIGNATURE_SERIALIZED_SIZE: usize =
<DoubleSignature<TinyBLS381> as SerializableToBytes>::SERIALIZED_BYTES_SIZE;

/// A secret seed.
Expand Down Expand Up @@ -258,7 +258,7 @@ impl<T> sp_std::fmt::Debug for Public<T> {
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<T: BlsBound> Serialize for Public<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -268,7 +268,7 @@ impl<T: BlsBound> Serialize for Public<T> {
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<'de, T: BlsBound> Deserialize<'de> for Public<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -330,7 +330,7 @@ impl<T> TryFrom<&[u8]> for Signature<T> {
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<T> Serialize for Signature<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -340,7 +340,7 @@ impl<T> Serialize for Signature<T> {
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<'de, T> Deserialize<'de> for Signature<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -529,11 +529,10 @@ mod test {
);
}

// Only passes if the seed = (seed mod ScalarField)
#[test]
fn seed_and_derive_should_work() {
let seed = array_bytes::hex2array_unchecked(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f00",
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60",
);
let pair = Pair::from_seed(&seed);
// we are using hash to field so this is not going to work
Expand All @@ -543,7 +542,7 @@ mod test {
assert_eq!(
derived.to_raw_vec(),
array_bytes::hex2array_unchecked::<_, 32>(
"a4f2269333b3e87c577aa00c4a2cd650b3b30b2e8c286a47c251279ff3a26e0d"
"3a0626d095148813cd1642d38254f1cfff7eb8cc1a2fc83b2a135377c3554c12"
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion primitives/core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ macro_rules! impl_from_entropy_base {
[$type; 17], [$type; 18], [$type; 19], [$type; 20], [$type; 21], [$type; 22], [$type; 23], [$type; 24],
[$type; 25], [$type; 26], [$type; 27], [$type; 28], [$type; 29], [$type; 30], [$type; 31], [$type; 32],
[$type; 36], [$type; 40], [$type; 44], [$type; 48], [$type; 56], [$type; 64], [$type; 72], [$type; 80],
[$type; 96], [$type; 112], [$type; 128], [$type; 160], [$type; 192], [$type; 224], [$type; 256]
[$type; 96], [$type; 112], [$type; 128], [$type; 160], [$type; 177], [$type; 192], [$type; 224], [$type; 256]
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion primitives/core/src/hexdisplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ macro_rules! impl_non_endians {
impl_non_endians!(
[u8; 1], [u8; 2], [u8; 3], [u8; 4], [u8; 5], [u8; 6], [u8; 7], [u8; 8], [u8; 10], [u8; 12],
[u8; 14], [u8; 16], [u8; 20], [u8; 24], [u8; 28], [u8; 32], [u8; 40], [u8; 48], [u8; 56],
[u8; 64], [u8; 65], [u8; 80], [u8; 96], [u8; 112], [u8; 128], [u8; 144]
[u8; 64], [u8; 65], [u8; 80], [u8; 96], [u8; 112], [u8; 128], [u8; 144], [u8; 177]
);

/// Format into ASCII + # + hex, suitable for storage key preimages.
Expand Down
1 change: 1 addition & 0 deletions primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub use paste;
pub mod bandersnatch;
#[cfg(feature = "bls-experimental")]
pub mod bls;
pub mod paired_crypto;
pub mod defer;
pub mod ecdsa;
pub mod ed25519;
Expand Down
Loading