wallet

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// MaxEntropyByteSize is the entropy bytes size used for recovery phrase
	// generation.
	MaxEntropyByteSize = 256
	// MagicIndex is the registered HD wallet index for Vega's wallets.
	MagicIndex = 1789
	// OriginIndex is a constant index used to derive a node from the master
	// node. The resulting node will be used to generate the cryptographic keys.
	OriginIndex = slip10.FirstHardenedIndex + MagicIndex
)
View Source
const (
	Version1 = uint32(1)
	// Version2 identifies HD wallet v2.
	Version2 = uint32(2)
	// LatestVersion is the latest version of Vega's HD wallet. Created wallets
	// are always pointing to the latest version.
	LatestVersion = Version2
)
View Source
const KeyNameMeta = "name"

Variables

View Source
var (
	ErrIsolatedWalletCantGenerateKeyPairs = errors.New("isolated wallet can't generate key pairs")
	ErrIsolatedWalletDoesNotHaveMasterKey = errors.New("isolated wallet doesn't have a master key")
	ErrCantRotateKeyInIsolatedWallet      = errors.New("isolated wallet can't rotate key")
	ErrInvalidRecoveryPhrase              = errors.New("recovery phrase is not valid")
	ErrPubKeyAlreadyTainted               = errors.New("public key is already tainted")
	ErrPubKeyIsTainted                    = errors.New("public key is tainted")
	ErrPubKeyNotTainted                   = errors.New("public key is not tainted")
	ErrPubKeyDoesNotExist                 = errors.New("public key does not exist")
	ErrWalletAlreadyExists                = errors.New("a wallet with the same name already exists")
	ErrWalletDoesNotExists                = errors.New("wallet does not exist")
	ErrWalletNotLoggedIn                  = errors.New("wallet is not logged in")
	ErrWrongPassphrase                    = errors.New("wrong passphrase")
)
View Source
var SupportedVersions = []uint32{Version1, Version2}

SupportedVersions list versions supported by Vega's HD wallet.

Functions

func AnnotateKey added in v0.10.0

func AnnotateKey(store Store, req *AnnotateKeyRequest) error

func GetKeyName added in v0.10.0

func GetKeyName(meta []Meta) string

func IsVersionSupported added in v0.9.2

func IsVersionSupported(v uint32) bool

func NewRecoveryPhrase added in v0.11.0

func NewRecoveryPhrase() (string, error)

NewRecoveryPhrase generates a recovery phrase with an entropy of 256 bits.

func TaintKey added in v0.10.0

func TaintKey(store Store, req *TaintKeyRequest) error

func UntaintKey added in v0.10.0

func UntaintKey(store Store, req *UntaintKeyRequest) error

Types

type Algorithm

type Algorithm struct {
	Name    string `json:"name"`
	Version uint32 `json:"version"`
}

type AnnotateKeyRequest added in v0.10.0

type AnnotateKeyRequest struct {
	Wallet     string `json:"wallet"`
	PubKey     string `json:"pubKey"`
	Metadata   []Meta `json:"metadata"`
	Passphrase string `json:"passphrase"`
}

type CreateWalletRequest added in v0.11.0

type CreateWalletRequest struct {
	Wallet     string `json:"wallet"`
	Passphrase string `json:"passphrase"`
}

type CreateWalletResponse added in v0.11.0

type CreateWalletResponse struct {
	Wallet CreatedWallet  `json:"wallet"`
	Key    FirstPublicKey `json:"key"`
}

func CreateWallet added in v0.11.0

func CreateWallet(store Store, req *CreateWalletRequest) (*CreateWalletResponse, error)

type CreatedWallet added in v0.13.0

type CreatedWallet struct {
	Name           string `json:"name"`
	Version        uint32 `json:"version"`
	FilePath       string `json:"filePath"`
	RecoveryPhrase string `json:"recoveryPhrase"`
}

type DescribeKeyRequest added in v0.10.0

type DescribeKeyRequest struct {
	Wallet     string `json:"wallet"`
	Passphrase string `json:"passphrase"`
	PubKey     string `json:"pubKey"`
}

type DescribeKeyResponse added in v0.10.0

type DescribeKeyResponse struct {
	PublicKey string    `json:"publicKey"`
	Algorithm Algorithm `json:"algorithm"`
	Meta      []Meta    `json:"meta"`
	IsTainted bool      `json:"isTainted"`
}

func DescribeKey added in v0.10.0

