ethereumtiger: github.com/ethereumtiger/ethereumtiger/signer/core Index | Files

package core

import "github.com/ethereumtiger/ethereumtiger/signer/core"

Index

Package Files

abihelper.go api.go auditlog.go cliui.go stdioui.go types.go validation.go

Constants

const (
    WARN = "WARNING"
    CRIT = "CRITICAL"
    INFO = "Info"
)

Variables

var ErrRequestDenied = errors.New("Request denied")
var Printable7BitAscii = regexp.MustCompile("^[A-Za-z0-9!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ]+$")

func MethodSelectorToAbi Uses

func MethodSelectorToAbi(selector string) ([]byte, error)

MethodSelectorToAbi converts a method selector into an ABI struct. The returned data is a valid json string which can be consumed by the standard abi package.

func SignHash Uses

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

SignHash 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.

func ValidatePasswordFormat Uses

func ValidatePasswordFormat(password string) error

ValidatePasswordFormat returns an error if the password is too short, or consists of characters outside the range of the printable 7bit ascii set

type AbiDb Uses

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

func NewAbiDBFromFile Uses

func NewAbiDBFromFile(path string) (*AbiDb, error)

NewAbiDBFromFile loads signature database from file, and errors if the file is not valid json. Does no other validation of contents

func NewAbiDBFromFiles Uses

func NewAbiDBFromFiles(standard, custom string) (*AbiDb, error)

NewAbiDBFromFiles loads both the standard signature database and a custom database. The latter will be used to write new values into if they are submitted via the API

func NewEmptyAbiDB Uses

func NewEmptyAbiDB() (*AbiDb, error)

NewEmptyAbiDB exists for test purposes

func (*AbiDb) AddSignature Uses

func (db *AbiDb) AddSignature(selector string, data []byte) error

AddSignature to the database, if custom database saving is enabled. OBS: This method does _not_ validate the correctness of the data, it is assumed that the caller has already done so

func (*AbiDb) LookupMethodSelector Uses

func (db *AbiDb) LookupMethodSelector(id []byte) (string, error)

LookupMethodSelector checks the given 4byte-sequence against the known ABI methods. OBS: This method does not validate the match, it's assumed the caller will do so

func (*AbiDb) Size Uses

func (db *AbiDb) Size() int

type Account Uses

type Account struct {
    Typ     string         `json:"type"`
    URL     accounts.URL   `json:"url"`
    Address common.Address `json:"address"`
}

func (Account) String Uses

func (a Account) String() string

type Accounts Uses

type Accounts []Account

func (Accounts) String Uses

func (as Accounts) String() string

type AuditLogger Uses

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

func NewAuditLogger Uses

func NewAuditLogger(path string, api ExternalAPI) (*AuditLogger, error)

func (*AuditLogger) Export Uses

func (l *AuditLogger) Export(ctx context.Context, addr common.Address) (json.RawMessage, error)

func (*AuditLogger) List Uses

func (l *AuditLogger) List(ctx context.Context) ([]common.Address, error)

func (*AuditLogger) New Uses

func (l *AuditLogger) New(ctx context.Context) (accounts.Account, error)

func (*AuditLogger) Sign Uses

func (l *AuditLogger) Sign(ctx context.Context, addr common.MixedcaseAddress, data hexutil.Bytes) (hexutil.Bytes, error)

func (*AuditLogger) SignTransaction Uses

func (l *AuditLogger) SignTransaction(ctx context.Context, args SendTxArgs, methodSelector *string) (*ethapi.SignTransactionResult, error)

type CommandlineUI Uses

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

func NewCommandlineUI Uses

func NewCommandlineUI() *CommandlineUI

func (*CommandlineUI) ApproveExport Uses

func (ui *CommandlineUI) ApproveExport(request *ExportRequest) (ExportResponse, error)

ApproveExport prompt the user for confirmation to export encrypted Account json

func (*CommandlineUI) ApproveImport Uses

func (ui *CommandlineUI) ApproveImport(request *ImportRequest) (ImportResponse, error)

ApproveImport prompt the user for confirmation to import Account json

func (*CommandlineUI) ApproveListing Uses

func (ui *CommandlineUI) ApproveListing(request *ListRequest) (ListResponse, error)

ApproveListing prompt the user for confirmation to list accounts the list of accounts to list can be modified by the UI

func (*CommandlineUI) ApproveNewAccount Uses

func (ui *CommandlineUI) ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error)

