Crypto/BIP44.pm

filter: Statementstmt 100% 55 / 55 Branchbran 87.5% 14 / 16 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 15 / 15 Podpod 100% 2 / 2 totaltotal 97.8% 91 / 93 CC 10 SCAR 10.4
CC
10
Cov
97%
as_string
6.0
__ANON__
4.0
_get_network_constant
2.0
CRAP 2.8
« Crypto/Key/Base.pm ↑ Summary Crypto/Key/Public.pm »
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
BranchTrueFalseTotal
unless defined $coin_type 0 52 52
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
BranchTrueFalseTotal
if (builtin::blessed($coin_type)) 48 6 54
39 48 ▶ $coin_type = $coin_type->network
Branch: 1 branch
BranchTrueFalseTotal
if $coin_type->DOES("Bitcoin::Crypto::Role::Network") 47 1 48
40 if $coin_type->DOES('Bitcoin::Crypto::Role::Network');
41  
42 48 ▶ $coin_type = _get_network_constant($coin_type)
Branch: 1 branch
BranchTrueFalseTotal
if $coin_type->isa("Bitcoin::Crypto::Network") 48 0 48
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
BranchTrueFalseTotal
$self->public ? : 6 48 54
97  
98 54 ▶ $path = sprintf "%s/%u'/%u'/%u'",
Branch: 1 branch
BranchTrueFalseTotal
unless $self->public or $self->get_from_account 34 20 54
Condition100%3/3
$self->public or $self->get_from_account
l!l&&r!l&&!r
61434
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $self->get_account 15 39 54
103 if $self->get_account;
104  
105 39 ▶ return sprintf "%s/%u/%u",
Branch: 1 branch
BranchTrueFalseTotal
$self->change ? : 8 31 39
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__
« Crypto/Key/Base.pm ↑ Summary Crypto/Key/Public.pm »