-
Notifications
You must be signed in to change notification settings - Fork 38
/
table_vrf_query.go
155 lines (140 loc) · 5.32 KB
/
table_vrf_query.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
package main
import (
"errors"
tablevrf "github.com/sec-bit/zkPoD-lib/pod_go/table/vrfq"
)
type PoDAliceTQ struct {
AliceSession *tablevrf.AliceSession `json:"AliceSession"`
}
// AliceNewSessForTQ prepares Alice's session while mode is table_vrf_query.
//
// It is provides an interface for NewAliceSession.
//
// Return:
// If no error occurs, return a PoDAliceTQ struct and a nil error.
// Otherwise, return a nil session and the non-nil error.
func AliceNewSessForTQ(publishPath string, AliceID [40]uint8, BobID [40]uint8, Log ILogger) (PoDAliceTQ, error) {
var tq PoDAliceTQ
rs, err := pathExists(publishPath)
if err != nil {
Log.Warnf("Failed to check. err=%v", err)
return tq, err
}
if !rs {
Log.Warnf("the path=%v does not exist.", publishPath)
return tq, errors.New("the path does not exist")
}
Log.Debugf("publishPath=%v", publishPath)
tq.AliceSession, err = tablevrf.NewAliceSession(publishPath, AliceID, BobID)
if err != nil {
Log.Warnf("failed to create session for Alice. err=%v", err)
return tq, errors.New("failed to create session for Alice")
}
Log.Debugf("success to create session")
return tq, nil
}
// AliceVerifyReq verifies request file and generates response file for Alice while mode is table_vrf_query.
//
// It is provides an interface for OnRequest.
//
// Return:
// If verify transaction requset and generate transaction response successfully, return true.
// Otherwise, return false.
func (tq PoDAliceTQ) AliceVerifyReq(requestFile string, responseFile string, Log ILogger) bool {
err := tq.AliceSession.OnRequest(requestFile, responseFile)
if err != nil {
Log.Warnf("Verify request and generate response....Failed. err=%v", err)
return false
}
Log.Debugf("success to verify request and generate response")
return true
}
// AliceVerifyReceipt verifies receipt file and generate secret file for Alice while mode is table_vrf_query.
//
// It is provides an interface for OnReceipt.
//
// Return:
// If verify receipt file and generate secret file successfully, return true.
// Otherwise, return false.
func (tq PoDAliceTQ) AliceVerifyReceipt(receiptFile string, secretFile string, Log ILogger) bool {
err := tq.AliceSession.OnReceipt(receiptFile, secretFile)
if err != nil {
Log.Warnf("Verify receipt file and generate secret file.....Failed. err=%v", err)
return false
}
Log.Debugf("success to verify receipt and generate secret. receiptFile=%v, secretFile=%v", receiptFile, secretFile)
return true
}
type PoDBobTQ struct {
BobSession *tablevrf.BobSession `json:"BobSession"`
KeyName string `json:"keyName"`
KeyValue []string `json:"keyValue"`
}
// BobNewSessForTQ prepares Bob's session while mode is table_vrf_query.
//
// It is provides an interface for NewBobSession.
//
// Return:
// If no error occurs, return a Bob's session and a nil error.
// Otherwise, return a nil session and the non-nil error.
func BobNewSessForTQ(keyName string, keyValue []string, tableBulletin string, tablePublicPath string, AliceID [40]uint8, BobID [40]uint8, Log ILogger) (PoDBobTQ, error) {
var tq PoDBobTQ
Log.Debugf("tableBulletin=%v, tablePublicPath=%v, AliceID=%v, BobID=%v, keyName=%v,keyValue=%v",
tableBulletin, tablePublicPath, AliceID, BobID, keyName, keyValue)
session, err := tablevrf.NewBobSession(tableBulletin, tablePublicPath, AliceID, BobID, keyName, keyValue)
if err != nil {
Log.Warnf("Failed to create session for Bob. err=%v", err)
return tq, errors.New("Failed to create session for Bob")
}
Log.Debugf("success to create session.")
tq = PoDBobTQ{session, keyName, keyValue}
return tq, nil
}
// BobNewReq creates request file for Bob while mode is table_vrf_query.
//
// It is provides an interface for GetRequest.
//
// Return:
// If no error occurs, generate a request file and return a nil error.
// Otherwise, return the non-nil error.
func (tq PoDBobTQ) BobNewReq(requestFile string, Log ILogger) error {
err := tq.BobSession.GetRequest(requestFile)
if err != nil {
Log.Warnf("Failed to create request file. err=%v", err)
return errors.New("Failed to create request file")
}
Log.Debugf("success to create request file. requestFile=%v", requestFile)
return nil
}
// BobVerifyResp verifies response data for Bob while mode is table_vrf_query.
//
// It is provides an interface for OnResponse.
//
// Return:
// If verify response and generate receipt successfully, return true.
// Otherwise, return false.
func (tq PoDBobTQ) BobVerifyResp(responseFile string, receiptFile string, Log ILogger) bool {
err := tq.BobSession.OnResponse(responseFile, receiptFile)
if err != nil {
Log.Warnf("Verify response failure. err=%v", err)
return false
}
Log.Debugf("success to verify response and geerate receipt. responseFile=%v, receiptFile=%v", responseFile, receiptFile)
return true
}
// BobVerifySecret verifies secret for Bob while mode is table_vrf_query.
//
// It is provides an interface for OnSecret.
//
// Return:
// If verify secret successfully, return true.
// Otherwise, return false.
func (tq PoDBobTQ) BobVerifySecret(secretFile string, tablePosition string, Log ILogger) bool {
err := tq.BobSession.OnSecret(secretFile, tablePosition)
if err != nil {
Log.Warnf("Verify secret failure. err=%v", err)
return false
}
Log.Debugf("success to verify secret and generate table position. secretFile=%v, tablePosition=%v", secretFile, tablePosition)
return true
}