James 3 meses atrás
pai
commit
4cefb22af3
1 arquivos alterados com 8 adições e 3 exclusões
  1. 8 3
      lib/util/hexUtils.dart

+ 8 - 3
lib/util/hexUtils.dart

@@ -59,12 +59,17 @@ String intToHex(i) {
 }
 
 /// Converts an [int] or [BigInt] to a [Uint8List]
-Uint8List intToBuffer(i) {
+Uint8List intToBytes(i) {
   return Uint8List.fromList(i == null || i == 0 || i == BigInt.zero ? [] : hex.decode(padToEven(intToHex(i).substring(2))));
 }
 
-Uint8List stringToBuffer(String i) {
-  return Uint8List.fromList(i.isEmpty ? [] : hex.decode(padToEven(stripHexPrefix(i))));
+Uint8List stringToBytes(String str) {
+  ArgumentError.checkNotNull(str);
+  if (str.isEmpty) {
+    return Uint8List(0);
+  }
+  // Use UTF-8 encoding to convert string to bytes
+  return Uint8List.fromList(utf8.encode(str));
 }
 
 /// Get the binary size of a string