The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Bitcoin::Crypto::BIP44 - BIP44 implementation in Perl

SYNOPSIS

        use Bitcoin::Crypto::BIP44;

        my $path = Bitcoin::Crypto::BIP44->new(
                coin_type => Bitcoin::Crypto::Network->get('bitcoin_testnet'), # can also be a number or a key instance
                index => 43,
                # account => 0,
                # change => 0,
        );

        # stringifies automatically
        say "$path";

        # can be used in key derivation
        $ext_private_key->derive_key($path);

DESCRIPTION

This class is a helper for constructing BIP44-compilant key derivation paths. BIP44 describes the mechanism the HD (Hierarchical Deterministic) wallets use to decide derivation paths for coins.

Each coin has its own coin_type constant, a list of which is maintained here: https://github.com/satoshilabs/slips/blob/master/slip-0044.md. Bitcoin::Crypto::Network instances hold these constants under the bip44_coin property.

BIP44 objects stringify automatically and can be directly used in "derive_key" in Bitcoin::Crypto::Key::ExtPrivate method. In return, any key object can be used as coin_type in "new", which will automatically fetch coin_type number from the key's current network.

PROPERTIES

Refer to https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki for details of those properties.

All of these properties can be fetched using a method with the same name.

coin_type

Needs to be a non-negative integer number. It should be less than 2^31 (but will not check for that).

Will also accept key objects and network objects, as it is possible to fetch the constant for them. In this case, it might raise an exception if the network does not contain the bip44_coin constant.

This value should be in line with the table of BIP44 constants mentioned above.

By default, the value defined in the current default network will be used: see Bitcoin::Crypto::Network.

account

Needs to be a non-negative integer number. It should be less than 2^31 (but will not check for that).

By default, the value 0 is used.

change

Needs to be a number 1 (for addresses to be used as change outputs) or 0 (for addresses that are to be used only internally). By default, the value 0 is used.

index

Required. Needs to be a non-negative integer number. It should be less than 2^31 (but will not check for that).

METHODS

new

        $key_object = $class->new(%data)

This is a regular Moo constructor, which can be used to create the object. It takes arguments specified in "PROPERTIES".

Returns class instance.

as_string

        $path = $object->as_string()

Stringifies the object as BIP44-compilant key derivation path. Can be used indirectly by just stringifying the object.

EXCEPTIONS

This module throws an instance of Bitcoin::Crypto::Exception if it encounters an error. It can produce the following error types from the Bitcoin::Crypto::Exception namespace:

  • NetworkConfig - incomplete or corrupted network configuration

SEE ALSO

Bitcoin::Crypto::Key::ExtPrivate
Bitcoin::Crypto::Network