Documentation
¶
Index ¶
- Constants
- Variables
- func ComparePaymentAddresses(addr1, addr2 string) (bool, error)
- func GetBurningPublicKey() []byte
- func GetPaymentAddressV1(addr string, isNewEncoding bool) (string, error)
- func IsPublicKeyBurningAddress(publicKey []byte) bool
- func NewMnemonic(bitSize int) (string, error)
- func NewMnemonicFromEntropy(entropy []byte) (string, error)
- func NewSeedFromMnemonic(mnemonic string) ([]byte, error)
- type Error
- type KeyWallet
- func (w *KeyWallet) Base58CheckSerialize(keyType byte) string
- func (w *KeyWallet) DeriveChild(i uint32) (*KeyWallet, error)
- func (w *KeyWallet) GetOTAPrivateKey() (string, error)
- func (w *KeyWallet) GetPaymentAddress() (string, error)
- func (w *KeyWallet) GetPrivateKey() (string, error)
- func (w *KeyWallet) GetPublicKey() (string, error)
- func (w *KeyWallet) GetReadonlyKey() (string, error)
- func (w *KeyWallet) Serialize(keyType byte, isNewCheckSum bool) ([]byte, error)
Constants ¶
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 )
const ( DefaultPassword = "12345678" HardenedKeyZeroIndex = 0x80000000 BIP44Purpose = 44 Bip44CoinType = 587 MinSeedBytes = 16 MaxSeedBytes = 64 )
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"}, }
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 IsPublicKeyBurningAddress ¶
IsPublicKeyBurningAddress checks if a public key is a burning address in the Incognito network.
func NewMnemonic ¶
NewMnemonic generates a mnemonic string given the entropy bitSize.
func NewMnemonicFromEntropy ¶
NewMnemonicFromEntropy generates a mnemonic string given the entropy
func NewSeedFromMnemonic ¶
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.
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 ¶
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 ¶
GenRandomWalletForShardID generates a random wallet for a specific shardID.
func NewMasterKey ¶
NewMasterKey returns a new KeyWallet, and a mnemonic that generates the KeyWallet.
func NewMasterKeyFromMnemonic ¶
NewMasterKeyFromMnemonic returns a new KeyWallet given a BIP39 mnemonic string.
func NewMasterKeyFromSeed ¶
NewMasterKeyFromSeed returns a new KeyWallet given a random seed.
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) DeriveChild ¶
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 ¶
GetOTAPrivateKey returns the base58-encoded privateOTA key of a KeyWallet.
func (*KeyWallet) GetPaymentAddress ¶
GetPaymentAddress returns the base58-encoded payment address of a KeyWallet.
func (*KeyWallet) GetPrivateKey ¶
GetPrivateKey returns the base58-encoded private key of a KeyWallet.
func (*KeyWallet) GetPublicKey ¶
GetPublicKey returns the base58-encoded public key of a KeyWallet.
func (*KeyWallet) GetReadonlyKey ¶
GetReadonlyKey returns the base58-encoded readonly key of a KeyWallet.