wallet

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2019 License: MIT Imports: 6 Imported by: 64

Documentation

Overview

Package wallet defines an abstraction to wallet providers. It provides an interface to connect other packages to a wallet provider. Wallet providers can be hardware, software remote or local wallets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexOfAddr

func IndexOfAddr(addrs []Address, addr Address) int

IndexOfAddr returns the index of the given address in the address slice, or -1 if it is not part of the slice.

func SetBackend

func SetBackend(b Backend)

SetBackend sets the global wallet backend. Must not be called directly but through backend.Set().

func SetBackendTest

func SetBackendTest(t *testing.T)

func VerifySignature

func VerifySignature(msg []byte, sign Sig, a Address) (bool, error)

VerifySignature calls VerifySignature of the current backend

Types

type Account

type Account interface {
	// Address used by this account.
	Address() Address

	// SignData requests a signature from this account.
	// It returns the signature or an error.
	SignData(data []byte) ([]byte, error)
}

Account represents a single account.

type Address

type Address interface {
	io.Serializable
	// Bytes should return the representation of the address as byte slice.
	Bytes() []byte
	// String converts this address to a string
	fmt.Stringer
	// Equals checks the equality of two addresses
	Equals(Address) bool
}

Address represents a identifier used in a cryptocurrency. It is dependent on the currency and needs to be implemented for every blockchain.

func DecodeAddress

func DecodeAddress(r io.Reader) (Address, error)

DecodeAddress calls DecodeAddress of the current backend

func NewAddressFromBytes

func NewAddressFromBytes(data []byte) (Address, error)

NewAddressFromBytes calls NewAddressFromBytes of the current backend

type Backend

type Backend interface {
	// NewAddressFromBytes creates a new address from a byte array.
	NewAddressFromBytes(data []byte) (Address, error)

	// DecodeAddress reads and decodes an address from an io.Writer
	DecodeAddress(io.Reader) (Address, error)

	// DecodeSig reads a signature from the provided stream. It is needed for
	// decoding of wire messages.
	DecodeSig(io.Reader) (Sig, error)

	// VerifySignature verifies if this signature was signed by this address.
	// It should return an error iff the signature or message are malformed.
	// If the signature does not match the address it should return false, nil
	VerifySignature(msg []byte, sign Sig, a Address) (bool, error)
}

Backend provides useful methods for this blockchain.

type Sig

type Sig = []byte

Sig is a single signature

func DecodeSig

func DecodeSig(r io.Reader) (Sig, error)

DecodeSig calls DecodeSig of the current backend

type Wallet

type Wallet interface {
	// Path returns an identifier under which this wallet is located.
	// Should return an empty string if the wallet was not properly initialized.
	Path() string

	// Connect establishes a connection to a wallet.
	// It should not decrypt the keys.
	// Returns an error if a connection cannot be established.
	Connect(path, password string) error

	// Disconnect closes a connection to a wallet and locks all accounts.
	// It returns an error if no connection is currently established to the wallet.
	Disconnect() error

	// Status returns the current status of the wallet.
	// Returns an error if the wallet is in a non-usable state (e.g. if no connection is established).
	Status() (string, error)

	// Accounts returns all accounts associated with this wallet.
	// Should return an empty byteslice if no accounts are found.
	Accounts() []Account

	// Contains checks whether this wallet contains this account.
	Contains(a Account) bool
}

Wallet represents a single or multiple accounts on a hardware or software wallet.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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