wallet

package
v0.0.0-...-96919c3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SymbolEth = "ETH"
	SymbolBtc = "BTC"
	SymbolTrx = "TRX"

	BtcChainMainNet  = int(wire.MainNet)
	BtcChainTestNet3 = int(wire.TestNet3)
	BtcChainRegtest  = int(wire.TestNet)
	BtcChainSimNet   = int(wire.SimNet)

	ChainMainNet      = 1 // for ETH
	ChainRopsten      = 3 // for ETH
	ChainRinkeby      = 4 // for ETH
	ChainGoerli       = 5 // for ETH
	ChainSepolia      = 11155111
	ChainBsc          = 56    // for Binance Smart Chain Mainnet
	ChainBscTestnet   = 97    // for Binance Smart Chain Testnet
	ChainMatic        = 137   // for Polygon Matic Mainnet
	ChainMaticTestnet = 80001 // for Polygon Matic Testnet
	ChainPrivate      = 1337  // for ETH

	SegWitNone   SegWitType = 0
	SegWitScript SegWitType = 1
	SegWitNative SegWitType = 2

	ChangeTypeExternal = 0
	ChangeTypeInternal = 1 // Usually used for change, not visible to the outside world

	SatoshiPerBitcoin = 1e8
	SunPerTrx         = 1e6
	GweiPerEther      = 1e9
	WeiPerGwei        = 1e9
	WeiPerEther       = 1e18

	EtherTransferGas = 21000

	TokenShowDecimals = 9
)

Variables

View Source
var (
	BscChainConfig          = &params.ChainConfig{}
	BscTestnetChainConfig   = &params.ChainConfig{}
	MaticChainConfig        = &params.ChainConfig{}
	MaticTestnetChainConfig = &params.ChainConfig{}
)
View Source
var ErrAddressNotMatch = errors.New("address not match")
View Source
var IsFixIssue172 = false

Functions

func DerivePrivateKeyByPath

func DerivePrivateKeyByPath(masterKey *hdkeychain.ExtendedKey, path string, fixIssue172 bool) (*btcec.PrivateKey, error)

func DerivePublicKey

func DerivePublicKey(privateKey *ecdsa.PrivateKey) (*ecdsa.PublicKey, error)

func EntropyFromMnemonic

func EntropyFromMnemonic(mnemonic string) (entropy []byte, err error)

func FormatBtc

func FormatBtc(amount int64) string

func FormatEth

func FormatEth(amount int64) string

func FormatFloat

func FormatFloat(f float64, precision int) string

func GetBtcChainParams

func GetBtcChainParams(chainId int) (*chaincfg.Params, error)

func GetEthChainParams

func GetEthChainParams(chainId int) (*params.ChainConfig, error)

func MakeBip44Path

func MakeBip44Path(symbol string, chainId int, accountIndex, changeType, index int) (string, error)

func MakeBip49Path

func MakeBip49Path(symbol string, chainId int, accountIndex, changeType, index int) (string, error)

func MakeBip84Path

func MakeBip84Path(symbol string, chainId int, accountIndex, changeType, index int) (string, error)

func MakeBipXPath

func MakeBipXPath(bipType int, symbol string, chainId int, accountIndex, changeType, index int) (string, error)

func NewEntropy

func NewEntropy(bits int) (entropy []byte, err error)

func NewMnemonic

func NewMnemonic(bits int) (mnemonic string, err error)

func NewMnemonicByEntropy

func NewMnemonicByEntropy(entropy []byte) (mnemonic string, err error)

func NewSeedFromMnemonic

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

Types

type BtcWallet

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

func NewBtcWallet

func NewBtcWallet(privateKey string, chainId int, segWitType SegWitType) (*BtcWallet, error)

func NewBtcWalletByPath

func NewBtcWalletByPath(path string, seed []byte, chainId int, segWitType SegWitType) (*BtcWallet, error)

func (*BtcWallet) ChainId

func (w *BtcWallet) ChainId() int

func (*BtcWallet) ChainParams

