sign

package
v0.0.0-...-084c4e9 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: MPL-2.0 Imports: 11 Imported by: 0

README

sign

sign package represents the API and signals for sending and receiving signature request to and from our API user.

When a method is called that requires an additional signature confirmation from a user (like, a transaction), it gets it's sign request.

Client of the API is then nofified of the sign request.

Client has a chance to approve the sign request (by providing a valid password) or to discard it. When the request is approved, the locked functinality is executed.

Documentation

Index

Constants

View Source
const (
	// SignRequestNoErrorCode is sent when no error occurred.
	SignRequestNoErrorCode = iota
	// SignRequestDefaultErrorCode is every case when there is no special tx return code.
	SignRequestDefaultErrorCode
	// SignRequestPasswordErrorCode is sent when account failed verification.
	SignRequestPasswordErrorCode
	// SignRequestTimeoutErrorCode is sent when tx is timed out.
	SignRequestTimeoutErrorCode
	// SignRequestDiscardedErrorCode is sent when tx was discarded.
	SignRequestDiscardedErrorCode
)
View Source
const (
	// MessageIDKey is a key for message ID
	// This ID is required to track from which chat a given send transaction request is coming.
	MessageIDKey = contextKey("message_id")
)

Variables

View Source
var (
	//ErrSignReqNotFound - error sign request hash not found
	ErrSignReqNotFound = errors.New("sign request not found")
	//ErrSignReqInProgress - error sign request is in progress
	ErrSignReqInProgress = errors.New("sign request is in progress")
	//ErrSignReqTimedOut - error sign request sending timed out
	ErrSignReqTimedOut = errors.New("sign request sending timed out")
	//ErrSignReqDiscarded - error sign request discarded
	ErrSignReqDiscarded = errors.New("sign request has been discarded")
)
View Source
var EmptyResponse = Response([]byte{})

EmptyResponse is returned when an error occures

Functions

func SendSignRequestAdded

func SendSignRequestAdded(request *Request)

SendSignRequestAdded sends a signal when a sign request is added.

func SendSignRequestFailed

func SendSignRequestFailed(request *Request, err error)

SendSignRequestFailed sends a signal only if error had happened

Types

type CompleteFunc

type CompleteFunc func(account *account.SelectedExtKey, password string, completeArgs *TxArgs) (Response, error)

CompleteFunc is a function that is called after the sign request is approved.

type Meta

type Meta interface{}

Meta represents any metadata that could be attached to a signing request. It will be JSON-serialized and used in notifications to the API consumer.

type PendingRequests

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

PendingRequests is a capped container that holds pending signing requests.

func NewPendingRequests

func NewPendingRequests() *PendingRequests

NewPendingRequests creates a new requests list

func (*PendingRequests) Add

func (rs *PendingRequests) Add(ctx context.Context, method string, meta Meta, completeFunc CompleteFunc) (*Request, error)

Add a new signing request.

func (*PendingRequests) Approve

func (rs *PendingRequests) Approve(id string, password string, args *TxArgs, verify verifyFunc) Result

Approve a signing request by it's ID. Requires a valid password and a verification function.

func (*PendingRequests) Count

func (rs *PendingRequests) Count() int

Count returns number of currently pending requests

func (*PendingRequests) Discard

func (rs *PendingRequests) Discard(id string) error

Discard remove a signing request from the list of pending requests.

func (*PendingRequests) First

func (rs *PendingRequests) First() *Request

First returns a first signing request (if exists, nil otherwise).

func (*PendingRequests) Get

func (rs *PendingRequests) Get(id string) (*Request, error)

Get returns a signing request by it's ID.

func (*PendingRequests) Has

func (rs *PendingRequests) Has(id string) bool

Has checks whether a pending request with a given identifier exists in the list

func (*PendingRequests) Wait

func (rs *PendingRequests) Wait(id string, timeout time.Duration) Result

Wait blocks until a request with a specified ID is completed (approved or discarded)

type Request

type Request struct {
	ID     string
	Method string
	Meta   Meta
	// contains filtered or unexported fields
}

Request is a single signing request.

type Response

type Response []byte

Response is a byte payload returned by the signed function

func (Response) Bytes

func (r Response) Bytes() []byte

Bytes returns a byte representation of the response

func (Response) Hash

func (r Response) Hash() common.Hash

Hash converts response to a hash.

func (Response) Hex

func (r Response) Hex() string

Hex returns a string representation of the response

type Result

type Result struct {
	Response Response
	Error    error
}

Result is a result of a signing request, error or successful

type TransientError

type TransientError struct {
	Reason error
}

TransientError means that the sign request won't be removed from the list of pending if it happens. There are a few built-in transient errors, and this struct can be used to wrap any error to be transient.

func NewTransientError

func NewTransientError(reason error) TransientError

NewTransientError wraps an error into a TransientError structure.

func (TransientError) Error

func (e TransientError) Error() string

Error returns the string representation of the underlying error.

type TxArgs

type TxArgs struct {
	Gas      *hexutil.Uint64 `json:"gas"`
	GasPrice *hexutil.Big    `json:"gasPrice"`
}

TxArgs represents the arguments to submit when signing a transaction

Jump to

Keyboard shortcuts

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