NAME

Bitcoin::Crypto - Bitcoin cryptography in Perl

SYNOPSIS

use Bitcoin::Crypto qw(btc_extprv);
use Bitcoin::Crypto::Util qw(generate_mnemonic to_format);
use Bitcoin::Crypto::Constants;

# extended keys are used for mnemonic generation and key derivation
my $mnemonic = generate_mnemonic;
say "your mnemonic code is: $mnemonic";

my $master_key = btc_extprv->from_mnemonic($mnemonic);
my $derived_key = $master_key->derive_key_bip44(
	purpose => Bitcoin::Crypto::Constants::bip44_segwit_purpose,
	index => 0,
);

# basic keys can be used for signatures and addresses
my $priv = $derived_key->get_basic_key;
my $pub = $priv->get_public_key;

say 'private key: ' . $priv->to_wif;
say 'public key: ' . to_format [hex => $pub->to_serialized];
say 'address: ' . $pub->get_address;

DESCRIPTION

This is a cryptographic module for common Bitcoin-related tasks. It enables low-level manipulation of Bitcoin keys, transactions and encodings. See Bitcoin::Crypto::Manual for an overview of the module.

SHORTCUT FUNCTIONS

This package exports the following functions when asked for them. These are shourtcut functions and will load needed packages and return their names. You can then use names of loaded packages to instantiate them however you want. It's also possible to load all of them with the :all tag in import. They functions can be used as follows:

use Bitcoin::Crypto qw(btc_pub);

# loads Bitcoin::Crypto::Key::Public and returns package name
# we can now use it to run its methods
my $public_key = btc_pub->from_serialized([hex => $hex_data]);

btc_extprv

Loads Bitcoin::Crypto::Key::ExtPrivate

btc_prv

Loads Bitcoin::Crypto::Key::Private

btc_extpub

Loads Bitcoin::Crypto::Key::ExtPublic

btc_pub

Loads Bitcoin::Crypto::Key::Public

btc_script

Loads Bitcoin::Crypto::Script

btc_transaction

Loads Bitcoin::Crypto::Transaction

btc_utxo

Loads Bitcoin::Crypto::Transaction::UTXO

btc_block

Loads Bitcoin::Crypto::Block

btc_psbt

Loads Bitcoin::Crypto::PSBT

SEE ALSO

Bitcoin::RPC::Client

https://github.com/bitcoin/bips

AUTHOR

Bartosz Jarzyna <bbrtj.pro@gmail.com>

Consider supporting my effort: https://bbrtj.eu/support

Contributors

In no particular order:

  • chromatic

COPYRIGHT AND LICENSE

Copyright (C) 2018 - 2024 by Bartosz Jarzyna

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.