This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
forked from Chia-Network/bls-signatures
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest2.py
78 lines (64 loc) · 2.19 KB
/
test2.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
# flake8: noqa: E501
from blspy import (
BNWrapper as BN,
G1Element as G1,
G2Element as G2,
GTElement as GT,
BasicScheme,
AugScheme,
PopScheme,
)
def test():
b1 = BN([1, 2])
b2 = BN([3, 1, 4, 1, 5, 9])
i1 = int.from_bytes(bytes([1, 2]), byteorder='big', signed=False)
i2 = int.from_bytes(bytes([3,1,4,1,5,9]), byteorder='big', signed=False)
g1 = G1.generator()
g2 = G2.generator()
u1 = G1() # unity
u2 = G2()
x1 = g1 * b1
x2 = g1 * b2
y1 = g2 * b1
y2 = g2 * b2
# Implicit conversion from python ints to BNWrapper
assert x1 == g1 * i1 == i1 * g1
assert x2 == g1 * i2 == i2 * g1
assert y1 == g2 * i1 == i1 * g2
assert y2 == g2 * i2 == i2 * g2
# G1
assert x1 != x2
assert x1 * b1 == b1 * x1
assert x1 * b1 != x1 * b2
assert x1 + u1 == x1
assert x1 + x2 == x2 + x1
assert x1 + x1.inverse() == u1
# G2
assert y1 != y2
assert y1 * b1 == b1 * y1
assert y1 * b1 != y1 * b2
assert y1 + u2 == y1
assert y1 + y2 == y2 + y1
assert y1 + y1.inverse() == u2
# pairing operation
pair = x1 & y1
assert pair != x1 & y2
assert pair != x2 & y1
assert pair == x1.pair(y1)
# Make G1/G2element from bytes object
#assert g1 == G1(bytes.fromhex('97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb'))
#assert g2 == G2(bytes.fromhex('024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb813e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e'))
test()
print("All tests done.")
"""
Copyright 2018 Chia Network Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""