nd

package module
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: Apache-2.0 Imports: 14 Imported by: 12

README

go-eth2-wallet-nd

Tag License GoDoc Go Report Card

Non-deterministic Ethereum 2 wallet.

Table of Contents

Install

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

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

Usage

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
Creating a wallet
package main

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

func main() {

    // Create a wallet
    wallet, err := e2wallet.CreateWallet("My wallet", e2wallet.WithType("non-deterministic"))
    if err != nil {
        panic(err)
    }

    ...
}
Accessing a wallet
package main

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

func main() {

    // Open a wallet
    wallet, err := e2wallet.OpenWallet("My wallet")
    if err != nil {
        panic(err)
    }

    ...
}
Creating an account
package main

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

func main() {

    // Open a wallet
    wallet, err := e2wallet.OpenWallet("My wallet")
    if err != nil {
        panic(err)
    }

    err = wallet.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.Lock()
    
    account, err := wallet.CreateAccount("My account", []byte("my account secret"))
    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.Lock()

    ...
}

Maintainers

Jim McDonald: @mcdee.

Contribute

Contributions welcome. Please check out the issues.

License

Apache-2.0 © 2019 Weald Technology Trading Ltd

Documentation

Overview

Package nd is a non-deterministic wallet, where each key is created from random bytes.

Package nd is a non-deterministic wallet, where each key is created from random bytes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateWallet

func CreateWallet(ctx context.Context, name string, store e2wtypes.Store, encryptor e2wtypes.Encryptor) (e2wtypes.Wallet, error)

CreateWallet creates a new wallet with the given name and stores it in the provided store. This will error if the wallet already exists.

func DeserializeWallet

func DeserializeWallet(ctx context.Context,
	data []byte,
	store e2wtypes.Store,
	encryptor e2wtypes.Encryptor,
) (
	e2wtypes.Wallet,
	error,
)

DeserializeWallet deserializes a wallet from its byte-level representation.

func Import

func Import(ctx context.Context,
	encryptedData []byte,
	passphrase []byte,
	store e2wtypes.Store,
	encryptor e2wtypes.Encryptor,
) (
	e2wtypes.Wallet,
	error,
)

Import imports the entire wallet, protected by an additional passphrase.

func OpenWallet

func OpenWallet(ctx context.Context, name string, store e2wtypes.Store, encryptor e2wtypes.Encryptor) (e2wtypes.Wallet, error)

OpenWallet opens an existing wallet with the given name.

Types

This section is empty.

Jump to

Keyboard shortcuts

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