(hexString: string)
| 14 | }; |
| 15 | |
| 16 | export const hexStringToArrayBuffer = (hexString: string): ArrayBuffer => { |
| 17 | // Ensure the hex string has an even length |
| 18 | if (hexString.length % 2 !== 0) { |
| 19 | throw new Error('Hex string must have an even length'); |
| 20 | } |
| 21 | |
| 22 | // Convert hex string to byte array |
| 23 | const byteArray = new Uint8Array(hexString.length / 2); |
| 24 | for (let i = 0; i < hexString.length; i += 2) { |
| 25 | byteArray[i / 2] = parseInt(hexString.substring(i, i + 2), 16); |
| 26 | } |
| 27 | |
| 28 | // Create an ArrayBuffer from the byte array |
| 29 | const arrayBuffer = byteArray.buffer; |
| 30 | |
| 31 | return arrayBuffer; |
| 32 | }; |
no outgoing calls
no test coverage detected