Skip to content

Commit

Permalink
hook up wot review screen (keybase#24001)
Browse files Browse the repository at this point in the history
* hook up wot review screen

* fix test

* weird cast

* feedback non-optional field

* feedback
  • Loading branch information
mlsteele authored May 4, 2020
1 parent 64cf164 commit 98bf68f
Show file tree
Hide file tree
Showing 21 changed files with 356 additions and 117 deletions.
4 changes: 1 addition & 3 deletions go/client/cmd_wot_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ func (c *cmdWotList) Run() error {
line(" `keybase wot revoke %s` to revoke your proposed vouch (coming soon)", vouch.VoucheeUsername) // TODO
}
}
if vouch.Confidence != nil {
line("Additional Details: %+v", *vouch.Confidence)
}
line("Additional Details: %+v", vouch.Confidence)
line("-------------------------------")
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions go/engine/wot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestWebOfTrustPending(t *testing.T) {
require.EqualValues(t, bobVouch, vouches[0])
charlieVouch := vouches[1]
require.Equal(t, keybase1.WotStatusType_PROPOSED, charlieVouch.Status)
require.Equal(t, confidence, *charlieVouch.Confidence)
require.Equal(t, confidence, charlieVouch.Confidence)
t.Log("alice sees two pending vouches")

// alice gets just charlie's vouch using FetchWotVouches
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestWebOfTrustAccept(t *testing.T) {
require.Equal(t, keybase1.WotStatusType_ACCEPTED, vouch.Status)
require.Equal(t, bob.User.GetUID(), vouch.Voucher.Uid)
require.Equal(t, vouchText, vouch.VouchText)
require.EqualValues(t, confidence, *vouch.Confidence)
require.EqualValues(t, confidence, vouch.Confidence)

vouches, err = libkb.FetchWotVouches(mctxB, libkb.FetchWotVouchesArg{Vouchee: aliceName})
require.NoError(t, err)
Expand All @@ -275,7 +275,7 @@ func TestWebOfTrustAccept(t *testing.T) {
require.Equal(t, keybase1.WotStatusType_ACCEPTED, vouch.Status)
require.Equal(t, bob.User.GetUID(), vouch.Voucher.Uid)
require.Equal(t, vouchText, vouch.VouchText)
require.EqualValues(t, confidence, *vouch.Confidence)
require.EqualValues(t, confidence, vouch.Confidence)
}

func TestWebOfTrustReject(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions go/externals/proof_service_generic_social.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ func (t *GenericSocialProofServiceType) ProveParameters(mctx libkb.MetaContext)
subtext = t.DisplayName()
}
return keybase1.ProveParameters{
LogoFull: MakeIcons(mctx, t.GetLogoKey(), "logo_full", 64),
LogoBlack: MakeIcons(mctx, t.GetLogoKey(), "logo_black", 16),
LogoWhite: MakeIcons(mctx, t.GetLogoKey(), "logo_white", 16),
LogoFull: libkb.MakeProofIcons(mctx, t.GetLogoKey(), "logo_full", 64),
LogoBlack: libkb.MakeProofIcons(mctx, t.GetLogoKey(), "logo_black", 16),
LogoWhite: libkb.MakeProofIcons(mctx, t.GetLogoKey(), "logo_white", 16),
Title: t.config.Domain,
Subtext: subtext,
Suffix: fmt.Sprintf("@%v", t.config.Domain),
Expand Down
44 changes: 17 additions & 27 deletions go/identify3/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,29 +240,23 @@ func (i *UIAdapter) rowPartial(mctx libkb.MetaContext, proof keybase1.RemoteProo
humanURLOrSigchainURL = i.makeSigchainViewURL(mctx, proof.SigID)
}

iconKey := proof.Key
row.ProofURL = humanURLOrSigchainURL
switch proof.ProofType {
case keybase1.ProofType_TWITTER:
row.SiteURL = fmt.Sprintf("https://twitter.com/%v", proof.Value)
iconKey = "twitter"
case keybase1.ProofType_GITHUB:
row.SiteURL = fmt.Sprintf("https://github.com/%v", proof.Value)
iconKey = "github"
case keybase1.ProofType_REDDIT:
row.SiteURL = fmt.Sprintf("https://reddit.com/user/%v", proof.Value)
iconKey = "reddit"
case keybase1.ProofType_HACKERNEWS:
// hackernews profile urls must have the username in its original casing.
username := proof.Value
if libkb.Cicmp(proof.Value, proof.DisplayMarkup) {
username = proof.DisplayMarkup
}
row.SiteURL = fmt.Sprintf("https://news.ycombinator.com/user?id=%v", username)
iconKey = "hackernews"
case keybase1.ProofType_FACEBOOK:
row.SiteURL = fmt.Sprintf("https://facebook.com/%v", proof.Value)
iconKey = "facebook"
case keybase1.ProofType_GENERIC_SOCIAL:
row.SiteURL = humanURLOrSigchainURL
serviceType := mctx.G().GetProofServices().GetServiceType(mctx.Ctx(), proof.Key)
Expand All @@ -273,9 +267,6 @@ func (i *UIAdapter) rowPartial(mctx libkb.MetaContext, proof keybase1.RemoteProo
row.SiteURL = profileURL
}
}
iconKey = serviceType.GetLogoKey()
} else {
iconKey = proof.Key
}
row.ProofURL = i.makeSigchainViewURL(mctx, proof.SigID)
case keybase1.ProofType_GENERIC_WEB_SITE:
Expand All @@ -284,18 +275,17 @@ func (i *UIAdapter) rowPartial(mctx libkb.MetaContext, proof keybase1.RemoteProo
protocol = "http"
}
row.SiteURL = fmt.Sprintf("%v://%v", protocol, proof.Value)
iconKey = "web"
case keybase1.ProofType_DNS:
row.SiteURL = fmt.Sprintf("http://%v", proof.Value)
row.ProofURL = i.makeSigchainViewURL(mctx, proof.SigID)
iconKey = "web"
default:
row.SiteURL = humanURLOrSigchainURL
}
row.SiteIcon = externals.MakeIcons(mctx, iconKey, externals.IconTypeSmall, 16)
row.SiteIconDarkmode = externals.MakeIcons(mctx, iconKey, externals.IconTypeSmallDarkmode, 16)
row.SiteIconFull = externals.MakeIcons(mctx, iconKey, externals.IconTypeFull, 64)
row.SiteIconFullDarkmode = externals.MakeIcons(mctx, iconKey, externals.IconTypeFullDarkmode, 64)
iconKey := libkb.ProofIconKey(mctx, proof.ProofType, proof.Key)
row.SiteIcon = libkb.MakeProofIcons(mctx, iconKey, libkb.ProofIconTypeSmall, 16)
row.SiteIconDarkmode = libkb.MakeProofIcons(mctx, iconKey, libkb.ProofIconTypeSmallDarkmode, 16)
row.SiteIconFull = libkb.MakeProofIcons(mctx, iconKey, libkb.ProofIconTypeFull, 64)
row.SiteIconFullDarkmode = libkb.MakeProofIcons(mctx, iconKey, libkb.ProofIconTypeFullDarkmode, 64)
switch proof.ProofType {
case keybase1.ProofType_NONE, keybase1.ProofType_PGP:
// These types are not eligible for web-of-trust selection.
Expand Down Expand Up @@ -370,10 +360,10 @@ func (i *UIAdapter) displayKey(mctx libkb.MetaContext, key keybase1.IdentifyKey)
SiteURL: i.makeKeybaseProfileURL(mctx),
// key.SigID is blank if the PGP key was there pre-sigchain
ProofURL: i.makeSigchainViewURL(mctx, key.SigID),
SiteIcon: externals.MakeIcons(mctx, "pgp", externals.IconTypeSmall, 16),
SiteIconDarkmode: externals.MakeIcons(mctx, "pgp", externals.IconTypeSmallDarkmode, 16),
SiteIconFull: externals.MakeIcons(mctx, "pgp", externals.IconTypeFull, 64),
SiteIconFullDarkmode: externals.MakeIcons(mctx, "pgp", externals.IconTypeFullDarkmode, 64),
SiteIcon: libkb.MakeProofIcons(mctx, "pgp", libkb.ProofIconTypeSmall, 16),
SiteIconDarkmode: libkb.MakeProofIcons(mctx, "pgp", libkb.ProofIconTypeSmallDarkmode, 16),
SiteIconFull: libkb.MakeProofIcons(mctx, "pgp", libkb.ProofIconTypeFull, 64),
SiteIconFullDarkmode: libkb.MakeProofIcons(mctx, "pgp", libkb.ProofIconTypeFullDarkmode, 64),
Kid: &key.KID,
// PICNIC-1092 consider adding `WotProof` to support pgp in web-of-trust.
}
Expand Down Expand Up @@ -515,10 +505,10 @@ func (i *UIAdapter) plumbCryptocurrency(mctx libkb.MetaContext, crypto keybase1.
SigID: crypto.SigID,
Ctime: 0,
SiteURL: i.makeSigchainViewURL(mctx, crypto.SigID),
SiteIcon: externals.MakeIcons(mctx, key, externals.IconTypeSmall, 16),
SiteIconDarkmode: externals.MakeIcons(mctx, key, externals.IconTypeSmallDarkmode, 16),
SiteIconFull: externals.MakeIcons(mctx, key, externals.IconTypeFull, 64),
SiteIconFullDarkmode: externals.MakeIcons(mctx, key, externals.IconTypeFullDarkmode, 64),
SiteIcon: libkb.MakeProofIcons(mctx, key, libkb.ProofIconTypeSmall, 16),
SiteIconDarkmode: libkb.MakeProofIcons(mctx, key, libkb.ProofIconTypeSmallDarkmode, 16),
SiteIconFull: libkb.MakeProofIcons(mctx, key, libkb.ProofIconTypeFull, 64),
SiteIconFullDarkmode: libkb.MakeProofIcons(mctx, key, libkb.ProofIconTypeFullDarkmode, 64),
ProofURL: i.makeSigchainViewURL(mctx, crypto.SigID),
})
}
Expand All @@ -537,10 +527,10 @@ func (i *UIAdapter) plumbStellarAccount(mctx libkb.MetaContext, str keybase1.Ste
SigID: str.SigID,
Ctime: 0,
SiteURL: i.makeSigchainViewURL(mctx, str.SigID),
SiteIcon: externals.MakeIcons(mctx, "stellar", externals.IconTypeSmall, 16),
SiteIconDarkmode: externals.MakeIcons(mctx, "stellar", externals.IconTypeSmallDarkmode, 16),
SiteIconFull: externals.MakeIcons(mctx, "stellar", externals.IconTypeFull, 64),
SiteIconFullDarkmode: externals.MakeIcons(mctx, "stellar", externals.IconTypeFullDarkmode, 64),
SiteIcon: libkb.MakeProofIcons(mctx, "stellar", libkb.ProofIconTypeSmall, 16),
SiteIconDarkmode: libkb.MakeProofIcons(mctx, "stellar", libkb.ProofIconTypeSmallDarkmode, 16),
SiteIconFull: libkb.MakeProofIcons(mctx, "stellar", libkb.ProofIconTypeFull, 64),
SiteIconFullDarkmode: libkb.MakeProofIcons(mctx, "stellar", libkb.ProofIconTypeFullDarkmode, 64),
ProofURL: i.makeSigchainViewURL(mctx, str.SigID),
})
}
Expand Down
17 changes: 8 additions & 9 deletions go/externals/icon.go → go/libkb/proof_icon.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package externals
package libkb

