(hexString)
| 228 | }; |
| 229 | |
| 230 | export function hexToUint8Array(hexString) { |
| 231 | assertString(hexString); |
| 232 | |
| 233 | if (hexString.length % 2 !== 0) { |
| 234 | throw new Error('Invalid Hex string length.'); |
| 235 | } |
| 236 | |
| 237 | const resultLength = hexString.length / 2; |
| 238 | const bytes = new Uint8Array(resultLength); |
| 239 | |
| 240 | for (let index = 0; index < resultLength; index++) { |
| 241 | const highNibble = hexToDecimalLookupTable[hexString[index * 2]]; |
| 242 | const lowNibble = hexToDecimalLookupTable[hexString[index * 2 + 1]]; |
| 243 | |
| 244 | if (highNibble === undefined || lowNibble === undefined) { |
| 245 | throw new Error(`Invalid Hex character encountered at position ${index * 2}`); |
| 246 | } |
| 247 | |
| 248 | bytes[index] = (highNibble << 4) | lowNibble; // eslint-disable-line no-bitwise |
| 249 | } |
| 250 | |
| 251 | return bytes; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | @param {DataView} view |
no test coverage detected