github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/externals/proof_service_rooter.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  //go:build !production
     5  // +build !production
     6  
     7  package externals
     8  
     9  import (
    10  	"regexp"
    11  	"strings"
    12  
    13  	libkb "github.com/keybase/client/go/libkb"
    14  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    15  	jsonw "github.com/keybase/go-jsonw"
    16  )
    17  
    18  // =============================================================================
    19  // Rooter
    20  //
    21  
    22  type RooterChecker struct {
    23  	proof libkb.RemoteProofChainLink
    24  }
    25  
    26  var _ libkb.ProofChecker = (*RooterChecker)(nil)
    27  
    28  func NewRooterChecker(p libkb.RemoteProofChainLink) (*RooterChecker, libkb.ProofError) {
    29  	return &RooterChecker{p}, nil
    30  }
    31  
    32  func (rc *RooterChecker) GetTorError() libkb.ProofError { return nil }
    33  
    34  func (rc *RooterChecker) CheckStatus(mctx libkb.MetaContext, h libkb.SigHint, _ libkb.ProofCheckerMode,
    35  	pvlU keybase1.MerkleStoreEntry) (*libkb.SigHint, libkb.ProofError) {
    36  	// TODO CORE-8951 see if we can populate verifiedHint with anything useful.
    37  	return nil, CheckProofPvl(mctx, keybase1.ProofType_ROOTER, rc.proof, h, pvlU)
    38  }
    39  
    40  //
    41  // =============================================================================
    42  
    43  type RooterServiceType struct{ libkb.BaseServiceType }
    44  
    45  func (t *RooterServiceType) Key() string { return t.GetTypeName() }
    46  
    47  var rooterUsernameRegexp = regexp.MustCompile(`^(?i:[a-z0-9_]{1,20})$`)
    48  
    49  func (t *RooterServiceType) NormalizeUsername(s string) (string, error) {
    50  	if !rooterUsernameRegexp.MatchString(s) {
    51  		return "", libkb.NewBadUsernameError(s)
    52  	}
    53  	return strings.ToLower(s), nil
    54  }
    55  
    56  func (t *RooterServiceType) NormalizeRemoteName(_ libkb.MetaContext, s string) (string, error) {
    57  	// Allow a leading '@'.
    58  	s = strings.TrimPrefix(s, "@")
    59  	return t.NormalizeUsername(s)
    60  }
    61  
    62  func (t *RooterServiceType) GetPrompt() string {
    63  	return "Your username on Rooter"
    64  }
    65  
    66  func (t *RooterServiceType) CanMakeNewProofs(mctx libkb.MetaContext) bool {
    67  	return mctx.G().GetRunMode() != libkb.ProductionRunMode
    68  }
    69  
    70  func (t *RooterServiceType) ToServiceJSON(un string) *jsonw.Wrapper {
    71  	return t.BaseToServiceJSON(t, un)
    72  }
    73  
    74  func (t *RooterServiceType) PostInstructions(un string) *libkb.Markup {
    75  	return libkb.FmtMarkup(`Please toot the following, and don't delete it:`)
    76  }
    77  
    78  func (t *RooterServiceType) DisplayName() string   { return "Rooter" }
    79  func (t *RooterServiceType) GetTypeName() string   { return "rooter" }
    80  func (t *RooterServiceType) PickerSubtext() string { return "" }
    81  func (t *RooterServiceType) RecheckProofPosting(tryNumber int, status keybase1.ProofStatus, _ string) (warning *libkb.Markup, err error) {
    82  	return t.BaseRecheckProofPosting(tryNumber, status)
    83  }
    84  func (t *RooterServiceType) GetProofType() string { return "test.web_service_binding.rooter" }
    85  
    86  func (t *RooterServiceType) CheckProofText(text string, id keybase1.SigID, sig string) (err error) {
    87  	return t.BaseCheckProofTextShort(text, id, true)
    88  }
    89  
    90  func (t *RooterServiceType) MakeProofChecker(l libkb.RemoteProofChainLink) libkb.ProofChecker {
    91  	return &RooterChecker{l}
    92  }
    93  
    94  func (t *RooterServiceType) IsDevelOnly() bool { return true }