Crypto/Key/Base.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 100% 6 / 6 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 2 totaltotal 94.5% 70 / 74 CC 6 SCAR 10.4
CC
6
Cov
98%
get_taproot_output_key
6.0
_is_private
2.0
BEGIN
1.0
CRAP 2.8
« Crypto/Transaction/Output.pm ↑ Summary Crypto/BIP44.pm »
1 package Bitcoin::Crypto::Key::Base;
2 30 $Bitcoin::Crypto::Key::Base::VERSION = '4.006';
3 43 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 43 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 43 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 43 ▶use Types::Common -sigs;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 43 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 43 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 43 ▶use Bitcoin::Crypto::Util::Internal qw(to_format tagged_hash lift_x has_even_y);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 43 ▶use Bitcoin::Crypto::Helpers qw(ecc);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 30 has param 'taproot_output' => (
15 isa => Bool,
16 writer => 1,
17 default => !!0,
18 );
19  
20 30 with qw(
21 Bitcoin::Crypto::Role::Key
22 Bitcoin::Crypto::Role::Compressed
23 Bitcoin::Crypto::Role::SignVerify
24 );
25  
26 sub _is_private
27 0 ▶{
Subroutine _is_private: not called CC=1 SCAR=6.9
28 0 die __PACKAGE__ . '::_is_private is unimplemented';
29 }
30  
31 sub from_serialized
32 612 ▶{
Subroutine from_serialized: called CC=1 SCAR=0.0
Pod undocumented
33 612 my ($class, $data) = @_;
34  
35 612 return $class->new(_key_instance => $data);
36 }
37  
38 sub to_serialized
39 375 ▶{
Subroutine to_serialized: called CC=1 SCAR=0.0
Pod undocumented
40 375 my ($self) = @_;
41  
42 375 return $self->raw_key;
43 }
44  
45 30 signature_for get_taproot_output_key => (
46 method => !!1,
47 positional => [Maybe [ByteStr], {default => undef}],
48 );
49  
50 sub get_taproot_output_key
51 143 ▶{
Subroutine get_taproot_output_key: called CC=6 SCAR=17.9
52 143 my ($self, $tweak_suffix) = @_;
53  
54 143 ▶ return $self if $self->taproot_output;
Branch: 1 branch
BranchTrueFalseTotal
if $self->taproot_output 10 133 143
55  
56 133 my $new_key;
57 133 ▶ if ($self->_is_private) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_private) { } 39 94 133
58 39 my $internal = $self->raw_key('private');
59 39 my $internal_public = ecc->create_public_key($internal);
60  
61 # NOTE: always negate the key to make it constant-time
62 39 my $internal_negated = ecc->negate_private_key($internal);
63 39 ▶ $internal = $internal_negated
Branch: 1 branch
BranchTrueFalseTotal
unless has_even_y($internal_public) 24 15 39
64 unless has_even_y($internal_public);
65  
66 39 ▶ my $tweak = tagged_hash('TapTweak', ecc->xonly_public_key($internal_public) . ($tweak_suffix // ''));
Condition100%2/2
$tweak_suffix // ""
l!l
831
MC/DC100%1/1
$tweak_suffix // ""
$tweak_suffix
Truth table100%2/2
A
A= $tweak_suffix
Aresult
11
00
67 39 $new_key = ecc->add_private_key($internal, $tweak);
68 }
69 else {
70 94 my $internal = $self->raw_key('public_xonly');
71 94 ▶ my $tweak = tagged_hash('TapTweak', $internal . ($tweak_suffix // ''));
Condition100%2/2
$tweak_suffix // ""
l!l
6331
MC/DC100%1/1
$tweak_suffix // ""
$tweak_suffix
Truth table100%2/2
A
A= $tweak_suffix
Aresult
11
00
72 94 $new_key = ecc->combine_public_keys(ecc->create_public_key($tweak), lift_x $internal);
73 }
74  
75 133 my $pkg = ref $self;
76 133 return $pkg->new(
77 _key_instance => $new_key,
78 purpose => $self->purpose,
79 network => $self->network,
80 taproot_output => !!1,
81 );
82 }
83  
84 30 1;
85  
86 # Internal use only
87  
« Crypto/Transaction/Output.pm ↑ Summary Crypto/BIP44.pm »