-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
86 lines (64 loc) · 2.43 KB
/
main.py
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
from schnorr_lib import *
import hashlib
import os
# priv key of Alice as bytes adn int
a = os.urandom(32)
aint = (int(a.hex(), 16) % n)
# priv key of Bob as bytes adn int
b = os.urandom(32)
bint = (int(b.hex(), 16) % n)
# priv key of Olivia as bytes adn int
v = os.urandom(32)
vint = (int(v.hex(), 16) % n)
# priv key of Alice and Bob for multisig address as bytes adn int
amulti = os.urandom(32)
amultiint = (int(amulti.hex(), 16) % n)
bmulti = os.urandom(32)
bmultiint = (int(bmulti.hex(), 16) % n)
# pubkey of Alice Bob and Olivia as point-bytes
pubkeyA = pubkey_gen_from_int(aint)
pubkeyB = pubkey_gen_from_int(bint)
pubkeyV = pubkey_gen_from_int(vint)
pubkeyA_aspoint=point_mul(G,aint)
pubkeyB_aspoint=point_mul(G,bint)
pubkeyV_aspoint=point_mul(G,vint)
pubkeyAmulti_aspoint = pubkey_gen_from_int(amultiint)
pubkeyBmulti_aspoint = pubkey_gen_from_int(bmultiint)
print("\nThese points are published by all parties")
print("Alice's pubkey is:\t",pubkeyA.hex())
print("Bob's pubkey is:\t",pubkeyB.hex())
print("Olivia's pubkey is:\t",pubkeyV.hex())
print("\nThese points are Alice's and Bob's multisig")
print("Alice's pubkey is:\t",pubkeyAmulti_aspoint.hex())
print("Bob's pubkey is:\t",pubkeyBmulti_aspoint.hex())
# nonce creation
k = os.urandom(32)
kint = (int(k.hex(), 16) % n)
R = pubkey_gen_from_int(kint)
R_aspoint = point_mul(G,kint)
print("\nThis point is published by Olivia")
print("Point from nonce:\t",R.hex())
print("\nLet's say the price of the Yen on Friday is around 1000 satoshis. Therefore possible transactions are")
SiG_array = []
Si_array = []
prices = [925,950,1000,1025,1050]
print("\nPrice\ts_iG\tPubAi\tPubBi")
for i in prices:
i_as_bytes = i.to_bytes(32,'big') # this is a spec thing, we try
hiR = hash_sha256(i_as_bytes+bytes_from_point(R_aspoint))
hiR_V = point_mul(pubkeyV_aspoint,int_from_bytes(hiR))
siG = point_add(R_aspoint,opposite(hiR_V))
SiG_array.append(siG)
PubAi = point_add(pubkeyA_aspoint,siG)
PubBi = point_add(pubkeyB_aspoint,siG)
print(i,"\t",siG,"\t",PubAi,"\t",PubBi)
print("\nPrice\ts_i")
for i in prices:
i_as_bytes = i.to_bytes(32,'big') # this is a spec thing, we try
hiR = hash_sha256(i_as_bytes+bytes_from_point(R_aspoint))
si = (kint - int_from_bytes(hiR)*vint) % n
Si_array.append(si)
print(i,"\t",si)
print ("\nCompare s_iG with s_i * G: are they equal?")
for i in range(len(prices)):
print(prices[i],":\t",point_mul(G,Si_array[i])==SiG_array[i])