Skip to content

Commit 916678e

Browse files
committed
docstring baseline commit & minor error result type update
1 parent 4da79ec commit 916678e

File tree

6 files changed

+307
-23
lines changed

6 files changed

+307
-23
lines changed

docs/jam_vrf.html

Lines changed: 170 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,18 @@ <h2>API Documentation</h2>
6363
<h1 class="modulename">
6464
jam_vrf </h1>
6565

66-
<div class="docstring"><p>Python module</p>
66+
<div class="docstring"><p>A Python library for verifying JAM VRF signatures</p>
6767
</div>
6868

6969
<input id="mod-jam_vrf-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
7070

7171
<label class="view-source-button" for="mod-jam_vrf-view-source"><span>View Source</span></label>
7272

73-
<div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos">1</span></a><span class="c1"># Import from the compiled Rust module</span>
74-
</span><span id="L-2"><a href="#L-2"><span class="linenos">2</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.jam_vrf</span><span class="w"> </span><span class="kn">import</span> <span class="o">*</span>
75-
</span><span id="L-3"><a href="#L-3"><span class="linenos">3</span></a>
76-
</span><span id="L-4"><a href="#L-4"><span class="linenos">4</span></a><span class="vm">__doc__</span> <span class="o">=</span> <span class="n">jam_vrf</span><span class="o">.</span><span class="vm">__doc__</span>
77-
</span><span id="L-5"><a href="#L-5"><span class="linenos">5</span></a>
78-
</span><span id="L-6"><a href="#L-6"><span class="linenos">6</span></a><span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;RingVerifier&quot;</span><span class="p">,</span> <span class="s2">&quot;VRFOutput&quot;</span><span class="p">,</span> <span class="s2">&quot;get_ring_commitment&quot;</span><span class="p">,</span> <span class="s2">&quot;ietf_verify&quot;</span><span class="p">]</span>
73+
<div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos">1</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.jam_vrf</span><span class="w"> </span><span class="kn">import</span> <span class="o">*</span>
74+
</span><span id="L-2"><a href="#L-2"><span class="linenos">2</span></a>
75+
</span><span id="L-3"><a href="#L-3"><span class="linenos">3</span></a><span class="vm">__doc__</span> <span class="o">=</span> <span class="n">jam_vrf</span><span class="o">.</span><span class="vm">__doc__</span>
76+
</span><span id="L-4"><a href="#L-4"><span class="linenos">4</span></a>
77+
</span><span id="L-5"><a href="#L-5"><span class="linenos">5</span></a><span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;RingVerifier&quot;</span><span class="p">,</span> <span class="s2">&quot;VRFOutput&quot;</span><span class="p">,</span> <span class="s2">&quot;get_ring_commitment&quot;</span><span class="p">,</span> <span class="s2">&quot;ietf_verify&quot;</span><span class="p">]</span>
7978
</span></pre></div>
8079

8180

@@ -90,7 +89,35 @@ <h1 class="modulename">
9089
</div>
9190
<a class="headerlink" href="#RingVerifier"></a>
9291

93-
<div class="docstring"><p>VRF verifier for ring signatures</p>
92+
<div class="docstring"><p>Verifier instance used for verifying signatures against a particular ring</p>
93+
94+
<p><strong>Args:</strong></p>
95+
96+
<ul>
97+
<li>commitment: <code>bytes</code> - ring commitment (in JAM this is called a <strong>ring root</strong>)</li>
98+
<li>ring_size: <code>int</code> - number of keys in the ring</li>
99+
</ul>
100+
101+
<p><strong>Raises:</strong></p>
102+
103+
<ul>
104+
<li><code>Exception</code> - if an internal error is encountered</li>
105+
</ul>
106+
107+
<p><strong>Example:</strong></p>
108+
109+
<pre><code>from jam_vrf import RingVerifier
110+
111+
# arguments
112+
commitment = bytes.fromhex("85f9...")
113+
ring_size = 6
114+
115+
# construct ring verifier
116+
try:
117+
verifier = RingVerifier(commitment, ring_size)
118+
except Exception as e:
119+
...
120+
</code></pre>
94121
</div>
95122

96123

@@ -104,7 +131,42 @@ <h1 class="modulename">
104131
</div>
105132
<a class="headerlink" href="#RingVerifier.verify"></a>
106133

107-
<div class="docstring"><p>Verify a ring VRF signature</p>
134+
<div class="docstring"><p>Verify a ring signature against some data &amp; additional data</p>
135+
136+
<p><strong>Args:</strong></p>
137+
138+
<ul>
139+
<li>data: <code>bytes</code></li>
140+
<li>ad: <code>bytes</code> - additional data</li>
141+
<li>signature: <code>bytes</code> - ring signature</li>
142+
</ul>
143+
144+
<p><strong>Raises:</strong></p>
145+
146+
<ul>
147+
<li><code>ValueError</code> - if the signature is invalid</li>
148+
<li><code>Exception</code> - if an internal error is encountered</li>
149+
</ul>
150+
151+
<p><strong>Example:</strong></p>
152+
153+
<pre><code>verifier: RingVerifier
154+
155+
# arguments
156+
entropy = bytes.fromhex("bb30...")
157+
attempt = 1
158+
signature = bytes.fromhex("1dfb...")
159+
160+
# verify signature
161+
try:
162+
verifier.verify(
163+
b"jam_ticket_seal" + entropy + bytes([attempt]),
164+
b"",
165+
signature
166+
)
167+
except ValueError as e:
168+
print("invalid signature!")
169+
</code></pre>
108170
</div>
109171

