generated from puria/README
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.js
174 lines (158 loc) · 5.61 KB
/
benchmark.js
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
const { execute } = require('./build/main/index');
const bench = require('nanobench');
const signPetition = async () => {
const account = `{"username": "Alice"}`;
const participants = `{ "participants": [ "[email protected]", "[email protected]", "[email protected]" ] }`;
const participant_email = `{"email": "[email protected]", "petition_uid": "More privacy for all!"}`;
const steps = {
verbose: false,
conf: 'memmanager=lw',
steps: [
{
id: 'issuer_keypair',
zencode: `Scenario credential: publish verifier
Given that I am known as 'Decidiamo'
When I create the issuer keypair
Then print my 'issuer keypair'`,
},
{
id: 'keypair',
zencode: `Scenario ecdh: create the keypair at user creation
Given that my name is in a 'string' named 'username'
When I create the keypair
Then print my 'keypair'`,
data: account,
},
{
id: 'pubkey',
zencode: `Scenario 'ecdh': Publish the public key
Given that my name is in a 'string' named 'username'
and I have my 'keypair'
Then print my 'public key' from 'keypair'`,
data: account,
keysFromStep: 'keypair',
},
{
id: 'petition_request',
zencode: `Scenario credential: create the petition credentials
Scenario petition: create the petition
Scenario ecdh: sign the petition
# state my identity
Given that I am known as 'Alice'
and I have my 'keypair'
and I have a 'string array' named 'participants'
# create the petition and its keypair
When I create the credential keypair
and I create the petition 'More privacy for all!'
# sign the hash
# When I create the hash of 'petition'
When I create the signature of 'petition'
and I insert 'signature' in 'petition'
When I create the signature of 'participants'
and I rename the 'signature' to 'participants.signature'
Then print my 'credential keypair'
and print the 'petition'
and print the 'participants'
and print the 'participants.signature'
and print the 'public key' inside 'keypair'
`,
keysFromStep: 'keypair',
data: participants,
},
{
id: 'new_petition',
dataFromStep: 'petition_request',
dataTransform: (data) => {
const o = JSON.parse(data);
delete o.Alice;
return JSON.stringify(o);
},
keysFromStep: 'pubkey',
zencode: `Scenario ecdh
Scenario petition
Given that I have a 'public key' from 'Alice'
and I have a 'petition'
and I have a 'string array' named 'participants'
and I have a 'signature' named 'participants.signature'
When I verify the 'petition' is signed by 'Alice'
and I verify the new petition to be empty
When I verify the 'participants' has a signature in 'participants.signature' by 'Alice'
and I verify 'participants' contains a list of emails
Then print 'petition'
and print 'participants'
and print the 'uid' as 'string' inside 'petition'`,
},
{
id: 'petition',
dataFromStep: 'new_petition',
keysFromStep: 'issuer_keypair',
zencode: `Scenario credential
Scenario petition
Given I am 'Decidiamo'
and I have my 'issuer keypair'
and I have a 'petition'
When I create the copy of 'verifier' from dictionary 'issuer keypair'
and I rename the 'copy' to 'verifier'
and I insert 'verifier' in 'petition'
Then print the 'petition'`,
},
{
id: 'signature_credential',
keysFromStep: 'issuer_keypair',
data: participant_email,
zencode: `Scenario credential
Given that I am known as 'Decidiamo'
and I have my 'issuer keypair'
and I have a 'string' named 'email'
and I have a 'string' named 'petition_uid'
When I append 'email' to 'petition_uid'
and I create the hash of 'petition_uid'
and I create the credential keypair with secret key 'hash'
and I create the credential request
and I create the credential signature
and I create the credentials
Then print the 'credentials'
and print the 'credential keypair'
and print the 'verifier'`,
},
{
id: 'sign_proof',
dataFromStep: 'signature_credential',
zencode: `Scenario credential
Scenario petition: sign petition
Given I am 'Bob'
and I have a 'credential keypair'
and I have a 'credentials'
and I have a 'verifier'
When I aggregate the verifiers
and I create the petition signature 'More privacy for all!'
Then print the 'petition signature'`,
},
{
id: 'sign_petition',
dataFromStep: 'petition',
keysFromStep: 'sign_proof',
zencode: `Scenario credential
Scenario petition: aggregate signature
Given that I am 'Decidiamo'
and I have a 'petition signature'
and I have a 'petition'
When the petition signature is not a duplicate
and the petition signature is just one more
and I add the signature to the petition
Then print the 'petition'`,
},
],
};
await execute(steps);
};
const tries = 150;
bench(`petition flow ${tries} times`, function (b) {
b.start();
for (var i = 0; i < tries; i++) {
(async () => {
await signPetition();
})();
}
b.end();
});