Utilities
Utilities¶
bytesToHex¶
bytes
– array of arbitrary length.byteSize
(optional) – if specified, the output is padded with leading zeros tobyteSize * 2
characters.
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:crypto
in 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.
intToHex
andintToBytes
accept bothnumber
andbigint
; however, for values > 2^53, you should usebigint
to avoid loss of precision.- When working with keys and hashes, specify
byteSize
to guarantee a fixed length (e.g.,32
bytes /64
characters).