-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
credential_definition.go
101 lines (95 loc) · 3.22 KB
/
credential_definition.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
package acapy
import (
"fmt"
)
func (c *Client) CreateCredentialDefinition(tag string, supportRevocation bool, revocationRegistrySize int, schemaID string) (string, error) {
var request = struct {
Tag string `json:"tag"`
SupportRevocation bool `json:"support_revocation,omitempty"`
RevocationRegistrySize int `json:"revocation_registry_size,omitempty"`
SchemaID string `json:"schema_id"`
}{
Tag: tag,
SupportRevocation: supportRevocation,
RevocationRegistrySize: revocationRegistrySize,
SchemaID: schemaID,
}
var response = struct {
CredentialDefinitionID string `json:"credential_definition_id"`
}{}
err := c.post("/credential-definitions", nil, request, &response)
if err != nil {
return "", err
}
return response.CredentialDefinitionID, nil
}
type QueryCredentialDefinitionsParams struct {
CredentialDefinitionID string `json:"cred_def_id"`
IssuerDID string `json:"issuer_did"`
SchemaID string `json:"schema_id"`
SchemaIssuerDID string `json:"schema_issuer_did"`
SchemaName string `json:"schema_name"`
SchemaVersion string `json:"schema_version"`
}
func (c *Client) QueryCredentialDefinitions(params QueryCredentialDefinitionsParams) ([]string, error) {
var result = struct {
CredentialDefinitionIDs []string `json:"credential_definition_ids"`
}{}
queryParams := map[string]string{
"cred_def_id": params.CredentialDefinitionID,
"issuer_did": params.IssuerDID,
"schema_id": params.SchemaID,
"schema_issuer_did": params.SchemaIssuerDID,
"schema_name": params.SchemaName,
"schema_version": params.SchemaVersion,
}
err := c.get("/credential-definitions/created", queryParams, &result)
if err != nil {
return nil, err
}
return result.CredentialDefinitionIDs, nil
}
type R struct {
Score string `json:"score"`
MasterSecret string `json:"master_secret"`
}
type Primary struct {
N string `json:"n"`
S string `json:"s"`
R R `json:"r"`
Rctxt string `json:"rctxt"`
Z string `json:"z"`
}
type Revocation struct {
G string `json:"g"`
GDash string `json:"g_dash"`
H string `json:"h"`
H0 string `json:"h0"`
H1 string `json:"h1"`
H2 string `json:"h2"`
Htilde string `json:"htilde"`
HCap string `json:"h_cap"`
U string `json:"u"`
Pk string `json:"pk"`
Y string `json:"y"`
}
type CredentialDefinitionValue struct {
Primary Primary `json:"primary"`
Revocation Revocation `json:"revocation"`
}
type CredentialDefinition struct {
Version string `json:"ver"`
ID string `json:"id"`
SchemaID string `json:"schemaId"`
Type string `json:"type"`
Tag string `json:"tag"`
Value CredentialDefinitionValue `json:"value"`
}
func (c *Client) GetCredentialDefinition(credentialDefinitionID string) (CredentialDefinition, error) {
var credentialDefinition CredentialDefinition
err := c.get(fmt.Sprintf("/credential-definitions/%s", credentialDefinitionID), nil, &credentialDefinition)
if err != nil {
return CredentialDefinition{}, err
}
return credentialDefinition, nil
}