toBytes static method

ByteArray toBytes(
  1. dynamic value,
  2. int length
)

Convert a number to a byte array of specified length

Implementation

static ByteArray toBytes(dynamic value, int length) {
  String hex;
  if (value is int) {
    hex = value.toRadixString(16).padLeft(length * 2, '0');
  } else if (value is BigInt) {
    hex = value.toRadixString(16).padLeft(length * 2, '0');
  } else {
    throw ArgumentError('Value must be int or BigInt');
  }
  return ByteUtils.hexToBytes(hex);
}