bip32

package module
v0.0.0-...-107dfd8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package bip32 implements Bitcoin BIP32 deterministic wallet key derivation.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDerivationIndex = fmt.Errorf("Cannot derive child of public key with index higher than 0x%x", constants.Bip32Hardened)

ErrInvalidDerivationIndex is returned by DerivePublicChild if the given index is above the hardening threshold.

View Source
var ErrInvalidExtendedKey = errors.New("Failed to deserialize extended key - Invalid format")

ErrInvalidExtendedKey is returned by Deserialize if it is passed a base58 key which fails to decode correctly.

View Source
var ErrInvalidSeed = errors.New("Invalid seed; bit size must be between 128 - 512 bits, and a multiple of 32")

ErrInvalidSeed is returned by GenerateMasterKey if the given seed is not valid.

Functions

func DerivePrivateChild

func DerivePrivateChild(parentPrivateKey, chainCode []byte, childIndices ...uint32) ([]byte, []byte)

DerivePrivateChild recursively derives a child private key and chain code of a given bip32 path from a parent private key and chain code.

func DerivePublicChild

func DerivePublicChild(parentPublicKey, chainCode []byte, childIndices ...uint32) ([]byte, []byte, error)

DerivePublicChild derives a child public key and chain code of a given bip32 path from a parent public key and chain code. Returns ErrInvalidDerivationIndex if any child index is greater than or equal to constants.Bip32Hardened.

The parentPublicKey parameter can be compressed or uncompressed, but this function always returns compressed public keys.

func Deserialize

func Deserialize(bs58Key string) (key, chainCode, parentFingerprint []byte, depth byte, index, version uint32, err error)

Deserialize parses a base58-check encoded extended key (public or private) and returns the key, chain code, parent fingerprint, depth from the master key, child index, version number prefix, and any error encountered during deserialization. Returns ErrInvalidExtendedKey if the key is not valid.

func ExampleDerivePrivateChild

func ExampleDerivePrivateChild()

func ExampleDerivePublicChild

func ExampleDerivePublicChild()

func GenerateMasterKey

func GenerateMasterKey(seed []byte) (masterKey, chainCode []byte, err error)

GenerateMasterKey generates a master key and chain code from the given seed bytes. Returns ErrInvalidSeed if the seed is not valid.

func KeyFingerprint

func KeyFingerprint(publicKey []byte) ([]byte, error)

KeyFingerprint returns the first 4 bytes of the Hash160 of the given public key. This is used as the fingerprint for serialized extended keys. Note that publicKey can be in compressed or uncompressed form, but will be converted to compressed form before hashing. Returns an error if the public key is not valid.

func SerializePrivate

func SerializePrivate(privateKey, chainCode, parentFingerprint []byte, depth byte, index, version uint32) string

SerializePrivate serializes an extended private key to base58-check encoded string.

func SerializePublic

func SerializePublic(publicKey, chainCode, parentFingerprint []byte, depth byte, index, version uint32) string

SerializePublic serializes an extended public key to a base58-check encoded string.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL