Documentation ¶
Overview ¶
Package account is related to account operation. You can reate account and mnemonic, or save account private to file. You can set contract account for account if you want to deploy contract.
Index ¶
- Constants
- func DoubleSha256(data []byte) []byte
- func EVMToXchainAddress(evmAddr string) (string, string, error)
- func UsingSha256(data []byte) []byte
- func XchainToEVMAddress(xchainAddr string) (string, string, error)
- type Account
- func CreateAccount(strength uint8, language int) (*Account, error)
- func CreateAndSaveAccountToFile(path, passwd string, strength uint8, language int) (*Account, error)
- func GetAccountFromFile(path, passwd string) (*Account, error)
- func GetAccountFromPlainFile(path string) (*Account, error)
- func RetrieveAccount(mnemonic string, language int) (*Account, error)
Constants ¶
const ( // XchainAddrType xchain AK 地址类型 XchainAddrType = "xchain" // ContractNameType 合约名字地址类型 ContractNameType = "contract-name" // ContractAccountType 合约账户地址类型 ContractAccountType = "contract-account" )
Variables ¶
This section is empty.
Functions ¶
func DoubleSha256 ¶
DoubleSha256 执行2次SHA256,这是为了防止SHA256算法被攻破。
func EVMToXchainAddress ¶
EVMToXchainAddress evm address transfer to xchain address: evmAddr can be evm contract account, AK address, xchain contract name.
Return: xchain address, address type, error.
func UsingSha256 ¶
UsingSha256 get the hash result of data using SHA256
Types ¶
type Account ¶
type Account struct { Address string PrivateKey string PublicKey string Mnemonic string // contains filtered or unexported fields }
Account account structure
func CreateAccount ¶
CreateAccount create an account.
Parameters:
- `strength`:1弱(12个助记词),2中(18个助记词),3强(24个助记词)。
- `language`:1中文,2英文。
func CreateAndSaveAccountToFile ¶
func CreateAndSaveAccountToFile(path, passwd string, strength uint8, language int) (*Account, error)
CreateAndSaveAccountToFile create an account and save to file.
Parameters:
- `path`:保存路径。
- `passwd`: 密码。
- `strength`:助记词强度。
- `language`:助记词语言。
func GetAccountFromFile ¶
GetAccountFromFile get an account from file and password.
func GetAccountFromPlainFile ¶
GetAccountFromPlainFile import account from plain files which are JSON encoded
指定路径下的结构如下:
- keys |-- address |-- private.key |-- public.key
func RetrieveAccount ¶
RetrieveAccount retrieve account from mnemonic. Parameters:
- `mnemonic`: 助记词,例如:"玉 脸 驱 协 介 跨 尔 籍 杆 伏 愈 即"。
- `language`: 1中文,2英文。
func (*Account) GetAuthRequire ¶
GetAuthRequire get this account's authRequire for transaction. If you set contract account, returns $ContractAccount+"/"+$Address, otherwise returns $Address.
func (*Account) GetContractAccount ¶
GetContractAccount get current contract account, returns an empty string if the contract account is not set.
func (*Account) HasContractAccount ¶
HasContractAccount reutrn true if you set contract account, otherwise returns false.
func (*Account) RemoveContractAccount ¶
func (a *Account) RemoveContractAccount()
RemoveContractAccount remove contract account from this account.
func (*Account) SetContractAccount ¶
SetContractAccount set contract account. If you set contract account, this account represents the contract account. In some scenarios, must set contract account, such as deploy contract.