account

package
v2.0.0-...-d7ce1a4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
const (

	// XchainAddrType xchain AK 地址类型
	XchainAddrType = "xchain"

	// ContractNameType 合约名字地址类型
	ContractNameType = "contract-name"

	// ContractAccountType 合约账户地址类型
	ContractAccountType = "contract-account"
)

Variables

This section is empty.

Functions

func DoubleSha256

func DoubleSha256(data []byte) []byte

DoubleSha256 执行2次SHA256,这是为了防止SHA256算法被攻破。

func EVMToXchainAddress

func EVMToXchainAddress(evmAddr string) (string, string, error)

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

func UsingSha256(data []byte) []byte

UsingSha256 get the hash result of data using SHA256

func XchainToEVMAddress

func XchainToEVMAddress(xchainAddr string) (string, string, error)

XchainToEVMAddress xchain address transfer to evm address: xchainAddr can be xchain contract account, AK address, xchain contract name.

Return: evm address, address type, error.

Types

type Account

type Account struct {
	Address    string
	PrivateKey string
	PublicKey  string
	Mnemonic   string
	// contains filtered or unexported fields
}

Account account structure

func CreateAccount

func CreateAccount(strength uint8, language int) (*Account, error)

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

func GetAccountFromFile(path, passwd string) (*Account, error)

GetAccountFromFile get an account from file and password.

func GetAccountFromPlainFile

func GetAccountFromPlainFile(path string) (*Account, error)

GetAccountFromPlainFile import account from plain files which are JSON encoded

指定路径下的结构如下:

  • keys |-- address |-- private.key |-- public.key

func RetrieveAccount

func RetrieveAccount(mnemonic string, language int) (*Account, error)

RetrieveAccount retrieve account from mnemonic. Parameters:

  • `mnemonic`: 助记词,例如:"玉 脸 驱 协 介 跨 尔 籍 杆 伏 愈 即"。
  • `language`: 1中文,2英文。

func (*Account) GetAuthRequire

func (a *Account) GetAuthRequire() string

GetAuthRequire get this account's authRequire for transaction. If you set contract account, returns $ContractAccount+"/"+$Address, otherwise returns $Address.

func (*Account) GetContractAccount

func (a *Account) GetContractAccount() string

GetContractAccount get current contract account, returns an empty string if the contract account is not set.

func (*Account) HasContractAccount

func (a *Account) HasContractAccount() bool

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

func (a *Account) SetContractAccount(contractAccount string) error

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.

Jump to

Keyboard shortcuts

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