wif.d.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Wallet Import Format (WIF) encoding and decoding.
  3. *
  4. * ```js
  5. * import { fromWifString, toWifString } from '@exodus/bytes/wif.js'
  6. * import { fromWifStringSync, toWifStringSync } from '@exodus/bytes/wif.js'
  7. * ```
  8. *
  9. * On non-Node.js, requires peer dependency [@noble/hashes](https://www.npmjs.com/package/@noble/hashes) to be installed.
  10. *
  11. * @module @exodus/bytes/wif.js
  12. */
  13. /// <reference types="node" />
  14. import type { Uint8ArrayBuffer } from './array.js';
  15. /**
  16. * WIF (Wallet Import Format) data structure
  17. */
  18. export interface Wif {
  19. /** Network version byte */
  20. version: number;
  21. /** 32-byte private key */
  22. privateKey: Uint8ArrayBuffer;
  23. /** Whether the key is compressed */
  24. compressed: boolean;
  25. }
  26. /**
  27. * Decode a WIF string to WIF data
  28. *
  29. * Returns a promise that resolves to an object with `{ version, privateKey, compressed }`.
  30. *
  31. * The optional `version` parameter validates the version byte.
  32. *
  33. * Throws if the WIF string is invalid or version doesn't match.
  34. *
  35. * @param string - The WIF encoded string
  36. * @param version - Optional expected version byte to validate against
  37. * @returns The decoded WIF data
  38. * @throws Error if the WIF string is invalid or version doesn't match
  39. */
  40. export function fromWifString(string: string, version?: number): Promise<Wif>;
  41. /**
  42. * Decode a WIF string to WIF data (synchronous)
  43. *
  44. * Returns an object with `{ version, privateKey, compressed }`.
  45. *
  46. * The optional `version` parameter validates the version byte.
  47. *
  48. * Throws if the WIF string is invalid or version doesn't match.
  49. *
  50. * @param string - The WIF encoded string
  51. * @param version - Optional expected version byte to validate against
  52. * @returns The decoded WIF data
  53. * @throws Error if the WIF string is invalid or version doesn't match
  54. */
  55. export function fromWifStringSync(string: string, version?: number): Wif;
  56. /**
  57. * Encode WIF data to a WIF string
  58. *
  59. * @param wif - The WIF data to encode
  60. * @returns The WIF encoded string
  61. */
  62. export function toWifString(wif: Wif): Promise<string>;
  63. /**
  64. * Encode WIF data to a WIF string (synchronous)
  65. *
  66. * @param wif - The WIF data to encode
  67. * @returns The WIF encoded string
  68. */
  69. export function toWifStringSync(wif: Wif): string;