go-ethereum: github.com/ethereum/go-ethereum/signer/core Index | Files

package core

import "github.com/ethereum/go-ethereum/signer/core"

Index

Package Files

api.go auditlog.go cliui.go signed_data.go stdioui.go types.go uiapi.go validation.go

Constants

const (

    // ExternalAPIVersion -- see extapi_changelog.md
    ExternalAPIVersion = "6.0.0"
    // InternalAPIVersion -- see intapi_changelog.md
    InternalAPIVersion = "7.0.1"
)
const (
    WARN = "WARNING"
    CRIT = "CRITICAL"
    INFO = "Info"
)

Variables

var (
    IntendedValidator = SigFormat{
        accounts.MimetypeDataWithValidator,
        0x00,
    }
    DataTyped = SigFormat{
        accounts.MimetypeTypedData,
        0x01,
    }
    ApplicationClique = SigFormat{
        accounts.MimetypeClique,
        0x02,
    }
    TextPlain = SigFormat{
        accounts.MimetypeTextPlain,
        0x45,
    }
)
var ErrRequestDenied = errors.New("request denied")

func SignTextValidator Uses

func SignTextValidator(validatorData ValidatorData) (hexutil.Bytes, string)

SignTextWithValidator signs the given message which can be further recovered with the given validator. hash = keccak256("\x19\x00"${address}${data}).

func StartClefAccountManager Uses

func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath string) *accounts.Manager

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 AuditLogger Uses

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

func NewAuditLogger Uses

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

func (*AuditLogger) EcRecover Uses

func (l *AuditLogger) EcRecover(ctx context.Context, data hexutil.Bytes, sig hexutil.Bytes) (common.Address, 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) (common.Address, error)

func (*AuditLogger) SignData Uses

func (l *AuditLogger) SignData(ctx context.Context, contentType string, addr common.MixedcaseAddress, data interface{}) (hexutil.Bytes, error)

func (*AuditLogger) SignTransaction Uses

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

func (*AuditLogger) SignTypedData Uses

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

func (*AuditLogger) Version Uses

func (l *AuditLogger) Version(ctx context.Context) (string, error)

type CommandlineUI Uses

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

func NewCommandlineUI Uses

func NewCommandlineUI() *CommandlineUI

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) RegisterUIServer Uses

func (ui *CommandlineUI) RegisterUIServer(api *UIServerAPI)

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 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) (common.Address, error)
    // SignTransaction request to sign the specified transaction
    SignTransaction(ctx context.Context, args SendTxArgs, methodSelector *string) (*ethapi.SignTransactionResult, error)
    // SignData - request to sign the given data (plus prefix)
    SignData(ctx context.Context, contentType string, addr common.MixedcaseAddress, data interface{}) (hexutil.Bytes, error)
    // SignTypedData - request to sign the given structured data (plus prefix)
    SignTypedData(ctx context.Context, addr common.MixedcaseAddress, data TypedData) (hexutil.Bytes, error)
    // EcRecover - recover public key from given message and signature
    EcRecover(ctx context.Context, data hexutil.Bytes, sig hexutil.Bytes) (common.Address, error)
    // Version info about the APIs
    Version(ctx context.Context) (string, error)
}

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

type ListRequest Uses

type ListRequest struct {
    Accounts []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 []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 NameValueType Uses

type NameValueType struct {
    Name  string      `json:"name"`
    Value interface{} `json:"value"`
    Typ   string      `json:"type"`
}

NameValueType is a very simple struct with Name, Value and Type. It's meant for simple json structures used to communicate signing-info about typed data with the UI

func (*NameValueType) Pprint Uses

func (nvt *NameValueType) Pprint(depth int) string

Pprint returns a pretty-printed version of nvt

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"`
}

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,omitempty"`
}

SendTxArgs represents the arguments to submit a transaction

func (SendTxArgs) String Uses

func (args SendTxArgs) String() string

type SigFormat Uses

type SigFormat struct {
    Mime        string
    ByteVersion byte
}

type SignDataRequest Uses

type SignDataRequest struct {
    ContentType string                  `json:"content_type"`
    Address     common.MixedcaseAddress `json:"address"`
    Rawdata     []byte                  `json:"raw_data"`
    Messages    []*NameValueType        `json:"messages"`
    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"`
}

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"`
}

SignTxResponse result from SignTxRequest

type SignerAPI Uses

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

SignerAPI defines the actual implementation of ExternalAPI

func NewSignerAPI Uses

func NewSignerAPI(am *accounts.Manager, chainID int64, noUSB bool, ui UIClientAPI, validator Validator, advancedMode bool, credentials storage.Storage) *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) EcRecover Uses

func (api *SignerAPI) EcRecover(ctx context.Context, data hexutil.Bytes, sig hexutil.Bytes) (common.Address, error)

EcRecover recovers the address associated with the given sig. Only compatible with `text/plain`

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) (common.Address, 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) SignData Uses