func DescribeKey(store Store, req *DescribeKeyRequest) (*DescribeKeyResponse, error)

type FirstPublicKey added in v0.13.0

type FirstPublicKey struct {
	PublicKey string    `json:"publicKey"`
	Algorithm Algorithm `json:"algorithm"`
	Meta      []Meta    `json:"meta"`
}

type GenerateKeyRequest added in v0.10.0

type GenerateKeyRequest struct {
	Wallet     string `json:"wallet"`
	Metadata   []Meta `json:"metadata"`
	Passphrase string `json:"passphrase"`
}

type GenerateKeyResponse added in v0.10.0

type GenerateKeyResponse struct {
	PublicKey string    `json:"publicKey"`
	Algorithm Algorithm `json:"algorithm"`
	Meta      []Meta    `json:"meta"`
}

func GenerateKey added in v0.10.0

func GenerateKey(store Store, req *GenerateKeyRequest) (*GenerateKeyResponse, error)

type GetWalletInfoRequest added in v0.10.0

type GetWalletInfoRequest struct {
	Wallet     string `json:"wallet"`
	Passphrase string `json:"passphrase"`
}

type GetWalletInfoResponse added in v0.10.0

type GetWalletInfoResponse struct {
	Type    string `json:"type"`
	Version uint32 `json:"version"`
	ID      string `json:"id"`
}

func GetWalletInfo added in v0.10.0

func GetWalletInfo(store Store, req *GetWalletInfoRequest) (*GetWalletInfoResponse, error)

type HDKeyPair

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

func NewHDKeyPair

func NewHDKeyPair(
	index uint32,
	publicKey ed25519.PublicKey,
	privateKey ed25519.PrivateKey,
) (*HDKeyPair, error)

func (*HDKeyPair) AlgorithmName

func (k *HDKeyPair) AlgorithmName() string

func (*HDKeyPair) AlgorithmVersion

func (k *HDKeyPair) AlgorithmVersion() uint32

func (*HDKeyPair) DeepCopy

func (k *HDKeyPair) DeepCopy() *HDKeyPair

func (*HDKeyPair) Index

func (k *HDKeyPair) Index() uint32

func (*HDKeyPair) IsTainted

func (k *HDKeyPair) IsTainted() bool

func (*HDKeyPair) MarshalJSON

func (k *HDKeyPair) MarshalJSON() ([]byte, error)

func (*HDKeyPair) Meta

func (k *HDKeyPair) Meta() []Meta

func (*HDKeyPair) PrivateKey

func (k *HDKeyPair) PrivateKey() string

func (*HDKeyPair) PublicKey

func (k *HDKeyPair) PublicKey() string

func (*HDKeyPair) Sign

func (k *HDKeyPair) Sign(data []byte) (*Signature, error)

func (*HDKeyPair) SignAny

func (k *HDKeyPair) SignAny(data []byte) ([]byte, error)

func (*HDKeyPair) Taint

func (k *HDKeyPair) Taint() error

func (*HDKeyPair) ToPublicKey

func (k *HDKeyPair) ToPublicKey() HDPublicKey

ToPublicKey ensures the sensitive information doesn't leak outside.

func (*HDKeyPair) UnmarshalJSON

func (k *HDKeyPair) UnmarshalJSON(data []byte) error

func (*HDKeyPair) Untaint

func (k *HDKeyPair) Untaint() error

func (*HDKeyPair) VerifyAny

func (k *HDKeyPair) VerifyAny(data, sig []byte) (bool, error)

type HDKeyRing

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

func LoadHDKeyRing

func LoadHDKeyRing(keyPairs []HDKeyPair) *HDKeyRing

func NewHDKeyRing

func NewHDKeyRing() *HDKeyRing

func (*HDKeyRing) FindPair

func (r *HDKeyRing) FindPair(pubKey string) (HDKeyPair, bool)

func (*HDKeyRing) ListKeyPairs

func (r *HDKeyRing) ListKeyPairs() []HDKeyPair

ListKeyPairs returns the list of key pairs sorted by key index.

func (*HDKeyRing) ListPublicKeys

func (r *HDKeyRing) ListPublicKeys() []HDPublicKey

ListPublicKeys returns the list of public keys sorted by key index.

func (*HDKeyRing) NextIndex

func (r *HDKeyRing) NextIndex() uint32

func (*HDKeyRing) Upsert

func (r *HDKeyRing) Upsert(keyPair HDKeyPair)

