@unlink-xyz/react 0.1.0 → 0.1.3-canary.04befc5

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.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { BrowserWalletOptions, Environment, UnlinkWallet, AccountInfo, Account, NoteRecord, HistoryStatus, TransferResult, TransferPlanResult, DepositRelayResult, WithdrawalInput, WithdrawResult, WithdrawPlanResult, RelayState, HistoryEntry } from '@unlink-xyz/core';
4
- export { Account, AccountInfo, Chain, HistoryEntry, NoteRecord, ParsedZkAddress, TransferPlanResult, TransferResult, TxStatusChangedEvent, UnlinkWallet, WalletSDKEvent, WithdrawPlanResult, WithdrawResult, computeBalances, decodeAddress, encodeAddress, formatAmount, normalizeAddress, parseAmount, parseZkAddress, randomHex, shortenHex } from '@unlink-xyz/core';
3
+ import { BrowserWalletOptions, SupportedChain, UnlinkWallet, AccountInfo, Account, NoteRecord, BurnerAccount, HistoryStatus, TransferResult, TransferPlanResult, DepositRelayResult, WithdrawalInput, WithdrawResult, WithdrawPlanResult, BurnerSendParams, SimpleBurnerFundParams, SimpleBurnerSweepToPoolParams, SimpleAdapterExecuteParams, AdapterExecuteResult, RelayState, HistoryEntry } from '@unlink-xyz/core';
4
+ export { Account, AccountInfo, AdapterExecuteResult, AdapterExecutionCall, BurnerAccount, BurnerSendParams, Chain, HistoryEntry, InputTokenSpec, NoteRecord, ParsedZkAddress, ReshieldInput, SimpleAdapterExecuteParams, SimpleBurnerFundParams, SimpleBurnerSweepToPoolParams, SupportedChain, TransferPlanResult, TransferResult, TxStatusChangedEvent, UnlinkWallet, WalletSDKEvent, WithdrawPlanResult, WithdrawResult, computeBalances, decodeAddress, encodeAddress, formatAmount, normalizeAddress, parseAmount, parseZkAddress, randomHex, shortenHex } from '@unlink-xyz/core';
5
5
 
6
6
  /**
7
7
  * Wallet note with value as bigint for convenience.
@@ -33,8 +33,6 @@ type PendingWithdrawJob = PendingJobBase & {
33
33
  * Base configuration shared by all UnlinkProvider variants.
34
34
  */
