MCPcopy Create free account
hub / github.com/NomicFoundation/hardhat / hexStringToBytes

Function hexStringToBytes

packages/hardhat-utils/src/hex.ts:111–123  ·  view source on GitHub ↗
(hexString: string)

Source from the content-addressed store, hash-verified

109 * @throws InvalidParameterError If the input is not a hexadecimal string.
110 */
111export function hexStringToBytes(hexString: string): Uint8Array {
112 if (!isHexString(hexString)) {
113 throw new InvalidParameterError(
114 `Expected a valid hexadecimal string. Received: ${hexString}`,
115 );
116 }
117
118 // Pad the hex string if it's odd, as Buffer.from will truncate it
119 // the last character if it's not a full byte.
120 // See: https://nodejs.org/api/buffer.html#buffers-and-character-encodings
121 const unprefixedHexString = getUnprefixedHexString(padToEven(hexString));
122 return Uint8Array.from(Buffer.from(unprefixedHexString, "hex"));
123}
124
125/**
126 * Normalizes and validates a string that represents a hexadecimal number.

Callers 15

e2e.tsFile · 0.90
local-accounts.tsFile · 0.90
hexToBytesFunction · 0.90
resolveCoinbaseFunction · 0.90
rpc-parity.tsFile · 0.90
address.tsFile · 0.90
hash.tsFile · 0.90
data.tsFile · 0.90
#parseMethod · 0.90
inferExecutableSectionFunction · 0.90

Calls 3

isHexStringFunction · 0.85
getUnprefixedHexStringFunction · 0.85
padToEvenFunction · 0.85

Tested by

no test coverage detected