type HDMasterKeyPair added in v0.11.0

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

func NewHDMasterKeyPair added in v0.11.0

func NewHDMasterKeyPair(
	publicKey ed25519.PublicKey,
	privateKey ed25519.PrivateKey,
) (*HDMasterKeyPair, error)

func (*HDMasterKeyPair) AlgorithmName added in v0.11.0

func (k *HDMasterKeyPair) AlgorithmName() string

func (*HDMasterKeyPair) AlgorithmVersion added in v0.11.0

func (k *HDMasterKeyPair) AlgorithmVersion() uint32

func (*HDMasterKeyPair) PrivateKey added in v0.11.0

func (k *HDMasterKeyPair) PrivateKey() string

func (*HDMasterKeyPair) PublicKey added in v0.11.0

func (k *HDMasterKeyPair) PublicKey() string

func (*HDMasterKeyPair) Sign added in v0.11.0

func (k *HDMasterKeyPair) Sign(data []byte) (*Signature, error)

func (*HDMasterKeyPair) SignAny added in v0.11.0

func (k *HDMasterKeyPair) SignAny(data []byte) ([]byte, error)

type HDPublicKey

type HDPublicKey struct {
	Idx       uint32    `json:"index"`
	PublicKey string    `json:"pub"`
	Algorithm Algorithm `json:"algorithm"`
	Tainted   bool      `json:"tainted"`
	MetaList  []Meta    `json:"meta"`
}

func (*HDPublicKey) AlgorithmName

func (k *HDPublicKey) AlgorithmName() string

func (*HDPublicKey) AlgorithmVersion

func (k *HDPublicKey) AlgorithmVersion() uint32

func (*HDPublicKey) Hash added in v0.11.0

func (k *HDPublicKey) Hash() (string, error)

func (*HDPublicKey) Index

func (k *HDPublicKey) Index() uint32

func (*HDPublicKey) IsTainted

func (k *HDPublicKey) IsTainted() bool

func (*HDPublicKey) Key

func (k *HDPublicKey) Key() string

func (*HDPublicKey) MarshalJSON

func (k *HDPublicKey) MarshalJSON() ([]byte, error)

func (*HDPublicKey) Meta

func (k *HDPublicKey) Meta() []Meta

func (*HDPublicKey) UnmarshalJSON

func (k *HDPublicKey) UnmarshalJSON(data []byte) error

type HDWallet

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

func ImportHDWallet

func ImportHDWallet(name, recoveryPhrase string, version uint32) (*HDWallet, error)

ImportHDWallet creates a wallet based on the recovery phrase in input. This is useful import or retrieve a wallet.

func NewHDWallet

func NewHDWallet(name string) (*HDWallet, string, error)

NewHDWallet creates a wallet with auto-generated recovery phrase. This is useful to create a brand-new wallet, without having to take care of the recovery phrase generation. The generated recovery phrase is returned alongside the created wallet.

func (*HDWallet) DescribeKeyPair added in v0.10.0

func (w *HDWallet) DescribeKeyPair(pubKey string) (KeyPair, error)

DescribeKeyPair returns all the information associated with a public key.

func (*HDWallet) DescribePublicKey

func (w *HDWallet) DescribePublicKey(pubKey string) (PublicKey, error)

DescribePublicKey returns all the information associated to a public key, except the private key.

func (*HDWallet) GenerateKeyPair

func (w *HDWallet) GenerateKeyPair(meta []Meta) (KeyPair, error)

GenerateKeyPair generates a new key pair from a node, that is derived from the wallet node.

func (*HDWallet) GetMasterKeyPair added in v0.11.0

func (w *HDWallet) GetMasterKeyPair() (MasterKeyPair, error)

GetMasterKeyPair returns all the information associated to a master key pair.

func (*HDWallet) ID

func (w *HDWallet) ID() string

func (*HDWallet) IsIsolated

func (w *HDWallet) IsIsolated() bool

func (*HDWallet) IsolateWithKey

func (w *HDWallet) IsolateWithKey(pubKey string) (Wallet, error)

func (*HDWallet) ListKeyPairs

func (w *HDWallet) ListKeyPairs() []KeyPair

ListKeyPairs lists the key pairs. Be careful, it contains the private key.

func (*HDWallet) ListPublicKeys

func (w *HDWallet) ListPublicKeys() []PublicKey

ListPublicKeys lists the public keys with their information. The private keys are not returned.

