@unlink-xyz/react 0.1.5 → 0.1.7-canary.252b8ea

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, Unlink, AccountInfo, Account, NoteRecord, BurnerAccount, HistoryStatus, SignerOverride, SendResult, SendPlanResult, DepositRelayResult, WithdrawalInput, WithdrawResult, WithdrawPlanResult, BurnerSendParams, SimpleBurnerFundParams, SimpleBurnerSweepToPoolParams, SimpleInteractParams, InteractResult, RelayState, HistoryEntry } from '@unlink-xyz/core';
4
+ export { Account, AccountInfo, AdapterExecutionCall, BurnerAccount, BurnerSendParams, Chain, HistoryEntry, InputTokenSpec, InteractResult, NoteRecord, ParsedZkAddress, ReceiveInput, ReshieldInput, SendPlanResult, SendResult, SignerOverride, SimpleBurnerFundParams, SimpleBurnerSweepToPoolParams, SimpleInteractParams, SpendInput, SupportedChain, TransactionLike, TxStatusChangedEvent, Unlink, UnlinkEvent, UnlinkWallet, WalletSDKEvent, WithdrawPlanResult, WithdrawResult, approve, buildApproveCall, computeBalances, contract, decodeAddress, encodeAddress, formatAmount, normalizeAddress, parseAmount, parseZkAddress, randomHex, shortenHex, toCall } from '@unlink-xyz/core';
5
5
 
6
6
  /**
7
7
  * Wallet note with value as bigint for convenience.
@@ -23,7 +23,7 @@ type PendingJobBase = {
23
23
  type PendingDepositJob = PendingJobBase & {
24
24
  commitment?: string;
25
25
  };
26
- type PendingTransferJob = PendingJobBase & {
26
+ type PendingSendJob = PendingJobBase & {
27
27
  recipient: string;
28
28
  };
29
29
  type PendingWithdrawJob = PendingJobBase & {
@@ -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,26 +42,29 @@ 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.
63
64
  */
