jam_vrf

A Python library for verifying JAM VRF signatures

1from .jam_vrf import *
2
3__doc__ = jam_vrf.__doc__
4
5__all__ = ["RingVerifier", "VRFOutput", "get_ring_commitment", "ietf_verify"]
class RingVerifier:

Used for verifying ring signatures

Constructor Args:

  • commitment: bytes - ring commitment
  • ring_size: int - number of keys in the ring

Raises:

  • Exception - internal error

Example:

try:
    verifier = RingVerifier(commitment, ring_size)
except Exception:
    ...
def verify(self, /, batch):

Verify a batch of ring signatures

Args:

  • batch: [(data, additional_data, signature)] - collection of data & signatures to be verified. All of the tuple fields are python bytes type.

Raises:

  • ValueError(Dict{index: PyErr}) - contains a dictionary mapping invalid indexes to validation errors
  • Exception - internal error

Example:

verifier: RingVerifier

try:
    verifier.verify([data, ad, signature], [data, ad, signature])
except ValueError as e:
    for batch_index, error in e.args[0].items():
        print("batch index {} produced error: {}".format(batch_index, error))
class VRFOutput:

VRF output type common to both IETF and ring VRFs

Args:

  • output: bytes

Raises:

  • Exception - internal error

Example: vrf_output = VRFOutput(output)

def hash(self, /):

Hash the output point

Example: hash = VRFOutput(output).hash()

def get_ring_commitment(public_keys):

Compute the ring commitment for an ordered list of public keys

Args:

  • public_keys: List[bytes] - bandersnatch public keys

Returns:

  • bytes: object that represents the ring commitment

Raises:

  • ValueError - invalid or empty input keys
  • Exception - internal error

Example

try:
    commitment = get_ring_commitment(public_keys)
except Exception:
    ...
def ietf_verify(public_key, data, ad, signature):

Verify an IETF signature against some data & additional data

Args:

  • public_key: bytes - bandersnatch public key
  • data: bytes
  • ad: bytes - additional data
  • signature: bytes

Raises:

  • ValueError - invalid signature
  • Exception - internal error

Example:

try:
    ietf_verify(public_key, data, ad, signature)
except ValueError:
    print("invalid signature!")