Hashing
Poseidon
Poseidon is the most efficient hashing algorithm for o1js, and it should be used for general purpose hashing. It operates over Field arrays, and all provable types can be converted to Field arrays.
const h = Poseidon.hash([Field(1), Field(2), Field(3)]);
const h2 = Poseidon.hash(PrivateKey.random().toFields());
Other Hash Functions
Other hash functions are supported, but should be reserved for cases where a specific hash function is required. For example, proving verification of an ethereum hash would involve calculating a keccak hash. In general, these other hash functions operate over blocks of bytes of a specific size (like 32 bytes).
class Bytes32 extends Bytes(32) {}
const blake = Hash.BLAKE2B.hash(Bytes32.random());
const sha256 = Hash.SHA2_256.hash(Bytes32.random());
const keccak = Hash.Keccak256.hash(Bytes32.random());