NAME
Bitcoin::Crypto::BIP85 - BIP85 (deterministic entropy) implementation
SYNOPSIS
use Bitcoin::Crypto::BIP85;
my $bip85 = Bitcoin::Crypto::BIP85->new(
key => $extended_private_key,
);
# get raw bytestring seed
my $seed = $bip85->derive_entropy("m/0'/0'");
# get a mnemonic
my $mnemonic = $bip85->derive_mnemonic(index => 0);
DESCRIPTION
This module implements BIP85, enabling deterministic entropy generation from a master key.
It currently implements the following applications from the BIP85 spec:
BIP39
: "derive_mnemonic"This application requires extra CPAN wordlists for Bitcoin::BIP39 to handle other languages than
en
.HD-Seed WIF
: "derive_prv"This application returns a private key instead of a WIF, but can be serialized using "to_wif" in Bitcoin::Crypto::Key::Private.
XPRV
: "derive_extprv"This application returns an extended private key instead of its serialized version, but can be serialized using "Bitcoin::Crypto::Key::ExtPrivate/to_serialized".
HEX
: "derive_bytes"This application returns a bytestring instead of a hex string in order to be coherent with other similar Bitcoin::Crypto methods. It can be represented as hex using "to_format" in Bitcoin::Crypto::Util.
Missing BIP85 applications can be implemented using "derive_entropy" with proper derivation path and entropy length.
INTERFACE
Attributes
key
Required in the constructor. The master key from which the generation will be performed, an instance of Bitcoin::Crypto::Key::ExtPrivate.
Methods
new
$bip_object = $class->new(%data)
This is a standard Moo constructor, which can be used to create the object. It takes arguments specified in "Attributes".
derive_entropy
$bytestr = $object->derive_entropy($path, $length = undef)
Returns entropy derived from the master key using $path
, which can be a standard string derivation path like m/83696968'/0'/0'
or an instance of Bitcoin::Crypto::DerivationPath. The derivation path must be fully hardened, as specified in the BIP.
Optional $length
is the desired length of the entropy in bytes. If not provided, full 64
bytes of entropy will be returned. If provided and less than 64
, the entropy will be truncated to the derired length. If greater than 64
, the DRNG
algorithm defined in BIP85 will be used to stretch the entropy to this size.
derive_mnemonic
$mnemonic = $object->derive_mnemonic(%args)
Derives mnemonic from the master key. %args
can be any combination of:
words
The number of words to generate. Can be either
12
,18
or24
. Default:24
.language
The language to use. See Bitcoin::BIP39 for more info about this argument. Default:
en
.index
The generation index. Must be a non-negative integer. Default:
0
derive_prv
$prv = $object->derive_prv(%args)
Derives private key from the master key. The key can immediately be serialized using ->to_wif
to match BIP85 spec for this application. %args
can be any combination of:
index
The generation index. Must be a non-negative integer. Default:
0
derive_extprv
$extprv = $object->derive_extprv(%args)
Derives an extended private key from the master key. The key can immediately be serialized using ->to_serialized
to match BIP85 spec for this application. %args
can be any combination of:
index
The generation index. Must be a non-negative integer. Default:
0
derive_bytes
$bytestr = $object->derive_bytes(%args)
Derives a number of bytes from the master key. The key can immediately be serialized as hex using "to_format" in Bitcoin::Crypto::Util to match BIP85 spec for this application. %args
can be any combination of:
bytes
The number of bytes to generate. Must be between
16
and64
, inclusive.index
The generation index. Must be a non-negative integer. Default:
0