@unlink-xyz/react 0.1.3-canary.b90837a → 0.1.3-canary.b98d1f5

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, 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, 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,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,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.
@@ -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 */
@@ -461,11 +486,11 @@ type UseOperationMutationResult<TInput, TOutput> = {
461
486
  * @example
462
487
  * ```tsx
463
488
  * function DepositButton() {
464
- * const { requestDeposit } = useUnlink();
465
- * const { mutate, isPending, error } = useOperationMutation(requestDeposit);
489
+ * const { deposit } = useUnlink();
490
+ * const { execute, isPending, error } = useOperationMutation(deposit);
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,14 +527,16 @@ 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() {
508
- * const { mutate: send, isPending, error } = useTransfer();
535
+ * const { mutate: send, isPending, error } = useSend();
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 useSend(overrides?: SignerOverride): UseOperationMutationResult<SendInput[], SendResult>;
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,69 @@ 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 interactions 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: interact, isPending, error } = useInteract();
590
+ *
591
+ * const handleSwap = async () => {
592
+ * const result = await interact({
593
+ * spend: [{ token: "0x...", amount: 1000n }],
594
+ * calls: [approveCall, swapCall],
595
+ * receive: [{ token: "0x...", minAmount: 500n }],
596
+ * });
597
+ * console.log("Relay ID:", result.relayId);
598
+ * };
599
+ *
600
+ * return (
601
+ * <button onClick={handleSwap} disabled={isPending}>
602
+ * {isPending ? "Executing..." : "Swap"}
603
+ * </button>
604
+ * );
605
+ * }
606
+ * ```
607
+ */
608
+ declare function useInteract(): UseOperationMutationResult<SimpleInteractParams, InteractResult>;
609
+
610
+ type BurnerSendInput = {
611
+ index: number;
612
+ tx: BurnerSendParams;
613
+ };
614
+ type BurnerFundInput = {
615
+ index: number;
616
+ params: SimpleBurnerFundParams;
617
+ };
618
+ type BurnerSweepInput = {
619
+ index: number;
620
+ params: SimpleBurnerSweepToPoolParams;
621
+ };
622
+ type UseBurnerResult = {
623
+ burners: BurnerAccount[];
624
+ createBurner: (index: number) => Promise<BurnerAccount>;
625
+ removeBurner: (index: number) => void;
626
+ send: UseOperationMutationResult<BurnerSendInput, {
627
+ txHash: string;
628
+ }>;
629
+ fund: UseOperationMutationResult<BurnerFundInput, WithdrawResult>;
630
+ sweepToPool: UseOperationMutationResult<BurnerSweepInput, {
631
+ txHash: string;
632
+ }>;
633
+ getTokenBalance: (address: string, token: string) => Promise<bigint>;
634
+ getBalance: (address: string) => Promise<bigint>;
635
+ };
636
+ /**
637
+ * Hook for burner account operations.
638
+ *
639
+ * `exportKey` is intentionally excluded here and can be accessed via
640
+ * `useUnlink().wallet?.burner.exportKey(index)`.
641
+ */
642
+ declare function useBurner(): UseBurnerResult;
551
643
 
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 };
644
+ export { type BurnerFundInput, type BurnerSendInput, type BurnerSweepInput, CONFIRMATION_POLL_INTERVAL_MS, DEFAULT_CONFIRMATION_TIMEOUT_MS, type DepositInput, 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 UseOperationMutationResult, type UseTxStatusResult, type UseUnlinkBalanceResult, type UseUnlinkHistoryOptions, type UseUnlinkHistoryResult, type WaitForConfirmationOptions, type WalletNote, type WithdrawInput, useBurner, useDeposit, useInteract, useOperationMutation, useSend, useTxStatus, useUnlink, useUnlinkBalance, useUnlinkBalances, useUnlinkHistory, useWithdraw };