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