Skip to content

Commit ba0200c

Browse files
authored
Merge pull request #54 from Sindri-Labs/kp-meta-field
Add meta field to compile/prove endpoint methods
2 parents 920f986 + baf593a commit ba0200c

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/sindri/sindri.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ def _set_json_request_headers(self) -> None:
350350
}
351351

352352
def create_circuit(
353-
self, circuit_upload_path: str, tags: list[str] | None = None, wait: bool = True
353+
self,
354+
circuit_upload_path: str,
355+
tags: list[str] | None = None,
356+
wait: bool = True,
357+
meta: dict | None = None,
354358
) -> str:
355359
"""Create a circuit. For information, refer to the
356360
[API docs](https://sindri.app/docs/reference/api/circuit-create/).
@@ -359,6 +363,9 @@ def create_circuit(
359363
- `circuit_upload_path`: The path to either
360364
- A directory containing your circuit files
361365
- A compressed file (`.tar.gz` or `.zip`) of your circuit directory
366+
- `meta`: An arbitrary mapping of metadata keys to string values.
367+
This can be used to track additional information about the circuit such as an ID
368+
from an external system.
362369
- `tags`: A list of tags to assign the circuit. Defaults to `["latest"]` if not
363370
sepecified.
364371
- `wait`:
@@ -401,11 +408,16 @@ def create_circuit(
401408
tar.add(circuit_upload_path, arcname=file_name)
402409
files = {"files": fh.getvalue()} # type: ignore
403410

411+
data = {
412+
"tags": tags,
413+
}
414+
if meta is not None:
415+
data["meta"] = json.dumps(meta) # type: ignore
404416
# Hit circuit/create API endpoint
405417
response_status_code, response_json = self._hit_api(
406418
"POST",
407419
"circuit/create",
408-
data={"tags": tags},
420+
data=data,
409421
files=files,
410422
)
411423
if response_status_code != 201:
@@ -740,13 +752,16 @@ def prove_circuit(
740752
proof_input: str,
741753
perform_verify: bool = False,
742754
wait: bool = True,
755+
meta: dict | None = None,
743756
**kwargs,
744757
) -> str:
745758
"""Prove a circuit with specified inputs. For information, refer to the
746759
[API docs](https://sindri.app/docs/reference/api/proof-create/).
747760
748761
Args:
749762
- `circuit_id`: The circuit identifier of the circuit.
763+
- `meta`: An arbitrary mapping of metadata keys to string values. This can be used to
764+
track additional information about the proof such as an ID from an external system.
750765
- `proof_input`: A string representing proof input which may be formatted as JSON for any
751766
framework. Noir circuits optionally accept TOML formatted proof input.
752767
- `perform_verify`: A boolean indicating whether to perform an internal verification check
@@ -775,15 +790,18 @@ def prove_circuit(
775790
# 1. Submit a proof, obtain a proof_id.
776791
if self.verbose_level > 0:
777792
print("Prove circuit")
793+
794+
data = {
795+
"proof_input": proof_input,
796+
"perform_verify": perform_verify,
797+
"prover_implementation": prover_implementation,
798+
}
799+
if meta is not None:
800+
data["meta"] = json.dumps(meta)
801+
778802
# Hit the circuit/<circuit_id>/prove endpoint
779803
response_status_code, response_json = self._hit_api(
780-
"POST",
781-
f"circuit/{circuit_id}/prove",
782-
data={
783-
"proof_input": proof_input,
784-
"perform_verify": perform_verify,
785-
"prover_implementation": prover_implementation,
786-
},
804+
"POST", f"circuit/{circuit_id}/prove", data=data
787805
)
788806
if response_status_code != 201:
789807
raise Sindri.APIError(

tests/test_sindri.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ def test_circuit_create_prove_other(self):
7373
1. Test delete proof
7474
1. Test delete circuit
7575
"""
76-
circuit_id = sindri.create_circuit(noir_circuit_dir)
77-
proof_id = sindri.prove_circuit(circuit_id, noir_proof_input)
76+
circuit_id = sindri.create_circuit(
77+
noir_circuit_dir, tags=["latest", "pytest"], meta={"py-sdk": "pytest"}
78+
)
79+
proof_id = sindri.prove_circuit(circuit_id, noir_proof_input, meta={"py-sdk": "pytest"})
7880
sindri.get_all_circuit_proofs(circuit_id)
7981
sindri.get_circuit(circuit_id)
8082
sindri.get_proof(proof_id)

0 commit comments

Comments
 (0)