driver

package
v0.0.0-...-15eb78e Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// PTMasterKey is the plaintext type for the master key
	PTMasterKey plaintextType = "master_key"
	// PTSecretKey is the plaintext type for a regular ed25519 secret key
	PTSecretKey plaintextType = "secret_key"
	// PTMasterDerivationKey is the plaintext type for the master derivation key
	PTMasterDerivationKey plaintextType = "master_derivation_key"
	// PTMaxKeyIdx is the plaintext type for the maximum key index
	PTMaxKeyIdx plaintextType = "max_key_idx"
)

Functions

func FetchWalletByID

func FetchWalletByID(id []byte) (wallet.Wallet, error)

FetchWalletByID iterates over the wallet drivers and returns a wallet with the passed ID

func InitWalletDrivers

func InitWalletDrivers(cfg config.KMDConfig, log logging.Logger) error

InitWalletDrivers accepts a KMDConfig and uses it to initialize each driver

func LedgerEnumerate

func LedgerEnumerate() ([]hid.DeviceInfo, error)

LedgerEnumerate returns all of the Ledger devices connected to this machine.

func ListWalletDriverNames

func ListWalletDriverNames() []string

ListWalletDriverNames returns a list of names of the wallet drivers that kmd is aware of

func ListWalletMetadatas

func ListWalletMetadatas() ([]wallet.Metadata, error)

ListWalletMetadatas fetches wallet metadata from all of the drivers

Types

type Driver

type Driver interface {
	InitWithConfig(cfg config.KMDConfig, log logging.Logger) error
	ListWalletMetadatas() ([]wallet.Metadata, error)
	CreateWallet(name []byte, id []byte, pw []byte, mdk crypto.MasterDerivationKey) error
	RenameWallet(newName []byte, id []byte, pw []byte) error
	FetchWallet(id []byte) (wallet.Wallet, error)
}

Driver is the interface that all wallet drivers must expose in order to be compatible with kmd. In particular, wallet drivers must be able to initialize themselves from a Config, create a wallet with a name, ID, and password, and fetch a wallet by ID.

func FetchWalletDriver

func FetchWalletDriver(driverName string) (Driver, error)

FetchWalletDriver accepts a driver name and returns a corresponding instance of the appropriate wallet driver, or nil

type LedgerUSB

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

LedgerUSB is a wrapper around a Ledger USB HID device, used to implement the protocol used for sending messages to the application running on the Ledger hardware wallet.

func (*LedgerUSB) Exchange

func (l *LedgerUSB) Exchange(msg []byte) ([]byte, error)

Exchange sends a message to the Ledger device, waits for a response, and returns the response data.

func (*LedgerUSB) ReadPackets

func (l *LedgerUSB) ReadPackets() ([]byte, error)

ReadPackets reads a message from the Ledger device, assembling multiple packets as needed.

func (*LedgerUSB) USBInfo

func (l *LedgerUSB) USBInfo() hid.DeviceInfo

USBInfo returns information about the underlying USB device.

func (*LedgerUSB) WritePackets

func (l *LedgerUSB) WritePackets(msg []byte) error

WritePackets sends a message to the Ledger device, by breaking it up into multiple packets as needed.

type LedgerUSBError

type LedgerUSBError uint16

LedgerUSBError is a wrapper around the two-byte error code that the Ledger protocol returns.

func (LedgerUSBError) Error

func (err LedgerUSBError) Error() string

Error satisfies builtin interface `error`

type LedgerWallet

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

LedgerWallet represents a particular wallet under the LedgerWalletDriver. The lock prevents concurrent access to the USB device.

func (*LedgerWallet) CheckPassword

func (lw *LedgerWallet) CheckPassword(pw []byte) error

CheckPassword implements the Wallet interface.

func (*LedgerWallet) DeleteKey

func (lw *LedgerWallet) DeleteKey(pk crypto.Digest, pw []byte) error

DeleteKey implements the Wallet interface.

func (*LedgerWallet) DeleteMultisigAddr

func (lw *LedgerWallet) DeleteMultisigAddr(addr crypto.Digest, pw []byte) error

DeleteMultisigAddr implements the Wallet interface.

func (*LedgerWallet) ExportKey

func (lw *LedgerWallet) ExportKey(pk crypto.Digest, pw []byte) (crypto.PrivateKey, error)

ExportKey implements the Wallet interface.

func (*LedgerWallet) ExportMasterDerivationKey

func (lw *LedgerWallet) ExportMasterDerivationKey(pw []byte) (crypto.MasterDerivationKey, error)

ExportMasterDerivationKey implements the Wallet interface.

func (*LedgerWallet) GenerateKey

func (lw *LedgerWallet) GenerateKey(displayMnemonic bool) (crypto.Digest, error)

GenerateKey implements the Wallet interface.

func (*LedgerWallet) ImportKey

func (lw *LedgerWallet) ImportKey(sk crypto.PrivateKey) (crypto.Digest, error)

ImportKey implements the Wallet interface.

func (*LedgerWallet) ImportMultisigAddr

