MCPcopy Create free account
hub / github.com/dfinity/orbit / hexStringToArrayBuffer

Function hexStringToArrayBuffer

apps/wallet/src/utils/crypto.utils.ts:16–32  ·  view source on GitHub ↗
(hexString: string)

Source from the content-addressed store, hash-verified

14};
15
16export 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};

Calls

no outgoing calls

Tested by

no test coverage detected