func (w *BtcWallet) ChainParams() *chaincfg.Params

func (*BtcWallet) DeriveAddress

func (w *BtcWallet) DeriveAddress() string

func (*BtcWallet) DeriveNativeAddress

func (w *BtcWallet) DeriveNativeAddress() btcutil.Address

func (*BtcWallet) DeriveNativePrivateKey

func (w *BtcWallet) DeriveNativePrivateKey() *btcec.PrivateKey

func (*BtcWallet) DerivePrivateKey

func (w *BtcWallet) DerivePrivateKey() string

func (*BtcWallet) DerivePublicKey

func (w *BtcWallet) DerivePublicKey() string

func (*BtcWallet) GetKey

func (w *BtcWallet) GetKey(addr btcutil.Address) (*btcec.PrivateKey, bool, error)

txauthor.SecretsSource

func (*BtcWallet) GetScript

func (w *BtcWallet) GetScript(addr btcutil.Address) ([]byte, error)

func (*BtcWallet) Symbol

func (w *BtcWallet) Symbol() string

type EthWallet

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

func NewEthWallet

func NewEthWallet(privateKey string, chainId int) (*EthWallet, error)

func NewEthWalletByPath

func NewEthWalletByPath(path string, seed []byte, chainId int) (*EthWallet, error)

func (*EthWallet) ChainId

func (w *EthWallet) ChainId() int

func (*EthWallet) ChainParams

func (w *EthWallet) ChainParams() *params.ChainConfig

func (*EthWallet) DeriveAddress

func (w *EthWallet) DeriveAddress() string

func (*EthWallet) DeriveNativeAddress

func (w *EthWallet) DeriveNativeAddress() common.Address

func (*EthWallet) DeriveNativePrivateKey

func (w *EthWallet) DeriveNativePrivateKey() *ecdsa.PrivateKey

func (*EthWallet) DerivePrivateKey

func (w *EthWallet) DerivePrivateKey() string

func (*EthWallet) DerivePublicKey

func (w *EthWallet) DerivePublicKey() string

func (*EthWallet) Symbol

func (w *EthWallet) Symbol() string

type HDWallet

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

func NewHDWallet

func NewHDWallet(mnemonic, password string, btcChainId int, ethChainId int) (*HDWallet, error)

func (*HDWallet) NewNativeSegWitWallet

func (this *HDWallet) NewNativeSegWitWallet(accountIndex, changeType, index int) (Wallet, error)

func (*HDWallet) NewSegWitWallet

func (this *HDWallet) NewSegWitWallet(accountIndex, changeType, index int) (Wallet, error)

func (*HDWallet) NewWallet

func (this *HDWallet) NewWallet(symbol string, accountIndex, changeType, index int) (Wallet, error)

func (*HDWallet) NewWalletByPath

func (this *HDWallet) NewWalletByPath(symbol string, path string, segWitType SegWitType) (Wallet, error)

type SegWitType

type SegWitType int

type TrxWallet

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

func NewTrxWallet

func NewTrxWallet(privateKey string) (*TrxWallet, error)

func NewTrxWalletByPath

func NewTrxWalletByPath(path string, seed []byte) (*TrxWallet, error)

func (*TrxWallet) ChainId

func (w *TrxWallet) ChainId() int

func (*TrxWallet) DeriveAddress

func (w *TrxWallet) DeriveAddress() string

func (*TrxWallet) DeriveNativePrivateKey

func (w *TrxWallet) DeriveNativePrivateKey() *ecdsa.PrivateKey

func (*TrxWallet) DerivePrivateKey

func (w *TrxWallet) DerivePrivateKey() string

func (*TrxWallet) DerivePublicKey

func (w *TrxWallet) DerivePublicKey() string

func (*TrxWallet) Symbol

func (w *TrxWallet) Symbol() string

type Wallet

type Wallet interface {
	ChainId() int
	Symbol() string

	DeriveAddress() string
	DerivePublicKey() string
	DerivePrivateKey() string
}

Jump to

Keyboard shortcuts

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