Get ZKP
Retrieve zero-knowledge proofs that verify database operations without revealing sensitive data.
Definition
await zkdb
.db(databaseName: string)
.zkProof(step?: bigint): Promise<TZkProofResponse | null>;
Parameters
step
(bigint, optional): Specific rollup step to retrieve proof for. If not provided, returns the latest proof.
Returns
Promise<TZkProofResponse | null>
: A promise that resolves to aTZkProofResponse
ornull
if no proof is available.
The TZkProofResponse
contains the following structure:
type TZkProofResponse = {
step: bigint;
proof: JsonProof;
};
type JsonProof = {
publicInput: string[];
publicOutput: string[];
maxProofsVerified: number;
proof: string;
};
Property | Type | Description |
---|---|---|
step | bigint | Represents the rollup step or iteration number within the proof generation. |
proof | JsonProof | A JSON object containing the generated zero-knowledge proof. |
JsonProof Fields:
Field | Type | Description |
---|---|---|
publicInput | string[] | An array of public inputs used in the proof generation. |
publicOutput | string[] | An array of public outputs derived from the proof. |
maxProofsVerified | number | The maximum number of proofs verified in the current proof. |
proof | string | The encoded proof data in a string format. |
Example
import { ZkDatabase } from 'zkdb';
const zkdb = await ZkDatabase.connect({
userName: "chiro-user",
privateKey: "EKFTciRxyxshZjimay9sktsn7v5PvmC5zPq7q4JnitHUytxUVnFP",
environment: "node",
// This URL is for test environment
url: "https://api.zkdatabase.org/graphql",
});
await zkdb.auth.signIn();
const dbTest = zkdb.db('zkdb_test');
const zkProof = await dbTest.zkProof();
console.log('ZK Proof:', zkProof);
await zkdb.auth.signOut();
Result:
{
"step": 10,
"proof": {
"publicInput": [
"9",
"25841764576285046988186167653748636396178872522546148714971399248557895316929",
"3947663588673285028481390057420318710802249460490724323846855806133396101815"
],
"publicOutput": [
"10",
"3947663588673285028481390057420318710802249460490724323846855806133396101815"
],
"maxProofsVerified": 1,
"proof": "KChzdGF0ZW1... 22508 more characters"
}
}
Proof Not Available?
If this method returns null
, it typically means:
- No document operations have been performed yet
- Prover system is still processing operations (check
proverStatus()
) - Proof generation failed (use
proverRetry()
to restart)
Troubleshooting workflow: zkProofStatus()
→ proverStatus()
→ proverRetry()
if needed
Verify ZKP
Verify the cryptographic integrity of zero-knowledge proofs.
When to use:
- Before
rollUpOnChainStart()
- For audit compliance
- When troubleshooting failed operations
Definition
await zkdb
.db(databaseName: string)
.zkProofVerify(step?: bigint): Promise<TZkDbProofVerify>;
Parameters
step
(bigint, optional): Specific rollup step to verify proof for. If not provided, verifies the latest proof.
Returns
Promise<TZkDbProofVerify>
: A promise that resolves to a verification result with validity status.
Related: zkProofStatus()
| proverStatus()
| rollUpOnChainStart()
type TZkDbProofVerify = {
step: bigint;
merkleRoot: string;
valid: boolean;
};
Property | Type | Description |
---|---|---|
step | bigint | The rollup step number that was verified. |
merkleRoot | string | The Merkle root hash representing the state at this step. |
valid | boolean | Indicates whether the proof verification was successful (true ) or failed (false ). |
Example
import { ZkDatabase } from 'zkdb';
const zkdb = await ZkDatabase.connect({
userName: "chiro-user",
privateKey: "EKFTciRxyxshZjimay9sktsn7v5PvmC5zPq7q4JnitHUytxUVnFP",
environment: "node",
// This URL is for test environment
url: "https://api.zkdatabase.org/graphql",
});
await zkdb.auth.signIn();
const dbTest = zkdb.db('zkdb_test');
const verifyResult = await dbTest.zkProofVerify();
console.log('Verify result:', verifyResult);
await zkdb.auth.signOut();
Result:
{
"step": 10,
"merkleRoot": "3947663588673285028481390057420318710802249460490724323846855806133396101815",
"valid": true
}