interactor

package
v0.68.0-prev2 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRequestAlreadyBeingProcessed = errors.New("a request is already being processed")

Functions

func InvalidResponsePayloadError

func InvalidResponsePayloadError(name InteractionName) error

func TraceIDMismatchError

func TraceIDMismatchError(expected, got string) error

func WrongResponseTypeError

func WrongResponseTypeError(expected, got InteractionName) error

Types

type CancelRequest added in v0.59.0

type CancelRequest struct{}

CancelRequest cancels a request that is waiting for user inputs. It can't cancel a request when there is no response awaited.

type Decision

type Decision struct {
	// Approved is set to true if the request is accepted by the user, false
	// otherwise.
	Approved bool `json:"approved"`
}

Decision is a generic response for the following review requests:

  • RequestPermissionsReview
  • RequestTransactionReviewForSigning
  • RequestTransactionReviewForSending

type EnteredPassphrase

type EnteredPassphrase struct {
	Passphrase string `json:"passphrase"`
}

EnteredPassphrase contains the passphrase of a given wallet the user entered. It's a response to the interactor.RequestPassphrase.

type ErrorOccurred

type ErrorOccurred struct {
	// Type is an enumeration that gives information about the origin of the error.
	// The value is the string representation of an api.ErrorType.
	Type string `json:"type"`

	// Error is the error message describing the reason of the failure.
	Error string `json:"error"`
}

ErrorOccurred is a generic notification emitted when the something failed. This notification can wrap an internal failure as much as a user input error. Receiving this notification doesn't necessarily mean the overall request failed. The request should be considered as failed when this notification is followed by the interactor.InteractionSessionEnded notification.

type Interaction

type Interaction struct {
	// TraceID is an identifier specifically made for client front-end to keep
	// track of a transaction during all of its lifetime, from transaction
	// review to sending confirmation and in-memory history.
	// It shouldn't be confused with the transaction hash that is the
	// transaction identifier.
	TraceID string `json:"traceID"`

	// Name is the name of the interaction. This helps to figure out how the
	// data payload should be parsed.
	Name InteractionName `json:"name"`

	// Data is the generic field that hold the data of the specific interaction.
	Data interface{} `json:"data"`
}

Interaction wraps the messages the JSON-RPC API sends to the wallet front-end along with information about the context.

func (*Interaction) UnmarshalJSON

func (f *Interaction) UnmarshalJSON(data []byte) error

type InteractionName

type InteractionName string
const (
	CancelRequestName                      InteractionName = "CANCEL_REQUEST"
	DecisionName                           InteractionName = "DECISION"
	EnteredPassphraseName                  InteractionName = "ENTERED_PASSPHRASE"
	ErrorOccurredName                      InteractionName = "ERROR_OCCURRED"
	InteractionSessionBeganName            InteractionName = "INTERACTION_SESSION_BEGAN"
	InteractionSessionEndedName            InteractionName = "INTERACTION_SESSION_ENDED"
	LogName                                InteractionName = "LOG"
	RequestPassphraseName                  InteractionName = "REQUEST_PASSPHRASE"
	RequestPermissionsReviewName           InteractionName = "REQUEST_PERMISSIONS_REVIEW"
	RequestSucceededName                   InteractionName = "REQUEST_SUCCEEDED"
	RequestTransactionReviewForSendingName InteractionName = "REQUEST_TRANSACTION_REVIEW_FOR_SENDING"
	RequestTransactionReviewForSigningName InteractionName = "REQUEST_TRANSACTION_REVIEW_FOR_SIGNING"
	RequestWalletConnectionReviewName      InteractionName = "REQUEST_WALLET_CONNECTION_REVIEW"
	RequestWalletSelectionName             InteractionName = "REQUEST_WALLET_SELECTION"
	SelectedWalletName                     InteractionName = "SELECTED_WALLET"
	TransactionFailedName                  InteractionName = "TRANSACTION_FAILED"
	TransactionSucceededName               InteractionName = "TRANSACTION_SUCCEEDED"
	WalletConnectionDecisionName           InteractionName = "WALLET_CONNECTION_DECISION"
)

