Skip to content

Commit

Permalink
adding generate pop to all crypto types
Browse files Browse the repository at this point in the history
  • Loading branch information
coax1d committed Nov 14, 2024
1 parent 38cb0ff commit 2334b58
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
7 changes: 7 additions & 0 deletions substrate/primitives/application-crypto/src/bandersnatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ impl RuntimePublic for Public {
false
}

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())
}

fn verify_pop(&self, pop: &Self::Signature) -> bool {
let pop = AppSignature::from(pop.clone());
let pub_key = AppPublic::from(self.clone());
Expand Down
7 changes: 7 additions & 0 deletions substrate/primitives/application-crypto/src/bls381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ impl RuntimePublic for Public {
false
}

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::bls381_sign(key_type, self, pop_statement.as_slice())
}

fn verify_pop(&self, pop: &Self::Signature) -> bool {
let pop = AppSignature::from(pop.clone());
let pub_key = AppPublic::from(self.clone());
Expand Down
7 changes: 7 additions & 0 deletions substrate/primitives/application-crypto/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ impl RuntimePublic for Public {
sp_io::crypto::ecdsa_verify(signature, msg.as_ref(), self)
}

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::ecdsa_sign(key_type, self, pop_statement.as_slice())
}

fn verify_pop(&self, pop: &Self::Signature) -> bool {
let pop = AppSignature::from(pop.clone());
let pub_key = AppPublic::from(self.clone());
Expand Down
13 changes: 10 additions & 3 deletions substrate/primitives/application-crypto/src/ecdsa_bls381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ impl RuntimePublic for Public {
false
}

// fn verify_pop(&self, pop: &Self::Signature) -> bool {
// AppPair::verify_proof_of_possession(pop.as_ptr(), self)
// }
fn generate_pop(&mut self, key_type: KeyTypeId) -> Option<Self::Signature> {
// TODO: Implement Special Case
None
}

fn verify_pop(&self, pop: &Self::Signature) -> bool {
let pop = AppSignature::from(pop.clone());
let pub_key = AppPublic::from(self.clone());
AppPair::verify_proof_of_possession(&pop, &pub_key)
}

fn to_raw_vec(&self) -> Vec<u8> {
sp_core::crypto::ByteArray::to_raw_vec(self)
Expand Down
12 changes: 6 additions & 6 deletions substrate/primitives/application-crypto/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ impl RuntimePublic for Public {
sp_io::crypto::ed25519_verify(signature, msg.as_ref(), self)
}

// fn generate_pop(&mut self, key_type: KeyTypeId) -> Option<Self::Signature> {
// let pub_key_as_bytes = self.public().to_raw_vec();
// let pop_context_tag: &[u8] = b"POP_";
// let pop_statement = [pop_context_tag, pub_key_as_bytes.as_slice()].concat();
// self.sign(key_type, pop_statement.as_slice())
// }
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::ed25519_sign(key_type, self, pop_statement.as_slice())
}

fn verify_pop(&self, pop: &Self::Signature) -> bool {
let pop = AppSignature::from(pop.clone());
Expand Down
7 changes: 7 additions & 0 deletions substrate/primitives/application-crypto/src/sr25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ impl RuntimePublic for Public {
sp_io::crypto::sr25519_verify(signature, msg.as_ref(), self)
}

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::sr25519_sign(key_type, self, pop_statement.as_slice())
}

fn verify_pop(&self, pop: &Self::Signature) -> bool {
let pop = AppSignature::from(pop.clone());
let pub_key = AppPublic::from(self.clone());
Expand Down

0 comments on commit 2334b58

Please sign in to comment.