hashBuffer function

BigInt hashBuffer(
  1. Uint8List msgBuff
)

Poseidon hash of a generic buffer @param {Uint8List} msgBuff @returns {BigInt} - final hash

Implementation

BigInt hashBuffer(Uint8List msgBuff) {
  const n = 31;
  const msgArray = [];
  final fullParts = (msgBuff.length / n).floor();
  for (int i = 0; i < fullParts; i++) {
    final v = msgBuff.sublist(n * i, n * (i + 1)).toList();
    msgArray.addAll(v);
  }
  if (msgBuff.length % n != 0) {
    final v = msgBuff.sublist(fullParts * n).toList();
    msgArray.addAll(v);
  }
  return multiHash(msgArray as List<BigInt>);
}