type InteractionSessionBegan

type InteractionSessionBegan struct{}

InteractionSessionBegan is a notification that is emitted when the interaction session begin. It only carries informational value on a request lifecycle. This is the first notification to be emitted and is always emitted when a request comes in.

type InteractionSessionEnded

type InteractionSessionEnded struct{}

InteractionSessionEnded is a notification that is emitted when the interaction session ended. This is the last notification to be emitted and is always emitted, regardless of the request status. It only carries informational value on a request lifecycle. The success or failure status of a request is carried by the interactor.RequestSucceeded and interactor.ErrorOccurred notifications, respectively. Nothing should be expected after receiving this notification.

type Log

type Log struct {
	// Type is an enumeration that gives information about the level of log.
	// The value is the string representation of an api.LogType.
	Type string `json:"type"`

	// Message is the log message itself.
	Message string `json:"message"`
}

Log is a generic event that shouldn't be confused with a notification. A log is conceptually different. Whatever the type (error, warning...), a log is just an information about the internal processing that we think is worth to broadcast to wallet front-ends. That said, it can be safely ignored if not needed. That is where is differs from the notifications.

type OngoingSession

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

func (*OngoingSession) Receive

func (s *OngoingSession) Receive() Interaction

func (*OngoingSession) Send

func (s *OngoingSession) Send(interaction Interaction)

type ParallelInteractor

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

func NewParallelInteractor

func NewParallelInteractor(userCtx context.Context, startSessionChan chan<- *OngoingSession) *ParallelInteractor

func (*ParallelInteractor) Log

func (i *ParallelInteractor) Log(ctx context.Context, traceID string, t api.LogType, msg string)

func (*ParallelInteractor) NotifyError

func (i *ParallelInteractor) NotifyError(ctx context.Context, traceID string, t api.ErrorType, err error)

func (*ParallelInteractor) NotifyFailedTransaction

func (i *ParallelInteractor) NotifyFailedTransaction(ctx context.Context, traceID, deserializedInputData, tx string, err error, sentAt time.Time, host string)

func (*ParallelInteractor) NotifyInteractionSessionBegan

func (i *ParallelInteractor) NotifyInteractionSessionBegan(ctx context.Context, traceID string) error

func (*ParallelInteractor) NotifyInteractionSessionEnded

func (i *ParallelInteractor) NotifyInteractionSessionEnded(ctx context.Context, traceID string)

func (*ParallelInteractor) NotifySuccessfulRequest

func (i *ParallelInteractor) NotifySuccessfulRequest(ctx context.Context, traceID string, message string)

func (*ParallelInteractor) NotifySuccessfulTransaction

func (i *ParallelInteractor) NotifySuccessfulTransaction(ctx context.Context, traceID, txHash, deserializedInputData, tx string, sentAt time.Time, host string)

func (*ParallelInteractor) RequestPassphrase

func (i *ParallelInteractor) RequestPassphrase(ctx context.Context, traceID, wallet string) (string, error)

func (*ParallelInteractor) RequestPermissionsReview

func (i *ParallelInteractor) RequestPermissionsReview(ctx context.Context, traceID, hostname, wallet string, perms map[string]string) (bool, error)

func (*ParallelInteractor) RequestTransactionReviewForSending

func (i *ParallelInteractor) RequestTransactionReviewForSending(ctx context.Context, traceID, hostname, wallet, pubKey, transaction string, receivedAt time.Time) (bool, error)

func (*ParallelInteractor) RequestTransactionReviewForSigning

func (i *ParallelInteractor) RequestTransactionReviewForSigning(ctx context.Context, traceID, hostname, wallet, pubKey, transaction string, receivedAt time.Time) (bool, error)

func (*ParallelInteractor) RequestWalletConnectionReview

func (i *ParallelInteractor) RequestWalletConnectionReview(ctx context.Context, traceID, hostname string) (string, error)

