@@ -5,6 +5,7 @@ use strict;
5
5
use warnings;
6
6
use Moo;
7
7
use Type::Params -sigs;
8
+ use Carp qw( carp) ;
8
9
9
10
use Bitcoin::Crypto::Script;
10
11
use Bitcoin::Crypto::Base58 qw( encode_base58check) ;
@@ -19,18 +20,27 @@ with qw(Bitcoin::Crypto::Role::BasicKey);
19
20
20
21
sub _is_private { 0 }
21
22
22
- signature_for key_hash => (
23
+ signature_for get_hash => (
23
24
method => Object,
24
25
positional => [],
25
26
);
26
27
27
- sub key_hash
28
+ sub get_hash
28
29
{
29
30
my ($self ) = @_ ;
30
31
31
32
return hash160($self -> to_serialized);
32
33
}
33
34
35
+ sub key_hash
36
+ {
37
+ my $self = shift ;
38
+ my $class = ref $self ;
39
+
40
+ carp " $class ->key_hash() is now deprecated. Use $class ->get_hash() instead" ;
41
+ return $self -> get_hash(@_ );
42
+ }
43
+
34
44
around from_serialized => sub {
35
45
my ($orig , $class , $key ) = @_ ;
36
46
@@ -52,7 +62,7 @@ sub witness_program
52
62
my $program = Bitcoin::Crypto::Script-> new(network => $self -> network);
53
63
$program
54
64
-> add_operation(' OP_' . Bitcoin::Crypto::Constants::segwit_witness_version)
55
- -> push_bytes($self -> key_hash );
65
+ -> push_bytes($self -> get_hash );
56
66
57
67
return $program ;
58
68
}
@@ -70,7 +80,7 @@ sub get_legacy_address
70
80
' legacy addresses can only be created with BIP44 in legacy (BIP44) mode'
71
81
) unless $self -> has_purpose(Bitcoin::Crypto::Constants::bip44_purpose);
72
82
73
- my $pkh = $self -> network-> p2pkh_byte . $self -> key_hash ;
83
+ my $pkh = $self -> network-> p2pkh_byte . $self -> get_hash ;
74
84
return encode_base58check($pkh );
75
85
}
76
86
@@ -218,6 +228,16 @@ Deprecated. Use C<< $class->from_serialized([hex => $data]) >> instead.
218
228
219
229
Deprecated. Use C<< to_format [hex => $key->to_serialized()] >> instead.
220
230
231
+ =head2 get_hash
232
+
233
+ $bytestr = $object->get_hash()
234
+
235
+ Returns hash160 of the serialized public key.
236
+
237
+ =head2 key_hash
238
+
239
+ Deprecated. Use C<< $key->get_hash() >> instead.
240
+
221
241
=head2 set_compressed
222
242
223
243
$key_object = $object->set_compressed($val)
0 commit comments