-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
revocation_registry.go
268 lines (248 loc) · 9.36 KB
/
revocation_registry.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package acapy
import (
"fmt"
)
type RevocationRegistry struct {
UpdatedAt string `json:"updated_at"`
Type string `json:"revoc_def_type"`
PendingPub []interface{} `json:"pending_pub"`
CreatedAt string `json:"created_at"`
Tag string `json:"tag"`
RecordID string `json:"record_id"`
CredDefID string `json:"cred_def_id"`
TailsHash string `json:"tails_hash"`
MaxCredNum int `json:"max_cred_num"`
State string `json:"state"`
IssuerDid string `json:"issuer_did"`
Definition RevocationRegistryDefinition `json:"revoc_reg_def"`
TailsLocalPath string `json:"tails_local_path"`
Entry RevocationRegistryEntry `json:"revoc_reg_entry"`
RevocationRegistryID string `json:"revoc_reg_id"`
}
type AccumKey struct {
Z string `json:"z"`
}
type PublicKeys struct {
AccumKey AccumKey `json:"accumKey"`
}
type RevocationRegistryDefinitionValue struct {
IssuanceType string `json:"issuanceType"`
MaxCredNum int `json:"maxCredNum"`
PublicKeys PublicKeys `json:"publicKeys"`
TailsHash string `json:"tailsHash"`
TailsLocation string `json:"tailsLocation"`
}
type RevocationRegistryDefinition struct {
Ver string `json:"ver"`
ID string `json:"id"`
RevocDefType string `json:"revocDefType"`
Tag string `json:"tag"`
CredDefID string `json:"credDefId"`
Value RevocationRegistryDefinitionValue `json:"value"`
}
type Value struct {
Accum string `json:"accum"`
}
type RevocationRegistryEntry struct {
Ver string `json:"ver"`
Value RevocationRegistryDefinitionValue `json:"value"`
}
type CredentialRevocationRecord struct {
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
CredentialDefinitionID string `json:"cred_def_id"`
CredentialRevocationID string `json:"cred_rev_id"`
RecordID string `json:"record_id"`
RevocationRegistryID string `json:"rev_reg_id"`
CredentialExchangeID string `json:"cred_ex_id"`
State string `json:"state"` // issued/revoked
}
func (c *Client) CreateRevocationRegistry(credentialDefinitionID string, maxCredNum int) (RevocationRegistry, error) {
var result = struct {
RevocationRegistry RevocationRegistry `json:"result"`
}{}
var body = struct {
CredentialDefinitionID string `json:"credential_definition_id"`
MaxCredNum int `json:"max_cred_num"`
}{
CredentialDefinitionID: credentialDefinitionID,
MaxCredNum: maxCredNum,
}
err := c.post("/revocation/create-registry", nil, body, &result)
if err != nil {
return RevocationRegistry{}, err
}
return result.RevocationRegistry, nil
}
func (c *Client) QueryRevocationRegistries(credentialDefinitionID string, state string) ([]string, error) {
var queryParams = map[string]string{
"cred_def_id": credentialDefinitionID,
"state": state,
}
var result = struct {
RevocationRegistryIDs []string `json:"rev_reg_ids"`
}{}
err := c.get("/revocation/registries/created", queryParams, &result)
if err != nil {
return nil, err
}
return result.RevocationRegistryIDs, nil
}
func (c *Client) GetRevocationRegistry(revocationRegistryID string) (RevocationRegistry, error) {
var result = struct {
RevocationRegistry RevocationRegistry `json:"result"`
}{}
err := c.get(fmt.Sprintf("/revocation/registry/%s", revocationRegistryID), nil, &result)
if err != nil {
return RevocationRegistry{}, err
}
return result.RevocationRegistry, nil
}
func (c *Client) UpdateRevocationRegistryTailsURI(revocationRegistryID string, tailsPublicURI string) (RevocationRegistry, error) {
var result = struct {
RevocationRegistry RevocationRegistry `json:"result"`
}{}
var body = struct {
TailsPublicURI string `json:"tails_public_uri"`
}{
TailsPublicURI: tailsPublicURI,
}
err := c.patch(fmt.Sprintf("/revocation/registry/%s", revocationRegistryID), nil, body, &result)
if err != nil {
return RevocationRegistry{}, err
}
return result.RevocationRegistry, nil
}
func (c *Client) GetActiveRevocationRegistry(credentialDefinitionID string) (RevocationRegistry, error) {
var revocationRegistry RevocationRegistry
err := c.get(fmt.Sprintf("/revocation/active-registry/%s", credentialDefinitionID), nil, &revocationRegistry)
if err != nil {
return RevocationRegistry{}, err
}
return revocationRegistry, nil
}
func (c *Client) DownloadRegistryTailsFile(revocationRegistryID string) ([]byte, error) {
tailsFile, err := c.getFile(fmt.Sprintf("/revocation/registry/%s/tails-file", revocationRegistryID))
if err != nil {
return nil, err
}
return tailsFile, nil
}
func (c *Client) UploadRegistryTailsFile(revocationRegistryID string) error {
return c.put(fmt.Sprintf("/revocation/registry/%s/tails-file", revocationRegistryID))
}
func (c *Client) PublishRevocationRegistryDefinition(revocationRegistryID string) (RevocationRegistry, error) {
var result = struct {
RevocationRegistry RevocationRegistry `json:"result"`
}{}
err := c.post(fmt.Sprintf("/revocation/registry/%s/definition", revocationRegistryID), nil, nil, &result)
if err != nil {
return RevocationRegistry{}, err
}
return result.RevocationRegistry, nil
}
func (c *Client) PublishRevocationRegistryEntry(revocationRegistryID string) (RevocationRegistry, error) {
var result = struct {
RevocationRegistry RevocationRegistry `json:"result"`
}{}
err := c.post(fmt.Sprintf("/revocation/registry/%s/entry", revocationRegistryID), nil, nil, &result)
if err != nil {
return RevocationRegistry{}, err
}
return result.RevocationRegistry, nil
}
func (c *Client) SetRevocationRegistryState(revocationRegistryID string, state string) (RevocationRegistry, error) {
var result = struct {
RevocationRegistry RevocationRegistry `json:"result"`
}{}
var queryParams = map[string]string{
"state": state,
}
err := c.patch(fmt.Sprintf("/revocation/registry/%s/set-state", revocationRegistryID), queryParams, nil, &result)
if err != nil {
return RevocationRegistry{}, err
}
return result.RevocationRegistry, nil
}
func (c *Client) RevokeIssuedCredential(credentialExchangeID string, credentialRevocationID string, revocationRegistryID string, publish bool) error {
// either (RevocationRegistryID and CredentialRevocationID) OR
// CredentialExchangeID
var body = struct {
CredentialExchangeID string `json:"cred_ex_id,omitempty"`
CredentialRevocationID string `json:"cred_rev_id,omitempty"`
RevocationRegistryID string `json:"rev_reg_id,omitempty"`
Publish bool `json:"publish"`
}{
CredentialExchangeID: credentialExchangeID,
CredentialRevocationID: credentialRevocationID,
RevocationRegistryID: revocationRegistryID,
Publish: publish,
}
return c.post("/revocation/revoke", nil, body, nil)
}
// A map from revocation registry identifier to credential revocation identifiers
// For example:
// map[string][]string{
// "6i7GFi2cDx524ZNfxmGWcp:4:6i7GFi2cDx524ZNfxmGWcp:3:CL:165:default:CL_ACCUM:159875bc-a5c7-4d51-b5c0-b4782a01fb94": ["1"].
// }
type PendingRevocations map[string][]string
// PublishRevocations
// Pass nil in case you want to publish all pending revocations
func (c *Client) PublishRevocations(revocations PendingRevocations) error {
if revocations == nil {
revocations = PendingRevocations{}
}
var body = struct {
Body PendingRevocations `json:"rrid2crid"`
}{
Body: revocations,
}
return c.post("/revocation/publish-revocations", nil, body, nil)
}
// ClearPendingRevocations
// Pass nil in case you want to clear all pending revocations
func (c *Client) ClearPendingRevocations(revocations PendingRevocations) (PendingRevocations, error) {
if revocations == nil {
revocations = PendingRevocations{}
}
var result = struct {
Result PendingRevocations `json:"rrid2crid"`
}{}
var body = struct {
Body map[string][]string `json:"purge"`
}{
Body: revocations,
}
err := c.post("/revocation/clear-pending-revocations", nil, body, &result)
if err != nil {
return nil, err
}
return result.Result, nil
}
func (c *Client) GetCredentialRevocationStatus(credentialExchangeID string, credentialRevocationID string, revocationRegistryID string) (CredentialRevocationRecord, error) {
// either (RevocationRegistryID and CredentialRevocationID) OR
// CredentialExchangeID
var queryParams = map[string]string{
"cred_ex_id": credentialExchangeID,
"cred_rev_id": credentialRevocationID,
"rev_reg_id": revocationRegistryID,
}
var result = struct {
Result CredentialRevocationRecord `json:"result"`
}{}
err := c.get("/revocation/credential-record", queryParams, &result)
if err != nil {
return CredentialRevocationRecord{}, err
}
return result.Result, nil
}
func (c *Client) GetNumberOfIssuedCredentials(revocationRegistryID string) (int, error) {
var result = struct {
Result int `json:"result"`
}{}
err := c.get(fmt.Sprintf("/revocation/registry/%s/issued", revocationRegistryID), nil, &result)
if err != nil {
return 0, err
}
return result.Result, nil
}