Skip to content

Commit

Permalink
refactor to allow for pair impl from crypto crate to take effect
Browse files Browse the repository at this point in the history
  • Loading branch information
coax1d committed Nov 18, 2024
1 parent ccfee52 commit b948a33
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions substrate/primitives/application-crypto/src/bandersnatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ use crate::{KeyTypeId, RuntimePublic};
use alloc::vec::Vec;
pub use sp_core::bandersnatch::*;

use sp_core::crypto::{ProofOfPossessionGenerator, ProofOfPossessionVerifier};

mod app {
crate::app_crypto!(super, sp_core::testing::BANDERSNATCH);

use sp_core::crypto::SingleScheme;
impl SingleScheme for Pair {}
}

#[cfg(feature = "full_crypto")]
Expand Down Expand Up @@ -55,10 +54,11 @@ impl RuntimePublic for Public {
}

fn generate_pop(&mut self, key_type: KeyTypeId) -> Option<Self::Signature> {
let pub_key_as_bytes = self.to_raw_vec();
let pop_context_tag: &[u8] = b"POP_";
let pop_statement = [pop_context_tag, pub_key_as_bytes.as_slice()].concat();
sp_io::crypto::bandersnatch_sign(key_type, self, pop_statement.as_slice())
// let pub_key_as_bytes = self.to_raw_vec();
// let pop_context_tag: &[u8] = b"POP_";
// let pop_statement = [pop_context_tag, pub_key_as_bytes.as_slice()].concat();
// sp_io::crypto::bandersnatch_sign(key_type, self, pop_statement.as_slice()) There is no sign for bandersnatch..
None
}

fn verify_pop(&self, pop: &Self::Signature) -> bool {
Expand Down
5 changes: 2 additions & 3 deletions substrate/primitives/application-crypto/src/bls381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ use crate::{KeyTypeId, RuntimePublic};
use alloc::vec::Vec;

pub use sp_core::bls::bls381::*;
use sp_core::crypto::{ProofOfPossessionGenerator, ProofOfPossessionVerifier};

mod app {
crate::app_crypto!(super, sp_core::testing::BLS381);

use sp_core::crypto::SingleScheme;
impl SingleScheme for Pair {}
}

#[cfg(feature = "full_crypto")]
Expand Down Expand Up @@ -58,6 +56,7 @@ impl RuntimePublic for Public {
fn generate_pop(&mut self, key_type: KeyTypeId) -> Option<Self::Signature> {
// TODO: Add host function
// sp_io::crypto::generate_pop()
None
}

fn verify_pop(&self, pop: &Self::Signature) -> bool {
Expand Down
3 changes: 0 additions & 3 deletions substrate/primitives/application-crypto/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ use sp_core::crypto::{ProofOfPossessionGenerator, ProofOfPossessionVerifier};

mod app {
crate::app_crypto!(super, sp_core::testing::ECDSA);

use sp_core::crypto::SingleScheme;
impl SingleScheme for Pair {}
}

pub use app::{Pair as AppPair, Public as AppPublic, Signature as AppSignature};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{KeyTypeId, RuntimePublic};
use alloc::vec::Vec;

pub use sp_core::paired_crypto::ecdsa_bls381::*;
use sp_core::crypto::{ProofOfPossessionGenerator, ProofOfPossessionVerifier};

mod app {
crate::app_crypto!(super, sp_core::testing::ECDSA_BLS381);
Expand Down
3 changes: 0 additions & 3 deletions substrate/primitives/application-crypto/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ use sp_core::crypto::{ProofOfPossessionGenerator, ProofOfPossessionVerifier};

mod app {
crate::app_crypto!(super, sp_core::testing::ED25519);

use sp_core::crypto::SingleScheme;
impl SingleScheme for Pair {}
}

pub use app::{Pair as AppPair, Public as AppPublic, Signature as AppSignature};
Expand Down
11 changes: 10 additions & 1 deletion substrate/primitives/application-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern crate alloc;

pub use sp_core::crypto::{key_types, CryptoTypeId, DeriveJunction, KeyTypeId, Ss58Codec};
#[doc(hidden)]
pub use sp_core::crypto::{DeriveError, Pair, SecretStringError};
pub use sp_core::crypto::{DeriveError, Pair, SecretStringError, ProofOfPossessionGenerator, ProofOfPossessionVerifier};
#[doc(hidden)]
pub use sp_core::{
self,
Expand Down Expand Up @@ -177,6 +177,15 @@ macro_rules! app_crypto_pair_common {
}
}

impl $crate::ProofOfPossessionVerifier for Pair {
fn verify_proof_of_possession(
proof_of_possession: &Self::Signature,
allegedly_possessed_pubkey: &Self::Public,
) -> bool {
<$pair>::verify_proof_of_possession(&proof_of_possession.0, allegedly_possessed_pubkey.as_ref())
}
}

impl $crate::AppCrypto for Pair {
type Public = Public;
type Pair = Pair;
Expand Down
3 changes: 0 additions & 3 deletions substrate/primitives/application-crypto/src/sr25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ use sp_core::crypto::ProofOfPossessionVerifier;

mod app {
crate::app_crypto!(super, sp_core::testing::SR25519);

use sp_core::crypto::SingleScheme;
impl SingleScheme for Pair {}
}

pub use app::{Pair as AppPair, Public as AppPublic, Signature as AppSignature};
Expand Down

0 comments on commit b948a33

Please sign in to comment.