64
65
  type UnlinkState = {
65
- /** The underlying wallet instance */
66
- wallet: UnlinkWallet | null;
66
+ /** The underlying Unlink instance */
67
+ unlink: Unlink | null;
67
68
  /** Whether a wallet (mnemonic) exists */
68
69
  walletExists: boolean;
69
70
  /** All derived accounts */
@@ -72,16 +73,18 @@ 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
- /** Pending transfer jobs */
84
- pendingTransfers: PendingTransferJob[];
86
+ /** Pending send jobs */
87
+ pendingSends: PendingSendJob[];
85
88
  /** Pending withdraw jobs */
86
89
  pendingWithdrawals: PendingWithdrawJob[];
87
90
  /** Whether the SDK is initialized and ready */
@@ -96,11 +99,11 @@ type UnlinkState = {
96
99
  error: UnlinkError | null;
97
100
  };
98
101
  /**
99
- * Transfer parameters for useUnlink.send()
102
+ * Send parameters for useUnlink.send()
100
103
  */
101
- type TransferInput = {
104
+ type SendInput = {
102
105
  token: string;
103
- /** Unlink address (0zk1... bech32m) */
106
+ /** Unlink address (unlink1... bech32m) */
104
107
  recipient: string;
105
108
  amount: bigint;
106
109
  };
@@ -114,7 +117,7 @@ type DepositInput = {
114
117
  depositor: string;
115
118
  };
116
119
  /**
117
- * Withdraw parameters for useUnlink.requestWithdraw()
120
+ * Withdraw parameters for useUnlink.withdraw()
118
121
  */
119
122
  type WithdrawInput = WithdrawalInput;
120
123
  /**
@@ -140,28 +143,28 @@ type UnlinkActions = {
140
143
  * Multiple transfers are processed atomically.
141
144
  *
142
145
  * @param params - Array of transfers (token + amount + recipient)
143
- * @returns TransferResult with array of plans
146
+ * @returns SendResult with array of plans
144
147
  */
145
- send(params: TransferInput[]): Promise<TransferResult>;
148
+ send(params: SendInput[], overrides?: SignerOverride): Promise<SendResult>;
146
149
  /**
147
- * Get a transfer plan without executing (for preview).
150
+ * Get a send plan without executing (for preview).
148
151
  * Validates balances and returns plans for each transfer.
149
152
  *
150
153
  * @param params - Array of transfers (token + amount + recipient)
151
154
  * @returns Array of TransactionPlan
152
155
  */
153
- planTransfer(params: TransferInput[]): Promise<TransferPlanResult>;
154
- /** Execute a pre-built transfer plan */
155
- executeTransfer(plans: TransferPlanResult): Promise<TransferResult>;
156
+ planSend(params: SendInput[]): Promise<SendPlanResult>;
157
+ /** Execute a pre-built send plan */
158
+ executeSend(plans: SendPlanResult, overrides?: SignerOverride): Promise<SendResult>;
156
159
  /**
157
- * Request a deposit (1 or more tokens).
160
+ * Deposit (1 or more tokens).
158
161
  * Returns calldata that the user must submit on-chain via their EOA.
159
162
  * Use the returned `to` and `calldata` fields to construct the transaction.
160
163
  *
161
164
  * @param params - Array of deposits (token + amount + depositor)
162
165
  * @returns DepositRelayResult with array of commitments
163
166
  */
164
- requestDeposit(params: DepositInput[]): Promise<DepositRelayResult>;
167
+ deposit(params: DepositInput[]): Promise<DepositRelayResult>;
165
168
  /**
166
169
  * High-level withdraw (1 or more tokens).
167
170
  * Specify recipient EOA + amount for each withdrawal.
@@ -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
+ withdraw(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 DeFi flow (unshield -> calls -> reshield).
207
+ */
208
+ interact(params: SimpleInteractParams): Promise<InteractResult>;
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" | "executeSend" | "deposit" | "withdraw" | "interact" | "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.
@@ -325,7 +350,7 @@ type UseUnlinkHistoryResult = {
325
350
  refresh: () => Promise<void>;
326
351
  };
327
352
  /**
328
- * Hook to get transaction history for the wallet.
353
+ * Hook to get transaction history for the Unlink instance.
329
354
  *
330
355
  * Uses the SDK's history service which provides properly categorized
331
356
  * transaction entries (Deposit, Receive, Send, SelfSend, Withdraw).
@@ -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 */
@@ -452,6 +477,13 @@ type UseOperationMutationResult<TInput, TOutput> = {
452
477
  /** Reset state back to idle */
453
478
  reset: () => void;
454
479
  };
480
+ /**
481
+ * `UseOperationMutationResult` with `execute` replaced by a semantic action name.
482
+ * Used by operation-specific hooks (useSend, useDeposit, etc.).
483
+ */
484
+ type NamedMutationResult<TAction extends string, TInput, TOutput> = Omit<UseOperationMutationResult<TInput, TOutput>, "execute"> & {
485
+ [K in TAction]: (input: TInput) => Promise<TOutput>;
486
+ };
455
487
  /**
456
488
  * Generic async mutation state machine for wallet operations.
457
489
  *
@@ -461,11 +493,11 @@ type UseOperationMutationResult<TInput, TOutput> = {
461
493
  * @example
462
494
  * ```tsx
463
495
  * function DepositButton() {
464
- * const { requestDeposit } = useUnlink();
465
- * const { mutate, isPending, error } = useOperationMutation(requestDeposit);
496
+ * const { deposit } = useUnlink();
497
+ * const { execute, isPending, error } = useOperationMutation(deposit);
466
498
  *
467
499
  * return (
468
- * <button onClick={() => mutate(params)} disabled={isPending}>
500
+ * <button onClick={() => execute(params)} disabled={isPending}>
469
501
  * {isPending ? "Depositing..." : "Deposit"}
470
502
  * </button>
471
503
  * );
@@ -474,13 +506,14 @@ type UseOperationMutationResult<TInput, TOutput> = {
474
506
  */
475
507
  declare function useOperationMutation<TInput, TOutput>(operation: (input: TInput) => Promise<TOutput>): UseOperationMutationResult<TInput, TOutput>;
476
508
 
509
+ type UseDepositResult = NamedMutationResult<"deposit", DepositInput[], DepositRelayResult>;
477
510
  /**
478
511
  * Hook for requesting deposits with loading/error state.
479
512
  *
480
513
  * @example
481
514
  * ```tsx
482
515
  * function DepositForm() {
483
- * const { mutate: deposit, isPending, error } = useDeposit();
516
+ * const { deposit, isPending, error } = useDeposit();
484
517
  *
485
518
  * const handleDeposit = async () => {
486
519
  * const result = await deposit([
@@ -497,19 +530,22 @@ declare function useOperationMutation<TInput, TOutput>(operation: (input: TInput
497
530
  * }
498
531
  * ```
499
532
  */
500
- declare function useDeposit(): UseOperationMutationResult<DepositInput[], DepositRelayResult>;
533
+ declare function useDeposit(): UseDepositResult;
501
534
 
535
+ type UseSendResult = NamedMutationResult<"send", SendInput[], SendResult>;
502
536
  /**
503
537
  * Hook for sending private transfers with loading/error state.
504
538
  *
539
+ * @param overrides - Optional signer override for multisig transactions
540
+ *
505
541
  * @example
506
542
  * ```tsx
507
543
  * function SendForm() {
508
- * const { mutate: send, isPending, error } = useTransfer();
544
+ * const { send, isPending, error } = useSend();
509
545
  *
510
546
  * const handleSend = async () => {
511
547
  * const result = await send([
512
- * { token: "0x...", recipient: "0zk1...", amount: 100n },
548
+ * { token: "0x...", recipient: "unlink1...", amount: 100n },
513
549
  * ]);
514
550
  * console.log("Relay ID:", result.relayId);
515
551
  * };
@@ -522,15 +558,18 @@ declare function useDeposit(): UseOperationMutationResult<DepositInput[], Deposi
522
558
  * }
523
559
  * ```
524
560
  */
525
- declare function useTransfer(): UseOperationMutationResult<TransferInput[], TransferResult>;
561
+ declare function useSend(overrides?: SignerOverride): UseSendResult;
526
562
 
563
+ type UseWithdrawResult = NamedMutationResult<"withdraw", WithdrawInput[], WithdrawResult>;
527
564
  /**
528
565
  * Hook for requesting withdrawals with loading/error state.
529
566
  *
567
+ * @param overrides - Optional signer override for multisig transactions
568
+ *
530
569
  * @example
531
570
  * ```tsx
532
571
  * function WithdrawForm() {
533
- * const { mutate: withdraw, isPending, error } = useWithdraw();
572
+ * const { withdraw, isPending, error } = useWithdraw();
534
573
  *
535
574
  * const handleWithdraw = async () => {
536
575
  * const result = await withdraw([
@@ -547,6 +586,70 @@ declare function useTransfer(): UseOperationMutationResult<TransferInput[], Tran
547
586
  * }
548
587
  * ```
549
588
  */
550
- declare function useWithdraw(): UseOperationMutationResult<WithdrawInput[], WithdrawResult>;
589
+ declare function useWithdraw(overrides?: SignerOverride): UseWithdrawResult;
590
+
591
+ type UseInteractResult = NamedMutationResult<"interact", SimpleInteractParams, InteractResult>;
592
+ /**
593
+ * Hook for executing private DeFi interactions with loading/error state.
594
+ *
595
+ * Performs atomic unshield → DeFi call(s) → reshield flows through an adapter contract.
596
+ *
597
+ * @example
598
+ * ```tsx
599
+ * function SwapButton() {
600
+ * const { interact, isPending, error } = useInteract();
601
+ *
602
+ * const handleSwap = async () => {
603
+ * const result = await interact({
604
+ * spend: [{ token: "0x...", amount: 1000n }],
605
+ * calls: [approveCall, swapCall],
606
+ * receive: [{ token: "0x...", minAmount: 500n }],
607
+ * });
608
+ * console.log("Relay ID:", result.relayId);
609
+ * };
610
+ *
611
+ * return (
612
+ * <button onClick={handleSwap} disabled={isPending}>
613
+ * {isPending ? "Executing..." : "Swap"}
614
+ * </button>
615
+ * );
616
+ * }
617
+ * ```
618
+ */
619
+ declare function useInteract(): UseInteractResult;
620
+
621
+ type BurnerSendInput = {
622
+ index: number;
623
+ tx: BurnerSendParams;
624
+ };
625
+ type BurnerFundInput = {
626
+ index: number;
627
+ params: SimpleBurnerFundParams;
628
+ };
629
+ type BurnerSweepInput = {
630
+ index: number;
631
+ params: SimpleBurnerSweepToPoolParams;
632
+ };
633
+ type UseBurnerResult = {
634
+ burners: BurnerAccount[];
635
+ createBurner: (index: number) => Promise<BurnerAccount>;
636
+ removeBurner: (index: number) => void;
637
+ send: UseOperationMutationResult<BurnerSendInput, {
638
+ txHash: string;
639
+ }>;
640
+ fund: UseOperationMutationResult<BurnerFundInput, WithdrawResult>;
641
+ sweepToPool: UseOperationMutationResult<BurnerSweepInput, {
642
+ txHash: string;
643
+ }>;
644
+ getTokenBalance: (address: string, token: string) => Promise<bigint>;
645
+ getBalance: (address: string) => Promise<bigint>;
646
+ };
647
+ /**
648
+ * Hook for burner account operations.
649
+ *
650
+ * `exportKey` is intentionally excluded here and can be accessed via
651
+ * `useUnlink().unlink?.burner.exportKey(index)`.
652
+ */
653
+ declare function useBurner(): UseBurnerResult;
551
654
 
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 };
655
+ export { type BurnerFundInput, type BurnerSendInput, type BurnerSweepInput, CONFIRMATION_POLL_INTERVAL_MS, DEFAULT_CONFIRMATION_TIMEOUT_MS, type DepositInput, type NamedMutationResult, type PendingDepositJob, type PendingSendJob, type PendingWithdrawJob, type SendInput, TERMINAL_TX_STATES, TimeoutError, TransactionFailedError, type TxState, type TxStatus, type UnlinkActions, type UnlinkConfig, type UnlinkContextValue, type UnlinkError, type UnlinkErrorCode, type UnlinkErrorOperation, UnlinkProvider, type UnlinkProviderProps, type UnlinkState, type UseBurnerResult, type UseDepositResult, type UseInteractResult, type UseOperationMutationResult, type UseSendResult, type UseTxStatusResult, type UseUnlinkBalanceResult, type UseUnlinkHistoryOptions, type UseUnlinkHistoryResult, type UseWithdrawResult, type WaitForConfirmationOptions, type WalletNote, type WithdrawInput, useBurner, useDeposit, useInteract, useOperationMutation, useSend, useTxStatus, useUnlink, useUnlinkBalance, useUnlinkBalances, useUnlinkHistory, useWithdraw };