bip84

package module
v0.0.0-...-5c957f6 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 10 Imported by: 0

README

go-bip84

Godoc

A simple and easy to use bitcoin bip84 library (https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki)

  • Derive zpub adresses from mnemonics and seeds
  • Derive zprv adresses from mnemonics and seeds
  • Derive private keys (WIF) from mnemonics, seeds and zprv addresses
  • Derive bech32 encoded addresses from mnemonics, seeds and zpub addresses

Installation

$ go get github.com/KaiWitt/go-bip84

Example

package main

import (
	"fmt"

	"github.com/KaiWitt/go-bip84"
)

func main() {
	zpub := "zpub6myffWeUbYq2HG9oJyQj7D4Ph4KvuKV7WM9QPHZc45zkKXZ4UCQjgATbQxMurxwhZUVU8EbLa2amHunRR5FoDRkQhmvZnh6cBWBo8cFW47y"
	firstReceiveAddress, _ := bip84.GetAddressFromZPubKeyString(zpub, true, 0)
	fmt.Println(firstReceiveAddress)
	// Output: bc1qu7ux5vp2e0t2wghkgq6p0kt8047xl5ev64vhfv

	mnemonic := "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
	sixthChangeAddressOf3rdAccount, _ := bip84.GetAddressFromMnemonic(mnemonic, "", 2, false, 5)
	fmt.Println(sixthChangeAddressOf3rdAccount)
	// Output: bc1qtg5eghwfymf7ayt4pyvwrh3ezegg94tvslwzm5
}

Useful Resources

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertMnemonicToSeed

func ConvertMnemonicToSeed(mnemonic, password string) ([]byte, error)

ConvertMnemonicToSeed converts a mnemonic to a bip39 seed. If the mnemonic is unvalid an error will be returned. Password will be ignored if string is empty "".

func DeriveChangeAndIndex

func DeriveChangeAndIndex(extended *hdkeychain.ExtendedKey, isReceive bool, index uint32) (*hdkeychain.ExtendedKey, error)

DeriveChangeAndIndex derives the account type and an index from an extended key. If isReceive is true the account type is 0, else it's 1.

func DeriveHardenedKeys

func DeriveHardenedKeys(seed []byte, account uint32) (*hdkeychain.ExtendedKey, error)

DeriveHardenedKeys derives hardened purpose, coin and account keys from a seed. The purpose is 84 (bip-0084) and coin is 0.

func EncodeBech32

func EncodeBech32(pubKey *btcec.PublicKey) (*btcutil.AddressWitnessPubKeyHash, error)

EncodeBech32 encodes a public key to a bech32 address (P2WPKH)

func Generate12WordMnemonic

func Generate12WordMnemonic() (string, error)

Generate12WordMnemonic generates a new 12 word mnemonic which can be used to derive addresses and private keys

func Generate24WordMnemonic

func Generate24WordMnemonic() (string, error)

Generate24WordMnemonic generates a new 24 word mnemonic which can be used to derive addresses and private keys

func GenerateMnemonicFromEntropy

func GenerateMnemonicFromEntropy(entropy []byte) (string, error)

GenerateMnemonicFromEntropy generates a new mnemonic which can be used to derive addresses and private keys

func GenerateSeed

func GenerateSeed() ([]byte, error)

GenerateSeed generates a new seed which can be used to derive addresses and private keys

func GetAddressFromMnemonic

func GetAddressFromMnemonic(mnemonic, password string, account uint32, isReceive bool, index uint32) (*btcutil.AddressWitnessPubKeyHash, error)

GetAddressFromMnemonic derives an address from a mnemonic by account, account type and index. Password for mnemonic will be ignored if string is empty "".

func GetAddressFromSeed

func GetAddressFromSeed(seed []byte, account uint32, isReceive bool, index uint32) (*btcutil.AddressWitnessPubKeyHash, error)

GetAddressFromSeed derives an address from a seed by account, account type and index.

func GetAddressFromZPubKey

func GetAddressFromZPubKey(zpub *hdkeychain.ExtendedKey, isReceive bool, index uint32) (*btcutil.AddressWitnessPubKeyHash, error)

GetAddressFromZPubKey derives an address from an extended public key by account type and index.

func GetAddressFromZPubKeyString

func GetAddressFromZPubKeyString(zpub string, isReceive bool, index uint32) (*btcutil.AddressWitnessPubKeyHash, error)

GetAddressFromZPubKeyString parses an extended public key and derives an address from it by account type and index.

func GetWifFromMnemonic

func GetWifFromMnemonic(mnemonic, password string, account uint32, isReceive bool, index uint32) (*btcutil.WIF, error)

GetWifFromMnemonic derives a private key as WIF (wallet import format) from a mnemonic by account, account type and index. Password for mnemonic will be ignored if string is empty "".

func GetWifFromSeed

func GetWifFromSeed(seed []byte, account uint32, isReceive bool, index uint32) (*btcutil.WIF, error)

GetWifFromSeed derives a private key as WIF (wallet import format) from a seed by account, account type and index.

func GetWifFromZPrivKey

func GetWifFromZPrivKey(zpriv *hdkeychain.ExtendedKey, isReceive bool, index uint32) (*btcutil.WIF, error)

GetWifFromZPrivKey derives a private key as WIF (wallet import format) from an extended private key by account type and index.

func GetWifFromZPrivKeyString

func GetWifFromZPrivKeyString(zpriv string, isReceive bool, index uint32) (*btcutil.WIF, error)

GetWifFromZPrivKeyString parses an extended private key and derives a private key as WIF (wallet import format) from it by account type and index.

func GetZPrivKeyFromMnemonic

func GetZPrivKeyFromMnemonic(mnemonic, password string, account uint32) (*hdkeychain.ExtendedKey, error)

GetZPrivKeyFromMnemonic derives an extended private key from a mnemonic by account. Password for mnemonic will be ignored if string is empty "".

func GetZPrivKeyFromSeed

func GetZPrivKeyFromSeed(seed []byte, account uint32) (*hdkeychain.ExtendedKey, error)

GetZPrivKeyFromSeed derives an extended private key from a seed by account.

func GetZPubKeyFromMnemonic

func GetZPubKeyFromMnemonic(mnemonic, password string, account uint32) (*hdkeychain.ExtendedKey, error)

GetZPubKeyFromMnemonic derives an extended public key from a mnemonic by account. Password for mnemonic will be ignored if string is empty "".

func GetZPubKeyFromSeed

func GetZPubKeyFromSeed(seed []byte, account uint32) (*hdkeychain.ExtendedKey, error)

GetZPubKeyFromSeed derives an extended public key from a seed by account.

Types

This section is empty.

Jump to

Keyboard shortcuts

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