func (*HDWallet) MarshalJSON

func (w *HDWallet) MarshalJSON() ([]byte, error)

func (*HDWallet) Name

func (w *HDWallet) Name() string

func (*HDWallet) SetName

func (w *HDWallet) SetName(newName string)

func (*HDWallet) SignAny

func (w *HDWallet) SignAny(pubKey string, data []byte) ([]byte, error)

func (*HDWallet) SignTx

func (w *HDWallet) SignTx(pubKey string, data []byte) (*Signature, error)

func (*HDWallet) TaintKey

func (w *HDWallet) TaintKey(pubKey string) error

TaintKey marks a key as tainted.

func (*HDWallet) Type

func (w *HDWallet) Type() string

func (*HDWallet) UnmarshalJSON

func (w *HDWallet) UnmarshalJSON(data []byte) error

func (*HDWallet) UntaintKey

func (w *HDWallet) UntaintKey(pubKey string) error

UntaintKey remove the taint on a key.

func (*HDWallet) UpdateMeta

func (w *HDWallet) UpdateMeta(pubKey string, meta []Meta) error

UpdateMeta replaces the key's metadata by the new ones.

func (*HDWallet) VerifyAny

func (w *HDWallet) VerifyAny(pubKey string, data, sig []byte) (bool, error)

func (*HDWallet) Version

func (w *HDWallet) Version() uint32

type ImportWalletRequest added in v0.10.0

type ImportWalletRequest struct {
	Wallet         string `json:"wallet"`
	RecoveryPhrase string `json:"recoveryPhrase"`
	Version        uint32 `json:"version"`
	Passphrase     string `json:"passphrase"`
}

type ImportWalletResponse added in v0.10.0

type ImportWalletResponse struct {
	Wallet ImportedWallet `json:"wallet"`
	Key    FirstPublicKey `json:"key"`
}

func ImportWallet added in v0.10.0

func ImportWallet(store Store, req *ImportWalletRequest) (*ImportWalletResponse, error)

type ImportedWallet added in v0.13.0

type ImportedWallet struct {
	Name     string `json:"name"`
	Version  uint32 `json:"version"`
	FilePath string `json:"filePath"`
}

type Info

type Info struct {
	ID   string `json:"id,omitempty"`
	Type string `json:"type"`
}

type IsolateKeyRequest added in v0.10.0

type IsolateKeyRequest struct {
	Wallet     string `json:"wallet"`
	PubKey     string `json:"pubKey"`
	Passphrase string `json:"passphrase"`
}

type IsolateKeyResponse added in v0.10.0

type IsolateKeyResponse struct {
	Wallet   string `json:"wallet"`
	FilePath string `json:"filePath"`
}

func IsolateKey added in v0.10.0

func IsolateKey(store Store, req *IsolateKeyRequest) (*IsolateKeyResponse, error)

type KeyPair

type KeyPair interface {
	PublicKey() string
	PrivateKey() string
	IsTainted() bool
	Meta() []Meta
	Index() uint32
	AlgorithmVersion() uint32
	AlgorithmName() string
	SignAny(data []byte) ([]byte, error)
	VerifyAny(data, sig []byte) (bool, error)
	Sign(data []byte) (*Signature, error)
}

type ListKeysRequest added in v0.10.0

type ListKeysRequest struct {
	Wallet     string `json:"wallet"`
	Passphrase string `json:"passphrase"`
}

type ListKeysResponse added in v0.10.0

type ListKeysResponse struct {
	Keys []NamedPubKey `json:"keys"`
}

func ListKeys added in v0.10.0

func ListKeys(store Store, req *ListKeysRequest) (*ListKeysResponse, error)

type ListWalletsResponse added in v0.10.0

type ListWalletsResponse struct {
	Wallets []string `json:"wallets"`
}

func ListWallets added in v0.10.0

func ListWallets(store Store) (*ListWalletsResponse, error)

type MasterKeyPair added in v0.11.0

type MasterKeyPair interface {
	PublicKey() string
	PrivateKey() string
	AlgorithmVersion() uint32
	AlgorithmName() string
	SignAny(data []byte) ([]byte, error)
	Sign(data []byte) (*Signature, error)
}

type Meta

type Meta struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type NamedPubKey added in v0.10.0

type NamedPubKey struct {
	Name      string `json:"name"`
	PublicKey string `json:"publicKey"`
}

type PublicKey

