| 1 | package Bitcoin::Crypto::Transaction::Signer::Legacy; | ||||||||||||
| 2 | 14 | $Bitcoin::Crypto::Transaction::Signer::Legacy::VERSION = '4.005'; | |||||||||||
| 3 | 14 | ▶ | use v5.14; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 14 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 14 | ▶ | use Mooish::Base -standard; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 14 | ▶ | use List::Util qw(any); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 14 | ▶ | use Bitcoin::Crypto qw(btc_script); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 14 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 14 | ▶ | use Bitcoin::Crypto::Constants; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 14 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 14 | extends 'Bitcoin::Crypto::Transaction::Signer'; | |||||||||||
| 15 | |||||||||||||
| 16 | sub _initialize | ||||||||||||
| 17 | 24 | ▶ | { | ||||||||||
|
Subroutine
_initialize: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 24 | my ($self) = @_; | |||||||||||
| 19 | |||||||||||||
| 20 | # do nothing | ||||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | sub _get_signature | ||||||||||||
| 24 | 27 | ▶ | { | ||||||||||
|
Subroutine
_get_signature: called CC=5 SCAR=16.2
| |||||||||||||
| 25 | 27 | my ($self, $privkey, $args) = @_; | |||||||||||
| 26 | 27 | my $runner = $self->_runner; | |||||||||||
| 27 | 27 | my $pubkey = $privkey->get_public_key; | |||||||||||
| 28 | |||||||||||||
| 29 | 27 | ▶ | if ($self->_multisigop) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | 11 | my $stack = $runner->stack; | |||||||||||
| 31 | 11 | ▶ | my $pubkey_count = $runner->to_int($stack->[-1] // "\x00"); | ||||||||||
|
Condition50%1/2
$stack->[-1] // "\0"
MC/DC0%0/1
$stack->[-1] // "\0"
$stack->[-1]
Truth table50%1/2
A
A= $stack->[-1]
| |||||||||||||
| 32 | 11 | my @pubkeys = @{$stack}[-1 - $pubkey_count .. -2]; | |||||||||||
| 33 | |||||||||||||
| 34 | 11 | my $pubkey_serialized = $pubkey->to_serialized; | |||||||||||
| 35 | Bitcoin::Crypto::Exception::Sign->raise( | ||||||||||||
| 36 | 'bad private key for public keys encountered in script multisigop at position ' . $runner->pos | ||||||||||||
| 37 | 11 | ▶ | ) unless any { $_ eq $pubkey_serialized } @pubkeys; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||
| 38 | } | ||||||||||||
| 39 | else { | ||||||||||||
| 40 | 16 | my $script_pubkey = $runner->stack->[-1]; | |||||||||||
| 41 | 16 | ▶ | Bitcoin::Crypto::Exception::Sign->raise( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 'bad private key for public key encountered in script sigop at position ' . $runner->pos | ||||||||||||
| 43 | ) unless $script_pubkey eq $pubkey->to_serialized; | ||||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | my $digest_obj = $runner->transaction->get_digest_object( | ||||||||||||
| 47 | sighash => $args->{sighash}, | ||||||||||||
| 48 | 27 | ); | |||||||||||
| 49 | |||||||||||||
| 50 | 27 | return $privkey->sign_message($digest_obj->get_digest) | |||||||||||
| 51 | . pack 'C', $digest_obj->sighash; | ||||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | sub _finalize | ||||||||||||
| 55 | 13 | ▶ | { | ||||||||||
|
Subroutine
_finalize: called CC=2 SCAR=6.9
| |||||||||||||
| 56 | 13 | my ($self) = @_; | |||||||||||
| 57 | |||||||||||||
| 58 | 13 | my $script = btc_script->new; | |||||||||||
| 59 | 13 | foreach my $element (reverse @{$self->_signature}) { | |||||||||||
| 60 | 29 | $script->push($element); | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 13 | $self->transaction->inputs->[$self->signing_index]->set_signature_script($script); | |||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 14 | 1; | |||||||||||
| 67 | |||||||||||||