| 1 | package Bitcoin::Crypto::Util; | ||||||||||
| 2 | 33 | $Bitcoin::Crypto::Util::VERSION = '4.005'; | |||||||||
| 3 | 34 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 34 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 34 | ▶ | use Exporter qw(import); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 34 | ▶ | use Types::Common -sigs, -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 34 | ▶ | use Bitcoin::Crypto::Helpers qw(parse_formatdesc ecc); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 34 | ▶ | use Bitcoin::Crypto::Constants qw(:key :witness); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 34 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 34 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 34 | ▶ | use Bitcoin::Crypto::Util::Internal qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | validate_segwit | ||||||||||
| 15 | get_address_type | ||||||||||
| 16 | get_key_type | ||||||||||
| 17 | get_public_key_compressed | ||||||||||
| 18 | generate_mnemonic | ||||||||||
| 19 | get_path_info | ||||||||||
| 20 | from_format | ||||||||||
| 21 | to_format | ||||||||||
| 22 | pack_compactsize | ||||||||||
| 23 | unpack_compactsize | ||||||||||
| 24 | hash160 | ||||||||||
| 25 | hash256 | ||||||||||
| 26 | merkle_root | ||||||||||
| 27 | tagged_hash | ||||||||||
| 28 | lift_x | ||||||||||
| 29 | has_even_y | ||||||||||
| 30 | get_taproot_ext | ||||||||||
| 31 | 34 | ); | |||||||||
| 32 | |||||||||||
| 33 | 33 | our @EXPORT_OK = qw( | |||||||||
| 34 | validate_wif | ||||||||||
| 35 | validate_segwit | ||||||||||
| 36 | get_address_type | ||||||||||
| 37 | get_key_type | ||||||||||
| 38 | get_public_key_compressed | ||||||||||
| 39 | generate_mnemonic | ||||||||||
| 40 | mnemonic_from_entropy | ||||||||||
| 41 | mnemonic_to_seed | ||||||||||
| 42 | get_path_info | ||||||||||
| 43 | from_format | ||||||||||
| 44 | to_format | ||||||||||
| 45 | pack_compactsize | ||||||||||
| 46 | unpack_compactsize | ||||||||||
| 47 | hash160 | ||||||||||
| 48 | hash256 | ||||||||||
| 49 | merkle_root | ||||||||||
| 50 | tagged_hash | ||||||||||
| 51 | lift_x | ||||||||||
| 52 | has_even_y | ||||||||||
| 53 | get_taproot_ext | ||||||||||
| 54 | ); | ||||||||||
| 55 | |||||||||||
| 56 | 33 | our %EXPORT_TAGS = (all => [@EXPORT_OK]); | |||||||||
| 57 | |||||||||||
| 58 | 33 | signature_for validate_wif => ( | |||||||||
| 59 | positional => [BitcoinSecret], | ||||||||||
| 60 | ); | ||||||||||
| 61 | |||||||||||
| 62 | sub validate_wif | ||||||||||
| 63 | 4 | ▶ | { | ||||||||
|
Subroutine
validate_wif: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 4 | my ($secret) = @_; | |||||||||
| 65 | 4 | state $inner_sig = signature(positional => [ByteStr]); | |||||||||
| 66 | |||||||||||
| 67 | return $secret->unmask_to( | ||||||||||
| 68 | 4 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 69 | 4 | return Bitcoin::Crypto::Util::Internal::validate_wif($inner_sig->(@_)); | |||||||||
| 70 | } | ||||||||||
| 71 | 4 | ); | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 33 | signature_for validate_segwit => ( | |||||||||
| 75 | positional => [ByteStr], | ||||||||||
| 76 | ); | ||||||||||
| 77 | |||||||||||
| 78 | 33 | signature_for get_address_type => ( | |||||||||
| 79 | positional => [Str, Maybe [Str], {default => undef}], | ||||||||||
| 80 | ); | ||||||||||
| 81 | |||||||||||
| 82 | 33 | signature_for get_key_type => ( | |||||||||
| 83 | positional => [ByteStr], | ||||||||||
| 84 | ); | ||||||||||
| 85 | |||||||||||
| 86 | 33 | signature_for get_public_key_compressed => ( | |||||||||
| 87 | positional => [ByteStr], | ||||||||||
| 88 | ); | ||||||||||
| 89 | |||||||||||
| 90 | 33 | signature_for mnemonic_to_seed => ( | |||||||||
| 91 | positional => [BitcoinSecret, Maybe [BitcoinSecret], {default => undef}], | ||||||||||
| 92 | ); | ||||||||||
| 93 | |||||||||||
| 94 | sub mnemonic_to_seed | ||||||||||
| 95 | 2 | ▶ | { | ||||||||
|
Subroutine
mnemonic_to_seed: called CC=2 SCAR=7.0
| |||||||||||
| 96 | 2 | my ($secret_mnemonic, $secret_password) = @_; | |||||||||
| 97 | |||||||||||
| 98 | 2 | ▶ | my $mnemonic = $secret_mnemonic->unmask_to(sub { shift }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 99 | my $password = $secret_password | ||||||||||
| 100 | 2 | ▶ | ? $secret_password->unmask_to(sub { shift }) | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 101 | 2 | ▶ | : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | |||||||||||
| 103 | 2 | return Bitcoin::Crypto::Util::Internal::mnemonic_to_seed($mnemonic, $password); | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 33 | signature_for generate_mnemonic => ( | |||||||||
| 107 | positional => [PositiveInt, {default => 128}, Str, {default => 'en'}], | ||||||||||
| 108 | ); | ||||||||||
| 109 | |||||||||||
| 110 | 33 | signature_for mnemonic_from_entropy => ( | |||||||||
| 111 | positional => [BitcoinSecret, Str, {default => 'en'}], | ||||||||||
| 112 | ); | ||||||||||
| 113 | |||||||||||
| 114 | sub mnemonic_from_entropy | ||||||||||
| 115 | 8 | ▶ | { | ||||||||
|
Subroutine
mnemonic_from_entropy: called CC=1 SCAR=0.0
| |||||||||||
| 116 | 8 | my ($secret_entropy, $language) = @_; | |||||||||
| 117 | 8 | state $inner_sig = signature(positional => [ByteStr]); | |||||||||
| 118 | |||||||||||
| 119 | return $secret_entropy->unmask_to( | ||||||||||
| 120 | 8 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 121 | 8 | return Bitcoin::Crypto::Util::Internal::mnemonic_from_entropy( | |||||||||
| 122 | $inner_sig->(@_), $language | ||||||||||
| 123 | ); | ||||||||||
| 124 | } | ||||||||||
| 125 | 8 | ); | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 33 | signature_for get_path_info => ( | |||||||||
| 129 | positional => [Defined], | ||||||||||
| 130 | ); | ||||||||||
| 131 | |||||||||||
| 132 | 33 | signature_for pack_compactsize => ( | |||||||||
| 133 | positional => [PositiveOrZeroInt], | ||||||||||
| 134 | ); | ||||||||||
| 135 | |||||||||||
| 136 | 33 | signature_for unpack_compactsize => ( | |||||||||
| 137 | positional => [ByteStr, Maybe [ScalarRef [PositiveOrZeroInt]], {default => undef}], | ||||||||||
| 138 | ); | ||||||||||
| 139 | |||||||||||
| 140 | 33 | signature_for hash160 => ( | |||||||||
| 141 | positional => [ByteStr], | ||||||||||
| 142 | ); | ||||||||||
| 143 | |||||||||||
| 144 | 33 | signature_for hash256 => ( | |||||||||
| 145 | positional => [ByteStr], | ||||||||||
| 146 | ); | ||||||||||
| 147 | |||||||||||
| 148 | 33 | signature_for merkle_root => ( | |||||||||
| 149 | positional => [ArrayRef [ByteStr]], | ||||||||||
| 150 | ); | ||||||||||
| 151 | |||||||||||
| 152 | 33 | signature_for tagged_hash => ( | |||||||||
| 153 | positional => [Str, ByteStr], | ||||||||||
| 154 | ); | ||||||||||
| 155 | |||||||||||
| 156 | 33 | signature_for lift_x => ( | |||||||||
| 157 | positional => [ByteStr], | ||||||||||
| 158 | ); | ||||||||||
| 159 | |||||||||||
| 160 | 33 | signature_for has_even_y => ( | |||||||||
| 161 | positional => [ByteStr | InstanceOf ['Bitcoin::Crypto::Key::Public']], | ||||||||||
| 162 | ); | ||||||||||
| 163 | |||||||||||
| 164 | 33 | 1; | |||||||||
| 165 | |||||||||||
| 166 | __END__ | ||||||||||