Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauthamastro committed Jan 19, 2024
1 parent ee5d2ee commit afcce97
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 325 deletions.
3 changes: 2 additions & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pub struct ExecutorDispatch;
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
type ExtendHostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
// NOTE: BLS host functions is a un-removable relic and should not be used or removed from here
// NOTE: BLS host functions is a un-removable relic and should not be used or removed from
// here
bls_primitives::host_functions::bls_crypto_ext::HostFunctions,
sp_statement_store::runtime_api::HostFunctions,
);
Expand Down
72 changes: 36 additions & 36 deletions primitives/bls/src/application_crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// DISCLAIMER: This module is deprecated and exists solely for the host function required during block sync.
// It will not be maintained and must not be used in production.
// DISCLAIMER: This module is deprecated and exists solely for the host function required during
// block sync. It will not be maintained and must not be used in production.

#[cfg(feature = "std")]
pub use app::Pair as AppPair;
Expand All @@ -28,52 +28,52 @@ use sp_std::vec::Vec;
pub use crate::*;

pub mod app {
use sp_core::crypto::KeyTypeId;
use sp_core::crypto::KeyTypeId;

pub const BLS: KeyTypeId = KeyTypeId(*b"blsk");
pub const BLS: KeyTypeId = KeyTypeId(*b"blsk");

sp_application_crypto::app_crypto!(super, BLS);
sp_application_crypto::app_crypto!(super, BLS);

// impl sp_application_crypto::BoundToRuntimeAppPublic for Public {
// type Public = Self;
// }
// impl sp_application_crypto::BoundToRuntimeAppPublic for Public {
// type Public = Self;
// }
}

impl RuntimePublic for Public {
type Signature = Signature;
type Signature = Signature;

fn all(_: KeyTypeId) -> Vec<Self> {
unimplemented!(
"BLS12-381 Host functions are not yet available in Polkadot,\
fn all(_: KeyTypeId) -> Vec<Self> {
unimplemented!(
"BLS12-381 Host functions are not yet available in Polkadot,\
so this will not work"
)
}
)
}

#[cfg(not(feature = "parachain"))]
fn generate_pair(key: KeyTypeId, seed: Option<Vec<u8>>) -> Self {
crate::host_functions::bls_crypto_ext::bls_generate_pair(key, seed)
}
#[cfg(not(feature = "parachain"))]
fn generate_pair(key: KeyTypeId, seed: Option<Vec<u8>>) -> Self {
crate::host_functions::bls_crypto_ext::bls_generate_pair(key, seed)
}

#[cfg(feature = "parachain")]
fn generate_pair(_: KeyTypeId, _: Option<Vec<u8>>) -> Self {
unimplemented!(
"BLS12-381 Host functions are not yet available in Polkadot,\
#[cfg(feature = "parachain")]
fn generate_pair(_: KeyTypeId, _: Option<Vec<u8>>) -> Self {
unimplemented!(
"BLS12-381 Host functions are not yet available in Polkadot,\
so this will not work"
)
}
)
}

fn sign<M: AsRef<[u8]>>(&self, _: KeyTypeId, _: &M) -> Option<Self::Signature> {
unimplemented!(
"BLS12-381 Host functions are not yet available in Polkadot,\
fn sign<M: AsRef<[u8]>>(&self, _: KeyTypeId, _: &M) -> Option<Self::Signature> {
unimplemented!(
"BLS12-381 Host functions are not yet available in Polkadot,\
so this will not work"
)
}
)
}

fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
signature.verify(&[*self], msg.as_ref())
}
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
signature.verify(&[*self], msg.as_ref())
}

fn to_raw_vec(&self) -> Vec<u8> {
self.0.to_vec()
}
}
fn to_raw_vec(&self) -> Vec<u8> {
self.0.to_vec()
}
}
44 changes: 22 additions & 22 deletions primitives/bls/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// DISCLAIMER: This module is deprecated and exists solely for the host function required during block sync.
// It will not be maintained and must not be used in production.
// DISCLAIMER: This module is deprecated and exists solely for the host function required during
// block sync. It will not be maintained and must not be used in production.

use sp_application_crypto::RuntimePublic;
use sp_core::crypto::KeyTypeId;
Expand All @@ -35,23 +35,23 @@ use sp_externalities::ExternalitiesExt;

#[runtime_interface]
pub trait BLSCryptoExt {
fn bls_generate_pair(&mut self, id: KeyTypeId, seed: Option<Vec<u8>>) -> Public {
let (pair, seed) = match seed {
None => {
let (pair, seed_string, _) = crate::Pair::generate_with_phrase(None);
(pair, seed_string)
},
Some(seed) => {
let seed = String::from_utf8(seed).expect("expected seed to be Utf-8");
(crate::Pair::from_string(seed.as_str(), None).expect("Seed not valid!"), seed)
},
};
let keystore = &***self
.extension::<KeystoreExt>()
.expect("No `keystore` associated for the current context!");
let public_key = pair.public().to_raw_vec();
<(dyn Keystore + 'static)>::insert(keystore, id, seed.as_str(), public_key.as_slice())
.unwrap();
pair.public()
}
}
fn bls_generate_pair(&mut self, id: KeyTypeId, seed: Option<Vec<u8>>) -> Public {
let (pair, seed) = match seed {
None => {
let (pair, seed_string, _) = crate::Pair::generate_with_phrase(None);
(pair, seed_string)
},
Some(seed) => {
let seed = String::from_utf8(seed).expect("expected seed to be Utf-8");
(crate::Pair::from_string(seed.as_str(), None).expect("Seed not valid!"), seed)
},
};
let keystore = &***self
.extension::<KeystoreExt>()
.expect("No `keystore` associated for the current context!");
let public_key = pair.public().to_raw_vec();
<(dyn Keystore + 'static)>::insert(keystore, id, seed.as_str(), public_key.as_slice())
.unwrap();
pair.public()
}
}
Loading

0 comments on commit afcce97

Please sign in to comment.