@node-dlc/bitcoin
Version:
42 lines (41 loc) • 1.46 kB
TypeScript
/// <reference types="node" />
export type WifDecodeResult = {
privateKey: Buffer;
compressed: boolean;
prefix: number;
};
export declare class Wif {
/**
* Encodes a private key using the WIF format. Can encode with compressed
* or uncompressed format and can be for testnet or mainnet.
*
* Mainnet prefix: 0x80
* Testnet prefix: 0xef
*
* Algorithm for WIF is:
* 1. Start with the prefix
* 2. Encode the secret in 32-byte big-endian format
* 3. If the SEC format used for the public key address was compressed add
* a suffix of 0x01
* 4. Combine wthe prefix from #1, serialized secret from #2, and suffix from #3
* 5. Do hash256 of the result from #4 and get the first 4 bytes
* 6. Take the combination of #4 and #5 and encode it with Base58
*
* @param privateKey a 32-byte private key as a big-endian buffer
* @param compressed default of true
* @param testnet default of false
*/
static encode(privateKey: Buffer, compressed?: boolean, testnet?: boolean): string;
/**
* To decode a WIF value, we must first decode the base58check
* input. If this validates then we need to split the resulting
* buffer of data into two or three parts.
*
* The first byte is the prefix
* The next 32-bytes are the private key
*
*
* @param buf
*/
static decode(input: string): WifDecodeResult;
}