zkenclave-sdk 0.1.6 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -17,6 +17,7 @@ interface WithdrawalRequest {
17
17
  merkleRoot?: Uint8Array;
18
18
  merklePath: Uint8Array[];
19
19
  pathIndices: boolean[];
20
+ secret?: Uint8Array;
20
21
  }
21
22
  interface WithdrawalResult {
22
23
  success: boolean;
@@ -93,7 +94,7 @@ declare class ZKProofClient {
93
94
  generateWithdrawalProof(request: WithdrawalRequest): Promise<WithdrawalResult>;
94
95
  private generateRealProof;
95
96
  private generateFallbackProof;
96
- generateComplianceProof(commitment: Uint8Array, associationRoot: Uint8Array): Promise<ComplianceProof>;
97
+ generateComplianceProof(commitment: Uint8Array, associationPath: Uint8Array[], pathIndices: boolean[], associationRoot: Uint8Array): Promise<ComplianceProof>;
97
98
  verifyProof(proofResult: WithdrawalResult): Promise<boolean>;
98
99
  isWasmReady(): boolean;
99
100
  private computeNullifierHash;
@@ -113,7 +114,7 @@ declare class PrivacyVaultSDK {
113
114
  constructor(config: VaultConfig, signer?: ethers.Signer, zkClient?: ZKProofClient);
114
115
  connect(signer: ethers.Signer): Promise<void>;
115
116
  deposit(amount: bigint): Promise<DepositResult>;
116
- withdraw(note: DepositNote, recipient: string): Promise<WithdrawalResult>;
117
+ withdraw(note: DepositNote, recipient: string, complianceProof?: Uint8Array): Promise<WithdrawalResult>;
117
118
  getLatestRoot(): Promise<Uint8Array>;
118
119
  getNextLeafIndex(): Promise<number>;
119
120
  isNullifierUsed(nullifier: Uint8Array): Promise<boolean>;
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ interface WithdrawalRequest {
17
17
  merkleRoot?: Uint8Array;
18
18
  merklePath: Uint8Array[];
19
19
  pathIndices: boolean[];
20
+ secret?: Uint8Array;
20
21
  }
21
22
  interface WithdrawalResult {
22
23
  success: boolean;
@@ -93,7 +94,7 @@ declare class ZKProofClient {
93
94
  generateWithdrawalProof(request: WithdrawalRequest): Promise<WithdrawalResult>;
94
95
  private generateRealProof;
95
96
  private generateFallbackProof;
96
- generateComplianceProof(commitment: Uint8Array, associationRoot: Uint8Array): Promise<ComplianceProof>;
97
+ generateComplianceProof(commitment: Uint8Array, associationPath: Uint8Array[], pathIndices: boolean[], associationRoot: Uint8Array): Promise<ComplianceProof>;
97
98
  verifyProof(proofResult: WithdrawalResult): Promise<boolean>;
98
99
  isWasmReady(): boolean;
99
100
  private computeNullifierHash;
@@ -113,7 +114,7 @@ declare class PrivacyVaultSDK {
113
114
  constructor(config: VaultConfig, signer?: ethers.Signer, zkClient?: ZKProofClient);
114
115
  connect(signer: ethers.Signer): Promise<void>;
115
116
  deposit(amount: bigint): Promise<DepositResult>;
116
- withdraw(note: DepositNote, recipient: string): Promise<WithdrawalResult>;
117
+ withdraw(note: DepositNote, recipient: string, complianceProof?: Uint8Array): Promise<WithdrawalResult>;
117
118
  getLatestRoot(): Promise<Uint8Array>;
118
119
  getNextLeafIndex(): Promise<number>;
119
120
  isNullifierUsed(nullifier: Uint8Array): Promise<boolean>;
package/dist/index.js CHANGED
@@ -502,16 +502,35 @@ var ZKProofClient = class {
502
502
  timestamp: Date.now()
503
503
  };
504
504
  }
505
- async generateComplianceProof(commitment, associationRoot) {
506
- const proofId = (0, import_ethers2.keccak256)(
507
- new Uint8Array([...commitment, ...associationRoot])
508
- );
505
+ async generateComplianceProof(commitment, associationPath, pathIndices, associationRoot) {
506
+ if (this.config.useRealProofs && this.wasmReady && wasmModule) {
507
+ const request = {
508
+ commitment: Array.from(commitment),
509
+ association_path: associationPath.map((p) => Array.from(p)),
510
+ path_indices: pathIndices,
511
+ association_root: Array.from(associationRoot)
512
+ };
513
+ const resultJson = wasmModule.generate_compliance_proof(
514
+ JSON.stringify(request)
515
+ );
516
+ const result = JSON.parse(resultJson);
517
+ if (!result.success) {
518
+ throw new Error(`Compliance proof generation failed: ${result.error}`);
519
+ }
520
+ return {
521
+ id: (0, import_ethers2.keccak256)(new Uint8Array(result.proof)),
522
+ associationRoot,
523
+ timestamp: Date.now(),
524
+ valid: true,
525
+ proof: new Uint8Array(result.proof)
526
+ };
527
+ }
509
528
  return {
510
- id: proofId,
529
+ id: "mock-compliance-proof",
511
530
  associationRoot,
512
531
  timestamp: Date.now(),
513
532
  valid: true,
514
- proof: new Uint8Array(256)
533
+ proof: new Uint8Array(64).fill(1)
515
534
  };
516
535
  }
517
536
  async verifyProof(proofResult) {
@@ -632,7 +651,7 @@ var PrivacyVaultSDK = class {
632
651
  note
633
652
  };
634
653
  }
635
- async withdraw(note, recipient) {
654
+ async withdraw(note, recipient, complianceProof) {
636
655
  if (!this.signer) {
637
656
  throw new Error("Signer required for withdrawals");
638
657
  }
@@ -651,7 +670,8 @@ var PrivacyVaultSDK = class {
651
670
  leafIndex: note.leafIndex,
652
671
  merkleRoot: root,
653
672
  merklePath: [],
654
- pathIndices: []
673
+ pathIndices: [],
674
+ secret: note.secret
655
675
  });
656
676
  const tx = await this.vault.withdraw(
657
677
  bytesToHex(nullifierHash),
@@ -659,7 +679,7 @@ var PrivacyVaultSDK = class {
659
679
  recipient,
660
680
  note.amount,
661
681
  zkProofResult.zkProof,
662
- new Uint8Array(64),
682
+ complianceProof || new Uint8Array(64),
663
683
  { gasLimit: DEFAULT_GAS_LIMIT }
664
684
  );
665
685
  const receipt = await tx.wait();
package/dist/index.mjs CHANGED
@@ -448,16 +448,35 @@ var ZKProofClient = class {
448
448
  timestamp: Date.now()
449
449
  };
450
450
  }
451
- async generateComplianceProof(commitment, associationRoot) {
452
- const proofId = keccak2562(
453
- new Uint8Array([...commitment, ...associationRoot])
454
- );
451
+ async generateComplianceProof(commitment, associationPath, pathIndices, associationRoot) {
452
+ if (this.config.useRealProofs && this.wasmReady && wasmModule) {
453
+ const request = {
454
+ commitment: Array.from(commitment),
455
+ association_path: associationPath.map((p) => Array.from(p)),
456
+ path_indices: pathIndices,
457
+ association_root: Array.from(associationRoot)
458
+ };
459
+ const resultJson = wasmModule.generate_compliance_proof(
460
+ JSON.stringify(request)
461
+ );
462
+ const result = JSON.parse(resultJson);
463
+ if (!result.success) {
464
+ throw new Error(`Compliance proof generation failed: ${result.error}`);
465
+ }
466
+ return {
467
+ id: keccak2562(new Uint8Array(result.proof)),
468
+ associationRoot,
469
+ timestamp: Date.now(),
470
+ valid: true,
471
+ proof: new Uint8Array(result.proof)
472
+ };
473
+ }
455
474
  return {
456
- id: proofId,
475
+ id: "mock-compliance-proof",
457
476
  associationRoot,
458
477
  timestamp: Date.now(),
459
478
  valid: true,
460
- proof: new Uint8Array(256)
479
+ proof: new Uint8Array(64).fill(1)
461
480
  };
462
481
  }
463
482
  async verifyProof(proofResult) {
@@ -578,7 +597,7 @@ var PrivacyVaultSDK = class {
578
597
  note
579
598
  };
580
599
  }
581
- async withdraw(note, recipient) {
600
+ async withdraw(note, recipient, complianceProof) {
582
601
  if (!this.signer) {
583
602
  throw new Error("Signer required for withdrawals");
584
603
  }
@@ -597,7 +616,8 @@ var PrivacyVaultSDK = class {
597
616
  leafIndex: note.leafIndex,
598
617
  merkleRoot: root,
599
618
  merklePath: [],
600
- pathIndices: []
619
+ pathIndices: [],
620
+ secret: note.secret
601
621
  });
602
622
  const tx = await this.vault.withdraw(
603
623
  bytesToHex(nullifierHash),
@@ -605,7 +625,7 @@ var PrivacyVaultSDK = class {
605
625
  recipient,
606
626
  note.amount,
607
627
  zkProofResult.zkProof,
608
- new Uint8Array(64),
628
+ complianceProof || new Uint8Array(64),
609
629
  { gasLimit: DEFAULT_GAS_LIMIT }
610
630
  );
611
631
  const receipt = await tx.wait();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zkenclave-sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.12",
4
4
  "description": "TypeScript SDK for privacy-preserving vault withdrawals with ZK proofs",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",