| 1 | package Bitcoin::Crypto::Util::Internal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 67 | $Bitcoin::Crypto::Util::Internal::VERSION = '4.005'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 67 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 67 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 67 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 67 | ▶ | use Unicode::Normalize; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 67 | ▶ | use Crypt::KeyDerivation qw(pbkdf2); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 67 | ▶ | use Encode qw(encode); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 67 | ▶ | use Crypt::Digest::RIPEMD160 qw(ripemd160); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 67 | ▶ | use Crypt::Digest::SHA256 qw(sha256); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 67 | ▶ | use Bitcoin::BIP39 qw(gen_bip39_mnemonic entropy_to_bip39_mnemonic); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 67 | ▶ | use Feature::Compat::Try; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 67 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 67 | ▶ | use Types::Common -types, -sigs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 67 | ▶ | use Bitcoin::Crypto::Helpers qw(parse_formatdesc ecc); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 67 | ▶ | use Bitcoin::Crypto::Constants qw(:key :witness); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 67 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 67 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 67 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | validate_wif | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | validate_segwit | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | get_address_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | get_key_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | get_public_key_compressed | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | generate_mnemonic | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | mnemonic_from_entropy | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | mnemonic_to_seed | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | get_path_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | from_format | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | to_format | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | pack_compactsize | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | unpack_compactsize | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | hash160 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | hash256 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | merkle_root | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | tagged_hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | lift_x | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | has_even_y | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | get_taproot_ext | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 67 | our %EXPORT_TAGS = (all => [@EXPORT_OK]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | sub validate_wif | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 21 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_wif: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 21 | my ($wif) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 21 | require Bitcoin::Crypto::Base58; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 21 | my $byte_wif = Bitcoin::Crypto::Base58::decode_base58check($wif); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 20 | my $last_byte = substr $byte_wif, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 20 | ▶ | if (length $byte_wif == KEY_MAX_LENGTH + 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | return $last_byte eq WIF_COMPRESSED_BYTE; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | return length $byte_wif == KEY_MAX_LENGTH + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | sub validate_segwit | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 162 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_segwit: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 162 | my ($program) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 162 | my $version = unpack 'C', $program; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 162 | ▶ | Bitcoin::Crypto::Exception::SegwitProgram->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%4/8
defined $version and $version >= 0 and $version <= 16
defined $version and $version >= 0
$version // "[null]"
MC/DC33%1/3
defined $version and $version >= 0 and $version <= 16
defined $version
$version >= 0
$version <= 16
MC/DC0%0/1
$version // "[null]"
$version
Truth table50%2/4
A and B and C
A= defined $versionB= $version >= 0C= $version <= 16
Truth table50%1/2
A
A= $version
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 'incorrect witness program version ' . ($version // '[null]') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ) unless defined $version && $version >= 0 && $version <= MAX_WITNESS_VERSION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 160 | $program = substr $program, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # common validator | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 160 | ▶ | Bitcoin::Crypto::Exception::SegwitProgram->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $program >= 2 and length $program <= 40
MC/DC100%2/2
length $program >= 2 and length $program <= 40
length $program >= 2
length $program <= 40
Truth table100%3/3
A and B
A= length $program >= 2B= length $program <= 40
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 'incorrect witness program length' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ) unless length $program >= 2 && length $program <= 40; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 154 | ▶ | if ($version == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # SegWit validator | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 83 | ▶ | Bitcoin::Crypto::Exception::SegwitProgram->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $program == 20 or length $program == 32
MC/DC100%2/2
length $program == 20 or length $program == 32
length $program == 20
length $program == 32
Truth table100%3/3
A or B
A= length $program == 20B= length $program == 32
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 'incorrect witness program length (segwit)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ) unless length $program == 20 || length $program == 32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | elsif ($version == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Taproot validator | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # taproot outputs are 32 bytes, but other lengths "remain unencumbered" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # do not throw this exception to make bip350 test suite pass (10-Bech32.t) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Bitcoin::Crypto::Exception::SegwitProgram->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # 'incorrect witness program length (taproot)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # ) unless length $program == 32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 152 | return $version; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | sub get_address_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 21 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_address_type: called CC=19 SCAR=30.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 21 | my ($address, $network_id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 21 | require Bitcoin::Crypto::Base58; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 21 | require Bitcoin::Crypto::Bech32; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 21 | require Bitcoin::Crypto::Network; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 21 | ▶ | my $network = Bitcoin::Crypto::Network->get($network_id // ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$network_id // ()
MC/DC0%0/2
$network_id // ()
$network_id
()
Truth table66%2/3
A // B
A= $network_idB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 21 | my $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # first, try segwit | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 21 | ▶ | if ($network->supports_segwit) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 21 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 21 | ▶ | Bitcoin::Crypto::Exception::SegwitProgram->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 'invalid human readable part in address' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ) unless Bitcoin::Crypto::Bech32::get_hrp($address) eq $network->segwit_hrp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 14 | my $data = Bitcoin::Crypto::Bech32::decode_segwit($address); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 14 | my $version = ord substr $data, 0, 1, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 14 | ▶ | $type = 'P2TR' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$version == 1 and length $data == 32
MC/DC50%1/2
$version == 1 and length $data == 32
$version == 1
length $data == 32
Truth table66%2/3
A and B
A= $version == 1B= length $data == 32
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | if $version == TAPROOT_WITNESS_VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | && length $data == 32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 14 | ▶ | return $type if $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 9 | ▶ | Bitcoin::Crypto::Exception::SegwitProgram->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | "invalid segwit address of version $version" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ) unless $version == SEGWIT_WITNESS_VERSION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | ▶ | $type = 'P2WPKH' if length $data == 20; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 9 | ▶ | $type = 'P2WSH' if length $data == 32; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | ▶ | return $type if $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | Bitcoin::Crypto::Exception::Address->raise( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 'invalid segwit address' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | catch ($ex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | ▶ | die $ex unless blessed $ex && $ex->isa('Bitcoin::Crypto::Exception::Bech32InputFormat'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($ex) and $ex->isa("Bitcoin::Crypto::Exception::Bech32InputFormat")
MC/DC50%1/2
builtin::blessed($ex) and $ex->isa("Bitcoin::Crypto::Exception::Bech32InputFormat")
builtin::blessed($ex)
$ex->isa("Bitcoin::Crypto::Exception::Bech32InputFormat")
Truth table66%2/3
A and B
A= builtin::blessed($ex)B= $ex->isa("Bitcoin::Crypto::Exception::Bech32InputFormat")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # then, try legacy | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 6 | my $data = Bitcoin::Crypto::Base58::decode_base58check($address); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | my $byte = substr $data, 0, 1, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | ▶ | $type = 'P2PKH' if $byte eq $network->p2pkh_byte; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | ▶ | $type = 'P2SH' if $byte eq $network->p2sh_byte; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | ▶ | Bitcoin::Crypto::Exception::Address->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 'invalid legacy address' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ) unless length $data == 20; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | ▶ | return $type if $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | Bitcoin::Crypto::Exception::Address->raise( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 'invalid first byte in address' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | catch ($ex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | ▶ | die $ex unless blessed $ex && $ex->isa('Bitcoin::Crypto::Exception::Base58InputFormat'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($ex) and $ex->isa("Bitcoin::Crypto::Exception::Base58InputFormat")
MC/DC0%0/2
builtin::blessed($ex) and $ex->isa("Bitcoin::Crypto::Exception::Base58InputFormat")
builtin::blessed($ex)
$ex->isa("Bitcoin::Crypto::Exception::Base58InputFormat")
Truth table33%1/3
A and B
A= builtin::blessed($ex)B= $ex->isa("Bitcoin::Crypto::Exception::Base58InputFormat")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | Bitcoin::Crypto::Exception::Address->raise( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | "not an address: $address" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | sub get_key_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1328 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_key_type: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1328 | my $entropy = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1328 | ▶ | return 0 if defined get_public_key_compressed($entropy); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 510 | ▶ | return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | if length $entropy <= KEY_MAX_LENGTH; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub get_public_key_compressed | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1785 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_public_key_compressed: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1785 | my $entropy = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1785 | my $octet = unpack 'C', $entropy; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1785 | ▶ | return undef unless defined $octet; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1784 | ▶ | if ($octet == 0x02 || $octet == 0x03) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$octet == 2 or $octet == 3
MC/DC100%2/2
$octet == 2 or $octet == 3
$octet == 2
$octet == 3
Truth table100%3/3
A or B
A= $octet == 2B= $octet == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1243 | ▶ | return 1 if length $entropy == KEY_MAX_LENGTH + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ▶ | elsif ($octet == 0x04 || $octet == 0x06 || $octet == 0x07) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$octet == 4 or $octet == 6 or $octet == 7
$octet == 4 or $octet == 6
MC/DC100%3/3
$octet == 4 or $octet == 6 or $octet == 7
$octet == 4
$octet == 6
$octet == 7
Truth table100%4/4
A or B or C
A= $octet == 4B= $octet == 6C= $octet == 7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 47 | ▶ | return 0 if length $entropy == 2 * KEY_MAX_LENGTH + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 509 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | sub mnemonic_to_seed | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 37 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mnemonic_to_seed: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 37 | my ($mnemonic, $password) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 37 | $mnemonic = encode('UTF-8', NFKD($mnemonic)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 37 | ▶ | $password = encode('UTF-8', NFKD('mnemonic' . ($password // ''))); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$password // ""
MC/DC100%1/1
$password // ""
$password
Truth table100%2/2
A
A= $password
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 37 | return pbkdf2($mnemonic, $password, 2048, 'SHA512', 64); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | sub generate_mnemonic | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_mnemonic: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 8 | my ($len, $lang) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | my ($min_len, $len_div, $max_len) = (128, 32, 256); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # bip39 specification values | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 8 | ▶ | Bitcoin::Crypto::Exception::MnemonicGenerate->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$len < $min_len or $len > $max_len or $len % $len_div != 0
$len < $min_len or $len > $max_len
MC/DC33%1/3
$len < $min_len or $len > $max_len or $len % $len_div != 0
$len < $min_len
$len > $max_len
$len % $len_div != 0
Truth table50%2/4
A or B or C
A= $len < $min_lenB= $len > $max_lenC= $len % $len_div != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | "required entropy of between $min_len and $max_len bits, divisible by $len_div" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ) if $len < $min_len || $len > $max_len || $len % $len_div != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | return Bitcoin::Crypto::Exception::MnemonicGenerate->trap_into( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | my $ret = gen_bip39_mnemonic(bits => $len, language => $lang); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 7 | $ret->{mnemonic}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | sub mnemonic_from_entropy | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mnemonic_from_entropy: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 12 | my ($entropy, $lang) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | return Bitcoin::Crypto::Exception::MnemonicGenerate->trap_into( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 12 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 12 | entropy_to_bip39_mnemonic( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | entropy => $entropy, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | language => $lang | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 12 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | sub get_path_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_path_info: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 9 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # NOTE: ->coerce may still throw because of exceptions in from_string of DerivationPath | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 9 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 9 | return scalar DerivationPath->assert_coerce($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | catch ($e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | sub from_format ($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 6 | state $sig = signature(positional => [Tuple [FormatStr, Str]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | my ($format, $data) = @{($sig->(@_))[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 6 | return parse_formatdesc($format, $data); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | sub to_format ($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1094 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1094 | state $sig = signature(positional => [Tuple [FormatStr, ByteStr]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1094 | my ($format, $data) = @{($sig->(@_))[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1094 | return parse_formatdesc($format, $data, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | sub pack_compactsize | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 6232 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack_compactsize: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 6232 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 6232 | ▶ | if ($value <= 0xfc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 6218 | return pack 'C', $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | elsif ($value <= 0xffff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 12 | return pack 'Cv', 0xfd, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | elsif ($value <= 0xffffffff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | return pack 'CV', 0xfe, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # 32 bit archs should not reach this | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | return pack 'CVV', 0xff, $value & 0xffffffff, $value >> 32; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | sub unpack_compactsize | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 5058 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpack_compactsize: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 5058 | my ($stream, $pos_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 5058 | my $partial = !!$pos_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 5058 | ▶ | my $pos = $partial ? $$pos_ref : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # if the first byte is 0xfd, 0xfe or 0xff, then CompactSize contains 2, 4 or 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # bytes respectively | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 5058 | my $value = ord substr $stream, $pos++, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 5058 | ▶ | if ($value > 0xfc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 14 | my $length = 1 << ($value - 0xfc); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 14 | ▶ | Bitcoin::Crypto::Exception->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | "cannot unpack CompactSize: not enough data in stream" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | ) if length $stream < $length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 14 | ▶ | if ($length == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 10 | $value = unpack "\@$pos v", $stream; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | elsif ($length == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 3 | $value = unpack "\@$pos V", $stream; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | Bitcoin::Crypto::Exception->raise( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | "cannot unpack CompactSize: no 64 bit support" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | ) if !Bitcoin::Crypto::Constants::is_64bit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | my ($lower, $higher) = unpack "\@$pos VV", $stream; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | $value = ($higher << 32) + $lower; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 14 | $pos += $length; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | Bitcoin::Crypto::Exception->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 5058 | ▶ | "cannot unpack CompactSize: leftover data in stream" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $partial and $pos != length $stream
MC/DC100%2/2
not $partial and $pos != length $stream
not $partial
$pos != length $stream
Truth table100%3/3
not(A) and B
A= not $partialB= $pos != length $stream
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | ) if !$partial && $pos != length $stream; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 5057 | ▶ | $$pos_ref = $pos | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | if $partial; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 5057 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | sub hash160 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 544 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash160: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 544 | return ripemd160(sha256(shift)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | sub hash256 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 894 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash256: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 894 | return sha256(sha256(shift)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | sub merkle_root | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merkle_root: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 9 | my ($leaves) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 9 | my @parts = map { hash256($_) } @$leaves; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 9 | ▶ | Bitcoin::Crypto::Exception->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 'need at least one element to calculate a merkle root' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | ) unless @parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 9 | ▶ | while (@parts > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | @parts = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 59 | ▶ | hash256($parts[$_] . ($parts[$_ + 1] // $parts[$_])) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$parts[$_ + 1] // $parts[$_]
MC/DC0%0/2
$parts[$_ + 1] // $parts[$_]
$parts[$_ + 1]
$parts[$_]
Truth table66%2/3
A // B
A= $parts[$_ + 1]B= $parts[$_]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 19 | $_ % 2 == 0 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } 0 .. $#parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 9 | return $parts[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | sub tagged_hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 237 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tagged_hash: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 237 | my ($tag, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 237 | state $tags = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 237 | ▶ | $tags->{$tag} //= sha256(encode 'UTF-8', $tag) x 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$tags->{$tag} //= sha256(&encode("UTF-8", $tag)) x 2
MC/DC100%1/1
$tags->{$tag} //= sha256(&encode("UTF-8", $tag)) x 2
$tags->{$tag}
Truth table100%2/2
A
A= $tags->{$tag}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 237 | return sha256($tags->{$tag} . $message); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | sub lift_x | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 221 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lift_x: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 221 | my ($x) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 221 | ▶ | my $key = "\x02" . ($x // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$x // ""
MC/DC0%0/1
$x // ""
$x
Truth table50%1/2
A
A= $x
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 221 | ▶ | Bitcoin::Crypto::Exception::KeyCreate->raise( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 'invalid xonly public key' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | ) unless ecc->verify_public_key($key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 216 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | sub has_even_y | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 52 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_even_y: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 52 | my ($key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 52 | ▶ | $key = $key->raw_key if ref $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | return Bitcoin::Crypto::Exception->trap_into( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 52 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 52 | $key = ecc->compress_public_key($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 51 | return substr($key, 0, 1) eq "\x02"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | sub get_taproot_ext | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 20 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_taproot_ext: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 20 | my ($ext_flag, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 20 | ▶ | if ($ext_flag == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | elsif ($ext_flag == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 19 | state $type = Dict [ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | script_tree => BitcoinScriptTree, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | leaf_id => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | codesep_pos => Optional [Maybe [PositiveOrZeroInt]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 19 | $type->assert_valid(\%args); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki#common-signature-message-extension | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | return $args{script_tree}->get_tapleaf_hash($args{leaf_id}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 19 | ▶ | . pack('xV', $args{codesep_pos} // 0xffffffff); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"codesep_pos"} // 4294967295
MC/DC100%1/1
$args{"codesep_pos"} // 4294967295
$args{"codesep_pos"}
Truth table100%2/2
A
A= $args{"codesep_pos"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | Bitcoin::Crypto::Exception->raise( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | "can not create taproot_ext for unknown ext flag $ext_flag" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 67 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||