-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (72 loc) · 1.93 KB
/
main.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
package main
import (
"github.com/go-errors/errors"
"github.com/minvws/nl-covid19-coronacheck-idemix/verifier"
"github.com/privacybydesign/gabi"
"encoding/json"
"fmt"
"syscall/js"
)
func PrettyPrint(v interface{}, created int64) (string) {
data := map[string]interface{}{
"created": created,
"attributes": v,
}
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
return err.Error()
}
return string(b)
}
func registerCallbacks() {
js.Global().Set("loadCerts", js.FuncOf(loadCerts))
js.Global().Set("readCode", js.FuncOf(readCode))
}
func main() {
c := make(chan struct{}, 0)
println("WASM Go Initialized")
/* Register callback functions */
registerCallbacks()
<-c
}
func loadCerts(this js.Value, i []js.Value) interface{} {
if (len(i) < 1) {
fmt.Println("Missing arguments")
}
testPk, _ = gabi.NewPublicKeyFromXML(i[0].String())
vwsCc1Pk, _ = gabi.NewPublicKeyFromXML(i[1].String())
vwsCc2Pk, _ = gabi.NewPublicKeyFromXML(i[2].String())
return "Certificates loaded"
}
func readCode(this js.Value, i []js.Value) interface{} {
if (len(i) < 1) {
fmt.Println("Missing arguments")
}
qrData := []byte(i[0].String())
/* Verify */
v := createVerifier2()
verifiedCred, err := v.VerifyQREncoded(qrData)
if err != nil {
fmt.Println("Could not verify disclosed credential:", err.Error())
}
/* Return data */
return PrettyPrint(verifiedCred.Attributes, verifiedCred.DisclosureTimeSeconds)
}
func createVerifier2() *verifier.Verifier {
return verifier.New(holderFindIssuerPk2)
}
func holderFindIssuerPk2(issuerPkId string) (*gabi.PublicKey, error) {
issuerPks := map[string]*gabi.PublicKey{
"testPk": testPk,
"VWS-CC-1": vwsCc1Pk,
"VWS-CC-2": vwsCc2Pk,
}
issuerPk, ok := issuerPks[issuerPkId]
if !ok {
return nil, errors.Errorf("Could not find public key id (%s) chosen by issuer", issuerPkId)
}
return issuerPk, nil
}
var testPk *gabi.PublicKey
var vwsCc1Pk *gabi.PublicKey
var vwsCc2Pk *gabi.PublicKey