hdkey

package module
v0.0.0-...-aee6f80 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2016 License: MIT Imports: 7 Imported by: 0

README

hdkey

Serialized Hierarchical Deterministic Keys

Documentation

Index

Constants

View Source
const (
	// Minimum seed size to create master key.
	MinSeedSize = 16

	// Recommended seed size to create master key.
	RecommendedSeedSize = 32

	// Maximum seed size to create master key.
	MaxSeedSize = 64
)
View Source
const (

	// Total size of an HDKey in bytes.
	HDKeySize = versionSize +
		depthSize +
		fingerprintSize +
		childNumberSize +
		chainCodeSize +
		childKeySize // 76 bytes

)
View Source
const HardenedKeyStart = 0x80000000

Start of hardened key indexes, 2^31

Variables

View Source
var (
	// ErrDeriveHardenedFromPublic indicates that an attempt was made to derive a
	// hardened key from a public key.
	ErrDeriveHardenedFromPublic = errors.New("Cannot derive hardened key from " +
		"public key")

	// ErrInvalidKeyLength indicates an attempt to decode an HDKey that is not
	// HDKeySize bytes in length.
	ErrInvalidKeyLength = errors.New("Invalid key length")

	// ErrInvalidSeedLength indicates that the provided seed length is less than
	// MinSeedSize or greater that MaxSeedSize.
	ErrInvalidSeedLength = fmt.Errorf("Seed length must be between %d and %d "+
		"bytes", MinSeedSize, MaxSeedSize)

	// ErrNotPrivHDKey indicates that an attempt was made to access the secret key
	// of a public HD key, which is not possible.
	ErrNotPrivHDKey = errors.New("Cannot get secret key from public key")

	// ErrUnknownVersionMapping indicates that the provided VersionMap does not
	// provide a mapping from the given private version to its public version.
	ErrUnknownVersionMapping = errors.New("Unknown version mapping")

	// ErrUnusableSeed indicates that the provided seed produces a secret key
	// greater than the order of secp256k1 or it's associated public key is the
	// point at infinity.
	ErrUnusableSeed = errors.New("Seed produces invalid key")
)

Functions

func GenerateSeed

func GenerateSeed(n uint8) ([]byte, error)

GenerateSeed produces a cryptographically secure seed consisting of n bytes.

Types

type HDKey

type HDKey [HDKeySize]byte

HDKey stores an extended key's version, depth, child number, chain code, parent fingerprint, and derived public or private key.

func New

func New(s string) (*HDKey, error)

NewKeyFromString decodes a hex encoded string, verifies the included checksum, and checks that the public key is on the secp256k1 curve.

func NewMaster

func NewMaster(seed, key []byte, version uint16) (*HDKey, error)

NewMasterHDKey computes the root HD key from the given seed, key and private version.

func (*HDKey) Child

func (k *HDKey) Child(i uint32) (*HDKey, error)

Child computes the descendant of an HDKey at the specified child number.

func (*HDKey) CompressedPublicKey

func (k *HDKey) CompressedPublicKey() *eckey.CompressedPublicKey

CompressedPublicKey returns the associated compressed public key of an HDKey. If the HDKey corresponds to a public key, the derived key is copied and returned. Otherwise, the public key is computed from the secret key and subsequently compressed.

func (*HDKey) IsPrivate

func (k *HDKey) IsPrivate() bool

IsPrivate returns a boolean denoting whether the HDKey belongs to private key.

func (*HDKey) Neuter

func (k *HDKey) Neuter(vMap VersionMap) (*HDKey, error)

Neuter converts a private HDKey into a public HDKey, effectively removing the signing capabilities.

func (*HDKey) PublicKey

func (k *HDKey) PublicKey() *eckey.PublicKey

PublicKey returns the associated public key of an HDKey. If the HDKey corresponds to a secret key, the public key is computed and returned. Otherwise, if the HDKey corresponds to a compressed public key, the public key is decompressed and returned. No error handling is during these operations, as it is assumes the HDKey is uncorrupted.

func (*HDKey) SecretKey

func (k *HDKey) SecretKey() (*eckey.SecretKey, error)

SecretKey returns the secret key belonging to an HDKey. This method returns an error if the HDKey corresponds to a compressed public key, since the secret key cannot be recovered.

func (*HDKey) String

func (k *HDKey) String() string

String converts an HDKey into a checksummed, hex encoded string.

func (*HDKey) Zero

func (k *HDKey) Zero()

Zero securely clears the contents of an HDKey from memory.

type VersionMap

type VersionMap map[uint16]uint16

VersionMap stores a mapping from private to public magic version constants for multiple networks.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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