encode static method

String encode(
  1. List<int> dataBytes,
  2. int ss58Format
)

Encodes SS58 address from the provided data bytes and SS58 format.

Parameters:

  • dataBytes: The data bytes to be encoded into an SS58 address.
  • ss58Format: The SS58 format specifying the address type.

Throws an ArgumentException if the input parameters are invalid, such as incorrect data length, out-of-range SS58 format, or using reserved formats.

Implementation

static String encode(List<int> dataBytes, int ss58Format) {
  if (ss58Format < 0 ||
      ss58Format > _Ss58Const.formatMaxVal ||
      _Ss58Const.reservedFormats.contains(ss58Format)) {
    throw ArgumentException.invalidOperationArguments(
      "decode",
      name: "ss58Str",
      reason: "Invalid SS58.",
    );
  }
  List<int> ss58FormatBytes;

  if (ss58Format <= _Ss58Const.simpleAccountFormatMaxVal) {
    ss58FormatBytes = IntUtils.toBytes(ss58Format, byteOrder: Endian.little);
  } else {
    ss58FormatBytes = [
      ((ss58Format & 0x00FC) >> 2) | 0x0040,
      (ss58Format >> 8) | ((ss58Format & 0x0003) << 6),
    ];
  }

  final payload = [...ss58FormatBytes, ...dataBytes];

  final checksum = _Ss58Utils.computeChecksum(payload);

  return Base58Encoder.encode([...payload, ...checksum]);
}