-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
sigchain_examples_test.go
53 lines (45 loc) · 1.62 KB
/
sigchain_examples_test.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
package client_test
import (
"context"
"fmt"
"log"
"github.com/keys-pub/keys"
"github.com/keys-pub/keys-ext/http/client"
"github.com/keys-pub/keys/http"
"github.com/keys-pub/keys/user"
"github.com/keys-pub/keys/user/services"
)
func ExampleClient_Sigchain() {
cl, err := client.New("https://keys.pub")
if err != nil {
log.Fatal(err)
}
// Get the keys.Sigchain.
kid := keys.ID("kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3")
resp, err := cl.Sigchain(context.TODO(), kid)
if err != nil {
log.Fatal(err)
}
sc, err := resp.Sigchain()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", sc.Spew())
// Find the user.User in the keys.Sigchain.
usr, err := user.FindInSigchain(sc)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", usr)
// Verify the user.
result := services.Verify(context.TODO(), services.HTTPS, http.NewClient(), usr)
if result.Status != user.StatusOK {
log.Fatalf("User check failed: %+v", result)
}
// Check result status.
fmt.Printf("%s\n", result.Status)
// Output:
// /sigchain/kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3/1 {".sig":"Rf39uRlHXTqmOjcqUs5BTssshRdqpaFfmoYYJuA5rNVGgGd/bRG8p8ZebB8K+w9kozMpnuAoa4lko+oPHcabCQ==","data":"eyJrIjoia2V4MXlkZWNhdWxzZzVxdHkyYXh5eTc3MGNqZHZxbjNlZjJxYTg1eHc4N3AwOXlkbHZzNWx1cnE1M3gwcDMiLCJuIjoia2V5cy5wdWIiLCJzcSI6MSwic3IiOiJodHRwcyIsInUiOiJodHRwczovL2tleXMucHViL2tleXNwdWIudHh0In0=","kid":"kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3","seq":1,"ts":1588276919715,"type":"user"}
// keys.pub@https!kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3-1#https://keys.pub/keyspub.txt
// ok
}