-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keybase.go
131 lines (119 loc) · 4.01 KB
/
keybase.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package moul
import (
"encoding/json"
"github.com/parnurzeal/gorequest"
"github.com/patrickmn/go-cache"
)
func init() {
RegisterAction("keybase", GetKeybaseProfileAction)
}
type KeybaseProof struct {
HumanURL string `json:"human_url"`
Nametag string `json:"nametag"`
PresentationGroup string `json:"presentation_group"`
PresentationTag string `json:"presentation_tag"`
ProofID string `json:"proof_id"`
ProofType string `json:"proof_type"`
ProofURL string `json:"proof_url"`
ServiceURL string `json:"service_url"`
SigID string `json:"sig_id"`
State int `json:"state"`
}
type KeybaseUser struct {
Basics struct {
Ctime int `json:"ctime"`
IDVersion int `json:"id_version"`
LastIDChange int `json:"last_id_change"`
Mtime int `json:"mtime"`
TrackVersion int `json:"track_version"`
Username string `json:"username"`
UsernameCased string `json:"username_cased"`
} `json:"basics"`
CryptocurrencyAddresses map[string][]struct {
Address string `json:"address"`
SigID string `json:"sig_id"`
} `json:"cryptocurrency_addresses"`
Devices struct{} `json:"devices"`
ID string `json:"id"`
Pictures map[string]struct {
Height int `json:"height"`
Source string `json:"source"`
URL string `json:"url"`
Width int `json:"width"`
} `json:"pictures"`
Profile struct {
Bio string `json:"bio"`
FullName string `json:"full_name"`
Location string `json:"location"`
Mtime int `json:"mtime"`
} `json:"profile"`
ProofsSummary struct {
All []KeybaseProof `json:"all"`
ByPresentationGroup map[string][]KeybaseProof `json:"by_presentation_group"`
ByProofType map[string][]KeybaseProof `json:"by_proof_type"`
} `json:"proofs_summary"`
PublicKeys struct {
AllBundles []string `json:"all_bundles"`
EldestKeyFingerprint string `json:"eldest_key_fingerprint"`
EldestKid string `json:"eldest_kid"`
Families map[string][]string `json:"families"`
PgpPublicKeys []string `json:"pgp_public_keys"`
Primary struct {
Bundle string `json:"bundle"`
Ctime int `json:"ctime"`
EldestKid interface{} `json:"eldest_kid"`
Etime int `json:"etime"`
KeyAlgo int `json:"key_algo"`
KeyBits int `json:"key_bits"`
KeyFingerprint string `json:"key_fingerprint"`
KeyLevel int `json:"key_level"`
KeyType int `json:"key_type"`
Kid string `json:"kid"`
Mtime int `json:"mtime"`
SelfSigned bool `json:"self_signed"`
SigningKid string `json:"signing_kid"`
Status int `json:"status"`
Ukbid string `json:"ukbid"`
} `json:"primary"`
Sibkeys []string `json:"sibkeys"`
Subkeys []interface{} `json:"subkeys"`
} `json:"public_keys"`
Sigs struct {
Last struct {
PayloadHash string `json:"payload_hash"`
Seqno int `json:"seqno"`
SigID string `json:"sig_id"`
} `json:"last"`
} `json:"sigs"`
}
type KeybaseResponse struct {
Status struct {
Code int
Name string
}
Them []KeybaseUser
}
const KeybaseLookupURL = "https://keybase.io/_/api/1.0/user/lookup.json?usernames=moul"
func GetKeybaseProfileAction(args []string) (interface{}, error) {
if profile, found := moulCache.Get("keybase-profile"); found {
return profile, nil
}
profile, err := GetKeybaseProfile()
if err != nil {
return nil, err
}
moulCache.Set("keybase-profile", profile, cache.DefaultExpiration)
return profile, nil
}
func GetKeybaseProfile() (*KeybaseUser, error) {
_, body, errs := gorequest.New().Get(KeybaseLookupURL).End()
if len(errs) > 0 {
return nil, errs[0]
}
var response KeybaseResponse
if err := json.Unmarshal([]byte(body), &response); err != nil {
return nil, err
}
user := response.Them[0]
return &user, nil
}