Ed25519
CosmWasm offers an API to verify and batch verify Ed25519 signatures. This is powerful, especially since batch verifications require a random component which is impossible to implement in contract code.
Ed25519 is known to have issues with inconsistent validation criteria (opens in a new tab), the API we offer follows ZIP215 (opens in a new tab). This means you will have no issues with signatures being valid in one place and invalid in another.
Example
contract.rs
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(
deps: Deps,
_env: Env,
msg: Ed25519VerifyMsg,
) -> StdResult<QueryResponse> {
let public_key = msg.public_key;
let signature = msg.signature;
let message = msg.message;
// Verify the signature. On chain!
let is_valid = deps.api.ed25519_verify(&message, &signature, &public_key)?;
let response = to_json_binary(&VerifyResponse {
is_valid
})?;
Ok(response)
}