Hash Credential
Overview
The create_hash
function generates a cryptographic hash using one of the supported algorithms. It returns a Result
containing either the generated hash as a String
or an error using the anyhow
library for extended error handling.
Function Definition
Parameters:
value: The value you want to hash, of type
Value<Testnet3>
.algorithm: An enum representing the hashing algorithm to be used (
HashAlgorithm
).
Returns:
Result<String, anyhow::Error>
: AResult
that will either contain the generated hash as aString
or an error.
Hash Calculation Steps
Conversion: The
value
is first converted into either fields or bits based on the algorithm selected.Hashing: The
Testnet3
object exposes static methods to generate hashes based on the selected algorithm. These methods return aResult
and can fail, leading to error propagation.Final Conversion: For some algorithms, additional steps like converting to a group and then back to a field are performed.
Hash Types
Poseidon2
BHP
Keccak
SHA3
Last updated