MiniKeyConverter

MiniKeyConverter

Class for managing and converting Bitcoin MiniKeys.

This class provides utilities for:

  • Generating valid 30-character Bitcoin MiniKeys.
  • Validating MiniKeys to ensure they conform to the correct format.
  • Converting MiniKeys to private keys in HEX format.
  • Converting private keys in HEX format to Wallet Import Format (WIF).

Important: MiniKeys cannot directly generate WIF keys. They must first be converted to HEX format using the miniToHex method, and only then can they be converted to WIF using hexToWif.

Constructor

new MiniKeyConverter()

Source:
Example
const converter = new MiniKeyConverter();

// Generate a new MiniKey
const newMiniKey = converter.generateMiniKey();
console.log(`Generated MiniKey: ${newMiniKey}`);

// Validate a MiniKey
const isValid = converter.check('S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy');
if (isValid) {
  console.log('Valid MiniKey!');
}

// Convert MiniKey to HEX
const hexKey = converter.miniToHex('S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy');
console.log(`HEX Key: ${hexKey}`);

// Convert HEX to WIF
const wifKey = converter.hexToWif(hexKey, false, false);
console.log(`WIF Key: ${wifKey}`);

Methods

check(miniKey, strictModeopt) → {boolean}

Description:
  • Validates a MiniKey to ensure it conforms to the correct format.

    A valid MiniKey:

    • Starts with 'S'.
    • Contains only Base58 characters.
    • Is either 22 or 30 characters long (or only 30 if strictMode is enabled).
    • Has a SHA-256 hash (appended with '?') that starts with 0x00.
Source:
Example
const isValid = converter.check('S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy');
console.log(`Is valid: ${isValid}`);
Parameters:
Name Type Attributes Default Description
miniKey string

The MiniKey to validate.

strictMode boolean <optional>
false

Enforce strict validation, allowing only 30-character MiniKeys.

Returns:

True if the MiniKey is valid, false otherwise.

Type
boolean

generateMiniKey() → {string}

Description:
  • Generates a valid 30-character MiniKey.

    The MiniKey will always start with 'S' and will contain 29 additional Base58 characters. It ensures the generated MiniKey passes validation checks before returning it.

Source:
Example
const newMiniKey = converter.generateMiniKey();
console.log(`Generated MiniKey: ${newMiniKey}`);
Returns:

A valid 30-character MiniKey.

Type
string

hexToWif(key, testnetopt, compressedopt) → {string}

Description:
  • Converts a private key in HEX format to Wallet Import Format (WIF).

    Note: The input key must be in HEX format, typically obtained by converting a MiniKey using the miniToHex method.

Source:
Example
const wifKey = converter.hexToWif(hexKey, false, false);
console.log(`WIF Key: ${wifKey}`);
Parameters:
Name Type Attributes Default Description
key string

The private key in HEX format (64 characters).

testnet boolean <optional>
false

Whether the key is for the Bitcoin testnet.

compressed boolean <optional>
false

Whether the key is compressed.

Returns:

The private key in Wallet Import Format (WIF).

Type
string

miniToHex(key) → {string}

Description:
  • Converts a MiniKey into its corresponding private key in HEX format.

Source:
Example
const hexKey = converter.miniToHex('S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy');
console.log(`HEX Key: ${hexKey}`);
Parameters:
Name Type Description
key string

The MiniKey to convert.

Returns:

The private key in HEX format.

Type
string

verifyWifAgainstMiniKey(miniKey, wifKey, testnetopt, compressedopt) → {boolean}

Description:
  • Verifies whether a WIF key matches a MiniKey.

Source:
Parameters:
Name Type Attributes Default Description
miniKey string

The Mini private key.

wifKey string

The WIF key to verify.

testnet boolean <optional>
false

Whether the WIF key is for testnet.

compressed boolean <optional>
false

Whether the WIF key is compressed.

Returns:
  • True if the WIF key matches the MiniKey, otherwise false.
Type
boolean