wallet

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KNamePrefix = "wallet-"
	KDefault    = "default"
)

Variables

View Source
var ErrNoAPI = fmt.Errorf("no filecoin api connected")

Functions

func ActSigType

func ActSigType(typ KeyType) crypto.SigType

ActSigType converts a key type to a Filecoin signature type

Types

type Driver

type Driver interface {
	NewKey(context.Context, KeyType) (address.Address, error)
	DefaultAddress() address.Address
	SetDefaultAddress(address.Address) error
	List() ([]address.Address, error)
	ImportKey(context.Context, *KeyInfo) (address.Address, error)
	ExportKey(context.Context, address.Address) (*KeyInfo, error)
	Sign(context.Context, address.Address, []byte) (*crypto.Signature, error)
	Verify(context.Context, address.Address, []byte, *crypto.Signature) (bool, error)
	Balance(context.Context, address.Address) (fil.BigInt, error)
	Transfer(ctx context.Context, from address.Address, to address.Address, amount string) error
	Signers() map[KeyType]Signer
}

Driver is a lightweight interface to control any available keychain and interact with blockchains

func NewFromKeystore

func NewFromKeystore(ks keystore.Keystore, opts ...Option) Driver

NewFromKeystore creates a new IPFS keystore based wallet implementing the Driver methods

type Key

type Key struct {
	KeyInfo

	PublicKey []byte
	Address   address.Address
}

Key adds the public key and address on top of the private key

func NewKeyFromKeyInfo

func NewKeyFromKeyInfo(ki KeyInfo) (*Key, error)

NewKeyFromKeyInfo adds public key and address to private key

func NewKeyFromLibp2p

func NewKeyFromLibp2p(pk ci.PrivKey, sigs map[KeyType]Signer) (*Key, error)

NewKeyFromLibp2p converts a libp2p crypto private key interface into a Key

func (*Key) Bytes

func (k *Key) Bytes() ([]byte, error)

Bytes implements libp2p PrivKey interface for IPFS keystore compat do not use

func (*Key) Equals

func (k *Key) Equals(ki ci.Key) bool

Equals implements libp2p key interface for IPFS keystore compat

func (*Key) GetPublic

func (k *Key) GetPublic() ci.PubKey

GetPublic implements libp2p PrivKey interface for IPFS keystore compat

func (*Key) Raw

func (k *Key) Raw() ([]byte, error)

Raw implements libp2p Key interface for IPFS keystore compat

func (*Key) Sign

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

Sign implements libp2p PrivKey interface for IPFS keystore compat

func (*Key) Type

func (k *Key) Type() pb.KeyType

Type implements libp2p key interface for IPFS keystore compat

func (*Key) Verify

func (k *Key) Verify(data []byte, sig []byte) (bool, error)

Verify implements libp2p PubKey interface for IPFS keystore compat

type KeyInfo

type KeyInfo struct {
	KType      KeyType `json:"Type"` // Had to name it KType as Type() is used already
	PrivateKey []byte
	// contains filtered or unexported fields
}

KeyInfo stores info about a private key

func (*KeyInfo) FromBytes

func (k *KeyInfo) FromBytes(data []byte) error

func (*KeyInfo) ToBytes

func (k *KeyInfo) ToBytes() ([]byte, error)

type KeyType

type KeyType string

KeyType enumerates all the types of key we support

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

Only supporting secp for now since bls cannot be stored in ipfs keystore

type KeystoreWallet

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

KeystoreWallet wraps an IPFS keystore

func (*KeystoreWallet) Balance

func (w *KeystoreWallet) Balance(ctx context.Context, addr address.Address) (fil.BigInt, error)

Balance for a given address

func (*KeystoreWallet) DefaultAddress

func (w *KeystoreWallet) DefaultAddress() address.Address

DefaultAddress of the wallet used for receiving payments as provider and paying when retrieving

func (*KeystoreWallet) ExportKey

func (w *KeystoreWallet) ExportKey(_ context.Context, addr address.Address) (*KeyInfo, error)

ExportKey to a private key and key type from an address in the wallet

func (*KeystoreWallet) ImportKey

func (w *KeystoreWallet) ImportKey(_ context.Context, k *KeyInfo) (address.Address, error)

ImportKey in the wallet from a private key and key type

func (*KeystoreWallet) List

func (w *KeystoreWallet) List() ([]address.Address, error)

List all the addresses in the wallet

func (*KeystoreWallet) NewKey

func (w *KeystoreWallet) NewKey(ctx context.Context, kt KeyType) (address.Address, error)

NewKey generates a brand new key for the given type in our wallet and returns the address

func (*KeystoreWallet) SetDefaultAddress

func (w *KeystoreWallet) SetDefaultAddress(addr address.Address) error

SetDefaultAddress for receiving and sending payments as provider or client

func (*KeystoreWallet) Sign

func (w *KeystoreWallet) Sign(ctx context.Context, addr address.Address, msg []byte) (*crypto.Signature, error)

Sign a message with the key associated with the given address. Generates a valid Filecoin signature

func (*KeystoreWallet) Signers

func (w *KeystoreWallet) Signers() map[KeyType]Signer

Signers returns all the signers registered for this wallet

func (*KeystoreWallet) Transfer

func (w *KeystoreWallet) Transfer(ctx context.Context, from address.Address, to address.Address, amount string) error

Transfer from an address in our wallet to any given address FIL amount is passed as a human readable string this methods blocks execution until the transaction was seen on chain

func (*KeystoreWallet) Verify

func (w *KeystoreWallet) Verify(ctx context.Context, k address.Address, msg []byte, sig *crypto.Signature) (bool, error)

Verify a signature for the given bytes

type Option

type Option func(kw *KeystoreWallet)

Option is an optional configuration of the wallet

func WithConfidence

func WithConfidence(c uint64) Option

WithConfidence sets the number of epochs before we accept a message as confirmed

func WithFilAPI

func WithFilAPI(f fil.API) Option

WithFilAPI sets the filecoin API client

type Signer

type Signer interface {
	GenPrivate() ([]byte, error)
	ToPublic(pk []byte) ([]byte, error)
	Sign(pk []byte, msg []byte) ([]byte, error)
	Verify(sig []byte, a address.Address, msg []byte) error
}

Signer encapsulates methods for a given key

func KeyTypeSig

func KeyTypeSig(typ KeyType, sigs map[KeyType]Signer) (Signer, error)

KeyTypeSig selects the signer based on key type

func SigTypeSig

func SigTypeSig(st crypto.SigType, sigs map[KeyType]Signer) (Signer, error)

SigTypeSig selects the signer based on sig type

Jump to

Keyboard shortcuts

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