NAME

App::Bitcoin::PaperWallet - Generate printable cold storage of bitcoins

SYNOPSIS

use App::Bitcoin::PaperWallet;

my $hash = App::Bitcoin::PaperWallet->generate($entropy, $password, {
	entropy_length => 128,
});

my $mnemonic = $hash->{mnemonic};
my $addresses = $hash->{addresses};

DESCRIPTION

This module allows you to generate a Hierarchical Deterministic BIP49/84 compilant Bitcoin wallet.

This package contains high level cryptographic operations for doing that. See paper-wallet for the main script of this distribution.

FUNCTIONS

generate

my $hash = $class->generate($entropy, $password, \%opts);

Not exported, should be used as a class method. Returns a hash containing two keys: mnemonic (string) and addresses (array reference of strings).

$entropy is meant to be user-defined entropy (string) that will be passed through sha256 to obtain wallet seed. Can be passed undef explicitly to use cryptographically secure random number generator instead.

$password is a password that will be used to secure the generated mnemonic. Passing empty string will disable the password protection. Note that password does not have to be strong, since it will only secure the mnemonic in case someone obtained physical access to your mnemonic. Using a hard, long password increases the possibility you will not be able to claim your bitcoins in the future.

\%opts can take following values:

  • compat_addresses

    A number of segwit compat (purpose 49) addresses to generate, 1 by default.

  • segwit_addresses

    A number of segwit native (purpose 84) addresses to generate, 3 by default.

  • entropy_length

    A number between 128 and 256 with intervals of 32. 128 will generate 12 words while 256 will generate 24 words. 256 by default.

CAVEATS

  • This module should properly handle unicode in command line, but for in-Perl usage it is required to pass UTF8-decoded strings to it (like with use utf8;).

    Internally, passwords are handled as-is, while seeds are encoded into UTF8 before passing them to SHA256.

  • An extra care should be taken when using this module on Windows command line. Some Windows-specific quirks may not be handled properly. Verify before sending funds to the wallet.

Compatibility

  • Version 1.12 changed the way optional parameters to generate are provided.

  • Versions 1.01 and older generated addresses with invalid derivation paths. Funds in these wallets won't be visible in most HD wallets, and have to be swept by revealing their private keys in tools like https://iancoleman.io/bip39/. Use derivation path m/44'/0'/0'/0 and indexes 0 throughout 3 - sweeping these private keys will recover your funds.

  • Versions 1.02 and older incorrectly handled unicode. If you generated a wallet with unicode password in the past, open an issue in the bug tracker.

SEE ALSO

Bitcoin::Crypto

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) 2021 by Bartosz Jarzyna

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.0 or, at your option, any later version of Perl 5 you may have available.