function hexStringToBytes(value) {
  if (typeof value !== "string") {
    throw new TypeError("value is not a string")
  }
  if (!/^([0-9a-f][0-9a-f])*$/.test(value)) {
    throw new RangeError("value is not hexadecimal")
  }
  if (value === "") {
    return new Uint8Array(0)
  } else {
    return new Uint8Array(value.match(/../g).map(b => parseInt(b, 16)))
  }
}
Converts a string consisting of hexadecimal digits into an Uint8Array.