stack_wallet/lib/utilities/extensions/impl/uint8_list.dart

40 lines
856 B
Dart
Raw Normal View History

2023-03-27 14:01:35 +00:00
import 'dart:convert';
2023-03-03 17:35:43 +00:00
import 'dart:typed_data';
import 'package:dart_bs58/dart_bs58.dart';
import 'package:dart_bs58check/dart_bs58check.dart';
import 'package:hex/hex.dart';
extension Uint8ListExtensions on Uint8List {
2023-03-27 14:01:35 +00:00
String get toUtf8String => utf8.decode(this);
2023-03-03 17:35:43 +00:00
String get toHex {
return HEX.encode(this);
}
String get toBase58Encoded {
return bs58.encode(this);
}
String get toBase58CheckEncoded {
return bs58check.encode(this);
}
/// returns copy of byte list in reverse order
Uint8List get reversed {
final reversed = Uint8List(length);
for (final byte in this) {
reversed.insert(0, byte);
}
return reversed;
}
BigInt get toBigInt {
BigInt number = BigInt.zero;
for (final byte in this) {
number = (number << 8) | BigInt.from(byte & 0xff);
}
return number;
}
}