accounts

package module
v0.0.0-...-c41ebe0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: MIT Imports: 8 Imported by: 1

README

DEPRECATED ledger-go-accumulate - repo moved into accumulate wallet

Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? Use the template at the bottom!

Add your files

cd existing_repo
git remote add origin https://gitlab.com/accumulatenetwork/ledger/ledger-go-accumulate.git
git branch -M main
git push -uf origin main

Integrate with your tools

Collaborate with your team

Test and Deploy

Use the built-in continuous integration in GitLab.


Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to makeareadme.com for this template.

Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

Name

Choose a self-explaining name for your project.

Description

Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

Badges

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

Visuals

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

Installation

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

Usage

Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

Support

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

Roadmap

If you have ideas for releases in the future, it is a good idea to list them in the README.

Contributing

State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

Authors and acknowledgment

Show your appreciation to those who have contributed to the project.

License

For open source projects, say how it is licensed.

Project status

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

Documentation

Overview

Package accounts implements high level Ethereum account management.

Index

Constants

View Source
const (
	MimetypeDataWithValidator = "data/validator"
	MimetypeTypedData         = "data/typed"
	MimetypeClique            = "application/x-clique-header"
	MimetypeTextPlain         = "text/plain"
)

Variables

View Source
var (
	ErrWalletClosed   = errors.New("wallet closed")
	ErrUnknownAccount = errors.New("unknown account")
	ErrNotSupported   = errors.New("not supported")
)

Functions

func TextAndHash

func TextAndHash(data []byte) ([]byte, string)

TextAndHash is a helper function that calculates a hash for the given message that can be safely used to calculate a signature from.

The hash is calculated as

sha256("\x19Accumulate Signed Message:\n"${message length}${message}).

This gives context to the signed message and prevents signing of transactions.

func TextHash

func TextHash(data []byte) []byte

TextHash is a helper function that calculates a hash for the given message that can be safely used to calculate a signature from.

The hash is calculated as

keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).

This gives context to the signed message and prevents signing of transactions.

Types

type Account

type Account struct {
	LiteAccount   url2.URL               `json:"liteAccount"` // Ethereum account address derived from the key
	PubKey        []byte                 `json:"publicKey"`
	SignatureType protocol.SignatureType `json:"signatureType"`
	KeyName       string                 `json:"keyName"`
}

Account represents key data needed for an Accumulate account. Key can be used for lite acocunt or an adi key page

type Backend

type Backend interface {
	// Wallets retrieves the list of wallets the backend is currently aware of.
	//
	// The returned wallets are not opened by default. For software HD wallets this
	// means that no base seeds are decrypted, and for hardware wallets that no actual
	// connection is established.
	//
	// The resulting wallet list will be sorted alphabetically based on its internal
	// URL assigned by the backend. Since wallets (especially hardware) may come and
	// go, the same wallet might appear at a different positions in the list during
	// subsequent retrievals.
	Wallets() []Wallet
}

Backend is a "wallet provider" that may contain a batch of accounts they can sign transactions with and upon request, do so.

type Version

type Version struct {
	Major byte `json:"major,omitempty" form:"major" query:"major" validate:"required"`
	Minor byte `json:"minor,omitempty" form:"minor" query:"minor" validate:"required"`
	Patch byte `json:"patch,omitempty" form:"patch" query:"patch" validate:"required"`
}

type Wallet

type Wallet interface {
	Info() WalletInfo

	WalletID() (*url2.URL, error)

	URL() url.URL

	Status() (string, error)

	Open(passphrase string) error

	Close() error

	Keys() []Account

	Contains(account *Account) bool

	Derive(path bip44.Derivation, pin bool, display bool, alias ...string) (Account, error)

	SelfDerive(bases []bip44.Derivation)

	SignData(account *Account, mimeType string, data []byte) ([]byte, error)

	SignDataWithPassphrase(account *Account, passphrase, mimeType string, data []byte) ([]byte, error)

	SignText(account *Account, text []byte) ([]byte, error)

	SignTextWithPassphrase(account *Account, passphrase string, hash []byte) ([]byte, error)

	SignTx(account *Account, tx *protocol.Transaction, signer protocol.Signature) (protocol.Signature, error)

	SignTxWithPassphrase(account *Account, passphrase string,
		tx *protocol.Transaction, preSig protocol.Signature) (protocol.Signature, error)
}