func (lw *LedgerWallet) ImportMultisigAddr(version, threshold uint8, pks []crypto.PublicKey) (crypto.Digest, error)

ImportMultisigAddr implements the Wallet interface.

func (*LedgerWallet) Init

func (lw *LedgerWallet) Init(pw []byte) error

Init implements the wallet interface.

func (*LedgerWallet) ListKeys

func (lw *LedgerWallet) ListKeys() ([]crypto.Digest, error)

ListKeys implements the Wallet interface.

func (*LedgerWallet) ListMultisigAddrs

func (lw *LedgerWallet) ListMultisigAddrs() (addrs []crypto.Digest, err error)

ListMultisigAddrs implements the Wallet interface.

func (*LedgerWallet) LookupMultisigPreimage

func (lw *LedgerWallet) LookupMultisigPreimage(crypto.Digest) (version, threshold uint8, pks []crypto.PublicKey, err error)

LookupMultisigPreimage implements the Wallet interface.

func (*LedgerWallet) Metadata

func (lw *LedgerWallet) Metadata() (wallet.Metadata, error)

Metadata implements the Wallet interface.

func (*LedgerWallet) MultisigSignProgram

func (lw *LedgerWallet) MultisigSignProgram(data []byte, src crypto.Digest, pk crypto.PublicKey, partial crypto.MultisigSig, pw []byte) (crypto.MultisigSig, error)

MultisigSignProgram implements the Wallet interface.

func (*LedgerWallet) MultisigSignTransaction

func (lw *LedgerWallet) MultisigSignTransaction(tx transactions.Transaction, pk crypto.PublicKey, partial crypto.MultisigSig, pw []byte, signer crypto.Digest) (crypto.MultisigSig, error)

MultisigSignTransaction implements the Wallet interface.

func (*LedgerWallet) SignProgram

func (lw *LedgerWallet) SignProgram(data []byte, src crypto.Digest, pw []byte) ([]byte, error)

SignProgram implements the Wallet interface.

func (*LedgerWallet) SignTransaction

func (lw *LedgerWallet) SignTransaction(tx transactions.Transaction, pk crypto.PublicKey, pw []byte) ([]byte, error)

SignTransaction implements the Wallet interface.

type LedgerWalletDriver

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

LedgerWalletDriver provides access to a hardware wallet on the Ledger Nano S device. The device must run the Algorand wallet application from https://github.com/algorand/ledger-app-algorand

func (*LedgerWalletDriver) CreateWallet

func (lwd *LedgerWalletDriver) CreateWallet(name []byte, id []byte, pw []byte, mdk crypto.MasterDerivationKey) error

CreateWallet implements the Driver interface. There is currently no way to create new wallet keys; there is one key in a hardware wallet, derived from the device master secret. We could, in principle, derive multiple keys. This is not supported at the moment.

func (*LedgerWalletDriver) FetchWallet

func (lwd *LedgerWalletDriver) FetchWallet(id []byte) (w wallet.Wallet, err error)

FetchWallet looks up a wallet by ID and returns it, failing if there's more than one wallet with the given ID

func (*LedgerWalletDriver) InitWithConfig

func (lwd *LedgerWalletDriver) InitWithConfig(cfg config.KMDConfig, log logging.Logger) error

InitWithConfig accepts a driver configuration. Currently, the Ledger driver does not have any configuration parameters. However, we use this to enumerate the USB devices.

func (*LedgerWalletDriver) ListWalletMetadatas

func (lwd *LedgerWalletDriver) ListWalletMetadatas() (metadatas []wallet.Metadata, err error)

ListWalletMetadatas returns all wallets supported by this driver.

func (*LedgerWalletDriver) RenameWallet

func (lwd *LedgerWalletDriver) RenameWallet(newName []byte, id []byte, pw []byte) error

RenameWallet implements the Driver interface.

type SQLiteWallet

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

SQLiteWallet represents a particular SQLiteWallet under the SQLiteWalletDriver

func (*SQLiteWallet) CheckPassword

func (sw *SQLiteWallet) CheckPassword(pw []byte) error

CheckPassword checks that the database can be decrypted with the password. It's the same as Init but doesn't store the decrypted key

func (*SQLiteWallet) DeleteKey

func (sw *SQLiteWallet) DeleteKey(addr crypto.Digest, pw []byte) (err error)

DeleteKey deletes the key corresponding to the passed public key from the wallet

func (*SQLiteWallet) DeleteMultisigAddr

func (sw *SQLiteWallet) DeleteMultisigAddr(addr crypto.Digest, pw []byte) (err error)

DeleteMultisigAddr deletes the multisig address and preimage from the database

func (*SQLiteWallet) ExportKey

func (sw *SQLiteWallet) ExportKey(addr crypto.Digest, pw []byte) (sk crypto.PrivateKey, err error)

ExportKey fetches the encrypted private key using the public key, decrypts it, verifies that it matches the passed public key, and returns it

func (*SQLiteWallet) ExportMasterDerivationKey

func (sw *SQLiteWallet) ExportMasterDerivationKey(pw []byte) (mdk crypto.MasterDerivationKey, err error)

