1 stable release
new 1.0.0 | Apr 6, 2025 |
---|
#24 in #salt
95 downloads per month
14KB
cw-argon2
Helpers to use argon2 hashing in CosmWasm contracts
Features
- Calculate hash bytes from password and salt
- Convert bech32 addresses to a salt
- Convert hex string to hash bytes
- Convert hash bytes to normalized decimal
Usage
use cosmwasm_std::{Addr, Decimal, Env, StdResult};
use cw_argon2::{address_to_salt, calc_hash_bytes, Hash};
pub fn get_random_weight(
env: &Env,
sender_address: &Addr,
previous_weight: &Decimal,
) -> StdResult<Decimal> {
let password = &format!("{}{}", previous_weight, env.block.time.nanos());
let salt = &address_to_salt(sender_address);
let hash_bytes = calc_hash_bytes(password, salt)?;
Ok(Hash::from(hash_bytes).to_norm_dec())
}
Licenses
This repo is licensed under Apache 2.0.
Dependencies
~4.5–8MB
~163K SLoC