bip44

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

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

Go to latest
Published: Jan 9, 2019 License: MIT Imports: 7 Imported by: 0

README

Go-BIP44

Go Report Card

A Golang implementation of the BIP44 for Hierarchical Deterministic (HD) addresses. It currently only supports Bitcoin.

Released under the terms of the MIT LICENSE.

Should I use this in production?

This library is in very early stages. Please be aware that some bugs may exist.

Can I trust this code?

Do not trust. Verify.

Since this lib is in its early days, we recommend every user of this library audit and verify any underlying code for its validity and suitability. You can do so by using this tool.

Installation

go get -u github.com/edunuzzi/go-bip44 

Usage

New 24-word Mnemonic and Seed
// bitSize must be a multiple of 32
bitSize := 256
mnemonic, _ := bip44.NewMnemonic(bitSize)
seedBytes := m.NewSeed("my password")
Master key From Seed Hex - (Unstable yet)
xKey, _ := bip44.NewKeyFromSeedHex("your secret seed in hex format", bip44.MAINNET)
Master key From Seed bytes - (Unstable yet)
xKey, _ := bip44.NewKeyFromSeedBytes(seedBytes, bip44.MAINNET)
From base58-encoded Extended Key
ak, _ := bip44.NewAccountKeyFromXPubKey(xPubKey)

externalAddress, _ := accountKey.DeriveP2PKAddress(bip44.ExternalChangeType, 0, bip44.MAINNET)
internalAddress, _ := accountKey.DeriveP2PKAddress(bip44.InternalChangeType, 0, bip44.MAINNET)
Deriving P2PK addresses
coin account chain address path
Bitcoin first external first m / 44' / 0' / 0' / 0 / 0
xKey, _ := bip44.NewKeyFromSeedHex("your secret seed in hex format", bip44.MAINNET)
accountKey, _ := xKey.BIP44AccountKey(bip44.BitcoinCoinType, 0, true)

externalAddress, _ := accountKey.DeriveP2PKAddress(bip44.ExternalChangeType, 0, bip44.MAINNET)

coin account chain address path
Bitcoin first external second m / 44' / 0' / 0' / 0 / 1
xKey, _ := bip44.NewKeyFromSeedHex("your secret seed in hex format", bip44.MAINNET)
accountKey, _ := xKey.BIP44AccountKey(bip44.BitcoinCoinType, 0, true)

externalAddress, _ := accountKey.DeriveP2PKAddress(bip44.ExternalChangeType, 1, bip44.MAINNET)

coin account chain address path
Bitcoin Testnet second internal first m / 44' / 1' / 1' / 1 / 0
xKey, _ := bip44.NewKeyFromSeedHex("your secret seed in hex format", bip44.TESTNET3)
accountKey, _ := xKey.BIP44AccountKey(bip44.TestnetCoinType, 1, true)

externalAddress, _ := accountKey.DeriveP2PKAddress(bip44.InternalChangeType, 0, bip44.TESTNET3)

TODO

  • Report badge
  • Unit Tests
  • Create GoDoc
  • Stellar
  • Ethereum

Contribution

Please feel free to contribute with both suggestions and pull requests :D

Documentation

Index

Constants

View Source
const HardenedKeyZeroIndex = 0x80000000

Variables

This section is empty.

Functions

func EncodeURI

func EncodeURI(p URIParams) (string, error)

Types

type AccountKey

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

func NewAccountKeyFromXPubKey

func NewAccountKeyFromXPubKey(value string) (*AccountKey, error)

func (*AccountKey) DeriveP2PKAddress

func (k *AccountKey) DeriveP2PKAddress(changeType ChangeType, index uint32, network Network) (*Address, error)

type Address

type Address struct {
	HDStartPath HDStartPath `json:"hd_start_path"`
	HDEndPath   HDEndPath   `json:"hd_end_path"`
	Value       string      `json:"value"`
}

type ChangeType

type ChangeType uint32
const (
	ExternalChangeType ChangeType = 0
	InternalChangeType ChangeType = 1
)

type CoinType

type CoinType uint32
const (
	BitcoinCoinType CoinType = 0
	TestnetCoinType CoinType = 1
)

type ExtendedKey

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

func NewKeyFromSeedBytes

func NewKeyFromSeedBytes(seed []byte, net Network) (*ExtendedKey, error)

func NewKeyFromSeedHex

func NewKeyFromSeedHex(seed string, net Network) (*ExtendedKey, error)

func (*ExtendedKey) BIP44AccountKey

func (e *ExtendedKey) BIP44AccountKey(coinType CoinType, accIndex uint32, includePrivateKey bool) (*AccountKey, error)

type HDEndPath

type HDEndPath struct {
	ChangeIndex  uint32 `json:"change_index"`
	AddressIndex uint32 `json:"address_index"`
}

type HDStartPath

type HDStartPath struct {
	PurposeIndex  uint32 `json:"purpose_index"`
	CoinTypeIndex uint32 `json:"coin_type"`
	AccountIndex  uint32 `json:"account_index"`
}

type Mnemonic

type Mnemonic struct {
	Value string
}

func NewMnemonic

func NewMnemonic(bitSize int) (*Mnemonic, error)

bitSize must be a multiple of 32

func ParseMnemonic

func ParseMnemonic(mnemonic string) Mnemonic

func (Mnemonic) NewSeed

func (m Mnemonic) NewSeed(password string) ([]byte, error)

type Network

type Network int16
const (
	TESTNET3 Network = 0
	MAINNET  Network = 1
)

type Purpose

type Purpose uint32
const (
	BIP44Purpose Purpose = 44
)

type URIParams

type URIParams struct {
	Address string
	Amount  float64
	Label   string
	Message string
}

Jump to

Keyboard shortcuts

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