bech32.d.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Implements bech32 and bech32m from
  3. * [BIP-0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#specification)
  4. * and [BIP-0350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki#specification).
  5. *
  6. * ```js
  7. * import { fromBech32, toBech32 } from '@exodus/bytes/bech32.js'
  8. * import { fromBech32m, toBech32m } from '@exodus/bytes/bech32.js'
  9. * import { getPrefix } from '@exodus/bytes/bech32.js'
  10. * ```
  11. *
  12. * @module @exodus/bytes/bech32.js
  13. */
  14. /// <reference types="node" />
  15. import type { Uint8ArrayBuffer } from './array.js';
  16. /**
  17. * Result of decoding a bech32 or bech32m string
  18. */
  19. export interface Bech32DecodeResult {
  20. /** The human-readable prefix */
  21. prefix: string;
  22. /** The decoded bytes */
  23. bytes: Uint8ArrayBuffer;
  24. }
  25. /**
  26. * Encode bytes to a bech32 string
  27. *
  28. * @param prefix - The human-readable prefix (e.g., 'bc' for Bitcoin)
  29. * @param bytes - The input bytes to encode
  30. * @param limit - Maximum length of the encoded string (default: 90)
  31. * @returns The bech32 encoded string
  32. */
  33. export function toBech32(prefix: string, bytes: Uint8Array, limit?: number): string;
  34. /**
  35. * Decode a bech32 string to bytes
  36. *
  37. * @param string - The bech32 encoded string
  38. * @param limit - Maximum length of the input string (default: 90)
  39. * @returns The decoded prefix and bytes
  40. */
  41. export function fromBech32(string: string, limit?: number): Bech32DecodeResult;
  42. /**
  43. * Encode bytes to a bech32m string
  44. *
  45. * @param prefix - The human-readable prefix (e.g., 'bc' for Bitcoin)
  46. * @param bytes - The input bytes to encode
  47. * @param limit - Maximum length of the encoded string (default: 90)
  48. * @returns The bech32m encoded string
  49. */
  50. export function toBech32m(prefix: string, bytes: Uint8Array, limit?: number): string;
  51. /**
  52. * Decode a bech32m string to bytes
  53. *
  54. * @param string - The bech32m encoded string
  55. * @param limit - Maximum length of the input string (default: 90)
  56. * @returns The decoded prefix and bytes
  57. */
  58. export function fromBech32m(string: string, limit?: number): Bech32DecodeResult;
  59. /**
  60. * Extract the prefix from a bech32 or bech32m string without full validation
  61. *
  62. * This is a quick check that skips most validation.
  63. *
  64. * @param string - The bech32/bech32m encoded string
  65. * @param limit - Maximum length of the input string (default: 90)
  66. * @returns The lowercase prefix
  67. */
  68. export function getPrefix(string: string, limit?: number): string;