wallet

package
v1.6.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: Apache-2.0, MIT Imports: 34 Imported by: 4

Documentation

Index

Constants

View Source
const (
	Lock
	Unlock
)
View Source
const (
	MTUnknown = MsgType("unknown")

	// Signing message CID. MsgMeta.Extra contains raw cbor message bytes
	MTChainMsg = MsgType("message")

	// Signing a blockheader. signing raw cbor block bytes (MsgMeta.Extra is empty)
	MTBlock = MsgType("block")

	// Signing a deal proposal. signing raw cbor proposal bytes (MsgMeta.Extra is empty)
	MTDealProposal = MsgType("dealproposal")
	// extra is nil, 'toSign' is cbor raw bytes of 'DrawRandomParams'
	//  following types follow above rule
	MTDrawRandomParam = MsgType("drawrandomparam")
	MTSignedVoucher   = MsgType("signedvoucher")
	MTStorageAsk      = MsgType("storageask")
	MTAskResponse     = MsgType("askresponse")
	MTNetWorkResponse = MsgType("networkresposne")

	// reference : storagemarket/impl/remotecli.go:330
	// sign storagemarket.ClientDeal.ProposalCid,
	// MsgMeta.Extra is nil, 'toSign' is market.ClientDealProposal
	// storagemarket.ClientDeal.ProposalCid equals cborutil.AsIpld(market.ClientDealProposal).Cid()
	MTClientDeal = MsgType("clientdeal")

	MTProviderDealState = MsgType("providerdealstate")
)
View Source
const (
	SigTypeUnknown = SigType(math.MaxUint8)

	SigTypeSecp256k1 = SigType(iota)
	SigTypeBLS
)
View Source
const StringEmpty = ""

Variables

View Source
var DSBackendType = reflect.TypeOf(&DSBackend{})

DSBackendType is the reflect type of the DSBackend.

View Source
var ErrDecrypt = errors.New("could not decrypt key with given password")
View Source
var ErrInvalidPassword = errors.New("password matching failed")
View Source
var ErrKeyInfoNotFound = fmt.Errorf("key info not found")
View Source
var ErrRepeatPassword = errors.New("set password more than once")
View Source
var (
	NilAddress = Address{}
)
View Source
var TestPassword = []byte("test-password")

Functions

This section is empty.

Types

type Address added in v0.9.7

type Address = address.Address

type AddressScope added in v0.9.7

type AddressScope struct {
	Root      bool      // is root auth,  true : can get all addresses in the wallet
	Addresses []Address // when root==false, should fill a scope of wallet addresses
}

type Backend

type Backend interface {
	// Addresses returns a list of all accounts currently stored in this backend.
	Addresses(ctx context.Context) []address.Address

	// Contains returns true if this backend stores the passed in address.
	HasAddress(context.Context, address.Address) bool

	// Sign cryptographically signs data with the private key associated with an address.
	SignBytes(context.Context, []byte, address.Address) (*crypto.Signature, error)

	// GetKeyInfo will return the keyinfo associated with address `addr`
	// iff backend contains the addr.
	GetKeyInfo(context.Context, address.Address) (*crypto.KeyInfo, error)

	GetKeyInfoPassphrase(context.Context, address.Address, []byte) (*crypto.KeyInfo, error)

	LockWallet(context.Context) error
	UnLockWallet(context.Context, []byte) error
	WalletState(context.Context) int
}

Backend is the interface to represent different storage backends that can contain many addresses.

type Cid added in v0.9.7

type Cid = cid.Cid

type CryptoJSON added in v0.9.1

type CryptoJSON struct {
	Cipher       string                 `json:"cipher"`
	CipherText   string                 `json:"ciphertext"`
	CipherParams cipherParams           `json:"cipherparams"`
	KDF          string                 `json:"kdf"`
	KDFParams    map[string]interface{} `json:"kdfparams"`
	MAC          string                 `json:"mac"`
}

type DSBackend

type DSBackend struct {
	PassphraseConf config.PassphraseConfig
	// contains filtered or unexported fields
}

DSBackend is a wallet backend implementation for storing addresses in a datastore.

func NewDSBackend

func NewDSBackend(ctx context.Context, ds repo.Datastore, passphraseCfg config.PassphraseConfig, password []byte) (*DSBackend, error)

NewDSBackend constructs a new backend using the passed in datastore.

func (*DSBackend) Addresses

func (backend *DSBackend) Addresses(ctx context.Context) []address.Address

