Bitcoin-Crypto

 view release on metacpan or  search on metacpan

lib/Bitcoin/Crypto/Key/Public.pm  view on Meta::CPAN

Returns string containing Bech32 encoded witness program (C<p2wpkh> address)

If the public key was obtained through BIP44 derivation scheme, this method
will check whether the purpose was C<84> and raise an exception otherwise. If
you wish to generate this address anyway, call L</clear_purpose>.

=head2 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 segwit address (same as C<get_segwit_address>)

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
C<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

		$input_copy->set_signature_script('');
		$tx_copy->add_input($input_copy);
	}

	my $this_input = $tx_copy->inputs->[$self->signing_index];
	if ($self->signing_subscript) {
		$this_input->set_signature_script($self->signing_subscript);
	}
	else {
		Bitcoin::Crypto::Exception::Transaction->raise(
			"can't guess the subscript from a non-standard transaction"
		) unless $this_input->utxo->output->is_standard;

		$this_input->set_signature_script($this_input->script_base->to_serialized);
	}

	# Handle sighashes
	if ($sighash_type == Bitcoin::Crypto::Constants::sighash_none) {
		@{$tx_copy->outputs} = ();
		foreach my $input (@{$tx_copy->inputs}) {
			$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 2.216 seconds using v1.01-cache-2.11-cpan-748bfb374f4 )