wallet

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedNetwork = errors.New("unsupported network")

Functions

This section is empty.

Types

type SegwitType

type SegwitType int
const (
	SEGWIT_TYPE_DISABLE SegwitType = iota
	SEGWIT_TYPE_P2WPKH
	SEGWIT_TYPE_P2WPKH_P2SH
	SEGWIT_TYPE_P2WSH
	SEGWIT_TYPE_P2WSH_P2SH
)

type Wallet

type Wallet struct {
	Mnemonic  string
	Password  string
	MasterKey *bip32.Key
}

func (*Wallet) NewAddress

func (w *Wallet) NewAddress(
	network networks.Network, path string, index uint32, segwitType SegwitType,
) (acc account.Account, err error)

NewAddress generates new address, public key and private key for specify path.

Example (Bitpay)
nw, err := networks.New("BCH - Bitcoin Cash")
if err != nil {
	log.Fatal(err)
}

acc, err := w.NewAddress(nw, "", 0, 0)
if err != nil {
	log.Fatal(err)
}

cashAddr := acc.Address
acc.ToBitcoinCash(&btc.MainNetParams, bch.ADDR_STYLE_BITPAY)
bitpayAddr := acc.Address

fmt.Printf("cash address: %s\n", cashAddr)
fmt.Printf("bitpay address: %s\n", bitpayAddr)
fmt.Printf("public key: %s\n", acc.PublicKeyText)
fmt.Printf("private key: %s\n", acc.PrivateKeyText)
Output:

cash address: bitcoincash:qz0r7yu7ns40xm0yda8dlftc445a5km57gnqthn900
bitpay address: CWtctzVwTbBJPCnyrV9W35JXPSdBJPJ7Gd
public key: 022bb58fb4028ff449e9af7c1e9da8c16577b0d54bcdd32f90e8684fc8cc8757e0
private key: L2ZeRGjztRuYRaKYPQJxSKMKivfig8UKZbsr6Kb98HykZCQbjjCw
Example (Legacy)
nw, err := networks.New("BTC - Bitcoin")
if err != nil {
	log.Fatal(err)
}

acc, err := w.NewAddress(nw, "", 0, wallet.SEGWIT_TYPE_DISABLE)
if err != nil {
	log.Fatal(err)
}

fmt.Printf("address: %s\n", acc.Address)
fmt.Printf("public key: %s\n", acc.PublicKeyText)
fmt.Printf("private key: %s\n", acc.PrivateKeyText)
Output:

address: 1NaFxCzxCJyYK6fP4kn936bSbpxvNTaBe6
public key: 02fb207bd0e7a3dff762a91a70d54fa65674b74aa6bc1e302deffc7bce5163643c
private key: L4t3tg2jB5XvDJ7s3vsprkHX6xdQUPcxkSeYyvAytLjqZhruRRaQ
Example (Segwit)
nw, err := networks.New("BTC - Bitcoin")
if err != nil {
	log.Fatal(err)
}

acc, err := w.NewAddress(nw, "", 0, wallet.SEGWIT_TYPE_P2WSH)
if err != nil {
	log.Fatal(err)
}

fmt.Printf("address: %s\n", acc.Address)
fmt.Printf("public key: %s\n", acc.PublicKeyText)
fmt.Printf("private key: %s\n", acc.PrivateKeyText)
Output:

address: bc1qpypdshwmyydmnc0hapgam2alj7yms7z6m35fqr27cfzkme3vucnq9v9t08
public key: 02fb207bd0e7a3dff762a91a70d54fa65674b74aa6bc1e302deffc7bce5163643c
private key: L4t3tg2jB5XvDJ7s3vsprkHX6xdQUPcxkSeYyvAytLjqZhruRRaQ

Jump to

Keyboard shortcuts

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