bigIntToBytes function

Uint8List bigIntToBytes(
  1. BigInt bigInt
)

Implementation

Uint8List bigIntToBytes(BigInt bigInt) {
  final data = ByteData((bigInt.bitLength / 8).ceil());
  BigInt _bigInt = bigInt;
  for (int i = 1; i <= data.lengthInBytes; i++) {
    data.setUint8(data.lengthInBytes - i, _bigInt.toUnsigned(8).toInt());
    _bigInt = _bigInt >> 8;
  }
  return data.buffer.asUint8List();
}