func (*ParallelInteractor) RequestWalletSelection

func (i *ParallelInteractor) RequestWalletSelection(ctx context.Context, traceID, hostname string, availableWallets []string) (api.SelectedWallet, error)

type RequestPassphrase

type RequestPassphrase struct {
	Wallet string `json:"wallet"`
}

RequestPassphrase is a request emitted when the service wants to confirm the user has access to the wallet. It should be answered by an interactor.EnteredPassphrase response.

type RequestPermissionsReview

type RequestPermissionsReview struct {
	Hostname    string            `json:"hostname"`
	Wallet      string            `json:"wallet"`
	Permissions map[string]string `json:"permissions"`
}

RequestPermissionsReview is a review request emitted when a third-party application performs an operation that requires an update to the permissions.

type RequestSucceeded

type RequestSucceeded struct {
	// Message can contain a custom success message.
	Message string `json:"message"`
}

RequestSucceeded is a generic notification emitted when the request succeeded, meaning no error has been encountered. This notification is emitted only once.

type RequestTransactionReviewForSending

type RequestTransactionReviewForSending struct {
	Hostname    string    `json:"hostname"`
	Wallet      string    `json:"wallet"`
	PublicKey   string    `json:"publicKey"`
	Transaction string    `json:"transaction"`
	ReceivedAt  time.Time `json:"receivedAt"`
}

RequestTransactionReviewForSending is a review request emitted when a third-party application wants to send a transaction.

type RequestTransactionReviewForSigning

type RequestTransactionReviewForSigning struct {
	Hostname    string    `json:"hostname"`
	Wallet      string    `json:"wallet"`
	PublicKey   string    `json:"publicKey"`
	Transaction string    `json:"transaction"`
	ReceivedAt  time.Time `json:"receivedAt"`
}

RequestTransactionReviewForSigning is a review request when a third-party application wants to sign a transaction.

type RequestWalletConnectionReview

type RequestWalletConnectionReview struct {
	Hostname string `json:"hostname"`
}

RequestWalletConnectionReview is a request emitted when a third-party application wants to connect to a wallet.

type RequestWalletSelection

type RequestWalletSelection struct {
	Hostname         string   `json:"hostname"`
	AvailableWallets []string `json:"availableWallets"`
}

RequestWalletSelection is a request emitted when the service requires the user to select a wallet. It is emitted after the user approved the wallet connection from a third-party application. It should be answered by an interactor.SelectedWallet response.

type SelectedNode added in v0.68.0

type SelectedNode struct {
	Host string `json:"host"`
}

type SelectedWallet

type SelectedWallet struct {
	Wallet     string `json:"wallet"`
	Passphrase string `json:"passphrase"`
}

SelectedWallet contains required information needed when the user need to choose a wallet and unlock it.

type SequentialInteractor

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

SequentialInteractor is built to handle one request at a time. Concurrent requests are not supported and will result in errors.

func NewSequentialInteractor

func NewSequentialInteractor(userCtx context.Context, receptionChan chan<- Interaction, responseChan <-chan Interaction) *SequentialInteractor

func (*SequentialInteractor) Log

func (i *SequentialInteractor) Log(ctx context.Context, traceID string, t api.LogType, msg string)

func (*SequentialInteractor) NotifyError

func (i *SequentialInteractor) NotifyError(ctx context.Context, traceID string, t api.ErrorType, err error)

func (*SequentialInteractor) NotifyFailedTransaction

func (i *SequentialInteractor) NotifyFailedTransaction(ctx context.Context, traceID, deserializedInputData, tx string, err error, sentAt time.Time, host string)

func (*SequentialInteractor) NotifyInteractionSessionBegan

func (i *SequentialInteractor) NotifyInteractionSessionBegan(_ context.Context, traceID string) error

func (*SequentialInteractor) NotifyInteractionSessionEnded

func (i *SequentialInteractor) NotifyInteractionSessionEnded(_ context.Context, traceID string)

