Bitcoin-Crypto
view release on metacpan or search on metacpan
lib/Bitcoin/Crypto/Manual.pod view on Meta::CPAN
garbage), but calling L<Bitcoin::Crypto::Script::Runner/success> on the runner
which compiled it will return C<true>.
=back
=head2 Partially Signed Bitcoin Transactions
PSBT is a format for exchanging transaction data between parties in a
standardized way. Each PSBT consists of maps, which are containers for values.
There are Global, Input and Output maps, and each consists of various fields
which can be used to store data. Fields each have an optional key and a value.
Bitcoin::Crypto implements PSBT in L<Bitcoin::Crypto::PSBT>. It contains
implementations of all fields from BIP174 (PSBTv0), BIP370 (PSBTv2) and BIP371
(taproot fields). Our implementation uses serializers and deserializers to map
binary PSBT data into Bitcoin::Crypto objects.
Following example (taken from C<ex/tx/taproot_script_create.pl>) creates a
minimal PSBTv0 to store a taproot script tree and a NUMS public key. It depends
on serializers to turn Perl objects into binary data:
use Bitcoin::Crypto qw(btc_psbt);
# create a PSBT with tree and public key saved for later
my $psbt = btc_psbt->new;
$psbt->add_field(
type => 'PSBT_GLOBAL_UNSIGNED_TX',
value => $tx,
);
$psbt->add_field(
type => 'PSBT_OUT_TAP_INTERNAL_KEY',
value => $public,
index => 0,
);
$psbt->add_field(
type => 'PSBT_OUT_TAP_TREE',
value => $tree,
index => 0,
);
say 'PSBT with tree and internal key: ' . to_format [base64 => $psbt->to_serialized];
Following example (taken from C<ex/tx/taproot_script_redeem.pl>) decodes a that
PSBT and pulls data out of it:
my $psbt = btc_psbt->from_serialized([base64 => $b64_psbt]);
my $prev_tx = $psbt->get_field('PSBT_GLOBAL_UNSIGNED_TX')->value;
my $tree = $psbt->get_field('PSBT_OUT_TAP_TREE', 0)->value;
my $public_key = $psbt->get_field('PSBT_OUT_TAP_INTERNAL_KEY', 0)->value;
See L<Bitcoin::Crypto::PSBT> for more details and a complete reference of field
types and what objects their serializers / deserializers use.
=head2 Performance
A lot of work has been done to ensure Bitcoin::Crypto transaction decoding and
verification performance is somewhat acceptable. Benchmarks on author's (not
very powerful) machine have shown that up to 600 legacy transactions (each
having 2 P2MS inputs) or 800 taproot transactions (each having 4 key spend
inputs) can be decoded and verified per second, per process.
For best performance, extra modules from CPAN should be installed, listed
below. This module will use them if they can be loaded.
=over
=item * Modules from L<Mooish::Base/Moo>
=item * L<Type::Tiny::XS> (used automatically by L<Type::Tiny>)
=item * L<Class::XSAccessor> (used automatically by L<Moo>)
=back
=head2 Module development and TODOs
There is no official roadmap for developing new Bitcoin::Crypto features. The
library tries to stay up to date with most impactful additions to the protocol,
but no promises can be made.
Contributions are welcome for:
=over
=item * All issues with L<help wanted|https://github.com/Perl-Bitcoin/Bitcoin-Crypto/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22help%20wanted%22> tag on GitHub
=item * Test improvements
=item * Documentation improvements
=item * Performance improvements
=back
=head1 DISCLAIMER
Although the module was written with an extra care and appropriate tests are in
place asserting compatibility with many Bitcoin standards, due to complexity of
the subject some bugs may still be present. In the world of digital money, a
single bug may lead to losing funds. I encourage anyone to test the module
themselves, review the test cases and use the module with care. Suggestions for
improvements and more edge cases to test will be gladly accepted, but there is
B<no warranty on funds manipulated by this module>.
=head1 SUPPORT
Use the L<GitHub
bug tracker|https://github.com/Perl-Bitcoin/Bitcoin-Crypto/issues> to report
issues. If you have any questions, ask them on L<GitHub
discussions|https://github.com/orgs/Perl-Bitcoin/discussions>.
=head1 SEE ALSO
L<Bitcoin whitepaper|https://bitcoin.org/en/bitcoin-paper>
L<Bitcoin BIPs|https://github.com/bitcoin/bips>
L<Bitcoin::BIP39>
L<Bitcoin::Secp256k1>
( run in 0.529 second using v1.01-cache-2.11-cpan-39bf76dae61 )