ApproveNewAccount prompt the user for confirmation to create new Account, and reveal to caller

func (*CommandlineUI) ApproveSignData Uses

func (ui *CommandlineUI) ApproveSignData(request *SignDataRequest) (SignDataResponse, error)

ApproveSignData prompt the user for confirmation to request to sign data

func (*CommandlineUI) ApproveTx Uses

func (ui *CommandlineUI) ApproveTx(request *SignTxRequest) (SignTxResponse, error)

ApproveTx prompt the user for confirmation to request to sign Transaction

func (*CommandlineUI) OnApprovedTx Uses

func (ui *CommandlineUI) OnApprovedTx(tx ethapi.SignTransactionResult)

func (*CommandlineUI) OnInputRequired Uses

func (ui *CommandlineUI) OnInputRequired(info UserInputRequest) (UserInputResponse, error)

func (*CommandlineUI) OnSignerStartup Uses

func (ui *CommandlineUI) OnSignerStartup(info StartupInfo)

func (*CommandlineUI) ShowError Uses

func (ui *CommandlineUI) ShowError(message string)

ShowError displays error message to user

func (*CommandlineUI) ShowInfo Uses

func (ui *CommandlineUI) ShowInfo(message string)

ShowInfo displays info message to user

type ExportRequest Uses

type ExportRequest struct {
    Address common.Address `json:"address"`
    Meta    Metadata       `json:"meta"`
}

ExportRequest info about query to export accounts

type ExportResponse Uses

type ExportResponse struct {
    Approved bool `json:"approved"`
}

ExportResponse response to export-request

type ExternalAPI Uses

type ExternalAPI interface {
    // List available accounts
    List(ctx context.Context) ([]common.Address, error)
    // New request to create a new account
    New(ctx context.Context) (accounts.Account, error)
    // SignTransaction request to sign the specified transaction
    SignTransaction(ctx context.Context, args SendTxArgs, methodSelector *string) (*ethapi.SignTransactionResult, error)
    // Sign - request to sign the given data (plus prefix)
    Sign(ctx context.Context, addr common.MixedcaseAddress, data hexutil.Bytes) (hexutil.Bytes, error)
    // Export - request to export an account
    Export(ctx context.Context, addr common.Address) (json.RawMessage, error)
}

ExternalAPI defines the external API through which signing requests are made.

type ImportRequest Uses

type ImportRequest struct {
    Meta Metadata `json:"meta"`
}

ImportRequest info about request to import an Account

type ImportResponse Uses

type ImportResponse struct {
    Approved    bool   `json:"approved"`
    OldPassword string `json:"old_password"`
    NewPassword string `json:"new_password"`
}

types for the requests/response types between signer and UI

type ListRequest Uses

type ListRequest struct {
    Accounts []Account `json:"accounts"`
    Meta     Metadata  `json:"meta"`
}

types for the requests/response types between signer and UI

type ListResponse Uses

type ListResponse struct {
    Accounts []Account `json:"accounts"`
}

types for the requests/response types between signer and UI

type Message Uses

type Message struct {
    Text string `json:"text"`
}

types for the requests/response types between signer and UI

type Metadata Uses

type Metadata struct {
    Remote    string `json:"remote"`
    Local     string `json:"local"`
    Scheme    string `json:"scheme"`
    UserAgent string `json:"User-Agent"`
    Origin    string `json:"Origin"`
}

Metadata about a request

func MetadataFromContext Uses

func MetadataFromContext(ctx context.Context) Metadata

MetadataFromContext extracts Metadata from a given context.Context

func (Metadata) String Uses

func (m Metadata) String() string

String implements Stringer interface

type NewAccountRequest Uses

type NewAccountRequest struct {
    Meta Metadata `json:"meta"`
}

types for the requests/response types between signer and UI

type NewAccountResponse Uses

type NewAccountResponse struct {
    Approved bool   `json:"approved"`
    Password string `json:"password"`
}

types for the requests/response types between signer and UI

type PasswordRequest Uses

type PasswordRequest struct {
    Prompt string `json:"prompt"`
}

types for the requests/response types between signer and UI

type PasswordResponse Uses

type PasswordResponse struct {
    Password string `json:"password"`
}

types for the requests/response types between signer and UI

type SendTxArgs Uses

