-
Notifications
You must be signed in to change notification settings - Fork 1
/
credentials.go
306 lines (250 loc) · 11.4 KB
/
credentials.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
package protocol
import (
"encoding/json"
"github.com/iden3/go-schema-processor/v2/verifiable"
"github.com/iden3/iden3comm/v2"
)
const (
// CredentialIssuanceRequestMessageType accepts request for credential creation
CredentialIssuanceRequestMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/1.0/issuance-request"
// CredentialFetchRequestMessageType is type for request of credential generation
CredentialFetchRequestMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/1.0/fetch-request"
// CredentialOfferMessageType is type of message with credential offering
CredentialOfferMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/1.0/offer"
// CredentialIssuanceResponseMessageType is type for message with a credential issuance
CredentialIssuanceResponseMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/1.0/issuance-response"
// CredentialStatusUpdateMessageType is type for message with a credential status update
CredentialStatusUpdateMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/1.0/status-update"
// CredentialRefreshMessageType is type for message with a credential refresh
CredentialRefreshMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/1.0/refresh"
// CredentialOnchainOfferMessageType is type for message with a credential onchain offer
CredentialOnchainOfferMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/1.0/onchain-offer"
// CredentialProposalRequestMessageType is type for request of the credential proposal
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
CredentialProposalRequestMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/0.1/proposal-request"
// CredentialProposalMessageType is type for proposal of the verifiable credential
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
CredentialProposalMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/0.1/proposal"
// CredentialOfferStatusPending is a type when a credential issuance is in the process
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
CredentialOfferStatusPending = "pending"
// CredentialOfferStatusCompleted if credential issuance is happened successfully
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
CredentialOfferStatusCompleted = "completed"
// CredentialOfferStatusRejected - if credential issuance is not possible for some reason
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
CredentialOfferStatusRejected = "rejected"
// CredentialProposalTypeWeb - if credential issuance is not possible for some reason
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
CredentialProposalTypeWeb = "WebVerificationFormV1.0"
)
// CredentialIssuanceRequestMessage represent Iden3message for credential request
type CredentialIssuanceRequestMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body CredentialIssuanceRequestMessageBody `json:"body,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
// CredentialIssuanceRequestMessageBody represents data for credential issuance request
type CredentialIssuanceRequestMessageBody struct {
Schema Schema `json:"schema"`
Data json.RawMessage `json:"data"`
Expiration int64 `json:"expiration"`
}
// CredentialsOfferMessage represent Iden3message for credential offer
type CredentialsOfferMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body CredentialsOfferMessageBody `json:"body,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
// CredentialsOfferMessageBody is struct the represents offer message
type CredentialsOfferMessageBody struct {
URL string `json:"url"`
Credentials []CredentialOffer `json:"credentials"`
}
// CredentialOffer is structure to fetch credential
type CredentialOffer struct {
ID string `json:"id"`
Description string `json:"description"`
Status string `json:"status,omitempty"`
}
// CredentialIssuanceMessage represent Iden3message for credential issuance
type CredentialIssuanceMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body IssuanceMessageBody `json:"body,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
// IssuanceMessageBody is struct the represents message when credential is issued
type IssuanceMessageBody struct {
Credential verifiable.W3CCredential `json:"credential"`
}
// CredentialFetchRequestMessage represent Iden3message for credential fetch request
type CredentialFetchRequestMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body CredentialFetchRequestMessageBody `json:"body,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
// CredentialFetchRequestMessageBody is msg body for fetch request
type CredentialFetchRequestMessageBody struct {
ID string `json:"id"`
}
// Schema represents location and type where it's stored
type Schema struct {
Hash string `json:"hash,omitempty"`
URL string `json:"url"`
Type string `json:"type"`
}
// CredentialStatusUpdateMessage represents credential status update message
type CredentialStatusUpdateMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body CredentialStatusUpdateMessageBody `json:"body,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
// CredentialStatusUpdateMessageBody the structure that represents the body of credential status update message
type CredentialStatusUpdateMessageBody struct {
ID string `json:"id"`
Reason string `json:"reason"`
}
// CredentialRefreshMessage represent Iden3message for credential refresh message
type CredentialRefreshMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body CredentialRefreshMessageBody `json:"body,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
// CredentialRefreshMessageBody is msg body for refresh message
type CredentialRefreshMessageBody struct {
ID string `json:"id"`
Reason string `json:"reason"`
}
// CredentialsOnchainOfferMessage represent Iden3message for credential onchain offer
type CredentialsOnchainOfferMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body CredentialsOnchainOfferMessageBody `json:"body,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
// CredentialsOnchainOfferMessageBody is struct the represents onchain offer message
type CredentialsOnchainOfferMessageBody struct {
Credentials []CredentialOffer `json:"credentials"`
TransactionData TransactionData `json:"transaction_data"`
}
// CredentialsProposalRequestMessage represent Iden3message for credential proposal request
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
type CredentialsProposalRequestMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body CredentialsProposalRequestBody `json:"body,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
// CredentialsProposalMessage represents Iden3message for credential proposal
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
type CredentialsProposalMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body CredentialsProposalBody `json:"body,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
// CredentialsProposalRequestBody is msg body for proposal requests
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
type CredentialsProposalRequestBody struct {
Credentials []CredentialInfo `json:"credentials"`
Metadata *Metadata `json:"metadata,omitempty"`
DIDDoc json.RawMessage `json:"did_doc,omitempty"`
}
// CredentialInfo is a part of credential proposal request bodys
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
type CredentialInfo struct {
Type string `json:"type"`
Context string `json:"context"`
}
// Metadata is metadata for credential proposal
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
type Metadata struct {
Type string `json:"type"`
Data string `json:"data"`
}
// CredentialsProposalBody is a body for a credential proposal message
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
type CredentialsProposalBody struct {
Proposals []CredentialProposalInfo `json:"proposals"`
}
// CredentialProposalInfo is a info of specific proposal that can relate to many credentials
//
// # Experimental
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
type CredentialProposalInfo struct {
Credentials []CredentialInfo `json:"credentials,omitempty"`
Type string `json:"type"`
URL string `json:"url"`
Expiration string `json:"expiration,omitempty"`
Description string `json:"description,omitempty"`
}