Skip to content

Instantly share code, notes, and snippets.

@bbrtj
Created Jun 12, 2021
Embed
What would you like to do?
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