toAccountId method

Uint8List toAccountId({
  1. Uint8List? subAccount,
})

Implementation

Uint8List toAccountId({Uint8List? subAccount}) {
  if (subAccount != null && subAccount.length != 32) {
    throw ArgumentError.value(
      subAccount,
      'subAccount',
      'Sub-account address must be 32-bytes length',
    );
  }
  final hash = SHA224();
  hash.update('\x0Aaccount-id'.plainToU8a());
  hash.update(toBlob());
  hash.update(subAccount ?? Uint8List(32));
  final data = hash.digest();
  final view = ByteData(4);
  view.setUint32(0, getCrc32(data.buffer));
  final checksum = view.buffer.asUint8List();
  final bytes = Uint8List.fromList(data);
  return Uint8List.fromList([...checksum, ...bytes]);
}