github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/interfaces.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package libkb
     5  
     6  /*
     7   * Interfaces
     8   *
     9   *   Here are the interfaces that we're going to assume when
    10   *   implementing the features of command-line clients or
    11   *   servers.  Depending on the context, we might get different
    12   *   instantiations of these interfaces.
    13   */
    14  
    15  import (
    16  	"io"
    17  	"net/http"
    18  	"time"
    19  
    20  	"golang.org/x/net/context"
    21  
    22  	"github.com/PuerkitoBio/goquery"
    23  	gregor "github.com/keybase/client/go/gregor"
    24  	"github.com/keybase/client/go/logger"
    25  	"github.com/keybase/client/go/protocol/chat1"
    26  	gregor1 "github.com/keybase/client/go/protocol/gregor1"
    27  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    28  	stellar1 "github.com/keybase/client/go/protocol/stellar1"
    29  	clockwork "github.com/keybase/clockwork"
    30  	jsonw "github.com/keybase/go-jsonw"
    31  )
    32  
    33  type configGetter interface {
    34  	GetAPITimeout() (time.Duration, bool)
    35  	GetAppType() AppType
    36  	IsMobileExtension() (bool, bool)
    37  	GetSlowGregorConn() (bool, bool)
    38  	GetReadDeletedSigChain() (bool, bool)
    39  	GetAutoFork() (bool, bool)
    40  	GetChatDbFilename() string
    41  	GetPvlKitFilename() string
    42  	GetParamProofKitFilename() string
    43  	GetExternalURLKitFilename() string
    44  	GetProveBypass() (bool, bool)
    45  	GetCodeSigningKIDs() []string
    46  	GetConfigFilename() string
    47  	GetDbFilename() string
    48  	GetDebug() (bool, bool)
    49  	GetDebugJourneycard() (bool, bool)
    50  	GetDisplayRawUntrustedOutput() (bool, bool)
    51  	GetGpg() string
    52  	GetGpgHome() string
    53  	GetGpgOptions() []string
    54  	GetGregorDisabled() (bool, bool)
    55  	GetSecretStorePrimingDisabled() (bool, bool)
    56  	GetBGIdentifierDisabled() (bool, bool)
    57  	GetGregorPingInterval() (time.Duration, bool)
    58  	GetGregorPingTimeout() (time.Duration, bool)
    59  	GetGregorSaveInterval() (time.Duration, bool)
    60  	GetGregorURI() string
    61  	GetHome() string
    62  	GetMobileSharedHome() string
    63  	GetLinkCacheSize() (int, bool)
    64  	GetLocalRPCDebug() string
    65  	GetLocalTrackMaxAge() (time.Duration, bool)
    66  	GetLogFile() string
    67  	GetEKLogFile() string
    68  	GetPerfLogFile() string
    69  	GetGUILogFile() string
    70  	GetUseDefaultLogFile() (bool, bool)
    71  	GetUseRootConfigFile() (bool, bool)
    72  	GetLogPrefix() string
    73  	GetLogFormat() string
    74  	GetMerkleKIDs() []string
    75  	GetMountDir() string
    76  	GetMountDirDefault() string
    77  	GetPidFile() string
    78  	GetPinentry() string
    79  	GetProofCacheSize() (int, bool)
    80  	GetProxy() string
    81  	GetProxyType() string
    82  	IsCertPinningEnabled() bool
    83  	GetRunMode() (RunMode, error)
    84  	GetScraperTimeout() (time.Duration, bool)
    85  	GetSecretKeyringTemplate() string
    86  	GetServerURI() (string, error)
    87  	GetSessionFilename() string
    88  	GetSocketFile() string
    89  	GetStandalone() (bool, bool)
    90  	GetTimers() string
    91  	GetTorHiddenAddress() string
    92  	GetTorMode() (TorMode, error)
    93  	GetTorProxy() string
    94  	GetUPAKCacheSize() (int, bool)
    95  	GetUIDMapFullNameCacheSize() (int, bool)
    96  	GetUpdaterConfigFilename() string
    97  	GetGUIConfigFilename() string
    98  	GetDeviceCloneStateFilename() string
    99  	GetUserCacheMaxAge() (time.Duration, bool)
   100  	GetVDebugSetting() string
   101  	GetChatDelivererInterval() (time.Duration, bool)
   102  	GetFeatureFlags() (FeatureFlags, error)
   103  	GetLevelDBNumFiles() (int, bool)
   104  	GetLevelDBWriteBufferMB() (int, bool)
   105  	GetChatInboxSourceLocalizeThreads() (int, bool)
   106  	GetPayloadCacheSize() (int, bool)
   107  	GetRememberPassphrase(NormalizedUsername) (bool, bool)
   108  	GetAttachmentHTTPStartPort() (int, bool)
   109  	GetAttachmentDisableMulti() (bool, bool)
   110  	GetDisableTeamAuditor() (bool, bool)
   111  	GetDisableTeamBoxAuditor() (bool, bool)
   112  	GetDisableEKBackgroundKeygen() (bool, bool)
   113  	GetDisableMerkleAuditor() (bool, bool)
   114  	GetDisableSearchIndexer() (bool, bool)
   115  	GetDisableBgConvLoader() (bool, bool)
   116  	GetEnableBotLiteMode() (bool, bool)
   117  	GetExtraNetLogging() (bool, bool)
   118  	GetForceLinuxKeyring() (bool, bool)
   119  	GetForceSecretStoreFile() (bool, bool)
   120  	GetRuntimeStatsEnabled() (bool, bool)
   121  }
   122  
   123  type CommandLine interface {
   124  	configGetter
   125  
   126  	GetAPIDump() (bool, bool)
   127  	GetPGPFingerprint() *PGPFingerprint
   128  	GetNoAutoFork() (bool, bool)
   129  
   130  	// Lower-level functions
   131  	GetGString(string) string
   132  	GetString(string) string
   133  	GetBool(string, bool) (bool, bool)
   134  }
   135  
   136  type Server interface {
   137  }
   138  
   139  type DBKeySet map[DbKey]struct{}
   140  
   141  type LocalDbOps interface {
   142  	Put(id DbKey, aliases []DbKey, value []byte) error
   143  	Delete(id DbKey) error
   144  	Get(id DbKey) ([]byte, bool, error)
   145  	Lookup(alias DbKey) ([]byte, bool, error)
   146  }
   147  
   148  type LocalDbTransaction interface {
   149  	LocalDbOps
   150  	Commit() error
   151  	Discard()
   152  }
   153  
   154  type LocalDb interface {
   155  	LocalDbOps
   156  	Open() error
   157  	Stats() string
   158  	CompactionStats() (bool, bool, error)
   159  	ForceOpen() error
   160  	Close() error
   161  	Nuke() (string, error)
   162  	Clean(force bool) error
   163  	OpenTransaction() (LocalDbTransaction, error)
   164  	KeysWithPrefixes(prefixes ...[]byte) (DBKeySet, error)
   165  }
   166  
   167  type KVStorer interface {
   168  	GetInto(obj interface{}, id DbKey) (found bool, err error)
   169  	PutObj(id DbKey, aliases []DbKey, obj interface{}) (err error)
   170  	Delete(id DbKey) error
   171  	KeysWithPrefixes(prefixes ...[]byte) (DBKeySet, error)
   172  }
   173  
   174  type JSONReader interface {
   175  	GetStringAtPath(string) (string, bool)
   176  	GetInterfaceAtPath(string) (interface{}, error)
   177  	GetBoolAtPath(string) (bool, bool)
   178  	GetIntAtPath(string) (int, bool)
   179  	GetFloatAtPath(string) (float64, bool)
   180  	GetNullAtPath(string) bool
   181  }
   182  
   183  type ConfigReader interface {
   184  	JSONReader
   185  	configGetter
   186  
   187  	GetUserConfig() (*UserConfig, error)
   188  	GetUserConfigForUsername(s NormalizedUsername) (*UserConfig, error)
   189  	GetBundledCA(host string) string
   190  	GetProofCacheLongDur() (time.Duration, bool)
   191  	GetProofCacheMediumDur() (time.Duration, bool)
   192  	GetProofCacheShortDur() (time.Duration, bool)
   193  	GetLinkCacheCleanDur() (time.Duration, bool)
   194  	GetNoPinentry() (bool, bool)
   195  	GetDeviceID() keybase1.DeviceID
   196  	GetDeviceIDForUsername(nu NormalizedUsername) keybase1.DeviceID
   197  	GetPassphraseState() *keybase1.PassphraseState
   198  	GetPassphraseStateForUsername(nu NormalizedUsername) *keybase1.PassphraseState
   199  	GetDeviceIDForUID(u keybase1.UID) keybase1.DeviceID
   200  	GetUsernameForUID(u keybase1.UID) NormalizedUsername
   201  	GetUIDForUsername(n NormalizedUsername) keybase1.UID
   202  	GetUsername() NormalizedUsername
   203  	GetAllUsernames() (current NormalizedUsername, others []NormalizedUsername, err error)
   204  	GetAllUserConfigs() (current *UserConfig, others []UserConfig, err error)
   205  	GetUID() keybase1.UID
   206  	GetProxyCACerts() ([]string, error)
   207  	GetSecurityAccessGroupOverride() (bool, bool)
   208  	GetBug3964RepairTime(NormalizedUsername) (time.Time, error)
   209  	GetStayLoggedOut() (bool, bool)
   210  
   211  	GetUpdatePreferenceAuto() (bool, bool)
   212  	GetUpdatePreferenceSkip() string
   213  	GetUpdatePreferenceSnoozeUntil() keybase1.Time
   214  	GetUpdateLastChecked() keybase1.Time
   215  	GetUpdateURL() string
   216  	GetUpdateDisabled() (bool, bool)
   217  
   218  	GetAndroidInstallReferrerChecked() bool
   219  }
   220  
   221  type UpdaterConfigReader interface {
   222  	GetInstallID() InstallID
   223  }
   224  
   225  type ConfigWriterTransacter interface {
   226  	Commit() error
   227  	Rollback() error
   228  	Abort() error
   229  }
   230  
   231  type JSONWriter interface {
   232  	SetStringAtPath(string, string) error
   233  	SetBoolAtPath(string, bool) error
   234  	SetIntAtPath(string, int) error
   235  	SetFloatAtPath(string, float64) error
   236  	SetNullAtPath(string) error
   237  	SetWrapperAtPath(string, *jsonw.Wrapper) error
   238  	DeleteAtPath(string)
   239  }
   240  
   241  type ConfigWriter interface {
   242  	JSONWriter
   243  	SetUserConfig(cfg *UserConfig, overwrite bool) error
   244  	SwitchUser(un NormalizedUsername) error
   245  	NukeUser(un NormalizedUsername) error
   246  	SetDeviceID(keybase1.DeviceID) error
   247  	SetUpdatePreferenceAuto(bool) error
   248  	SetUpdatePreferenceSkip(string) error
   249  	SetUpdatePreferenceSnoozeUntil(keybase1.Time) error
   250  	SetUpdateLastChecked(keybase1.Time) error
   251  	SetBug3964RepairTime(NormalizedUsername, time.Time) error
   252  	SetRememberPassphrase(NormalizedUsername, bool) error
   253  	SetPassphraseState(keybase1.PassphraseState) error
   254  	SetStayLoggedOut(bool) error
   255  	Reset()
   256  	BeginTransaction() (ConfigWriterTransacter, error)
   257  
   258  	SetAndroidInstallReferrerChecked(b bool) error
   259  }
   260  
   261  type HTTPRequest interface {
   262  	SetEnvironment(env Env)
   263  }
   264  
   265  type Usage struct {
   266  	Config     bool
   267  	GpgKeyring bool
   268  	KbKeyring  bool
   269  	API        bool
   270  	Socket     bool
   271  	AllowRoot  bool
   272  }
   273  
   274  type Command interface {
   275  	GetUsage() Usage
   276  }
   277  
   278  type JSONPayload map[string]interface{}
   279  
   280  type APIRes struct {
   281  	Status     *jsonw.Wrapper
   282  	Body       *jsonw.Wrapper
   283  	HTTPStatus int
   284  	AppStatus  *AppStatus
   285  }
   286  
   287  type AppStatus struct {
   288  	Code   int               `json:"code"`
   289  	Name   string            `json:"name"`
   290  	Desc   string            `json:"desc"`
   291  	Fields map[string]string `json:"fields"`
   292  }
   293  
   294  type APIResponseWrapper interface {
   295  	GetAppStatus() *AppStatus
   296  }
   297  
   298  type ExternalHTMLRes struct {
   299  	HTTPStatus int
   300  	GoQuery    *goquery.Document
   301  }
   302  
   303  type ExternalTextRes struct {
   304  	HTTPStatus int
   305  	Body       string
   306  }
   307  
   308  type ExternalAPIRes struct {
   309  	HTTPStatus int
   310  	Body       *jsonw.Wrapper
   311  }
   312  
   313  type API interface {
   314  	Get(MetaContext, APIArg) (*APIRes, error)
   315  	GetDecode(MetaContext, APIArg, APIResponseWrapper) error
   316  	GetDecodeCtx(context.Context, APIArg, APIResponseWrapper) error
   317  	GetResp(MetaContext, APIArg) (*http.Response, func(), error)
   318  	Post(MetaContext, APIArg) (*APIRes, error)
   319  	PostJSON(MetaContext, APIArg) (*APIRes, error)
   320  	PostDecode(MetaContext, APIArg, APIResponseWrapper) error
   321  	PostDecodeCtx(context.Context, APIArg, APIResponseWrapper) error
   322  	PostRaw(MetaContext, APIArg, string, io.Reader) (*APIRes, error)
   323  	Delete(MetaContext, APIArg) (*APIRes, error)
   324  }
   325  
   326  type ExternalAPI interface {
   327  	Get(MetaContext, APIArg) (*ExternalAPIRes, error)
   328  	Post(MetaContext, APIArg) (*ExternalAPIRes, error)
   329  	GetHTML(MetaContext, APIArg) (*ExternalHTMLRes, error)
   330  	GetText(MetaContext, APIArg) (*ExternalTextRes, error)
   331  	PostHTML(MetaContext, APIArg) (*ExternalHTMLRes, error)
   332  }
   333  
   334  type IdentifyUI interface {
   335  	Start(MetaContext, string, keybase1.IdentifyReason, bool) error
   336  	FinishWebProofCheck(MetaContext, keybase1.RemoteProof, keybase1.LinkCheckResult) error
   337  	FinishSocialProofCheck(MetaContext, keybase1.RemoteProof, keybase1.LinkCheckResult) error
   338  	Confirm(MetaContext, *keybase1.IdentifyOutcome) (keybase1.ConfirmResult, error)
   339  	DisplayCryptocurrency(MetaContext, keybase1.Cryptocurrency) error
   340  	DisplayStellarAccount(MetaContext, keybase1.StellarAccount) error
   341  	DisplayKey(MetaContext, keybase1.IdentifyKey) error
   342  	ReportLastTrack(MetaContext, *keybase1.TrackSummary) error
   343  	LaunchNetworkChecks(MetaContext, *keybase1.Identity, *keybase1.User) error
   344  	DisplayTrackStatement(MetaContext, string) error
   345  	DisplayUserCard(MetaContext, keybase1.UserCard) error
   346  	ReportTrackToken(MetaContext, keybase1.TrackToken) error
   347  	Cancel(MetaContext) error
   348  	Finish(MetaContext) error
   349  	DisplayTLFCreateWithInvite(MetaContext, keybase1.DisplayTLFCreateWithInviteArg) error
   350  	Dismiss(MetaContext, string, keybase1.DismissReason) error
   351  }
   352  
   353  type Checker struct {
   354  	F             func(string) bool
   355  	Transform     func(string) string
   356  	Normalize     func(string) string
   357  	Hint          string
   358  	PreserveSpace bool
   359  }
   360  
   361  type PromptArg struct {
   362  	TerminalPrompt string
   363  	PinentryDesc   string
   364  	PinentryPrompt string
   365  	Checker        *Checker
   366  	RetryMessage   string
   367  	UseSecretStore bool
   368  	ShowTyping     bool
   369  }
   370  
   371  type LoginUI interface {
   372  	keybase1.LoginUiInterface
   373  }
   374  
   375  type ProveUI interface {
   376  	PromptOverwrite(context.Context, keybase1.PromptOverwriteArg) (bool, error)
   377  	PromptUsername(context.Context, keybase1.PromptUsernameArg) (string, error)
   378  	OutputPrechecks(context.Context, keybase1.OutputPrechecksArg) error
   379  	PreProofWarning(context.Context, keybase1.PreProofWarningArg) (bool, error)
   380  	OutputInstructions(context.Context, keybase1.OutputInstructionsArg) error
   381  	OkToCheck(context.Context, keybase1.OkToCheckArg) (bool, error)
   382  	Checking(context.Context, keybase1.CheckingArg) error
   383  	ContinueChecking(context.Context, int) (bool, error)
   384  	DisplayRecheckWarning(context.Context, keybase1.DisplayRecheckWarningArg) error
   385  }
   386  
   387  type SecretUI interface {
   388  	GetPassphrase(pinentry keybase1.GUIEntryArg, terminal *keybase1.SecretEntryArg) (keybase1.GetPassphraseRes, error)
   389  }
   390  
   391  type SaltpackUI interface {
   392  	SaltpackPromptForDecrypt(context.Context, keybase1.SaltpackPromptForDecryptArg, bool) error
   393  	SaltpackVerifySuccess(context.Context, keybase1.SaltpackVerifySuccessArg) error
   394  	SaltpackVerifyBadSender(context.Context, keybase1.SaltpackVerifyBadSenderArg) error
   395  }
   396  
   397  type LogUI interface {
   398  	Debug(format string, args ...interface{})
   399  	Info(format string, args ...interface{})
   400  	Warning(format string, args ...interface{})
   401  	Notice(format string, args ...interface{})
   402  	Errorf(format string, args ...interface{})
   403  	Critical(format string, args ...interface{})
   404  }
   405  
   406  type LogFunc func(format string, args ...interface{})
   407  
   408  type GPGUI interface {
   409  	keybase1.GpgUiInterface
   410  }
   411  
   412  type PgpUI interface {
   413  	keybase1.PGPUiInterface
   414  }
   415  
   416  type ProvisionUI interface {
   417  	keybase1.ProvisionUiInterface
   418  }
   419  
   420  type ChatUI interface {
   421  	ChatInboxUnverified(context.Context, chat1.ChatInboxUnverifiedArg) error
   422  	ChatInboxConversation(context.Context, chat1.ChatInboxConversationArg) error
   423  	ChatInboxFailed(context.Context, chat1.ChatInboxFailedArg) error
   424  	ChatInboxLayout(context.Context, string) error
   425  	ChatThreadCached(context.Context, *string) error
   426  	ChatThreadFull(context.Context, string) error
   427  	ChatThreadStatus(context.Context, chat1.UIChatThreadStatus) error
   428  	ChatConfirmChannelDelete(context.Context, chat1.ChatConfirmChannelDeleteArg) (bool, error)
   429  	ChatSearchHit(context.Context, chat1.ChatSearchHitArg) error
   430  	ChatSearchDone(context.Context, chat1.ChatSearchDoneArg) error
   431  	ChatSearchInboxHit(context.Context, chat1.ChatSearchInboxHitArg) error
   432  	ChatSearchInboxStart(context.Context) error
   433  	ChatSearchInboxDone(context.Context, chat1.ChatSearchInboxDoneArg) error
   434  	ChatSearchIndexStatus(context.Context, chat1.ChatSearchIndexStatusArg) error
   435  	ChatSearchConvHits(context.Context, chat1.UIChatSearchConvHits) error
   436  	ChatSearchTeamHits(context.Context, chat1.UIChatSearchTeamHits) error
   437  	ChatSearchBotHits(context.Context, chat1.UIChatSearchBotHits) error
   438  	ChatStellarShowConfirm(context.Context) error
   439  	ChatStellarDataConfirm(context.Context, chat1.UIChatPaymentSummary) (bool, error)
   440  	ChatStellarDataError(context.Context, keybase1.Status) (bool, error)
   441  	ChatStellarDone(context.Context, bool) error
   442  	ChatGiphySearchResults(ctx context.Context, convID chat1.ConversationID,
   443  		results chat1.GiphySearchResults) error
   444  	ChatGiphyToggleResultWindow(ctx context.Context, convID chat1.ConversationID, show, clearInput bool) error
   445  	ChatShowManageChannels(context.Context, string) error
   446  	ChatCoinFlipStatus(context.Context, []chat1.UICoinFlipStatus) error
   447  	ChatCommandMarkdown(context.Context, chat1.ConversationID, *chat1.UICommandMarkdown) error
   448  	ChatMaybeMentionUpdate(context.Context, string, string, chat1.UIMaybeMentionInfo) error
   449  	ChatLoadGalleryHit(context.Context, chat1.UIMessage) error
   450  	ChatWatchPosition(context.Context, chat1.ConversationID, chat1.UIWatchPositionPerm) (chat1.LocationWatchID, error)
   451  	ChatClearWatch(context.Context, chat1.LocationWatchID) error
   452  	ChatCommandStatus(context.Context, chat1.ConversationID, string, chat1.UICommandStatusDisplayTyp,
   453  		[]chat1.UICommandStatusActionTyp) error
   454  	ChatBotCommandsUpdateStatus(context.Context, chat1.ConversationID, chat1.UIBotCommandsUpdateStatus) error
   455  	TriggerContactSync(context.Context) error
   456  }
   457  
   458  type PromptDefault int
   459  
   460  const (
   461  	PromptDefaultNo PromptDefault = iota
   462  	PromptDefaultYes
   463  	PromptDefaultNeither
   464  )
   465  
   466  type PromptDescriptor int
   467  type OutputDescriptor int
   468  
   469  type TerminalUI interface {
   470  	// The ErrorWriter is not escaped: it should not be used to show unescaped user-originated data.
   471  	ErrorWriter() io.Writer
   472  	Output(string) error
   473  	OutputDesc(OutputDescriptor, string) error
   474  	OutputWriter() io.Writer
   475  	UnescapedOutputWriter() io.Writer
   476  	Printf(fmt string, args ...interface{}) (int, error)
   477  	PrintfUnescaped(fmt string, args ...interface{}) (int, error)
   478  	// Prompt strings are not escaped: they should not be used to show unescaped user-originated data.
   479  	Prompt(PromptDescriptor, string) (string, error)
   480  	PromptForConfirmation(prompt string) error
   481  	PromptPassword(PromptDescriptor, string) (string, error)
   482  	PromptPasswordMaybeScripted(PromptDescriptor, string) (string, error)
   483  	PromptYesNo(PromptDescriptor, string, PromptDefault) (bool, error)
   484  	TerminalSize() (width int, height int)
   485  }
   486  
   487  type DumbOutputUI interface {
   488  	Printf(fmt string, args ...interface{}) (int, error)
   489  	PrintfStderr(fmt string, args ...interface{}) (int, error)
   490  	PrintfUnescaped(fmt string, args ...interface{}) (int, error)
   491  }
   492  
   493  type UI interface {
   494  	GetIdentifyUI() IdentifyUI
   495  	GetIdentifyTrackUI() IdentifyUI
   496  	GetLoginUI() LoginUI
   497  	GetSecretUI() SecretUI
   498  	GetTerminalUI() TerminalUI
   499  	GetDumbOutputUI() DumbOutputUI
   500  	GetProveUI() ProveUI
   501  	GetLogUI() LogUI
   502  	GetGPGUI() GPGUI
   503  	GetProvisionUI(role KexRole) ProvisionUI
   504  	GetPgpUI() PgpUI
   505  	Configure() error
   506  	Shutdown() error
   507  }
   508  
   509  type UIRouter interface {
   510  	SetUI(ConnectionID, UIKind)
   511  
   512  	// These are allowed to return nil for the UI even if
   513  	// error is nil.
   514  	GetIdentifyUI() (IdentifyUI, error)
   515  	GetIdentifyUICtx(ctx context.Context) (int, IdentifyUI, error)
   516  	GetSecretUI(sessionID int) (SecretUI, error)
   517  	GetRekeyUI() (keybase1.RekeyUIInterface, int, error)
   518  	GetRekeyUINoSessionID() (keybase1.RekeyUIInterface, error)
   519  	GetHomeUI() (keybase1.HomeUIInterface, error)
   520  	GetIdentify3UIAdapter(MetaContext) (IdentifyUI, error)
   521  	GetIdentify3UI(MetaContext) (keybase1.Identify3UiInterface, error)
   522  	GetChatUI() (ChatUI, error)
   523  	GetLogUI() (LogUI, error)
   524  
   525  	// WaitForUIType returns true if a UI of the specified type is registered,
   526  	// or waits until timeout for such UI to register and returns false if this
   527  	// does not happen.
   528  	WaitForUIType(uiKind UIKind, timeout time.Duration) bool
   529  
   530  	DumpUIs() map[UIKind]ConnectionID
   531  	Shutdown()
   532  }
   533  
   534  type UIConsumer interface {
   535  	Name() string
   536  	RequiredUIs() []UIKind
   537  	SubConsumers() []UIConsumer
   538  }
   539  
   540  type Triplesec interface {
   541  	DeriveKey(l int) ([]byte, []byte, error)
   542  	Decrypt([]byte) ([]byte, error)
   543  	Encrypt([]byte) ([]byte, error)
   544  	Scrub()
   545  }
   546  
   547  type Clock interface {
   548  	Now() time.Time
   549  }
   550  
   551  type GregorState interface {
   552  	State(ctx context.Context) (gregor.State, error)
   553  	UpdateCategory(ctx context.Context, cat string, body []byte,
   554  		dtime gregor1.TimeOrOffset) (res gregor1.MsgID, err error)
   555  	InjectItem(ctx context.Context, cat string, body []byte, dtime gregor1.TimeOrOffset) (gregor1.MsgID, error)
   556  	DismissItem(ctx context.Context, cli gregor1.IncomingInterface, id gregor.MsgID) error
   557  	DismissCategory(ctx context.Context, cat gregor1.Category) error
   558  	LocalDismissItem(ctx context.Context, id gregor.MsgID) error
   559  }
   560  
   561  type GregorInBandMessageHandler interface {
   562  	IsAlive() bool
   563  	Name() string
   564  	Create(ctx context.Context, cli gregor1.IncomingInterface, category string, ibm gregor.Item) (bool, error)
   565  	Dismiss(ctx context.Context, cli gregor1.IncomingInterface, category string, ibm gregor.Item) (bool, error)
   566  }
   567  
   568  type GregorFirehoseHandler interface {
   569  	IsAlive() bool
   570  	PushState(gregor1.State, keybase1.PushReason)
   571  	PushOutOfBandMessages([]gregor1.OutOfBandMessage)
   572  }
   573  
   574  type GregorListener interface {
   575  	PushHandler(handler GregorInBandMessageHandler)
   576  	PushFirehoseHandler(handler GregorFirehoseHandler)
   577  }
   578  
   579  type LogContext interface {
   580  	GetLog() logger.Logger
   581  }
   582  
   583  type VLogContext interface {
   584  	LogContext
   585  	GetVDebugLog() *VDebugLog
   586  }
   587  
   588  // APIContext defines methods for accessing API server
   589  type APIContext interface {
   590  	GetAPI() API
   591  	GetExternalAPI() ExternalAPI
   592  	GetServerURI() (string, error)
   593  }
   594  
   595  type NetContext interface {
   596  	GetNetContext() context.Context
   597  }
   598  
   599  type DNSNameServerFetcher interface {
   600  	GetServers() []string
   601  }
   602  
   603  type DNSContext interface {
   604  	GetDNSNameServerFetcher() DNSNameServerFetcher
   605  }
   606  
   607  type AssertionContext interface {
   608  	Ctx() context.Context
   609  	NormalizeSocialName(service string, username string) (string, error)
   610  }
   611  
   612  // ProofChecker is an interface for performing a remote check for a proof
   613  
   614  type ProofCheckerMode int
   615  
   616  const (
   617  	ProofCheckerModePassive ProofCheckerMode = iota
   618  	ProofCheckerModeActive  ProofCheckerMode = iota
   619  )
   620  
   621  type ProofChecker interface {
   622  	// `h` is the server provided sigHint. If the client can provide validated
   623  	// information it returns this. The verifiedSigHint is preferred over the
   624  	// server-trust one when displaying to users.
   625  	CheckStatus(m MetaContext, h SigHint, pcm ProofCheckerMode, pvlU keybase1.MerkleStoreEntry) (*SigHint, ProofError)
   626  	GetTorError() ProofError
   627  }
   628  
   629  // ServiceType is an interface for describing an external proof service, like 'Twitter'
   630  // or 'GitHub', etc.
   631  type ServiceType interface {
   632  	Key() string
   633  
   634  	// NormalizeUsername normalizes the given username, assuming
   635  	// that it's free of any leading strings like '@' or 'dns://'.
   636  	NormalizeUsername(string) (string, error)
   637  
   638  	// NormalizeRemote normalizes the given remote username, which
   639  	// is usually but not always the same as the username. It also
   640  	// allows leaders like '@' and 'dns://'.
   641  	//
   642  	// In the case of Facebook, this version does the standard downcasing, but
   643  	// leaves the dots in (that NormalizeUsername above would strip out). This
   644  	// lets us keep the dots in the proof text, and display them on your
   645  	// profile page, even though we ignore them for proof checking.
   646  	NormalizeRemoteName(m MetaContext, name string) (string, error)
   647  
   648  	GetPrompt() string
   649  	LastWriterWins() bool
   650  	PreProofCheck(m MetaContext, remotename string) (*Markup, error)
   651  	PreProofWarning(remotename string) *Markup
   652  	ToServiceJSON(remotename string) *jsonw.Wrapper
   653  	PostInstructions(remotename string) *Markup
   654  	DisplayName() string
   655  	RecheckProofPosting(tryNumber int, status keybase1.ProofStatus, remotename string) (warning *Markup, err error)
   656  	GetProofType() string
   657  	GetTypeName() string
   658  	PickerSubtext() string
   659  	CheckProofText(text string, id keybase1.SigID, sig string) error
   660  	FormatProofText(mctx MetaContext, ppr *PostProofRes,
   661  		kbUsername, remoteUsername string, sigID keybase1.SigID) (string, error)
   662  	GetAPIArgKey() string
   663  	IsDevelOnly() bool
   664  	GetLogoKey() string
   665  
   666  	MakeProofChecker(l RemoteProofChainLink) ProofChecker
   667  	SetDisplayConfig(*keybase1.ServiceDisplayConfig)
   668  	CanMakeNewProofs(mctx MetaContext) bool
   669  	CanMakeNewProofsSkipFeatureFlag(mctx MetaContext) bool
   670  	DisplayPriority() int
   671  	DisplayGroup() string
   672  	IsNew(MetaContext) bool
   673  }
   674  
   675  type ExternalServicesCollector interface {
   676  	GetServiceType(context.Context, string) ServiceType
   677  	ListProofCheckers(MetaContext) []string
   678  	ListServicesThatAcceptNewProofs(MetaContext) []string
   679  	ListDisplayConfigs(MetaContext) (res []keybase1.ServiceDisplayConfig)
   680  	SuggestionFoldPriority(MetaContext) int
   681  	Shutdown()
   682  }
   683  
   684  // Generic store for data that is hashed into the merkle root. Used by pvl and
   685  // parameterized proofs.
   686  type MerkleStore interface {
   687  	GetLatestEntry(m MetaContext) (keybase1.MerkleStoreEntry, error)
   688  	GetLatestEntryWithKnown(MetaContext, *keybase1.MerkleStoreKitHash) (*keybase1.MerkleStoreEntry, error)
   689  }
   690  
   691  // UserChangedHandler is a generic interface for handling user changed events.
   692  // If the call returns an error, we'll remove this handler from the list, under the
   693  // supposition that it's now dead.
   694  type UserChangedHandler interface {
   695  	// HandlerUserChanged is called when the with User with the given UID has
   696  	// changed, either because of a sigchain change, or a profile change.
   697  	HandleUserChanged(uid keybase1.UID) error
   698  }
   699  
   700  type ConnectivityMonitorResult int
   701  
   702  const (
   703  	ConnectivityMonitorYes ConnectivityMonitorResult = iota
   704  	ConnectivityMonitorNo
   705  	ConnectivityMonitorUnknown
   706  )
   707  
   708  type ConnectivityMonitor interface {
   709  	IsConnected(ctx context.Context) ConnectivityMonitorResult
   710  	CheckReachability(ctx context.Context) error
   711  }
   712  
   713  type TeamLoader interface {
   714  	VerifyTeamName(ctx context.Context, id keybase1.TeamID, name keybase1.TeamName) error
   715  	ImplicitAdmins(ctx context.Context, teamID keybase1.TeamID) (impAdmins []keybase1.UserVersion, err error)
   716  	// MapTeamAncestors runs `f` for each of a team's ancestors, excluding the team itself.
   717  	// `f` is an arbitrary function. if it returns an error, the load halts.
   718  	// `teamID` is the team whose ancestors we are mapping over.
   719  	// `reason` is a context string used for logging.
   720  	// `forceFullReloadOnceToAssert` is a predicate that will cause a force full reload if it is
   721  	//		false. It can be used when a new field is added to keybase1.SigChainState that requires
   722  	//		a full reload to obtain.
   723  	MapTeamAncestors(ctx context.Context, f func(t keybase1.TeamSigChainState, n keybase1.TeamName) error, teamID keybase1.TeamID, reason string, forceFullReloadOnceToAssert func(t keybase1.TeamSigChainState) bool) error
   724  	NotifyTeamRename(ctx context.Context, id keybase1.TeamID, newName string) error
   725  	Load(context.Context, keybase1.LoadTeamArg) (*keybase1.TeamData, *keybase1.HiddenTeamChain, error)
   726  	// Freezing a team clears most data and forces a full reload when the team
   727  	// is loaded again. The team loader checks that the previous tail is
   728  	// contained within the new chain post-freeze. In particular, since we load
   729  	// a team before deleting it in response to the server-driven delete gregor
   730  	// notifications, the server can't roll-back to a state where the team is
   731  	// undeleted, so we don't have to special-case team deletion.
   732  	Freeze(ctx context.Context, teamID keybase1.TeamID) error
   733  	// Tombstoning a team prevents it from being loaded ever again, as long as
   734  	// that cache entry exists. Used to prevent server from "undeleting" a
   735  	// team. While a team is tombstoned, most data is cleared.
   736  	Tombstone(ctx context.Context, teamID keybase1.TeamID) error
   737  	// Untrusted hint of what a team's latest seqno is
   738  	HintLatestSeqno(ctx context.Context, id keybase1.TeamID, seqno keybase1.Seqno) error
   739  	ResolveNameToIDUntrusted(ctx context.Context, teamName keybase1.TeamName, public bool, allowCache bool) (id keybase1.TeamID, err error)
   740  	ForceRepollUntil(ctx context.Context, t gregor.TimeOrOffset) error
   741  	IsOpenCached(ctx context.Context, teamID keybase1.TeamID) (bool, error)
   742  	// Clear the in-memory cache. Does not affect the disk cache.
   743  	ClearMem()
   744  }
   745  
   746  type FastTeamLoader interface {
   747  	Load(MetaContext, keybase1.FastTeamLoadArg) (keybase1.FastTeamLoadRes, error)
   748  	// Untrusted hint of what a team's latest seqno is
   749  	HintLatestSeqno(m MetaContext, id keybase1.TeamID, seqno keybase1.Seqno) error
   750  	VerifyTeamName(m MetaContext, id keybase1.TeamID, name keybase1.TeamName, forceRefresh bool) error
   751  	ForceRepollUntil(m MetaContext, t gregor.TimeOrOffset) error
   752  	// See comment in TeamLoader#Freeze.
   753  	Freeze(MetaContext, keybase1.TeamID) error
   754  	// See comment in TeamLoader#Tombstone.
   755  	Tombstone(MetaContext, keybase1.TeamID) error
   756  }
   757  
   758  type HiddenTeamChainManager interface {
   759  	// We got gossip about what the latest chain-tail should be, so ratchet the
   760  	// chain forward; the next call to Advance() has to match.
   761  	Ratchet(MetaContext, keybase1.TeamID, keybase1.HiddenTeamChainRatchetSet) error
   762  	// We got a bunch of new links downloaded via slow or fast loader, so add them
   763  	// onto the HiddenTeamChain state. Ensure that the updated state is at least up to the
   764  	// given ratchet value.
   765  	Advance(mctx MetaContext, update keybase1.HiddenTeamChain, expectedPrev *keybase1.LinkTriple) error
   766  	// Access the tail of the HiddenTeamChain, for embedding into gossip vectors.
   767  	Tail(MetaContext, keybase1.TeamID) (*keybase1.LinkTriple, error)
   768  	// Load the latest data for the given team ID, and just return it wholesale.
   769  	Load(MetaContext, keybase1.TeamID) (dat *keybase1.HiddenTeamChain, err error)
   770  	// See comment in TeamLoader#Freeze.
   771  	Freeze(MetaContext, keybase1.TeamID) error
   772  	// See comment in TeamLoader#Tombstone.
   773  	Tombstone(MetaContext, keybase1.TeamID) error
   774  	// Untrusted hint of what a team's latest seqno is
   775  	HintLatestSeqno(m MetaContext, id keybase1.TeamID, seqno keybase1.Seqno) error
   776  	Shutdown(m MetaContext)
   777  	TeamSupportsHiddenChain(m MetaContext, id keybase1.TeamID) (state bool, err error)
   778  	ClearSupportFlagIfFalse(m MetaContext, id keybase1.TeamID)
   779  }
   780  
   781  type TeamRoleMapManager interface {
   782  	Get(m MetaContext, retryOnFail bool) (res keybase1.TeamRoleMapAndVersion, err error)
   783  	Update(m MetaContext, version keybase1.UserTeamVersion) (err error)
   784  	FlushCache()
   785  }
   786  
   787  type TeamAuditor interface {
   788  	AuditTeam(m MetaContext, id keybase1.TeamID, isPublic bool, headMerkleSeqno keybase1.Seqno,
   789  		chain map[keybase1.Seqno]keybase1.LinkID, hiddenChain map[keybase1.Seqno]keybase1.LinkID,
   790  		maxSeqno keybase1.Seqno, maxHiddenSeqno keybase1.Seqno, lastMerkleRoot *MerkleRoot, auditMode keybase1.AuditMode) (err error)
   791  }
   792  
   793  type TeamBoxAuditor interface {
   794  	AssertUnjailedOrReaudit(m MetaContext, id keybase1.TeamID) (didReaudit bool, err error)
   795  	IsInJail(m MetaContext, id keybase1.TeamID) (bool, error)
   796  	RetryNextBoxAudit(m MetaContext) (attempt *keybase1.BoxAuditAttempt, err error)
   797  	BoxAuditRandomTeam(m MetaContext) (attempt *keybase1.BoxAuditAttempt, err error)
   798  	BoxAuditTeam(m MetaContext, id keybase1.TeamID) (attempt *keybase1.BoxAuditAttempt, err error)
   799  	MaybeScheduleDelayedBoxAuditTeam(m MetaContext, id keybase1.TeamID)
   800  	Attempt(m MetaContext, id keybase1.TeamID, rotateBeforeAudit bool) keybase1.BoxAuditAttempt
   801  }
   802  
   803  // MiniChatPayment is the argument for sending an in-chat payment.
   804  type MiniChatPayment struct {
   805  	Username NormalizedUsername
   806  	Amount   string
   807  	Currency string
   808  }
   809  
   810  // MiniChatPaymentResult is the result of sending an in-chat payment to
   811  // one username.
   812  type MiniChatPaymentResult struct {
   813  	Username  NormalizedUsername
   814  	PaymentID stellar1.PaymentID
   815  	Error     error
   816  }
   817  
   818  // MiniChatPaymentSpec describes the amounts involved in a MiniChatPayment.
   819  type MiniChatPaymentSpec struct {
   820  	Username      NormalizedUsername
   821  	Error         error
   822  	XLMAmount     string
   823  	DisplayAmount string // optional
   824  }
   825  
   826  // MiniChatPaymentSummary contains all the recipients and the amounts they
   827  // will receive plus a total in XLM and in the sender's preferred currency.
   828  type MiniChatPaymentSummary struct {
   829  	Specs        []MiniChatPaymentSpec
   830  	XLMTotal     string
   831  	DisplayTotal string
   832  }
   833  
   834  type Stellar interface {
   835  	CreateWalletSoft(context.Context)
   836  	Upkeep(context.Context) error
   837  	GetServerDefinitions(context.Context) (stellar1.StellarServerDefinitions, error)
   838  	KickAutoClaimRunner(MetaContext, gregor.MsgID)
   839  	UpdateUnreadCount(ctx context.Context, accountID stellar1.AccountID, unread int) error
   840  	SpecMiniChatPayments(mctx MetaContext, payments []MiniChatPayment) (*MiniChatPaymentSummary, error)
   841  	SendMiniChatPayments(mctx MetaContext, convID chat1.ConversationID, payments []MiniChatPayment) ([]MiniChatPaymentResult, error)
   842  	HandleOobm(context.Context, gregor.OutOfBandMessage) (bool, error)
   843  	RemovePendingTx(mctx MetaContext, accountID stellar1.AccountID, txID stellar1.TransactionID) error
   844  	KnownCurrencyCodeInstant(ctx context.Context, code string) (known, ok bool)
   845  	InformBundle(MetaContext, stellar1.BundleRevision, []stellar1.BundleEntry)
   846  	InformDefaultCurrencyChange(MetaContext)
   847  	Refresh(mctx MetaContext, reason string)
   848  }
   849  
   850  type DeviceEKStorage interface {
   851  	Put(mctx MetaContext, generation keybase1.EkGeneration, deviceEK keybase1.DeviceEk) error
   852  	Get(mctx MetaContext, generation keybase1.EkGeneration) (keybase1.DeviceEk, error)
   853  	GetAllActive(mctx MetaContext, merkleRoot MerkleRoot) ([]keybase1.DeviceEkMetadata, error)
   854  	MaxGeneration(mctx MetaContext, includeErrs bool) (keybase1.EkGeneration, error)
   855  	DeleteExpired(mctx MetaContext, merkleRoot MerkleRoot) ([]keybase1.EkGeneration, error)
   856  	ClearCache()
   857  	// Dangerous! Only for deprovisioning or shutdown/logout when in oneshot mode.
   858  	ForceDeleteAll(mctx MetaContext, username NormalizedUsername) error
   859  	// For keybase log send
   860  	ListAllForUser(mctx MetaContext) ([]string, error)
   861  	// Called on login/logout hooks to set the logged in username in the EK log
   862  	SetLogPrefix(mctx MetaContext)
   863  }
   864  
   865  type UserEKBoxStorage interface {
   866  	Put(mctx MetaContext, generation keybase1.EkGeneration, userEKBoxed keybase1.UserEkBoxed) error
   867  	Get(mctx MetaContext, generation keybase1.EkGeneration, contentCtime *gregor1.Time) (keybase1.UserEk, error)
   868  	MaxGeneration(mctx MetaContext, includeErrs bool) (keybase1.EkGeneration, error)
   869  	DeleteExpired(mctx MetaContext, merkleRoot MerkleRoot) ([]keybase1.EkGeneration, error)
   870  	ClearCache()
   871  }
   872  
   873  type TeamEKBoxStorage interface {
   874  	Put(mctx MetaContext, teamID keybase1.TeamID, generation keybase1.EkGeneration, teamEKBoxed keybase1.TeamEphemeralKeyBoxed) error
   875  	Get(mctx MetaContext, teamID keybase1.TeamID, generation keybase1.EkGeneration, contentCtime *gregor1.Time) (keybase1.TeamEphemeralKey, error)
   876  	MaxGeneration(mctx MetaContext, teamID keybase1.TeamID, includeErrs bool) (keybase1.EkGeneration, error)
   877  	DeleteExpired(mctx MetaContext, teamID keybase1.TeamID, merkleRoot MerkleRoot) ([]keybase1.EkGeneration, error)
   878  	PurgeCacheForTeamID(mctx MetaContext, teamID keybase1.TeamID) error
   879  	Delete(mctx MetaContext, teamID keybase1.TeamID, generation keybase1.EkGeneration) error
   880  	ClearCache()
   881  }
   882  
   883  type EKLib interface {
   884  	KeygenIfNeeded(mctx MetaContext) error
   885  	// Team ephemeral keys
   886  	GetOrCreateLatestTeamEK(mctx MetaContext, teamID keybase1.TeamID) (keybase1.TeamEphemeralKey, bool, error)
   887  	GetTeamEK(mctx MetaContext, teamID keybase1.TeamID, generation keybase1.EkGeneration, contentCtime *gregor1.Time) (keybase1.TeamEphemeralKey, error)
   888  	PurgeTeamEKCachesForTeamIDAndGeneration(mctx MetaContext, teamID keybase1.TeamID, generation keybase1.EkGeneration)
   889  	PurgeTeamEKCachesForTeamID(mctx MetaContext, teamID keybase1.TeamID)
   890  
   891  	// Teambot ephemeral keys
   892  	GetOrCreateLatestTeambotEK(mctx MetaContext, teamID keybase1.TeamID, botUID gregor1.UID) (keybase1.TeamEphemeralKey, bool, error)
   893  	GetTeambotEK(mctx MetaContext, teamID keybase1.TeamID, botUID gregor1.UID, generation keybase1.EkGeneration,
   894  		contentCtime *gregor1.Time) (keybase1.TeamEphemeralKey, error)
   895  	ForceCreateTeambotEK(mctx MetaContext, teamID keybase1.TeamID, botUID gregor1.UID,
   896  		generation keybase1.EkGeneration) (keybase1.TeamEphemeralKey, bool, error)
   897  	PurgeTeambotEKCachesForTeamIDAndGeneration(mctx MetaContext, teamID keybase1.TeamID, generation keybase1.EkGeneration)
   898  	PurgeTeambotEKCachesForTeamID(mctx MetaContext, teamID keybase1.TeamID)
   899  	PurgeAllTeambotMetadataCaches(mctx MetaContext)
   900  	PurgeTeambotMetadataCache(mctx MetaContext, teamID keybase1.TeamID, botUID keybase1.UID, generation keybase1.EkGeneration)
   901  
   902  	NewEphemeralSeed() (keybase1.Bytes32, error)
   903  	DeriveDeviceDHKey(seed keybase1.Bytes32) *NaclDHKeyPair
   904  	SignedDeviceEKStatementFromSeed(mctx MetaContext, generation keybase1.EkGeneration, seed keybase1.Bytes32, signingKey GenericKey) (keybase1.DeviceEkStatement, string, error)
   905  	BoxLatestUserEK(mctx MetaContext, receiverKey NaclDHKeyPair, deviceEKGeneration keybase1.EkGeneration) (*keybase1.UserEkBoxed, error)
   906  	PrepareNewUserEK(mctx MetaContext, merkleRoot MerkleRoot, pukSeed PerUserKeySeed) (string, []keybase1.UserEkBoxMetadata, keybase1.UserEkMetadata, *keybase1.UserEkBoxed, error)
   907  	BoxLatestTeamEK(mctx MetaContext, teamID keybase1.TeamID, uids []keybase1.UID) (*[]keybase1.TeamEkBoxMetadata, error)
   908  	PrepareNewTeamEK(mctx MetaContext, teamID keybase1.TeamID, signingKey NaclSigningKeyPair, uids []keybase1.UID) (string, *[]keybase1.TeamEkBoxMetadata, keybase1.TeamEkMetadata, *keybase1.TeamEkBoxed, error)
   909  	ClearCaches(mctx MetaContext)
   910  	// For testing
   911  	NewTeamEKNeeded(mctx MetaContext, teamID keybase1.TeamID) (bool, error)
   912  }
   913  
   914  type TeambotBotKeyer interface {
   915  	GetLatestTeambotKey(mctx MetaContext, teamID keybase1.TeamID, app keybase1.TeamApplication) (keybase1.TeambotKey, error)
   916  	GetTeambotKeyAtGeneration(mctx MetaContext, teamID keybase1.TeamID, app keybase1.TeamApplication,
   917  		generation keybase1.TeambotKeyGeneration) (keybase1.TeambotKey, error)
   918  
   919  	DeleteTeambotKeyForTest(mctx MetaContext, teamID keybase1.TeamID, app keybase1.TeamApplication,
   920  		generation keybase1.TeambotKeyGeneration) error
   921  }
   922  
   923  type TeambotMemberKeyer interface {
   924  	GetOrCreateTeambotKey(mctx MetaContext, teamID keybase1.TeamID, botUID gregor1.UID,
   925  		appKey keybase1.TeamApplicationKey) (keybase1.TeambotKey, bool, error)
   926  	PurgeCache(mctx MetaContext)
   927  	PurgeCacheAtGeneration(mctx MetaContext, teamID keybase1.TeamID, botUID keybase1.UID,
   928  		app keybase1.TeamApplication, generation keybase1.TeambotKeyGeneration)
   929  }
   930  
   931  type ImplicitTeamConflictInfoCacher interface {
   932  	Get(context.Context, bool, keybase1.TeamID) *keybase1.ImplicitTeamConflictInfo
   933  	Put(context.Context, bool, keybase1.TeamID, keybase1.ImplicitTeamConflictInfo) error
   934  }
   935  
   936  type KVStoreContext interface {
   937  	GetKVStore() KVStorer
   938  }
   939  
   940  type LRUContext interface {
   941  	VLogContext
   942  	KVStoreContext
   943  	ClockContext
   944  }
   945  
   946  type LRUKeyer interface {
   947  	MemKey() string
   948  	DbKey() DbKey
   949  }
   950  
   951  type LRUer interface {
   952  	Get(context.Context, LRUContext, LRUKeyer) (interface{}, error)
   953  	Put(context.Context, LRUContext, LRUKeyer, interface{}) error
   954  	OnLogout(mctx MetaContext) error
   955  	OnDbNuke(mctx MetaContext) error
   956  }
   957  
   958  type MemLRUer interface {
   959  	Get(key interface{}) (interface{}, bool)
   960  	Put(key, value interface{}) bool
   961  	OnLogout(mctx MetaContext) error
   962  	OnDbNuke(mctx MetaContext) error
   963  }
   964  
   965  type ClockContext interface {
   966  	GetClock() clockwork.Clock
   967  }
   968  
   969  type UIDMapperContext interface {
   970  	VLogContext
   971  	APIContext
   972  	KVStoreContext
   973  	ClockContext
   974  }
   975  
   976  type UsernamePackage struct {
   977  	NormalizedUsername NormalizedUsername
   978  	FullName           *keybase1.FullNamePackage
   979  }
   980  
   981  type SkinnyLogger interface {
   982  	// Error logs a message at error level, with formatting args
   983  	Errorf(format string, args ...interface{})
   984  	// Debug logs a message at debug level, with formatting args.
   985  	Debug(format string, args ...interface{})
   986  }
   987  
   988  type UIDMapper interface {
   989  	// CheckUIDAginstUsername makes sure that the UID actually does map to the given username.
   990  	// For new UIDs, it's a question of just SHA2'ing. For legacy usernames, we check the
   991  	// hardcoded map.
   992  	CheckUIDAgainstUsername(uid keybase1.UID, un NormalizedUsername) bool
   993  
   994  	// MapHardcodedUsernameToUID will map the given legacy username to a UID if it exists
   995  	// in the hardcoded map. If not, it will return the nil UID.
   996  	MapHardcodedUsernameToUID(un NormalizedUsername) keybase1.UID
   997  
   998  	// MapUIDToUsernamePackages maps the given set of UIDs to the username
   999  	// packages, which include a username and a fullname, and when the mapping
  1000  	// was loaded from the server. It blocks on the network until all usernames
  1001  	// are known. If the `forceNetworkForFullNames` flag is specified, it will
  1002  	// block on the network too. If the flag is not specified, then stale
  1003  	// values (or unknown values) are OK, we won't go to network if we lack
  1004  	// them. All network calls are limited by the given timeBudget, or if 0 is
  1005  	// specified, there is indefinite budget. In the response, a nil
  1006  	// FullNamePackage means that the lookup failed. A non-nil FullNamePackage
  1007  	// means that some previous lookup worked, but might be arbitrarily out of
  1008  	// date (depending on the cachedAt time). A non-nil FullNamePackage with an
  1009  	// empty fullName field means that the user just hasn't supplied a
  1010  	// fullName.
  1011  	//
  1012  	// *NOTE* that this function can return useful data and an error. In this
  1013  	// regard, the error is more like a warning. But if, for instance, the
  1014  	// mapper runs out of time budget, it will return the data
  1015  	MapUIDsToUsernamePackages(ctx context.Context, g UIDMapperContext, uids []keybase1.UID, fullNameFreshness time.Duration,
  1016  		networktimeBudget time.Duration, forceNetworkForFullNames bool) ([]UsernamePackage, error)
  1017  
  1018  	// SetTestingNoCachingMode puts the UID mapper into a mode where it never serves cached results, *strictly
  1019  	// for use in tests*
  1020  	SetTestingNoCachingMode(enabled bool)
  1021  
  1022  	ClearUIDFullName(context.Context, UIDMapperContext, keybase1.UID) error
  1023  
  1024  	// ClearUID is called to clear the given UID out of the cache, if the given eldest
  1025  	// seqno doesn't match what's currently cached.
  1026  	ClearUIDAtEldestSeqno(context.Context, UIDMapperContext, keybase1.UID, keybase1.Seqno) error
  1027  
  1028  	// InformOfEldestSeqno informs the mapper of an up-to-date (uid,eldestSeqno) pair.
  1029  	// If the cache has a different value, it will clear the cache and then plumb
  1030  	// the pair all the way through to the server, whose cache may also be in need
  1031  	// of busting. Will return true if the cached value was up-to-date, and false
  1032  	// otherwise.
  1033  	InformOfEldestSeqno(context.Context, UIDMapperContext, keybase1.UserVersion) (bool, error)
  1034  
  1035  	// MapUIDsToUsernamePackagesOffline maps given set of UIDs to username packages
  1036  	// from the cache only. No network calls will be made. Results might contains
  1037  	// unresolved usernames (caller should check with `IsNil()`).
  1038  	MapUIDsToUsernamePackagesOffline(ctx context.Context, g UIDMapperContext,
  1039  		uids []keybase1.UID, fullNameFreshness time.Duration) ([]UsernamePackage, error)
  1040  }
  1041  
  1042  type UserServiceSummary map[string]string // service -> username
  1043  type UserServiceSummaryPackage struct {
  1044  	CachedAt   keybase1.Time
  1045  	ServiceMap UserServiceSummary
  1046  }
  1047  
  1048  type ServiceSummaryMapper interface {
  1049  	MapUIDsToServiceSummaries(ctx context.Context, g UIDMapperContext, uids []keybase1.UID, freshness time.Duration,
  1050  		networkTimeBudget time.Duration) map[keybase1.UID]UserServiceSummaryPackage
  1051  	InformOfServiceSummary(ctx context.Context, g UIDMapperContext, uid keybase1.UID, summary UserServiceSummary) error
  1052  }
  1053  
  1054  type ChatHelper interface {
  1055  	NewConversation(ctx context.Context, uid gregor1.UID, tlfName string,
  1056  		topicName *string, topicType chat1.TopicType, membersType chat1.ConversationMembersType,
  1057  		vis keybase1.TLFVisibility) (chat1.ConversationLocal, bool, error)
  1058  	NewConversationSkipFindExisting(ctx context.Context, uid gregor1.UID, tlfName string,
  1059  		topicName *string, topicType chat1.TopicType, membersType chat1.ConversationMembersType,
  1060  		vis keybase1.TLFVisibility) (chat1.ConversationLocal, bool, error)
  1061  	NewConversationWithMemberSourceConv(ctx context.Context, uid gregor1.UID, tlfName string,
  1062  		topicName *string, topicType chat1.TopicType, membersType chat1.ConversationMembersType,
  1063  		vis keybase1.TLFVisibility, retentionPolicy *chat1.RetentionPolicy,
  1064  		memberSourceConv *chat1.ConversationID) (chat1.ConversationLocal, bool, error)
  1065  	SendTextByID(ctx context.Context, convID chat1.ConversationID,
  1066  		tlfName string, text string, vis keybase1.TLFVisibility) error
  1067  	SendMsgByID(ctx context.Context, convID chat1.ConversationID,
  1068  		tlfName string, body chat1.MessageBody, msgType chat1.MessageType, vis keybase1.TLFVisibility) error
  1069  	SendTextByIDNonblock(ctx context.Context, convID chat1.ConversationID,
  1070  		tlfName string, text string, outboxID *chat1.OutboxID, replyTo *chat1.MessageID) (chat1.OutboxID, error)
  1071  	SendMsgByIDNonblock(ctx context.Context, convID chat1.ConversationID,
  1072  		tlfName string, body chat1.MessageBody, msgType chat1.MessageType, outboxID *chat1.OutboxID,
  1073  		replyTo *chat1.MessageID) (chat1.OutboxID, error)
  1074  	SendTextByName(ctx context.Context, name string, topicName *string,
  1075  		membersType chat1.ConversationMembersType, ident keybase1.TLFIdentifyBehavior, text string) error
  1076  	SendMsgByName(ctx context.Context, name string, topicName *string,
  1077  		membersType chat1.ConversationMembersType, ident keybase1.TLFIdentifyBehavior, body chat1.MessageBody,
  1078  		msgType chat1.MessageType) error
  1079  	SendTextByNameNonblock(ctx context.Context, name string, topicName *string,
  1080  		membersType chat1.ConversationMembersType, ident keybase1.TLFIdentifyBehavior, text string,
  1081  		outboxID *chat1.OutboxID) (chat1.OutboxID, error)
  1082  	SendMsgByNameNonblock(ctx context.Context, name string, topicName *string,
  1083  		membersType chat1.ConversationMembersType, ident keybase1.TLFIdentifyBehavior, body chat1.MessageBody,
  1084  		msgType chat1.MessageType, outboxID *chat1.OutboxID) (chat1.OutboxID, error)
  1085  	DeleteMsg(ctx context.Context, convID chat1.ConversationID, tlfName string,
  1086  		msgID chat1.MessageID) error
  1087  	DeleteMsgNonblock(ctx context.Context, convID chat1.ConversationID, tlfName string,
  1088  		msgID chat1.MessageID) error
  1089  	FindConversations(ctx context.Context, name string,
  1090  		topicName *string, topicType chat1.TopicType, membersType chat1.ConversationMembersType,
  1091  		vis keybase1.TLFVisibility) ([]chat1.ConversationLocal, error)
  1092  	FindConversationsByID(ctx context.Context, convIDs []chat1.ConversationID) ([]chat1.ConversationLocal, error)
  1093  	JoinConversationByID(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID) error
  1094  	JoinConversationByName(ctx context.Context, uid gregor1.UID, tlfName, topicName string,
  1095  		topicType chat1.TopicType, vid keybase1.TLFVisibility) error
  1096  	LeaveConversation(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID) error
  1097  	GetChannelTopicName(context.Context, keybase1.TeamID, chat1.TopicType, chat1.ConversationID) (string, error)
  1098  	GetMessages(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID,
  1099  		msgIDs []chat1.MessageID, resolveSupersedes bool, reason *chat1.GetThreadReason) ([]chat1.MessageUnboxed, error)
  1100  	GetMessage(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID,
  1101  		msgID chat1.MessageID, resolveSupersedes bool, reason *chat1.GetThreadReason) (chat1.MessageUnboxed, error)
  1102  	UpgradeKBFSToImpteam(ctx context.Context, tlfName string, tlfID chat1.TLFID, public bool) error
  1103  	UserReacjis(ctx context.Context, uid gregor1.UID) keybase1.UserReacjis
  1104  	JourneycardTimeTravel(context.Context, gregor1.UID, time.Duration) (int, int, error)
  1105  	JourneycardResetAllConvs(context.Context, gregor1.UID) error
  1106  	JourneycardDebugState(context.Context, gregor1.UID, keybase1.TeamID) (string, error)
  1107  	// InTeam gives a best effort to answer team membership based on the current state of the inbox cache
  1108  	InTeam(context.Context, gregor1.UID, keybase1.TeamID) (bool, error)
  1109  	BulkAddToConv(context.Context, gregor1.UID, chat1.ConversationID, []string) error
  1110  }
  1111  
  1112  // Resolver resolves human-readable usernames (joe) and user asssertions (joe+joe@github)
  1113  // into UIDs. It is based on sever-trust. All results are unverified. So you should check
  1114  // its answer if used in a security-sensitive setting. (See engine.ResolveAndCheck)
  1115  type Resolver interface {
  1116  	EnableCaching(m MetaContext)
  1117  	Shutdown(m MetaContext)
  1118  	ResolveFullExpression(m MetaContext, input string) (res ResolveResult)
  1119  	ResolveFullExpressionNeedUsername(m MetaContext, input string) (res ResolveResult)
  1120  	ResolveFullExpressionWithBody(m MetaContext, input string) (res ResolveResult)
  1121  	ResolveUser(m MetaContext, assertion string) (u keybase1.User, res ResolveResult, err error)
  1122  	ResolveWithBody(m MetaContext, input string) ResolveResult
  1123  	Resolve(m MetaContext, input string) ResolveResult
  1124  	PurgeResolveCache(m MetaContext, input string) error
  1125  	CacheTeamResolution(m MetaContext, id keybase1.TeamID, name keybase1.TeamName)
  1126  }
  1127  
  1128  type EnginePrereqs struct {
  1129  	TemporarySession bool
  1130  	Device           bool
  1131  }
  1132  
  1133  type Engine2 interface {
  1134  	Run(MetaContext) error
  1135  	Prereqs() EnginePrereqs
  1136  	UIConsumer
  1137  }
  1138  
  1139  type SaltpackRecipientKeyfinderEngineInterface interface {
  1140  	Engine2
  1141  	GetPublicKIDs() []keybase1.KID
  1142  	GetSymmetricKeys() []SaltpackReceiverSymmetricKey
  1143  	UsedUnresolvedSBSAssertion() (bool, string)
  1144  }
  1145  
  1146  type SaltpackRecipientKeyfinderArg struct {
  1147  	Recipients        []string // usernames or user assertions
  1148  	TeamRecipients    []string // team names
  1149  	NoSelfEncrypt     bool
  1150  	UseEntityKeys     bool // Both per user and per team keys (and implicit teams for non existing users)
  1151  	UsePaperKeys      bool
  1152  	UseDeviceKeys     bool // Does not include Paper Keys
  1153  	UseRepudiableAuth bool // This is needed as team keys (implicit or not) are not compatible with repudiable authentication, so we can error out.
  1154  	NoForcePoll       bool // if we want to stop forcepolling, which is on by default, but should be off for GUI
  1155  }
  1156  
  1157  type SaltpackReceiverSymmetricKey struct {
  1158  	Key        [32]byte
  1159  	Identifier []byte
  1160  }
  1161  
  1162  type StandaloneChatConnector interface {
  1163  	StartStandaloneChat(g *GlobalContext) error
  1164  }
  1165  
  1166  type SyncedContactListProvider interface {
  1167  	SaveProcessedContacts(MetaContext, []keybase1.ProcessedContact) error
  1168  	RetrieveContacts(MetaContext) ([]keybase1.ProcessedContact, error)
  1169  	RetrieveAssertionToName(MetaContext) (map[string]string, error)
  1170  	UnresolveContactsWithComponent(MetaContext, *keybase1.PhoneNumber, *keybase1.EmailAddress)
  1171  }
  1172  
  1173  type KVRevisionCacher interface {
  1174  	Check(mctx MetaContext, entryID keybase1.KVEntryID, ciphertext *string, teamKeyGen keybase1.PerTeamKeyGeneration, revision int) (err error)
  1175  	Put(mctx MetaContext, entryID keybase1.KVEntryID, ciphertext *string, teamKeyGen keybase1.PerTeamKeyGeneration, revision int) (err error)
  1176  	CheckForUpdate(mctx MetaContext, entryID keybase1.KVEntryID, revision int) (err error)
  1177  	MarkDeleted(mctx MetaContext, entryID keybase1.KVEntryID, revision int) (err error)
  1178  }
  1179  
  1180  type AvatarLoaderSource interface {
  1181  	LoadUsers(MetaContext, []string, []keybase1.AvatarFormat) (keybase1.LoadAvatarsRes, error)
  1182  	LoadTeams(MetaContext, []string, []keybase1.AvatarFormat) (keybase1.LoadAvatarsRes, error)
  1183  
  1184  	ClearCacheForName(MetaContext, string, []keybase1.AvatarFormat) error
  1185  	OnDbNuke(MetaContext) error // Called after leveldb data goes away after db nuke
  1186  
  1187  	StartBackgroundTasks(MetaContext)
  1188  	StopBackgroundTasks(MetaContext)
  1189  }
  1190  
  1191  type RuntimeStats interface {
  1192  	Start(context.Context)
  1193  	Stop(context.Context) chan struct{}
  1194  	PushPerfEvent(keybase1.PerfEvent)
  1195  }