Documentation ¶
Index ¶
- Constants
- Variables
- func Encode(input []byte) string
- func EncodeCheck(input []byte) string
- func NewMnemonic(length int, language string) (string, error)
- func NewSeed(mnemonic, password, language string) ([]byte, error)
- func PathNumber(str string) uint32
- type Address
- type Key
- func (k *Key) AddressBCH() (string, error)
- func (k *Key) AddressBNB(network string) (string, error)
- func (k *Key) AddressBTC() (string, error)
- func (k *Key) AddressP2WPKH() (string, error)
- func (k *Key) AddressP2WPKHInP2SH() (string, error)
- func (k *Key) AddressTapRoot() (string, error)
- func (k *Key) GetChildKey(opts ...Option) (*Key, error)
- func (k *Key) GetWallet(opts ...Option) (Wallet, error)
- func (k *Key) PrivateHex() string
- func (k *Key) PrivateWIF(compress bool) (string, error)
- func (k *Key) PublicHash() ([]byte, error)
- func (k *Key) PublicHex(compress bool) string
- type Option
- func Account(a uint32) Option
- func AddressIndex(a uint32) Option
- func Change(c uint32) Option
- func CoinType(c uint32) Option
- func Language(l string) Option
- func MaxLevel(c int) Option
- func MinLevel(c int) Option
- func Mnemonic(m string) Option
- func Params(p *chaincfg.Params) Option
- func Password(p string) Option
- func Path(path string) Option
- func Purpose(p uint32) Option
- func Seed(s []byte) Option
- type Options
- type Wallet
Constants ¶
const ( English = "english" ChineseSimplified = "chinese_simplified" ChineseTraditional = "chinese_traditional" )
mnemonic language
const ( Zero uint32 = 0 ZeroQuote uint32 = 0x80000000 BTCToken uint32 = 0x10000000 ETHToken uint32 = 0x20000000 )
zero is default of uint32
const ( BTC = ZeroQuote + 0 BTCTestnet = ZeroQuote + 1 LTC = ZeroQuote + 2 DOGE = ZeroQuote + 3 DASH = ZeroQuote + 5 ETH = ZeroQuote + 60 ETC = ZeroQuote + 61 BCH = ZeroQuote + 145 QTUM = ZeroQuote + 2301 TRX = ZeroQuote + 195 BNB = ZeroQuote + 714 FIL = ZeroQuote + 461 USDT = BTCToken + 1 IOST = ETHToken + 1 USDC = ETHToken + 2 )
wallet type from bip44
const ( MAINNET = "mainnet" TESTNET = "testnet" )
network
const ( PathLevelAuto = -1 PathLevelPurpose = iota - 1 PathLevelCoinType PathLevelAccount PathLevelChange PathLevelAddressIndex )
const (
TronBytePrefix = byte(0x41)
)
Variables ¶
var ( DefaultParams = &BTCParams DefaultPassword = "" DefaultLanguage = "" DefaultPurpose = ZeroQuote + 44 DefaultCoinType = Zero DefaultAccount = ZeroQuote DefaultChange = Zero DefaultAddressIndex = Zero )
default options
var ( BTCParams = chaincfg.MainNetParams BTCTestnetParams = chaincfg.TestNet3Params LTCParams = chaincfg.MainNetParams DOGEParams = chaincfg.MainNetParams DASHParams = chaincfg.MainNetParams BCHParams = chaincfg.MainNetParams QTUMParams = chaincfg.MainNetParams USDTParams = chaincfg.MainNetParams )
init net params
var (
ErrCoinTypeUnknown = errors.New("unknown coin type")
)
var (
ErrPrivateKeyNotExists = errors.New("private key not exists")
)
Functions ¶
func EncodeCheck ¶
func NewMnemonic ¶
NewMnemonic creates a random mnemonic
Types ¶
type Address ¶
type Address []byte
Address represents the 21 byte address of an Tron account.
func PubkeyToAddress ¶
PubkeyToAddress returns address from ecdsa public key
type Key ¶
type Key struct { Opt *Options Extended *hdkeychain.ExtendedKey // for btc Private *btcec.PrivateKey Public *btcec.PublicKey // for eth PrivateECDSA *ecdsa.PrivateKey PublicECDSA *ecdsa.PublicKey }
Key struct
func NewKeyFromString ¶
func (*Key) AddressBCH ¶
AddressBCH generate public key to bch style address
func (*Key) AddressBNB ¶
AddressBNB 生成bnb地址 network mainnet主网地址 testnet测试网地址
func (*Key) AddressBTC ¶
AddressBTC generate public key to btc style address
func (*Key) AddressP2WPKH ¶
AddressP2WPKH generate public key to p2wpkh style address
func (*Key) AddressP2WPKHInP2SH ¶
AddressP2WPKHInP2SH generate public key to p2wpkh nested within p2sh style address
func (*Key) AddressTapRoot ¶
AddressTapRoot generate public key to taproot address
func (*Key) GetChildKey ¶
GetChildKey return a key from master key params: Purpose, CoinType, Account, Change, AddressIndex, Path
func (*Key) GetWallet ¶
GetWallet return wallet from master key params: Purpose, CoinType, Account, Change, AddressIndex, Path
func (*Key) PrivateHex ¶
PrivateHex generate private key to string by hex
func (*Key) PrivateWIF ¶
PrivateWIF generate private key to string by wif
func (*Key) PublicHash ¶
PublicHash generate public key by hash160
type Option ¶
type Option func(*Options)
Option of key
type Options ¶
type Options struct { Params *chaincfg.Params // master key options Mnemonic string Password string Language string Seed []byte // child key options Purpose uint32 CoinType uint32 Account uint32 Change uint32 AddressIndex uint32 // level for derive from public key MinPathLevel int // [ MaxPathLevel int // ] }
Options of key