| 1 | package Bitcoin::Crypto::Key::ExtPublic; | ||||||||||
| 2 | 13 | $Bitcoin::Crypto::Key::ExtPublic::VERSION = '4.005'; | |||||||||
| 3 | 13 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 13 | ▶ | use Mooish::Base -standard; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 13 | ▶ | use Crypt::Mac::HMAC qw(hmac); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 13 | ▶ | use Types::Common -sigs; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 13 | ▶ | use Bitcoin::Crypto::Constants; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 13 | ▶ | use Bitcoin::Crypto::Helpers qw(ensure_length ecc); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 13 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 13 | ▶ | use Bitcoin::Crypto::BIP44; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 13 | extends qw(Bitcoin::Crypto::Key::ExtBase); | |||||||||
| 16 | |||||||||||
| 17 | 821 | ▶ | sub _is_private { 0 } | ||||||||
|
Subroutine
_is_private: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | sub derive_key_bip44 | ||||||||||
| 20 | 5 | ▶ | { | ||||||||
|
Subroutine
derive_key_bip44: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | 5 | my ($self, %data) = @_; | |||||||||
| 22 | 5 | my $path = Bitcoin::Crypto::BIP44->new( | |||||||||
| 23 | %data, | ||||||||||
| 24 | coin_type => $self, | ||||||||||
| 25 | public => 1, | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 5 | return $self->derive_key($path); | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | sub _derive_key_partial | ||||||||||
| 32 | 25 | ▶ | { | ||||||||
|
Subroutine
_derive_key_partial: called CC=2 SCAR=6.9
| |||||||||||
| 33 | 25 | my ($self, $child_num, $hardened) = @_; | |||||||||
| 34 | |||||||||||
| 35 | 25 | ▶ | Bitcoin::Crypto::Exception::KeyDerive->raise( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 'cannot derive hardened key from public key' | ||||||||||
| 37 | ) if $hardened; | ||||||||||
| 38 | |||||||||||
| 39 | # public key data - SEC compressed form | ||||||||||
| 40 | 25 | my $key = $self->raw_key('public_compressed'); | |||||||||
| 41 | |||||||||||
| 42 | # key + child number - 4 bytes | ||||||||||
| 43 | 25 | my $hmac_data = $key . ensure_length pack('N', $child_num), 4; | |||||||||
| 44 | |||||||||||
| 45 | 25 | my $data = hmac('SHA512', $self->chain_code, $hmac_data); | |||||||||
| 46 | 25 | my $tweak = substr $data, 0, 32; | |||||||||
| 47 | 25 | my $chain_code = substr $data, 32, 32; | |||||||||
| 48 | |||||||||||
| 49 | Bitcoin::Crypto::Exception::KeyDerive->trap_into( | ||||||||||
| 50 | 25 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 25 | $key = ecc->add_public_key($key, $tweak); | |||||||||
| 52 | }, | ||||||||||
| 53 | 25 | "key $child_num in sequence was found invalid" | |||||||||
| 54 | ); | ||||||||||
| 55 | |||||||||||
| 56 | 25 | return $self->new( | |||||||||
| 57 | _key_instance => $key, | ||||||||||
| 58 | chain_code => $chain_code, | ||||||||||
| 59 | child_number => $child_num, | ||||||||||
| 60 | parent_fingerprint => $self->get_fingerprint, | ||||||||||
| 61 | depth => $self->depth + 1, | ||||||||||
| 62 | ); | ||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 13 | 1; | |||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||