Addresses returns a list of all addresses that are stored in this backend.

func (*DSBackend) GetKeyInfo

func (backend *DSBackend) GetKeyInfo(ctx context.Context, addr address.Address) (*crypto.KeyInfo, error)

GetKeyInfo will return the private & public keys associated with address `addr` iff backend contains the addr.

func (*DSBackend) GetKeyInfoPassphrase added in v0.9.1

func (backend *DSBackend) GetKeyInfoPassphrase(ctx context.Context, addr address.Address, password []byte) (*crypto.KeyInfo, error)

GetKeyInfoPassphrase get private private key from wallet, get encrypt byte from db and decrypto it with password

func (*DSBackend) HasAddress

func (backend *DSBackend) HasAddress(ctx context.Context, addr address.Address) bool

HasAddress checks if the passed in address is stored in this backend. Safe for concurrent access.

func (*DSBackend) HasPassword added in v0.9.4

func (backend *DSBackend) HasPassword() bool

HasPassword return whether the password has been set in the wallet

func (*DSBackend) ImportKey

func (backend *DSBackend) ImportKey(ctx context.Context, ki *crypto.KeyInfo) error

ImportKey loads the address in `ai` and KeyInfo `ki` into the backend

func (*DSBackend) LockWallet added in v0.9.7

func (backend *DSBackend) LockWallet(ctx context.Context) error

func (*DSBackend) NewAddress

func (backend *DSBackend) NewAddress(ctx context.Context, protocol address.Protocol) (address.Address, error)

NewAddress creates a new address and stores it. Safe for concurrent access.

func (*DSBackend) SetPassword added in v0.9.1

func (backend *DSBackend) SetPassword(ctx context.Context, password []byte) error

SetPassword set password for wallet , and wallet used this password to encrypt private key

func (*DSBackend) SignBytes

func (backend *DSBackend) SignBytes(ctx context.Context, data []byte, addr address.Address) (*crypto.Signature, error)

SignBytes cryptographically signs `data` using the private key `priv`.

func (*DSBackend) UnLockWallet added in v0.9.7

func (backend *DSBackend) UnLockWallet(ctx context.Context, password []byte) error

UnLockWallet unlock wallet with password, decrypt local key in db and save to protected memory

func (*DSBackend) UsePassword added in v0.9.7

func (backend *DSBackend) UsePassword(f func(password []byte) error) error

func (*DSBackend) WalletState added in v0.9.4

func (backend *DSBackend) WalletState(ctx context.Context) int

WalletState return wallet state(lock/unlock)

type Importer

type Importer interface {
	// ImportKey imports the key described by the given keyinfo
	// into the backend
	ImportKey(context.Context, *crypto.KeyInfo) error
}

Importer is a specialization of a wallet backend that can import new keys into its permanent storage. Disk backed wallets can do this, hardware wallets generally cannot.

type KeccakState added in v0.9.1

type KeccakState interface {
	hash.Hash
	Read([]byte) (int, error)
}

KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of data from the hash state. Read is faster than Sum because it doesn't copy the internal state, but also modifies the internal state.

type Key added in v0.9.1

type Key struct {
	ID uuid.UUID // Version 4 "random" for unique id not derived from key data
	// to simplify lookups we also store the address
	Address address.Address
	KeyInfo *crypto.KeyInfo
}

Key private key info

func (*Key) MarshalJSON added in v0.9.1

func (k *Key) MarshalJSON() (j []byte, err error)

func (*Key) UnmarshalJSON added in v0.9.1

func (k *Key) UnmarshalJSON(j []byte) (err error)

type KeyInfo added in v0.9.7

type KeyInfo struct {
	Type       KeyType
	PrivateKey []byte
}

type KeyType added in v0.9.7

type KeyType string

KeyType defines a type of a key

const (
	KTUnknown   KeyType = "unknown"
	KTBLS       KeyType = "bls"
	KTSecp256k1 KeyType = "secp256k1"
)

func SignType2Key added in v0.9.7

func SignType2Key(kt SigType) KeyType

func (*KeyType) UnmarshalJSON added in v0.9.7

func (kt *KeyType) UnmarshalJSON(bb []byte) error

type MethodNum added in v0.9.7

type MethodNum = abi.MethodNum

type MsgMeta

type MsgMeta struct {
	Type MsgType
	// Additional data related to what is signed. Should be verifiable with the
	// signed bytes (e.g. CID(Extra).Bytes() == toSign)
	Extra []byte
}