func (*SequentialInteractor) NotifySuccessfulRequest

func (i *SequentialInteractor) NotifySuccessfulRequest(ctx context.Context, traceID string, message string)

func (*SequentialInteractor) NotifySuccessfulTransaction

func (i *SequentialInteractor) NotifySuccessfulTransaction(ctx context.Context, traceID, txHash, deserializedInputData, tx string, sentAt time.Time, host string)

func (*SequentialInteractor) RequestPassphrase

func (i *SequentialInteractor) RequestPassphrase(ctx context.Context, traceID, wallet string) (string, error)

func (*SequentialInteractor) RequestPermissionsReview

func (i *SequentialInteractor) RequestPermissionsReview(ctx context.Context, traceID, hostname, wallet string, perms map[string]string) (bool, error)

func (*SequentialInteractor) RequestTransactionReviewForSending

func (i *SequentialInteractor) RequestTransactionReviewForSending(ctx context.Context, traceID, hostname, wallet, pubKey, transaction string, receivedAt time.Time) (bool, error)

func (*SequentialInteractor) RequestTransactionReviewForSigning

func (i *SequentialInteractor) RequestTransactionReviewForSigning(ctx context.Context, traceID, hostname, wallet, pubKey, transaction string, receivedAt time.Time) (bool, error)

func (*SequentialInteractor) RequestWalletConnectionReview

func (i *SequentialInteractor) RequestWalletConnectionReview(ctx context.Context, traceID, hostname string) (string, error)

func (*SequentialInteractor) RequestWalletSelection

func (i *SequentialInteractor) RequestWalletSelection(ctx context.Context, traceID, hostname string, availableWallets []string) (api.SelectedWallet, error)

type TransactionFailed

type TransactionFailed struct {
	// DeserializedInputData is the input data bundled in the transaction in a
	// human-readable format.
	DeserializedInputData string `json:"deserializedInputData"`

	// Tx is the true representation of the transaction that is sent to the
	// network.
	Tx string `json:"tx"`

	// Error is the error message describing the reason of the failure.
	Error error `json:"error"`

	// SentAt is the time a which the transaction has been sent to the network.
	// It's useful to build a list of the sending in a chronological order on
	// the front-ends.
	SentAt time.Time `json:"sentAt"`

	// Node contains all the information related to the node selected for the
	// sending of the transaction.
	Node SelectedNode `json:"node"`
}

TransactionFailed is a notification sent when the sending of a transaction failed for any reason. It replaces the ErrorOccurred notification as it carries specific information that wallet front-ends may use for investigation. This notification is emitted only once.

type TransactionSucceeded

type TransactionSucceeded struct {
	// TxHash is the hash of the transaction that is used to uniquely identify
	// a transaction. It can be used to retrieve a transaction in the explorer.
	TxHash string `json:"txHash"`

	// DeserializedInputData is the input data bundled in the transaction in a
	// human-readable format.
	DeserializedInputData string `json:"deserializedInputData"`

	// Tx is the true representation of the transaction that is sent to the
	// network.
	Tx string `json:"tx"`

	// SentAt is the time a which the transaction has been sent to the network.
	// It's useful to build a list of the sending in a chronological order on
	// the front-ends.
	SentAt time.Time `json:"sentAt"`

	// Node contains all the information related to the node selected for the
	// sending of the transaction.
	Node SelectedNode `json:"node"`
}

TransactionSucceeded is a notification sent when the sending of a transaction succeeded. It replaces the RequestSucceeded notification as it carries specific information that wallet front-ends may use for history. This notification is emitted only once.

type WalletConnectionDecision

type WalletConnectionDecision struct {
	// ConnectionApproval tells if the third-party application is authorized
	// to connect to a wallet.
	// The value is the string representation of a preferences.ConnectionApproval.
	ConnectionApproval string `json:"connectionApproval"`
}

WalletConnectionDecision is a specific response for interactor.RequestWalletConnectionReview.

Jump to

Keyboard shortcuts

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