35
35
  type UnlinkConfigBase = {
36
- /** Chain ID for the target blockchain */
37
- chainId: number;
38
36
  /** Auto-sync interval in milliseconds (default: 5000) */
39
37
  syncInterval?: number;
40
38
  /** Whether to start auto-sync on mount (default: true) */
@@ -44,19 +42,22 @@ type UnlinkConfigBase = {
44
42
  };
45
43
  /**
46
44
  * Configuration for the UnlinkProvider.
47
- * Either provide explicit gatewayUrl + poolAddress, or environment to auto-resolve.
45
+ * Either provide a chain name to auto-resolve, or explicit gatewayUrl + poolAddress.
48
46
  */
49
47
  type UnlinkConfig = UnlinkConfigBase & ({
48
+ /** Supported chain name — resolves chainId, gateway, pool, artifacts */
49
+ chain: SupportedChain;
50
+ /** Override pool address from chain config */
51
+ poolAddress?: string;
52
+ chainId?: never;
53
+ gatewayUrl?: never;
54
+ } | {
55
+ /** Chain ID for the target blockchain */
56
+ chainId: number;
50
57
  /** Explicit gateway URL - requires poolAddress */
51
58
  gatewayUrl: string;
52
59
  poolAddress: string;
53
- environment?: never;
54
- } | {
55
- /** Environment to use from the config file */
56
- environment: Environment;
57
- /** Pool contract address - optional, defaults to environment config */
58
- poolAddress?: string;
59
- gatewayUrl?: never;
60
+ chain?: never;
60
61
  });
61
62
  /**
62
63
  * State exposed by the useUnlink hook.
@@ -72,12 +73,14 @@ type UnlinkState = {
72
73
  activeAccount: Account | null;
73
74
  /** Current active account index (null if none) */
74
75
  activeAccountIndex: number | null;
75
- /** Chain ID configured for this provider */
76
- chainId: number;
76
+ /** Chain ID (resolved from chain config or provided explicitly, null before init) */
77
+ chainId: number | null;
77
78
  /** User's notes with value as bigint */
78
79
  notes: WalletNote[];
79
80
  /** Token balances by address */
80
81
  balances: Record<string, bigint>;
82
+ /** Tracked burner accounts */
83
+ burners: BurnerAccount[];
81
84
  /** Pending deposit jobs */
82
85
  pendingDeposits: PendingDepositJob[];
83
86
  /** Pending transfer jobs */
@@ -181,6 +184,28 @@ type UnlinkActions = {
181
184
  planWithdraw(params: WithdrawInput[]): Promise<WithdrawPlanResult>;
182
185
  /** Execute a pre-built withdrawal plan */
183
186
  executeWithdraw(plans: WithdrawPlanResult): Promise<WithdrawResult>;
187
+ /** Derive and track burner account at index */
188
+ createBurner(index: number): Promise<BurnerAccount>;
189
+ /** Remove tracked burner account (client-side only) */
190
+ removeBurner(index: number): void;
191
+ /** Send transaction from burner account */
192
+ burnerSend(index: number, tx: BurnerSendParams): Promise<{
193
+ txHash: string;
194
+ }>;
195
+ /** Fund burner from shielded pool */
196
+ burnerFund(index: number, params: SimpleBurnerFundParams): Promise<WithdrawResult>;
197
+ /** Sweep burner funds back to shielded pool */
198
+ burnerSweepToPool(index: number, params: SimpleBurnerSweepToPoolParams): Promise<{
199
+ txHash: string;
200
+ }>;
201
+ /** Get ERC-20 token balance for address */
202
+ burnerGetTokenBalance(address: string, token: string): Promise<bigint>;
203
+ /** Get native balance for address */
204
+ burnerGetBalance(address: string): Promise<bigint>;
205
+ /**
206
+ * Execute an atomic private adapter flow (unshield -> calls -> reshield).
207
+ */
208
+ executeAdapter(params: SimpleAdapterExecuteParams): Promise<AdapterExecuteResult>;
184
209
  /** Refresh notes and balances */
185
210
  refresh(): Promise<void>;
186
211
  /** Force full resync from chain */
@@ -269,7 +294,7 @@ type UnlinkErrorCode = "UNKNOWN" | "SDK_NOT_INITIALIZED" | "NETWORK_ERROR" | "VA
269
294
  /**
270
295
  * Operations that can trigger an error in the Unlink context.
271
296
  */
272
- type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "executeTransfer" | "requestDeposit" | "requestWithdraw" | "executeWithdraw" | "refresh" | "forceResync";
297
+ type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "executeTransfer" | "requestDeposit" | "requestWithdraw" | "executeAdapter" | "executeWithdraw" | "createBurner" | "burnerSend" | "burnerFund" | "burnerSweepToPool" | "refresh" | "forceResync";
273
298
  /**
274
299
  * Structured error type for the Unlink context.
275
300
  */
@@ -284,7 +309,7 @@ type UnlinkError = {
284
309
  type UnlinkProviderProps = UnlinkConfig & {
285
310
  children: ReactNode;
286
311
  };
287
- declare function UnlinkProvider({ children, chainId, poolAddress, syncInterval, autoSync, gatewayUrl, environment, prover, }: UnlinkProviderProps): react_jsx_runtime.JSX.Element;
312
+ declare function UnlinkProvider({ children, poolAddress, syncInterval, autoSync, prover, ...configProps }: UnlinkProviderProps): react_jsx_runtime.JSX.Element;
288
313
 
289
314
  /**
290
315
  * Hook to access the Unlink wallet SDK.
@@ -549,4 +574,68 @@ declare function useTransfer(): UseOperationMutationResult<TransferInput[], Tran
549
574
  */
550
575
  declare function useWithdraw(): UseOperationMutationResult<WithdrawInput[], WithdrawResult>;
551
576
 
552
- export { CONFIRMATION_POLL_INTERVAL_MS, DEFAULT_CONFIRMATION_TIMEOUT_MS, type DepositInput, type PendingDepositJob, type PendingTransferJob, type PendingWithdrawJob, TERMINAL_TX_STATES, TimeoutError, TransactionFailedError, type TransferInput, type TxState, type TxStatus, type UnlinkActions, type UnlinkConfig, type UnlinkContextValue, type UnlinkError, type UnlinkErrorCode, type UnlinkErrorOperation, UnlinkProvider, type UnlinkProviderProps, type UnlinkState, type UseOperationMutationResult, type UseTxStatusResult, type UseUnlinkBalanceResult, type UseUnlinkHistoryOptions, type UseUnlinkHistoryResult, type WaitForConfirmationOptions, type WalletNote, type WithdrawInput, useDeposit, useOperationMutation, useTransfer, useTxStatus, useUnlink, useUnlinkBalance, useUnlinkBalances, useUnlinkHistory, useWithdraw };
577
+ /**
578
+ * Hook for executing private DeFi adapter operations with loading/error state.
579
+ *
580
+ * Performs atomic unshield → DeFi call(s) → reshield flows through an adapter contract.
581
+ *
582
+ * @example
583
+ * ```tsx
584
+ * function SwapButton() {
585
+ * const { mutate: executeAdapter, isPending, error } = useAdapter();
586
+ *
587
+ * const handleSwap = async () => {
588
+ * const result = await executeAdapter({
589
+ * adapterAddress: "0x...",
590
+ * inputs: [{ token: "0x...", amount: 1000n }],
591
+ * calls: [approveCall, swapCall],
592
+ * reshields: [{ token: "0x...", minAmount: 500n }],
593
+ * });
594
+ * console.log("Relay ID:", result.relayId);
595
+ * };
596
+ *
597
+ * return (
598
+ * <button onClick={handleSwap} disabled={isPending}>
599
+ * {isPending ? "Executing..." : "Swap"}
600
+ * </button>
601
+ * );
602
+ * }
603
+ * ```
604
+ */
605
+ declare function useAdapter(): UseOperationMutationResult<SimpleAdapterExecuteParams, AdapterExecuteResult>;
606
+
607
+ type BurnerSendInput = {
608
+ index: number;
609
+ tx: BurnerSendParams;
610
+ };
611
+ type BurnerFundInput = {
612
+ index: number;
613
+ params: SimpleBurnerFundParams;
614
+ };
615
+ type BurnerSweepInput = {
616
+ index: number;
617
+ params: SimpleBurnerSweepToPoolParams;
618
+ };
619
+ type UseBurnerResult = {
620
+ burners: BurnerAccount[];
621
+ createBurner: (index: number) => Promise<BurnerAccount>;
622
+ removeBurner: (index: number) => void;
623
+ send: UseOperationMutationResult<BurnerSendInput, {
624
+ txHash: string;
625
+ }>;
626
+ fund: UseOperationMutationResult<BurnerFundInput, WithdrawResult>;
627
+ sweepToPool: UseOperationMutationResult<BurnerSweepInput, {
628
+ txHash: string;
629
+ }>;
630
+ getTokenBalance: (address: string, token: string) => Promise<bigint>;
631
+ getBalance: (address: string) => Promise<bigint>;
632
+ };
633
+ /**
634
+ * Hook for burner account operations.
635
+ *
636
+ * `exportKey` is intentionally excluded here and can be accessed via
637
+ * `useUnlink().wallet?.burner.exportKey(index)`.
638
+ */
639
+ declare function useBurner(): UseBurnerResult;
640
+
641
+ export { type BurnerFundInput, type BurnerSendInput, type BurnerSweepInput, CONFIRMATION_POLL_INTERVAL_MS, DEFAULT_CONFIRMATION_TIMEOUT_MS, type DepositInput, type PendingDepositJob, type PendingTransferJob, type PendingWithdrawJob, TERMINAL_TX_STATES, TimeoutError, TransactionFailedError, type TransferInput, type TxState, type TxStatus, type UnlinkActions, type UnlinkConfig, type UnlinkContextValue, type UnlinkError, type UnlinkErrorCode, type UnlinkErrorOperation, UnlinkProvider, type UnlinkProviderProps, type UnlinkState, type UseBurnerResult, type UseOperationMutationResult, type UseTxStatusResult, type UseUnlinkBalanceResult, type UseUnlinkHistoryOptions, type UseUnlinkHistoryResult, type WaitForConfirmationOptions, type WalletNote, type WithdrawInput, useAdapter, useBurner, useDeposit, useOperationMutation, useTransfer, useTxStatus, useUnlink, useUnlinkBalance, useUnlinkBalances, useUnlinkHistory, useWithdraw };