Crypto/Util.pm

filter: Statementstmt 100% 64 / 64 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 98.7% 81 / 82 CC 2 SCAR 1.1
CC
2
Cov
98%
mnemonic_to_seed
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Crypto/Transaction/Signer/CompatP2WPKH.pm ↑ Summary Crypto.pm »
1 package Bitcoin::Crypto::Util;
2 45 $Bitcoin::Crypto::Util::VERSION = '4.006';
3 46 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 46 ▶use Types::Common -sigs, -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 46 ▶use Bitcoin::Crypto::Helpers qw(parse_formatdesc ecc);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 46 ▶use Bitcoin::Crypto::Constants qw(:key :witness);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 46 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 46 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 46 ▶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 pack_array
25 unpack_array
26 hash160
27 hash256
28 merkle_root
29 tagged_hash
30 lift_x
31 has_even_y
32 get_taproot_ext
33 46 );
34  
35 45 our @EXPORT_OK = qw(
36 validate_wif
37 validate_segwit
38 get_address_type
39 get_key_type
40 get_public_key_compressed
41 generate_mnemonic
42 mnemonic_from_entropy
43 mnemonic_to_seed
44 get_path_info
45 from_format
46 to_format
47 pack_compactsize
48 unpack_compactsize
49 pack_array
50 unpack_array
51 hash160
52 hash256
53 merkle_root
54 tagged_hash
55 lift_x
56 has_even_y
57 get_taproot_ext
58 );
59  
60 45 our %EXPORT_TAGS = (all => [@EXPORT_OK]);
61  
62 45 signature_for validate_wif => (
63 positional => [BitcoinSecret],
64 );
65  
66 sub validate_wif
67 4 ▶{
Subroutine validate_wif: called CC=1 SCAR=0.0
68 4 my ($secret) = @_;
69 4 state $inner_sig = signature(positional => [ByteStr]);
70  
71 return $secret->unmask_to(
72 4 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 4 return Bitcoin::Crypto::Util::Internal::validate_wif($inner_sig->(@_));
74 }
75 4 );
76 }
77  
78 45 signature_for validate_segwit => (
79 positional => [ByteStr],
80 );
81  
82 45 signature_for get_address_type => (
83 positional => [Str, Maybe [Str], {default => undef}],
84 );
85  
86 45 signature_for get_key_type => (
87 positional => [ByteStr],
88 );
89  
90 45 signature_for get_public_key_compressed => (
91 positional => [ByteStr],
92 );
93  
94 45 signature_for mnemonic_to_seed => (
95 positional => [BitcoinSecret, Maybe [BitcoinSecret], {default => undef}],
96 );
97  
98 sub mnemonic_to_seed
99 2 ▶{
Subroutine mnemonic_to_seed: called CC=2 SCAR=7.0
100 2 my ($secret_mnemonic, $secret_password) = @_;
101  
102 2 ▶ my $mnemonic = $secret_mnemonic->unmask_to(sub { shift });
Subroutine __ANON__: called CC=1 SCAR=0.0
103 my $password = $secret_password
104 2 ▶ ? $secret_password->unmask_to(sub { shift })
Subroutine __ANON__: called CC=1 SCAR=0.0
105 2 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
$secret_password ? : 2 0 2
106  
107 2 return Bitcoin::Crypto::Util::Internal::mnemonic_to_seed($mnemonic, $password);
108 }
109  
110 45 signature_for generate_mnemonic => (
111 positional => [PositiveInt, {default => 128}, Str, {default => 'en'}],
112 );
113  
114 45 signature_for mnemonic_from_entropy => (
115 positional => [BitcoinSecret, Str, {default => 'en'}],
116 );
117  
118 sub mnemonic_from_entropy
119 8 ▶{
Subroutine mnemonic_from_entropy: called CC=1 SCAR=0.0
120 8 my ($secret_entropy, $language) = @_;
121 8 state $inner_sig = signature(positional => [ByteStr]);
122  
123 return $secret_entropy->unmask_to(
124 8 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
125 8 return Bitcoin::Crypto::Util::Internal::mnemonic_from_entropy(
126 $inner_sig->(@_), $language
127 );
128 }
129 8 );
130 }
131  
132 45 signature_for get_path_info => (
133 positional => [Defined],
134 );
135  
136 45 signature_for pack_compactsize => (
137 positional => [PositiveOrZeroInt],
138 );
139  
140 45 signature_for unpack_compactsize => (
141 positional => [ByteStr, Maybe [ScalarRef [PositiveOrZeroInt]], {default => undef}],
142 );
143  
144 45 signature_for pack_array => (
145 positional => [ArrayRef [ByteStr]],
146 );
147  
148 45 signature_for unpack_array => (
149 positional => [ByteStr, Maybe [ScalarRef [PositiveOrZeroInt]], {default => undef}],
150 );
151  
152 45 signature_for hash160 => (
153 positional => [ByteStr],
154 );
155  
156 45 signature_for hash256 => (
157 positional => [ByteStr],
158 );
159  
160 45 signature_for merkle_root => (
161 positional => [ArrayRef [ByteStr]],
162 );
163  
164 45 signature_for tagged_hash => (
165 positional => [Str, ByteStr],
166 );
167  
168 45 signature_for lift_x => (
169 positional => [ByteStr],
170 );
171  
172 45 signature_for has_even_y => (
173 positional => [ByteStr | InstanceOf ['Bitcoin::Crypto::Key::Public']],
174 );
175  
176 45 signature_for get_taproot_ext => (
177 head => [PositiveOrZeroInt],
178 positional => [
179 Dict [] | Dict [
180 script_tree => BitcoinScriptTree,
181 leaf_id => ByteStr,
182 codesep_pos => Optional [Maybe [PositiveOrZeroInt]],
183 ],
184 {slurpy => !!1}
185 ],
186 );
187  
188 45 1;
189  
190 __END__
« Crypto/Transaction/Signer/CompatP2WPKH.pm ↑ Summary Crypto.pm »