when (NimMajor, NimMinor) < (1, 4): {.push raises: [Defect].} else: {.push raises: [].} type HexDataStr* = distinct string Identifier* = distinct string # 32 bytes, no 0x prefix! HexStrings* = HexDataStr | Identifier # Validation template hasHexHeader(value: string): bool = if value.len >= 2 and value[0] == '0' and value[1] in {'x', 'X'}: true else: false template isHexChar(c: char): bool = if c notin {'0'..'9'} and c notin {'a'..'f'} and c notin {'A'..'F'}: false else: true func isValidHexQuantity*(value: string): bool = if not hasHexHeader(value): return false # No leading zeros (but allow 0x0) if value.len < 3 or (value.len > 3 and value[2] == '0'): return false for i in 2..