@aintivirus-ai/mixer-sdk 1.0.6 → 1.0.8

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.
Files changed (67) hide show
  1. package/README.md +6 -15
  2. package/dist/config.d.ts +37 -0
  3. package/dist/config.js +95 -0
  4. package/dist/createSDK.d.ts +29 -0
  5. package/dist/createSDK.js +48 -0
  6. package/dist/errors.d.ts +46 -0
  7. package/dist/errors.js +72 -0
  8. package/dist/evm/abis/AintiVirusFactory.json +1463 -0
  9. package/dist/evm/abis/AintiVirusPayment.json +677 -0
  10. package/dist/evm/abis/AintiVirusStaking.json +586 -0
  11. package/dist/evm/abis/WETHGateway.json +137 -0
  12. package/dist/evm/index.d.ts +222 -22
  13. package/dist/evm/index.js +681 -246
  14. package/dist/evm/multicall.d.ts +24 -0
  15. package/dist/evm/multicall.js +43 -0
  16. package/dist/evm/subgraph/client.d.ts +49 -21
  17. package/dist/evm/subgraph/client.js +177 -80
  18. package/dist/evm/subgraph/queries.d.ts +16 -11
  19. package/dist/evm/subgraph/queries.js +134 -40
  20. package/dist/evm/subgraph/types.d.ts +72 -28
  21. package/dist/evm/subgraph/utils.d.ts +9 -2
  22. package/dist/evm/subgraph/utils.js +21 -4
  23. package/dist/hooks/context.d.ts +48 -0
  24. package/dist/hooks/context.js +115 -0
  25. package/dist/hooks/index.d.ts +15 -23
  26. package/dist/hooks/index.js +17 -23
  27. package/dist/hooks/useAdmin.d.ts +49 -35
  28. package/dist/hooks/useAdmin.js +99 -163
  29. package/dist/hooks/useAintiVirus.d.ts +9 -27
  30. package/dist/hooks/useAintiVirus.js +55 -125
  31. package/dist/hooks/useClaim.d.ts +6 -19
  32. package/dist/hooks/useClaim.js +24 -67
  33. package/dist/hooks/useDeploy.d.ts +11 -22
  34. package/dist/hooks/useDeploy.js +18 -82
  35. package/dist/hooks/useDeposit.d.ts +24 -21
  36. package/dist/hooks/useDeposit.js +47 -77
  37. package/dist/hooks/useEVMReady.d.ts +19 -0
  38. package/dist/hooks/useEVMReady.js +42 -0
  39. package/dist/hooks/usePayment.d.ts +37 -0
  40. package/dist/hooks/usePayment.js +75 -0
  41. package/dist/hooks/useStake.d.ts +6 -19
  42. package/dist/hooks/useStake.js +28 -73
  43. package/dist/hooks/useView.d.ts +6 -19
  44. package/dist/hooks/useView.js +29 -76
  45. package/dist/hooks/useWithdraw.d.ts +24 -23
  46. package/dist/hooks/useWithdraw.js +26 -99
  47. package/dist/hooks/useWithdrawByGiftCard.d.ts +34 -0
  48. package/dist/hooks/useWithdrawByGiftCard.js +44 -0
  49. package/dist/hooks/utils.d.ts +4 -2
  50. package/dist/hooks/utils.js +82 -10
  51. package/dist/index.d.ts +13 -14
  52. package/dist/index.js +58 -54
  53. package/dist/sdkConfig.d.ts +14 -0
  54. package/dist/sdkConfig.js +17 -0
  55. package/dist/solana/index.d.ts +1 -0
  56. package/dist/solana/index.js +24 -23
  57. package/dist/types/index.d.ts +63 -7
  58. package/dist/utils/circuit.d.ts +14 -0
  59. package/dist/utils/circuit.js +17 -0
  60. package/dist/utils/crypto.d.ts +2 -0
  61. package/dist/utils/crypto.js +7 -4
  62. package/dist/utils/proof.d.ts +11 -7
  63. package/dist/utils/proof.js +46 -37
  64. package/dist/utils/withdrawProof.d.ts +19 -0
  65. package/dist/utils/withdrawProof.js +32 -0
  66. package/dist/utils/witness_calculator.js +381 -0
  67. package/package.json +82 -69