110172

@@ -121,6 +183,27 @@ <h1 class="modulename">
121183
<a class="headerlink" href="#VRFOutput"></a>
122184

123185
<div class="docstring"><p>VRF output type common to both ietf and ring VRFs</p>
186+
187+
<p><strong>Args:</strong></p>
188+
189+
<ul>
190+
<li>bytes: <code>bytes</code> - output bytes</li>
191+
</ul>
192+
193+
<p><strong>Raises:</strong></p>
194+
195+
<ul>
196+
<li><code>Exception</code> if an internal error is encountered</li>
197+
</ul>
198+
199+
<p><strong>Example:</strong></p>
200+
201+
<pre><code>from jam_vrf import VRFOutput
202+
203+
# construct vrf output from a safrole ticket signature
204+
signature = bytes.fromhex("1dfb...")
205+
vrf_output = VRFOutput(signature[:32])
206+
</code></pre>
124207
</div>
125208

126209

@@ -134,7 +217,13 @@ <h1 class="modulename">
134217
</div>
135218
<a class="headerlink" href="#VRFOutput.hash"></a>
136219

137-
<div class="docstring"><p>Get the hash bytes</p>
220+
<div class="docstring"><p>Return the VRF output hash</p>
221+
222+
<p><strong>Example:</strong></p>
223+
224+
<pre><code>vrf_output: VRFOutput
225+
id = vrf_output.hash()[:32] # ticket IDs in JAM only use the first 32 bytes
226+
</code></pre>
138227
</div>
139228

140229

@@ -150,7 +239,43 @@ <h1 class="modulename">
150239
</div>
151240
<a class="headerlink" href="#get_ring_commitment"></a>
152241

153-
<div class="docstring"><p>Create a commitment from a list of public keys</p>
242+
<div class="docstring"><p>Compute the ring commitment for an ordered list of public keys</p>
243+
244+
<p><strong>Args:</strong></p>
245+
246+
<ul>
247+
<li>public_keys: <code>List[bytes]</code> - bandersnatch public keys</li>
248+
</ul>
249+
250+
<p><strong>Returns:</strong></p>
251+
252+
<ul>
253+
<li><code>bytes</code>: object that represents the ring commitment</li>
254+
</ul>
255+
256+
<p><strong>Raises:</strong></p>
257+
258+
<ul>
259+
<li><code>ValueError</code> if no public keys are provided</li>
260+
<li><code>Exception</code> if an internal error is encountered</li>
261+
</ul>
262+
263+
<p><strong>Example</strong></p>
264+
265+
<pre><code>from jam_vrf get_ring_commitment
266+
267+
# ring public keys
268+
public_keys = [
269+
bytes.fromhex("7b32..."),
270+
...
271+
]
272+
273+
# generate ring commitment
274+
try:
275+
commitment = get_ring_commitment(public_keys)
276+
except Exception as e:
277+
...
278+
</code></pre>
154279
</div>
155280

156281

@@ -165,7 +290,40 @@ <h1 class="modulename">
165290
</div>
166291
<a class="headerlink" href="#ietf_verify"></a>
167292

168-
<div class="docstring"><p>Verify an IETF signature of some data &amp; ad by a given public key</p>
293+
<div class="docstring"><p>Verify an IETF signature against some data &amp; additional data</p>
294+
295+
<p><strong>Args:</strong></p>
296+
297+
<ul>
298+
<li>public_keys: <code>bytes</code> - bandersnatch public key</li>
299+
<li>data: <code>bytes</code></li>
300+
<li>ad: <code>bytes</code> - additional data</li>
301+
<li>signature: <code>bytes</code></li>
302+
</ul>
303+
304+
<p><strong>Raises:</strong></p>
305+
306+
<ul>
307+
<li><code>ValueError</code> if the signature is invalid</li>
308+
<li><code>Exception</code> if an internal error is encountered</li>
309+
</ul>
310+
311+
<p><strong>Example:</strong></p>
312+
313+
<pre><code>from jam_vrf import ietf_verify
314+
315+
# arguments
316+
public_key = bytes.fromhex("b0e1...")
317+
data = bytes.fromhex("4261...")
318+
ad = bytes.fromhex("1f42")
319+
signature = bytes.fromhex("6d1d...")
320+
321+
# verify signature
322+
try:
323+
ietf_verify(public_key, data, ad, signature)
324+
except ValueError as e:
325+
print("invalid signature!")
326+
</code></pre>
169327
</div>
170328

171329

0 commit comments

Comments
 (0)