hdkeychain

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MinSeedBytes is the minimum number of bytes allowed for a seed to
	// a master node.
	MinSeedBytes = 16 // 128 bits

	// MaxSeedBytes is the maximum number of bytes allowed for a seed to
	// a master node.
	MaxSeedBytes = 64 // 512 bits
)

Variables

View Source
var (
	// ErrInvalidSeedLen describes an error in which the provided seed or
	// seed length is not in the allowed range.
	ErrInvalidSeedLen = fmt.Errorf("seed length must be between %d and %d "+
		"bits", MinSeedBytes*8, MaxSeedBytes*8)

	// ErrInvalidKeyData describes an error in which the provided key is
	// not valid.
	ErrInvalidKeyData = errors.New("key data is invalid")

	// ErrInvalidHRP describes an error in which the HRP is not valid.
	ErrInvalidHRP = errors.New("HRP is invalid")

	// ErrNonHardenedPath is returned when a non-hardened derivation path is used,
	// which is not supported by ed25519.
	ErrNonHardenedPath = errors.New("non-hardened derivation not supported")
)

Functions

func GenerateSeed

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

GenerateSeed returns a cryptographically secure random seed that can be used as the input for the NewMaster function to generate a new master node.

The length is in bytes and it must be between 16 and 64 (128 to 512 bits). The recommended length is 32 (256 bits) as defined by the RecommendedSeedLen constant.

Types

type ExtendedKey

type ExtendedKey struct {
	// contains filtered or unexported fields
}

ExtendedKey houses all the information needed to support a hierarchical deterministic extended key.

func NewKeyFromString

func NewKeyFromString(str string) (*ExtendedKey, error)

NewKeyFromString returns a new extended key instance from a bech32-encoded string.

func NewMaster

func NewMaster(seed []byte) (*ExtendedKey, error)

NewMaster creates a new master node for use in creating a hierarchical deterministic key chain. The seed must be between 128 and 512 bits and should be generated by a cryptographically secure random generation source.

func (*ExtendedKey) Derive

func (k *ExtendedKey) Derive(index uint32) (*ExtendedKey, error)

Derive returns a derived child extended key at the given index.

For ed25519 and curve25519 the private keys are no longer multipliers for the group generator; instead the hash of the private key is the multiplier. For this reason, our scheme for ed25519 and curve25519 does not support public key derivation and uses the produced hashes directly as private keys.

func (*ExtendedKey) DerivePath

func (k *ExtendedKey) DerivePath(path []uint32) (*ExtendedKey, error)

DerivePath returns a derived child extended key from this master key at the given path.

func (*ExtendedKey) Path

func (k *ExtendedKey) Path() []uint32

Path returns the path of derived key.

Path values are always between 2^31 and 2^32-1 as they are hardened keys.

func (*ExtendedKey) RawPrivateKey

func (k *ExtendedKey) RawPrivateKey() []byte

RawPrivateKey returns the raw bytes of the private key.

func (*ExtendedKey) RawPublicKey

func (k *ExtendedKey) RawPublicKey() []byte

RawPublicKey returns the raw bytes of the public key.

func (*ExtendedKey) String

func (k *ExtendedKey) String() string

String returns the extended key as a bech32-encoded string.

Jump to

Keyboard shortcuts

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