hex.d.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Implements Base16 from [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648)
  3. * (no differences from [RFC3548](https://datatracker.ietf.org/doc/html/rfc4648)).
  4. *
  5. * ```js
  6. * import { fromHex, toHex } from '@exodus/bytes/hex.js'
  7. * ```
  8. *
  9. * @module @exodus/bytes/hex.js
  10. */
  11. /// <reference types="node" />
  12. import type { OutputFormat, Uint8ArrayBuffer } from './array.js';
  13. /**
  14. * Encode a `Uint8Array` to a lowercase hex string
  15. *
  16. * @param arr - The input bytes
  17. * @returns The hex encoded string
  18. */
  19. export function toHex(arr: Uint8Array): string;
  20. /**
  21. * Decode a hex string to bytes
  22. *
  23. * Unlike `Buffer.from()`, throws on invalid input
  24. *
  25. * @param string - The hex encoded string (case-insensitive)
  26. * @param format - Output format (default: 'uint8')
  27. * @returns The decoded bytes
  28. */
  29. export function fromHex(string: string, format?: 'uint8'): Uint8ArrayBuffer;
  30. export function fromHex(string: string, format: 'buffer'): Buffer;
  31. export function fromHex(string: string, format?: OutputFormat): Uint8ArrayBuffer | Buffer;