cosmos-sdk: Index | Files

package hd

import ""

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:

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.


Package Files

algo.go doc.go hdpath.go


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")


var (
    // Secp256k1 uses the Bitcoin secp256k1 ECDSA parameters.
    Secp256k1 = secp256k1Algo{}

func ComputeMastersFromSeed Uses

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

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

func DerivePrivateKeyForPath Uses

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.

type BIP44Params Uses

type BIP44Params struct {
    Purpose      uint32 `json:"purpose"`
    CoinType     uint32 `json:"coinType"`
    Account      uint32 `json:"account"`
    Change       bool   `json:"change"`
    AddressIndex uint32 `json:"addressIndex"`

BIP44Params wraps BIP 44 params (5 level BIP 32 path). To receive a canonical string representation ala m / purpose' / coinType' / account' / change / addressIndex call String() on a BIP44Params instance.

func CreateHDPath Uses

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

CreateHDPath returns BIP 44 object from account and index parameters.

func NewFundraiserParams Uses

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 Uses

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 Uses

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 Uses

func (p BIP44Params) DerivationPath() []uint32

DerivationPath returns the BIP44 fields as an array.

func (BIP44Params) String Uses

func (p BIP44Params) String() string

String returns the full absolute HD path of the BIP44 ( params: m / purpose' / coin_type' / account' / change / address_index

type DeriveFn Uses

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

type GenerateFn Uses

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

type PubKeyType Uses

type PubKeyType string

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

type WalletGenerator Uses

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

Package hd imports 11 packages (graph) and is imported by 10 packages. Updated 2020-12-01. Refresh now. Tools for package owners.