Wallet represents a software or hardware wallet that might contain one or more accounts (derived from the same seed). Info returns the device info & ledger app version URL retrieves the canonical path under which this wallet is reachable. It is used by upper layers to define a sorting order over all wallets from multiple backends. Status returns a textual status to aid the user in the current state of the wallet. It also returns an error indicating any failure the wallet might have encountered. Open initializes access to a wallet instance. It is not meant to unlock or decrypt account keys, rather simply to establish a connection to hardware wallets and/or to access derivation seeds.

The passphrase parameter may or may not be used by the implementation of a particular wallet instance. The reason there is no passwordless open method is to strive towards a uniform wallet handling, oblivious to the different backend providers.

Please note, if you open a wallet, you must close it to release any allocated resources (especially important when working with hardware wallets). Close releases any resources held by an open wallet instance. Keys retrieves the list of signing accounts the wallet is currently aware of. For hierarchical deterministic wallets, the list will not be exhaustive, rather only contain the accounts explicitly pinned during account derivation. Contains returns whether an account is part of this particular wallet or not. Derive attempts to explicitly derive a hierarchical deterministic account at the specified derivation path. If requested, the derived account will be added to the wallet's tracked account list. SelfDerive sets a base account derivation path from which the wallet attempts to discover non zero accounts and automatically add them to list of tracked accounts.

Note, self derivation will increment the last component of the specified path opposed to descending into a child path to allow discovering accounts starting from non zero components.

Some hardware wallets switched derivation paths through their evolution, so this method supports providing multiple bases to discover old user accounts too. Only the last base will be used to derive the next empty account.

You can disable automatic account discovery by calling SelfDerive with a nil chain state reader. SignData requests the wallet to sign the hash of the given data It looks up the account specified either solely via its address contained within, or optionally with the aid of any location metadata from the embedded URL field.

If the wallet requires additional authentication to sign the request (e.g. a password to decrypt the account, or a PIN code to verify the transaction), an AuthNeededError instance will be returned, containing infos for the user about which fields or actions are needed. The user may retry by providing the needed details via SignDataWithPassphrase, or by other means (e.g. unlock the account in a keystore). SignDataWithPassphrase is identical to SignData, but also takes a password NOTE: there's a chance that an erroneous call might mistake the two strings, and supply password in the mimetype field, or vice versa. Thus, an implementation should never echo the mimetype or return the mimetype in the error-response SignText requests the wallet to sign the hash of a given piece of data, prefixed by the Ethereum prefix scheme It looks up the account specified either solely via its address contained within, or optionally with the aid of any location metadata from the embedded URL field.

If the wallet requires additional authentication to sign the request (e.g. a password to decrypt the account, or a PIN code to verify the transaction), an AuthNeededError instance will be returned, containing infos for the user about which fields or actions are needed. The user may retry by providing the needed details via SignTextWithPassphrase, or by other means (e.g. unlock the account in a keystore).

This method should return the signature in 'canonical' format, with v 0 or 1. SignTextWithPassphrase is identical to Signtext, but also takes a password SignTx requests the wallet to sign the given transaction.

It looks up the account specified either solely via its address contained within, or optionally with the aid of any location metadata from the embedded URL field.

If the wallet requires additional authentication to sign the request (e.g. a password to decrypt the account, or a PIN code to verify the transaction), an AuthNeededError instance will be returned, containing infos for the user about which fields or actions are needed. The user may retry by providing the needed details via SignTxWithPassphrase, or by other means (e.g. unlock the account in a keystore). SignTxWithPassphrase is identical to SignTx, but also takes a password

type WalletEvent

type WalletEvent struct {
	Wallet Wallet          // Wallet instance arrived or departed
	Kind   WalletEventType // Event type that happened in the system
}

WalletEvent is an event fired by an account backend when a wallet arrival or departure is detected.

type WalletEventType

type WalletEventType int

WalletEventType represents the different event types that can be fired by the wallet subscription subsystem.

const (
	// WalletArrived is fired when a new wallet is detected either via USB or via
	// a filesystem event in the keystore.
	WalletArrived WalletEventType = iota

	// WalletOpened is fired when a wallet is successfully opened with the purpose
	// of starting any background processes such as automatic key derivation.
	WalletOpened

	// WalletDropped
	WalletDropped
)

type WalletInfo

type WalletInfo struct {
	AppVersion Version
	DeviceInfo usb.DeviceInfo
	WalletID   *url2.URL
}

Directories

Path Synopsis
Package common contains various helper functions.
Package common contains various helper functions.
hexutil
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.
Package usbwallet implements support for USB hardware wallets.
Package usbwallet implements support for USB hardware wallets.

Jump to

Keyboard shortcuts

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