@unlink-xyz/react 0.1.6 → 0.1.8
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 +50 -40
- package/dist/index.js +449 -334
- package/dist/index.js.map +1 -1
- package/dist/multisig/index.d.ts +1 -1
- package/dist/multisig/index.js +70 -70
- package/dist/multisig/index.js.map +1 -1
- package/package.json +3 -3
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,
|
|
4
|
-
export { Account, AccountInfo,
|
|
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
|
|
26
|
+
type PendingSendJob = PendingJobBase & {
|
|
27
27
|
recipient: string;
|
|
28
28
|
};
|
|
29
29
|
type PendingWithdrawJob = PendingJobBase & {
|
|
@@ -63,8 +63,8 @@ type UnlinkConfig = UnlinkConfigBase & ({
|
|
|
63
63
|
* State exposed by the useUnlink hook.
|
|
64
64
|
*/
|
|
65
65
|
type UnlinkState = {
|
|
66
|
-
/** The underlying
|
|
67
|
-
|
|
66
|
+
/** The underlying Unlink instance */
|
|
67
|
+
unlink: Unlink | null;
|
|
68
68
|
/** Whether a wallet (mnemonic) exists */
|
|
69
69
|
walletExists: boolean;
|
|
70
70
|
/** All derived accounts */
|
|
@@ -83,8 +83,8 @@ type UnlinkState = {
|
|
|
83
83
|
burners: BurnerAccount[];
|
|
84
84
|
/** Pending deposit jobs */
|
|
85
85
|
pendingDeposits: PendingDepositJob[];
|
|
86
|
-
/** Pending
|
|
87
|
-
|
|
86
|
+
/** Pending send jobs */
|
|
87
|
+
pendingSends: PendingSendJob[];
|
|
88
88
|
/** Pending withdraw jobs */
|
|
89
89
|
pendingWithdrawals: PendingWithdrawJob[];
|
|
90
90
|
/** Whether the SDK is initialized and ready */
|
|
@@ -99,9 +99,9 @@ type UnlinkState = {
|
|
|
99
99
|
error: UnlinkError | null;
|
|
100
100
|
};
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
102
|
+
* Send parameters for useUnlink.send()
|
|
103
103
|
*/
|
|
104
|
-
type
|
|
104
|
+
type SendInput = {
|
|
105
105
|
token: string;
|
|
106
106
|
/** Unlink address (unlink1... bech32m) */
|
|
107
107
|
recipient: string;
|
|
@@ -117,7 +117,7 @@ type DepositInput = {
|
|
|
117
117
|
depositor: string;
|
|
118
118
|
};
|
|
119
119
|
/**
|
|
120
|
-
* Withdraw parameters for useUnlink.
|
|
120
|
+
* Withdraw parameters for useUnlink.withdraw()
|
|
121
121
|
*/
|
|
122
122
|
type WithdrawInput = WithdrawalInput;
|
|
123
123
|
/**
|
|
@@ -143,28 +143,28 @@ type UnlinkActions = {
|
|
|
143
143
|
* Multiple transfers are processed atomically.
|
|
144
144
|
*
|
|
145
145
|
* @param params - Array of transfers (token + amount + recipient)
|
|
146
|
-
* @returns
|
|
146
|
+
* @returns SendResult with array of plans
|
|
147
147
|
*/
|
|
148
|
-
send(params:
|
|
148
|
+
send(params: SendInput[], overrides?: SignerOverride): Promise<SendResult>;
|
|
149
149
|
/**
|
|
150
|
-
* Get a
|
|
150
|
+
* Get a send plan without executing (for preview).
|
|
151
151
|
* Validates balances and returns plans for each transfer.
|
|
152
152
|
*
|
|
153
153
|
* @param params - Array of transfers (token + amount + recipient)
|
|
154
154
|
* @returns Array of TransactionPlan
|
|
155
155
|
*/
|
|
156
|
-
|
|
157
|
-
/** Execute a pre-built
|
|
158
|
-
|
|
156
|
+
planSend(params: SendInput[]): Promise<SendPlanResult>;
|
|
157
|
+
/** Execute a pre-built send plan */
|
|
158
|
+
executeSend(plans: SendPlanResult, overrides?: SignerOverride): Promise<SendResult>;
|
|
159
159
|
/**
|
|
160
|
-
*
|
|
160
|
+
* Deposit (1 or more tokens).
|
|
161
161
|
* Returns calldata that the user must submit on-chain via their EOA.
|
|
162
162
|
* Use the returned `to` and `calldata` fields to construct the transaction.
|
|
163
163
|
*
|
|
164
164
|
* @param params - Array of deposits (token + amount + depositor)
|
|
165
165
|
* @returns DepositRelayResult with array of commitments
|
|
166
166
|
*/
|
|
167
|
-
|
|
167
|
+
deposit(params: DepositInput[]): Promise<DepositRelayResult>;
|
|
168
168
|
/**
|
|
169
169
|
* High-level withdraw (1 or more tokens).
|
|
170
170
|
* Specify recipient EOA + amount for each withdrawal.
|
|
@@ -173,7 +173,7 @@ type UnlinkActions = {
|
|
|
173
173
|
* @param params - Array of withdrawals (token + amount + recipient)
|
|
174
174
|
* @returns WithdrawResult with array of plans
|
|
175
175
|
*/
|
|
176
|
-
|
|
176
|
+
withdraw(params: WithdrawInput[], overrides?: SignerOverride): Promise<WithdrawResult>;
|
|
177
177
|
/**
|
|
178
178
|
* Get a withdrawal plan without executing (for preview).
|
|
179
179
|
* Validates balances and returns plans for each withdrawal.
|
|
@@ -203,9 +203,9 @@ type UnlinkActions = {
|
|
|
203
203
|
/** Get native balance for address */
|
|
204
204
|
burnerGetBalance(address: string): Promise<bigint>;
|
|
205
205
|
/**
|
|
206
|
-
* Execute an atomic private
|
|
206
|
+
* Execute an atomic private DeFi flow (unshield -> calls -> reshield).
|
|
207
207
|
*/
|
|
208
|
-
|
|
208
|
+
interact(params: SimpleInteractParams): Promise<InteractResult>;
|
|
209
209
|
/** Refresh notes and balances */
|
|
210
210
|
refresh(): Promise<void>;
|
|
211
211
|
/** Force full resync from chain */
|
|
@@ -294,7 +294,7 @@ type UnlinkErrorCode = "UNKNOWN" | "SDK_NOT_INITIALIZED" | "NETWORK_ERROR" | "VA
|
|
|
294
294
|
/**
|
|
295
295
|
* Operations that can trigger an error in the Unlink context.
|
|
296
296
|
*/
|
|
297
|
-
type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "
|
|
297
|
+
type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "executeSend" | "deposit" | "withdraw" | "interact" | "executeWithdraw" | "createBurner" | "burnerSend" | "burnerFund" | "burnerSweepToPool" | "refresh" | "forceResync";
|
|
298
298
|
/**
|
|
299
299
|
* Structured error type for the Unlink context.
|
|
300
300
|
*/
|
|
@@ -350,7 +350,7 @@ type UseUnlinkHistoryResult = {
|
|
|
350
350
|
refresh: () => Promise<void>;
|
|
351
351
|
};
|
|
352
352
|
/**
|
|
353
|
-
* Hook to get transaction history for the
|
|
353
|
+
* Hook to get transaction history for the Unlink instance.
|
|
354
354
|
*
|
|
355
355
|
* Uses the SDK's history service which provides properly categorized
|
|
356
356
|
* transaction entries (Deposit, Receive, Send, SelfSend, Withdraw).
|
|
@@ -477,6 +477,13 @@ type UseOperationMutationResult<TInput, TOutput> = {
|
|
|
477
477
|
/** Reset state back to idle */
|
|
478
478
|
reset: () => void;
|
|
479
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
|
+
};
|
|
480
487
|
/**
|
|
481
488
|
* Generic async mutation state machine for wallet operations.
|
|
482
489
|
*
|
|
@@ -486,8 +493,8 @@ type UseOperationMutationResult<TInput, TOutput> = {
|
|
|
486
493
|
* @example
|
|
487
494
|
* ```tsx
|
|
488
495
|
* function DepositButton() {
|
|
489
|
-
* const {
|
|
490
|
-
* const { execute, isPending, error } = useOperationMutation(
|
|
496
|
+
* const { deposit } = useUnlink();
|
|
497
|
+
* const { execute, isPending, error } = useOperationMutation(deposit);
|
|
491
498
|
*
|
|
492
499
|
* return (
|
|
493
500
|
* <button onClick={() => execute(params)} disabled={isPending}>
|
|
@@ -499,13 +506,14 @@ type UseOperationMutationResult<TInput, TOutput> = {
|
|
|
499
506
|
*/
|
|
500
507
|
declare function useOperationMutation<TInput, TOutput>(operation: (input: TInput) => Promise<TOutput>): UseOperationMutationResult<TInput, TOutput>;
|
|
501
508
|
|
|
509
|
+
type UseDepositResult = NamedMutationResult<"deposit", DepositInput[], DepositRelayResult>;
|
|
502
510
|
/**
|
|
503
511
|
* Hook for requesting deposits with loading/error state.
|
|
504
512
|
*
|
|
505
513
|
* @example
|
|
506
514
|
* ```tsx
|
|
507
515
|
* function DepositForm() {
|
|
508
|
-
* const {
|
|
516
|
+
* const { deposit, isPending, error } = useDeposit();
|
|
509
517
|
*
|
|
510
518
|
* const handleDeposit = async () => {
|
|
511
519
|
* const result = await deposit([
|
|
@@ -522,8 +530,9 @@ declare function useOperationMutation<TInput, TOutput>(operation: (input: TInput
|
|
|
522
530
|
* }
|
|
523
531
|
* ```
|
|
524
532
|
*/
|
|
525
|
-
declare function useDeposit():
|
|
533
|
+
declare function useDeposit(): UseDepositResult;
|
|
526
534
|
|
|
535
|
+
type UseSendResult = NamedMutationResult<"send", SendInput[], SendResult>;
|
|
527
536
|
/**
|
|
528
537
|
* Hook for sending private transfers with loading/error state.
|
|
529
538
|
*
|
|
@@ -532,7 +541,7 @@ declare function useDeposit(): UseOperationMutationResult<DepositInput[], Deposi
|
|
|
532
541
|
* @example
|
|
533
542
|
* ```tsx
|
|
534
543
|
* function SendForm() {
|
|
535
|
-
* const {
|
|
544
|
+
* const { send, isPending, error } = useSend();
|
|
536
545
|
*
|
|
537
546
|
* const handleSend = async () => {
|
|
538
547
|
* const result = await send([
|
|
@@ -549,8 +558,9 @@ declare function useDeposit(): UseOperationMutationResult<DepositInput[], Deposi
|
|
|
549
558
|
* }
|
|
550
559
|
* ```
|
|
551
560
|
*/
|
|
552
|
-
declare function
|
|
561
|
+
declare function useSend(overrides?: SignerOverride): UseSendResult;
|
|
553
562
|
|
|
563
|
+
type UseWithdrawResult = NamedMutationResult<"withdraw", WithdrawInput[], WithdrawResult>;
|
|
554
564
|
/**
|
|
555
565
|
* Hook for requesting withdrawals with loading/error state.
|
|
556
566
|
*
|
|
@@ -559,7 +569,7 @@ declare function useTransfer(overrides?: SignerOverride): UseOperationMutationRe
|
|
|
559
569
|
* @example
|
|
560
570
|
* ```tsx
|
|
561
571
|
* function WithdrawForm() {
|
|
562
|
-
* const {
|
|
572
|
+
* const { withdraw, isPending, error } = useWithdraw();
|
|
563
573
|
*
|
|
564
574
|
* const handleWithdraw = async () => {
|
|
565
575
|
* const result = await withdraw([
|
|
@@ -576,24 +586,24 @@ declare function useTransfer(overrides?: SignerOverride): UseOperationMutationRe
|
|
|
576
586
|
* }
|
|
577
587
|
* ```
|
|
578
588
|
*/
|
|
579
|
-
declare function useWithdraw(overrides?: SignerOverride):
|
|
589
|
+
declare function useWithdraw(overrides?: SignerOverride): UseWithdrawResult;
|
|
580
590
|
|
|
591
|
+
type UseInteractResult = NamedMutationResult<"interact", SimpleInteractParams, InteractResult>;
|
|
581
592
|
/**
|
|
582
|
-
* Hook for executing private DeFi
|
|
593
|
+
* Hook for executing private DeFi interactions with loading/error state.
|
|
583
594
|
*
|
|
584
595
|
* Performs atomic unshield → DeFi call(s) → reshield flows through an adapter contract.
|
|
585
596
|
*
|
|
586
597
|
* @example
|
|
587
598
|
* ```tsx
|
|
588
599
|
* function SwapButton() {
|
|
589
|
-
* const {
|
|
600
|
+
* const { interact, isPending, error } = useInteract();
|
|
590
601
|
*
|
|
591
602
|
* const handleSwap = async () => {
|
|
592
|
-
* const result = await
|
|
593
|
-
*
|
|
594
|
-
* inputs: [{ token: "0x...", amount: 1000n }],
|
|
603
|
+
* const result = await interact({
|
|
604
|
+
* spend: [{ token: "0x...", amount: 1000n }],
|
|
595
605
|
* calls: [approveCall, swapCall],
|
|
596
|
-
*
|
|
606
|
+
* receive: [{ token: "0x...", minAmount: 500n }],
|
|
597
607
|
* });
|
|
598
608
|
* console.log("Relay ID:", result.relayId);
|
|
599
609
|
* };
|
|
@@ -606,7 +616,7 @@ declare function useWithdraw(overrides?: SignerOverride): UseOperationMutationRe
|
|
|
606
616
|
* }
|
|
607
617
|
* ```
|
|
608
618
|
*/
|
|
609
|
-
declare function
|
|
619
|
+
declare function useInteract(): UseInteractResult;
|
|
610
620
|
|
|
611
621
|
type BurnerSendInput = {
|
|
612
622
|
index: number;
|
|
@@ -638,8 +648,8 @@ type UseBurnerResult = {
|
|
|
638
648
|
* Hook for burner account operations.
|
|
639
649
|
*
|
|
640
650
|
* `exportKey` is intentionally excluded here and can be accessed via
|
|
641
|
-
* `useUnlink().
|
|
651
|
+
* `useUnlink().unlink?.burner.exportKey(index)`.
|
|
642
652
|
*/
|
|
643
653
|
declare function useBurner(): UseBurnerResult;
|
|
644
654
|
|
|
645
|
-
export { type BurnerFundInput, type BurnerSendInput, type BurnerSweepInput, CONFIRMATION_POLL_INTERVAL_MS, DEFAULT_CONFIRMATION_TIMEOUT_MS, type DepositInput, type PendingDepositJob, type
|
|
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 };
|