Crypto/Key/Base.pm

filter: Statementstmt 97.8% 46 / 47 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% 69 / 73 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 29 $Bitcoin::Crypto::Key::Base::VERSION = '4.005';
3 40 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 40 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 40 ▶use Types::Common -sigs;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 40 ▶use Bitcoin::Crypto::Util::Internal qw(to_format tagged_hash lift_x has_even_y);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 40 ▶use Bitcoin::Crypto::Helpers qw(ecc);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 29 has param 'taproot_output' => (
15 isa => Bool,
16 writer => 1,
17 default => !!0,
18 );
19  
20 29 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 527 ▶{
Subroutine from_serialized: called CC=1 SCAR=0.0
Pod undocumented
33 527 my ($class, $data) = @_;
34  
35 527 return $class->new(_key_instance => $data);
36 }
37  
38 sub to_serialized
39 268 ▶{
Subroutine to_serialized: called CC=1 SCAR=0.0
Pod undocumented
40 268 my ($self) = @_;
41  
42 268 return $self->raw_key;
43 }
44  
45 29 signature_for get_taproot_output_key => (
46 method => !!1,
47 positional => [Maybe [ByteStr], {default => undef}],
48 );
49  
50 sub get_taproot_output_key
51 89 ▶{
Subroutine get_taproot_output_key: called CC=6 SCAR=17.9
52 89 my ($self, $tweak_suffix) = @_;
53  
54 89 ▶ return $self if $self->taproot_output;
Branch: 1 branch
BranchTrueFalseTotal
if $self->taproot_output 4 85 89
55  
56 85 my $new_key;
57 85 ▶ if ($self->_is_private) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_private) { } 19 66 85
58 19 my $internal = $self->raw_key('private');
59 19 my $internal_public = ecc->create_public_key($internal);
60 19 ▶ $internal = ecc->negate_private_key($internal)
Branch: 1 branch
BranchTrueFalseTotal
unless has_even_y($internal_public) 9 10 19
61 unless has_even_y($internal_public);
62  
63 19 ▶ my $tweak = tagged_hash('TapTweak', ecc->xonly_public_key($internal_public) . ($tweak_suffix // ''));
Condition100%2/2
$tweak_suffix // ""
l!l
712
MC/DC100%1/1
$tweak_suffix // ""
$tweak_suffix
Truth table100%2/2
A
A= $tweak_suffix
Aresult
11
00
64 19 $new_key = ecc->add_private_key($internal, $tweak);
65 }
66 else {
67 66 my $internal = $self->raw_key('public_xonly');
68 66 ▶ my $tweak = tagged_hash('TapTweak', $internal . ($tweak_suffix // ''));
Condition100%2/2
$tweak_suffix // ""
l!l
4323
MC/DC100%1/1
$tweak_suffix // ""
$tweak_suffix
Truth table100%2/2
A
A= $tweak_suffix
Aresult
11
00
69 66 $new_key = ecc->combine_public_keys(ecc->create_public_key($tweak), lift_x $internal);
70 }
71  
72 85 my $pkg = ref $self;
73 85 return $pkg->new(
74 _key_instance => $new_key,
75 purpose => $self->purpose,
76 network => $self->network,
77 taproot_output => !!1,
78 );
79 }
80  
81 29 1;
82  
83 # Internal use only
84  
« Crypto/Transaction/Output.pm ↑ Summary Crypto/BIP44.pm »