wallet

package
v0.0.0-...-09e170c Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// contains ethereum, bsc, chainx_eth, polygon...
	ChainTypeEthereum = "ethereum"
	ChainTypeBitcoin  = "bitcoin"
	ChainTypeCosmos   = "cosmos"
	ChainTypeSolana   = "solana"

	// contains chainx, minix, sherpax, polkadot...
	ChainTypePolka    = "polka"
	ChainTypeSignet   = "signet"
	ChainTypeDoge     = "dogecoin"
	ChainTypeTerra    = "terra"
	ChainTypeAptos    = "aptos"
	ChainTypeSui      = "sui"
	ChainTypeStarcoin = "starcoin"
)

Variables

View Source
var (
	ErrWalletInfoUnspecified = errors.New("Wallet info provider unspecified")

	ErrWalletInfoNotExist = errors.New("The specified wallet info does not exist")

	ErrUnsupportKeystore = errors.New("The chain type does not support keystore")

	ErrInvalidMnemonic = errors.New("Invalid mnemonic")
)

Functions

func ByteToHex

func ByteToHex(data []byte) string

func ChainTypeFrom deprecated

func ChainTypeFrom(address string) *base.StringArray

Deprecated: renamed to `ChainTypeOfWatchAddress()`.

func ChainTypeOfPrivateKey

func ChainTypeOfPrivateKey(prikey string) *base.StringArray

func ChainTypeOfWatchAddress

func ChainTypeOfWatchAddress(address string) *base.StringArray

Only support evm, btc, cosmos, solana now.

func CleanCachedAccountInfo

func CleanCachedAccountInfo()

func GenMnemonic

func GenMnemonic() (string, error)

func HexToByte

func HexToByte(hex string) ([]byte, error)

func IsValidMnemonic

func IsValidMnemonic(mnemonic string) bool

Types

type AccountInfo

type AccountInfo struct {
	Wallet *CacheWallet
	// contains filtered or unexported fields
}

func (*AccountInfo) Account

func (i *AccountInfo) Account() (base.Account, error)

获取账号对象,该对象可以用来签名. 账号不会缓存,每次都会重新生成

func (*AccountInfo) Address

func (i *AccountInfo) Address() (*base.OptionalString, error)

获取地址,该方法会优先读取缓存

func (*AccountInfo) PrivateKeyHex

func (i *AccountInfo) PrivateKeyHex() (*base.OptionalString, error)

获取账号私钥,私钥不会缓存,每次都会重新生成

func (*AccountInfo) PublicKeyHex

func (i *AccountInfo) PublicKeyHex() (*base.OptionalString, error)

获取公钥,该方法会优先读取缓存

type CacheWallet

type CacheWallet struct {
	WalletInfo SDKWalletSecretInfo
	// contains filtered or unexported fields
}

旧的钱包对象在内存里面会缓存 **助记词**,还有很多链的账号 **私钥**,可能会有用户钱包被盗的风险 因此 SDK 里面不能缓存 **助记词** 、**私钥** 、还有 **keystore 密码**

考虑到每次都导入助记词生成账号,而仅仅是为了获取账号地址或者公钥,可能会影响钱包的性能和体验 因此新提供了这个可以缓存 *账号地址* 和 *公钥* 这种不敏感信息的钱包

func NewCacheWallet

func NewCacheWallet(info SDKWalletSecretInfo) *CacheWallet

func NewWatchWallet

func NewWatchWallet(address string) (*CacheWallet, error)

Create a watch wallet

func (*CacheWallet) AptosAccountInfo

func (w *CacheWallet) AptosAccountInfo() *AccountInfo

func (*CacheWallet) BitcoinAccountInfo

func (w *CacheWallet) BitcoinAccountInfo(chainnet string) *AccountInfo

func (*CacheWallet) CosmosAccountInfo

func (w *CacheWallet) CosmosAccountInfo(cointype int64, prefix string) *AccountInfo

func (*CacheWallet) DogecoinAccountInfo

func (w *CacheWallet) DogecoinAccountInfo(chainnet string) *AccountInfo

func (*CacheWallet) EthereumAccountInfo

func (w *CacheWallet) EthereumAccountInfo() *AccountInfo

func (*CacheWallet) PolkaAccountInfo

func (w *CacheWallet) PolkaAccountInfo(network int) *AccountInfo

func (*CacheWallet) SolanaAccountInfo

func (w *CacheWallet) SolanaAccountInfo() *AccountInfo

func (*CacheWallet) StarcoinAccountInfo

func (w *CacheWallet) StarcoinAccountInfo() *AccountInfo

func (*CacheWallet) SuiAccountInfo

func (w *CacheWallet) SuiAccountInfo() *AccountInfo

func (*CacheWallet) WalletType

func (w *CacheWallet) WalletType() WalletType

获取钱包类型 枚举值见 `WalletType` (Mnemonic / Keystore / PrivateKey / Watch / Error)

type SDKWalletSecretInfo

type SDKWalletSecretInfo interface {
	// 需要提供一个 key, 可以缓存钱包地址公钥信息
	SDKCacheKey() string
	// 如果是一个助记词钱包,返回助记词
	SDKMnemonic() string
	// 如果是一个 keystore 钱包,返回 keystore
	SDKKeystore() string
	// 如果是一个 keystore 钱包,返回密码
	SDKPassword() string
	// 如果是一个私钥钱包,返回私钥
	SDKPrivateKey() string
	// 如果是一个观察者钱包,返回观察地址
	SDKWatchAddress() string
}

任意一个类可以遵循这个协议, 通过创建一个 `CacheWallet` 来计算钱包公钥、地址 SDK 会在需要的时候从该对象读取 **助记词/keystore/私钥** 等信息