package/README.md CHANGED
@@ -88,7 +88,7 @@ const signer = await provider.getSigner();
88
88
  const sdk = new AintiVirusEVM(
89
89
  "0x...", // Factory contract address
90
90
  "0x...", // Token contract address
91
- signer
91
+ signer,
92
92
  );
93
93
 
94
94
  // Deposit ETH
@@ -134,7 +134,7 @@ const sdk = new AintiVirusSolana(
134
134
  "AinTiV1ru5Staking1111111111111111111111111111", // Staking program ID
135
135
  wallet,
136
136
  connection,
137
- "TokenMintAddress..." // Optional: Token mint address
137
+ "TokenMintAddress...", // Optional: Token mint address
138
138
  );
139
139
 
140
140
  // Deposit SOL
@@ -224,11 +224,7 @@ import {
224
224
  AssetMode,
225
225
  } from "@aintivirus-ai/mixer-sdk/hooks";
226
226
 
227
- const { withdraw, isEVMReady } = useWithdraw({
228
- evm: {
229
- factoryAddress: "0x...",
230
- },
231
- });
227
+ const { withdraw, isEVMReady } = useWithdraw();
232
228
 
233
229
  // Withdraw
234
230
  await withdraw(ChainType.EVM, proof, amount, AssetMode.ETH);
@@ -495,17 +491,14 @@ const commitment = computeCommitment(secret, nullifier);
495
491
 
496
492
  ### Generating Withdrawal Proof
497
493
 
