Skip to main content

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

from py_arkworks_bls12381 import Scalar

# Initialisation - The default initialiser for a scalar is an u128 integer
scalar = Scalar(12345)

# Equality -- We override eq and neq operators
assert scalar == scalar
assert Scalar(1234) != Scalar(4567)

# Scalar Addition/subtraction/Negation -- We override the add/sub/neg operators
a = Scalar(3)
b = Scalar(4)
c = Scalar(5)
assert a.square() + b.square() == c.square()
assert a * a + b * b == c * c

neg_a = -a
assert a + neg_a == Scalar(0)
assert (a + neg_a).is_zero()

# Serialisation
compressed_bytes = scalar.to_bytes()
deserialised_scalar = Scalar.from_bytes(compressed_bytes)
deserialised_scalar_unchecked = Scalar.from_bytes_unchecked(compressed_bytes)
assert scalar == deserialised_scalar
assert scalar == deserialised_scalar_unchecked

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


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.2.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_arkworks_bls12381-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (268.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file py_arkworks_bls12381-0.1.2.tar.gz.

File metadata

  • Download URL: py_arkworks_bls12381-0.1.2.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.14.13

File hashes

Hashes for py_arkworks_bls12381-0.1.2.tar.gz
Algorithm Hash digest
SHA256 68849700e1100ff4ecf2edaa4b6edb26b4ed98aaea633a0faf99fb4af317d864
MD5 49be56e4a1045500f8b2c1bf04d108dc
BLAKE2b-256 c8b818a6d685801b7055d162f61085daecf8af70e976dca5a38e48c007a74efc

See more details on using hashes here.

File details

Details for the file py_arkworks_bls12381-0.1.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for py_arkworks_bls12381-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 685ab25dda5637f7054104db5134f492b1379df0c9dc0d4798a078224d89c4c9
MD5 aa690b5cb5985b0d945a50b35e0b3795
BLAKE2b-256 e7d92d464d63e12129b880afd79a858ff5f5b7829223b4a67726a37cd0d60b4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page