Skip to content

Commit

Permalink
simpler key representation
Browse files Browse the repository at this point in the history
  • Loading branch information
ash-burnt committed Nov 16, 2023
1 parent 4e16f97 commit 15ecf10
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 89 deletions.
1 change: 0 additions & 1 deletion account/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use serde::{Deserialize, Serialize};
mod eth_crypto;
mod jwt;
pub mod passkey;
mod passkey2;
mod secp256r1;
mod sign_arb;
pub mod util;
Expand Down
80 changes: 0 additions & 80 deletions account/src/auth/passkey2.rs

This file was deleted.

14 changes: 6 additions & 8 deletions account/src/auth/secp256r1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use p256::ecdsa::{signature::Verifier, Signature, VerifyingKey};
use p256::EncodedPoint;

Check warning on line 4 in account/src/auth/secp256r1.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `p256::EncodedPoint`

Check failure on line 4 in account/src/auth/secp256r1.rs

View workflow job for this annotation

GitHub Actions / Lints

unused import: `p256::EncodedPoint`

pub fn verify(tx_hash: &[u8], sig_bytes: &[u8], pubkey_bytes: &Binary) -> ContractResult<bool> {
let encoded_point = match EncodedPoint::from_bytes(pubkey_bytes) {
Ok(point) => point,
Err(_) => return Err(RebuildingKey),
};
let verifying_key: VerifyingKey = VerifyingKey::from_encoded_point(&encoded_point)?;
let verifying_key: VerifyingKey = VerifyingKey::from_sec1_bytes(pubkey_bytes.as_slice())?;

let signature: Signature = Signature::from_bytes(sig_bytes.into())?;
verifying_key.verify(tx_hash, &signature)?;
Expand All @@ -19,6 +15,7 @@ pub fn verify(tx_hash: &[u8], sig_bytes: &[u8], pubkey_bytes: &Binary) -> Contra
#[cfg(test)]
mod tests {
use crate::auth::secp256r1::verify;
use cosmwasm_std::Binary;
use p256::ecdsa::{signature::Signer, Signature, SigningKey, VerifyingKey};

#[test]
Expand All @@ -34,15 +31,16 @@ mod tests {
println!("signature: {}", hex::encode(signature_bytes));

let verifying_key = VerifyingKey::from(&signing_key);
let verifying_key_bytes = verifying_key.to_encoded_point(true);
let verifying_key_bytes = verifying_key.to_sec1_bytes();
let verifying_key_binary = Binary::from(verifying_key_bytes.to_vec());
println!("verifying key: {}", hex::encode(verifying_key_bytes));

assert_eq!(
true,
verify(
&test_value.to_vec(),
signature_bytes.as_slice(),
&verifying_key_bytes.as_bytes().into(),
&verifying_key_binary,
)
.unwrap()
);
Expand All @@ -52,7 +50,7 @@ mod tests {
let result = verify(
&bad_value.to_vec(),
signature_bytes.as_slice(),
&verifying_key_bytes.as_bytes().into(),
&verifying_key_binary,
);
assert!(result.is_err())
}
Expand Down

0 comments on commit 15ecf10

Please sign in to comment.