-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctional_test.py
More file actions
114 lines (96 loc) · 3.2 KB
/
functional_test.py
File metadata and controls
114 lines (96 loc) · 3.2 KB
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
import os
import shutil
import subprocess
import musig2
children = ['one', 'two', 'three']
sig = ''
X = b''
def create_dirs():
if os.path.exists("musig2-test"):
shutil.rmtree("musig2-test")
os.mkdir("musig2-test")
for child in children:
os.mkdir(f"musig2-test/{child}")
musig2.write_bytes("hello world\n".encode(), f"musig2-test/{child}/message")
def gen_pub_keys():
keys = b''
for child in children:
one = subprocess.Popen(["python3", "../../musig2.py", "keygen"],
cwd=f"musig2-test/{child}",
stdout=subprocess.PIPE
)
stdout, _ = one.communicate()
pubkey = stdout.strip().split(b'\n')[-1]
keys += pubkey + b'\n'
for child in children:
musig2.write_bytes(keys, f"musig2-test/{child}/public_keys")
def gen_nonces():
nonces = b''
for child in children:
one = subprocess.Popen(["python3", "../../musig2.py", "noncegen"],
cwd=f"musig2-test/{child}",
stdout=subprocess.PIPE
)
stdout, _ = one.communicate()
stdout = stdout.strip().split(b'\n')
nonces += stdout[-1] + b'\n'
for child in children:
musig2.write_bytes(nonces, f"musig2-test/{child}/public_nonces")
def do_sign():
s_values = b''
for child in children:
one = subprocess.Popen(["python3", "../../musig2.py", "sign"],
cwd=f"musig2-test/{child}",
stdout=subprocess.PIPE
)
stdout, _ = one.communicate()
stdout = stdout.strip().split(b'\n')
s_value = stdout[-1]
global X
X = stdout[-5].decode()
s_values += s_value + b'\n'
for child in children:
musig2.write_bytes(s_values, f"musig2-test/{child}/s_values")
def aggregate_signatures():
one = subprocess.Popen(["python3", "../../musig2.py", "aggregatesignature"],
cwd=f"musig2-test/one",
stdout=subprocess.PIPE
)
stdout, _ = one.communicate()
global sig
sig = stdout.strip().split(b'\n')[-1].split(b' ')[-1].decode()
def do_verify():
print(f"X: {X}")
#print(f"R: {R}")
print(f"S: {sig}")
one = subprocess.Popen(["python3", "../../musig2.py", "verify", X, sig],
cwd=f"musig2-test/one",
stdout=subprocess.PIPE
)
stdout, _ = one.communicate()
print(stdout.decode())
def remove_single_use_files():
for child in children:
if os.path.exists(f"musig2-test/{child}/s_values"):
os.remove(f"musig2-test/{child}/s_values")
if os.path.exists(f"musig2-test/{child}/public_nonces"):
os.remove(f"musig2-test/{child}/public_nonces")
def cleanup():
if os.path.exists("musig2-test"):
shutil.rmtree("musig2-test")
def main():
create_dirs()
gen_pub_keys()
gen_nonces()
do_sign()
aggregate_signatures()
do_verify()
remove_single_use_files()
# Sign a second message with the same public keys
gen_nonces()
do_sign()
aggregate_signatures()
do_verify()
cleanup()
if __name__ == "__main__":
main()