This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
/
main.go
58 lines (45 loc) · 2.2 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
// +build wasm
// Package portablegabi is used to wrap the gabi library into a wasm module.
package main
import (
"syscall/js"
"github.com/KILTprotocol/portablegabi/go-wasm/pkg/wasm"
)
var c chan bool
func init() {
c = make(chan bool)
}
func CloseWasm(js.Value, []js.Value) interface{} {
close(c)
return nil
}
func main() {
// expose all methods to the js environment. Use callbacker to transform the
// return style methods to callback style methods.
methods := make(map[string]js.Func)
methods["genKeypair"] = js.FuncOf(wasm.Callbacker(wasm.GenKeypair))
methods["createAccumulator"] = js.FuncOf(wasm.Callbacker(wasm.CreateAccumulator))
methods["startAttestationSession"] = js.FuncOf(wasm.Callbacker(wasm.StartAttestationSession))
methods["issueAttestation"] = js.FuncOf(wasm.Callbacker(wasm.IssueAttestation))
methods["revokeAttestation"] = js.FuncOf(wasm.Callbacker(wasm.RevokeAttestation))
methods["genKey"] = js.FuncOf(wasm.Callbacker(wasm.GenKey))
methods["keyFromSeed"] = js.FuncOf(wasm.Callbacker(wasm.KeyFromSeed))
methods["requestAttestation"] = js.FuncOf(wasm.Callbacker(wasm.RequestAttestation))
methods["buildCredential"] = js.FuncOf(wasm.Callbacker(wasm.BuildCredential))
methods["buildPresentation"] = js.FuncOf(wasm.Callbacker(wasm.BuildPresentation))
methods["buildCombinedPresentation"] = js.FuncOf(wasm.Callbacker(wasm.BuildCombinedPresentation))
methods["updateCredential"] = js.FuncOf(wasm.Callbacker(wasm.UpdateCredential))
methods["updateAllCredential"] = js.FuncOf(wasm.Callbacker(wasm.UpdateAllCredential))
methods["requestPresentation"] = js.FuncOf(wasm.Callbacker(wasm.RequestPresentation))
methods["requestCombinedPresentation"] = js.FuncOf(wasm.Callbacker(wasm.RequestCombinedPresentation))
methods["verifyPresentation"] = js.FuncOf(wasm.Callbacker(wasm.VerifyPresentation))
methods["verifyCombinedPresentation"] = js.FuncOf(wasm.Callbacker(wasm.VerifyCombinedPresentation))
methods["getAccumulatorIndex"] = js.FuncOf(wasm.Callbacker(wasm.GetAccumulatorIndex))
methods["getAccumulatorTimestamp"] = js.FuncOf(wasm.Callbacker(wasm.GetAccumulatorTimestamp))
methods["closeWasm"] = js.FuncOf(CloseWasm)
for k, v := range methods {
js.Global().Set(k, v)
defer v.Release()
}
<-c
}