diff --git a/Changes b/Changes index 0ddaa72..7192564 100644 --- a/Changes +++ b/Changes @@ -18,9 +18,10 @@ Revision history for Perl extension Bitcoin::Crypto. - exception is no longer raised if the default network is among multiple possible networks after deserialization of WIFs and extended keys - module can now be configured to work in single-network mode, disallowing creation of objects with different networks - [Changes] + [Changes and deprecations] - codes in Bitcoin::Crypto::Script::Opcode are now integers instead of bytestrings of length 1 - Bitcoin::Crypto::Util::get_path_info now returns instances of Bitcoin::Crypto::DerivationPath (internal structure remains unchanged) + - Bitcoin::Crypto::Key::Public::key_hash is now deprecated, added new method get_hash (consistent naming with other modules) 2.004 Tue Apr 23 2024 [Improvements] diff --git a/lib/Bitcoin/Crypto/Key/Public.pm b/lib/Bitcoin/Crypto/Key/Public.pm index 13ce416..32b299e 100644 --- a/lib/Bitcoin/Crypto/Key/Public.pm +++ b/lib/Bitcoin/Crypto/Key/Public.pm @@ -5,6 +5,7 @@ use strict; use warnings; use Moo; use Type::Params -sigs; +use Carp qw(carp); use Bitcoin::Crypto::Script; use Bitcoin::Crypto::Base58 qw(encode_base58check); @@ -19,18 +20,27 @@ with qw(Bitcoin::Crypto::Role::BasicKey); sub _is_private { 0 } -signature_for key_hash => ( +signature_for get_hash => ( method => Object, positional => [], ); -sub key_hash +sub get_hash { my ($self) = @_; return hash160($self->to_serialized); } +sub key_hash +{ + my $self = shift; + my $class = ref $self; + + carp "$class->key_hash() is now deprecated. Use $class->get_hash() instead"; + return $self->get_hash(@_); +} + around from_serialized => sub { my ($orig, $class, $key) = @_; @@ -52,7 +62,7 @@ sub witness_program my $program = Bitcoin::Crypto::Script->new(network => $self->network); $program ->add_operation('OP_' . Bitcoin::Crypto::Constants::segwit_witness_version) - ->push_bytes($self->key_hash); + ->push_bytes($self->get_hash); return $program; } @@ -70,7 +80,7 @@ sub get_legacy_address 'legacy addresses can only be created with BIP44 in legacy (BIP44) mode' ) unless $self->has_purpose(Bitcoin::Crypto::Constants::bip44_purpose); - my $pkh = $self->network->p2pkh_byte . $self->key_hash; + my $pkh = $self->network->p2pkh_byte . $self->get_hash; return encode_base58check($pkh); } @@ -218,6 +228,16 @@ Deprecated. Use C<< $class->from_serialized([hex => $data]) >> instead. Deprecated. Use C<< to_format [hex => $key->to_serialized()] >> instead. +=head2 get_hash + + $bytestr = $object->get_hash() + +Returns hash160 of the serialized public key. + +=head2 key_hash + +Deprecated. Use C<< $key->get_hash() >> instead. + =head2 set_compressed $key_object = $object->set_compressed($val)