type SendTxArgs struct {
    From     common.MixedcaseAddress  `json:"from"`
    To       *common.MixedcaseAddress `json:"to"`
    Gas      hexutil.Uint64           `json:"gas"`
    GasPrice hexutil.Big              `json:"gasPrice"`
    Value    hexutil.Big              `json:"value"`
    Nonce    hexutil.Uint64           `json:"nonce"`
    // We accept "data" and "input" for backwards-compatibility reasons.
    Data  *hexutil.Bytes `json:"data"`
    Input *hexutil.Bytes `json:"input"`
}

SendTxArgs represents the arguments to submit a transaction

func (SendTxArgs) String Uses

func (args SendTxArgs) String() string

type SignDataRequest Uses

type SignDataRequest struct {
    Address common.MixedcaseAddress `json:"address"`
    Rawdata hexutil.Bytes           `json:"raw_data"`
    Message string                  `json:"message"`
    Hash    hexutil.Bytes           `json:"hash"`
    Meta    Metadata                `json:"meta"`
}

types for the requests/response types between signer and UI

type SignDataResponse Uses

type SignDataResponse struct {
    Approved bool `json:"approved"`
    Password string
}

types for the requests/response types between signer and UI

type SignTxRequest Uses

type SignTxRequest struct {
    Transaction SendTxArgs       `json:"transaction"`
    Callinfo    []ValidationInfo `json:"call_info"`
    Meta        Metadata         `json:"meta"`
}

SignTxRequest contains info about a Transaction to sign

type SignTxResponse Uses

type SignTxResponse struct {
    //The UI may make changes to the TX
    Transaction SendTxArgs `json:"transaction"`
    Approved    bool       `json:"approved"`
    Password    string     `json:"password"`
}

SignTxResponse result from SignTxRequest

type SignerAPI Uses

type SignerAPI struct {
    UI SignerUI
    // contains filtered or unexported fields
}

SignerAPI defines the actual implementation of ExternalAPI

func NewSignerAPI Uses

func NewSignerAPI(chainID int64, ksLocation string, noUSB bool, ui SignerUI, abidb *AbiDb, lightKDF bool, advancedMode bool) *SignerAPI

NewSignerAPI creates a new API that can be used for Account management. ksLocation specifies the directory where to store the password protected private key that is generated when a new Account is created. noUSB disables USB support that is required to support hardware devices such as ledger and trezor.

func (*SignerAPI) Export Uses

func (api *SignerAPI) Export(ctx context.Context, addr common.Address) (json.RawMessage, error)

Export returns encrypted private key associated with the given address in web3 keystore format.

func (*SignerAPI) Import Uses

func (api *SignerAPI) Import(ctx context.Context, keyJSON json.RawMessage) (Account, error)

Import tries to import the given keyJSON in the local keystore. The keyJSON data is expected to be in web3 keystore format. It will decrypt the keyJSON with the given passphrase and on successful decryption it will encrypt the key with the given newPassphrase and store it in the keystore. OBS! This method is removed from the public API. It should not be exposed on the external API for a couple of reasons: 1. Even though it is encrypted, it should still be seen as sensitive data 2. It can be used to DoS clef, by using malicious data with e.g. extreme large values for the kdfparams.

func (*SignerAPI) List Uses

func (api *SignerAPI) List(ctx context.Context) ([]common.Address, error)

List returns the set of wallet this signer manages. Each wallet can contain multiple accounts.

func (*SignerAPI) New Uses

func (api *SignerAPI) New(ctx context.Context) (accounts.Account, error)

New creates a new password protected Account. The private key is protected with the given password. Users are responsible to backup the private key that is stored in the keystore location thas was specified when this API was created.

func (*SignerAPI) Sign Uses

func (api *SignerAPI) Sign(ctx context.Context, addr common.MixedcaseAddress, data hexutil.Bytes) (hexutil.Bytes, error)

Sign calculates an Ethereum ECDSA signature for: keccack256("\x19Ethereum Signed Message:\n" + len(message) + message))

Note, the produced signature conforms to the secp256k1 curve R, S and V values, where the V value will be 27 or 28 for legacy reasons.

The key used to calculate the signature is decrypted with the given password.

https://github.com/ethereumtiger/ethereumtiger/wiki/Management-APIs#personal_sign

func (*SignerAPI) SignTransaction Uses

func (api *SignerAPI) SignTransaction(ctx context.Context, args SendTxArgs, methodSelector *string) (*ethapi.SignTransactionResult, error)

SignTransaction signs the given Transaction and returns it both as json and rlp-encoded form

type SignerUI Uses

