Skip to content

Commit

Permalink
Adjust the documentation of extended key classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrtj committed Oct 14, 2023
1 parent ba4b600 commit ce013b4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
50 changes: 36 additions & 14 deletions lib/Bitcoin/Crypto/Key/ExtPrivate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ You can use an extended private key to:
=back
see L<Bitcoin::Crypto::Network> if you want to work with other networks than Bitcoin Mainnet.
see L<Bitcoin::Crypto::Network> if you want to work with other networks than
Bitcoin Mainnet.
=head1 METHODS
Expand All @@ -256,21 +257,30 @@ Deprecated - see L<Bitcoin::Crypto::Util/mnemonic_from_entropy>.
Creates a new key from given mnemonic and password.
Note that technically any password is correct and there's no way to tell if it was mistaken.
Note that technically any password is correct and there's no way to tell if it
was mistaken.
If you need to validate if C<$mnemonic> is a valid mnemonic you should specify C<$lang>, e.g. 'en'.
If you need to validate if C<$mnemonic> is a valid mnemonic you should specify
C<$lang>, e.g. 'en'.
If no C<$lang> is given then any string passed as C<$mnemonic> will produce a valid key.
If no C<$lang> is given then any string passed as C<$mnemonic> will produce a
valid key.
Returns a new instance of this class.
B<Important note about unicode:> this function only accepts UTF8-decoded strings (both C<$mnemonic> and C<$password>), but can't detect whether it got it or not. This will only become a problem if you use non-ascii mnemonic and/or password. If there's a possibility of non-ascii, always use utf8 and set binmodes to get decoded (wide) characters to avoid problems recovering your wallet.
B<Important note about unicode:> this function only accepts UTF8-decoded
strings (both C<$mnemonic> and C<$password>), but can't detect whether it got
it or not. This will only become a problem if you use non-ascii mnemonic and/or
password. If there's a possibility of non-ascii, always use utf8 and set
binmodes to get decoded (wide) characters to avoid problems recovering your
wallet.
=head2 from_seed
$key_object = $class->from_seed($seed)
Creates and returns a new key from seed, which can be any data of any length. C<$seed> is expected to be a byte string.
Creates and returns a new key from seed, which can be any data of any length.
C<$seed> is expected to be a byte string.
=head2 from_hex_seed
Expand All @@ -292,7 +302,8 @@ Deprecated. Use C<< to_format [base58 => $key->to_serialized] >> instead.
Tries to unserialize byte string C<$serialized> with format specified in BIP32.
Dies on errors. If multiple networks match serialized data specify C<$network> manually (id of the network) to avoid exception.
Dies on errors. If multiple networks match serialized data specify C<$network>
manually (id of the network) to avoid exception.
=head2 from_serialized_base58
Expand All @@ -302,15 +313,17 @@ Deprecated. Use C<< $class->from_serialized([base58 => $base58]) >> instead.
$key_object = $object->set_network($val)
Change key's network state to C<$val>. It can be either network name present in L<Bitcoin::Crypto::Network> package or an instance of this class.
Change key's network state to C<$val>. It can be either network name present in
L<Bitcoin::Crypto::Network> package or an instance of this class.
Returns current key instance.
=head2 get_public_key
$public_key_object = $object->get_public_key()
Returns instance of L<Bitcoin::Crypto::Key::ExtPublic> generated from the private key.
Returns instance of L<Bitcoin::Crypto::Key::ExtPublic> generated from the
private key.
=head2 get_basic_key
Expand All @@ -322,7 +335,8 @@ Returns the key in basic format: L<Bitcoin::Crypto::Key::Private>
$derived_key_object = $object->derive_key($path)
Performs extended key derivation as specified in BIP32 on the current key with C<$path>. Dies on error.
Performs extended key derivation as specified in BIP32 on the current key with
C<$path>. Dies on error.
See BIP32 document for details on derivation paths and methods.
Expand All @@ -332,11 +346,17 @@ Returns a new extended key instance - result of a derivation.
$derived_key_object = $object->derive_key_bip44(%data)
A helper that constructs a L<Bitcoin::Crypto::BIP44> path from C<%data> and calls L</derive_key> with it. Refer to L<Bitcoin::Crypto::BIP44/Attributes> to see what you can include in C<%data>.
A helper that constructs a L<Bitcoin::Crypto::BIP44> path from C<%data> and
calls L</derive_key> with it. Refer to L<Bitcoin::Crypto::BIP44/Attributes> to
see what you can include in C<%data>.
Using this method instead of specifying BIP44 path yourself will make sure all features of BIP44 derivation will be enabled, like different prefixes for extended keys (C<xprv> / C<yprv> / C<zprv>) and address type generation checking.
Using this method instead of specifying BIP44 path yourself will make sure all
features of BIP44 derivation will be enabled, like different prefixes for
extended keys (C<xprv> / C<yprv> / C<zprv>) and address type generation
checking.
I<Note: coin_type parameter will be ignored, and the current network configuration set in the extended key will be used.>
I<Note: coin_type parameter will be ignored, and the current network
configuration set in the extended key will be used.>
=head2 get_fingerprint
Expand All @@ -346,7 +366,9 @@ Returns a fingerprint of the extended key of C<$len> length (byte string)
=head1 EXCEPTIONS
This module throws an instance of L<Bitcoin::Crypto::Exception> if it encounters an error. It can produce the following error types from the L<Bitcoin::Crypto::Exception> namespace:
This module throws an instance of L<Bitcoin::Crypto::Exception> if it
encounters an error. It can produce the following error types from the
L<Bitcoin::Crypto::Exception> namespace:
=over 2
Expand Down
16 changes: 11 additions & 5 deletions lib/Bitcoin/Crypto/Key/ExtPublic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ Deprecated. Use C<< to_format [base58 => $key->to_serialized] >> instead.
Tries to unserialize byte string C<$serialized> with format specified in BIP32.
Dies on errors. If multiple networks match serialized data specify C<$network> manually (id of the network) to avoid exception.
Dies on errors. If multiple networks match serialized data specify C<$network>
manually (id of the network) to avoid exception.
=head2 from_serialized_base58
Expand All @@ -149,7 +150,8 @@ Deprecated. Use C<< $class->from_serialized([base58 => $base58]) >> instead.
$key_object = $object->set_network($val)
Change key's network state to C<$val>. It can be either network name present in Bitcoin::Crypto::Network package or an instance of this class.
Change key's network state to C<$val>. It can be either network name present in
Bitcoin::Crypto::Network package or an instance of this class.
Returns current key instance.
Expand All @@ -163,11 +165,13 @@ Returns the key in basic format: L<Bitcoin::Crypto::Key::Public>
$derived_key_object = $object->derive_key($path)
Performs extended key derivation as specified in BIP32 on the current key with C<$path>. Dies on error.
Performs extended key derivation as specified in BIP32 on the current key with
C<$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).
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.
Expand All @@ -188,7 +192,9 @@ Returns a fingerprint of the extended key of C<$len> length (byte string)
=head1 EXCEPTIONS
This module throws an instance of L<Bitcoin::Crypto::Exception> if it encounters an error. It can produce the following error types from the L<Bitcoin::Crypto::Exception> namespace:
This module throws an instance of L<Bitcoin::Crypto::Exception> if it
encounters an error. It can produce the following error types from the
L<Bitcoin::Crypto::Exception> namespace:
=over 2
Expand Down

0 comments on commit ce013b4

Please sign in to comment.