| 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
| |||||||||||||
| 55 | |||||||||||||
| 56 | 133 | my $new_key; | |||||||||||
| 57 | 133 | ▶ | if ($self->_is_private) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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 // ""
MC/DC100%1/1
$tweak_suffix // ""
$tweak_suffix
Truth table100%2/2
A
A= $tweak_suffix
| |||||||||||||
| 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 // ""
MC/DC100%1/1
$tweak_suffix // ""
$tweak_suffix
Truth table100%2/2
A
A= $tweak_suffix
| |||||||||||||
| 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 | |||||||||||||