-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcredentialAtomicQueryV3OnChain.go
681 lines (557 loc) · 21.4 KB
/
credentialAtomicQueryV3OnChain.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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
package circuits
import (
"encoding/json"
"fmt"
"math/big"
"strconv"
core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-iden3-crypto/babyjub"
"github.com/iden3/go-merkletree-sql/v2"
"github.com/pkg/errors"
)
// AtomicQueryV3OnChainInputs ZK private inputs for credentialAtomicQueryV3OnChain.circom
type AtomicQueryV3OnChainInputs struct {
BaseConfig
RequestID *big.Int
ID *core.ID
ProfileNonce *big.Int
ClaimSubjectProfileNonce *big.Int
Claim ClaimWithSigAndMTPProof
SkipClaimRevocationCheck bool
AuthClaim *core.Claim `json:"authClaim"`
AuthClaimIncMtp *merkletree.Proof `json:"authClaimIncMtp"`
AuthClaimNonRevMtp *merkletree.Proof `json:"authClaimNonRevMtp"`
TreeState TreeState `json:"treeState"`
GISTProof GISTProof `json:"gistProof"`
Signature *babyjub.Signature `json:"signature"`
Challenge *big.Int `json:"challenge"`
// query
Query Query
CurrentTimeStamp int64
ProofType ProofType
LinkNonce *big.Int
VerifierID *core.ID
NullifierSessionID *big.Int
IsBJJAuthEnabled int
}
// atomicQueryV3OnChainCircuitInputs type represents credentialAtomicQueryV3OnChain.circom private inputs required by prover
type atomicQueryV3OnChainCircuitInputs 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"`
IssuerClaimNonRevClaimsTreeRoot string `json:"issuerClaimNonRevClaimsTreeRoot"`
IssuerClaimNonRevRevTreeRoot string `json:"issuerClaimNonRevRevTreeRoot"`
IssuerClaimNonRevRootsTreeRoot string `json:"issuerClaimNonRevRootsTreeRoot"`
IssuerClaimNonRevState string `json:"issuerClaimNonRevState"`
IssuerClaimNonRevMtp []string `json:"issuerClaimNonRevMtp"`
IssuerClaimNonRevMtpAuxHi *merkletree.Hash `json:"issuerClaimNonRevMtpAuxHi"`
IssuerClaimNonRevMtpAuxHv *merkletree.Hash `json:"issuerClaimNonRevMtpAuxHv"`
IssuerClaimNonRevMtpNoAux string `json:"issuerClaimNonRevMtpNoAux"`
ClaimSchema string `json:"claimSchema"`
IssuerClaimSignatureR8X string `json:"issuerClaimSignatureR8x"`
IssuerClaimSignatureR8Y string `json:"issuerClaimSignatureR8y"`
IssuerClaimSignatureS string `json:"issuerClaimSignatureS"`
IssuerAuthClaim *core.Claim `json:"issuerAuthClaim"`
IssuerAuthClaimMtp []string `json:"issuerAuthClaimMtp"`
IssuerAuthClaimNonRevMtp []string `json:"issuerAuthClaimNonRevMtp"`
IssuerAuthClaimNonRevMtpAuxHi *merkletree.Hash `json:"issuerAuthClaimNonRevMtpAuxHi"`
IssuerAuthClaimNonRevMtpAuxHv *merkletree.Hash `json:"issuerAuthClaimNonRevMtpAuxHv"`
IssuerAuthClaimNonRevMtpNoAux string `json:"issuerAuthClaimNonRevMtpNoAux"`
IssuerAuthClaimsTreeRoot string `json:"issuerAuthClaimsTreeRoot"`
IssuerAuthRevTreeRoot string `json:"issuerAuthRevTreeRoot"`
IssuerAuthRootsTreeRoot string `json:"issuerAuthRootsTreeRoot"`
IssuerAuthState *merkletree.Hash `json:"issuerAuthState"`
IsRevocationChecked int `json:"isRevocationChecked"`
// Query
// JSON path
ClaimPathMtp []string `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"`
ValueArraySize int `json:"valueArraySize"`
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"`
ProofType string `json:"proofType"`
// 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-cain 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"`
// Private random nonce, used to generate LinkID
LinkNonce string `json:"linkNonce"`
VerifierID string `json:"verifierID"`
NullifierSessionID string `json:"nullifierSessionID"`
IsBJJAuthEnabled string `json:"isBJJAuthEnabled"`
}
func (a AtomicQueryV3OnChainInputs) Validate() error {
if a.RequestID == nil {
return errors.New(ErrorEmptyRequestID)
}
if a.Claim.NonRevProof.Proof == nil {
return errors.New(ErrorEmptyClaimNonRevProof)
}
if err := a.Query.ValidateValueArraySize(a.GetValueArrSize()); err != nil {
return err
}
if a.Challenge == nil {
return errors.New(ErrorEmptyChallenge)
}
if a.IsBJJAuthEnabled == 1 {
if a.AuthClaimIncMtp == nil {
return errors.New(ErrorEmptyAuthClaimProof)
}
if a.AuthClaimNonRevMtp == nil {
return errors.New(ErrorEmptyAuthClaimNonRevProof)
}
if a.GISTProof.Proof == nil {
return errors.New(ErrorEmptyGISTProof)
}
if a.Signature == nil {
return errors.New(ErrorEmptyChallengeSignature)
}
}
switch a.ProofType {
case BJJSignatureProofType:
if a.Claim.SignatureProof == nil {
return errors.New(ErrorEmptySignatureProof)
}
if a.Claim.SignatureProof.IssuerAuthIncProof.Proof == nil {
return errors.New(ErrorEmptyIssuerAuthClaimProof)
}
if a.Claim.SignatureProof.IssuerAuthNonRevProof.Proof == nil {
return errors.New(ErrorEmptyIssuerAuthClaimNonRevProof)
}
if a.Claim.SignatureProof.Signature == nil {
return errors.New(ErrorEmptyClaimSignature)
}
case Iden3SparseMerkleTreeProofType:
if a.Claim.IncProof == nil {
return errors.New(ErrorEmptyMTPProof)
}
if a.Claim.IncProof.Proof == nil {
return errors.New(ErrorEmptyClaimProof)
}
default:
return errors.New(ErrorInvalidProofType)
}
return nil
}
// InputsMarshal returns Circom private inputs for credentialAtomicQueryV3OnChain.circom
func (a AtomicQueryV3OnChainInputs) InputsMarshal() ([]byte, error) {
if err := a.Validate(); err != nil {
return nil, err
}
if a.Query.ValueProof != nil {
if err := a.Query.validate(); err != nil {
return nil, err
}
if err := a.Query.ValueProof.validate(); err != nil {
return nil, err
}
}
valueProof := a.Query.ValueProof
if valueProof == nil {
valueProof = &ValueProof{}
valueProof.Path = big.NewInt(0)
valueProof.Value = big.NewInt(0)
valueProof.MTP = &merkletree.Proof{}
}
s := atomicQueryV3OnChainCircuitInputs{
RequestID: a.RequestID.String(),
UserGenesisID: a.ID.BigInt().String(),
ProfileNonce: a.ProfileNonce.String(),
ClaimSubjectProfileNonce: a.ClaimSubjectProfileNonce.String(),
IssuerID: a.Claim.IssuerID.BigInt().String(),
IssuerClaim: a.Claim.Claim,
IssuerClaimNonRevClaimsTreeRoot: a.Claim.NonRevProof.TreeState.ClaimsRoot.BigInt().String(),
IssuerClaimNonRevRevTreeRoot: a.Claim.NonRevProof.TreeState.RevocationRoot.BigInt().String(),
IssuerClaimNonRevRootsTreeRoot: a.Claim.NonRevProof.TreeState.RootOfRoots.BigInt().String(),
IssuerClaimNonRevState: a.Claim.NonRevProof.TreeState.State.BigInt().String(),
IssuerClaimNonRevMtp: PrepareSiblingsStr(a.Claim.NonRevProof.Proof.AllSiblings(),
a.GetMTLevel()),
ClaimSchema: a.Claim.Claim.GetSchemaHash().BigInt().String(),
ClaimPathMtp: PrepareSiblingsStr(valueProof.MTP.AllSiblings(),
a.GetMTLevelsClaim()),
ClaimPathValue: valueProof.Value.Text(10),
Operator: a.Query.Operator,
Timestamp: a.CurrentTimeStamp,
// value in this path in merklized json-ld document
SlotIndex: a.Query.SlotIndex,
IsRevocationChecked: 1,
}
s.Challenge = a.Challenge.String()
if a.IsBJJAuthEnabled == 1 {
s.AuthClaim = a.AuthClaim
s.ClaimsTreeRoot = a.TreeState.ClaimsRoot
s.RevTreeRoot = a.TreeState.RevocationRoot
s.RootsTreeRoot = a.TreeState.RootOfRoots
s.State = a.TreeState.State
s.AuthClaimMtp = merkletree.CircomSiblingsFromSiblings(a.AuthClaimIncMtp.AllSiblings(),
a.GetMTLevel()-1)
s.AuthClaimNonRevMtp = merkletree.CircomSiblingsFromSiblings(a.AuthClaimNonRevMtp.AllSiblings(),
a.GetMTLevel()-1)
s.ChallengeSignatureR8X = a.Signature.R8.X.String()
s.ChallengeSignatureR8Y = a.Signature.R8.Y.String()
s.ChallengeSignatureS = a.Signature.S.String()
s.GISTRoot = a.GISTProof.Root
s.GISTMtp = merkletree.CircomSiblingsFromSiblings(a.GISTProof.Proof.AllSiblings(),
a.GetMTLevelOnChain()-1)
nodeAuxAuth := GetNodeAuxValue(a.AuthClaimNonRevMtp)
s.AuthClaimNonRevMtpAuxHi = nodeAuxAuth.key
s.AuthClaimNonRevMtpAuxHv = nodeAuxAuth.value
s.AuthClaimNonRevMtpNoAux = nodeAuxAuth.noAux
globalNodeAux := GetNodeAuxValue(a.GISTProof.Proof)
s.GISTMtpAuxHi = globalNodeAux.key
s.GISTMtpAuxHv = globalNodeAux.value
s.GISTMtpNoAux = globalNodeAux.noAux
} else {
a.fillAuthWithZero(&s)
}
if a.SkipClaimRevocationCheck {
s.IsRevocationChecked = 0
}
switch a.ProofType {
case BJJSignatureProofType:
s.ProofType = "1"
if a.Claim.SignatureProof == nil {
return nil, errors.New(ErrorEmptySignatureProof)
}
s.IssuerClaimSignatureR8X = a.Claim.SignatureProof.Signature.R8.X.String()
s.IssuerClaimSignatureR8Y = a.Claim.SignatureProof.Signature.R8.Y.String()
s.IssuerClaimSignatureS = a.Claim.SignatureProof.Signature.S.String()
s.IssuerAuthClaim = a.Claim.SignatureProof.IssuerAuthClaim
s.IssuerAuthClaimMtp = PrepareSiblingsStr(a.Claim.SignatureProof.IssuerAuthIncProof.Proof.AllSiblings(),
a.GetMTLevel())
s.IssuerAuthClaimsTreeRoot = a.Claim.SignatureProof.IssuerAuthIncProof.TreeState.ClaimsRoot.
BigInt().String()
s.IssuerAuthRevTreeRoot = a.Claim.SignatureProof.IssuerAuthIncProof.TreeState.RevocationRoot.BigInt().String()
s.IssuerAuthRootsTreeRoot = a.Claim.SignatureProof.IssuerAuthIncProof.TreeState.RootOfRoots.BigInt().String()
s.IssuerAuthClaimNonRevMtp = PrepareSiblingsStr(a.Claim.SignatureProof.IssuerAuthNonRevProof.Proof.
AllSiblings(), a.GetMTLevel())
nodeAuxIssuerAuthNonRev := GetNodeAuxValue(a.Claim.SignatureProof.IssuerAuthNonRevProof.Proof)
s.IssuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev.key
s.IssuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev.value
s.IssuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev.noAux
s.IssuerAuthState = a.Claim.SignatureProof.IssuerAuthIncProof.TreeState.State
a.fillMTPProofsWithZero(&s)
case Iden3SparseMerkleTreeProofType:
s.ProofType = "2"
if a.Claim.IncProof == nil {
return nil, errors.New(ErrorEmptyMTPProof)
}
s.IssuerClaimMtp = CircomSiblings(a.Claim.IncProof.Proof, a.GetMTLevel())
s.IssuerClaimClaimsTreeRoot = a.Claim.IncProof.TreeState.ClaimsRoot
s.IssuerClaimRevTreeRoot = a.Claim.IncProof.TreeState.RevocationRoot
s.IssuerClaimRootsTreeRoot = a.Claim.IncProof.TreeState.RootOfRoots
s.IssuerClaimIdenState = a.Claim.IncProof.TreeState.State
a.fillSigProofWithZero(&s)
}
nodeAuxNonRev := GetNodeAuxValue(a.Claim.NonRevProof.Proof)
s.IssuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key
s.IssuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value
s.IssuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux
nodAuxJSONLD := GetNodeAuxValue(valueProof.MTP)
s.ClaimPathMtpNoAux = nodAuxJSONLD.noAux
s.ClaimPathMtpAuxHi = nodAuxJSONLD.key
s.ClaimPathMtpAuxHv = nodAuxJSONLD.value
s.ClaimPathKey = valueProof.Path.String()
values, err := PrepareCircuitArrayValues(a.Query.Values, a.GetValueArrSize())
if err != nil {
return nil, err
}
s.Value = bigIntArrayToStringArray(values)
s.ValueArraySize = len(a.Query.Values)
s.LinkNonce = "0"
if a.LinkNonce != nil {
s.LinkNonce = a.LinkNonce.String()
}
s.VerifierID = "0"
if a.VerifierID != nil {
s.VerifierID = a.VerifierID.BigInt().String()
}
s.NullifierSessionID = "0"
if a.NullifierSessionID != nil {
s.NullifierSessionID = a.NullifierSessionID.String()
}
s.IsBJJAuthEnabled = strconv.Itoa(a.IsBJJAuthEnabled)
return json.Marshal(s)
}
func (a AtomicQueryV3OnChainInputs) fillMTPProofsWithZero(s *atomicQueryV3OnChainCircuitInputs) {
s.IssuerClaimMtp = CircomSiblings(&merkletree.Proof{}, a.GetMTLevel())
s.IssuerClaimClaimsTreeRoot = &merkletree.HashZero
s.IssuerClaimRevTreeRoot = &merkletree.HashZero
s.IssuerClaimRootsTreeRoot = &merkletree.HashZero
s.IssuerClaimIdenState = &merkletree.HashZero
}
func (a AtomicQueryV3OnChainInputs) fillAuthWithZero(s *atomicQueryV3OnChainCircuitInputs) {
s.AuthClaim = &core.Claim{}
s.ClaimsTreeRoot = &merkletree.HashZero
s.RevTreeRoot = &merkletree.HashZero
s.RootsTreeRoot = &merkletree.HashZero
s.State = &merkletree.HashZero
s.AuthClaimMtp = CircomSiblings(&merkletree.Proof{},
a.GetMTLevel())
s.AuthClaimNonRevMtp = CircomSiblings(&merkletree.Proof{},
a.GetMTLevel())
s.ChallengeSignatureR8X = "0"
s.ChallengeSignatureR8Y = "0"
s.ChallengeSignatureS = "0"
s.GISTRoot = &merkletree.HashZero
s.GISTMtp = CircomSiblings(&merkletree.Proof{},
a.GetMTLevelOnChain())
s.AuthClaimNonRevMtpAuxHi = &merkletree.HashZero
s.AuthClaimNonRevMtpAuxHv = &merkletree.HashZero
s.AuthClaimNonRevMtpNoAux = "0"
s.GISTMtpAuxHi = &merkletree.HashZero
s.GISTMtpAuxHv = &merkletree.HashZero
s.GISTMtpNoAux = "0"
}
func (a AtomicQueryV3OnChainInputs) fillSigProofWithZero(s *atomicQueryV3OnChainCircuitInputs) {
s.IssuerClaimSignatureR8X = "0"
s.IssuerClaimSignatureR8Y = "0"
s.IssuerClaimSignatureS = "0"
s.IssuerAuthClaim = &core.Claim{}
s.IssuerAuthClaimMtp = PrepareSiblingsStr([]*merkletree.Hash{}, a.GetMTLevel())
s.IssuerAuthClaimsTreeRoot = "0"
s.IssuerAuthRevTreeRoot = "0"
s.IssuerAuthRootsTreeRoot = "0"
s.IssuerAuthClaimNonRevMtp = PrepareSiblingsStr([]*merkletree.Hash{}, a.GetMTLevel())
s.IssuerAuthClaimNonRevMtpAuxHi = &merkletree.HashZero
s.IssuerAuthClaimNonRevMtpAuxHv = &merkletree.HashZero
s.IssuerAuthClaimNonRevMtpNoAux = "0"
s.IssuerAuthState = &merkletree.HashZero
}
func (a AtomicQueryV3OnChainInputs) GetPublicStatesInfo() (StatesInfo, error) {
if err := a.Validate(); err != nil {
return StatesInfo{}, err
}
issuerID := a.Claim.IssuerID
var issuerState merkletree.Hash
switch a.ProofType {
case BJJSignatureProofType:
if a.Claim.SignatureProof == nil {
return StatesInfo{}, errors.New(ErrorEmptySignatureProof)
}
if a.Claim.SignatureProof.IssuerAuthIncProof.TreeState.State == nil {
return StatesInfo{}, errors.New(ErrorEmptyStateHash)
}
issuerState = *a.Claim.SignatureProof.IssuerAuthIncProof.TreeState.State
case Iden3SparseMerkleTreeProofType:
if a.Claim.IncProof == nil {
return StatesInfo{}, errors.New(ErrorEmptyMTPProof)
}
if a.Claim.IncProof.TreeState.State == nil {
return StatesInfo{}, errors.New(ErrorEmptyStateHash)
}
issuerState = *a.Claim.IncProof.TreeState.State
default:
return StatesInfo{}, errors.New(ErrorInvalidProofType)
}
if a.Claim.NonRevProof.TreeState.State == nil {
return StatesInfo{}, errors.New(ErrorEmptyStateHash)
}
userID, err := core.ProfileID(*a.ID, a.ProfileNonce)
if err != nil {
return StatesInfo{}, err
}
if a.GISTProof.Root == nil {
return StatesInfo{}, errors.New(ErrorEmptyGISTProof)
}
statesInfo := StatesInfo{
States: []State{
{
ID: *issuerID,
State: issuerState,
},
},
Gists: []Gist{
{
ID: userID,
Root: *a.GISTProof.Root,
},
},
}
nonRevProofState := *a.Claim.NonRevProof.TreeState.State
if issuerState != nonRevProofState {
statesInfo.States = append(statesInfo.States, State{
ID: *issuerID,
State: nonRevProofState,
})
}
return statesInfo, nil
}
// AtomicQueryV3OnChainPubSignals public inputs
type AtomicQueryV3OnChainPubSignals struct {
BaseConfig
RequestID *big.Int `json:"requestID"`
UserID *core.ID `json:"userID"`
IssuerID *core.ID `json:"issuerID"`
IssuerState *merkletree.Hash `json:"issuerState"`
IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
Timestamp int64 `json:"timestamp"`
QueryHash *big.Int `json:"circuitQueryHash"`
Challenge *big.Int `json:"challenge"`
GlobalRoot *merkletree.Hash `json:"gistRoot"`
ProofType int `json:"proofType"`
LinkID *big.Int `json:"linkID"`
Nullifier *big.Int `json:"nullifier"`
OperatorOutput *big.Int `json:"operatorOutput"`
IsBJJAuthEnabled int `json:"isBJJAuthEnabled"`
}
// PubSignalsUnmarshal unmarshal credentialAtomicQueryV3OnChain.circom public signals
func (ao *AtomicQueryV3OnChainPubSignals) PubSignalsUnmarshal(data []byte) error {
// expected order:
// userID
// circuitQueryHash
// issuerState
// linkID
// nullifier
// operatorOutput
// proofType
// requestID
// challenge
// gistRoot
// issuerID
// issuerClaimNonRevState
// timestamp
// isBJJAuthEnabled
var sVals []string
err := json.Unmarshal(data, &sVals)
if err != nil {
return err
}
fieldIdx := 0
// - userID
if ao.UserID, err = idFromIntStr(sVals[fieldIdx]); err != nil {
return err
}
fieldIdx++
var ok bool
// - valueHash
if ao.QueryHash, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid circuits query hash value: '%s'", sVals[fieldIdx])
}
fieldIdx++
// - issuerState
if ao.IssuerState, err = merkletree.NewHashFromString(sVals[fieldIdx]); err != nil {
return err
}
fieldIdx++
// - linkID
if ao.LinkID, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid link ID value: '%s'", sVals[fieldIdx])
}
fieldIdx++
// - nullifier
if ao.Nullifier, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid link ID value: '%s'", sVals[fieldIdx])
}
fieldIdx++
// - operatorOutput
if ao.OperatorOutput, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid operator output value: '%s'", sVals[fieldIdx])
}
fieldIdx++
// - proofType
if ao.ProofType, err = strconv.Atoi(sVals[fieldIdx]); err != nil {
return fmt.Errorf("invalid proofType value: '%s'", sVals[fieldIdx])
}
fieldIdx++
// - requestID
if ao.RequestID, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid requestID value: '%s'", sVals[fieldIdx])
}
fieldIdx++
// - challenge
if ao.Challenge, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid challenge value: '%s'", sVals[fieldIdx])
}
fieldIdx++
// - gistRoot
if ao.GlobalRoot, err = merkletree.NewHashFromString(sVals[fieldIdx]); err != nil {
return err
}
fieldIdx++
// - issuerID
if ao.IssuerID, err = idFromIntStr(sVals[fieldIdx]); err != nil {
return err
}
fieldIdx++
// - issuerClaimNonRevState
if ao.IssuerClaimNonRevState, err = merkletree.NewHashFromString(sVals[fieldIdx]); err != nil {
return err
}
fieldIdx++
// - timestamp
ao.Timestamp, err = strconv.ParseInt(sVals[fieldIdx], 10, 64)
if err != nil {
return err
}
fieldIdx++
// - IsBJJAuthEnabled
if ao.IsBJJAuthEnabled, err = strconv.Atoi(sVals[fieldIdx]); err != nil {
return err
}
return nil
}
// GetObjMap returns struct field as a map
func (ao AtomicQueryV3OnChainPubSignals) GetObjMap() map[string]interface{} {
return toMap(ao)
}
func (ao AtomicQueryV3OnChainPubSignals) GetStatesInfo() (StatesInfo, error) {
if ao.UserID == nil || ao.IssuerID == nil {
return StatesInfo{}, errors.New(ErrorEmptyID)
}
if ao.IssuerState == nil || ao.IssuerClaimNonRevState == nil ||
ao.GlobalRoot == nil {
return StatesInfo{}, errors.New(ErrorEmptyStateHash)
}
states := []State{
{
ID: *ao.IssuerID,
State: *ao.IssuerState,
},
}
if *ao.IssuerClaimNonRevState != *ao.IssuerState {
states = append(states, State{
ID: *ao.IssuerID,
State: *ao.IssuerClaimNonRevState,
})
}
return StatesInfo{
States: states,
Gists: []Gist{{ID: *ao.UserID, Root: *ao.GlobalRoot}},
}, nil
}