bigintToBytesWithPadding static method

List<int> bigintToBytesWithPadding(
  1. BigInt x,
  2. BigInt order
)

Converts a BigInt 'num' into a List

This method converts 'num' into a hexadecimal string, ensuring it's at least 'l' bytes long, and then creates a List

Returns a List

Implementation

static List<int> bigintToBytesWithPadding(BigInt x, BigInt order) {
  String hexStr = x.toRadixString(16);
  int hexLen = hexStr.length;
  int byteLen = (order.bitLength + 7) ~/ 8;

  if (hexLen < byteLen * 2) {
    hexStr = '0' * (byteLen * 2 - hexLen) + hexStr;
  }

  return BytesUtils.fromHexString(hexStr);
}