Utilities
Utilities¶
bytesToHex¶
bytes– array of arbitrary length.byteSize(optional) – if specified, the output is padded with leading zeros tobyteSize * 2characters.
bytesToInt¶
Returns an unsigned bigint value.
hexToBytes¶
- Requirement: string length must be even; otherwise, an exception is thrown.
hexToInt¶
intToBytes¶
byteSize– optional fixed length. If provided, the result is padded with leading zeros.- When passing a
number, internal conversion is performed viaBigInt().
intToHex¶
Similar to intToBytes, but returns a string.
randomBytes¶
- Delegates to
@noble/hashes/utils::randomBytes, which uses the platform's cryptographically secure generator (Web Crypto in browsers /node:cryptoin Node.js). - Guaranteed to return a buffer of exactly the specified length.
Notes¶
- All functions do not modify the input buffers — a new object is always created.
intToHexandintToBytesaccept bothnumberandbigint; however, for values > 2^53, you should usebigintto avoid loss of precision.- When working with keys and hashes, specify
byteSizeto guarantee a fixed length (e.g.,32bytes /64characters).