| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bitcoin::Crypto; |
|
2
|
|
|
|
|
|
|
$Bitcoin::Crypto::VERSION = '2.000_01'; # TRIAL |
|
3
|
|
|
|
|
|
|
$Bitcoin::Crypto::VERSION = '2.00001'; |
|
4
|
30
|
|
|
30
|
|
1306483
|
use v5.10; |
|
|
30
|
|
|
|
|
313
|
|
|
5
|
30
|
|
|
30
|
|
181
|
use strict; |
|
|
30
|
|
|
|
|
87
|
|
|
|
30
|
|
|
|
|
784
|
|
|
6
|
30
|
|
|
30
|
|
164
|
use warnings; |
|
|
30
|
|
|
|
|
90
|
|
|
|
30
|
|
|
|
|
995
|
|
|
7
|
30
|
|
|
30
|
|
190
|
use Exporter qw(import); |
|
|
30
|
|
|
|
|
100
|
|
|
|
30
|
|
|
|
|
9231
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
|
10
|
|
|
|
|
|
|
btc_extprv |
|
11
|
|
|
|
|
|
|
btc_prv |
|
12
|
|
|
|
|
|
|
btc_extpub |
|
13
|
|
|
|
|
|
|
btc_pub |
|
14
|
|
|
|
|
|
|
btc_script |
|
15
|
|
|
|
|
|
|
btc_transaction |
|
16
|
|
|
|
|
|
|
btc_block |
|
17
|
|
|
|
|
|
|
btc_utxo |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => [@EXPORT_OK]); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub btc_extprv |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
49
|
|
|
49
|
1
|
68547
|
require Bitcoin::Crypto::Key::ExtPrivate; |
|
25
|
49
|
|
|
|
|
429
|
return 'Bitcoin::Crypto::Key::ExtPrivate'; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub btc_prv |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
31
|
|
|
31
|
1
|
51677
|
require Bitcoin::Crypto::Key::Private; |
|
31
|
31
|
|
|
|
|
280
|
return 'Bitcoin::Crypto::Key::Private'; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub btc_extpub |
|
35
|
|
|
|
|
|
|
{ |
|
36
|
10
|
|
|
10
|
1
|
11115
|
require Bitcoin::Crypto::Key::ExtPublic; |
|
37
|
10
|
|
|
|
|
84
|
return 'Bitcoin::Crypto::Key::ExtPublic'; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub btc_pub |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
74
|
|
|
74
|
1
|
42233
|
require Bitcoin::Crypto::Key::Public; |
|
43
|
74
|
|
|
|
|
2061
|
return 'Bitcoin::Crypto::Key::Public'; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub btc_script |
|
47
|
|
|
|
|
|
|
{ |
|
48
|
254
|
|
|
254
|
1
|
72421
|
require Bitcoin::Crypto::Script; |
|
49
|
254
|
|
|
|
|
2856
|
return 'Bitcoin::Crypto::Script'; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub btc_transaction |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
53
|
|
|
53
|
1
|
105080
|
require Bitcoin::Crypto::Transaction; |
|
55
|
53
|
|
|
|
|
1070
|
return 'Bitcoin::Crypto::Transaction'; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub btc_utxo |
|
59
|
|
|
|
|
|
|
{ |
|
60
|
68
|
|
|
68
|
1
|
41845
|
require Bitcoin::Crypto::Transaction::UTXO; |
|
61
|
68
|
|
|
|
|
969
|
return 'Bitcoin::Crypto::Transaction::UTXO'; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub btc_block |
|
65
|
|
|
|
|
|
|
{ |
|
66
|
54
|
|
|
54
|
1
|
15829
|
require Bitcoin::Crypto::Block; |
|
67
|
54
|
|
|
|
|
1102
|
return 'Bitcoin::Crypto::Block'; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Bitcoin::Crypto - Bitcoin cryptography in Perl |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
use Bitcoin::Crypto qw(btc_extprv); |
|
79
|
|
|
|
|
|
|
use Bitcoin::Crypto::Util qw(generate_mnemonic to_format); |
|
80
|
|
|
|
|
|
|
use Bitcoin::Crypto::Constants; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# extended keys are used for mnemonic generation and key derivation |
|
83
|
|
|
|
|
|
|
my $mnemonic = generate_mnemonic; |
|
84
|
|
|
|
|
|
|
say "your mnemonic code is: $mnemonic"; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $master_key = btc_extprv->from_mnemonic($mnemonic); |
|
87
|
|
|
|
|
|
|
my $derived_key = $master_key->derive_key_bip44( |
|
88
|
|
|
|
|
|
|
purpose => Bitcoin::Crypto::Constants::bip44_segwit_purpose, |
|
89
|
|
|
|
|
|
|
index => 0, |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# basic keys can be used for signatures and addresses |
|
93
|
|
|
|
|
|
|
my $priv = $derived_key->get_basic_key; |
|
94
|
|
|
|
|
|
|
my $pub = $priv->get_public_key; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
say 'private key: ' . $priv->to_wif; |
|
97
|
|
|
|
|
|
|
say 'public key: ' . to_format [hex => $pub->to_serialized]; |
|
98
|
|
|
|
|
|
|
say 'address: ' . $pub->get_address; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Cryptographic module for common Bitcoin-related tasks. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
See L<Bitcoin::Crypto::Manual> for an overview of the module. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SHORTCUT FUNCTIONS |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 Exported interface |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This package exports the following functions when asked for them. These are |
|
111
|
|
|
|
|
|
|
shourtcut functions and will load needed packages and return their names. You |
|
112
|
|
|
|
|
|
|
can then use names of loaded packages to instantiate them however you want. You |
|
113
|
|
|
|
|
|
|
can also load all of them with the I<:all> tag in import. These functions can |
|
114
|
|
|
|
|
|
|
be used as follows: |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
use Bitcoin::Crypto qw(btc_pub); |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# loads Bitcoin::Crypto::Key::Public and returns package name |
|
119
|
|
|
|
|
|
|
# we can now use it to run its methods |
|
120
|
|
|
|
|
|
|
my $public_key = btc_pub->from_serialized([hex => $hex_data]); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head3 btc_extprv |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Loads L<Bitcoin::Crypto::Key::ExtPrivate> |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head3 btc_prv |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Loads L<Bitcoin::Crypto::Key::Private> |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head3 btc_extpub |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Loads L<Bitcoin::Crypto::Key::ExtPublic> |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head3 btc_pub |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Loads L<Bitcoin::Crypto::Key::Public> |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head3 btc_script |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Loads L<Bitcoin::Crypto::Script> |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head3 btc_transaction |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Loads L<Bitcoin::Crypto::Transaction> |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head3 btc_utxo |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Loads L<Bitcoin::Crypto::Transaction::UTXO> |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head3 btc_block |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Loads L<Bitcoin::Crypto::Block> |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L<Bitcoin::RPC::Client> |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L<https://github.com/bitcoin/bips> |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Bartosz Jarzyna E<lt>bbrtj.pro@gmail.comE<gt> (L<Support me|https://bbrtj.eu/support>) |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Copyright (C) 2018 - 2023 by Bartosz Jarzyna |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
169
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
170
|
|
|
|
|
|
|
|