type PublicKey interface {
	Key() string
	IsTainted() bool
	Meta() []Meta
	Index() uint32
	AlgorithmVersion() uint32
	AlgorithmName() string
	Hash() (string, error)

	MarshalJSON() ([]byte, error)
	UnmarshalJSON(data []byte) error
}

type RotateKeyRequest added in v0.11.0

type RotateKeyRequest struct {
	Wallet            string `json:"wallet"`
	Passphrase        string `json:"passphrase"`
	NewPublicKey      string `json:"newPublicKey"`
	CurrentPublicKey  string `json:"currentPublicKey"`
	TxBlockHeight     uint64 `json:"txBlockHeight"`
	TargetBlockHeight uint64 `json:"targetBlockHeight"`
}

type RotateKeyResponse added in v0.11.0

type RotateKeyResponse struct {
	MasterPublicKey   string `json:"masterPublicKey"`
	Base64Transaction string `json:"base64Transaction"`
}

func RotateKey added in v0.11.0

func RotateKey(store Store, req *RotateKeyRequest) (*RotateKeyResponse, error)

type SignCommandRequest added in v0.11.1

type SignCommandRequest struct {
	Wallet        string `json:"wallet"`
	Passphrase    string `json:"passphrase"`
	TxBlockHeight uint64 `json:"txBlockHeight"`

	Request *walletpb.SubmitTransactionRequest `json:"request"`
}

type SignCommandResponse added in v0.11.1

type SignCommandResponse struct {
	Base64Transaction string `json:"base64Transaction"`
}

func SignCommand added in v0.11.1

func SignCommand(store Store, req *SignCommandRequest) (*SignCommandResponse, error)

type SignMessageRequest added in v0.10.0

type SignMessageRequest struct {
	Wallet     string `json:"wallet"`
	PubKey     string `json:"pubKey"`
	Message    []byte `json:"message"`
	Passphrase string `json:"passphrase"`
}

type SignMessageResponse added in v0.10.0

type SignMessageResponse struct {
	Base64 string `json:"hexSignature"`
	Bytes  []byte `json:"bytesSignature"`
}

func SignMessage added in v0.10.0

func SignMessage(store Store, req *SignMessageRequest) (*SignMessageResponse, error)

type Signature

type Signature struct {
	// Value is hex-encoded
	Value   string `json:"value"`
	Algo    string `json:"algo"`
	Version uint32 `json:"version"`
}

type Store added in v0.10.0

type Store interface {
	WalletExists(name string) bool
	SaveWallet(w Wallet, passphrase string) error
	GetWallet(name, passphrase string) (Wallet, error)
	GetWalletPath(name string) string
	ListWallets() ([]string, error)
}

type TaintKeyRequest added in v0.10.0

type TaintKeyRequest struct {
	Wallet     string `json:"wallet"`
	PubKey     string `json:"pubKey"`
	Passphrase string `json:"passphrase"`
}

type UnsupportedWalletVersionError added in v0.9.2

type UnsupportedWalletVersionError struct {
	UnsupportedVersion uint32
}

func NewUnsupportedWalletVersionError added in v0.9.2

func NewUnsupportedWalletVersionError(v uint32) UnsupportedWalletVersionError

func (UnsupportedWalletVersionError) Error added in v0.9.2

type UntaintKeyRequest added in v0.10.0

type UntaintKeyRequest struct {
	Wallet     string `json:"wallet"`
	PubKey     string `json:"pubKey"`
	Passphrase string `json:"passphrase"`
}

type Wallet

type Wallet interface {
	Version() uint32
	Name() string
	SetName(newName string)
	ID() string
	Type() string
	DescribePublicKey(pubKey string) (PublicKey, error)
	DescribeKeyPair(pubKey string) (KeyPair, error)
	ListPublicKeys() []PublicKey
	ListKeyPairs() []KeyPair
	GetMasterKeyPair() (MasterKeyPair, error)
	GenerateKeyPair(meta []Meta) (KeyPair, error)
	TaintKey(pubKey string) error
	UntaintKey(pubKey string) error
	UpdateMeta(pubKey string, meta []Meta) error
	SignAny(pubKey string, data []byte) ([]byte, error)
	VerifyAny(pubKey string, data, sig []byte) (bool, error)
	SignTx(pubKey string, data []byte) (*Signature, error)
	IsolateWithKey(pubKey string) (Wallet, error)
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
store
v1

Jump to

Keyboard shortcuts

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