-
-
13 May 2022 20:30:43 UTC
- Distribution: Bitcoin-Crypto
- Module version: 1.006
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers (202 / 0 / 0)
- Kwalitee
Bus factor: 1- % Coverage
- License: perl_5
- Perl: v5.10.0
- Activity
24 month- Tools
- Download (59.96KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
NAME
Bitcoin::Crypto::Key::ExtPublic - Bitcoin extended public keys
SYNOPSIS
use Bitcoin::Crypto::Key::ExtPrivate; my $mnemonic = Bitcoin::Crypto::Key::ExtPrivate->generate_mnemonic; my $key = Bitcoin::Crypto::Key::ExtPrivate->from_mnemonic($mnemonic); # derive child public key my $path = "M/0"; my $child_key = $key->derive_key($path); my $ser_child_key = $child_key->to_serialized_base58; print "Your exported $path child key is: $ser_child_key"; # create basic public key my $basic_public = $child_key->get_basic_key;
DESCRIPTION
This class allows you to create an extended public key instance.
You can use an extended public key to:
derive extended keys using a path (only public keys)
restore keys from serialized base58 format
see Bitcoin::Crypto::Network if you want to work with other networks than Bitcoin Mainnet.
METHODS
to_serialized
$serialized_key = $object->to_serialized()
Returns the key serialized in format specified in BIP32 as byte string.
Note: different prefixes defined in BIP49 and BIP84 are not yet supported.
to_serialized_base58
$serialized_key = $object->to_serialized_base58()
Behaves the same as to_serialized(), but performs Base58Check encoding on the resulting byte string.
from_serialized
$key_object = $class->from_serialized($serialized, $network = undef)
Tries to unserialize byte string
$serialized
with format specified in BIP32.Dies on errors. If multiple networks match serialized data specify
$network
manually (id of the network) to avoid exception.Note: different prefixes defined in BIP49 and BIP84 are not yet supported.
from_serialized_base58
$key_object = $class->from_serialized_base58($base58, $network = undef)
Same as from_serialized, but performs Base58Check decoding on
$base58
argument.set_network
$key_object = $object->set_network($val)
Change key's network state to
$val
. It can be either network name present in Bitcoin::Crypto::Network package or an instance of this class.Returns current key instance.
get_basic_key
$basic_key_object = $object->get_basic_key()
Returns the key in basic format: Bitcoin::Crypto::Key::Public
derive_key
$derived_key_object = $object->derive_key($path)
Performs extended key derivation as specified in BIP32 on the current key with
$path
. Dies on error.See BIP32 document for details on derivation paths and methods.
Note that public keys cannot derive private keys and your derivation path must start with M (capital m).
Returns a new extended key instance - result of a derivation.
get_fingerprint
$fingerprint = $object->get_fingerprint($len = 4)
Returns a fingerprint of the extended key of
$len
length (byte string)EXCEPTIONS
This module throws an instance of Bitcoin::Crypto::Exception if it encounters an error. It can produce the following error types from the Bitcoin::Crypto::Exception namespace:
KeyDerive - key couldn't be derived correctly
KeyCreate - key couldn't be created correctly
NetworkConfig - incomplete or corrupted network configuration
SEE ALSO
Module Install Instructions
To install Bitcoin::Crypto, copy and paste the appropriate command in to your terminal.
cpanm Bitcoin::Crypto
perl -MCPAN -e shell install Bitcoin::Crypto
For more information on module installation, please visit the detailed CPAN module installation guide.