wallet

package
v1.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: MIT Imports: 9 Imported by: 9

Documentation

Index

Constants

View Source
const (
	PrivateKeyType     = byte(0x0) // Serialize wallet account key into string with only PRIVATE KEY of account key set
	PaymentAddressType = byte(0x1) // Serialize wallet account key into string with only PAYMENT ADDRESS of account key set
	ReadonlyKeyType    = byte(0x2) // Serialize wallet account key into string with only READONLY KEY of account key set
	OTAKeyType         = byte(0x3) // Serialize wallet account key into string with only OTA KEY of account key set
)
View Source
const (
	DefaultPassword      = "12345678"
	HardenedKeyZeroIndex = 0x80000000
	BIP44Purpose         = 44
	Bip44CoinType        = 587
	MinSeedBytes         = 16
	MaxSeedBytes         = 64
)
View Source
const (
	InvalidChecksumErr = iota
	WrongPassphraseErr
	ExistedAccountErr
	ExistedAccountNameErr
	UnexpectedErr
	EmptyWalletNameErr
	NotFoundAccountErr
	JsonMarshalErr
	JsonUnmarshalErr
	WriteFileErr
	ReadFileErr
	AESEncryptErr
	AESDecryptErr
	InvalidKeyTypeErr
	InvalidPlaintextErr
	NewChildKeyError
	NewEntropyError
	NewMnemonicError
	MnemonicInvalidError
	InvalidSeserializedKey
)

Variables

View Source
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"},
}

Functions

func ComparePaymentAddresses

func ComparePaymentAddresses(addr1, addr2 string) (bool, error)

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

func GetPaymentAddressV1(addr string, isNewEncoding bool) (string, error)

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 IsPublicKeyBurningAddress

func IsPublicKeyBurningAddress(publicKey []byte) bool

IsPublicKeyBurningAddress checks if a public key is a burning address in the Incognito network.

func NewMnemonic

func NewMnemonic(bitSize int) (string, error)

NewMnemonic generates a mnemonic string given the entropy bitSize.

func NewMnemonicFromEntropy

func NewMnemonicFromEntropy(entropy []byte) (string, error)

NewMnemonicFromEntropy generates a mnemonic string given the entropy

func NewSeedFromMnemonic

func NewSeedFromMnemonic(mnemonic string) ([]byte, error)

NewSeedFromMnemonic creates a hashed seed output given a provided mnemonic string. The mnemonic is validated against the BIP39 standard before the seed is generated.

Types

type Error

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

Error represents a wallet error.

func NewError

func NewError(key int, err error) *Error

NewError creates a new wallet-wrapped error given a key and an error.

func (Error) Error

func (e Error) Error() string

Error returns the error message.

type KeyWallet

type KeyWallet struct {
	Depth       byte               // 1 bytes
	ChildNumber []byte             // 4 bytes
	ChainCode   []byte             // 32 bytes
	HDKey       *hdwallet.HDWallet // Actual HD wallet key
	KeySet      key.KeySet         // Incognito key-set
}

KeyWallet defines the components of a hierarchical deterministic wallet.

func Base58CheckDeserialize

func Base58CheckDeserialize(data string) (*KeyWallet, error)

Base58CheckDeserialize deserializes the keySet of a KeyWallet encoded in base58 because data contains keyType and serialized data of corresponding key. It returns KeySet just contain corresponding key.

func GenRandomWalletForShardID

func GenRandomWalletForShardID(shardID byte) (*KeyWallet, error)

GenRandomWalletForShardID generates a random wallet for a specific shardID.

func NewMasterKey

func NewMasterKey() (*KeyWallet, string, error)

NewMasterKey returns a new KeyWallet, and a mnemonic that generates the KeyWallet.

func NewMasterKeyFromMnemonic

func NewMasterKeyFromMnemonic(mnemonic string) (*KeyWallet, error)

NewMasterKeyFromMnemonic returns a new KeyWallet given a BIP39 mnemonic string.

func NewMasterKeyFromSeed

func NewMasterKeyFromSeed(seed []byte) (*KeyWallet, error)

NewMasterKeyFromSeed returns a new KeyWallet given a random seed.

func (*KeyWallet) Base58CheckSerialize

func (w *KeyWallet) Base58CheckSerialize(keyType byte) string

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) DeriveChild

func (w *KeyWallet) DeriveChild(i uint32) (*KeyWallet, error)

DeriveChild returns the i-th child of wallet w following the BIP-44 standard. Call this function with increasing i to create as many wallets as you want.

func (*KeyWallet) GetOTAPrivateKey

func (w *KeyWallet) GetOTAPrivateKey() (string, error)

GetOTAPrivateKey returns the base58-encoded privateOTA key of a KeyWallet.

func (*KeyWallet) GetPaymentAddress

func (w *KeyWallet) GetPaymentAddress() (string, error)

GetPaymentAddress returns the base58-encoded payment address of a KeyWallet.

func (*KeyWallet) GetPrivateKey

func (w *KeyWallet) GetPrivateKey() (string, error)

GetPrivateKey returns the base58-encoded private key of a KeyWallet.

func (*KeyWallet) GetPublicKey

func (w *KeyWallet) GetPublicKey() (string, error)

GetPublicKey returns the base58-encoded public key of a KeyWallet.

func (*KeyWallet) GetReadonlyKey

func (w *KeyWallet) GetReadonlyKey() (string, error)

GetReadonlyKey returns the base58-encoded readonly key of a KeyWallet.

func (*KeyWallet) Serialize

func (w *KeyWallet) Serialize(keyType byte, isNewCheckSum bool) ([]byte, error)

Serialize receives keyType and serializes key which has keyType to bytes array and append 4-byte checksum into bytes array

Jump to

Keyboard shortcuts

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