sp_application_crypto/
bandersnatch.rs1use crate::{KeyTypeId, RuntimePublic};
21use alloc::vec::Vec;
22pub use sp_core::bandersnatch::*;
23
24use sp_core::{
25 crypto::CryptoType,
26 proof_of_possession::{NonAggregatable, ProofOfPossessionVerifier},
27 Pair as TraitPair,
28};
29
30mod app {
31 crate::app_crypto!(super, sp_core::testing::BANDERSNATCH);
32}
33
34#[cfg(feature = "full_crypto")]
35pub use app::Pair as AppPair;
36pub use app::{Public as AppPublic, Signature as AppSignature};
37
38impl RuntimePublic for Public {
39 type Signature = Signature;
40
41 fn all(_key_type: KeyTypeId) -> Vec<Self> {
43 Vec::new()
44 }
45
46 fn generate_pair(key_type: KeyTypeId, seed: Option<Vec<u8>>) -> Self {
47 sp_io::crypto::bandersnatch_generate(key_type, seed)
48 }
49
50 fn sign<M: AsRef<[u8]>>(&self, key_type: KeyTypeId, msg: &M) -> Option<Self::Signature> {
51 sp_io::crypto::bandersnatch_sign(key_type, self, msg.as_ref())
52 }
53
54 fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
55 let sig = AppSignature::from(*signature);
56 let pub_key = AppPublic::from(*self);
57 <AppPublic as CryptoType>::Pair::verify(&sig, msg.as_ref(), &pub_key)
58 }
59
60 fn generate_proof_of_possession(&mut self, key_type: KeyTypeId) -> Option<Self::Signature> {
61 let proof_of_possession_statement = Pair::proof_of_possession_statement(self);
62 sp_io::crypto::bandersnatch_sign(key_type, self, &proof_of_possession_statement)
63 }
64
65 fn verify_proof_of_possession(&self, proof_of_possession: &Self::Signature) -> bool {
66 let proof_of_possession = AppSignature::from(*proof_of_possession);
67 let pub_key = AppPublic::from(*self);
68 <AppPublic as CryptoType>::Pair::verify_proof_of_possession(&proof_of_possession, &pub_key)
69 }
70
71 fn to_raw_vec(&self) -> Vec<u8> {
72 sp_core::crypto::ByteArray::to_raw_vec(self)
73 }
74}