@cloak.ag/sdk 1.0.7 → 1.0.9

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.cts CHANGED
@@ -1753,6 +1753,7 @@ interface ShieldPoolPDAs {
1753
1753
  merkleTree: PublicKey;
1754
1754
  commitments: PublicKey;
1755
1755
  rootsRing: PublicKey;
1756
+ /** @deprecated Use getNullifierPDA() for the new per-nullifier PDA design */
1756
1757
  nullifierShard: PublicKey;
1757
1758
  treasury: PublicKey;
1758
1759
  }
@@ -1774,6 +1775,30 @@ interface ShieldPoolPDAs {
1774
1775
  * @param mint - Optional mint address (defaults to 32 zero bytes for native SOL)
1775
1776
  */
1776
1777
  declare function getShieldPoolPDAs(programId?: PublicKey, mint?: PublicKey): ShieldPoolPDAs;
1778
+ /**
1779
+ * Derive the nullifier PDA for a specific nullifier hash.
1780
+ *
1781
+ * With the new PDA-per-nullifier design, each nullifier has its own PDA
1782
+ * instead of being stored in a shared shard. The PDA is created when
1783
+ * the nullifier is used during withdrawal.
1784
+ *
1785
+ * Seeds: ["nullifier", nullifier_hash]
1786
+ *
1787
+ * @param nullifier - 32-byte nullifier hash
1788
+ * @param programId - Optional program ID (defaults to CLOAK_PROGRAM_ID)
1789
+ * @returns [PublicKey, bump] - The nullifier PDA and its bump seed
1790
+ */
1791
+ declare function getNullifierPDA(nullifier: Uint8Array | Buffer, programId?: PublicKey): [PublicKey, number];
1792
+ /**
1793
+ * Derive the swap state PDA for a given nullifier.
1794
+ *
1795
+ * Seeds: ["swap_state", nullifier_hash]
1796
+ *
1797
+ * @param nullifier - 32-byte nullifier hash
1798
+ * @param programId - Optional program ID (defaults to CLOAK_PROGRAM_ID)
1799
+ * @returns [PublicKey, bump] - The swap state PDA and its bump seed
1800
+ */
1801
+ declare function getSwapStatePDA(nullifier: Uint8Array | Buffer, programId?: PublicKey): [PublicKey, number];
1777
1802
 
1778
1803
  /**
1779
1804
  * On-chain Merkle proof computation
@@ -1838,6 +1863,11 @@ declare function computeProofForLatestDeposit(connection: Connection, merkleTree
1838
1863
  * as it doesn't require a backend prover service.
1839
1864
  */
1840
1865
 
1866
+ /**
1867
+ * Default URL for fetching circuit artifacts
1868
+ * These are served from the Cloak web app at https://cloak.ag
1869
+ */
1870
+ declare const DEFAULT_CIRCUITS_URL = "https://www.cloak.ag/circuits";
1841
1871
  interface WithdrawRegularInputs {
1842
1872
  root: bigint;
1843
1873
  nullifier: bigint;
@@ -1898,6 +1928,23 @@ declare function generateWithdrawRegularProof(inputs: WithdrawRegularInputs, cir
1898
1928
  * @param circuitsPath - Path or URL to circuits directory. In browser, use URL like '/circuits' or full URL.
1899
1929
  */
1900
1930
  declare function generateWithdrawSwapProof(inputs: WithdrawSwapInputs, circuitsPath: string): Promise<ProofResult>;
1931
+ /**
1932
+ * Check if circuits are available at the given path or URL
1933
+ * Supports both local file paths and remote URLs
1934
+ *
1935
+ * Note: For remote URLs, this returns true without checking (snarkjs will handle loading).
1936
+ * For local paths, it checks if the files exist on disk.
1937
+ */
1938
+ declare function areCircuitsAvailable(circuitsPath: string): Promise<boolean>;
1939
+ /**
1940
+ * Get default circuits path or URL
1941
+ *
1942
+ * Priority:
1943
+ * 1. CIRCUITS_PATH environment variable (if set)
1944
+ * 2. Local file paths (if available)
1945
+ * 3. Default remote URL (https://cloak.ag/circuits)
1946
+ */
1947
+ declare function getDefaultCircuitsPath(): Promise<string>;
1901
1948
  /**
1902
1949
  * Expected circuit hashes for verification
1903
1950
  * These are computed from the verification key files to ensure circuits match on-chain vkeys
@@ -2076,4 +2123,4 @@ declare function cleanupStalePendingOperations(maxAgeMs?: number): {
2076
2123
 
2077
2124
  declare const VERSION = "1.0.0";
2078
2125
 
2079
- export { CLOAK_PROGRAM_ID, type CircuitVerificationResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, CloakSDK, type DepositInstructionParams, type DepositOptions, type DepositResult, type DepositStatus, EXPECTED_CIRCUIT_HASHES, type EncryptedNote, type ErrorCategory, FIXED_FEE_LAMPORTS, type Groth16Proof, LAMPORTS_PER_SOL, LocalStorageAdapter, type LogLevel, type Logger, type MasterKey, type MaxLengthArray, MemoryStorageAdapter, type MerkleProof, type MerkleRootResponse, type Network, type NoteData, type OnchainMerkleProof, type PendingDeposit, type PendingWithdrawal, type ProofResult, RelayService, RootNotFoundError, ShieldPoolErrors, type ShieldPoolPDAs, type SpendKey, type StorageAdapter, type SwapOptions, type SwapParams, type SwapResult, type Transfer, type TransferOptions, type TransferResult, type TxStatus, type UserFriendlyError, VARIABLE_FEE_RATE, VERSION, type ViewKey, type WalletAdapter, type WithdrawOptions, type WithdrawRegularInputs, type WithdrawSubmissionResult, type WithdrawSwapInputs, bigintToBytes32, buildPublicInputsBytes, bytesToHex, calculateFee, calculateRelayFee, cleanupStalePendingOperations, clearPendingDeposits, clearPendingWithdrawals, computeCommitment, computeMerkleRoot, computeNullifier, computeNullifierAsync, computeNullifierSync, computeOutputsHash, computeOutputsHashAsync, computeOutputsHashSync, computeProofForLatestDeposit, computeProofFromChain, computeSwapOutputsHash, computeSwapOutputsHashAsync, computeSwapOutputsHashSync, copyNoteToClipboard, createCloakError, createDepositInstruction, createLogger, deriveSpendKey, deriveViewKey, detectNetworkFromRpcUrl, downloadNote, encodeNoteSimple, encryptNoteForRecipient, exportKeys, exportNote, exportWalletKeys, filterNotesByNetwork, filterWithdrawableNotes, findNoteByCommitment, formatAmount, formatErrorForLogging, formatSol, generateCloakKeys, generateCommitment, generateCommitmentAsync, generateMasterSeed, generateNote, generateNoteFromWallet, generateWithdrawRegularProof, generateWithdrawSwapProof, getAddressExplorerUrl, getDistributableAmount, getExplorerUrl, getPendingOperationsSummary, getPublicKey, getPublicViewKey, getRecipientAmount, getRpcUrlForNetwork, getShieldPoolPDAs, getViewKey, hasPendingOperations, hexToBigint, hexToBytes, importKeys, importWalletKeys, isDebugEnabled, isRootNotFoundError, isValidHex, isValidRpcUrl, isValidSolanaAddress, isWithdrawable, keypairToAdapter, loadPendingDeposits, loadPendingWithdrawals, parseAmount, parseError, parseNote, parseTransactionError, poseidonHash, prepareEncryptedOutput, prepareEncryptedOutputForRecipient, proofToBytes, pubkeyToLimbs, randomBytes, readMerkleTreeState, removePendingDeposit, removePendingWithdrawal, savePendingDeposit, savePendingWithdrawal, scanNotesForWallet, sdkLogger, sendTransaction, serializeNote, setDebugMode, signTransaction, splitTo2Limbs, truncate, tryDecryptNote, updateNoteWithDeposit, updatePendingDeposit, updatePendingWithdrawal, validateDepositParams, validateNote, validateOutputsSum, validateTransfers, validateWalletConnected, validateWithdrawableNote, verifyAllCircuits, verifyCircuitIntegrity, withTiming };
2126
+ export { CLOAK_PROGRAM_ID, type CircuitVerificationResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, CloakSDK, DEFAULT_CIRCUITS_URL, type DepositInstructionParams, type DepositOptions, type DepositResult, type DepositStatus, EXPECTED_CIRCUIT_HASHES, type EncryptedNote, type ErrorCategory, FIXED_FEE_LAMPORTS, type Groth16Proof, LAMPORTS_PER_SOL, LocalStorageAdapter, type LogLevel, type Logger, type MasterKey, type MaxLengthArray, MemoryStorageAdapter, type MerkleProof, type MerkleRootResponse, type Network, type NoteData, type OnchainMerkleProof, type PendingDeposit, type PendingWithdrawal, type ProofResult, RelayService, RootNotFoundError, ShieldPoolErrors, type ShieldPoolPDAs, type SpendKey, type StorageAdapter, type SwapOptions, type SwapParams, type SwapResult, type Transfer, type TransferOptions, type TransferResult, type TxStatus, type UserFriendlyError, VARIABLE_FEE_RATE, VERSION, type ViewKey, type WalletAdapter, type WithdrawOptions, type WithdrawRegularInputs, type WithdrawSubmissionResult, type WithdrawSwapInputs, areCircuitsAvailable, bigintToBytes32, buildPublicInputsBytes, bytesToHex, calculateFee, calculateRelayFee, cleanupStalePendingOperations, clearPendingDeposits, clearPendingWithdrawals, computeCommitment, computeMerkleRoot, computeNullifier, computeNullifierAsync, computeNullifierSync, computeOutputsHash, computeOutputsHashAsync, computeOutputsHashSync, computeProofForLatestDeposit, computeProofFromChain, computeSwapOutputsHash, computeSwapOutputsHashAsync, computeSwapOutputsHashSync, copyNoteToClipboard, createCloakError, createDepositInstruction, createLogger, deriveSpendKey, deriveViewKey, detectNetworkFromRpcUrl, downloadNote, encodeNoteSimple, encryptNoteForRecipient, exportKeys, exportNote, exportWalletKeys, filterNotesByNetwork, filterWithdrawableNotes, findNoteByCommitment, formatAmount, formatErrorForLogging, formatSol, generateCloakKeys, generateCommitment, generateCommitmentAsync, generateMasterSeed, generateNote, generateNoteFromWallet, generateWithdrawRegularProof, generateWithdrawSwapProof, getAddressExplorerUrl, getDefaultCircuitsPath, getDistributableAmount, getExplorerUrl, getNullifierPDA, getPendingOperationsSummary, getPublicKey, getPublicViewKey, getRecipientAmount, getRpcUrlForNetwork, getShieldPoolPDAs, getSwapStatePDA, getViewKey, hasPendingOperations, hexToBigint, hexToBytes, importKeys, importWalletKeys, isDebugEnabled, isRootNotFoundError, isValidHex, isValidRpcUrl, isValidSolanaAddress, isWithdrawable, keypairToAdapter, loadPendingDeposits, loadPendingWithdrawals, parseAmount, parseError, parseNote, parseTransactionError, poseidonHash, prepareEncryptedOutput, prepareEncryptedOutputForRecipient, proofToBytes, pubkeyToLimbs, randomBytes, readMerkleTreeState, removePendingDeposit, removePendingWithdrawal, savePendingDeposit, savePendingWithdrawal, scanNotesForWallet, sdkLogger, sendTransaction, serializeNote, setDebugMode, signTransaction, splitTo2Limbs, truncate, tryDecryptNote, updateNoteWithDeposit, updatePendingDeposit, updatePendingWithdrawal, validateDepositParams, validateNote, validateOutputsSum, validateTransfers, validateWalletConnected, validateWithdrawableNote, verifyAllCircuits, verifyCircuitIntegrity, withTiming };
package/dist/index.d.ts CHANGED
@@ -1753,6 +1753,7 @@ interface ShieldPoolPDAs {
1753
1753
  merkleTree: PublicKey;
1754
1754
  commitments: PublicKey;
1755
1755
  rootsRing: PublicKey;
1756
+ /** @deprecated Use getNullifierPDA() for the new per-nullifier PDA design */
1756
1757
  nullifierShard: PublicKey;
1757
1758
  treasury: PublicKey;
1758
1759
  }
@@ -1774,6 +1775,30 @@ interface ShieldPoolPDAs {
1774
1775
  * @param mint - Optional mint address (defaults to 32 zero bytes for native SOL)
1775
1776
  */
1776
1777
  declare function getShieldPoolPDAs(programId?: PublicKey, mint?: PublicKey): ShieldPoolPDAs;
1778
+ /**
1779
+ * Derive the nullifier PDA for a specific nullifier hash.
1780
+ *
1781
+ * With the new PDA-per-nullifier design, each nullifier has its own PDA
1782
+ * instead of being stored in a shared shard. The PDA is created when
1783
+ * the nullifier is used during withdrawal.
1784
+ *
1785
+ * Seeds: ["nullifier", nullifier_hash]
1786
+ *
1787
+ * @param nullifier - 32-byte nullifier hash
1788
+ * @param programId - Optional program ID (defaults to CLOAK_PROGRAM_ID)
1789
+ * @returns [PublicKey, bump] - The nullifier PDA and its bump seed
1790
+ */
1791
+ declare function getNullifierPDA(nullifier: Uint8Array | Buffer, programId?: PublicKey): [PublicKey, number];
1792
+ /**
1793
+ * Derive the swap state PDA for a given nullifier.
1794
+ *
1795
+ * Seeds: ["swap_state", nullifier_hash]
1796
+ *
1797
+ * @param nullifier - 32-byte nullifier hash
1798
+ * @param programId - Optional program ID (defaults to CLOAK_PROGRAM_ID)
1799
+ * @returns [PublicKey, bump] - The swap state PDA and its bump seed
1800
+ */
1801
+ declare function getSwapStatePDA(nullifier: Uint8Array | Buffer, programId?: PublicKey): [PublicKey, number];
1777
1802
 
1778
1803
  /**
1779
1804
  * On-chain Merkle proof computation
@@ -1838,6 +1863,11 @@ declare function computeProofForLatestDeposit(connection: Connection, merkleTree
1838
1863
  * as it doesn't require a backend prover service.
1839
1864
  */
1840
1865
 
1866
+ /**
1867
+ * Default URL for fetching circuit artifacts
1868
+ * These are served from the Cloak web app at https://cloak.ag
1869
+ */
1870
+ declare const DEFAULT_CIRCUITS_URL = "https://www.cloak.ag/circuits";
1841
1871
  interface WithdrawRegularInputs {
1842
1872
  root: bigint;
1843
1873
  nullifier: bigint;
@@ -1898,6 +1928,23 @@ declare function generateWithdrawRegularProof(inputs: WithdrawRegularInputs, cir
1898
1928
  * @param circuitsPath - Path or URL to circuits directory. In browser, use URL like '/circuits' or full URL.
1899
1929
  */
1900
1930
  declare function generateWithdrawSwapProof(inputs: WithdrawSwapInputs, circuitsPath: string): Promise<ProofResult>;
1931
+ /**
1932
+ * Check if circuits are available at the given path or URL
1933
+ * Supports both local file paths and remote URLs
1934
+ *
1935
+ * Note: For remote URLs, this returns true without checking (snarkjs will handle loading).
1936
+ * For local paths, it checks if the files exist on disk.
1937
+ */
1938
+ declare function areCircuitsAvailable(circuitsPath: string): Promise<boolean>;
1939
+ /**
1940
+ * Get default circuits path or URL
1941
+ *
1942
+ * Priority:
1943
+ * 1. CIRCUITS_PATH environment variable (if set)
1944
+ * 2. Local file paths (if available)
1945
+ * 3. Default remote URL (https://cloak.ag/circuits)
1946
+ */
1947
+ declare function getDefaultCircuitsPath(): Promise<string>;
1901
1948
  /**
1902
1949
  * Expected circuit hashes for verification
1903
1950
  * These are computed from the verification key files to ensure circuits match on-chain vkeys
@@ -2076,4 +2123,4 @@ declare function cleanupStalePendingOperations(maxAgeMs?: number): {
2076
2123
 
2077
2124
  declare const VERSION = "1.0.0";
2078
2125
 
2079
- export { CLOAK_PROGRAM_ID, type CircuitVerificationResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, CloakSDK, type DepositInstructionParams, type DepositOptions, type DepositResult, type DepositStatus, EXPECTED_CIRCUIT_HASHES, type EncryptedNote, type ErrorCategory, FIXED_FEE_LAMPORTS, type Groth16Proof, LAMPORTS_PER_SOL, LocalStorageAdapter, type LogLevel, type Logger, type MasterKey, type MaxLengthArray, MemoryStorageAdapter, type MerkleProof, type MerkleRootResponse, type Network, type NoteData, type OnchainMerkleProof, type PendingDeposit, type PendingWithdrawal, type ProofResult, RelayService, RootNotFoundError, ShieldPoolErrors, type ShieldPoolPDAs, type SpendKey, type StorageAdapter, type SwapOptions, type SwapParams, type SwapResult, type Transfer, type TransferOptions, type TransferResult, type TxStatus, type UserFriendlyError, VARIABLE_FEE_RATE, VERSION, type ViewKey, type WalletAdapter, type WithdrawOptions, type WithdrawRegularInputs, type WithdrawSubmissionResult, type WithdrawSwapInputs, bigintToBytes32, buildPublicInputsBytes, bytesToHex, calculateFee, calculateRelayFee, cleanupStalePendingOperations, clearPendingDeposits, clearPendingWithdrawals, computeCommitment, computeMerkleRoot, computeNullifier, computeNullifierAsync, computeNullifierSync, computeOutputsHash, computeOutputsHashAsync, computeOutputsHashSync, computeProofForLatestDeposit, computeProofFromChain, computeSwapOutputsHash, computeSwapOutputsHashAsync, computeSwapOutputsHashSync, copyNoteToClipboard, createCloakError, createDepositInstruction, createLogger, deriveSpendKey, deriveViewKey, detectNetworkFromRpcUrl, downloadNote, encodeNoteSimple, encryptNoteForRecipient, exportKeys, exportNote, exportWalletKeys, filterNotesByNetwork, filterWithdrawableNotes, findNoteByCommitment, formatAmount, formatErrorForLogging, formatSol, generateCloakKeys, generateCommitment, generateCommitmentAsync, generateMasterSeed, generateNote, generateNoteFromWallet, generateWithdrawRegularProof, generateWithdrawSwapProof, getAddressExplorerUrl, getDistributableAmount, getExplorerUrl, getPendingOperationsSummary, getPublicKey, getPublicViewKey, getRecipientAmount, getRpcUrlForNetwork, getShieldPoolPDAs, getViewKey, hasPendingOperations, hexToBigint, hexToBytes, importKeys, importWalletKeys, isDebugEnabled, isRootNotFoundError, isValidHex, isValidRpcUrl, isValidSolanaAddress, isWithdrawable, keypairToAdapter, loadPendingDeposits, loadPendingWithdrawals, parseAmount, parseError, parseNote, parseTransactionError, poseidonHash, prepareEncryptedOutput, prepareEncryptedOutputForRecipient, proofToBytes, pubkeyToLimbs, randomBytes, readMerkleTreeState, removePendingDeposit, removePendingWithdrawal, savePendingDeposit, savePendingWithdrawal, scanNotesForWallet, sdkLogger, sendTransaction, serializeNote, setDebugMode, signTransaction, splitTo2Limbs, truncate, tryDecryptNote, updateNoteWithDeposit, updatePendingDeposit, updatePendingWithdrawal, validateDepositParams, validateNote, validateOutputsSum, validateTransfers, validateWalletConnected, validateWithdrawableNote, verifyAllCircuits, verifyCircuitIntegrity, withTiming };
2126
+ export { CLOAK_PROGRAM_ID, type CircuitVerificationResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, CloakSDK, DEFAULT_CIRCUITS_URL, type DepositInstructionParams, type DepositOptions, type DepositResult, type DepositStatus, EXPECTED_CIRCUIT_HASHES, type EncryptedNote, type ErrorCategory, FIXED_FEE_LAMPORTS, type Groth16Proof, LAMPORTS_PER_SOL, LocalStorageAdapter, type LogLevel, type Logger, type MasterKey, type MaxLengthArray, MemoryStorageAdapter, type MerkleProof, type MerkleRootResponse, type Network, type NoteData, type OnchainMerkleProof, type PendingDeposit, type PendingWithdrawal, type ProofResult, RelayService, RootNotFoundError, ShieldPoolErrors, type ShieldPoolPDAs, type SpendKey, type StorageAdapter, type SwapOptions, type SwapParams, type SwapResult, type Transfer, type TransferOptions, type TransferResult, type TxStatus, type UserFriendlyError, VARIABLE_FEE_RATE, VERSION, type ViewKey, type WalletAdapter, type WithdrawOptions, type WithdrawRegularInputs, type WithdrawSubmissionResult, type WithdrawSwapInputs, areCircuitsAvailable, bigintToBytes32, buildPublicInputsBytes, bytesToHex, calculateFee, calculateRelayFee, cleanupStalePendingOperations, clearPendingDeposits, clearPendingWithdrawals, computeCommitment, computeMerkleRoot, computeNullifier, computeNullifierAsync, computeNullifierSync, computeOutputsHash, computeOutputsHashAsync, computeOutputsHashSync, computeProofForLatestDeposit, computeProofFromChain, computeSwapOutputsHash, computeSwapOutputsHashAsync, computeSwapOutputsHashSync, copyNoteToClipboard, createCloakError, createDepositInstruction, createLogger, deriveSpendKey, deriveViewKey, detectNetworkFromRpcUrl, downloadNote, encodeNoteSimple, encryptNoteForRecipient, exportKeys, exportNote, exportWalletKeys, filterNotesByNetwork, filterWithdrawableNotes, findNoteByCommitment, formatAmount, formatErrorForLogging, formatSol, generateCloakKeys, generateCommitment, generateCommitmentAsync, generateMasterSeed, generateNote, generateNoteFromWallet, generateWithdrawRegularProof, generateWithdrawSwapProof, getAddressExplorerUrl, getDefaultCircuitsPath, getDistributableAmount, getExplorerUrl, getNullifierPDA, getPendingOperationsSummary, getPublicKey, getPublicViewKey, getRecipientAmount, getRpcUrlForNetwork, getShieldPoolPDAs, getSwapStatePDA, getViewKey, hasPendingOperations, hexToBigint, hexToBytes, importKeys, importWalletKeys, isDebugEnabled, isRootNotFoundError, isValidHex, isValidRpcUrl, isValidSolanaAddress, isWithdrawable, keypairToAdapter, loadPendingDeposits, loadPendingWithdrawals, parseAmount, parseError, parseNote, parseTransactionError, poseidonHash, prepareEncryptedOutput, prepareEncryptedOutputForRecipient, proofToBytes, pubkeyToLimbs, randomBytes, readMerkleTreeState, removePendingDeposit, removePendingWithdrawal, savePendingDeposit, savePendingWithdrawal, scanNotesForWallet, sdkLogger, sendTransaction, serializeNote, setDebugMode, signTransaction, splitTo2Limbs, truncate, tryDecryptNote, updateNoteWithDeposit, updatePendingDeposit, updatePendingWithdrawal, validateDepositParams, validateNote, validateOutputsSum, validateTransfers, validateWalletConnected, validateWithdrawableNote, verifyAllCircuits, verifyCircuitIntegrity, withTiming };