type SignerUI interface {
    // ApproveTx prompt the user for confirmation to request to sign Transaction
    ApproveTx(request *SignTxRequest) (SignTxResponse, error)
    // ApproveSignData prompt the user for confirmation to request to sign data
    ApproveSignData(request *SignDataRequest) (SignDataResponse, error)
    // ApproveExport prompt the user for confirmation to export encrypted Account json
    ApproveExport(request *ExportRequest) (ExportResponse, error)
    // ApproveImport prompt the user for confirmation to import Account json
    ApproveImport(request *ImportRequest) (ImportResponse, error)
    // ApproveListing prompt the user for confirmation to list accounts
    // the list of accounts to list can be modified by the UI
    ApproveListing(request *ListRequest) (ListResponse, error)
    // ApproveNewAccount prompt the user for confirmation to create new Account, and reveal to caller
    ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error)
    // ShowError displays error message to user
    ShowError(message string)
    // ShowInfo displays info message to user
    ShowInfo(message string)
    // OnApprovedTx notifies the UI about a transaction having been successfully signed.
    // This method can be used by a UI to keep track of e.g. how much has been sent to a particular recipient.
    OnApprovedTx(tx ethapi.SignTransactionResult)
    // OnSignerStartup is invoked when the signer boots, and tells the UI info about external API location and version
    // information
    OnSignerStartup(info StartupInfo)
    // OnInputRequried is invoked when clef requires user input, for example master password or
    // pin-code for unlocking hardware wallets
    OnInputRequired(info UserInputRequest) (UserInputResponse, error)
}

SignerUI specifies what method a UI needs to implement to be able to be used as a UI for the signer

type StartupInfo Uses

type StartupInfo struct {
    Info map[string]interface{} `json:"info"`
}

types for the requests/response types between signer and UI

type StdIOUI Uses

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

func NewStdIOUI Uses

func NewStdIOUI() *StdIOUI

func (*StdIOUI) ApproveExport Uses

func (ui *StdIOUI) ApproveExport(request *ExportRequest) (ExportResponse, error)

func (*StdIOUI) ApproveImport Uses

func (ui *StdIOUI) ApproveImport(request *ImportRequest) (ImportResponse, error)

func (*StdIOUI) ApproveListing Uses

func (ui *StdIOUI) ApproveListing(request *ListRequest) (ListResponse, error)

func (*StdIOUI) ApproveNewAccount Uses

func (ui *StdIOUI) ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error)

func (*StdIOUI) ApproveSignData Uses

func (ui *StdIOUI) ApproveSignData(request *SignDataRequest) (SignDataResponse, error)

func (*StdIOUI) ApproveTx Uses

func (ui *StdIOUI) ApproveTx(request *SignTxRequest) (SignTxResponse, error)

func (*StdIOUI) OnApprovedTx Uses

func (ui *StdIOUI) OnApprovedTx(tx ethapi.SignTransactionResult)

func (*StdIOUI) OnInputRequired Uses

func (ui *StdIOUI) OnInputRequired(info UserInputRequest) (UserInputResponse, error)

func (*StdIOUI) OnSignerStartup Uses

func (ui *StdIOUI) OnSignerStartup(info StartupInfo)

func (*StdIOUI) ShowError Uses

func (ui *StdIOUI) ShowError(message string)

func (*StdIOUI) ShowInfo Uses

func (ui *StdIOUI) ShowInfo(message string)

type UserInputRequest Uses

type UserInputRequest struct {
    Prompt     string `json:"prompt"`
    Title      string `json:"title"`
    IsPassword bool   `json:"isPassword"`
}

types for the requests/response types between signer and UI

type UserInputResponse Uses

type UserInputResponse struct {
    Text string `json:"text"`
}

types for the requests/response types between signer and UI

type ValidationInfo Uses

type ValidationInfo struct {
    Typ     string `json:"type"`
    Message string `json:"message"`
}

type ValidationMessages Uses

type ValidationMessages struct {
    Messages []ValidationInfo
}

type Validator Uses

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

func NewValidator Uses

func NewValidator(db *AbiDb) *Validator

func (*Validator) ValidateTransaction Uses

func (v *Validator) ValidateTransaction(txArgs *SendTxArgs, methodSelector *string) (*ValidationMessages, error)

ValidateTransaction does a number of checks on the supplied transaction, and returns either a list of warnings, or an error, indicating that the transaction should be immediately rejected

Package core imports 27 packages (graph) and is imported by 2 packages. Updated 2019-01-05. Refresh now. Tools for package owners.