func (api *SignerAPI) SignData(ctx context.Context, contentType string, addr common.MixedcaseAddress, data interface{}) (hexutil.Bytes, error)

SignData signs the hash of the provided data, but does so differently depending on the content-type specified.

Different types of validation occur.

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

func (*SignerAPI) SignTypedData Uses

func (api *SignerAPI) SignTypedData(ctx context.Context, addr common.MixedcaseAddress, typedData TypedData) (hexutil.Bytes, error)

SignTypedData signs EIP-712 conformant typed data hash = keccak256("\x19${byteVersion}${domainSeparator}${hashStruct(message)}")

func (*SignerAPI) Version Uses

func (api *SignerAPI) Version(ctx context.Context) (string, error)

Returns the external api version. This method does not require user acceptance. Available methods are available via enumeration anyway, and this info does not contain user-specific data

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) 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) RegisterUIServer Uses

func (ui *StdIOUI) RegisterUIServer(api *UIServerAPI)

func (*StdIOUI) ShowError Uses

func (ui *StdIOUI) ShowError(message string)

func (*StdIOUI) ShowInfo Uses

func (ui *StdIOUI) ShowInfo(message string)

type Type Uses

type Type struct {
    Name string `json:"name"`
    Type string `json:"type"`
}

type TypePriority Uses

type TypePriority struct {
    Type  string
    Value uint
}

type TypedData Uses

type TypedData struct {
    Types       Types            `json:"types"`
    PrimaryType string           `json:"primaryType"`
    Domain      TypedDataDomain  `json:"domain"`
    Message     TypedDataMessage `json:"message"`
}

func (*TypedData) Dependencies Uses

func (typedData *TypedData) Dependencies(primaryType string, found []string) []string

Dependencies returns an array of custom types ordered by their hierarchical reference tree

func (*TypedData) EncodeData Uses

func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int) (hexutil.Bytes, error)

EncodeData generates the following encoding: `enc(value₁) ‖ enc(value₂) ‖ … ‖ enc(valueₙ)`

each encoded member is 32-byte long

func (*TypedData) EncodePrimitiveValue Uses

func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interface{}, depth int) ([]byte, error)

EncodePrimitiveValue deals with the primitive values found while searching through the typed data

func (*TypedData) EncodeType Uses

func (typedData *TypedData) EncodeType(primaryType string) hexutil.Bytes

EncodeType generates the following encoding: `name ‖ "(" ‖ member₁ ‖ "," ‖ member₂ ‖ "," ‖ … ‖ memberₙ ")"`

each member is written as `type ‖ " " ‖ name` encodings cascade down and are sorted by name

func (*TypedData) Format Uses

func (typedData *TypedData) Format() ([]*NameValueType, error)

Format returns a representation of typedData, which can be easily displayed by a user-interface without in-depth knowledge about 712 rules

func (*TypedData) HashStruct Uses

func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage) (hexutil.Bytes, error)

HashStruct generates a keccak256 hash of the encoding of the provided data

func (*TypedData) Map Uses

func (typedData *TypedData) Map() map[string]interface{}

Map generates a map version of the typed data

func (*TypedData) TypeHash Uses

func (typedData *TypedData) TypeHash(primaryType string) hexutil.Bytes

TypeHash creates the keccak256 hash of the data

type TypedDataDomain Uses

type TypedDataDomain struct {
    Name              string                `json:"name"`
    Version           string                `json:"version"`
    ChainId           *math.HexOrDecimal256 `json:"chainId"`
    VerifyingContract string                `json:"verifyingContract"`
    Salt              string                `json:"salt"`
}

func (*TypedDataDomain) Map Uses

func (domain *TypedDataDomain) Map() map[string]interface{}

Map is a helper function to generate a map version of the domain

type TypedDataMessage Uses

type TypedDataMessage = map[string]interface{}

type Types Uses

type Types map[string][]Type

type UIClientAPI Uses

type UIClientAPI 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)
    // 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)
    // OnInputRequired is invoked when clef requires user input, for example master password or
    // pin-code for unlocking hardware wallets
    OnInputRequired(info UserInputRequest) (UserInputResponse, error)
    // RegisterUIServer tells the UI to use the given UIServerAPI for ui->clef communication
    RegisterUIServer(api *UIServerAPI)
}

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

type UIServerAPI Uses

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

SignerUIAPI implements methods Clef provides for a UI to query, in the bidirectional communication channel. This API is considered secure, since a request can only ever arrive from the UI -- and the UI is capable of approving any action, thus we can consider these requests pre-approved. NB: It's very important that these methods are not ever exposed on the external service registry.

func NewUIServerAPI Uses

func NewUIServerAPI(extapi *SignerAPI) *UIServerAPI

NewUIServerAPI creates a new UIServerAPI

func (*UIServerAPI) ChainId Uses

func (s *UIServerAPI) ChainId() math.HexOrDecimal64

ChainId returns the chainid in use for Eip-155 replay protection Example call {"jsonrpc":"2.0","method":"clef_chainId","params":[], "id":8}

