@unlink-xyz/react 0.1.3-canary.9185ea0 → 0.1.3-canary.9329a34

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, 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.
@@ -79,6 +79,8 @@ 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
86
  /** Pending transfer jobs */
@@ -182,6 +184,24 @@ type UnlinkActions = {
182
184
  planWithdraw(params: WithdrawInput[]): Promise<WithdrawPlanResult>;
183
185
  /** Execute a pre-built withdrawal plan */
184
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>;
185
205
  /**
186
206
  * Execute an atomic private adapter flow (unshield -> calls -> reshield).
187
207
  */
@@ -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" | "executeTransfer" | "requestDeposit" | "requestWithdraw" | "executeAdapter" | "executeWithdraw" | "createBurner" | "burnerSend" | "burnerFund" | "burnerSweepToPool" | "refresh" | "forceResync";
278
298
  /**
279
299
  * Structured error type for the Unlink context.
280
300
  */
@@ -584,4 +604,38 @@ declare function useWithdraw(): UseOperationMutationResult<WithdrawInput[], With
584
604
  */
585
605
  declare function useAdapter(): UseOperationMutationResult<SimpleAdapterExecuteParams, AdapterExecuteResult>;
586
606
 
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 };
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 };
package/dist/index.js CHANGED
@@ -55656,6 +55656,16 @@ function createAdapterService(deps) {
55656
55656
  const reshieldSpecs = params.reshields.map(
55657
55657
  (reshield, i) => normalizeReshieldSpec(reshield, i)
55658
55658
  );
55659
+ const seenReshieldTokens = /* @__PURE__ */ new Set();
55660
+ for (const r2 of reshieldSpecs) {
55661
+ const lower = r2.token.toLowerCase();
55662
+ if (seenReshieldTokens.has(lower)) {
55663
+ throw new AdapterError(
55664
+ `duplicate reshield token ${r2.token}; each reshield must target a unique token`
55665
+ );
55666
+ }
55667
+ seenReshieldTokens.add(lower);
55668
+ }
55659
55669
  const account = overrides?.account ?? await deps.requireActiveAccount();
55660
55670
  const signer = overrides?.signer ?? deps.requireSigner(account);
55661
55671
  const nowSeconds = BigInt(Math.floor(nowImpl() / 1e3));
@@ -56957,6 +56967,7 @@ var initialState = {
56957
56967
  chainId: null,
56958
56968
  notes: [],
56959
56969
  balances: {},
56970
+ burners: [],
56960
56971
  pendingDeposits: [],
56961
56972
  pendingTransfers: [],
56962
56973
  pendingWithdrawals: [],
@@ -57178,6 +57189,7 @@ function UnlinkProvider({
57178
57189
  accounts,
57179
57190
  activeAccount,
57180
57191
  activeAccountIndex,
57192
+ burners: [],
57181
57193
  busy: false,
57182
57194
  status: accounts.length > 0 ? "Wallet imported" : "Wallet imported - create an account",
57183
57195
  syncError: null,
@@ -57212,6 +57224,7 @@ function UnlinkProvider({
57212
57224
  activeAccountIndex: null,
57213
57225
  notes: [],
57214
57226
  balances: {},
57227
+ burners: [],
57215
57228
  busy: false,
57216
57229
  status: "Wallet cleared",
57217
57230
  syncError: null,
@@ -57567,6 +57580,149 @@ function UnlinkProvider({
57567
57580
  throw err;
57568
57581
  }
57569
57582
  }, []);
57583
+ const createBurner = useCallback(async (index) => {
57584
+ const wallet = walletRef.current;
57585
+ if (!wallet) throw new Error("SDK not initialized");
57586
+ setState((prev2) => ({
57587
+ ...prev2,
57588
+ busy: true,
57589
+ status: `Creating burner ${index}...`
57590
+ }));
57591
+ try {
57592
+ const burner = await wallet.burner.addressOf(index);
57593
+ setState((prev2) => ({
57594
+ ...prev2,
57595
+ burners: [
57596
+ ...prev2.burners.filter((existing) => existing.index !== burner.index),
57597
+ burner
57598
+ ],
57599
+ busy: false,
57600
+ status: `Burner ${index} ready`,
57601
+ error: null
57602
+ }));
57603
+ return burner;
57604
+ } catch (err) {
57605
+ setState((prev2) => ({
57606
+ ...prev2,
57607
+ busy: false,
57608
+ status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
57609
+ error: createUnlinkError(err, "createBurner")
57610
+ }));
57611
+ throw err;
57612
+ }
57613
+ }, []);
57614
+ const removeBurner = useCallback((index) => {
57615
+ setState((prev2) => ({
57616
+ ...prev2,
57617
+ burners: prev2.burners.filter((burner) => burner.index !== index)
57618
+ }));
57619
+ }, []);
57620
+ const burnerSend = useCallback(
57621
+ async (index, tx) => {
57622
+ const wallet = walletRef.current;
57623
+ if (!wallet) throw new Error("SDK not initialized");
57624
+ setState((prev2) => ({
57625
+ ...prev2,
57626
+ busy: true,
57627
+ status: "Sending burner transaction..."
57628
+ }));
57629
+ try {
57630
+ const result = await wallet.burner.send(index, tx);
57631
+ setState((prev2) => ({
57632
+ ...prev2,
57633
+ busy: false,
57634
+ status: "Burner transaction sent",
57635
+ error: null
57636
+ }));
57637
+ return result;
57638
+ } catch (err) {
57639
+ setState((prev2) => ({
57640
+ ...prev2,
57641
+ busy: false,
57642
+ status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
57643
+ error: createUnlinkError(err, "burnerSend")
57644
+ }));
57645
+ throw err;
57646
+ }
57647
+ },
57648
+ []
57649
+ );
57650
+ const burnerFund = useCallback(
57651
+ async (index, params) => {
57652
+ const wallet = walletRef.current;
57653
+ if (!wallet) throw new Error("SDK not initialized");
57654
+ setState((prev2) => ({
57655
+ ...prev2,
57656
+ busy: true,
57657
+ status: "Funding burner..."
57658
+ }));
57659
+ try {
57660
+ const result = await wallet.burner.fund(index, params);
57661
+ setState((prev2) => ({
57662
+ ...prev2,
57663
+ busy: false,
57664
+ status: "Burner funded",
57665
+ error: null
57666
+ }));
57667
+ return result;
57668
+ } catch (err) {
57669
+ setState((prev2) => ({
57670
+ ...prev2,
57671
+ busy: false,
57672
+ status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
57673
+ error: createUnlinkError(err, "burnerFund")
57674
+ }));
57675
+ throw err;
57676
+ }
57677
+ },
57678
+ []
57679
+ );
57680
+ const burnerSweepToPool = useCallback(
57681
+ async (index, params) => {
57682
+ const wallet = walletRef.current;
57683
+ if (!wallet) throw new Error("SDK not initialized");
57684
+ setState((prev2) => ({
57685
+ ...prev2,
57686
+ busy: true,
57687
+ status: "Sweeping burner to pool..."
57688
+ }));
57689
+ try {
57690
+ const result = await wallet.burner.sweepToPool(index, params);
57691
+ setState((prev2) => ({
57692
+ ...prev2,
57693
+ busy: false,
57694
+ status: "Burner sweep submitted",
57695
+ error: null
57696
+ }));
57697
+ return result;
57698
+ } catch (err) {
57699
+ setState((prev2) => ({
57700
+ ...prev2,
57701
+ busy: false,
57702
+ status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
57703
+ error: createUnlinkError(err, "burnerSweepToPool")
57704
+ }));
57705
+ throw err;
57706
+ }
57707
+ },
57708
+ []
57709
+ );
57710
+ const burnerGetTokenBalance = useCallback(
57711
+ async (address, token) => {
57712
+ const wallet = walletRef.current;
57713
+ if (!wallet) throw new Error("SDK not initialized");
57714
+ return wallet.burner.getTokenBalance(address, token);
57715
+ },
57716
+ []
57717
+ );
57718
+ const burnerGetBalance = useCallback(
57719
+ async (address) => {
57720
+ const wallet = walletRef.current;
57721
+ if (!wallet) throw new Error("SDK not initialized");
57722
+ return wallet.burner.getBalance(address);
57723
+ },
57724
+ []
57725
+ );
57570
57726
  const refresh = useCallback(async () => {
57571
57727
  const wallet = walletRef.current;
57572
57728
  if (!wallet) return;
@@ -57702,6 +57858,14 @@ function UnlinkProvider({
57702
57858
  executeAdapter,
57703
57859
  planWithdraw,
57704
57860
  executeWithdraw,
57861
+ // Burner actions
57862
+ createBurner,
57863
+ removeBurner,
57864
+ burnerSend,
57865
+ burnerFund,
57866
+ burnerSweepToPool,
57867
+ burnerGetTokenBalance,
57868
+ burnerGetBalance,
57705
57869
  // Sync actions
57706
57870
  refresh,
57707
57871
  forceResync,
@@ -57727,6 +57891,13 @@ function UnlinkProvider({
57727
57891
  executeAdapter,
57728
57892
  planWithdraw,
57729
57893
  executeWithdraw,
57894
+ createBurner,
57895
+ removeBurner,
57896
+ burnerSend,
57897
+ burnerFund,
57898
+ burnerSweepToPool,
57899
+ burnerGetTokenBalance,
57900
+ burnerGetBalance,
57730
57901
  refresh,
57731
57902
  forceResync,
57732
57903
  clearError,
@@ -57973,6 +58144,46 @@ function useAdapter() {
57973
58144
  );
57974
58145
  return useOperationMutation(op);
57975
58146
  }
58147
+
58148
+ // src/useBurner.ts
58149
+ import { useCallback as useCallback9 } from "react";
58150
+ function useBurner() {
58151
+ const {
58152
+ burners,
58153
+ createBurner,
58154
+ removeBurner,
58155
+ burnerSend,
58156
+ burnerFund,
58157
+ burnerSweepToPool,
58158
+ burnerGetTokenBalance,
58159
+ burnerGetBalance
58160
+ } = useUnlink();
58161
+ const sendOp = useCallback9(
58162
+ (input) => burnerSend(input.index, input.tx),
58163
+ [burnerSend]
58164
+ );
58165
+ const fundOp = useCallback9(
58166
+ (input) => burnerFund(input.index, input.params),
58167
+ [burnerFund]
58168
+ );
58169
+ const sweepOp = useCallback9(
58170
+ (input) => burnerSweepToPool(input.index, input.params),
58171
+ [burnerSweepToPool]
58172
+ );
58173
+ const send = useOperationMutation(sendOp);
58174
+ const fund = useOperationMutation(fundOp);
58175
+ const sweepToPool = useOperationMutation(sweepOp);
58176
+ return {
58177
+ burners,
58178
+ createBurner,
58179
+ removeBurner,
58180
+ send,
58181
+ fund,
58182
+ sweepToPool,
58183
+ getTokenBalance: burnerGetTokenBalance,
58184
+ getBalance: burnerGetBalance
58185
+ };
58186
+ }
57976
58187
  export {
57977
58188
  CONFIRMATION_POLL_INTERVAL_MS,
57978
58189
  DEFAULT_CONFIRMATION_TIMEOUT_MS,
@@ -57990,6 +58201,7 @@ export {
57990
58201
  randomHex,
57991
58202
  shortenHex,
57992
58203
  useAdapter,
58204
+ useBurner,
57993
58205
  useDeposit,
57994
58206
  useOperationMutation,
57995
58207
  useTransfer,