dirk

package module
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: Apache-2.0 Imports: 28 Imported by: 3

README

go-eth2-wallet-dirk

Tag License GoDoc Travis CI codecov.io Go Report Card

Ethereum 2 wallet held by dirk.

Table of Contents

Install

go-eth2-wallet-dirk is a standard Go module which can be installed with:

go get github.com/wealdtech/go-eth2-wallet-dirk

Usage

Access to the wallet is through the Open() call.
Access to the wallet is usually via go-eth2-wallet; the first two examples below shows how this can be achieved.

This wallet generates keys non-deterministically, i.e. there is no relationship between keys or idea of a "seed".

Wallet and account names may be composed of any valid UTF-8 characters; the only restriction is they can not start with the underscore (_) character.

Note that although non-deterministic wallets do not have passphrases they still need to be unlocked before accounts can be created. This can be carried out with walllet.Unlock(nil)

Example
Accessing a wallet
package main

import (
    "github.com/wealdtech/go-eth2-dirk"
    "google.golang.org/grpc/credentials"
)

func main() {
    // Open a wallet
    wallet, err := dirk.Open(context.Background(),
        dirk.WithName("My wallet"),
        dirk.WithEndpoints([]*Endpoint{
            {"host": "host1.example.com", port: 12345},
            {"host": "host2.example.com", port: 12345},
        }),
        dirk.WithCredentials(credentials.NewTLS(tlsConfig)),
    )
    if err != nil {
        panic(err)
    }

    ...
}
Generating a distributed account
package main

import (
    "github.com/wealdtech/go-eth2-wallet-dirk"
)

func main() {

    // Open a wallet
    wallet, err := dirk.Open(context.Background(),
        dirk.WithName("My wallet"),
        dirk.WithEndpoints([]*Endpoint{
            {"host": "host1.example.com", port: 12345},
            {"host": "host2.example.com", port: 12345},
        }),
        dirk.WithCredentials(credentials.NewTLS(tlsConfig)),
    )
    if err != nil {
        panic(err)
    }

    // Dirk walllets have their own rules as to if a client is allowed to unlock them.
    err = wallet.(e2wtypes.WalletLocker).Unlock(nil)
    if err != nil {
        panic(err)
    }
    // Always immediately defer locking the wallet to ensure it does not remain unlocked outside of the function.
    defer wallet.(e2wtypes.WalletLocker).Lock()
    
    accountCreator, isAccountCreator := wallet.(e2wtypes.WalletDistributedAccountCreator)
    if !isAccountCreator {
        panic(errors.New("not a distributed account creator"))
    }
    account, err := accountCreator.CreateDistributedAccount(context.Background(),"My account", 2, 3, nil)
    if err != nil {
        panic(err)
    }
    // Wallet should be locked as soon as unlocked operations have finished; it is safe to explicitly call wallet.Lock() as well
    // as defer it as per above.
    wallet.(e2wtypes.WalletLocker).Lock()

    ...
}

Maintainers

Jim McDonald: @mcdee.

Contribute

Contributions welcome. Please check out the issues.

License

Apache-2.0 © 2020 Weald Technology Trading Ltd

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeCredentials

func ComposeCredentials(ctx context.Context, certPath string, keyPath string, caCertPath string) (credentials.TransportCredentials, error)

ComposeCredentials composes a set of transport credentials given individual certificate and key paths. The CA certificate path can be empty.

func Credentials added in v1.1.0

func Credentials(_ context.Context, clientCert []byte, clientKey []byte, caCert []byte) (credentials.TransportCredentials, error)

Credentials composes a set of transport credentials given a client certificate and an optional CA certificate.

func Open added in v1.4.0

func Open(ctx context.Context,
	params ...Parameter,
) (
	e2wtypes.Wallet,
	error,
)

Open opens an existing wallet with the given name.

func OpenWallet

func OpenWallet(_ context.Context, name string, credentials credentials.TransportCredentials, endpoints []*Endpoint) (e2wtypes.Wallet, error)

OpenWallet opens an existing wallet with the given name. Deprecated; use Open() instead.

Types

type ConnectionProvider added in v1.1.0

type ConnectionProvider interface {
	// Connection returns a connection and release function.
	Connection(ctx context.Context, endpoint *Endpoint) (*grpc.ClientConn, func(), error)
}

ConnectionProvider is an interface that provides GRPC connections.

type Endpoint

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

Endpoint specifies a host/port tuple.

func NewEndpoint

func NewEndpoint(host string, port uint32) *Endpoint

NewEndpoint creates a new endpoint.

func (*Endpoint) String

func (e *Endpoint) String() string

String implements the stringer interface.

type Metrics added in v1.4.1

type Metrics interface {
	// Presenter returns the presenter for the metrics.
	Presenter() string
}

Metrics is an interface to a metrics provider.

type Parameter added in v1.4.0

type Parameter interface {
	// contains filtered or unexported methods
}

Parameter is the interface for service parameters.

func WithCredentials added in v1.4.0

func WithCredentials(credentials credentials.TransportCredentials) Parameter

WithCredentials sets the transport credentials for the wallet.

func WithEndpoints added in v1.4.0

func WithEndpoints(endpoints []*Endpoint) Parameter

WithEndpoints sets the endpoints for the wallet.

func WithLogLevel added in v1.4.8

func WithLogLevel(logLevel zerolog.Level) Parameter

WithLogLevel sets the log level for the module.

func WithMonitor added in v1.4.1

func WithMonitor(monitor Metrics) Parameter

WithMonitor sets the monitor for the wallet.

func WithName added in v1.4.0

func WithName(name string) Parameter

WithName sets the name for the wallet.

func WithPoolConnections added in v1.4.1

func WithPoolConnections(connections int32) Parameter

WithPoolConnections sets the number of connections for the wallet connection pool.

func WithTimeout added in v1.4.0

func WithTimeout(timeout time.Duration) Parameter

WithTimeout sets the timeout for wallet requests.

type PuddleConnectionProvider added in v1.1.0

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

PuddleConnectionProvider provides connections using the Puddle connection pooler.

func (*PuddleConnectionProvider) Connection added in v1.1.0

func (c *PuddleConnectionProvider) Connection(ctx context.Context, endpoint *Endpoint) (*grpc.ClientConn, func(), error)

Connection returns a connection and release function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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