ZK Adapter API Reference¶
The ZK adapter provides post-quantum zero-knowledge proof primitives built on
STARKs (via winterfell). It covers Poseidon hashing, shielded commitments,
nullifiers, preimage proofs, and range proofs. A separate set of shielded pool
methods on DilithiaClient lets you interact with the on-chain shielded
contract.
Types¶
Commitment¶
A commitment to a shielded value, computed as Poseidon(value || secret || nonce).
Nullifier¶
A nullifier proving a commitment was spent, computed as Poseidon(secret || nonce).
StarkProof / StarkProofResult¶
The result of generating a STARK proof. Contains the serialized proof bytes, the verification key, and the public inputs.
ComplianceType¶
The type of compliance proof being submitted to the shielded pool.
ComplianceType is passed as a plain str with values "not_on_sanctions",
"tax_paid", or "balance_range".
ComplianceType is passed as a plain string with values "not_on_sanctions",
"tax_paid", or "balance_range".
ComplianceType is passed as a plain String with values "not_on_sanctions",
"tax_paid", or "balance_range".
ComplianceType is passed as a plain string with values "not_on_sanctions",
"tax_paid", or "balance_range".
ZK Adapter Methods¶
These methods are exposed by the ZK adapter interface. In TypeScript and Python there are both async and sync variants of the adapter (see notes below).
poseidonHash¶
Compute a Poseidon hash over an array of field elements.
Parameters:
| Name | Type | Description |
|---|---|---|
inputs |
array of integers | Field elements to hash |
Returns: hex-encoded hash string.
computeCommitment¶
Create a shielded commitment: Poseidon(value || secret || nonce).
Parameters:
| Name | Type | Description |
|---|---|---|
value |
integer | Amount to commit |
secretHex |
string | Hex-encoded 32-byte secret |
nonceHex |
string | Hex-encoded 32-byte nonce |
Returns: a Commitment object.
computeNullifier¶
Create a nullifier: Poseidon(secret || nonce). The nullifier uniquely
identifies a commitment without revealing its value.
Parameters:
| Name | Type | Description |
|---|---|---|
secretHex |
string | Hex-encoded 32-byte secret |
nonceHex |
string | Hex-encoded 32-byte nonce |
Returns: a Nullifier object.
generatePreimageProof¶
Generate a STARK proof of knowledge of a hash preimage. Proves that the prover knows field elements whose Poseidon hash equals a public output, without revealing the elements themselves.
Parameters:
| Name | Type | Description |
|---|---|---|
values |
array of integers | Preimage field elements |
Returns: a StarkProof / StarkProofResult.
verifyPreimageProof¶
Verify a STARK preimage proof.
Parameters:
| Name | Type | Description |
|---|---|---|
proofHex |
string | Hex-encoded proof bytes |
vkJson |
string | JSON-encoded verification key |
inputsJson |
string | JSON-encoded public inputs |
Returns: boolean -- true if the proof is valid.
generateRangeProof¶
Generate a STARK range proof proving that value is in the range [min, max]
without revealing the actual value.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
integer | The secret value |
min |
integer | Range lower bound |
max |
integer | Range upper bound |
Returns: a StarkProof / StarkProofResult.
verifyRangeProof¶
Verify a STARK range proof.
Parameters:
| Name | Type | Description |
|---|---|---|
proofHex |
string | Hex-encoded proof bytes |
vkJson |
string | JSON-encoded verification key |
inputsJson |
string | JSON-encoded public inputs |
Returns: boolean -- true if the proof is valid.
Shielded Pool Client Methods¶
These methods live on DilithiaClient and interact with the on-chain
shielded contract. They are available in all five SDKs.
shieldedDeposit¶
Deposit funds into the shielded pool by publishing a commitment.
Parameters:
| Name | Type | Description |
|---|---|---|
commitment |
string | Hex-encoded commitment hash |
value |
integer | Amount to deposit |
proofHex |
string | Hex-encoded STARK proof |
Returns: a submitted call / transaction result.
shieldedWithdraw¶
Withdraw funds from the shielded pool by revealing a nullifier and providing a ZK proof of commitment ownership.
Parameters:
| Name | Type | Description |
|---|---|---|
nullifier |
string | Hex-encoded nullifier hash |
amount |
integer | Amount to withdraw |
recipient |
string | Destination address |
proofHex |
string | Hex-encoded STARK proof |
commitmentRoot |
string | Current Merkle root of the commitment tree |
Returns: a submitted call / transaction result.
// Via builder: client.shielded().withdraw(nullifier, amount, recipient, proof, root).send(signer)
public ShieldedCallBuilder withdraw(String nullifier, long amount,
String recipient, String proof, String root)
// ShieldedCallBuilder.send returns:
public Receipt send(DilithiaSigner signer) throws DilithiaException, CryptoException
getCommitmentRoot¶
Query the current Merkle root of the shielded pool's commitment tree. This root is required when generating withdrawal proofs.
Parameters: none.
Returns: the current commitment root hash.
isNullifierSpent¶
Check whether a nullifier has already been used (i.e., the corresponding commitment has been withdrawn).
Parameters:
| Name | Type | Description |
|---|---|---|
nullifier |
string | Hex-encoded nullifier hash |
Returns: whether the nullifier has been spent.
shieldedComplianceProof¶
Submit a compliance proof to the shielded pool. This allows a user to prove regulatory compliance (e.g., tax paid, not on sanctions list, balance in range) without revealing the underlying transaction data.
Note
This method is currently available in the Rust SDK only. Other SDKs
can achieve the same result by calling buildContractCall / callContract
with the "shielded" contract and "compliance_proof" method directly.
Parameters:
| Name | Type | Description |
|---|---|---|
proofType |
string | One of "not_on_sanctions", "tax_paid", "balance_range" |
proofHex |
string | Hex-encoded STARK proof |
inputsHex |
string | Hex-encoded public inputs |
Returns: a submitted call / transaction result.
Adapter Variants¶
TypeScript¶
TypeScript provides two adapter interfaces:
DilithiaZkAdapter-- all methods returnPromise<T>. Loaded vialoadZkAdapter(), which dynamically imports@dilithia/sdk-zk.SyncDilithiaZkAdapter-- all methods returnTsynchronously. Loaded vialoadSyncZkAdapter(), which usescreateRequireto synchronously require the native bridge.
Both loaders return null if the @dilithia/sdk-zk package is not installed.
Python¶
Python provides two adapter protocols:
DilithiaZkAdapter(Protocol) -- synchronous methods. The concrete implementation isNativeZkAdapter. Loaded viaload_zk_adapter().AsyncDilithiaZkAdapter(Protocol) -- async methods. The concrete implementation isAsyncNativeZkAdapter, which wraps a sync adapter usingasyncio.to_threadso CPU-intensive STARK work does not block the event loop. Loaded viaload_async_zk_adapter().
Both loaders return None if dilithia_sdk_zk is not importable.
Rust¶
Rust defines a DilithiaZkAdapter trait. Enable it with the stark feature
on the dilithia-core crate. Implement the trait for your own type or use the
provided native implementation.
Go¶
Go defines a ZkAdapter interface in sdk.ZkAdapter. Provide your own
implementation backed by a CGo bridge or a gRPC call to a proof service.
Java¶
Java defines a DilithiaZkAdapter interface in
org.dilithia.sdk.DilithiaZkAdapter. Implement it with JNI bindings or a
remote proof service.