The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Bitcoin::Crypto::PublicKey - class for Bitcoin public keys

SYNOPSIS

  use Bitcoin::Crypto::PublicKey;

  # verify signature (it has to be byte string, see perlpacktut)

  $pub->verifyMessage("Hello world", $sig);

  # getting address from public key (p2pkh)

  my $address = $pub->getAddress();

DESCRIPTION

This class allows you to create a public key instance.

You can use a public key to:

  • read from and export to byte / hexadecimal string

  • verify messages

  • create p2pkh address

This class doesn't:

  • create any addresses other than p2pkh (yet)

METHODS

fromHex($str) / fromBytes($str)

Use these methods to create a PublicKey instance. All take single string argument with public key data. Returns class instance.

new($instance)

Takes a single argument which must be instance of Crypt::PK::ECC. This allows you to use raw Crypt::PK::ECC methods to create key on your own.

setCompressed($val)

Change key's compression state to $val (1/0). This will change the Address generated by public key.

setNetwork($val)

Change key's network state to $val. It can be either network name present in Bitcoin::Crypto::Network package or a valid network hashref. This will enable generation of this network's addresses.

getAddress()

Returns string containing Base58Check encoded public key hash (p2pkh address)

verifyMessage($message, $signature, $algo)

Verifies $signature against digest of $message (with $algo digest algorithm) using public key. $algo must be available in Digest package. Returns boolean.

toHex() / toBytes()

Returns public key representation in specified format.

SEE ALSO

Bitcoin::Crypto::PrivateKey
Bitcoin::Crypto::Network