import (
"fmt"
"strings"

"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
)

Expand All @@ -21,20 +20,20 @@ func normalizeIconKey(key string) string {
}
}

const IconTypeSmall = "logo_black"
const IconTypeSmallDarkmode = "logo_white"
const IconTypeFull = "logo_full"
const IconTypeFullDarkmode = "logo_full_darkmode"
const ProofIconTypeSmall = "logo_black"
const ProofIconTypeSmallDarkmode = "logo_white"
const ProofIconTypeFull = "logo_full"
const ProofIconTypeFullDarkmode = "logo_full_darkmode"

func MakeIcons(mctx libkb.MetaContext, serviceKey, iconType string, size int) (res []keybase1.SizedImage) {
func MakeProofIcons(mctx MetaContext, serviceKey, iconType string, size int) (res []keybase1.SizedImage) {
for _, factor := range []int{1, 2} {
factorix := ""
if factor > 1 {
factorix = fmt.Sprintf("@%vx", factor)
}

site := libkb.SiteURILookup[mctx.G().Env.GetRunMode()]
if mctx.G().Env.GetRunMode() == libkb.DevelRunMode {
site := SiteURILookup[mctx.G().Env.GetRunMode()]
if mctx.G().Env.GetRunMode() == DevelRunMode {
site = strings.Replace(site, "localhost", "127.0.0.1", 1)
}

Expand Down
50 changes: 50 additions & 0 deletions go/libkb/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,3 +1231,53 @@ func NewWotProof(proofType keybase1.ProofType, key, value string) (res keybase1.
return res, fmt.Errorf("unexpected proof type: %v", proofType)
}
}

// Format a web-of-trust proof for gui display.
func NewWotProofUI(mctx MetaContext, proof keybase1.WotProof) (res keybase1.WotProofUI, err error) {
iconKey := ProofIconKey(mctx, proof.ProofType, proof.Name)
res = keybase1.WotProofUI{
SiteIcon: MakeProofIcons(mctx, iconKey, ProofIconTypeSmall, 16),
SiteIconDarkmode: MakeProofIcons(mctx, iconKey, ProofIconTypeSmallDarkmode, 16),
}
switch proof.ProofType {
case keybase1.ProofType_TWITTER, keybase1.ProofType_GITHUB, keybase1.ProofType_REDDIT,
keybase1.ProofType_COINBASE, keybase1.ProofType_HACKERNEWS, keybase1.ProofType_FACEBOOK,
keybase1.ProofType_GENERIC_SOCIAL, keybase1.ProofType_ROOTER:
res.Type = proof.Name
res.Value = proof.Username
case keybase1.ProofType_GENERIC_WEB_SITE:
res.Type = proof.Protocol
res.Value = proof.Hostname
case keybase1.ProofType_DNS:
res.Type = "dns"
res.Value = proof.Domain
default:
return res, fmt.Errorf("unexpected proof type: %v", proof.ProofType)
}
return res, nil
}

func ProofIconKey(mctx MetaContext, proofType keybase1.ProofType, genericKeyAndFallback string) (iconKey string) {
switch proofType {
case keybase1.ProofType_TWITTER:
return "twitter"
case keybase1.ProofType_GITHUB:
return "github"
case keybase1.ProofType_REDDIT:
return "reddit"
case keybase1.ProofType_HACKERNEWS:
return "hackernews"
case keybase1.ProofType_FACEBOOK:
return "facebook"
case keybase1.ProofType_GENERIC_SOCIAL:
serviceType := mctx.G().GetProofServices().GetServiceType(mctx.Ctx(), genericKeyAndFallback)
if serviceType != nil {
return serviceType.GetLogoKey()
}
return genericKeyAndFallback
case keybase1.ProofType_GENERIC_WEB_SITE, keybase1.ProofType_DNS:
return "web"
default:
return genericKeyAndFallback
}
}
21 changes: 13 additions & 8 deletions go/libkb/wot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package libkb
import (
"encoding/json"
"fmt"
"reflect"
"strings"

"github.com/keybase/client/go/kbun"
Expand Down Expand Up @@ -76,9 +75,9 @@ type wotExpansionUser struct {
}

type vouchExpansion struct {
User wotExpansionUser `json:"user"`
Confidence *keybase1.Confidence `json:"confidence,omitempty"`
VouchText string `json:"vouch_text"`
User wotExpansionUser `json:"user"`
Confidence keybase1.Confidence `json:"confidence"`
VouchText string `json:"vouch_text"`
}

type reactionExpansion struct {
Expand Down Expand Up @@ -115,10 +114,6 @@ func transformUserVouch(mctx MetaContext, serverVouch serverWotVouch, voucheeUse
if err != nil {
return res, fmt.Errorf("error casting vouch expansion object to expected web-of-trust schema: %s", err.Error())
}
if wotObj.Confidence != nil && reflect.DeepEqual(*wotObj.Confidence, keybase1.Confidence{}) {
// nil out an empty confidence
wotObj.Confidence = nil
}

if voucheeUser == nil || voucheeUser.GetUID() != serverVouch.Vouchee {
// load vouchee
Expand Down Expand Up @@ -175,6 +170,15 @@ func transformUserVouch(mctx MetaContext, serverVouch serverWotVouch, voucheeUse
return res, fmt.Errorf("could not determine the status of web-of-trust from %s", voucher.GetName())
}

var proofs []keybase1.WotProofUI
for _, proof := range wotObj.Confidence.Proofs {
proofForUI, err := NewWotProofUI(mctx, proof)
if err != nil {
return res, err
}
proofs = append(proofs, proofForUI)
}

// build a WotVouch
return keybase1.WotVouch{
Status: status,
Expand All @@ -186,6 +190,7 @@ func transformUserVouch(mctx MetaContext, serverVouch serverWotVouch, voucheeUse
VouchProof: serverVouch.VouchSigID,
VouchedAt: keybase1.ToTime(wotVouchLink.GetCTime()),
Confidence: wotObj.Confidence,
Proofs: proofs,
}, nil
}

Expand Down
Loading

0 comments on commit 98bf68f

Please sign in to comment.