func (*UIServerAPI) DeriveAccount Uses

func (s *UIServerAPI) DeriveAccount(url string, path string, pin *bool) (accounts.Account, error)

DeriveAccount requests a HD wallet to derive a new account, optionally pinning it for later reuse. Example call {"jsonrpc":"2.0","method":"clef_deriveAccount","params":["ledger://","m/44'/60'/0'", false], "id":6}

func (*UIServerAPI) Export Uses

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

Export returns encrypted private key associated with the given address in web3 keystore format. Example {"jsonrpc":"2.0","method":"clef_export","params":["0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a"], "id":4}

func (*UIServerAPI) Import Uses

func (api *UIServerAPI) Import(ctx context.Context, keyJSON json.RawMessage, oldPassphrase, newPassphrase string) (accounts.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. Example (the address in question has privkey `11...11`): {"jsonrpc":"2.0","method":"clef_import","params":[{"address":"19e7e376e7c213b7e7e7e46cc70a5dd086daff2a","crypto":{"cipher":"aes-128-ctr","ciphertext":"33e4cd3756091d037862bb7295e9552424a391a6e003272180a455ca2a9fb332","cipherparams":{"iv":"b54b263e8f89c42bb219b6279fba5cce"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"e4ca94644fd30569c1b1afbbc851729953c92637b7fe4bb9840bbb31ffbc64a5"},"mac":"f4092a445c2b21c0ef34f17c9cd0d873702b2869ec5df4439a0c2505823217e7"},"id":"216c7eac-e8c1-49af-a215-fa0036f29141","version":3},"test","yaddayadda"], "id":4}

func (*UIServerAPI) ImportRawKey Uses

func (s *UIServerAPI) ImportRawKey(privkey string, password string) (accounts.Account, error)

ImportRawKey stores the given hex encoded ECDSA key into the key directory, encrypting it with the passphrase. Example call (should fail on password too short) {"jsonrpc":"2.0","method":"clef_importRawKey","params":["1111111111111111111111111111111111111111111111111111111111111111","test"], "id":6}

func (*UIServerAPI) ListAccounts Uses

func (s *UIServerAPI) ListAccounts(ctx context.Context) ([]accounts.Account, error)

List available accounts. As opposed to the external API definition, this method delivers the full Account object and not only Address. Example call {"jsonrpc":"2.0","method":"clef_listAccounts","params":[], "id":4}

func (*UIServerAPI) ListWallets Uses

func (s *UIServerAPI) ListWallets() []rawWallet

ListWallets will return a list of wallets that clef manages Example call {"jsonrpc":"2.0","method":"clef_listWallets","params":[], "id":5}

func (*UIServerAPI) New Uses

func (api *UIServerAPI) New(ctx context.Context) (common.Address, 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 that was specified when this API was created. This method is the same as New on the external API, the difference being that this implementation does not ask for confirmation, since it's initiated by the user

func (*UIServerAPI) OpenWallet Uses

func (s *UIServerAPI) OpenWallet(url string, passphrase *string) error

OpenWallet initiates a hardware wallet opening procedure, establishing a USB connection and attempting to authenticate via the provided passphrase. Note, the method may return an extra challenge requiring a second open (e.g. the Trezor PIN matrix challenge). Example {"jsonrpc":"2.0","method":"clef_openWallet","params":["ledger://",""], "id":6}

func (*UIServerAPI) SetChainId Uses

func (s *UIServerAPI) SetChainId(id math.HexOrDecimal64) math.HexOrDecimal64

SetChainId sets the chain id to use when signing transactions. Example call to set Ropsten: {"jsonrpc":"2.0","method":"clef_setChainId","params":["3"], "id":8}

type UserInputRequest Uses

type UserInputRequest struct {
    Title      string `json:"title"`
    Prompt     string `json:"prompt"`
    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
}

func (*ValidationMessages) Crit Uses

func (vs *ValidationMessages) Crit(msg string)

func (*ValidationMessages) Info Uses

func (vs *ValidationMessages) Info(msg string)

func (*ValidationMessages) Warn Uses

func (vs *ValidationMessages) Warn(msg string)

type Validator Uses

type Validator interface {
    // 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).
    ValidateTransaction(selector *string, tx *SendTxArgs) (*ValidationMessages, error)
}

Validator defines the methods required to validate a transaction against some sanity defaults as well as any underlying 4byte method database.

Use fourbyte.Database as an implementation. It is separated out of this package to allow pieces of the signer package to be used without having to load the 7MB embedded 4byte dump.

type ValidatorData Uses

type ValidatorData struct {
    Address common.Address
    Message hexutil.Bytes
}

func UnmarshalValidatorData Uses

func UnmarshalValidatorData(data interface{}) (ValidatorData, error)

UnmarshalValidatorData converts the bytes input to typed data

Package core imports 33 packages (graph) and is imported by 39 packages. Updated 2020-05-28. Refresh now. Tools for package owners.