Skip to content

wealdtech/go-eth2-wallet-dirk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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-wallet-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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages