aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/@exodus/bytes/wif.d.ts
blob: 6e038a10afabbd8eba13424bffa6076d7d4c7e7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
 * Wallet Import Format (WIF) encoding and decoding.
 *
 * ```js
 * import { fromWifString, toWifString } from '@exodus/bytes/wif.js'
 * import { fromWifStringSync, toWifStringSync } from '@exodus/bytes/wif.js'
 * ```
 *
 * On non-Node.js, requires peer dependency [@noble/hashes](https://www.npmjs.com/package/@noble/hashes) to be installed.
 *
 * @module @exodus/bytes/wif.js
 */

/// <reference types="node" />

import type { Uint8ArrayBuffer } from './array.js';

/**
 * WIF (Wallet Import Format) data structure
 */
export interface Wif {
  /** Network version byte */
  version: number;
  /** 32-byte private key */
  privateKey: Uint8ArrayBuffer;
  /** Whether the key is compressed */
  compressed: boolean;
}

/**
 * Decode a WIF string to WIF data
 *
 * Returns a promise that resolves to an object with `{ version, privateKey, compressed }`.
 *
 * The optional `version` parameter validates the version byte.
 *
 * Throws if the WIF string is invalid or version doesn't match.
 *
 * @param string - The WIF encoded string
 * @param version - Optional expected version byte to validate against
 * @returns The decoded WIF data
 * @throws Error if the WIF string is invalid or version doesn't match
 */
export function fromWifString(string: string, version?: number): Promise<Wif>;

/**
 * Decode a WIF string to WIF data (synchronous)
 *
 * Returns an object with `{ version, privateKey, compressed }`.
 *
 * The optional `version` parameter validates the version byte.
 *
 * Throws if the WIF string is invalid or version doesn't match.
 *
 * @param string - The WIF encoded string
 * @param version - Optional expected version byte to validate against
 * @returns The decoded WIF data
 * @throws Error if the WIF string is invalid or version doesn't match
 */
export function fromWifStringSync(string: string, version?: number): Wif;

/**
 * Encode WIF data to a WIF string
 *
 * @param wif - The WIF data to encode
 * @returns The WIF encoded string
 */
export function toWifString(wif: Wif): Promise<string>;

/**
 * Encode WIF data to a WIF string (synchronous)
 *
 * @param wif - The WIF data to encode
 * @returns The WIF encoded string
 */
export function toWifStringSync(wif: Wif): string;