forked from keybase/client
/
prove_check.go
85 lines (72 loc) · 2.17 KB
/
prove_check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
// ProveCheck looks for an active proof in the logged in user's id
// table for a service, username pair.
package engine
import (
"fmt"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
// ProveCheck is an engine.
type ProveCheck struct {
libkb.Contextified
sigID keybase1.SigID
found bool
status keybase1.ProofStatus
state keybase1.ProofState
proofText string
}
// NewProveCheck creates a ProveCheck engine.
func NewProveCheck(g *libkb.GlobalContext, sigID keybase1.SigID) *ProveCheck {
return &ProveCheck{
Contextified: libkb.NewContextified(g),
sigID: sigID,
}
}
// Name is the unique engine name.
func (e *ProveCheck) Name() string {
return "ProveCheck"
}
// GetPrereqs returns the engine prereqs.
func (e *ProveCheck) Prereqs() Prereqs {
return Prereqs{Device: true}
}
// RequiredUIs returns the required UIs.
func (e *ProveCheck) RequiredUIs() []libkb.UIKind {
return []libkb.UIKind{}
}
// SubConsumers returns the other UI consumers for this engine.
func (e *ProveCheck) SubConsumers() []libkb.UIConsumer {
return nil
}
// Run starts the engine.
func (e *ProveCheck) Run(m libkb.MetaContext) error {
found, status, state, err := libkb.CheckPosted(m, e.sigID)
if err != nil {
return err
}
e.found = found
e.status = status
e.state = state
m.Debug("looking for ChainLink for %s", e.sigID)
me, err := libkb.LoadMe(libkb.NewLoadUserArgWithMetaContext(m).WithPublicKeyOptional())
if err != nil {
return err
}
link := me.LinkFromSigID(e.sigID)
if link == nil {
return fmt.Errorf("no chain link found for %s", e.sigID)
}
m.Debug("chain link found: (%T)", link.Typed())
if rlink, ok := link.Typed().(libkb.RemoteProofChainLink); ok {
e.proofText = rlink.ProofText()
m.Debug("chain link proof text: %q", e.proofText)
} else {
m.Warning("chain link had invalid type: %T", link.Typed())
}
return nil
}
func (e *ProveCheck) Results() (found bool, status keybase1.ProofStatus, state keybase1.ProofState, proofText string) {
return e.found, e.status, e.state, e.proofText
}