Bitcoin-Crypto
view release on metacpan or search on metacpan
lib/Bitcoin/Crypto/BIP85.pm view on Meta::CPAN
my $spec_path = "m/83696968'/2'/$args->{index}'";
my $entropy = $self->derive_entropy($spec_path, 32);
return btc_prv->from_serialized($entropy);
}
signature_for derive_extprv => (
method => !!1,
named => [
index => PositiveOrZeroInt,
{default => 0},
],
bless => !!0,
);
sub derive_extprv
{
my ($self, $args) = @_;
my $spec_path = "m/83696968'/32'/$args->{index}'";
my $entropy = $self->derive_entropy($spec_path);
return btc_extprv->new(
_key_instance => substr($entropy, 32, 32),
chain_code => substr($entropy, 0, 32),
);
}
signature_for derive_bytes => (
method => !!1,
named => [
bytes => Int->where(q{$_ >= 16 && $_ <= 64}),
{default => 64},
index => PositiveOrZeroInt,
{default => 0},
],
bless => !!0,
);
sub derive_bytes
{
my ($self, $args) = @_;
my $spec_path = "m/83696968'/128169'/$args->{bytes}'/$args->{index}'";
return $self->derive_entropy($spec_path, $args->{bytes});
}
1;
__END__
=head1 NAME
Bitcoin::Crypto::BIP85 - BIP85 (deterministic entropy) implementation
=head1 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);
=head1 DESCRIPTION
This module implements
L<BIP85|https://github.com/bitcoin/bips/blob/master/bip-0085.mediawiki>,
enabling deterministic entropy generation from a master key.
It currently implements the following applications from the BIP85 spec:
=over
=item * C<BIP39>: L</derive_mnemonic>
This application requires extra CPAN wordlists for L<Bitcoin::BIP39> to handle
other languages than C<en>.
=item * C<HD-Seed WIF>: L</derive_prv>
This application returns a private key instead of a WIF, but can be serialized
using L<Bitcoin::Crypto::Key::Private/to_wif>.
=item * C<XPRV>: L</derive_extprv>
This application returns an extended private key instead of its serialized
version, but can be serialized using
L<Bitcoin::Crypto::Key::ExtPrivate/to_serialized>.
=item * C<HEX>: L</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 L<Bitcoin::Crypto::Util/to_format>.
=back
Missing BIP85 applications can be implemented using L</derive_entropy> with
proper derivation path and entropy length.
=head1 INTERFACE
=head2 Attributes
=head3 key
B<Required in the constructor.> The master key from which the generation will
be performed, an instance of L<Bitcoin::Crypto::Key::ExtPrivate>.
=head2 Methods
=head3 new
$bip_object = $class->new(%data)
( run in 1.260 second using v1.01-cache-2.11-cpan-5837b0d9d2c )