Skip to content

Commit a51c58a

Browse files
committed
Deprecate key_hash of public key in favor of get_hash
1 parent 49b6a89 commit a51c58a

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

Changes

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ Revision history for Perl extension Bitcoin::Crypto.
1818
- exception is no longer raised if the default network is among multiple possible networks after deserialization of WIFs and extended keys
1919
- module can now be configured to work in single-network mode, disallowing creation of objects with different networks
2020

21-
[Changes]
21+
[Changes and deprecations]
2222
- codes in Bitcoin::Crypto::Script::Opcode are now integers instead of bytestrings of length 1
2323
- Bitcoin::Crypto::Util::get_path_info now returns instances of Bitcoin::Crypto::DerivationPath (internal structure remains unchanged)
24+
- Bitcoin::Crypto::Key::Public::key_hash is now deprecated, added new method get_hash (consistent naming with other modules)
2425

2526
2.004 Tue Apr 23 2024
2627
[Improvements]

lib/Bitcoin/Crypto/Key/Public.pm

+24-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use strict;
55
use warnings;
66
use Moo;
77
use Type::Params -sigs;
8+
use Carp qw(carp);
89

910
use Bitcoin::Crypto::Script;
1011
use Bitcoin::Crypto::Base58 qw(encode_base58check);
@@ -19,18 +20,27 @@ with qw(Bitcoin::Crypto::Role::BasicKey);
1920

2021
sub _is_private { 0 }
2122

22-
signature_for key_hash => (
23+
signature_for get_hash => (
2324
method => Object,
2425
positional => [],
2526
);
2627

27-
sub key_hash
28+
sub get_hash
2829
{
2930
my ($self) = @_;
3031

3132
return hash160($self->to_serialized);
3233
}
3334

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+
3444
around from_serialized => sub {
3545
my ($orig, $class, $key) = @_;
3646

@@ -52,7 +62,7 @@ sub witness_program
5262
my $program = Bitcoin::Crypto::Script->new(network => $self->network);
5363
$program
5464
->add_operation('OP_' . Bitcoin::Crypto::Constants::segwit_witness_version)
55-
->push_bytes($self->key_hash);
65+
->push_bytes($self->get_hash);
5666

5767
return $program;
5868
}
@@ -70,7 +80,7 @@ sub get_legacy_address
7080
'legacy addresses can only be created with BIP44 in legacy (BIP44) mode'
7181
) unless $self->has_purpose(Bitcoin::Crypto::Constants::bip44_purpose);
7282

73-
my $pkh = $self->network->p2pkh_byte . $self->key_hash;
83+
my $pkh = $self->network->p2pkh_byte . $self->get_hash;
7484
return encode_base58check($pkh);
7585
}
7686

@@ -218,6 +228,16 @@ Deprecated. Use C<< $class->from_serialized([hex => $data]) >> instead.
218228
219229
Deprecated. Use C<< to_format [hex => $key->to_serialized()] >> instead.
220230
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+
221241
=head2 set_compressed
222242
223243
$key_object = $object->set_compressed($val)

0 commit comments

Comments
 (0)