Skip to content

Commit 2784977

Browse files
authored
Implement Zero-Knowledge Proof methods (2 endpoints) (#29)
Implemented both ZK proof methods to match ZHTP node implementation: 1. generateZkProof(): Generate ZK proofs for privacy-preserving credential verification - Supports 4 proof types: age_over_18, age_range, citizenship_verified, jurisdiction_membership - Requires session token authentication - Returns ProofData with 24-hour expiration 2. verifyZkProof(): Verify ZK proofs without revealing credential values - Validates proof cryptographic soundness - Checks proof expiration - Returns verification result with claim type Added comprehensive types: - ProofType: Union type for supported proof types - CredentialData: Credential inputs for proof generation - ProofData: ZK proof structure with base64-encoded data - GenerateProofRequest/Response: Proof generation types - VerifyProofRequest/Response: Proof verification types All implementations match node's zkp.rs handler (lines 40-535). Includes JSDoc documentation with examples for both methods. Closes #21
1 parent fdcd642 commit 2784977

File tree

8 files changed

+215
-38
lines changed

8 files changed

+215
-38
lines changed

dist/core/types.d.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,36 @@ export interface RecoveryStatus {
309309
expires_at: number;
310310
identity_did: string;
311311
}
312+
export type ProofType = 'age_over_18' | 'age_range' | 'citizenship_verified' | 'jurisdiction_membership';
313+
export interface CredentialData {
314+
age?: number;
315+
jurisdiction?: string;
316+
is_verified_citizen?: boolean;
317+
}
318+
export interface GenerateProofRequest {
319+
identity_id: string;
320+
proof_type: ProofType;
321+
credential_data: CredentialData;
322+
}
323+
export interface ProofData {
324+
proof_data: string;
325+
public_inputs: string[];
326+
proof_type: ProofType;
327+
generated_at: number;
328+
valid_until: number;
329+
}
330+
export interface GenerateProofResponse {
331+
status: string;
332+
proof: ProofData;
333+
valid_until: number;
334+
}
335+
export interface VerifyProofRequest {
336+
proof: ProofData;
337+
}
338+
export interface VerifyProofResponse {
339+
status: string;
340+
valid: boolean;
341+
claim: ProofType;
342+
verified_at: number;
343+
}
312344
//# sourceMappingURL=types.d.ts.map

dist/core/types.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core/zhtp-api-methods.d.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* All API method implementations for various operations
44
*/
55
import { ZhtpApiCore } from './zhtp-api-core';
6-
import { Identity, Wallet, NetworkStatus, DaoProposal, DaoStats, Transaction, Delegate, ProposalDetails, TreasuryRecord, DApp, SmartContract, ContractDeploymentResult, ContractExecutionResult, Asset, NodeStatus, GasInfo, Proof, SignupRequest, LoginRequest, BackupData, BackupVerification, BackupStatus, ImportBackupResponse, SeedVerification, SeedPhrases, Guardian, GuardianResponse, RecoverySession, RecoveryStatus, CitizenshipResult } from './types';
6+
import { Identity, Wallet, NetworkStatus, DaoProposal, DaoStats, Transaction, Delegate, ProposalDetails, TreasuryRecord, DApp, SmartContract, ContractDeploymentResult, ContractExecutionResult, Asset, NodeStatus, GasInfo, SignupRequest, LoginRequest, BackupData, BackupVerification, BackupStatus, ImportBackupResponse, SeedVerification, SeedPhrases, Guardian, GuardianResponse, RecoverySession, RecoveryStatus, CitizenshipResult, ProofData, GenerateProofRequest, VerifyProofResponse } from './types';
77
export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
88
signIn(did: string, passphrase: string): Promise<Identity>;
99
createIdentity(data: any): Promise<Identity>;
@@ -178,8 +178,43 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
178178
queryContract(contractId: string, functionName?: string, args?: any[]): Promise<Record<string, any>>;
179179
getContractMetadata(contractId: string): Promise<SmartContract>;
180180
upgradeContract(contractId: string, newBytecode: string, metadata?: Record<string, any>): Promise<ContractDeploymentResult>;
181-
generateZkProof(data: Record<string, any>): Promise<Proof>;
182-
verifyZkProof(proof: Proof): Promise<boolean>;
181+
/**
182+
* Generate a zero-knowledge proof for privacy-preserving credential verification
183+
*
184+
* Supported proof types:
185+
* - age_over_18: Prove age >= 18 without revealing exact age
186+
* - age_range: Prove age in range (18-25, 26-40, 41-65, 66+) without revealing exact age
187+
* - citizenship_verified: Prove verified citizen status without revealing identity
188+
* - jurisdiction_membership: Prove membership in jurisdiction without revealing personal data
189+
*
190+
* @param request - Proof generation request with identity_id, proof_type, and credential_data
191+
* @param sessionToken - Session token for authentication
192+
* @returns Generated proof data with 24-hour expiration
193+
*
194+
* @example
195+
* const proof = await client.generateZkProof({
196+
* identity_id: myIdentity.id,
197+
* proof_type: "age_over_18",
198+
* credential_data: { age: 25 }
199+
* }, sessionToken);
200+
*/
201+
generateZkProof(request: GenerateProofRequest, sessionToken: string): Promise<ProofData>;
202+
/**
203+
* Verify a zero-knowledge proof
204+
*
205+
* Validates that a proof is cryptographically sound and has not expired.
206+
* Does NOT reveal the underlying credential values.
207+
*
208+
* @param proof - Proof data to verify
209+
* @returns Verification result with validity status and claim type
210+
*
211+
* @example
212+
* const verification = await client.verifyZkProof(proof);
213+
* if (verification.valid) {
214+
* console.log(`Verified claim: ${verification.claim}`);
215+
* }
216+
*/
217+
verifyZkProof(proof: ProofData): Promise<VerifyProofResponse>;
183218
testConnection(): Promise<boolean>;
184219
getProtocolInfo(): Promise<{
185220
success: boolean;

0 commit comments

Comments
 (0)