hd

package
v0.46.4 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package hd provides support for hierarchical deterministic wallets generation and derivation.

The user must understand the overall concept of the BIP 32 and the BIP 44 specs:

https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki

In combination with the bip39 package in go-crypto this package provides the functionality for deriving keys using a BIP 44 HD path, or, more general, by passing a BIP 32 path.

In particular, this package (together with bip39) provides all necessary functionality to derive keys from mnemonics generated during the cosmos fundraiser.

Index

Constants

View Source
const (
	// MultiType implies that a pubkey is a multisignature
	MultiType = PubKeyType("multi")
	// Secp256k1Type uses the Bitcoin secp256k1 ECDSA parameters.
	Secp256k1Type = PubKeyType("secp256k1")
	// Ed25519Type represents the Ed25519Type signature system.
	// It is currently not supported for end-user keys (wallets/ledgers).
	Ed25519Type = PubKeyType("ed25519")
	// Sr25519Type represents the Sr25519Type signature system.
	Sr25519Type = PubKeyType("sr25519")
)

Variables

View Source
var (
	ErrInvalidLengthHd        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowHd          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupHd = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	// Secp256k1 uses the Bitcoin secp256k1 ECDSA parameters.
	Secp256k1 = secp256k1Algo{}
)

Functions

func ComputeMastersFromSeed

func ComputeMastersFromSeed(seed []byte) (secret [32]byte, chainCode [32]byte)

ComputeMastersFromSeed returns the master secret key's, and chain code.

func DerivePrivateKeyForPath

func DerivePrivateKeyForPath(privKeyBytes, chainCode [32]byte, path string) ([]byte, error)

DerivePrivateKeyForPath derives the private key by following the BIP 32/44 path from privKeyBytes, using the given chainCode.

Types

type BIP44Params

type BIP44Params struct {
	// purpose is a constant set to 44' (or 0x8000002C) following the BIP43 recommendation
	Purpose uint32 `protobuf:"varint,1,opt,name=purpose,proto3" json:"purpose,omitempty"`
	// coin_type is a constant that improves privacy
	CoinType uint32 `protobuf:"varint,2,opt,name=coin_type,json=coinType,proto3" json:"coin_type,omitempty"`
	// account splits the key space into independent user identities
	Account uint32 `protobuf:"varint,3,opt,name=account,proto3" json:"account,omitempty"`
	// change is a constant used for public derivation. Constant 0 is used for external chain and constant 1 for internal
	// chain.
	Change bool `protobuf:"varint,4,opt,name=change,proto3" json:"change,omitempty"`
	// address_index is used as child index in BIP32 derivation
	AddressIndex uint32 `protobuf:"varint,5,opt,name=address_index,json=addressIndex,proto3" json:"address_index,omitempty"`
}

BIP44Params is used as path field in ledger item in Record.

func CreateHDPath

func CreateHDPath(coinType, account, index uint32) *BIP44Params

CreateHDPath returns BIP 44 object from account and index parameters.

func NewFundraiserParams

func NewFundraiserParams(account, coinType, addressIdx uint32) *BIP44Params

NewFundraiserParams creates a BIP 44 parameter object from the params: m / 44' / coinType' / account' / 0 / address_index The fixed parameters (purpose', coin_type', and change) are determined by what was used in the fundraiser.

func NewParams

func NewParams(purpose, coinType, account uint32, change bool, addressIdx uint32) *BIP44Params

NewParams creates a BIP 44 parameter object from the params: m / purpose' / coinType' / account' / change / addressIndex

func NewParamsFromPath

func NewParamsFromPath(path string) (*BIP44Params, error)

NewParamsFromPath parses the BIP44 path and unmarshals it into a Bip44Params. It supports both absolute and relative paths.

func (BIP44Params) DerivationPath

func (p BIP44Params) DerivationPath() []uint32

DerivationPath returns the BIP44 fields as an array.

func (*BIP44Params) Descriptor

func (*BIP44Params) Descriptor() ([]byte, []int)

func (*BIP44Params) Marshal

func (m *BIP44Params) Marshal() (dAtA []byte, err error)

func (*BIP44Params) MarshalTo

func (m *BIP44Params) MarshalTo(dAtA []byte) (int, error)

func (*BIP44Params) MarshalToSizedBuffer

func (m *BIP44Params) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*BIP44Params) ProtoMessage

func (*BIP44Params) ProtoMessage()

func (*BIP44Params) Reset

func (m *BIP44Params) Reset()

func (*BIP44Params) Size

func (m *BIP44Params) Size() (n int)

func (BIP44Params) String

func (p BIP44Params) String() string

String returns the full absolute HD path of the BIP44 (https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) params: m / purpose' / coin_type' / account' / change / address_index

func (*BIP44Params) Unmarshal

func (m *BIP44Params) Unmarshal(dAtA []byte) error

func (*BIP44Params) XXX_DiscardUnknown

func (m *BIP44Params) XXX_DiscardUnknown()

func (*BIP44Params) XXX_Marshal

func (m *BIP44Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BIP44Params) XXX_Merge

func (m *BIP44Params) XXX_Merge(src proto.Message)

func (*BIP44Params) XXX_Size

func (m *BIP44Params) XXX_Size() int

func (*BIP44Params) XXX_Unmarshal

func (m *BIP44Params) XXX_Unmarshal(b []byte) error

type DeriveFn

type DeriveFn func(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)

type GenerateFn

type GenerateFn func(bz []byte) types.PrivKey

type PubKeyType

type PubKeyType string

PubKeyType defines an algorithm to derive key-pairs which can be used for cryptographic signing.

type WalletGenerator

type WalletGenerator interface {
	Derive(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)
	Generate(bz []byte) types.PrivKey
}

Jump to

Keyboard shortcuts

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