No project description provided
Project description
py_arkworks_bls12381
Installation
To install you will need maturin to run the builds:
pip install maturin
G1/G2Points
from py_arkworks_bls12381 import G1Point, G2Point, Scalar
# G1Point and G2Point have the same methods implemented on them
# For brevity, I will only show one method using G1Point and G2Point
# The rest of the code will just use G1Point
# Point initialization -- This will be initialized to the g1 generator
g1_generator = G1Point()
g2_generator = G2Point()
# Identity element
identity = G1Point.identity()
# Equality -- We override eq and neq operators
assert g1_generator == g1_generator
assert g1_generator != identity
# Printing an element -- We override __str__ so when we print
# an element it prints in hex
print("identity: ",identity)
print("g1 generator: ", g1_generator)
print("g2 generator: ", g2_generator)
# Point Addition/subtraction/Negation -- We override the add/sub/neg operators
gen = G1Point()
double_gen = gen + gen
assert double_gen - gen == gen
neg_gen = -gen
assert neg_gen + gen == identity
# Scalar multiplication
#
scalar = Scalar(4)
four_gen = gen * scalar
assert four_gen == gen + gen + gen + gen
# Serialisation
#
# serialising to/from a g1 point
# We don't expose the uncompressed form
# because it seems like its not needed
compressed_bytes = gen.to_compressed_bytes()
deserialised_point = G1Point.from_compressed_bytes(compressed_bytes)
# If the bytes being received are trusted, we can avoid
# doing subgroup checks
deserialised_point_unchecked = G1Point.from_compressed_bytes_unchecked(compressed_bytes)
assert deserialised_point == deserialised_point_unchecked
assert deserialised_point == gen
Pairing
from py_arkworks_bls12381 import G1Point, G2Point, GT, Scalar
# Initilisation -- This is the generator point
gt_gen = GT()
# Identity
id = GT.identity()
# Computing a pairing using pairing and multi_pairing
# multi_pairing does multiple pairings with only one final_exp
assert gt_gen == GT.pairing(G1Point(), G2Point())
g1s = [G1Point()]
g2s = [G2Point()]
assert gt_gen == GT.multi_pairing(g1s, g2s)
# Bilinearity
a = Scalar(1234)
b = Scalar(4566)
c = a * b
g = G1Point() * a
h = G2Point() * b
p = GT.pairing(g, h)
c_g1 = G1Point() *c
c_g2 = G2Point() *c
assert p == GT.pairing(c_g1, G2Point())
assert p == GT.pairing(G1Point(), c_g2)
Scalar
Usage (Development)
- First activate the virtual environment
source .env/bin/activate
- Next build the rust package and install it in your virtual environment
maturin develop
- Now run a file in the examples folder
python3 examples/point.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py_arkworks_bls12381-0.1.1.tar.gz
(11.0 kB
view hashes)
Built Distribution
Close
Hashes for py_arkworks_bls12381-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b8c1829cc7479c34c47479ea8000d90e786c7687f314dd20da7f7a6007bb11f |
|
MD5 | 7f4a50678838d3ec444d10ff2c2047e0 |
|
BLAKE2b-256 | 991af9eb01edadd8ffed64a8fb8aa358160acbd475e517f7674910242f245a1a |
Close
Hashes for py_arkworks_bls12381-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fdc38c835c8f75c003967ade5bc29a1af320200d2456e42a242e71c5ee1ba2e |
|
MD5 | d1d19477f9a485698b961c2278d79b6e |
|
BLAKE2b-256 | 7ed761a6cfd4d7a72d7ceaf663ef4239d45e65035536cbf341f101c8bbc00ddf |