fromHexString static method
Decodes a hex string (with an optional 0x prefix) into bytes.
paddingZero left-pads a zero when the string has odd length.
Throws BuError on an invalid hex string.
Implementation
static BuBytes fromHexString(String hexStr, {bool paddingZero = false}) {
try {
String hexString = StringUtils.strip0x(hexStr);
if (hexString.isEmpty) return BuBytes.empty();
if (paddingZero && hexString.length.isOdd) {
hexString = "0$hexString";
}
return hex.hex.decode(hexString);
} catch (e) {
throw CoreErrors.invalidOperationArguments(
"fromHexString",
name: "hexStr",
reason: "invalid hex string.",
);
}
}