use crate::{env::internal, unwrap::UnwrapInfallible, Bytes, BytesN, Env};
pub struct Crypto {
env: Env,
}
impl Crypto {
pub(crate) fn new(env: &Env) -> Crypto {
Crypto { env: env.clone() }
}
pub fn env(&self) -> &Env {
&self.env
}
pub fn sha256(&self, data: &Bytes) -> BytesN<32> {
let env = self.env();
let bin = internal::Env::compute_hash_sha256(env, data.into()).unwrap_infallible();
unsafe { BytesN::unchecked_new(env.clone(), bin) }
}
pub fn ed25519_verify(&self, public_key: &BytesN<32>, message: &Bytes, signature: &BytesN<64>) {
let env = self.env();
let _ = internal::Env::verify_sig_ed25519(
env,
public_key.to_object(),
message.to_object(),
signature.to_object(),
);
}
}