Documentation ¶
Index ¶
- Constants
- Variables
- func ByteToHex(data []byte) string
- func ChainTypeFrom(address string) *base.StringArraydeprecated
- func ChainTypeOfPrivateKey(prikey string) *base.StringArray
- func ChainTypeOfWatchAddress(address string) *base.StringArray
- func CleanCachedAccountInfo()
- func GenMnemonic() (string, error)
- func HexToByte(hex string) ([]byte, error)
- func IsValidMnemonic(mnemonic string) bool
- type AccountInfo
- type CacheWallet
- func (w *CacheWallet) AptosAccountInfo() *AccountInfo
- func (w *CacheWallet) BitcoinAccountInfo(chainnet string) *AccountInfo
- func (w *CacheWallet) CosmosAccountInfo(cointype int64, prefix string) *AccountInfo
- func (w *CacheWallet) DogecoinAccountInfo(chainnet string) *AccountInfo
- func (w *CacheWallet) EthereumAccountInfo() *AccountInfo
- func (w *CacheWallet) PolkaAccountInfo(network int) *AccountInfo
- func (w *CacheWallet) SolanaAccountInfo() *AccountInfo
- func (w *CacheWallet) StarcoinAccountInfo() *AccountInfo
- func (w *CacheWallet) SuiAccountInfo() *AccountInfo
- func (w *CacheWallet) WalletType() WalletType
- type SDKWalletSecretInfo
- type Walletdeprecated
- func (w *Wallet) CheckPassword(password string) (bool, error)
- func (w *Wallet) GetAddress(network int) (string, error)deprecated
- func (w *Wallet) GetOrCreateAptosAccount() (*aptos.Account, error)
- func (w *Wallet) GetOrCreateBitcoinAccount(chainnet string) (*btc.Account, error)
- func (w *Wallet) GetOrCreateCosmosAccount() (*cosmos.Account, error)
- func (w *Wallet) GetOrCreateCosmosTypeAccount(cointype int64, addressPrefix string) (*cosmos.Account, error)
- func (w *Wallet) GetOrCreateDogeAccount(chainnet string) (*doge.Account, error)
- func (w *Wallet) GetOrCreateEthereumAccount() (*eth.Account, error)
- func (w *Wallet) GetOrCreatePolkaAccount(network int) (*polka.Account, error)
- func (w *Wallet) GetOrCreateSolanaAccount() (*solana.Account, error)
- func (w *Wallet) GetOrCreateStarcoinAccount() (*starcoin.Account, error)
- func (w *Wallet) GetOrCreateSuiAccount() (*sui.Account, error)
- func (w *Wallet) GetPrivateKeyHex() (string, error)deprecated
- func (w *Wallet) GetPublicKey() ([]byte, error)deprecated
- func (w *Wallet) GetPublicKeyHex() (string, error)deprecated
- func (w *Wallet) GetWatchWallet() *WatchAccount
- func (w *Wallet) IsKeystoreWallet() bool
- func (w *Wallet) IsMnemonicWallet() bool
- func (w *Wallet) IsWatchWallet() bool
- func (w *Wallet) Sign(message []byte, password string) (b []byte, err error)deprecated
- func (w *Wallet) SignFromHex(messageHex string, password string) ([]byte, error)deprecated
- type WalletType
- type WatchAccount
- func (a *WatchAccount) Address() string
- func (a *WatchAccount) PrivateKey() ([]byte, error)
- func (a *WatchAccount) PrivateKeyHex() (string, error)
- func (a *WatchAccount) PublicKey() []byte
- func (a *WatchAccount) PublicKeyHex() string
- func (a *WatchAccount) Sign(message []byte, password string) ([]byte, error)
- func (a *WatchAccount) SignHex(messageHex string, password string) (*base.OptionalString, error)
Constants ¶
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 ¶
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 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 IsValidMnemonic ¶
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 ¶
Only support Polka keystore.
func NewWalletWithMnemonic ¶
func WatchWallet ¶
func (*Wallet) CheckPassword ¶
check keystore password
func (*Wallet) GetAddress
deprecated
func (*Wallet) GetOrCreateAptosAccount ¶
Get or create the aptos account.
func (*Wallet) GetOrCreateBitcoinAccount ¶
Get or create the bitcoin account with specified chainnet.
func (*Wallet) GetOrCreateCosmosAccount ¶
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 (*Wallet) GetOrCreateEthereumAccount ¶
Get or create the ethereum account.
func (*Wallet) GetOrCreatePolkaAccount ¶
Get or create the polka account with specified network.
func (*Wallet) GetOrCreateSolanaAccount ¶
Get or create the solana account.
func (*Wallet) GetOrCreateStarcoinAccount ¶
Get or create the starcoin account.
func (*Wallet) GetOrCreateSuiAccount ¶
Get or create the sui account.
func (*Wallet) GetPrivateKeyHex
deprecated
func (*Wallet) GetPublicKey
deprecated
func (*Wallet) GetPublicKeyHex
deprecated
func (*Wallet) GetWatchWallet ¶
func (w *Wallet) GetWatchWallet() *WatchAccount
func (*Wallet) IsKeystoreWallet ¶
func (*Wallet) IsMnemonicWallet ¶
func (*Wallet) IsWatchWallet ¶
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)