NAME

Bitcoin::Crypto::Util - Basic utilities for working with bitcoin

SYNOPSIS

        use Bitcoin::Crypto::Util qw(
                validate_wif
                get_key_type
                get_path_info
        );

DESCRIPTION

These are basic utilities for working with bitcoin, used by other packages.

FUNCTIONS

validate_wif

        $bool = validate_wif($str);

Ensures Base58 encoded string looks like encoded private key in WIF format. Throws an exception if $str is not valid base58.

get_key_type

        $is_private = get_key_type($bytestr);

Checks if the $bytestr looks like a valid ASN X9.62 format (compressed / uncompressed / hybrid public key or private key entropy up to curve size bits). Returns boolean which can be used to determine if the key is private. Returns undef if $bytestr does not look like a valid key entropy.

mnemonic_to_seed

        $seed = mnemonic_to_seed($mnemonic, $password);

Transforms the given BIP39 $mnemonic and $password into a valid BIP32 $seed, which can be fed into "from_seed" in Bitcoin::Crypto::Key::ExtPrivate.

$seed is a 512 bit bytestring (64 characters). $mnemonic should be a BIP39 mnemonic, but will not be checked against a dictionary.

This function is only useful if you need a seed instead of mnemonic (for example, you use a wallet implementation which does not implement BIP39). If you only want to create a private key from mnemonic, you should consider using "from_mnemonic" in Bitcoin::Crypto::Key::ExtPrivate instead.

Important note about unicode: this function only accepts UTF8-decoded strings (both $mnemonic and $password), but can't detect whether it got it or not. This will only become a problem if you use non-ascii mnemonic and/or password. If there's a possibility of non-ascii, always use utf8 and set binmodes to get decoded (wide) characters to avoid problems recovering your wallet.

get_path_info

        $path_data = get_path_info($path);

Tries to get derivation path data from $path. Returns undef if $path is not a valid path. Otherwise returns the structure:

        {
                private => bool, # is path derivation private (lowercase m)
                path => [
                        # derivation path with 2^31 added to every hardened child number
                        int, int, ..
                ],
        }

Example:

        my $path = "m/1/3'";
        my $path_data = get_path_info($path);

SEE ALSO

Bitcoin::Crypto::Key::ExtPrivate