494
+ Set `CIRCUIT_WASM` and `CIRCUIT_ZKEY` in your environment. Values may be HTTPS URLs (fetched at proof time) or base64-encoded file content.
495
+
498
496
  ```typescript
499
497
  import {
500
498
  generateWithdrawalProofFromData,
501
499
  buildMerkleTree,
502
500
  getMerklePath,
503
501
  } from "@aintivirus-ai/mixer-sdk";
504
- import { readFileSync } from "fs";
505
-
506
- // Load circuit files (from your build directory)
507
- const circuitWasm = readFileSync("path/to/mixer.wasm");
508
- const circuitZkey = readFileSync("path/to/mixer.zkey");
509
502
 
510
503
  // Get all commitments from deposit events
511
504
  const commitments = [
@@ -519,14 +512,12 @@ const root = BigInt(tree.root);
519
512
  // Get merkle path for your commitment
520
513
  const path = getMerklePath(tree, commitment);
521
514
 
522
- // Generate proof
515
+ // Generate proof (circuit files loaded from env)
523
516
  const proof = await generateWithdrawalProofFromData({
524
517
  secret,
525
518
  nullifier,
526
519
  recipient: "0x...", // Recipient address
527
520
  commitments,
528
- circuitWasm,
529
- circuitZkey,
530
521
  });
531
522
 
532
523
  // Withdraw
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Config normalization and chain resolution for multi-chain (EVM + Solana) and legacy single-chain.
3
+ * Solana config is still normalized and exposed; SDK/hooks Solana integration is disabled elsewhere.
4
+ */
5
+ import type { SDKConfig, MixerSDKConfig, EvmChainConfig, SolanaChainConfig } from "./types";
6
+ /** Normalized config: always has chains.evm and chains.solana as records */
7
+ export interface NormalizedMixerConfig {
8
+ chains: {
9
+ evm: Record<number, EvmChainConfig>;
10
+ solana: Record<string, SolanaChainConfig>;
11
+ };
12
+ useMulticall?: boolean;
13
+ }
14
+ /**
15
+ * Normalize SDK config to canonical shape (chains.evm / chains.solana).
16
+ * Legacy flat evm/solana are converted to single-entry chains so one code path handles both.
17
+ */
18
+ export declare function normalizeConfig(config: SDKConfig | MixerSDKConfig): NormalizedMixerConfig;
19
+ /**
20
+ * Get EVM chain config for the given chainId.
21
+ * For legacy single-chain config, returns the single evm config for any chainId.
22
+ * Optimized for many EVM networks: each chainId is looked up in config.chains.evm.
23
+ */
24
+ export declare function getEvmChainConfig(config: SDKConfig | MixerSDKConfig | NormalizedMixerConfig, chainId: number): EvmChainConfig | undefined;
25
+ /**
26
+ * Get Solana chain config for the given network id (e.g. "mainnet", "devnet").
27
+ * For legacy single-chain config, returns the single solana config for any network.
28
+ */
29
+ export declare function getSolanaChainConfig(config: SDKConfig | MixerSDKConfig | NormalizedMixerConfig, network: string): SolanaChainConfig | undefined;
30
+ /**
31
+ * Return all EVM chain IDs present in the config.
32
+ */
33
+ export declare function getEvmChainIds(config: NormalizedMixerConfig): number[];
34
+ /**
35
+ * Return all Solana network ids present in the config.
36
+ */
37
+ export declare function getSolanaNetworks(config: NormalizedMixerConfig): string[];
package/dist/config.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ /**
3
+ * Config normalization and chain resolution for multi-chain (EVM + Solana) and legacy single-chain.
4
+ * Solana config is still normalized and exposed; SDK/hooks Solana integration is disabled elsewhere.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.normalizeConfig = normalizeConfig;
8
+ exports.getEvmChainConfig = getEvmChainConfig;
9
+ exports.getSolanaChainConfig = getSolanaChainConfig;
10
+ exports.getEvmChainIds = getEvmChainIds;
11
+ exports.getSolanaNetworks = getSolanaNetworks;
12
+ const DEFAULT_EVM_CHAIN_ID = 1;
13
+ const DEFAULT_SOLANA_NETWORK = "mainnet";
14
+ /**
15
+ * Normalize SDK config to canonical shape (chains.evm / chains.solana).
16
+ * Legacy flat evm/solana are converted to single-entry chains so one code path handles both.
17
+ */
18
+ function normalizeConfig(config) {
19
+ const hasChains = "chains" in config && config.chains != null;
20
+ const evmRecord = hasChains && config.chains?.evm
21
+ ? { ...config.chains.evm }
22
+ : {};
23
+ const solanaRecord = hasChains && config.chains?.solana
24
+ ? { ...config.chains.solana }
25
+ : {};
26
+ if (!hasChains || Object.keys(evmRecord).length === 0) {
27
+ const legacy = config;
28
+ if (legacy.evm) {
29
+ evmRecord[DEFAULT_EVM_CHAIN_ID] = {
30
+ factoryAddress: legacy.evm.factoryAddress,
31
+ tokenAddress: legacy.evm.tokenAddress,
32
+ wethAddress: legacy.evm.wethAddress,
33
+ wethGatewayAddress: legacy.evm.wethGatewayAddress,
34
+ rpcUrl: legacy.evm.rpcUrl,
35
+ };
36
+ }
37
+ }
38
+ if (!hasChains || Object.keys(solanaRecord).length === 0) {
39
+ const legacy = config;
40
+ if (legacy.solana) {
41
+ solanaRecord[DEFAULT_SOLANA_NETWORK] = {
42
+ factoryProgramId: legacy.solana.factoryProgramId,
43
+ mixerProgramId: legacy.solana.mixerProgramId,
44
+ stakingProgramId: legacy.solana.stakingProgramId,
45
+ tokenMint: legacy.solana.tokenMint,
46
+ rpcUrl: legacy.solana.rpcUrl,
47
+ };
48
+ }
49
+ }
50
+ return {
51
+ chains: { evm: evmRecord, solana: solanaRecord },
52
+ useMulticall: "useMulticall" in config ? config.useMulticall : undefined,
53
+ };
54
+ }
55
+ /**
56
+ * Get EVM chain config for the given chainId.
57
+ * For legacy single-chain config, returns the single evm config for any chainId.
58
+ * Optimized for many EVM networks: each chainId is looked up in config.chains.evm.
59
+ */
60
+ function getEvmChainConfig(config, chainId) {
61
+ const normalized = "chains" in config && config.chains ? config : normalizeConfig(config);
62
+ const evm = normalized.chains?.evm?.[chainId];
63
+ if (evm)
64
+ return evm;
65
+ const legacy = config;
66
+ if (legacy.evm)
67
+ return legacy.evm;
68
+ return undefined;
69
+ }
70
+ /**
71
+ * Get Solana chain config for the given network id (e.g. "mainnet", "devnet").
72
+ * For legacy single-chain config, returns the single solana config for any network.
73
+ */
74
+ function getSolanaChainConfig(config, network) {
75
+ const normalized = "chains" in config && config.chains ? config : normalizeConfig(config);
76
+ const solana = normalized.chains?.solana?.[network];
77
+ if (solana)
78
+ return solana;
79
+ const legacy = config;
80
+ if (legacy.solana)
81
+ return legacy.solana;
82
+ return undefined;
83
+ }
84
+ /**
85
+ * Return all EVM chain IDs present in the config.
86
+ */
87
+ function getEvmChainIds(config) {
88
+ return Object.keys(config.chains?.evm ?? {}).map(Number);
89
+ }
90
+ /**
91
+ * Return all Solana network ids present in the config.
92
+ */
93
+ function getSolanaNetworks(config) {
94
+ return Object.keys(config.chains?.solana ?? {});
95
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Factory for multi-chain SDK instances (EVM + Solana config).
3
+ * EVM: built on demand per chainId. Solana: getSolana() disabled (returns null) for now.
4
+ */
5
+ import type { Signer } from "ethers";
6
+ import type { Provider } from "ethers";
7
+ import type { MixerSDKConfig, SDKConfig } from "./types";
8
+ import type { NormalizedMixerConfig } from "./config";
9
+ import { AintiVirusEVM } from "./evm";
10
+ import type { AintiVirusSolana } from "./solana";
11
+ export type { NormalizedMixerConfig } from "./config";
12
+ export interface MixerSDKInstance {
13
+ /** Get normalized config */
14
+ getConfig(): NormalizedMixerConfig;
15
+ /** EVM chain IDs present in config */
16
+ getEvmChainIds(): number[];
17
+ /** Solana network ids present in config (Solana SDK integration disabled) */
18
+ getSolanaNetworks(): string[];
19
+ /** Get EVM SDK for chainId; signerOrProvider from wagmi/ethers for that chain */
20
+ getEVM(chainId: number, signerOrProvider: Signer | Provider): AintiVirusEVM | null;
21
+ /** Get Solana SDK – disabled, returns null. Re-enable by uncommenting implementation in createSDK. */
22
+ getSolana(network: string, wallet: import("@coral-xyz/anchor").Wallet, connection: import("@solana/web3.js").Connection): AintiVirusSolana | null;
23
+ }
24
+ /**
25
+ * Create a multi-chain SDK instance. Accepts full settings (MixerSDKConfig) or legacy SDKConfig.
26
+ * EVM instances are created on demand via getEVM(chainId, signerOrProvider).
27
+ * Solana: getSolana() disabled (returns null).
28
+ */
29
+ export declare function createMixerSDK(config: MixerSDKConfig | SDKConfig): MixerSDKInstance;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Factory for multi-chain SDK instances (EVM + Solana config).
4
+ * EVM: built on demand per chainId. Solana: getSolana() disabled (returns null) for now.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.createMixerSDK = createMixerSDK;
8
+ const config_1 = require("./config");
9
+ const evm_1 = require("./evm");
10
+ const multicall_1 = require("./evm/multicall");
11
+ /**
12
+ * Create a multi-chain SDK instance. Accepts full settings (MixerSDKConfig) or legacy SDKConfig.
13
+ * EVM instances are created on demand via getEVM(chainId, signerOrProvider).
14
+ * Solana: getSolana() disabled (returns null).
15
+ */
16
+ function createMixerSDK(config) {
17
+ const normalized = (0, config_1.normalizeConfig)(config);
18
+ return {
19
+ getConfig: () => normalized,
20
+ getEvmChainIds: () => (0, config_1.getEvmChainIds)(normalized),
21
+ getSolanaNetworks: () => (0, config_1.getSolanaNetworks)(normalized),
22
+ getEVM(chainId, signerOrProvider) {
23
+ const chainConfig = (0, config_1.getEvmChainConfig)(normalized, chainId);
24
+ if (!chainConfig)
25
+ return null;
26
+ const tokenAddress = chainConfig.tokenAddress ?? "0x0000000000000000000000000000000000000000";
27
+ try {
28
+ const useMulticall = chainConfig.useMulticall ?? normalized.useMulticall ?? false;
29
+ const multicallAddress = chainConfig.multicallAddress ?? multicall_1.MULTICALL3_ADDRESS;
30
+ return new evm_1.AintiVirusEVM(chainConfig.factoryAddress, tokenAddress, signerOrProvider, chainConfig.wethGatewayAddress, chainConfig.wethAddress, useMulticall, multicallAddress);
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ },
36
+ // Solana integration disabled – returns null. Uncomment below and add: import { AintiVirusSolana } from "./solana";
37
+ getSolana(_network, _wallet, _connection) {
38
+ return null;
39
+ // const chainConfig = getSolanaChainConfig(normalized, network);
40
+ // if (!chainConfig) return null;
41
+ // try {
42
+ // return new AintiVirusSolana(wallet, connection, chainConfig.tokenMint);
43
+ // } catch {
44
+ // return null;
45
+ // }
46
+ },
47
+ };
48
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Structured SDK errors for predictable handling (e.g. instanceof or code checks).
3
+ */
4
+ export declare const ERROR_CODES: {
5
+ readonly SIGNER_REQUIRED: "SIGNER_REQUIRED";
6
+ readonly TRANSACTION: "TRANSACTION";
7
+ readonly SUBGRAPH: "SUBGRAPH";
8
+ readonly PROOF: "PROOF";
9
+ readonly MULTICALL: "MULTICALL";
10
+ };
11
+ /**
12
+ * Base error for all SDK errors. Has optional code and cause for programmatic handling.
13
+ */
14
+ export declare class MixerSDKError extends Error {
15
+ readonly code?: string;
16
+ readonly cause?: unknown;
17
+ constructor(message: string, options?: {
18
+ code?: string;
19
+ cause?: unknown;
20
+ });
21
+ }
22
+ /** Thrown when a write operation is attempted without a signer (wallet). */
23
+ export declare class SignerRequiredError extends MixerSDKError {
24
+ constructor(message?: string);
25
+ }
26
+ /** Thrown when a transaction fails (missing hash, receipt timeout, revert). */
27
+ export declare class TransactionError extends MixerSDKError {
28
+ constructor(message: string, cause?: unknown);
29
+ }
30
+ /** Thrown when subgraph request fails (HTTP or GraphQL errors). */
31
+ export declare class SubgraphError extends MixerSDKError {
32
+ readonly status?: number;
33
+ constructor(message: string, options?: {
34
+ code?: string;
35
+ cause?: unknown;
36
+ status?: number;
37
+ });
38
+ }
39
+ /** Thrown when proof generation or circuit fetch fails. */
40
+ export declare class ProofError extends MixerSDKError {
41
+ constructor(message: string, cause?: unknown);
42
+ }
43
+ /** Thrown when multicall aggregate or decode fails. */
44
+ export declare class MulticallError extends MixerSDKError {
45
+ constructor(message: string, cause?: unknown);
46
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /**
3
+ * Structured SDK errors for predictable handling (e.g. instanceof or code checks).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MulticallError = exports.ProofError = exports.SubgraphError = exports.TransactionError = exports.SignerRequiredError = exports.MixerSDKError = exports.ERROR_CODES = void 0;
7
+ exports.ERROR_CODES = {
8
+ SIGNER_REQUIRED: "SIGNER_REQUIRED",
9
+ TRANSACTION: "TRANSACTION",
10
+ SUBGRAPH: "SUBGRAPH",
11
+ PROOF: "PROOF",
12
+ MULTICALL: "MULTICALL",
13
+ };
14
+ /**
15
+ * Base error for all SDK errors. Has optional code and cause for programmatic handling.
16
+ */
17
+ class MixerSDKError extends Error {
18
+ constructor(message, options) {
19
+ super(message);
20
+ this.name = "MixerSDKError";
21
+ this.code = options?.code;
22
+ this.cause = options?.cause;
23
+ Object.setPrototypeOf(this, MixerSDKError.prototype);
24
+ }
25
+ }
26
+ exports.MixerSDKError = MixerSDKError;
27
+ /** Thrown when a write operation is attempted without a signer (wallet). */
28
+ class SignerRequiredError extends MixerSDKError {
29
+ constructor(message = "Signer required for transactions") {
30
+ super(message, { code: exports.ERROR_CODES.SIGNER_REQUIRED });
31
+ this.name = "SignerRequiredError";
32
+ Object.setPrototypeOf(this, SignerRequiredError.prototype);
33
+ }
34
+ }
35
+ exports.SignerRequiredError = SignerRequiredError;
36
+ /** Thrown when a transaction fails (missing hash, receipt timeout, revert). */
37
+ class TransactionError extends MixerSDKError {
38
+ constructor(message, cause) {
39
+ super(message, { code: exports.ERROR_CODES.TRANSACTION, cause });
40
+ this.name = "TransactionError";
41
+ Object.setPrototypeOf(this, TransactionError.prototype);
42
+ }
43
+ }
44
+ exports.TransactionError = TransactionError;
45
+ /** Thrown when subgraph request fails (HTTP or GraphQL errors). */
46
+ class SubgraphError extends MixerSDKError {
47
+ constructor(message, options) {
48
+ super(message, { code: options?.code ?? exports.ERROR_CODES.SUBGRAPH, cause: options?.cause });
49
+ this.name = "SubgraphError";
50
+ this.status = options?.status;
51
+ Object.setPrototypeOf(this, SubgraphError.prototype);
52
+ }
53
+ }
54
+ exports.SubgraphError = SubgraphError;
55
+ /** Thrown when proof generation or circuit fetch fails. */
56
+ class ProofError extends MixerSDKError {
57
+ constructor(message, cause) {
58
+ super(message, { code: exports.ERROR_CODES.PROOF, cause });
59
+ this.name = "ProofError";
60
+ Object.setPrototypeOf(this, ProofError.prototype);
61
+ }
62
+ }
63
+ exports.ProofError = ProofError;
64
+ /** Thrown when multicall aggregate or decode fails. */
65
+ class MulticallError extends MixerSDKError {
66
+ constructor(message, cause) {
67
+ super(message, { code: exports.ERROR_CODES.MULTICALL, cause });
68
+ this.name = "MulticallError";
69
+ Object.setPrototypeOf(this, MulticallError.prototype);
70
+ }
71
+ }
72
+ exports.MulticallError = MulticallError;