sp_application_crypto/
bls381.rs1use crate::{KeyTypeId, RuntimePublic};
20
21use alloc::vec::Vec;
22
23pub use sp_core::bls::{
24 bls381::{BlsEngine as Bls381Engine, *},
25 Pair as BLS_Pair, ProofOfPossession as BLSPoP,
26};
27use sp_core::{crypto::CryptoType, proof_of_possession::ProofOfPossessionVerifier};
28
29mod app {
30 crate::app_crypto!(super, sp_core::testing::BLS381);
31}
32
33#[cfg(feature = "full_crypto")]
34pub use app::Pair as AppPair;
35pub use app::{
36 ProofOfPossession as AppProofOfPossession, Public as AppPublic, Signature as AppSignature,
37};
38
39impl RuntimePublic for Public {
40 type Signature = Signature;
41 type ProofOfPossession = ProofOfPossession;
42
43 fn all(_key_type: KeyTypeId) -> Vec<Self> {
45 Vec::new()
46 }
47
48 fn generate_pair(key_type: KeyTypeId, seed: Option<Vec<u8>>) -> Self {
49 sp_io::crypto::bls381_generate(key_type, seed)
50 }
51
52 fn sign<M: AsRef<[u8]>>(&self, _key_type: KeyTypeId, _msg: &M) -> Option<Self::Signature> {
54 None
55 }
56
57 fn verify<M: AsRef<[u8]>>(&self, _msg: &M, _signature: &Self::Signature) -> bool {
59 false
60 }
61
62 fn generate_proof_of_possession(
63 &mut self,
64 key_type: KeyTypeId,
65 owner: &[u8],
66 ) -> Option<Self::ProofOfPossession> {
67 sp_io::crypto::bls381_generate_proof_of_possession(key_type, self, owner)
68 }
69
70 fn verify_proof_of_possession(
71 &self,
72 owner: &[u8],
73 proof_of_possession: &Self::ProofOfPossession,
74 ) -> bool {
75 let pub_key = AppPublic::from(*self);
76 <AppPublic as CryptoType>::Pair::verify_proof_of_possession(
77 owner,
78 &proof_of_possession,
79 &pub_key,
80 )
81 }
82
83 fn to_raw_vec(&self) -> Vec<u8> {
84 sp_core::crypto::ByteArray::to_raw_vec(self)
85 }
86}