Remove verify_eip191_identity_proof and verify_ed25519_signature functions

This commit is contained in:
silverpill 2023-03-14 23:07:30 +00:00
parent 1d4bb200d2
commit 43b56be722
5 changed files with 25 additions and 41 deletions

View file

@ -6,11 +6,14 @@ use crate::activitypub::vocabulary::{
PROPERTY_VALUE,
};
use crate::errors::ValidationError;
use crate::ethereum::identity::verify_eip191_identity_proof;
use crate::ethereum::identity::verify_eip191_signature;
use crate::identity::{
claims::create_identity_claim,
did::Did,
minisign::verify_minisign_identity_proof,
minisign::{
parse_minisign_signature,
verify_minisign_signature,
},
};
use crate::json_signatures::proofs::{
PROOF_TYPE_ID_EIP191,
@ -68,17 +71,19 @@ pub fn parse_identity_proof(
if !matches!(proof_type, IdentityProofType::LegacyMinisignIdentityProof) {
return Err(ValidationError("incorrect proof type"));
};
verify_minisign_identity_proof(
let signature_bin = parse_minisign_signature(signature)
.map_err(|_| ValidationError("invalid signature encoding"))?;
verify_minisign_signature(
did_key,
&message,
signature,
&signature_bin,
).map_err(|_| ValidationError("invalid identity proof"))?;
},
Did::Pkh(ref did_pkh) => {
if !matches!(proof_type, IdentityProofType::LegacyEip191IdentityProof) {
return Err(ValidationError("incorrect proof type"));
};
verify_eip191_identity_proof(
verify_eip191_signature(
did_pkh,
&message,
signature,

View file

@ -24,15 +24,6 @@ pub fn verify_eip191_signature(
Ok(())
}
/// Verifies proof of address ownership
pub fn verify_eip191_identity_proof(
did: &DidPkh,
message: &str,
signature_hex: &str,
) -> Result<(), Eip191VerificationError> {
verify_eip191_signature(did, message, signature_hex)
}
#[cfg(test)]
mod tests {
use web3::signing::{Key, SecretKeyRef};
@ -49,7 +40,7 @@ mod tests {
const ETHEREUM: Currency = Currency::Ethereum;
#[test]
fn test_verify_eip191_identity_proof() {
fn test_verify_eip191_signature() {
let message = "test";
let secret_key = generate_ecdsa_key();
let secret_key_ref = SecretKeyRef::new(&secret_key);
@ -58,7 +49,7 @@ mod tests {
let did = DidPkh::from_address(&ETHEREUM, &address);
let signature = sign_message(&secret_key_str, message.as_bytes())
.unwrap().to_string();
let result = verify_eip191_identity_proof(&did, message, &signature);
let result = verify_eip191_signature(&did, message, &signature);
assert_eq!(result.is_ok(), true);
}
}

View file

@ -105,23 +105,7 @@ pub enum VerificationError {
SignatureError(#[from] SignatureError),
}
pub fn verify_minisign_identity_proof(
signer: &DidKey,
message: &str,
signature: &str,
) -> Result<(), VerificationError> {
let ed25519_key = signer.try_ed25519_key()?;
let ed25519_signature = parse_minisign_signature(signature)?;
let message = format!("{}\n", message);
_verify_ed25519_signature(
&message,
ed25519_key,
ed25519_signature,
)?;
Ok(())
}
pub fn verify_ed25519_signature(
pub fn verify_minisign_signature(
signer: &DidKey,
message: &str,
signature: &[u8],
@ -150,6 +134,8 @@ mod tests {
let minisign_signature =
"RUSA58rRENpGFVKxdZGMG1WdIJ+dlyP83qOqw6GP0H/Li6Brug2A3mFKLtleIRLi6IIG0smzOlX5CEsisNnc897OUHIOSNLsQQs=";
let signer = minisign_key_to_did(minisign_key).unwrap();
verify_minisign_identity_proof(&signer, message, minisign_signature).unwrap();
let signature_bin = parse_minisign_signature(minisign_signature).unwrap();
let result = verify_minisign_signature(&signer, message, &signature_bin);
assert_eq!(result.is_ok(), true);
}
}

View file

@ -18,7 +18,7 @@ use crate::identity::{
did::Did,
did_key::DidKey,
did_pkh::DidPkh,
minisign::verify_ed25519_signature,
minisign::verify_minisign_signature,
};
use super::create::{
IntegrityProof,
@ -126,7 +126,7 @@ pub fn verify_ed25519_json_signature(
message: &str,
signature: &[u8],
) -> Result<(), VerificationError> {
verify_ed25519_signature(signer, message, signature)
verify_minisign_signature(signer, message, signature)
.map_err(|_| VerificationError::InvalidSignature)
}

View file

@ -37,7 +37,7 @@ use crate::ethereum::{
contracts::ContractSet,
eip4361::verify_eip4361_signature,
gate::is_allowed_user,
identity::verify_eip191_identity_proof,
identity::verify_eip191_signature,
};
use crate::http::get_request_base_url;
use crate::identity::{
@ -47,7 +47,7 @@ use crate::identity::{
minisign::{
minisign_key_to_did,
parse_minisign_signature,
verify_minisign_identity_proof,
verify_minisign_signature,
},
};
use crate::json_signatures::{
@ -406,10 +406,12 @@ async fn create_identity_proof(
// Verify proof
let proof_type = match did {
Did::Key(ref did_key) => {
verify_minisign_identity_proof(
let signature_bin = parse_minisign_signature(&proof_data.signature)
.map_err(|_| ValidationError("invalid signature encoding"))?;
verify_minisign_signature(
did_key,
&message,
&proof_data.signature,
&signature_bin,
).map_err(|_| ValidationError("invalid signature"))?;
IdentityProofType::LegacyMinisignIdentityProof
},
@ -427,7 +429,7 @@ async fn create_identity_proof(
return Err(ValidationError("DID doesn't match current identity").into());
};
};
verify_eip191_identity_proof(
verify_eip191_signature(
did_pkh,
&message,
&proof_data.signature,