@unlink-xyz/react 0.1.5 → 0.1.6

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, SignerOverride, 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, SignerOverride, 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 */
@@ -100,7 +103,7 @@ type UnlinkState = {
100
103
  */
101
104
  type TransferInput = {
102
105
  token: string;
103
- /** Unlink address (0zk1... bech32m) */
106
+ /** Unlink address (unlink1... bech32m) */
104
107
  recipient: string;
105
108
  amount: bigint;
106
109
  };
@@ -142,7 +145,7 @@ type UnlinkActions = {
142
145
  * @param params - Array of transfers (token + amount + recipient)
143
146
  * @returns TransferResult with array of plans
144
147
  */
145
- send(params: TransferInput[]): Promise<TransferResult>;
148
+ send(params: TransferInput[], overrides?: SignerOverride): Promise<TransferResult>;
146
149
  /**
147
150
  * Get a transfer plan without executing (for preview).
148
151
  * Validates balances and returns plans for each transfer.
@@ -152,7 +155,7 @@ type UnlinkActions = {
152
155
  */
153
156
  planTransfer(params: TransferInput[]): Promise<TransferPlanResult>;
154
157
  /** Execute a pre-built transfer plan */
155
- executeTransfer(plans: TransferPlanResult): Promise<TransferResult>;
158
+ executeTransfer(plans: TransferPlanResult, overrides?: SignerOverride): Promise<TransferResult>;
156
159
  /**
157
160
  * Request a deposit (1 or more tokens).
158
161
  * Returns calldata that the user must submit on-chain via their EOA.
@@ -170,7 +173,7 @@ type UnlinkActions = {
170
173
  * @param params - Array of withdrawals (token + amount + recipient)
171
174
  * @returns WithdrawResult with array of plans
172
175
  */
173
- requestWithdraw(params: WithdrawInput[]): Promise<WithdrawResult>;
176
+ requestWithdraw(params: WithdrawInput[], overrides?: SignerOverride): Promise<WithdrawResult>;
174
177
  /**
175
178
  * Get a withdrawal plan without executing (for preview).
176
179
  * Validates balances and returns plans for each withdrawal.
@@ -180,7 +183,29 @@ type UnlinkActions = {
180
183
  */
181
184
  planWithdraw(params: WithdrawInput[]): Promise<WithdrawPlanResult>;
182
185
  /** Execute a pre-built withdrawal plan */
183
- executeWithdraw(plans: WithdrawPlanResult): Promise<WithdrawResult>;
186
+ executeWithdraw(plans: WithdrawPlanResult, overrides?: SignerOverride): 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.
@@ -437,8 +462,8 @@ declare function useUnlinkBalances(): {
437
462
  declare function useTxStatus(txId: string | null): UseTxStatusResult;
438
463
 
439
464
  type UseOperationMutationResult<TInput, TOutput> = {
440
- /** Execute the mutation */
441
- mutate: (input: TInput) => Promise<TOutput>;
465
+ /** Execute the operation */
466
+ execute: (input: TInput) => Promise<TOutput>;
442
467
  /** Last successful result */
443
468
  data: TOutput | null;
444
469
  /** Whether the mutation is currently running */
@@ -462,10 +487,10 @@ type UseOperationMutationResult<TInput, TOutput> = {
462
487
  * ```tsx
463
488
  * function DepositButton() {
464
489
  * const { requestDeposit } = useUnlink();
465
- * const { mutate, isPending, error } = useOperationMutation(requestDeposit);
490
+ * const { execute, isPending, error } = useOperationMutation(requestDeposit);
466
491
  *
467
492
  * return (
468
- * <button onClick={() => mutate(params)} disabled={isPending}>
493
+ * <button onClick={() => execute(params)} disabled={isPending}>
469
494
  * {isPending ? "Depositing..." : "Deposit"}
470
495
  * </button>
471
496
  * );
@@ -502,6 +527,8 @@ declare function useDeposit(): UseOperationMutationResult<DepositInput[], Deposi
502
527
  /**
503
528
  * Hook for sending private transfers with loading/error state.
504
529
  *
530
+ * @param overrides - Optional signer override for multisig transactions
531
+ *
505
532
  * @example
506
533
  * ```tsx
507
534
  * function SendForm() {
@@ -509,7 +536,7 @@ declare function useDeposit(): UseOperationMutationResult<DepositInput[], Deposi
509
536
  *
510
537
  * const handleSend = async () => {
511
538
  * const result = await send([
512
- * { token: "0x...", recipient: "0zk1...", amount: 100n },
539
+ * { token: "0x...", recipient: "unlink1...", amount: 100n },
513
540
  * ]);
514
541
  * console.log("Relay ID:", result.relayId);
515
542
  * };
@@ -522,11 +549,13 @@ declare function useDeposit(): UseOperationMutationResult<DepositInput[], Deposi
522
549
  * }
523
550
  * ```
524
551
  */
525
- declare function useTransfer(): UseOperationMutationResult<TransferInput[], TransferResult>;
552
+ declare function useTransfer(overrides?: SignerOverride): UseOperationMutationResult<TransferInput[], TransferResult>;
526
553
 
527
554
  /**
528
555
  * Hook for requesting withdrawals with loading/error state.
529
556
  *
557
+ * @param overrides - Optional signer override for multisig transactions
558
+ *
530
559
  * @example
531
560
  * ```tsx
532
561
  * function WithdrawForm() {
@@ -547,6 +576,70 @@ declare function useTransfer(): UseOperationMutationResult<TransferInput[], Tran
547
576
  * }
548
577
  * ```
549
578
  */
550
- declare function useWithdraw(): UseOperationMutationResult<WithdrawInput[], WithdrawResult>;
579
+ declare function useWithdraw(overrides?: SignerOverride): UseOperationMutationResult<WithdrawInput[], WithdrawResult>;
580
+
581
+ /**
582
+ * Hook for executing private DeFi adapter operations with loading/error state.
583
+ *
584
+ * Performs atomic unshield → DeFi call(s) → reshield flows through an adapter contract.
585
+ *
586
+ * @example
587
+ * ```tsx
588
+ * function SwapButton() {
589
+ * const { mutate: executeAdapter, isPending, error } = useAdapter();
590
+ *
591
+ * const handleSwap = async () => {
592
+ * const result = await executeAdapter({
593
+ * adapterAddress: "0x...",
594
+ * inputs: [{ token: "0x...", amount: 1000n }],
595
+ * calls: [approveCall, swapCall],
596
+ * reshields: [{ token: "0x...", minAmount: 500n }],
597
+ * });
598
+ * console.log("Relay ID:", result.relayId);
599
+ * };
600
+ *
601
+ * return (
602
+ * <button onClick={handleSwap} disabled={isPending}>
603
+ * {isPending ? "Executing..." : "Swap"}
604
+ * </button>
605
+ * );
606
+ * }
607
+ * ```
608
+ */
609
+ declare function useAdapter(): UseOperationMutationResult<SimpleAdapterExecuteParams, AdapterExecuteResult>;
610
+
611
+ type BurnerSendInput = {
612
+ index: number;
613
+ tx: BurnerSendParams;
614
+ };
615
+ type BurnerFundInput = {
616
+ index: number;
617
+ params: SimpleBurnerFundParams;
618
+ };
619
+ type BurnerSweepInput = {
620
+ index: number;
621
+ params: SimpleBurnerSweepToPoolParams;
622
+ };
623
+ type UseBurnerResult = {
624
+ burners: BurnerAccount[];
625
+ createBurner: (index: number) => Promise<BurnerAccount>;
626
+ removeBurner: (index: number) => void;
627
+ send: UseOperationMutationResult<BurnerSendInput, {
628
+ txHash: string;
629
+ }>;
630
+ fund: UseOperationMutationResult<BurnerFundInput, WithdrawResult>;
631
+ sweepToPool: UseOperationMutationResult<BurnerSweepInput, {
632
+ txHash: string;
633
+ }>;
634
+ getTokenBalance: (address: string, token: string) => Promise<bigint>;
635
+ getBalance: (address: string) => Promise<bigint>;
636
+ };
637
+ /**
638
+ * Hook for burner account operations.
639
+ *
640
+ * `exportKey` is intentionally excluded here and can be accessed via
641
+ * `useUnlink().wallet?.burner.exportKey(index)`.
642
+ */
643
+ declare function useBurner(): UseBurnerResult;
551
644
 
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 };
645
+ 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 };