ExportMasterDerivationKey decrypts the encrypted MDK and returns it

func (*SQLiteWallet) GenerateKey

func (sw *SQLiteWallet) GenerateKey(displayMnemonic bool) (addr crypto.Digest, err error)

GenerateKey generates a key from system entropy and imports it

func (*SQLiteWallet) ImportKey

func (sw *SQLiteWallet) ImportKey(rawSK crypto.PrivateKey) (addr crypto.Digest, err error)

ImportKey imports a keypair into the wallet, deriving the public key from the passed secret key

func (*SQLiteWallet) ImportMultisigAddr

func (sw *SQLiteWallet) ImportMultisigAddr(version, threshold uint8, pks []crypto.PublicKey) (addr crypto.Digest, err error)

ImportMultisigAddr imports a multisig address, taking in version, threshold, and public keys

func (*SQLiteWallet) Init

func (sw *SQLiteWallet) Init(pw []byte) error

Init attempts to decrypt the master encrypt password and master derivation key, and store them in memory for subsequent operations

func (*SQLiteWallet) ListKeys

func (sw *SQLiteWallet) ListKeys() (addrs []crypto.Digest, err error)

ListKeys lists all the addresses in the wallet

func (*SQLiteWallet) ListMultisigAddrs

func (sw *SQLiteWallet) ListMultisigAddrs() (addrs []crypto.Digest, err error)

ListMultisigAddrs lists the multisig addresses whose preimages we know

func (*SQLiteWallet) LookupMultisigPreimage

func (sw *SQLiteWallet) LookupMultisigPreimage(addr crypto.Digest) (version, threshold uint8, pks []crypto.PublicKey, err error)

LookupMultisigPreimage exports the preimage of a multisig address: version, threshold, public keys

func (*SQLiteWallet) Metadata

func (sw *SQLiteWallet) Metadata() (meta wallet.Metadata, err error)

Metadata builds a wallet.Metadata from our metadata table

func (*SQLiteWallet) MultisigSignProgram

func (sw *SQLiteWallet) MultisigSignProgram(data []byte, src crypto.Digest, pk crypto.PublicKey, partial crypto.MultisigSig, pw []byte) (sig crypto.MultisigSig, err error)

MultisigSignProgram starts a multisig signature or adds a signature to a partially signed multisig transaction signature of the passed transaction using the key

func (*SQLiteWallet) MultisigSignTransaction

func (sw *SQLiteWallet) MultisigSignTransaction(tx transactions.Transaction, pk crypto.PublicKey, partial crypto.MultisigSig, pw []byte, signer crypto.Digest) (sig crypto.MultisigSig, err error)

MultisigSignTransaction starts a multisig signature or adds a signature to a partially signed multisig transaction signature of the passed transaction using the key

func (*SQLiteWallet) SignProgram

func (sw *SQLiteWallet) SignProgram(data []byte, src crypto.Digest, pw []byte) (stx []byte, err error)

SignProgram signs the passed data for the src address

func (*SQLiteWallet) SignTransaction

func (sw *SQLiteWallet) SignTransaction(tx transactions.Transaction, pk crypto.PublicKey, pw []byte) (stx []byte, err error)

SignTransaction signs the passed transaction with the private key whose public key is provided, or if the provided public key is zero, inferring the required private key from the transaction itself

type SQLiteWalletDriver

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

SQLiteWalletDriver is the default wallet driver used by kmd. Keys are stored as authenticated-encrypted blobs in a sqlite 3 database.

func (*SQLiteWalletDriver) CreateWallet

func (swd *SQLiteWalletDriver) CreateWallet(name []byte, id []byte, pw []byte, mdk crypto.MasterDerivationKey) error

CreateWallet ensures that a wallet of the given name/id combo doesn't exist, and initializes a database with the appropriate name.

func (*SQLiteWalletDriver) FetchWallet

func (swd *SQLiteWalletDriver) FetchWallet(id []byte) (sqWallet wallet.Wallet, err error)

FetchWallet looks up a wallet by ID and returns it, failing if there's more than one wallet with the given ID

func (*SQLiteWalletDriver) InitWithConfig

func (swd *SQLiteWalletDriver) InitWithConfig(cfg config.KMDConfig, log logging.Logger) error

InitWithConfig accepts a driver configuration so that the SQLite driver knows where to read and write its wallet databases

func (*SQLiteWalletDriver) ListWalletMetadatas

func (swd *SQLiteWalletDriver) ListWalletMetadatas() (metadatas []wallet.Metadata, err error)

ListWalletMetadatas opens everything that looks like a wallet in the walletsDir() and tries to extract its metadata. It does not fail if it is unable to read metadata from one of the files it attempts to open

func (*SQLiteWalletDriver) RenameWallet

func (swd *SQLiteWalletDriver) RenameWallet(newName []byte, id []byte, pw []byte) error

RenameWallet renames the wallet with the given id to newName. It does not rename the database file itself, because doing so safely is tricky

Jump to

Keyboard shortcuts

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