hexToBase64BJJ function

String hexToBase64BJJ(
  1. String bjjCompressedHex
)

Get API Bjj compressed data format @param {String} bjjCompressedHex Bjj compressed address encoded as hex string @returns {String} API adapted bjj compressed address

Implementation

String hexToBase64BJJ(String bjjCompressedHex) {
  BigInt bjjScalar = hexToInt(bjjCompressedHex);
  Uint8List littleEndianBytes = Uint8ArrayUtils.bigIntToBytes(bjjScalar);
  String bjjSwap =
      bytesToHex(littleEndianBytes, forcePadLength: 64, padToEvenLength: false);
  Uint8List bjjSwapBuffer = hexToBytes(bjjSwap);

  var sum = 0;
  for (var i = 0; i < bjjSwapBuffer.length; i++) {
    sum += bjjSwapBuffer[i];
    sum = sum % (pow(2, 8) as int);
  }

  final BytesBuilder finalBuffBjj = BytesBuilder();
  finalBuffBjj.add(bjjSwapBuffer.toList());
  finalBuffBjj.addByte(sum);

  return 'hez:${base64Url.encode(finalBuffBjj.toBytes())}';
}