Documentation ¶
Index ¶
- Constants
- Variables
- func ComparePaymentAddresses(addr1, addr2 string) (bool, error)
- func GetBurningPublicKey() []byte
- func GetPaymentAddressV1(addr string, isNewEncoding bool) (string, error)
- func GetPublicKeysFromPaymentAddresses(payments []string) []string
- func InitPublicKeyBurningAddressByte() error
- func IsPublicKeyBurningAddress(publicKey []byte) bool
- func NewWordList(language string) []string
- type AccountWallet
- type KeySerializedData
- type KeyWallet
- type MnemonicGenerator
- type Wallet
- func (wallet *Wallet) ContainPublicKey(pubKey []byte) bool
- func (wallet *Wallet) CreateNewAccount(accountName string, shardID *byte) (*AccountWallet, error)
- func (wallet *Wallet) DumpPrivateKey(paymentAddrSerialized string) KeySerializedData
- func (wallet *Wallet) ExportAccount(childIndex uint32) string
- func (wallet *Wallet) GetAddressByAccName(accountName string, shardID *byte) KeySerializedData
- func (wallet *Wallet) GetAddressesByAccName(accountName string) []KeySerializedData
- func (wallet Wallet) GetConfig() *WalletConfig
- func (wallet *Wallet) ImportAccount(privateKeyStr string, accountName string, passPhrase string) (*AccountWallet, error)
- func (wallet *Wallet) Init(passPhrase string, numOfAccount uint32, name string) error
- func (wallet *Wallet) ListAccounts() map[string]AccountWallet
- func (wallet *Wallet) LoadWallet(password string) error
- func (wallet *Wallet) RemoveAccount(privateKeyStr string, passPhrase string) error
- func (wallet *Wallet) Save(password string) error
- func (wallet *Wallet) SetConfig(config *WalletConfig)
- type WalletConfig
- type WalletError
- type WalletLogger
Constants ¶
const ( PriKeyType = byte(0x0) // Serialize wallet account key into string with only PRIVATE KEY of account keyset PaymentAddressType = byte(0x1) // Serialize wallet account key into string with only PAYMENT ADDRESS of account keyset ReadonlyKeyType = byte(0x2) // Serialize wallet account key into string with only READONLY KEY of account keyset OTAKeyType = byte(0x3) // Serialize wallet account key into string with only OTA KEY of account keyset PrivateReceivingAddressType = byte(0x4) // prefix for marshalled receiving address (coin pk + txRandom), not used for KeyWallet )
const ( InvalidChecksumErr = iota WrongPassphraseErr ExistedAccountErr ExistedAccountNameErr UnexpectedErr EmptyWalletNameErr NotFoundAccountErr JsonMarshalErr JsonUnmarshalErr WriteFileErr ReadFileErr AESEncryptErr AESDecryptErr InvalidKeyTypeErr InvalidPlaintextErr NewChildKeyError NewEntropyError NewMnemonicError MnemonicInvalidError InvalidSeserializedKey )
Variables ¶
var ErrCodeMessage = map[int]struct { code int message string }{ UnexpectedErr: {-1, "Unexpected error"}, InvalidChecksumErr: {-1000, "Checksum does not match"}, WrongPassphraseErr: {-1001, "Wrong passphrase"}, ExistedAccountErr: {-1002, "Existed account"}, ExistedAccountNameErr: {-1002, "Existed account name"}, EmptyWalletNameErr: {-1003, "Wallet name is empty"}, NotFoundAccountErr: {-1004, "Account wallet is not found"}, JsonMarshalErr: {-1005, "Can not json marshal"}, JsonUnmarshalErr: {-1006, "Can not json unmarshal"}, WriteFileErr: {-1007, "Can not write file"}, ReadFileErr: {-1008, "Can not read file"}, AESEncryptErr: {-1009, "Can not AES encrypt data"}, AESDecryptErr: {-1010, "Can not AES decrypt data"}, InvalidKeyTypeErr: {-1011, "Serialized key type is invalid"}, InvalidPlaintextErr: {-1012, "Plaintext is invalid"}, NewChildKeyError: {-1013, "Can not create new child key"}, NewEntropyError: {-1014, "Can not create entropy"}, NewMnemonicError: {-1015, "Can not create mnemonic"}, MnemonicInvalidError: {-1016, "Mnemonic is invalid"}, InvalidSeserializedKey: {-1016, "Serialized key is invalid"}, }
var Logger = WalletLogger{}
Global instant to use
Functions ¶
func ComparePaymentAddresses ¶
ComparePaymentAddresses checks if two payment addresses are generated from the same private key.
Just need to compare PKs and TKs.
func GetBurningPublicKey ¶
func GetBurningPublicKey() []byte
GetBurningPublicKey returns the public key of the burning address.
func GetPaymentAddressV1 ¶
GetPaymentAddressV1 retrieves the payment address ver 1 from the payment address ver 2.
- Payment Address V1 consists of: PK + TK
- Payment Address V2 consists of: PK + TK + PublicOTA
If the input is a payment address ver 2, try to retrieve the corresponding payment address ver 1. Otherwise, return the input.
func InitPublicKeyBurningAddressByte ¶
func InitPublicKeyBurningAddressByte() error
func NewWordList ¶
Types ¶
type AccountWallet ¶
type AccountWallet struct { Name string Key KeyWallet Child []AccountWallet IsImported bool }
type KeySerializedData ¶
type KeyWallet ¶
type KeyWallet struct { Depth byte // 1 bytes ChildNumber []byte // 4 bytes ChainCode []byte // 32 bytes KeySet incognitokey.KeySet }
KeyWallet represents with bip32 standard
func Base58CheckDeserialize ¶
Base58CheckDeserialize deserializes a KeySet encoded in base58 encoding because data contains keyType and serialized data of corresponding key it returns KeySet just contain corresponding key
func NewMasterKey ¶
NewMasterKey creates a new master extended PubKey from a Seed Seed is a bytes array which any size
func (*KeyWallet) Base58CheckSerialize ¶
Base58CheckSerialize encodes the key corresponding to keyType in KeySet in the standard Incognito base58 encoding It returns the encoding string of the key
func (*KeyWallet) NewChildKey ¶
NewChildKey derives a Child KeyWallet from a given parent as outlined by bip32 2 child keys is derived from one key and a same child index are the same
type MnemonicGenerator ¶
type MnemonicGenerator struct{}
type Wallet ¶
type Wallet struct { Seed []byte Entropy []byte PassPhrase string Mnemonic string MasterAccount AccountWallet Name string // contains filtered or unexported fields }
func (*Wallet) ContainPublicKey ¶
ContainPubKey checks whether the wallet contains any account with pubKey or not
func (*Wallet) CreateNewAccount ¶
func (wallet *Wallet) CreateNewAccount(accountName string, shardID *byte) (*AccountWallet, error)
CreateNewAccount create new account with accountName it returns that new account and returns errors if accountName is existed If shardID is nil, new account will belong to any shards Otherwise, new account will belong to specific shard
func (*Wallet) DumpPrivateKey ¶
func (wallet *Wallet) DumpPrivateKey(paymentAddrSerialized string) KeySerializedData
DumpPrivkey receives base58 check serialized payment address (paymentAddrSerialized) and returns KeySerializedData object contains PrivateKey which is corresponding to paymentAddrSerialized in all wallet accounts If there is not any wallet account corresponding to paymentAddrSerialized, it returns empty KeySerializedData object
func (*Wallet) ExportAccount ¶
ExportAccount returns a private key string of account at childIndex in wallet It is base58 check serialized
func (*Wallet) GetAddressByAccName ¶
func (wallet *Wallet) GetAddressByAccName(accountName string, shardID *byte) KeySerializedData
GetAddressByAccName receives accountName and shardID and returns corresponding account's KeySerializedData object contains base58 check serialized PaymentAddress, hex encoding Pubkey and base58 check serialized ReadonlyKey If there is not any account corresponding to accountName, we will create new account
func (*Wallet) GetAddressesByAccName ¶
func (wallet *Wallet) GetAddressesByAccName(accountName string) []KeySerializedData
GetAddressesByAccName receives accountName and returns list of KeySerializedData of accounts which has accountName
func (Wallet) GetConfig ¶
func (wallet Wallet) GetConfig() *WalletConfig
GetConfig returns configuration of wallet
func (*Wallet) ImportAccount ¶
func (wallet *Wallet) ImportAccount(privateKeyStr string, accountName string, passPhrase string) (*AccountWallet, error)
ImportAccount adds account into wallet with privateKeyStr, accountName, and passPhrase which is used to init wallet It returns AccountWallet which is imported and errors (if any)
func (*Wallet) Init ¶
Init initializes new wallet with pass phrase, number of accounts and wallet name It returns error if there are any errors when initializing wallet. Otherwise, it returns nil passPhrase can be empty string, it is used to generate seed and master key If numOfAccount equals zero, wallet is initialized with one account If name is empty string, it returns error
func (*Wallet) ListAccounts ¶
func (wallet *Wallet) ListAccounts() map[string]AccountWallet
ListAccounts returns a map with key is account name and value is account wallet
func (*Wallet) LoadWallet ¶
LoadWallet loads encrypted wallet from file and then decrypts it to wallet struct It returns error if any
func (*Wallet) RemoveAccount ¶
func (*Wallet) Save ¶
Save saves encrypted wallet (using AES encryption scheme) in config data file of wallet It returns error if any
func (*Wallet) SetConfig ¶
func (wallet *Wallet) SetConfig(config *WalletConfig)
SetConfig sets config to configuration of wallet
type WalletConfig ¶
type WalletError ¶
type WalletError struct {
// contains filtered or unexported fields
}
func NewWalletError ¶
func NewWalletError(key int, err error) *WalletError
func (WalletError) Error ¶
func (e WalletError) Error() string
func (WalletError) GetCode ¶
func (e WalletError) GetCode() int
type WalletLogger ¶
type WalletLogger struct {
// contains filtered or unexported fields
}
func (*WalletLogger) Init ¶
func (walletLogger *WalletLogger) Init(inst common.Logger)