Skip to content

Instantly share code, notes, and snippets.

@bbrtj
Created June 12, 2021 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbrtj/ec47c3c0041174726101620f546104aa to your computer and use it in GitHub Desktop.
Save bbrtj/ec47c3c0041174726101620f546104aa to your computer and use it in GitHub Desktop.
Sign and verify a message
use v5.20;
use warnings;
use Bitcoin::Crypto qw(btc_prv);
my $wif = 'KzTvd4uwnyRsFyoyTUWicxvP1HVQhTfsNLGVeyZSD6eajpTYvaRk';
my $private_key = btc_prv->from_wif($wif);
my $message = 'I own this Bitcoin address! ' . $private_key->get_public_key->get_legacy_address;
my $signature = $private_key->sign_message($message);
say 'Message is ' . $message;
say 'Signature is ' . unpack 'H*', $signature;
say 'Verification is ' . ($private_key->get_public_key->verify_message($message, $signature) ? 'successful' : 'unsuccessful');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment