Skip to content

Commit 47b0997

Browse files
Add pedersen_commitment function and docstring explaining parameters
1 parent 75e7b2f commit 47b0997

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

pydatastructs/graphs/graph.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,37 @@ def serialize_graph(graph):
3131
if not graph.vertices or not graph.edge_weights:
3232
return "EMPTY_GRAPH"
3333
return str(sorted(graph.vertices)) + str(sorted(graph.edge_weights.items()))
34+
def pedersen_commitment(graph, g, h, p, q, include_weights=True):
35+
"""
36+
Returns a Pedersen commitment for the given graph.
37+
38+
This function creates a cryptographic commitment of the graph's structure.
39+
The commitment hides node and edge information but allows later verification
40+
by revealing the original graph and blinding factor.
41+
42+
Parameters
43+
----------
44+
graph : Graph
45+
The PyDataStructs graph object to commit.
46+
47+
g : int
48+
A generator of a subgroup of order q (g^q ≡ 1 mod p).
49+
50+
h : int
51+
A second, independent generator of the same subgroup.
52+
53+
p : int
54+
A large prime modulus (≥1024 bits) such that q divides p - 1.
55+
56+
q : int
57+
A prime number representing the subgroup order (≥160 bits).
58+
59+
include_weights : bool, optional
60+
Whether to include edge weights in the graph serialization. Default is True.
61+
3462
3563
__all__ = [
36-
'Graph'
64+
'Graph', 'pedersen_commitment'
3765
]
3866
import copy
3967
import time

0 commit comments

Comments
 (0)