Created
June 12, 2021 09:33
-
-
Save bbrtj/ec47c3c0041174726101620f546104aa to your computer and use it in GitHub Desktop.
Sign and verify a message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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