Giter Club home page Giter Club logo

go-eth2-wallet-dirk's Introduction

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

go-eth2-wallet-dirk's People

Contributors

mcdee avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.