type Wallet deprecated

type Wallet struct {
	Mnemonic string

	Keystore string

	WatchAddress string
	// contains filtered or unexported fields
}

Deprecated: 这个钱包对象缓存了助记词、密码、私钥等信息,继续使用有泄露资产的风险 ⚠️

func NewWalletWithKeyStore

func NewWalletWithKeyStore(keyStoreJson string, password string) (*Wallet, error)

Only support Polka keystore.

func NewWalletWithMnemonic

func NewWalletWithMnemonic(mnemonic string) (*Wallet, error)

func WatchWallet

func WatchWallet(address string) (*Wallet, error)

func (*Wallet) CheckPassword

func (w *Wallet) CheckPassword(password string) (bool, error)

check keystore password

func (*Wallet) GetAddress deprecated

func (w *Wallet) GetAddress(network int) (string, error)

Deprecated: GetAddress is deprecated. Please use wallet.PolkaAccount(network).Address() instead

func (*Wallet) GetOrCreateAptosAccount

func (w *Wallet) GetOrCreateAptosAccount() (*aptos.Account, error)

Get or create the aptos account.

func (*Wallet) GetOrCreateBitcoinAccount

func (w *Wallet) GetOrCreateBitcoinAccount(chainnet string) (*btc.Account, error)

Get or create the bitcoin account with specified chainnet.

func (*Wallet) GetOrCreateCosmosAccount

func (w *Wallet) GetOrCreateCosmosAccount() (*cosmos.Account, error)

Get or create cosmos chain account

func (*Wallet) GetOrCreateCosmosTypeAccount

func (w *Wallet) GetOrCreateCosmosTypeAccount(cointype int64, addressPrefix string) (*cosmos.Account, error)

Get or create a wallet account based on cosmos architecture.

func (*Wallet) GetOrCreateDogeAccount

func (w *Wallet) GetOrCreateDogeAccount(chainnet string) (*doge.Account, error)

func (*Wallet) GetOrCreateEthereumAccount

func (w *Wallet) GetOrCreateEthereumAccount() (*eth.Account, error)

Get or create the ethereum account.

func (*Wallet) GetOrCreatePolkaAccount

func (w *Wallet) GetOrCreatePolkaAccount(network int) (*polka.Account, error)

Get or create the polka account with specified network.

func (*Wallet) GetOrCreateSolanaAccount

func (w *Wallet) GetOrCreateSolanaAccount() (*solana.Account, error)

Get or create the solana account.

func (*Wallet) GetOrCreateStarcoinAccount

func (w *Wallet) GetOrCreateStarcoinAccount() (*starcoin.Account, error)

Get or create the starcoin account.

func (*Wallet) GetOrCreateSuiAccount

func (w *Wallet) GetOrCreateSuiAccount() (*sui.Account, error)

Get or create the sui account.

func (*Wallet) GetPrivateKeyHex deprecated

func (w *Wallet) GetPrivateKeyHex() (string, error)

Deprecated: GetPrivateKeyHex is deprecated. Please use wallet.PolkaAccount(network).PrivateKey() instead

func (*Wallet) GetPublicKey deprecated

func (w *Wallet) GetPublicKey() ([]byte, error)

Deprecated: GetPublicKey is deprecated. Please use wallet.PolkaAccount(network).PublicKey() instead

func (*Wallet) GetPublicKeyHex deprecated

func (w *Wallet) GetPublicKeyHex() (string, error)

Deprecated: GetPublicKeyHex is deprecated. Please use wallet.PolkaAccount(network).PublicKey() instead

func (*Wallet) GetWatchWallet

func (w *Wallet) GetWatchWallet() *WatchAccount

func (*Wallet) IsKeystoreWallet

func (w *Wallet) IsKeystoreWallet() bool

func (*Wallet) IsMnemonicWallet

func (w *Wallet) IsMnemonicWallet() bool

func (*Wallet) IsWatchWallet

func (w *Wallet) IsWatchWallet() bool

func (*Wallet) Sign deprecated

func (w *Wallet) Sign(message []byte, password string) (b []byte, err error)

Deprecated: Sign is deprecated. Please use wallet.PolkaAccount(network).Sign() instead

func (*Wallet) SignFromHex deprecated

func (w *Wallet) SignFromHex(messageHex string, password string) ([]byte, error)

Deprecated: SignFromHex is deprecated. Please use wallet.PolkaAccount(network).SignHex() instead

type WalletType

type WalletType = base.SDKEnumInt
const (
	WalletTypeMnemonic   WalletType = 1
	WalletTypeKeystore   WalletType = 2
	WalletTypePrivateKey WalletType = 3
	WalletTypeWatch      WalletType = 4
	WalletTypeError      WalletType = 5
)

type WatchAccount

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

func (*WatchAccount) Address

func (a *WatchAccount) Address() string

func (*WatchAccount) PrivateKey

func (a *WatchAccount) PrivateKey() ([]byte, error)

func (*WatchAccount) PrivateKeyHex

func (a *WatchAccount) PrivateKeyHex() (string, error)

func (*WatchAccount) PublicKey

func (a *WatchAccount) PublicKey() []byte

func (*WatchAccount) PublicKeyHex

func (a *WatchAccount) PublicKeyHex() string

func (*WatchAccount) Sign

func (a *WatchAccount) Sign(message []byte, password string) ([]byte, error)

func (*WatchAccount) SignHex

func (a *WatchAccount) SignHex(messageHex string, password string) (*base.OptionalString, error)

Jump to

Keyboard shortcuts

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