github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/engine/hasserverkeys.go (about)

     1  // Copyright 2016 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package engine
     5  
     6  import (
     7  	"github.com/keybase/client/go/libkb"
     8  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
     9  )
    10  
    11  // HasServerKeys is an engine.
    12  type HasServerKeys struct {
    13  	libkb.Contextified
    14  	res keybase1.HasServerKeysRes
    15  }
    16  
    17  // NewHasServerKeys creates a HasServerKeys engine.
    18  func NewHasServerKeys(g *libkb.GlobalContext) *HasServerKeys {
    19  	return &HasServerKeys{
    20  		Contextified: libkb.NewContextified(g),
    21  	}
    22  }
    23  
    24  // Name is the unique engine name.
    25  func (e *HasServerKeys) Name() string {
    26  	return "HasServerKeys"
    27  }
    28  
    29  // Prereqs returns the engine prereqs.
    30  func (e *HasServerKeys) Prereqs() Prereqs {
    31  	return Prereqs{
    32  		Device: true,
    33  	}
    34  }
    35  
    36  // RequiredUIs returns the required UIs.
    37  func (e *HasServerKeys) RequiredUIs() []libkb.UIKind {
    38  	return []libkb.UIKind{}
    39  }
    40  
    41  // SubConsumers returns the other UI consumers for this engine.
    42  func (e *HasServerKeys) SubConsumers() []libkb.UIConsumer {
    43  	return nil
    44  }
    45  
    46  // Run starts the engine.
    47  func (e *HasServerKeys) Run(m libkb.MetaContext) error {
    48  	apiRes, err := m.G().API.Get(m, libkb.APIArg{
    49  		Endpoint:    "key/fetch_private",
    50  		Args:        libkb.HTTPArgs{},
    51  		SessionType: libkb.APISessionTypeREQUIRED,
    52  	})
    53  	if err != nil {
    54  		return err
    55  	}
    56  	var spk libkb.ServerPrivateKeys
    57  	if err = apiRes.Body.UnmarshalAgain(&spk); err != nil {
    58  		m.Debug("error unmarshaling ServerPrivateKeys")
    59  		return err
    60  	}
    61  	e.res.HasServerKeys = len(spk.PrivateKeys) > 0
    62  	m.Debug("HasServerKeys: %v", e.res.HasServerKeys)
    63  
    64  	return nil
    65  }
    66  
    67  func (e *HasServerKeys) GetResult() keybase1.HasServerKeysRes {
    68  	return e.res
    69  }