Bitcoin-Crypto
view release on metacpan or search on metacpan
lib/Bitcoin/Crypto/Key/Public.pm view on Meta::CPAN
unspendable script path will be used according to BIP341.
If the public key was obtained through BIP44 derivation scheme, this method
will check whether the purpose was C<86> and raise an exception otherwise. If
you wish to generate this address anyway, call C<clear_purpose>.
=head3 get_address
$address_string = $object->get_address()
Returns a string containing the address. Tries to guess which address type is
most fitting:
=over
=item * If the key has a BIP44 purpose set, generates type of address which
matches the purpose
=item * If the key doesn't have a purpose but the network supports segwit,
returns a taproot address (same as C<get_taproot_address>, but does not accept
a script tree)
lib/Bitcoin/Crypto/PSBT/FieldType.pm view on Meta::CPAN
B<Required in the constructor.> Name of the field type defined in BIP174.
=head3 code
B<Required in the constructor.> Code of the field type defined in BIP174.
=head3 map_type
B<Available in the constructor.> A map type this field belongs to. If not
passed, it will be guessed from L</name>. Map types are defined as constants in
L<Bitcoin::Crypto::Constants>.
=head3 serializer
B<Available in the constructor.> A coderef which will be used to do DWIM
serialization of the value for easier handling. If not passed, a simple coderef
will be installed which will only coerce format descriptions into bytestrings.
=head3 deserializer
lib/Bitcoin/Crypto/Transaction/Digest.pm view on Meta::CPAN
# no other inputs if anyonecanpay - skip cloning and all other work
next if $anyonecanpay && $input_ind != $signing_index;
my $input = $inputs->[$input_ind]->clone;
if ($input_ind == $signing_index) {
my $subscript = $self->signing_subscript;
if (!$subscript) {
Bitcoin::Crypto::Exception::Transaction->raise(
"can't guess the subscript from a non-standard transaction"
) unless $input->utxo->output->is_standard;
$subscript = $input->script_base;
}
$input->set_signature_script($subscript);
}
else {
$input->set_signature_script('');
$input->set_sequence_no(0)
lib/Bitcoin/Crypto/Util.pm view on Meta::CPAN
and C<1>. Future segwit version addresses will work just fine, but no special
validation will be performed until implemented.
Raises an exception (C<Bitcoin::Crypto::Exception::SegwitProgram>) on error.
Returns the detected segwit program version.
=head2 get_address_type
$type = get_address_type($address, $network = Bitcoin::Crypto::Network->get)
Tries to guess the type of C<$address>. Returns C<P2PKH>, C<P2SH>, C<P2WPKH>,
C<P2WSH> or C<P2TR>. May throw Base58, Bech32, SegwitProgram, Address or other
exceptions if the string is not a valid address.
=head2 get_key_type
$is_private = get_key_type($bytestr);
Checks if the C<$bytestr> looks like a valid ASN X9.62 format (compressed /
uncompressed / hybrid public key or private key entropy up to curve size bits).
t/Key/Public.t view on Meta::CPAN
is(
$pubkey->get_legacy_address,
$case->{compressed_address},
'correctly created compressed address'
);
$pubkey->set_purpose(44);
is(
$pubkey->get_address,
$case->{compressed_address},
'correctly guessed legacy address'
);
};
++$case_num;
}
$case_num = 0;
foreach my $case (@cases_segwit) {
subtest "testing SegWit readiness, case $case_num" => sub {
my $pubkey = btc_pub->from_serialized([hex => $case->{pubkey}]);
t/Key/Public.t view on Meta::CPAN
$pubkey->get_segwit_address,
$case->{segwit_address},
'correctly created segwit native address'
);
$pubkey->set_purpose(49);
is(
$pubkey->get_address,
$case->{compat_address},
'correctly guessed segwit compat address'
);
$pubkey->set_purpose(84);
is(
$pubkey->get_address,
$case->{segwit_address},
'correctly guessed segwit native address'
);
};
++$case_num;
}
subtest 'verify message using pubkey' => sub {
my $message = 'Perl test script';
my $pub = btc_pub->from_serialized([hex => $validation_case{uncompressed}]);
t/Script/standard-types.t view on Meta::CPAN
]
);
my $case_num = 0;
foreach my $case (@cases) {
my ($type, $raw_script, $address) = @$case;
my $type_str = $type // 'no type';
subtest "testing case $case_num ($type_str)" => sub {
subtest "testing script type guessing" => sub {
my $script = btc_script->from_serialized($raw_script);
my $got_type = $script->type // 'no type';
is !!$script->has_type, !!$type, 'has_type ok';
is $got_type, $type_str, 'type ok';
};
subtest "testing address" => sub {
my $script = btc_script->from_serialized($raw_script);
( run in 0.518 second using v1.01-cache-2.11-cpan-39bf76dae61 )