-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
wallet.go
99 lines (88 loc) · 2.1 KB
/
wallet.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
package acapy
import (
"strconv"
)
type QueryDIDsParams DID
type DID struct {
DID string `json:"did"`
Public bool `json:"public"`
VerKey string `json:"verkey"`
}
func (c *Client) QueryDIDs(params QueryDIDsParams) ([]DID, error) {
type results struct {
DIDs []DID `json:"results"`
}
var r results
queryParams := map[string]string{
"did": params.DID,
"public": strconv.FormatBool(params.Public),
"verkey": params.VerKey,
}
err := c.get("/wallet/did", queryParams, &r)
if err != nil {
return nil, err
}
return r.DIDs, nil
}
type didResult struct {
DID `json:"didResult"`
}
func (c *Client) CreateLocalDID() (DID, error) {
var r didResult
err := c.post("/wallet/didResult/create", nil, nil, &r)
if err != nil {
return DID{}, err
}
return r.DID, nil
}
func (c *Client) GetPublicDID() (DID, error) {
var r didResult
err := c.get("/wallet/did/public", nil, &r)
if err != nil {
return DID{}, err
}
return r.DID, nil
}
func (c *Client) SetPublicDID(did string) (DID, error) {
var r didResult
queryParams := map[string]string{
"did": did,
}
err := c.post("/wallet/did/public", queryParams, nil, &r)
if err != nil {
return DID{}, err
}
return r.DID, nil
}
func (c *Client) SetDIDEndpointInWallet(did string, endpoint string, endpointType string) error {
var setDIDEndpointRequest = struct {
DID string `json:"did"`
Endpoint string `json:"endpoint"`
EndpointType string `json:"endpoint_type"`
}{
DID: did,
Endpoint: endpoint,
EndpointType: endpointType,
}
return c.post("/wallet/set-did-endpoint", nil, setDIDEndpointRequest, nil)
}
func (c *Client) GetDIDEndpointFromWallet(did string) (string, error) {
var r = struct {
DID string `json:"did"`
Endpoint string `json:"endpoint"`
}{}
queryParams := map[string]string{
"did": did,
}
err := c.get("/wallet/get-did-endpoint", queryParams, &r)
if err != nil {
return "", err
}
return r.Endpoint, nil
}
func (c *Client) RotateKeypair(did string) error {
queryParams := map[string]string{
"did": did,
}
return c.patch("/wallet/did/local/rotate-keypair", queryParams, nil, nil)
}