@hula-privacy/mixer 0.5.0 → 1.0.0

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
@@ -1,4 +1,4 @@
1
- import { PublicKey, TransactionInstruction, Keypair, Connection } from '@solana/web3.js';
1
+ import { PublicKey, TransactionInstruction, Keypair, Connection, Transaction, VersionedTransaction } from '@solana/web3.js';
2
2
  import { BN, Program } from '@coral-xyz/anchor';
3
3
  import { Poseidon } from 'circomlibjs';
4
4
 
@@ -341,6 +341,18 @@ declare function toAnchorPublicInputs(builtTx: BuiltTransaction): {
341
341
  * High-level wallet abstraction that manages keys, UTXOs, and syncing
342
342
  */
343
343
 
344
+ /**
345
+ * Minimal wallet interface compatible with both Keypair and wallet adapters
346
+ */
347
+ interface WalletAdapter {
348
+ publicKey: PublicKey;
349
+ signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
350
+ signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
351
+ }
352
+ /**
353
+ * Create a wallet adapter from a Keypair (for Node.js/CLI usage)
354
+ */
355
+ declare function createKeypairWalletAdapter(keypair: Keypair): WalletAdapter;
344
356
  /**
345
357
  * Hula Privacy Wallet
346
358
  *
@@ -351,7 +363,7 @@ declare class HulaWallet {
351
363
  private relayerUrl;
352
364
  private programId;
353
365
  private keys;
354
- private signer?;
366
+ private walletAdapter?;
355
367
  private utxos;
356
368
  private lastSyncedSlot;
357
369
  private initialized;
@@ -405,13 +417,17 @@ declare class HulaWallet {
405
417
  */
406
418
  getConnection(): Connection;
407
419
  /**
408
- * Get the signer keypair (if available)
420
+ * Get the wallet adapter (if available)
409
421
  */
410
- getSigner(): Keypair | undefined;
422
+ getWalletAdapter(): WalletAdapter | undefined;
411
423
  /**
412
- * Set the signer keypair
424
+ * Set the wallet adapter (for browser usage with Phantom etc.)
413
425
  */
414
- setSigner(signer: Keypair): void;
426
+ setWalletAdapter(adapter: WalletAdapter): void;
427
+ /**
428
+ * Get the program ID
429
+ */
430
+ getProgramId(): PublicKey;
415
431
  /**
416
432
  * Sync wallet with relayer
417
433
  *
@@ -438,6 +454,10 @@ declare class HulaWallet {
438
454
  * Export UTXOs for backup
439
455
  */
440
456
  exportUTXOs(): SerializableUTXO[];
457
+ /**
458
+ * Build and submit a transaction using the wallet adapter
459
+ */
460
+ private submitTransactionWithAdapter;
441
461
  /**
442
462
  * Deposit tokens into the privacy pool
443
463
  *
@@ -766,6 +786,7 @@ declare function scanNotesForUTXOs(notes: Array<{
766
786
  declare function syncUTXOs(walletKeys: WalletKeys, existingUTXOs: SerializableUTXO[], relayerUrl?: string, afterSlot?: string): Promise<{
767
787
  newUTXOs: SerializableUTXO[];
768
788
  spentUTXOs: string[];
789
+ lastSlot: string | null;
769
790
  }>;
770
791
  /**
771
792
  * Select UTXOs for spending (greedy algorithm)
@@ -835,22 +856,26 @@ declare function getCurrentTreeIndex(relayerUrl?: string): Promise<number>;
835
856
  /**
836
857
  * ZK Proof generation utilities
837
858
  *
838
- * Uses snarkjs to generate Groth16 proofs for the transaction circuit
859
+ * Uses snarkjs to generate Groth16 proofs for the transaction circuit.
860
+ * Supports both browser (using URLs) and Node.js (using file paths) environments.
839
861
  */
840
862
 
841
863
  /**
842
- * Set circuit file paths
864
+ * Set circuit file paths (Node.js) or URLs (browser)
865
+ *
866
+ * In browser: use URLs like "/circuits/transaction.wasm"
867
+ * In Node.js: use file paths like "/path/to/transaction.wasm"
843
868
  */
844
869
  declare function setCircuitPaths(wasmPath: string, zkeyPath: string): void;
845
870
  /**
846
- * Get circuit file paths (with fallback to default locations)
871
+ * Get circuit file paths/URLs
847
872
  */
848
873
  declare function getCircuitPaths(): {
849
874
  wasmPath: string;
850
875
  zkeyPath: string;
851
876
  };
852
877
  /**
853
- * Verify circuit files exist
878
+ * Verify circuit files exist (only works in Node.js)
854
879
  */
855
880
  declare function verifyCircuitFiles(): void;
856
881
  /**
@@ -864,19 +889,19 @@ declare function parseProof(proofJson: {
864
889
  pi_c: string[];
865
890
  }): Uint8Array;
866
891
  /**
867
- * Generate ZK proof using snarkjs CLI (subprocess for Bun compatibility)
892
+ * Generate ZK proof using snarkjs
868
893
  *
869
- * This spawns snarkjs as a subprocess to avoid web-worker issues with Bun.
870
- * Works in both Node.js and Bun environments.
894
+ * Works in both browser and Node.js environments:
895
+ * - Browser: loads WASM and zkey from URLs, generates proof in-memory
896
+ * - Node.js: uses file paths for WASM and zkey
871
897
  */
872
898
  declare function generateProof(circuitInputs: CircuitInputs): Promise<{
873
899
  proof: Uint8Array;
874
900
  publicSignals: string[];
875
901
  }>;
876
902
  /**
877
- * Generate proof using snarkjs in-memory (for Node.js environments)
878
- *
879
- * This is more efficient but may not work in all environments.
903
+ * Generate proof using snarkjs in-memory
904
+ * Alias for generateProof for backwards compatibility
880
905
  */
881
906
  declare function generateProofInMemory(circuitInputs: CircuitInputs): Promise<{
882
907
  proof: Uint8Array;
@@ -928,4 +953,4 @@ declare function getVaultPDA(mint: PublicKey): [PublicKey, number];
928
953
  */
929
954
  declare function getNullifierPDA(nullifier: Uint8Array): [PublicKey, number];
930
955
 
931
- export { type BuiltTransaction, type CircuitInputs, DOMAIN_ENCRYPTION, DOMAIN_NULLIFIER, DOMAIN_OWNER, DOMAIN_VIEWING, type EncryptedNote, FIELD_PRIME, type HulaSDKConfig, HulaWallet, type LeafData, MAX_LEAVES, MERKLE_TREE_DEPTH, MERKLE_TREE_SEED, type MerklePath, NULLIFIER_SEED, NUM_INPUT_UTXOS, NUM_OUTPUT_UTXOS, type NoteData, type OutputSpec, POOL_SEED, PROGRAM_ID, PROOF_SIZE, type PaginatedResponse, type PoolData, type PublicInputs, RelayerClient, type SerializableUTXO, type StatsData, type SyncProgress, type SyncResult, TOKEN_2022_PROGRAM_ID, type TransactionData, type TransactionRequest, type TreeData, type UTXO, VAULT_SEED, type WalletKeys, bigIntToBytes, bigIntToBytes32, buildTransaction, buildTransactionAccounts, bytesToBigInt, bytesToHex, calculateBalance, computeCommitment, computeMerklePathFromLeaves, computeMerkleRoot, computeNullifier, computeNullifierFromKeys, computeZeros, createDummyUTXO, createUTXO, decryptNote, deriveKeys, deriveSpendingKeyFromSignature, deserializeEncryptedNote, deserializeUTXO, encryptNote, fetchMerklePath, fetchMerkleRoot, formatCommitment, generateProof, generateProofInMemory, generateSpendingKey, getCircuitPaths, getCurrentTreeIndex, getEmptyTreeRoot, getKeyDerivationMessage, getMerkleTreePDA, getNextLeafIndex, getNullifierPDA, getPoolPDA, getPoseidon, getRelayerClient, getVaultPDA, getZeroAtLevel, hexToBytes, initHulaSDK, initPoseidon, isPoseidonInitialized, parseProof, poseidonHash, pubkeyToBigInt, scanNotesForUTXOs, selectUTXOs, serializeEncryptedNote, serializeUTXO, setCircuitPaths, setDefaultRelayerUrl, syncUTXOs, toAnchorPublicInputs, verifyCircuitFiles, verifyMerklePath };
956
+ export { type BuiltTransaction, type CircuitInputs, DOMAIN_ENCRYPTION, DOMAIN_NULLIFIER, DOMAIN_OWNER, DOMAIN_VIEWING, type EncryptedNote, FIELD_PRIME, type HulaSDKConfig, HulaWallet, type LeafData, MAX_LEAVES, MERKLE_TREE_DEPTH, MERKLE_TREE_SEED, type MerklePath, NULLIFIER_SEED, NUM_INPUT_UTXOS, NUM_OUTPUT_UTXOS, type NoteData, type OutputSpec, POOL_SEED, PROGRAM_ID, PROOF_SIZE, type PaginatedResponse, type PoolData, type PublicInputs, RelayerClient, type SerializableUTXO, type StatsData, type SyncProgress, type SyncResult, TOKEN_2022_PROGRAM_ID, type TransactionData, type TransactionRequest, type TreeData, type UTXO, VAULT_SEED, type WalletAdapter, type WalletKeys, bigIntToBytes, bigIntToBytes32, buildTransaction, buildTransactionAccounts, bytesToBigInt, bytesToHex, calculateBalance, computeCommitment, computeMerklePathFromLeaves, computeMerkleRoot, computeNullifier, computeNullifierFromKeys, computeZeros, createDummyUTXO, createKeypairWalletAdapter, createUTXO, decryptNote, deriveKeys, deriveSpendingKeyFromSignature, deserializeEncryptedNote, deserializeUTXO, encryptNote, fetchMerklePath, fetchMerkleRoot, formatCommitment, generateProof, generateProofInMemory, generateSpendingKey, getCircuitPaths, getCurrentTreeIndex, getEmptyTreeRoot, getKeyDerivationMessage, getMerkleTreePDA, getNextLeafIndex, getNullifierPDA, getPoolPDA, getPoseidon, getRelayerClient, getVaultPDA, getZeroAtLevel, hexToBytes, initHulaSDK, initPoseidon, isPoseidonInitialized, parseProof, poseidonHash, pubkeyToBigInt, scanNotesForUTXOs, selectUTXOs, serializeEncryptedNote, serializeUTXO, setCircuitPaths, setDefaultRelayerUrl, syncUTXOs, toAnchorPublicInputs, verifyCircuitFiles, verifyMerklePath };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PublicKey, TransactionInstruction, Keypair, Connection } from '@solana/web3.js';
1
+ import { PublicKey, TransactionInstruction, Keypair, Connection, Transaction, VersionedTransaction } from '@solana/web3.js';
2
2
  import { BN, Program } from '@coral-xyz/anchor';
3
3
  import { Poseidon } from 'circomlibjs';
4
4
 
@@ -341,6 +341,18 @@ declare function toAnchorPublicInputs(builtTx: BuiltTransaction): {
341
341
  * High-level wallet abstraction that manages keys, UTXOs, and syncing
342
342
  */
343
343
 
344
+ /**
345
+ * Minimal wallet interface compatible with both Keypair and wallet adapters
346
+ */
347
+ interface WalletAdapter {
348
+ publicKey: PublicKey;
349
+ signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
350
+ signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
351
+ }
352
+ /**
353
+ * Create a wallet adapter from a Keypair (for Node.js/CLI usage)
354
+ */
355
+ declare function createKeypairWalletAdapter(keypair: Keypair): WalletAdapter;
344
356
  /**
345
357
  * Hula Privacy Wallet
346
358
  *
@@ -351,7 +363,7 @@ declare class HulaWallet {
351
363
  private relayerUrl;
352
364
  private programId;
353
365
  private keys;
354
- private signer?;
366
+ private walletAdapter?;
355
367
  private utxos;
356
368
  private lastSyncedSlot;
357
369
  private initialized;
@@ -405,13 +417,17 @@ declare class HulaWallet {
405
417
  */
406
418
  getConnection(): Connection;
407
419
  /**
408
- * Get the signer keypair (if available)
420
+ * Get the wallet adapter (if available)
409
421
  */
410
- getSigner(): Keypair | undefined;
422
+ getWalletAdapter(): WalletAdapter | undefined;
411
423
  /**
412
- * Set the signer keypair
424
+ * Set the wallet adapter (for browser usage with Phantom etc.)
413
425
  */
414
- setSigner(signer: Keypair): void;
426
+ setWalletAdapter(adapter: WalletAdapter): void;
427
+ /**
428
+ * Get the program ID
429
+ */
430
+ getProgramId(): PublicKey;
415
431
  /**
416
432
  * Sync wallet with relayer
417
433
  *
@@ -438,6 +454,10 @@ declare class HulaWallet {
438
454
  * Export UTXOs for backup
439
455
  */
440
456
  exportUTXOs(): SerializableUTXO[];
457
+ /**
458
+ * Build and submit a transaction using the wallet adapter
459
+ */
460
+ private submitTransactionWithAdapter;
441
461
  /**
442
462
  * Deposit tokens into the privacy pool
443
463
  *
@@ -766,6 +786,7 @@ declare function scanNotesForUTXOs(notes: Array<{
766
786
  declare function syncUTXOs(walletKeys: WalletKeys, existingUTXOs: SerializableUTXO[], relayerUrl?: string, afterSlot?: string): Promise<{
767
787
  newUTXOs: SerializableUTXO[];
768
788
  spentUTXOs: string[];
789
+ lastSlot: string | null;
769
790
  }>;
770
791
  /**
771
792
  * Select UTXOs for spending (greedy algorithm)
@@ -835,22 +856,26 @@ declare function getCurrentTreeIndex(relayerUrl?: string): Promise<number>;
835
856
  /**
836
857
  * ZK Proof generation utilities
837
858
  *
838
- * Uses snarkjs to generate Groth16 proofs for the transaction circuit
859
+ * Uses snarkjs to generate Groth16 proofs for the transaction circuit.
860
+ * Supports both browser (using URLs) and Node.js (using file paths) environments.
839
861
  */
840
862
 
841
863
  /**
842
- * Set circuit file paths
864
+ * Set circuit file paths (Node.js) or URLs (browser)
865
+ *
866
+ * In browser: use URLs like "/circuits/transaction.wasm"
867
+ * In Node.js: use file paths like "/path/to/transaction.wasm"
843
868
  */
844
869
  declare function setCircuitPaths(wasmPath: string, zkeyPath: string): void;
845
870
  /**
846
- * Get circuit file paths (with fallback to default locations)
871
+ * Get circuit file paths/URLs
847
872
  */
848
873
  declare function getCircuitPaths(): {
849
874
  wasmPath: string;
850
875
  zkeyPath: string;
851
876
  };
852
877
  /**
853
- * Verify circuit files exist
878
+ * Verify circuit files exist (only works in Node.js)
854
879
  */
855
880
  declare function verifyCircuitFiles(): void;
856
881
  /**
@@ -864,19 +889,19 @@ declare function parseProof(proofJson: {
864
889
  pi_c: string[];
865
890
  }): Uint8Array;
866
891
  /**
867
- * Generate ZK proof using snarkjs CLI (subprocess for Bun compatibility)
892
+ * Generate ZK proof using snarkjs
868
893
  *
869
- * This spawns snarkjs as a subprocess to avoid web-worker issues with Bun.
870
- * Works in both Node.js and Bun environments.
894
+ * Works in both browser and Node.js environments:
895
+ * - Browser: loads WASM and zkey from URLs, generates proof in-memory
896
+ * - Node.js: uses file paths for WASM and zkey
871
897
  */
872
898
  declare function generateProof(circuitInputs: CircuitInputs): Promise<{
873
899
  proof: Uint8Array;
874
900
  publicSignals: string[];
875
901
  }>;
876
902
  /**
877
- * Generate proof using snarkjs in-memory (for Node.js environments)
878
- *
879
- * This is more efficient but may not work in all environments.
903
+ * Generate proof using snarkjs in-memory
904
+ * Alias for generateProof for backwards compatibility
880
905
  */
881
906
  declare function generateProofInMemory(circuitInputs: CircuitInputs): Promise<{
882
907
  proof: Uint8Array;
@@ -928,4 +953,4 @@ declare function getVaultPDA(mint: PublicKey): [PublicKey, number];
928
953
  */
929
954
  declare function getNullifierPDA(nullifier: Uint8Array): [PublicKey, number];
930
955
 
931
- export { type BuiltTransaction, type CircuitInputs, DOMAIN_ENCRYPTION, DOMAIN_NULLIFIER, DOMAIN_OWNER, DOMAIN_VIEWING, type EncryptedNote, FIELD_PRIME, type HulaSDKConfig, HulaWallet, type LeafData, MAX_LEAVES, MERKLE_TREE_DEPTH, MERKLE_TREE_SEED, type MerklePath, NULLIFIER_SEED, NUM_INPUT_UTXOS, NUM_OUTPUT_UTXOS, type NoteData, type OutputSpec, POOL_SEED, PROGRAM_ID, PROOF_SIZE, type PaginatedResponse, type PoolData, type PublicInputs, RelayerClient, type SerializableUTXO, type StatsData, type SyncProgress, type SyncResult, TOKEN_2022_PROGRAM_ID, type TransactionData, type TransactionRequest, type TreeData, type UTXO, VAULT_SEED, type WalletKeys, bigIntToBytes, bigIntToBytes32, buildTransaction, buildTransactionAccounts, bytesToBigInt, bytesToHex, calculateBalance, computeCommitment, computeMerklePathFromLeaves, computeMerkleRoot, computeNullifier, computeNullifierFromKeys, computeZeros, createDummyUTXO, createUTXO, decryptNote, deriveKeys, deriveSpendingKeyFromSignature, deserializeEncryptedNote, deserializeUTXO, encryptNote, fetchMerklePath, fetchMerkleRoot, formatCommitment, generateProof, generateProofInMemory, generateSpendingKey, getCircuitPaths, getCurrentTreeIndex, getEmptyTreeRoot, getKeyDerivationMessage, getMerkleTreePDA, getNextLeafIndex, getNullifierPDA, getPoolPDA, getPoseidon, getRelayerClient, getVaultPDA, getZeroAtLevel, hexToBytes, initHulaSDK, initPoseidon, isPoseidonInitialized, parseProof, poseidonHash, pubkeyToBigInt, scanNotesForUTXOs, selectUTXOs, serializeEncryptedNote, serializeUTXO, setCircuitPaths, setDefaultRelayerUrl, syncUTXOs, toAnchorPublicInputs, verifyCircuitFiles, verifyMerklePath };
956
+ export { type BuiltTransaction, type CircuitInputs, DOMAIN_ENCRYPTION, DOMAIN_NULLIFIER, DOMAIN_OWNER, DOMAIN_VIEWING, type EncryptedNote, FIELD_PRIME, type HulaSDKConfig, HulaWallet, type LeafData, MAX_LEAVES, MERKLE_TREE_DEPTH, MERKLE_TREE_SEED, type MerklePath, NULLIFIER_SEED, NUM_INPUT_UTXOS, NUM_OUTPUT_UTXOS, type NoteData, type OutputSpec, POOL_SEED, PROGRAM_ID, PROOF_SIZE, type PaginatedResponse, type PoolData, type PublicInputs, RelayerClient, type SerializableUTXO, type StatsData, type SyncProgress, type SyncResult, TOKEN_2022_PROGRAM_ID, type TransactionData, type TransactionRequest, type TreeData, type UTXO, VAULT_SEED, type WalletAdapter, type WalletKeys, bigIntToBytes, bigIntToBytes32, buildTransaction, buildTransactionAccounts, bytesToBigInt, bytesToHex, calculateBalance, computeCommitment, computeMerklePathFromLeaves, computeMerkleRoot, computeNullifier, computeNullifierFromKeys, computeZeros, createDummyUTXO, createKeypairWalletAdapter, createUTXO, decryptNote, deriveKeys, deriveSpendingKeyFromSignature, deserializeEncryptedNote, deserializeUTXO, encryptNote, fetchMerklePath, fetchMerkleRoot, formatCommitment, generateProof, generateProofInMemory, generateSpendingKey, getCircuitPaths, getCurrentTreeIndex, getEmptyTreeRoot, getKeyDerivationMessage, getMerkleTreePDA, getNextLeafIndex, getNullifierPDA, getPoolPDA, getPoseidon, getRelayerClient, getVaultPDA, getZeroAtLevel, hexToBytes, initHulaSDK, initPoseidon, isPoseidonInitialized, parseProof, poseidonHash, pubkeyToBigInt, scanNotesForUTXOs, selectUTXOs, serializeEncryptedNote, serializeUTXO, setCircuitPaths, setDefaultRelayerUrl, syncUTXOs, toAnchorPublicInputs, verifyCircuitFiles, verifyMerklePath };