hashStrToField function

BigInt hashStrToField(
  1. String str,
  2. int maxSizeBytes
)

Hashes a string to a field element via Poseidon hashing. This function is useful for converting a string into a fixed-size hash that can be used in cryptographic applications.

str is the string to be hashed and maxSizeBytes the maximum size in bytes for the resulting hash.

Implementation

BigInt hashStrToField(String str, int maxSizeBytes) {
  final strBytes = Uint8List.fromList(utf8.encode(str));
  return _hashBytesWithLen(strBytes, maxSizeBytes);
}