@unlink-xyz/react 0.1.3-canary.b0ad588 → 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, SupportedChain, UnlinkWallet, AccountInfo, Account, NoteRecord, HistoryStatus, TransferResult, TransferPlanResult, DepositRelayResult, WithdrawalInput, WithdrawResult, WithdrawPlanResult, SimpleAdapterExecuteParams, AdapterExecuteResult, RelayState, HistoryEntry } from '@unlink-xyz/core';
4
- export { Account, AccountInfo, AdapterExecuteResult, AdapterExecutionCall, Chain, HistoryEntry, InputTokenSpec, NoteRecord, ParsedZkAddress, ReshieldInput, SimpleAdapterExecuteParams, SupportedChain, 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 & {
@@ -79,10 +79,12 @@ type UnlinkState = {
79
79
  notes: WalletNote[];
80
80
  /** Token balances by address */
81
81
  balances: Record<string, bigint>;
82
+ /** Tracked burner accounts */
83
+ burners: BurnerAccount[];
82
84
  /** Pending deposit jobs */
83
85
  pendingDeposits: PendingDepositJob[];
84
- /** Pending transfer jobs */
85
- pendingTransfers: PendingTransferJob[];
86
+ /** Pending send jobs */
87
+ pendingSends: PendingSendJob[];
86
88
  /** Pending withdraw jobs */
87
89
  pendingWithdrawals: PendingWithdrawJob[];
88
90
  /** Whether the SDK is initialized and ready */
@@ -97,11 +99,11 @@ type UnlinkState = {
97
99
  error: UnlinkError | null;
98
100
  };
99
101
  /**
100
- * Transfer parameters for useUnlink.send()
102
+ * Send parameters for useUnlink.send()
101
103
  */
102
- type TransferInput = {
104
+ type SendInput = {
103
105
  token: string;
104
- /** Unlink address (0zk1... bech32m) */
106
+ /** Unlink address (unlink1... bech32m) */
105
107
  recipient: string;
106
108
  amount: bigint;
107
109
  };
@@ -115,7 +117,7 @@ type DepositInput = {
115
117
  depositor: string;
116
118
  };
117
119
  /**
118
- * Withdraw parameters for useUnlink.requestWithdraw()
120
+ * Withdraw parameters for useUnlink.withdraw()
119
121
  */
120
122
  type WithdrawInput = WithdrawalInput;
121
123
  /**
@@ -141,28 +143,28 @@ type UnlinkActions = {
141
143
  * Multiple transfers are processed atomically.
142
144
  *
143
145
  * @param params - Array of transfers (token + amount + recipient)
144
- * @returns TransferResult with array of plans
146
+ * @returns SendResult with array of plans
145
147
  */
146
- send(params: TransferInput[]): Promise<TransferResult>;
148
+ send(params: SendInput[], overrides?: SignerOverride): Promise<SendResult>;
147
149
  /**
148
- * Get a transfer plan without executing (for preview).
150
+ * Get a send plan without executing (for preview).
149
151
  * Validates balances and returns plans for each transfer.
150
152
  *
151
153
  * @param params - Array of transfers (token + amount + recipient)
152
154
  * @returns Array of TransactionPlan
153
155
  */
154
- planTransfer(params: TransferInput[]): Promise<TransferPlanResult>;
155
- /** Execute a pre-built transfer plan */
156
- 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>;
157
159
  /**
158
- * Request a deposit (1 or more tokens).
160
+ * Deposit (1 or more tokens).
159
161
  * Returns calldata that the user must submit on-chain via their EOA.
160
162
  * Use the returned `to` and `calldata` fields to construct the transaction.
161
163
  *
162
164
  * @param params - Array of deposits (token + amount + depositor)
163
165
  * @returns DepositRelayResult with array of commitments
164
166
  */
165
- requestDeposit(params: DepositInput[]): Promise<DepositRelayResult>;
167
+ deposit(params: DepositInput[]): Promise<DepositRelayResult>;
166
168
  /**
167
169
  * High-level withdraw (1 or more tokens).
168
170
  * Specify recipient EOA + amount for each withdrawal.
@@ -171,7 +173,7 @@ type UnlinkActions = {
171
173
  * @param params - Array of withdrawals (token + amount + recipient)
172
174
  * @returns WithdrawResult with array of plans
173
175
  */
174
- requestWithdraw(params: WithdrawInput[]): Promise<WithdrawResult>;
176
+ withdraw(params: WithdrawInput[], overrides?: SignerOverride): Promise<WithdrawResult>;
175
177
  /**
176
178
  * Get a withdrawal plan without executing (for preview).
177
179
  * Validates balances and returns plans for each withdrawal.
@@ -181,11 +183,29 @@ type UnlinkActions = {
181
183
  */
182
184
  planWithdraw(params: WithdrawInput[]): Promise<WithdrawPlanResult>;
183
185
  /** Execute a pre-built withdrawal plan */
184
- 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>;
185
205
  /**
186
- * Execute an atomic private adapter flow (unshield -> calls -> reshield).
206
+ * Execute an atomic private DeFi flow (unshield -> calls -> reshield).
187
207
  */
188
- executeAdapter(params: SimpleAdapterExecuteParams): Promise<AdapterExecuteResult>;
208
+ interact(params: SimpleInteractParams): Promise<InteractResult>;
189
209
  /** Refresh notes and balances */
190
210
  refresh(): Promise<void>;
191
211
  /** Force full resync from chain */
@@ -274,7 +294,7 @@ type UnlinkErrorCode = "UNKNOWN" | "SDK_NOT_INITIALIZED" | "NETWORK_ERROR" | "VA
274
294
  /**
275
295
  * Operations that can trigger an error in the Unlink context.
276
296
  */
277
- type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "executeTransfer" | "requestDeposit" | "requestWithdraw" | "executeAdapter" | "executeWithdraw" | "refresh" | "forceResync";
297
+ type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "executeSend" | "deposit" | "withdraw" | "interact" | "executeWithdraw" | "createBurner" | "burnerSend" | "burnerFund" | "burnerSweepToPool" | "refresh" | "forceResync";
278
298
  /**
279
299
  * Structured error type for the Unlink context.
280
300
  */
@@ -442,8 +462,8 @@ declare function useUnlinkBalances(): {
442
462
  declare function useTxStatus(txId: string | null): UseTxStatusResult;
443
463
 
444
464
  type UseOperationMutationResult<TInput, TOutput> = {
445
- /** Execute the mutation */
446
- mutate: (input: TInput) => Promise<TOutput>;
465
+ /** Execute the operation */
466
+ execute: (input: TInput) => Promise<TOutput>;
447
467
  /** Last successful result */
448
468
  data: TOutput | null;
449
469
  /** Whether the mutation is currently running */
@@ -466,11 +486,11 @@ type UseOperationMutationResult<TInput, TOutput> = {
466
486
  * @example
467
487
  * ```tsx
468
488
  * function DepositButton() {
469
- * const { requestDeposit } = useUnlink();
470
- * const { mutate, isPending, error } = useOperationMutation(requestDeposit);
489
+ * const { deposit } = useUnlink();
490
+ * const { execute, isPending, error } = useOperationMutation(deposit);
471
491
  *
472
492
  * return (
473
- * <button onClick={() => mutate(params)} disabled={isPending}>
493
+ * <button onClick={() => execute(params)} disabled={isPending}>
474
494
  * {isPending ? "Depositing..." : "Deposit"}
475
495
  * </button>
476
496
  * );
@@ -507,14 +527,16 @@ declare function useDeposit(): UseOperationMutationResult<DepositInput[], Deposi
507
527
  /**
508
528
  * Hook for sending private transfers with loading/error state.
509
529
  *
530
+ * @param overrides - Optional signer override for multisig transactions
531
+ *
510
532
  * @example
511
533
  * ```tsx
512
534
  * function SendForm() {
513
- * const { mutate: send, isPending, error } = useTransfer();
535
+ * const { mutate: send, isPending, error } = useSend();
514
536
  *
515
537
  * const handleSend = async () => {
516
538
  * const result = await send([
517
- * { token: "0x...", recipient: "0zk1...", amount: 100n },
539
+ * { token: "0x...", recipient: "unlink1...", amount: 100n },
518
540
  * ]);
519
541
  * console.log("Relay ID:", result.relayId);
520
542
  * };
@@ -527,11 +549,13 @@ declare function useDeposit(): UseOperationMutationResult<DepositInput[], Deposi
527
549
  * }
528
550
  * ```
529
551
  */
530
- declare function useTransfer(): UseOperationMutationResult<TransferInput[], TransferResult>;
552
+ declare function useSend(overrides?: SignerOverride): UseOperationMutationResult<SendInput[], SendResult>;
531
553
 
532
554
  /**
533
555
  * Hook for requesting withdrawals with loading/error state.
534
556
  *
557
+ * @param overrides - Optional signer override for multisig transactions
558
+ *
535
559
  * @example
536
560
  * ```tsx
537
561
  * function WithdrawForm() {
@@ -552,24 +576,23 @@ declare function useTransfer(): UseOperationMutationResult<TransferInput[], Tran
552
576
  * }
553
577
  * ```
554
578
  */
555
- declare function useWithdraw(): UseOperationMutationResult<WithdrawInput[], WithdrawResult>;
579
+ declare function useWithdraw(overrides?: SignerOverride): UseOperationMutationResult<WithdrawInput[], WithdrawResult>;
556
580
 
557
581
  /**
558
- * Hook for executing private DeFi adapter operations with loading/error state.
582
+ * Hook for executing private DeFi interactions with loading/error state.
559
583
  *
560
584
  * Performs atomic unshield → DeFi call(s) → reshield flows through an adapter contract.
561
585
  *
562
586
  * @example
563
587
  * ```tsx
564
588
  * function SwapButton() {
565
- * const { mutate: executeAdapter, isPending, error } = useAdapter();
589
+ * const { mutate: interact, isPending, error } = useInteract();
566
590
  *
567
591
  * const handleSwap = async () => {
568
- * const result = await executeAdapter({
569
- * adapterAddress: "0x...",
570
- * inputs: [{ token: "0x...", amount: 1000n }],
592
+ * const result = await interact({
593
+ * spend: [{ token: "0x...", amount: 1000n }],
571
594
  * calls: [approveCall, swapCall],
572
- * reshields: [{ token: "0x...", minAmount: 500n }],
595
+ * receive: [{ token: "0x...", minAmount: 500n }],
573
596
  * });
574
597
  * console.log("Relay ID:", result.relayId);
575
598
  * };
@@ -582,6 +605,40 @@ declare function useWithdraw(): UseOperationMutationResult<WithdrawInput[], With
582
605
  * }
583
606
  * ```
584
607
  */
585
- declare function useAdapter(): UseOperationMutationResult<SimpleAdapterExecuteParams, AdapterExecuteResult>;
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;
586
643
 
587
- 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, useAdapter, 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 };