-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
543 lines (452 loc) · 15.9 KB
/
types.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
package identity
import (
"math/big"
core "github.com/iden3/go-iden3-core/v2"
babyjub "github.com/iden3/go-iden3-crypto/babyjub"
merkletree "github.com/rarimo/go-merkletree"
verifiable "github.com/rarimo/go-schema-processor/verifiable"
)
type StateProvider interface {
ProveAuthV2(inputs []byte) ([]byte, error)
GetGISTProof(userId string, blockNumber string) ([]byte, error)
ProveCredentialAtomicQueryMTPV2OnChainVoting(inputs []byte) ([]byte, error)
}
type FinalizedResponse struct {
IsFinalized bool `json:"isFinalized"`
StateInfo *StateInfo `json:"stateInfo"`
}
type TreeState struct {
State *merkletree.Hash
ClaimsRoot *merkletree.Hash
RevocationsRoot *merkletree.Hash
RootsRoot *merkletree.Hash
}
type NodeAuxValue struct {
key merkletree.Hash
value merkletree.Hash
noAux string
}
type AuthV2CircuitInputs struct {
GenesisID string `json:"genesisID"`
ProfileNonce string `json:"profileNonce"`
AuthClaim *core.Claim `json:"authClaim"`
AuthClaimMtp []*merkletree.Hash `json:"authClaimIncMtp"`
AuthClaimNonRevMtp []*merkletree.Hash `json:"authClaimNonRevMtp"`
AuthClaimNonRevMtpAuxHi *merkletree.Hash `json:"authClaimNonRevMtpAuxHi"`
AuthClaimNonRevMtpAuxHv *merkletree.Hash `json:"authClaimNonRevMtpAuxHv"`
AuthClaimNonRevMtpNoAux string `json:"authClaimNonRevMtpNoAux"`
Challenge string `json:"challenge"`
ChallengeSignatureR8X string `json:"challengeSignatureR8x"`
ChallengeSignatureR8Y string `json:"challengeSignatureR8y"`
ChallengeSignatureS string `json:"challengeSignatureS"`
ClaimsTreeRoot *merkletree.Hash `json:"claimsTreeRoot"`
RevTreeRoot *merkletree.Hash `json:"revTreeRoot"`
RootsTreeRoot *merkletree.Hash `json:"rootsTreeRoot"`
State *merkletree.Hash `json:"state"`
GISTRoot *merkletree.Hash `json:"gistRoot"`
GISTMtp []*merkletree.Hash `json:"gistMtp"`
GISTMtpAuxHi *merkletree.Hash `json:"gistMtpAuxHi"`
GISTMtpAuxHv *merkletree.Hash `json:"gistMtpAuxHv"`
GISTMtpNoAux string `json:"gistMtpNoAux"`
}
type GISTProofInfo struct {
Root *merkletree.Hash `json:"root"`
Existence bool `json:"existence"`
Siblings [64]*merkletree.Hash `json:"siblings"`
Index *merkletree.Hash `json:"index"`
Value *merkletree.Hash `json:"value"`
AuxExistence bool `json:"aux_existence"`
AuxIndex *merkletree.Hash `json:"aux_index"`
AuxValue *merkletree.Hash `json:"aux_value"`
}
func (p *GISTProofInfo) GetProof() (*GISTProof, error) {
gistProof := &GISTProof{
Root: p.Root,
}
proof := merkletree.Proof{
Existence: p.Existence,
}
if p.AuxExistence {
proof.NodeAux = &merkletree.NodeAux{
Key: p.AuxIndex,
Value: p.AuxValue,
}
}
siblings := make([]*merkletree.Hash, 0, 64)
for _, s := range p.Siblings {
siblings = append(siblings, s)
}
proof.Siblings = siblings
gistProof.Proof = &proof
return gistProof, nil
}
type GISTProof struct {
Root *merkletree.Hash `json:"root"`
Proof *merkletree.Proof `json:"proof"`
}
type ClaimOfferResponse struct {
Identifier string `json:"id"`
Typ string `json:"typ"`
ClaimType string `json:"type"`
ThreadID string `json:"threadID"`
Body CredentialsRequestBody `json:"body"`
From string `json:"from"`
To string `json:"to"`
}
type CredentialsRequestBody struct {
Credentials []CredentialRequest `json:"Credentials"`
Url string `json:"url"`
}
type CredentialStatus struct {
Identifier string `json:"id"`
InnerType string `json:"type"`
RevocationNonce *big.Int `json:"revocationNonce,omitempty"`
StatusIssuer *CredentialStatus `json:"statusIssuer,omitempty"`
}
type CredentialSchema struct {
Id string `json:"id"`
InnerType string `json:"type"`
}
type VSResponseBody struct {
Credential verifiable.W3CCredential `json:"credential"`
}
type VSResponse struct {
Body VSResponseBody `json:"body"`
}
type CredentialRequest struct {
Description string `json:"description"`
Identifier string `json:"id"`
}
type ClaimDetailsBody struct {
Id string `json:"id"`
}
type ClaimDetails struct {
Id string `json:"id"`
Typ string `json:"typ"`
ClaimType string `json:"type"`
ThreadID string `json:"threadID"`
Body ClaimDetailsBody `json:"body"`
From string `json:"from"`
To string `json:"to"`
}
type CircuitId string
const (
AtomicQueryMTPV2OnChainVotingCircuit CircuitId = "AtomicQueryMTPV2OnChainVoting"
)
type Operators int
const (
NOOP Operators = iota
EQ
LT
GT
IN
NIN
NE
)
type QueryWithFieldName struct {
Query Query
FieldName string
}
var QueryOperators = map[string]Operators{
"$noop": NOOP,
"$eq": EQ,
"$lt": LT,
"$gt": GT,
"$in": IN,
"$nin": NIN,
"$ne": NE,
}
type ChainInfo struct {
Identifier int64 `json:"id"`
RpcUrl string `json:"rpcUrl"`
StateContractAddress string `json:"stateContractAddress"`
RarimoNetworkType string `json:"rarimoNetworkType"`
}
func NewCredentialRequest(description string, id string) *CredentialRequest {
return &CredentialRequest{
Description: description,
Identifier: id,
}
}
func NewCredentialsRequestBody(credentials []CredentialRequest, url string) *CredentialsRequestBody {
return &CredentialsRequestBody{
Credentials: credentials,
Url: url,
}
}
func NewClaimOfferResponse(
id string,
typ string,
claimType string,
threadID string,
body CredentialsRequestBody,
from string,
to string,
) *ClaimOfferResponse {
return &ClaimOfferResponse{
Identifier: id,
Typ: typ,
ClaimType: claimType,
ThreadID: threadID,
Body: body,
From: from,
To: to,
}
}
type ProofData struct {
A []string `json:"pi_a"`
B [][]string `json:"pi_b"`
C []string `json:"pi_c"`
Protocol string `json:"protocol"`
}
type ZKProof struct {
Proof *ProofData `json:"proof"`
PubSignals []string `json:"pub_signals"`
}
type AtomicQueryMTPV2OnChainVotingCircuitInputs struct {
RequestID string `json:"requestID"`
// user data
UserGenesisID string `json:"userGenesisID"` //
ProfileNonce string `json:"profileNonce"` //
ClaimSubjectProfileNonce string `json:"claimSubjectProfileNonce"` //
IssuerID string `json:"issuerID"`
// Claim
IssuerClaim *core.Claim `json:"issuerClaim"`
// Inclusion
IssuerClaimMtp []*merkletree.Hash `json:"issuerClaimMtp"`
IssuerClaimClaimsTreeRoot *merkletree.Hash `json:"issuerClaimClaimsTreeRoot"`
IssuerClaimRevTreeRoot *merkletree.Hash `json:"issuerClaimRevTreeRoot"`
IssuerClaimRootsTreeRoot *merkletree.Hash `json:"issuerClaimRootsTreeRoot"`
IssuerClaimIdenState *merkletree.Hash `json:"issuerClaimIdenState"`
IssuerClaimNonRevClaimsTreeRoot *merkletree.Hash `json:"issuerClaimNonRevClaimsTreeRoot"`
IssuerClaimNonRevRevTreeRoot *merkletree.Hash `json:"issuerClaimNonRevRevTreeRoot"`
IssuerClaimNonRevRootsTreeRoot *merkletree.Hash `json:"issuerClaimNonRevRootsTreeRoot"`
IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
IssuerClaimNonRevMtp []*merkletree.Hash `json:"issuerClaimNonRevMtp"`
IssuerClaimNonRevMtpAuxHi *merkletree.Hash `json:"issuerClaimNonRevMtpAuxHi"`
IssuerClaimNonRevMtpAuxHv *merkletree.Hash `json:"issuerClaimNonRevMtpAuxHv"`
IssuerClaimNonRevMtpNoAux string `json:"issuerClaimNonRevMtpNoAux"`
IsRevocationChecked int `json:"isRevocationChecked"`
ClaimSchema string `json:"claimSchema"`
// Query
// JSON path
ClaimPathNotExists int `json:"claimPathNotExists"` // 0 for inclusion, 1 for non-inclusion
ClaimPathMtp []*merkletree.Hash `json:"claimPathMtp"`
ClaimPathMtpNoAux string `json:"claimPathMtpNoAux"` // 1 if aux node is empty,
// 0 if non-empty or for inclusion proofs
ClaimPathMtpAuxHi *merkletree.Hash `json:"claimPathMtpAuxHi"` // 0 for inclusion proof
ClaimPathMtpAuxHv *merkletree.Hash `json:"claimPathMtpAuxHv"` // 0 for inclusion proof
ClaimPathKey string `json:"claimPathKey"` // hash of path in merklized json-ld document
ClaimPathValue string `json:"claimPathValue"` // value in this path in merklized json-ld document
Operator int `json:"operator"`
SlotIndex int `json:"slotIndex"`
Timestamp int64 `json:"timestamp"`
Value []string `json:"value"`
// AuthClaim proof of inclusion
AuthClaim *core.Claim `json:"authClaim"`
AuthClaimMtp []*merkletree.Hash `json:"authClaimIncMtp"`
// AuthClaim non revocation proof
AuthClaimNonRevMtp []*merkletree.Hash `json:"authClaimNonRevMtp"`
AuthClaimNonRevMtpAuxHi *merkletree.Hash `json:"authClaimNonRevMtpAuxHi"`
AuthClaimNonRevMtpAuxHv *merkletree.Hash `json:"authClaimNonRevMtpAuxHv"`
AuthClaimNonRevMtpNoAux string `json:"authClaimNonRevMtpNoAux"`
Challenge string `json:"challenge"`
ChallengeSignatureR8X string `json:"challengeSignatureR8x"`
ChallengeSignatureR8Y string `json:"challengeSignatureR8y"`
ChallengeSignatureS string `json:"challengeSignatureS"`
// User State
ClaimsTreeRoot *merkletree.Hash `json:"userClaimsTreeRoot"`
RevTreeRoot *merkletree.Hash `json:"userRevTreeRoot"`
RootsTreeRoot *merkletree.Hash `json:"userRootsTreeRoot"`
State *merkletree.Hash `json:"userState"`
// Global on-chain state
GISTRoot *merkletree.Hash `json:"gistRoot"`
GISTMtp []*merkletree.Hash `json:"gistMtp"`
GISTMtpAuxHi *merkletree.Hash `json:"gistMtpAuxHi"`
GISTMtpAuxHv *merkletree.Hash `json:"gistMtpAuxHv"`
GISTMtpNoAux string `json:"gistMtpNoAux"`
VotingAddress string `json:"votingAddress"`
Commitment string `json:"commitment"`
}
type Issuer struct {
State string `json:"state"`
RootOfRoots string `json:"rootOfRoots"`
ClaimsTreeRoot string `json:"claimsTreeRoot"`
RevTreeRoot string `json:"revocationTreeRoot"`
}
func (i *Issuer) GetIssuerPreparedState() (*TreeState, error) {
state, err := merkletree.NewHashFromHex(i.State)
if err != nil {
return nil, err
}
rootOfRoots, err := merkletree.NewHashFromHex(i.RootOfRoots)
if err != nil {
return nil, err
}
claimsTreeRoot, err := merkletree.NewHashFromHex(i.ClaimsTreeRoot)
if err != nil {
return nil, err
}
revTreeRoot, err := merkletree.NewHashFromHex(i.RevTreeRoot)
if err != nil {
return nil, err
}
return &TreeState{
State: state,
RootsRoot: rootOfRoots,
ClaimsRoot: claimsTreeRoot,
RevocationsRoot: revTreeRoot,
}, nil
}
type TreeStateIssuerPreparedState struct {
State *merkletree.Hash
RootOfRoots *merkletree.Hash
ClaimsTreeRoot *merkletree.Hash
RevTreeRoot *merkletree.Hash
}
type ProofStatus struct {
Mtp *merkletree.Proof `json:"mtp"`
Issuer *Issuer `json:"issuer"`
}
type ProofState struct {
TxID string `json:"txID,omitempty"`
BlockTimestamp int64 `json:"blockTimestamp,omitempty"`
BlockNumber int64 `json:"blockNumber,omitempty"`
RootOfRoots string `json:"rootOfRoot"`
ClaimsTreeRoot string `json:"claimsTreeRoot"`
RevocationTreeRoot string `json:"revocationTreeRoot"`
Value string `json:"value"`
Status string `json:"status,omitempty"`
}
type IssuerData struct {
Identifier string `json:"identifier"`
State ProofState `json:"state"`
AuthCoreClaim *core.Claim `json:"authCoreClaim,omitempty"`
Mtp *merkletree.Proof `json:"mtp,omitempty"`
CredentialStatus *CredentialStatus `json:"credentialStatus,omitempty"`
UpdateURL string `json:"updateURL"`
}
type Iden3SparseMerkleTreeProof struct {
Type string `json:"type"`
IssuerData *IssuerData `json:"issuerData"`
Mtp *merkletree.Proof `json:"mtp"`
CoreClaim string `json:"coreClaim"`
Identifier string `json:"id"`
}
func (p *Iden3SparseMerkleTreeProof) GetCoreClaim() (*core.Claim, error) {
var claim core.Claim
if err := claim.FromHex(p.CoreClaim); err != nil {
return nil, err
}
return &claim, nil
}
func (p *Iden3SparseMerkleTreeProof) ProofType() verifiable.ProofType {
return verifiable.Iden3SparseMerkleTreeProofType
}
type BJJSignatureProof2021 struct {
ProofType string `json:"type"`
IssuerData *IssuerData `json:"issuerData"`
Signature string `json:"signature"`
CoreClaim string `json:"coreClaim"`
}
type CircuitClaim struct {
IssuerId string
Claim *core.Claim
SignatureProof *BJJSignatureProof
Status *ProofStatus
}
type MTP struct {
Proof *merkletree.Proof `json:"proof"`
TreeState *TreeState `json:"treeState,omitempty"`
}
type BJJSignatureProof struct {
Signature *babyjub.Signature `json:"signature"`
IssuerAuthClaim *core.Claim `json:"issuerAuthClaim,omitempty"`
IssuerAuthIncProof *MTP `json:"issuerAuthIncProof"`
IssuerAuthNonRevProof *MTP `json:"issuerAuthNonRevProof"`
}
type CreateProofRequest struct {
AccountAddress string `json:"accountAddress"`
CircuitId CircuitId `json:"circuitId"`
Query *ProofQuery `json:"query"`
}
type ProofQuery struct {
AllowedIssuers []string `json:"allowedIssuers,omitempty"`
CredentialSubject *ProofQueryCredentialSubject `json:"credentialSubject,omitempty"`
CredentialSubjectId string `json:"credentialSubjectId,omitempty"`
Type []string `json:"type,omitempty"`
}
type ProofQueryCredentialSubject struct {
CredentialHash *CredentialHash `json:"credentialHash"`
}
type CredentialHash struct {
Eq string `json:"$eq"`
}
type Query struct {
SlotIndex int `json:"slotIndex"`
Values []*big.Int `json:"values"`
Operator Operators `json:"operator"`
ValueProof *ValueProof `json:"valueProof,omitempty"`
}
type ValueProof struct {
Path *big.Int `json:"path"`
Value *big.Int `json:"value"`
Mtp *merkletree.Proof `json:"mtp"`
}
type SerializationSchema struct {
IndexDataSlotA string `json:"indexDataSlotA"`
IndexDataSlotB string `json:"indexDataSlotB"`
ValueDataSlotA string `json:"valueDataSlotA"`
ValueDataSlotB string `json:"valueDataSlotB"`
}
type SchemaMetadata struct {
Uris map[string]string `json:"uris"`
Serialization *SerializationSchema `json:"serialization,omitempty"`
}
type JSONSchema struct {
Metadata SchemaMetadata `json:"$metadata"`
Schema string `json:"$schema"`
Type string `json:"type"`
}
type OperationProof struct {
Path []string `json:"path"`
Signature string `json:"signature"`
}
type StateInfo struct {
Index string `json:"index"`
Hash string `json:"hash"`
CreatedAtTimestamp string `json:"createdAtTimestamp"`
CreatedAtBlock string `json:"createdAtBlock"`
LastUpdateOperationIdx string `json:"lastUpdateOperationIndex"`
}
type GetStateInfoResponse struct {
State StateInfo `json:"state"`
}
type CoreMTP struct {
Proof []string `json:"proof"`
}
type OperationData struct {
Operation Operation `json:"operation"`
}
type Operation struct {
Index string `json:"index"`
OperationType string `json:"operationType"`
Details OperationDetails `json:"details"`
Status string `json:"status"`
Creator string `json:"creator"`
Timestamp string `json:"timestamp"`
}
type OperationDetails struct {
Type string `json:"@type"`
Contract string `json:"contract"`
Chain string `json:"chain"`
GISTHash string `json:"GISTHash"`
StateRootHash string `json:"stateRootHash"`
Timestamp string `json:"timestamp"`
}
type RegistrationData struct {
Secret string
Nullifier string
Calldata string
DocumentNullifier string
}