| 1 | package Bitcoin::Crypto::BIP44; | ||||||||||||||||||||||||||||
| 2 | 13 | $Bitcoin::Crypto::BIP44::VERSION = '4.005'; | |||||||||||||||||||||||||||
| 3 | 13 | ▶ | use v5.14; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Mooish::Base -standard; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use Bitcoin::Crypto::DerivationPath; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Bitcoin::Crypto::Network; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub _get_network_constant | ||||||||||||||||||||||||||||
| 16 | 52 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_get_network_constant: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 17 | 52 | my ($network) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 52 | my $coin_type = $network->bip44_coin; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 52 | ▶ | Bitcoin::Crypto::Exception::NetworkConfig->raise( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 'no bip44_coin constant found in network configuration' | ||||||||||||||||||||||||||||
| 23 | ) unless defined $coin_type; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 52 | return $coin_type; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 13 | has param 'purpose' => ( | |||||||||||||||||||||||||||
| 29 | isa => BIP44Purpose, | ||||||||||||||||||||||||||||
| 30 | default => 44, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | has param 'coin_type' => ( | ||||||||||||||||||||||||||||
| 34 | isa => PositiveOrZeroInt, | ||||||||||||||||||||||||||||
| 35 | 54 | ▶ | coerce => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 36 | 54 | my ($coin_type) = @_; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 54 | ▶ | if (blessed $coin_type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 48 | ▶ | $coin_type = $coin_type->network | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | if $coin_type->DOES('Bitcoin::Crypto::Role::Network'); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 48 | ▶ | $coin_type = _get_network_constant($coin_type) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | if $coin_type->isa('Bitcoin::Crypto::Network'); | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 54 | return $coin_type; | |||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | 4 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 4 | _get_network_constant(Bitcoin::Crypto::Network->get); | |||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||
| 51 | 13 | ); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 13 | has param 'account' => ( | |||||||||||||||||||||||||||
| 54 | isa => PositiveOrZeroInt, | ||||||||||||||||||||||||||||
| 55 | default => 0, | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 13 | has param 'change' => ( | |||||||||||||||||||||||||||
| 59 | isa => Bool, | ||||||||||||||||||||||||||||
| 60 | default => 0, | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 13 | has param 'index' => ( | |||||||||||||||||||||||||||
| 64 | isa => PositiveOrZeroInt, | ||||||||||||||||||||||||||||
| 65 | default => 0, | ||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 13 | has param 'get_account' => ( | |||||||||||||||||||||||||||
| 69 | isa => Bool, | ||||||||||||||||||||||||||||
| 70 | default => !!0, | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 13 | has param 'get_from_account' => ( | |||||||||||||||||||||||||||
| 74 | isa => Bool, | ||||||||||||||||||||||||||||
| 75 | default => !!0, | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 13 | has param 'public' => ( | |||||||||||||||||||||||||||
| 79 | isa => Bool, | ||||||||||||||||||||||||||||
| 80 | default => !!0, | ||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 13 | with qw(Bitcoin::Crypto::Role::WithDerivationPath); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | use overload | ||||||||||||||||||||||||||||
| 86 | 6 | ▶ | q{""} => sub { shift->as_string }, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 13 | fallback => 1; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub as_string | ||||||||||||||||||||||||||||
| 90 | 54 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 54 | my ($self) = @_; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki | ||||||||||||||||||||||||||||
| 94 | # m / purpose' / coin_type' / account' / change / address_index | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 54 | ▶ | my $path = $self->public ? 'M' : 'm'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 54 | ▶ | $path = sprintf "%s/%u'/%u'/%u'", | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->public or $self->get_from_account
MC/DC100%2/2
$self->public or $self->get_from_account
$self->public
$self->get_from_account
Truth table100%3/3
A or B
A= $self->publicB= $self->get_from_account
| |||||||||||||||||||||||||||||
| 99 | $path, $self->purpose, $self->coin_type, $self->account | ||||||||||||||||||||||||||||
| 100 | if !$self->public && !$self->get_from_account; | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 54 | ▶ | return $path | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | if $self->get_account; | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 39 | ▶ | return sprintf "%s/%u/%u", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | $path, ($self->change ? 1 : 0), $self->index; | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | sub get_derivation_path | ||||||||||||||||||||||||||||
| 110 | 48 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_derivation_path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 48 | my ($self) = @_; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 48 | return Bitcoin::Crypto::DerivationPath->from_string($self->as_string); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 13 | 1; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||