hd

package module
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: BSD-2-Clause Imports: 9 Imported by: 2

README

hd

Hierarchical deterministic wallet for Ethereum.

GoDoc Go Report Card

Usage

This package provides hierarchical deterministic wallet ("HD wallet") functionality according to BIP39, BIP32 and BIP44.

Once the HdWallet is initialized, you can easily generate any address by requesting the wallet number, either Change or External and the id of the address (a number between 1 and 2e32-1). See test file for same code.

For a full description of what a HD wallet is, please read here.

Configuration

The initialization of the wallet requires a 64-byte seed. It is recommended to generate seeds using BIP39 out of a 24 word mnemonic and passphrase which are easy to remember. You should always keep private keys and seed safe.

Documentation

Overview

Package hd provides hierarchical deterministic wallet (HD wallet) functionality according to BIP39, BIP32 and BIP44. The initialization of the wallet requires a 64-byte seed. It is recommended to generate seeds using BIP39 out of a 24 word mnemonic and passphrase which are easy to remember. Once the HdWallet is initialized, you can easily generate any address. For a full description of what a HD wallet is, please read: https://en.bitcoinwiki.org/wiki/Deterministic_wallet

Index

Constants

View Source
const (
	// External addresses are used for inputs or deposits.
	External uint8 = 0x00
	// Change addresses are used for internal use.
	Change uint8 = 0x01
)

Variables

View Source
var (
	// ErrInternal wraps errors reported by deps.
	ErrInternal error = errors.New("hd internal error")
	// ErrInvalidSeedLen will be reported when setting a wrong length (recommended seed length is 64-byte).
	ErrInvalidSeedLen error = errors.New("hd: length of seed is invalid")
	// ErrUnusableSeed will be reported if the seed cannot be used.
	ErrUnusableSeed error = errors.New("hd: the master key cannot be used")
)

Functions

This section is empty.

Types

type HdWallet

type HdWallet struct {
	*hdkeychain.ExtendedKey // HD wallet branch from which account/addresses are generated
}

HdWallet is a composed type.

func Init

func Init(seed []byte) (*HdWallet, error)

Init initializes the HD wallet for Ethereum for the given seed.

func (*HdWallet) Address

func (w *HdWallet) Address(wallet uint32, flg uint8, addrNum uint32,
) (addr, key []byte, prv ecdsa.PrivateKey, err error)

Address generates an address for 'wallet', flg should be either external or change and address number.

Jump to

Keyboard shortcuts

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