type MsgType

type MsgType string

type SigType added in v0.9.7

type SigType = crypto.SigType

func KeyType2Sign added in v0.9.7

func KeyType2Sign(kt KeyType) SigType

type Signature added in v0.9.7

type Signature = crypto.Signature

type TokenAmount added in v0.9.7

type TokenAmount = abi.TokenAmount

type Wallet

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

wallet manages the locally stored addresses.

func New

func New(backends ...Backend) *Wallet

New constructs a new wallet, that manages addresses in all the passed in backends.

func (*Wallet) Addresses

func (w *Wallet) Addresses(ctx context.Context) []address.Address

Addresses retrieves all stored addresses. Safe for concurrent access. Always sorted in the same order.

func (*Wallet) Backends

func (w *Wallet) Backends(typ reflect.Type) []Backend

Backends returns backends by their type.

func (*Wallet) DSBacked added in v0.9.1

func (w *Wallet) DSBacked() (*DSBackend, error)

DSBacked return the first wallet backend todo support multi wallet backend

func (*Wallet) Export

func (w *Wallet) Export(ctx context.Context, addr address.Address, password string) (*crypto.KeyInfo, error)

Export returns the KeyInfos for the given wallet addresses

func (*Wallet) Find

func (w *Wallet) Find(ctx context.Context, addr address.Address) (Backend, error)

Find searches through all backends and returns the one storing the passed in address. Safe for concurrent access.

func (*Wallet) GetPubKeyForAddress

func (w *Wallet) GetPubKeyForAddress(ctx context.Context, addr address.Address) ([]byte, error)

GetPubKeyForAddress returns the public key in the keystore associated with the given address.

func (*Wallet) HasAddress

func (w *Wallet) HasAddress(ctx context.Context, a address.Address) bool

HasAddress checks if the given address is stored. Safe for concurrent access.

func (*Wallet) HasPassword added in v0.9.4

func (w *Wallet) HasPassword(ctx context.Context) bool

HasPassword return whether the password has been set in the wallet

func (*Wallet) Import

func (w *Wallet) Import(ctx context.Context, ki *crypto.KeyInfo) (address.Address, error)

Import adds the given keyinfo to the wallet

func (*Wallet) LockWallet added in v0.9.7

func (w *Wallet) LockWallet(ctx context.Context) error

LockWallet lock lock wallet

func (*Wallet) NewAddress added in v0.9.1

func (w *Wallet) NewAddress(ctx context.Context, p address.Protocol) (address.Address, error)

NewAddress creates a new account address on the default wallet backend.

func (*Wallet) NewKeyInfo

func (w *Wallet) NewKeyInfo(ctx context.Context) (*crypto.KeyInfo, error)

NewKeyInfo creates a new KeyInfo struct in the wallet backend and returns it

func (*Wallet) SetPassword added in v0.9.1

func (w *Wallet) SetPassword(ctx context.Context, password []byte) error

SetPassword

func (*Wallet) SignBytes

func (w *Wallet) SignBytes(ctx context.Context, data []byte, addr address.Address) (*crypto.Signature, error)

SignBytes cryptographically signs `data` using the private key corresponding to address `addr`

func (*Wallet) UnLockWallet added in v0.9.7

func (w *Wallet) UnLockWallet(ctx context.Context, password []byte) error

func (*Wallet) WalletSign

func (w *Wallet) WalletSign(ctx context.Context, addr address.Address, msg []byte, meta types.MsgMeta) (*crypto.Signature, error)

WalletSign used to sign message with private key

func (*Wallet) WalletState added in v0.9.4

func (w *Wallet) WalletState(ctx context.Context) int

WalletState return wallet state(lock/unlock)

type WalletIntersection added in v0.9.4

type WalletIntersection interface {
	HasAddress(ctx context.Context, a address.Address) bool
	Addresses(ctx context.Context) []address.Address
	NewAddress(ctx context.Context, p address.Protocol) (address.Address, error)
	Import(ctx context.Context, ki *crypto.KeyInfo) (address.Address, error)
	Export(ctx context.Context, addr address.Address, password string) (*crypto.KeyInfo, error)
	WalletSign(ctx context.Context, keyAddr address.Address, msg []byte, meta types.MsgMeta) (*crypto.Signature, error)
	HasPassword(ctx context.Context) bool
}

WalletIntersection nolint

Jump to

Keyboard shortcuts

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