@bestinslot/wallet-kit 0.15.0 → 0.16.0-rc.0

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/node.js CHANGED
@@ -1,7 +1,7 @@
1
- import { F as eI, G as RA, H as f, I as tI, J as SI, K as UA, L as d, M as zA, N as mA, O as e, P as qA, Q as nI, R as pI, S as rI, T as sI, U as FI, V as KI, X as BA, f as XA, m as eA, Y as RI, c as UI, Z as qI, W as VI, a as lI, b as dI, d as xI, e as YI, h as JI, i as PI, j as vI, k as OI, s as uI, l as jI, n as bI, o as LI, p as TI, q as ZI, r as zI } from "./helpers-DhmRTIg0.js";
2
- import { B as WQ, v as _Q, w as $Q, u as AC, D as IC, t as gC, z as QC, x as CC, y as BC, A as EC, E as iC, C as DC } from "./helpers-DhmRTIg0.js";
3
- import { s as mI } from "./balances-vRSi3fDl.js";
4
- import { c as oC, b as aC, m as hC, a as GC } from "./balances-vRSi3fDl.js";
1
+ import { F as eI, G as RA, H as f, I as tI, J as SI, K as UA, L as d, M as zA, N as mA, O as e, P as qA, Q as nI, R as pI, S as rI, T as sI, U as FI, V as KI, X as BA, f as XA, m as eA, Y as RI, c as UI, Z as qI, W as VI, a as lI, b as dI, d as xI, e as YI, h as JI, i as PI, j as vI, k as OI, s as uI, l as jI, n as bI, o as LI, p as TI, q as ZI, r as zI } from "./helpers-Dho-nzKc.js";
2
+ import { B as WQ, v as _Q, w as $Q, u as AC, D as IC, t as gC, z as QC, x as CC, y as BC, A as EC, E as iC, C as DC } from "./helpers-Dho-nzKc.js";
3
+ import { s as mI } from "./balances-DV6c-dIo.js";
4
+ import { c as oC, b as aC, m as hC, a as GC } from "./balances-DV6c-dIo.js";
5
5
  var XI = eI();
6
6
  const VA = {
7
7
  messagePrefix: `Bitcoin Signed Message:
package/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useSyncExternalStore as u, useCallback as r, useState as f } from "react";
2
- import { _ as c, f as t, m as l, k as n } from "./helpers-DhmRTIg0.js";
2
+ import { _ as c, f as t, m as l, k as n } from "./helpers-Dho-nzKc.js";
3
3
  function m() {
4
4
  const e = u(c, t, t), s = r((o) => l(o), []);
5
5
  return [e, s];
@@ -1,4 +1,4 @@
1
- import { O as f, N as K, i as P, P as W, Q as ke, R as ve, S as Me, T as Ie, h as Ae, L as x, M as N, $ as Ce, X as Y, a0 as Be, a1 as Ne, f as y, a2 as _e, K as _, a3 as Z, a4 as v, Z as $ } from "./helpers-DhmRTIg0.js";
1
+ import { O as f, N as K, i as P, P as W, Q as ke, R as ve, S as Me, T as Ie, h as Ae, L as x, M as N, $ as Ce, X as Y, a0 as Be, a1 as Ne, f as y, a2 as _e, K as _, a3 as Z, a4 as v, Z as $ } from "./helpers-Dho-nzKc.js";
2
2
  const J = 4294967295;
3
3
  let X = Math.floor(Math.random() * J);
4
4
  const ee = () => (X = (X + 1) % J, X), $e = () => typeof chrome < "u" && !!chrome.runtime && typeof chrome.runtime.connect == "function";
@@ -681,7 +681,6 @@ async function fe(e, n, t) {
681
681
  i.push({
682
682
  address: r.address,
683
683
  index: r.signingIndexes[d]
684
- // disableTweakSigner: i == 0 ? true : false // TODO: remove this hack!!
685
684
  });
686
685
  o = {
687
686
  autoFinalized: !0,
@@ -1,7 +1,9 @@
1
+ import { Brc20ProgWithdrawArgs, PrepareBrc20ProgWithdrawArgs, PreparedBrc20Withdraw, SendBrc20ProgWithdrawToSelfArgs } from '../core/brc20-direct-withdraw';
1
2
  import { Brc20SendQuote, SendAsBrc20Args, SendAsBrc20ProgArgs, SendAsBrc20ProgResult, SendAsBrc20Result } from '../core/brc20-send';
2
3
  import { TransactArgs, TransactResult } from '../core/brc20-transact';
3
4
  import { FrBtcResult, UnwrapBtcFromBrc20ProgArgs, WrapBtcToBrc20ProgArgs } from '../core/frbtc';
4
5
  import { BISWalletPurpose, PaymentOpts } from '../types/common';
6
+ export type { Brc20ProgWithdrawArgs, PrepareBrc20ProgWithdrawArgs, PreparedBrc20Withdraw, SendBrc20ProgWithdrawToSelfArgs, } from '../core/brc20-direct-withdraw';
5
7
  export type { Brc20AmountOptions, Brc20DeployOptions, Brc20PredeployOptions, Brc20PredeployResult, } from '../core/brc20-inscriptions';
6
8
  export { computeBrc20PredeployHash, deployBrc20Inscription, generateBrc20Salt, mintBrc20Inscription, predeployInscriptions, transferBrc20Inscription, } from '../core/brc20-inscriptions';
7
9
  export type { Brc20SendPart, Brc20SendQuote, Brc20SendStepName, Brc20SendStepQuote, SendAsBrc20Args, SendAsBrc20ProgArgs, SendAsBrc20ProgResult, SendAsBrc20Result, } from '../core/brc20-send';
@@ -45,6 +47,54 @@ export declare function sendAsBrc20Prog(args: SendAsBrc20ProgArgs & {
45
47
  dryRun: false;
46
48
  }): Promise<SendAsBrc20ProgResult>;
47
49
  export declare function sendAsBrc20Prog(args: SendAsBrc20ProgArgs): Promise<Brc20SendQuote | SendAsBrc20ProgResult>;
50
+ /**
51
+ * Signs a BRC2.0 withdraw chain without broadcasting it, so a relay can broadcast it later. The
52
+ * commit and reveal inscribe `{"p":"brc20-module","op":"withdraw",...}` to the ordinals address; the
53
+ * send moves the inscription to `targetAddress`. The send spends only the reveal output
54
+ * (`<revealTxId>:0`) and pays its fee from that output's postage, so it needs no other wallet UTXO.
55
+ * The three transactions are tested for mempool acceptance as one package. The commit must spend
56
+ * confirmed or broadcast outputs: the call refuses while unbroadcast extra transactions are saved.
57
+ * It also refuses a wallet `canPrepareBrc20ProgWithdraw` rejects, such as a single-address wallet.
58
+ *
59
+ * For a withdraw order, pass the connected ordinals address as `targetAddress`: the same target
60
+ * given to `swap.withdraw` (its default when `targetAddress` is omitted there).
61
+ *
62
+ * `onSignRequest` is called before each wallet prompt with `{ step, total }`; `total` is 2.
63
+ *
64
+ * @param args - `tick`, `amount` (decimal string, as inscribed), `targetAddress`, `feeRate` (sats/vB), and optional `onSignRequest`.
65
+ * @returns The inscription id, each transaction's id and signed hex, and `feeSats`, the miner fees of all three.
66
+ */
67
+ export declare function prepareBrc20ProgWithdraw(args: PrepareBrc20ProgWithdrawArgs): Promise<PreparedBrc20Withdraw>;
68
+ /**
69
+ * Whether the connected wallet can prepare a BRC2.0 withdraw chain: it has separate payment and
70
+ * ordinals addresses, and the ordinals address is `p2tr` or `p2wpkh`. A single-address wallet could
71
+ * spend the held reveal output as a cardinal UTXO before the relay sends it, so it cannot.
72
+ *
73
+ * @returns `false` when no wallet is connected, or it cannot hold a withdraw chain.
74
+ */
75
+ export declare function canPrepareBrc20ProgWithdraw(): boolean;
76
+ /**
77
+ * Prices the chain `prepareBrc20ProgWithdraw` signs for the same arguments, without signing. It
78
+ * refuses the same wallets and arguments `prepareBrc20ProgWithdraw` refuses.
79
+ *
80
+ * @param args - `tick`, `amount`, `targetAddress` and `feeRate` (sats/vB).
81
+ * @returns The miner fees of the commit, reveal and send, in sats.
82
+ */
83
+ export declare function getBrc20ProgWithdrawFee(args: Brc20ProgWithdrawArgs): Promise<number>;
84
+ /**
85
+ * Sends a withdraw inscription from its reveal output back to the connected ordinals address and
86
+ * broadcasts it. Input 0 is `<revealTxId>:0` itself, so the send replaces a stuck relay send of the
87
+ * inscription when `feeRate` beats it. The fee comes from cardinal UTXOs and every input signals RBF.
88
+ *
89
+ * `onSignRequest` is called before the wallet prompt with `{ step, total }`; `total` is 1.
90
+ *
91
+ * @param args - `inscriptionId` (`<revealTxId>i0`), `feeRate` (sats/vB), and optional `onSignRequest`.
92
+ * @returns The broadcast transaction's id.
93
+ * @throws {Error} When the reveal output is not at the connected ordinals address, or the wallet cannot cover the fee.
94
+ */
95
+ export declare function sendBrc20ProgWithdrawToSelf(args: SendBrc20ProgWithdrawToSelfArgs): Promise<{
96
+ txId: string;
97
+ }>;
48
98
  export type { TransactArgs, TransactResult } from '../core/brc20-transact';
49
99
  /**
50
100
  * Inscribes a pre-signed legacy EVM transaction as a BRC2.0 `transact` op, so a signature made
@@ -1,7 +1,9 @@
1
- import { DepositOrderOptions, GetRecentActivityRequest, WalletActivityKind } from '../core/bis_swap';
1
+ import { DepositOrderOptions, GetRecentActivityRequest, WalletActivityKind, WithdrawOrderOptions } from '../core/bis_swap';
2
2
  import { SignProgressOptions } from '../core/sign-progress';
3
- export { generateAndStoreSwapWallet as createSwapWallet, ensureSwapWallet, getAddLiquidityResult, getKlines, requestMinerFee as getMinerFee, getMinerFeesOfDepositOrder, getMinerFeesOfWrapOrder, getPairReserves, getPairVolumeOverDays, getRemoveLiquidityResult, getSwapBalance, getSwapBalances, getSwapResult as getSwapExactInputResult, getSwap2Result as getSwapExactOutputResult, getSwapInfo, getSwapRoute, getSwapStatus, getSwapWalletSecurityCode, getTokenDecimals, getTvlHistory, getUnwrapResult as getUnwrapBtcResult, importSwapWallet, listPairs, listTokens, tryGetSwapReferrerInfo, } from '../core/bis_swap';
4
- export type { EnsureSwapWalletResult, GetActivityOfPairResponse, GetKlinesRequest, GetKlinesResponse, GetPairVolumeRequest, GetPairVolumeResponse, GetRecentActivityRequest, GetRecentActivityResponse, GetSwapStatusResponse, GetTvlHistoryRequest, GetTvlHistoryResponse, GetWalletActivitiesResponse, ImportSwapWalletOptions, Kline, ListPairsOrderBy, ListPairsRequest, ListPairsResponse, PairActivityEntry, PairInfo, PairReserves, RecentActivityEntry, RecentActivityKind, RecentActivityToken, SwapBalance, SwapInfo, TokenInfo, TvlPoint, WalletActivityEntry, WalletActivityKind, } from '../core/bis_swap';
3
+ export { generateAndStoreSwapWallet as createSwapWallet, ensureSwapWallet, getAddLiquidityResult, getKlines, requestMinerFee as getMinerFee, getMinerFeesOfDepositOrder, getMinerFeesOfWrapOrder, getPairReserves, getPairVolumeOverDays, getRemoveLiquidityResult, getSwapBalance, getSwapBalances, getSwapResult as getSwapExactInputResult, getSwap2Result as getSwapExactOutputResult, getSwapInfo, getSwapRoute, getSwapStatus, getSwapWalletSecurityCode, getTokenDecimals, getTransferRecipient, getTvlHistory, getUnwrapResult as getUnwrapBtcResult, importSwapWallet, listPairs, listTokens, tryGetSwapReferrerInfo, } from '../core/bis_swap';
4
+ export type { EnsureSwapWalletResult, GetActivityOfPairResponse, GetKlinesRequest, GetKlinesResponse, GetPairVolumeRequest, GetPairVolumeResponse, GetRecentActivityRequest, GetRecentActivityResponse, GetSwapStatusResponse, GetTvlHistoryRequest, GetTvlHistoryResponse, GetWalletActivitiesResponse, ImportSwapWalletOptions, Kline, ListPairsOrderBy, ListPairsRequest, ListPairsResponse, PairActivityEntry, PairInfo, PairReserves, RecentActivityEntry, RecentActivityKind, RecentActivityToken, SwapBalance, SwapInfo, TokenInfo, TransferRecipient, TvlPoint, WalletActivityEntry, WalletActivityKind, WithdrawOrderOptions, } from '../core/bis_swap';
5
+ export { signBlsMessage } from '../core/bls-sign';
6
+ export type { SignBlsMessageOptions } from '../core/bls-sign';
5
7
  export type { AllBalanceDetails } from '../core/helpers';
6
8
  export type { SignProgressOptions, SignRequest } from '../core/sign-progress';
7
9
  export type { BISSwapWalletInfo } from '../core/store';
@@ -153,6 +155,22 @@ export declare function wrapBtc(btcAmount: bigint, feeRate: number, options?: Si
153
155
  * @param tokenAddress - The address of the token to withdraw.
154
156
  * @param amount - The amount of the token to withdraw, specified as a bigint.
155
157
  * @param targetAddress - (Optional) The target address to which the tokens should be withdrawn. If not provided, the tokens will be withdrawn to the user's own Ordinals wallet.
158
+ * @param opts - `brc20Withdraw` is a BRC-20 transfer chain prepared by `brc20.prepareBrc20ProgWithdraw`. It is sent with the order as `brc20_withdraw` so the sequencer broadcasts it to pay the withdraw out directly. Prepare the chain with `targetAddress` set to the connected ordinals address, the same target this withdraw pays (omit `targetAddress` here, or pass that address); a chain whose send pays another address is refused before any signature. Without it the request body carries no `brc20_withdraw`.
156
159
  * @returns A promise that resolves when the withdrawal process is complete.
157
160
  */
158
- export declare function withdraw(tokenAddress: string, amount: bigint, targetAddress?: string): Promise<boolean>;
161
+ export declare function withdraw(tokenAddress: string, amount: bigint, targetAddress?: string, opts?: WithdrawOrderOptions): Promise<boolean>;
162
+ /**
163
+ * Sends a token balance from the user's smart wallet to another user's smart wallet, inside the
164
+ * swap: the token never leaves it, so there is no withdraw and re-deposit. The fee is the withdraw
165
+ * fee, in WBTC. Only registered tokens can be sent, not LP tokens.
166
+ *
167
+ * Needs a backend with `getSwapInfo().allow_transfers`. Check the recipient first with
168
+ * `getTransferRecipient`: it must have a swap wallet and no emergency exit in progress.
169
+ *
170
+ * @param tokenAddress - The address of the token to send.
171
+ * @param toBtcAddress - The recipient's BTC (ordinals) address.
172
+ * @param amount - The amount to send, in the token's base units.
173
+ * @returns A promise that resolves to true once the backend queues the transfer.
174
+ * @throws If the amount is not positive, transfers are off, or the recipient is unknown, exiting or the sender's own wallet, before any signature is requested.
175
+ */
176
+ export declare function transfer(tokenAddress: string, toBtcAddress: string, amount: bigint): Promise<boolean>;
@@ -1,6 +1,7 @@
1
1
  import { FeePolicy } from '../lib/fee-policy';
2
2
  import { SwapFees } from '../lib/swap-reporting';
3
3
  import { SwapRoute } from '../lib/swap-route';
4
+ import { PreparedBrc20Withdraw } from './brc20-direct-withdraw';
4
5
  import { BatchedSendLayout } from './mint';
5
6
  import { SignProgressOptions } from './sign-progress';
6
7
  import { BISSwapWalletInfo } from './store';
@@ -109,6 +110,7 @@ export interface SwapInfo {
109
110
  fee_policy: FeePolicy | null;
110
111
  allow_token_token_pairs: boolean;
111
112
  allow_multi_hop_routes: boolean;
113
+ allow_transfers: boolean;
112
114
  }
113
115
  /**
114
116
  * Fetches the swap's deployment info (the factory, WBTC and WBTC handler addresses, and the
@@ -186,10 +188,10 @@ export declare function tryGetSwapReferrerInfo(currentPubkey: string, refId: str
186
188
  /**
187
189
  * Requests the estimated miner fee for a specific swap operation type by making an API call to the swap backend.
188
190
  *
189
- * @param type The type of swap operation to estimate the miner fee for. Valid values are 'add_liquidity', 'remove_liquidity', 'swap', 'withdraw', or 'unwrap'.
191
+ * @param type The type of swap operation to estimate the miner fee for. Valid values are 'add_liquidity', 'remove_liquidity', 'swap', 'withdraw', 'unwrap', or 'transfer'.
190
192
  * @returns {Promise<bigint>} A promise that resolves to a bigint representing the estimated miner fee for the specified swap operation type. The fee is returned as a string from the API and converted to bigint in this function.
191
193
  */
192
- export declare function requestMinerFee(type: 'add_liquidity' | 'remove_liquidity' | 'swap' | 'withdraw' | 'unwrap'): Promise<bigint>;
194
+ export declare function requestMinerFee(type: 'add_liquidity' | 'remove_liquidity' | 'swap' | 'withdraw' | 'unwrap' | 'transfer'): Promise<bigint>;
193
195
  export interface TokenInfo {
194
196
  token_address: string;
195
197
  symbol: string;
@@ -375,7 +377,7 @@ export interface GetActivityOfPairResponse {
375
377
  */
376
378
  export declare function getActivityOfPair(params: GetActivityOfPairRequest): Promise<GetActivityOfPairResponse>;
377
379
  /** A kind of operation `getRecentActivity` can filter on; `swap` covers swap1 and swap2. */
378
- export type RecentActivityKind = 'swap' | 'add_liq' | 'remove_liq' | 'withdraw' | 'unwrap';
380
+ export type RecentActivityKind = 'swap' | 'add_liq' | 'remove_liq' | 'withdraw' | 'unwrap' | 'transfer';
379
381
  export interface GetRecentActivityRequest {
380
382
  /** Page size, 1-100. The backend defaults to 15. */
381
383
  limit?: number;
@@ -392,7 +394,7 @@ export interface RecentActivityToken {
392
394
  export interface RecentActivityEntry {
393
395
  id: string;
394
396
  op_type: number;
395
- type: 'add_liq' | 'remove_liq' | 'swap1' | 'swap2' | 'withdraw' | 'unwrap';
397
+ type: 'add_liq' | 'remove_liq' | 'swap1' | 'swap2' | 'withdraw' | 'unwrap' | 'transfer';
396
398
  /** Milliseconds since the epoch, when the operation was placed. */
397
399
  timestamp: number;
398
400
  block_height: number | null;
@@ -400,15 +402,17 @@ export interface RecentActivityEntry {
400
402
  success: boolean;
401
403
  user_address: string | null;
402
404
  user_pubkey: string | null;
403
- /** A swap's input token, a liquidity change's first token, or a withdraw/unwrap's token. */
405
+ /** A swap's input token, a liquidity change's first token, or a withdraw/unwrap/transfer's token. */
404
406
  token_1: RecentActivityToken | null;
405
- /** A swap's output token or a liquidity change's second token; null for withdraw/unwrap. */
407
+ /** A swap's output token or a liquidity change's second token; null for withdraw/unwrap/transfer. */
406
408
  token_2: RecentActivityToken | null;
407
409
  amount1: string | null;
408
410
  amount2: string | null;
409
411
  liquidity?: string | null;
410
412
  target_address?: string;
411
413
  target_pkscript?: string;
414
+ /** A transfer's recipient BTC address; the sender is `user_address`. */
415
+ to_address?: string;
412
416
  }
413
417
  export interface GetRecentActivityResponse {
414
418
  /** Newest first, across every pair. */
@@ -424,7 +428,7 @@ export interface GetRecentActivityResponse {
424
428
  */
425
429
  export declare function getRecentActivity(params?: GetRecentActivityRequest): Promise<GetRecentActivityResponse>;
426
430
  /** A kind of wallet activity that `getWalletActivities` can filter on. */
427
- export type WalletActivityKind = 'swap' | 'add_liq' | 'remove_liq' | 'deposit' | 'withdraw' | 'unwrap';
431
+ export type WalletActivityKind = 'swap' | 'add_liq' | 'remove_liq' | 'deposit' | 'withdraw' | 'unwrap' | 'transfer';
428
432
  interface GetWalletActivitiesRequest {
429
433
  pubkey: string;
430
434
  /** Pair to filter activities for. When omitted, the backend returns the wallet's activity across every pair and token. */
@@ -441,7 +445,7 @@ interface GetWalletActivitiesRequest {
441
445
  }
442
446
  export interface WalletActivityEntry {
443
447
  id: string;
444
- type: 'add_liq' | 'remove_liq' | 'swap1' | 'swap2' | 'deposit' | 'unwrap' | 'withdraw' | 'withdraw (lp)';
448
+ type: 'add_liq' | 'remove_liq' | 'swap1' | 'swap2' | 'deposit' | 'unwrap' | 'withdraw' | 'withdraw (lp)' | 'transfer';
445
449
  timestamp: number | null;
446
450
  block_height: number | null;
447
451
  success: boolean;
@@ -461,6 +465,12 @@ export interface WalletActivityEntry {
461
465
  liquidity?: string | null;
462
466
  target_address?: string | null;
463
467
  target_pkscript?: string | null;
468
+ /** A transfer this wallet sent or received. */
469
+ direction?: 'sent' | 'received';
470
+ /** A transfer's sender BTC address. */
471
+ from_address?: string | null;
472
+ /** A transfer's recipient BTC address. */
473
+ to_address?: string | null;
464
474
  }
465
475
  export interface GetWalletActivitiesResponse {
466
476
  pubkey: string;
@@ -743,29 +753,11 @@ interface Swap2OrderResponse {
743
753
  * @returns A promise that resolves to an object indicating the success of the swap order request.
744
754
  */
745
755
  export declare function prepareAndSendSwap2Order(token1Addr: string, token2Addr: string, amt1: bigint, amt2: bigint, slippageBPS: bigint, referrerId?: string, path?: readonly string[]): Promise<Swap2OrderResponse>;
746
- /**
747
- * Prepares and sends a withdraw request to transfer tokens from the smart wallet to an ordinal wallet. The function retrieves the necessary swap information and connected wallet details, converts the target ordinal Bitcoin address to an Ethereum-compatible address, and generates the required signatures for the withdraw request. It then constructs the withdraw request parameters and sends the request to the backend API.
748
- *
749
- * @param tokenAddress The address of the token to be withdrawn.
750
- * @param ordinalAddress The Bitcoin address of the target ordinal wallet.
751
- * @param amt The amount of the token to be withdrawn, represented as a bigint.
752
- *
753
- * @returns A promise that resolves to an object containing the amount withdrawn, represented as a bigint.
754
- */
755
- export declare function getWithdrawToOrdinalWalletResult(tokenAddress: string, ordinalAddress: string, amt: bigint): Promise<{
756
- amt: bigint;
757
- }>;
758
- /**
759
- * Prepares and sends a withdraw request to transfer tokens from the smart wallet to the user's own ordinal wallet. The function retrieves the necessary swap information and connected wallet details, obtains the user's ordinal wallet address, converts it to an Ethereum-compatible address, and generates the required signatures for the withdraw request. It then constructs the withdraw request parameters and sends the request to the backend API.
760
- *
761
- * @param tokenAddress The address of the token to be withdrawn.
762
- * @param amt The amount of the token to be withdrawn, represented as a bigint.
763
- *
764
- * @returns A promise that resolves to an object containing the amount withdrawn, represented as a bigint.
765
- */
766
- export declare function getWithdrawToSelfOrdinalWalletResult(tokenAddress: string, amt: bigint): Promise<{
767
- amt: bigint;
768
- }>;
756
+ /** Options for a withdraw order. */
757
+ export interface WithdrawOrderOptions {
758
+ /** A BRC-20 transfer chain the sequencer broadcasts to pay the withdraw out directly. */
759
+ brc20Withdraw?: PreparedBrc20Withdraw;
760
+ }
769
761
  export interface WithdrawOrderResponse {
770
762
  success: boolean;
771
763
  }
@@ -775,19 +767,21 @@ export interface WithdrawOrderResponse {
775
767
  * @param tokenAddr The address of the token to be withdrawn.
776
768
  * @param ordinalAddr The Bitcoin address of the target ordinal wallet.
777
769
  * @param amt The amount of the token to be withdrawn, represented as a bigint.
770
+ * @param opts `brc20Withdraw` attaches a held BRC-20 transfer chain for the sequencer to broadcast.
778
771
  *
779
772
  * @returns A promise that resolves to an object indicating the success of the withdraw order request.
780
773
  */
781
- export declare function prepareAndSendWithdrawOrderToOrdinalWallet(tokenAddr: string, ordinalAddr: string, amt: bigint): Promise<WithdrawOrderResponse>;
774
+ export declare function prepareAndSendWithdrawOrderToOrdinalWallet(tokenAddr: string, ordinalAddr: string, amt: bigint, opts?: WithdrawOrderOptions): Promise<WithdrawOrderResponse>;
782
775
  /**
783
776
  * Prepares and sends a withdraw order to transfer tokens from the smart wallet to the user's own ordinal wallet. The function retrieves the necessary swap information and connected wallet details, obtains the user's ordinal wallet address, converts it to an Ethereum-compatible address, and generates the required signatures for the withdraw order. It then constructs the withdraw order parameters and sends the order to the backend API.
784
777
  *
785
778
  * @param tokenAddr The address of the token to be withdrawn.
786
779
  * @param amt The amount of the token to be withdrawn, represented as a bigint.
780
+ * @param opts `brc20Withdraw` attaches a held BRC-20 transfer chain for the sequencer to broadcast.
787
781
  *
788
782
  * @returns A promise that resolves to an object indicating the success of the withdraw order request.
789
783
  */
790
- export declare function prepareAndSendWithdrawOrderToSelfOrdinalWallet(tokenAddr: string, amt: bigint): Promise<WithdrawOrderResponse>;
784
+ export declare function prepareAndSendWithdrawOrderToSelfOrdinalWallet(tokenAddr: string, amt: bigint, opts?: WithdrawOrderOptions): Promise<WithdrawOrderResponse>;
791
785
  /**
792
786
  * Prepares and sends an unwrap order to transfer WBTC from the smart wallet back to Bitcoin. The function retrieves the necessary swap information and connected wallet details, generates the required signatures for the unwrap order, and constructs the unwrap order parameters before sending the order to the backend API.
793
787
  *
@@ -811,4 +805,45 @@ interface UnwrapOrderResponse {
811
805
  * @returns A promise that resolves to an object indicating the success of the unwrap order request.
812
806
  */
813
807
  export declare function prepareAndSendUnwrapOrder(pkscript: string, amt: bigint): Promise<UnwrapOrderResponse>;
808
+ /**
809
+ * Whether a BTC address can receive a transfer between swap wallets, as the backend sees it.
810
+ */
811
+ export interface TransferRecipient {
812
+ /** The address has a swap wallet registered with the backend. A transfer to any other address is refused. */
813
+ registered: boolean;
814
+ /** The recipient's swap wallet has an emergency exit open or queued; the backend refuses transfers to it. */
815
+ exiting: boolean;
816
+ /** The recipient's BLS pubkey, whose hash the transfer signature covers; null when not registered. */
817
+ pubkey: string | null;
818
+ }
819
+ /**
820
+ * Looks up whether a BTC address has a swap wallet that can receive a transfer. Check it before
821
+ * asking the user to sign, so a typo or an unregistered address is caught without a wallet prompt.
822
+ *
823
+ * This does not require a connected wallet or a smart wallet.
824
+ *
825
+ * @param btcAddress The recipient's BTC (ordinals) address.
826
+ * @returns {Promise<TransferRecipient>} Whether the address is registered, whether it is exiting, and its swap pubkey.
827
+ * @throws If the address is empty, before any request is sent.
828
+ */
829
+ export declare function getTransferRecipient(btcAddress: string): Promise<TransferRecipient>;
830
+ export interface TransferOrderResponse {
831
+ success: boolean;
832
+ }
833
+ /**
834
+ * Sends a token balance from the user's smart wallet to another user's smart wallet, inside the
835
+ * swap contract: no withdraw and re-deposit, and the token never leaves the swap. The fee is the
836
+ * withdraw fee, in WBTC. Only registered tokens can be sent, not LP tokens.
837
+ *
838
+ * The recipient is named by BTC address and must have a swap wallet registered with the backend
839
+ * (`getTransferRecipient`), and the backend must allow transfers (`getSwapInfo().allow_transfers`).
840
+ * The ordinals wallet signs the order text, then the swap key signs the contract message.
841
+ *
842
+ * @param tokenAddr The address of the token to send.
843
+ * @param toBtcAddress The recipient's BTC (ordinals) address.
844
+ * @param amt The amount to send, in the token's base units.
845
+ * @returns A promise that resolves to `{ success: true }` once the backend queues the transfer.
846
+ * @throws If the amount is not positive, transfers are off, or the recipient is unknown, exiting or the sender's own wallet, before any signature is requested.
847
+ */
848
+ export declare function prepareAndSendTransferOrder(tokenAddr: string, toBtcAddress: string, amt: bigint): Promise<TransferOrderResponse>;
814
849
  export {};
@@ -0,0 +1,26 @@
1
+ export interface SignBlsMessageOptions {
2
+ /**
3
+ * Return the negated signature, the form a contract verifies a single signature in.
4
+ * Leave it off for signatures a sequencer aggregates (the swap-op form).
5
+ */
6
+ negate?: boolean;
7
+ }
8
+ /**
9
+ * Signs `msgHex` with a BLS private key, using the swap-op DST, and returns the G1
10
+ * signature as 0x-prefixed `x || y` (64 bytes each, big-endian).
11
+ *
12
+ * @param privKeyHex The 32-byte BLS private key, hex with or without 0x.
13
+ * @param msgHex The message bytes, hex with or without 0x.
14
+ * @param options `negate` returns the negated signature.
15
+ */
16
+ export declare function signBlsMessageWithKey(privKeyHex: string, msgHex: string, options?: SignBlsMessageOptions): string;
17
+ /**
18
+ * Signs `msgHex` with the connected wallet's stored swap BLS key. The message is not
19
+ * filtered: whoever can call this can already read the key through `ensureSwapWallet`.
20
+ *
21
+ * @param msgHex The message bytes, hex with or without 0x.
22
+ * @param options `negate` returns the negated signature.
23
+ * @returns The G1 signature as 0x-prefixed `x || y`.
24
+ * @throws {Error} When no swap wallet is stored for the connected wallet.
25
+ */
26
+ export declare function signBlsMessage(msgHex: string, options?: SignBlsMessageOptions): Promise<string>;
@@ -0,0 +1,85 @@
1
+ import { SignProgressOptions } from './sign-progress';
2
+ /**
3
+ * Whether the connected wallet can prepare a BRC2.0 withdraw chain: it has separate payment and
4
+ * ordinals addresses, and the ordinals address is `p2tr` or `p2wpkh`. A wallet whose one address
5
+ * serves both roles may spend the held reveal output as a cardinal UTXO before the relay sends it.
6
+ */
7
+ export declare function canPrepareBrc20ProgWithdraw(): boolean;
8
+ /**
9
+ * The vsize of a withdraw's send: one key-path input of `inputType` (the inscription) and one
10
+ * `outputType` output.
11
+ *
12
+ * @throws When `inputType` is not `p2tr` or `p2wpkh`, or `outputType` is not a payable script type.
13
+ */
14
+ export declare function sendVsize(inputType: string, outputType: string): number;
15
+ /**
16
+ * The reveal output value that lets a withdraw's send pay its own fee: the target's dust plus the
17
+ * send's fee at `feeRate`. The send spends only that output, so nothing else in the wallet funds it.
18
+ *
19
+ * @param scriptType The inscription address's script type (`p2tr` or `p2wpkh`).
20
+ * @param feeRate The send's fee rate in sat/vB.
21
+ * @param targetScriptType The target address's script type; defaults to `scriptType`.
22
+ */
23
+ export declare function selfFundedSendPostage(scriptType: string, feeRate: number, targetScriptType?: string): number;
24
+ export interface Brc20ProgWithdrawArgs {
25
+ /** The BRC-20 ticker, as it appears in the inscription. */
26
+ tick: string;
27
+ /** The decimal amount, as it appears in the inscription. */
28
+ amount: string;
29
+ /** The address the withdrawn BRC-20 lands on. */
30
+ targetAddress: string;
31
+ /** Fee rate in sat/vB for the commit, reveal and send. */
32
+ feeRate: number;
33
+ }
34
+ export interface PrepareBrc20ProgWithdrawArgs extends Brc20ProgWithdrawArgs, SignProgressOptions {
35
+ }
36
+ /** A signed, unbroadcast BRC2.0 withdraw chain: commit, reveal, and the send to the target. */
37
+ export interface PreparedBrc20Withdraw {
38
+ inscriptionId: string;
39
+ commitTxId: string;
40
+ commitTxHex: string;
41
+ revealTxId: string;
42
+ revealTxHex: string;
43
+ /** Spends only `<revealTxId>:0` and pays the target's dust, so it stays valid while held. */
44
+ sendTxId: string;
45
+ sendTxHex: string;
46
+ /** Miner fees of the three transactions, in sats. */
47
+ feeSats: number;
48
+ }
49
+ /**
50
+ * Signs a BRC2.0 withdraw inscription chain without broadcasting it. The commit and reveal inscribe
51
+ * `{"p":"brc20-module","op":"withdraw",...}` to the ordinals address, with a reveal output large
52
+ * enough to pay the send's fee; the send moves the inscription from `<revealTxId>:0` to
53
+ * `targetAddress` as its only input and output. The three are tested for mempool acceptance as one
54
+ * package. Refuses a wallet `canPrepareBrc20ProgWithdraw` rejects.
55
+ *
56
+ * `onSignRequest` is called before each wallet prompt with `{ step, total }`; `total` is 2.
57
+ */
58
+ export declare function prepareBrc20ProgWithdraw(args: PrepareBrc20ProgWithdrawArgs): Promise<PreparedBrc20Withdraw>;
59
+ export interface SendBrc20ProgWithdrawToSelfArgs extends SignProgressOptions {
60
+ /** The withdraw inscription held at the connected ordinals address. */
61
+ inscriptionId: string;
62
+ /** Fee rate in sat/vB for the send. */
63
+ feeRate: number;
64
+ }
65
+ /**
66
+ * Sends a withdraw inscription from its reveal output back to the connected ordinals address and
67
+ * broadcasts it. Input 0 is `<revealTxId>:0`, read from the reveal transaction rather than from
68
+ * where an indexer places the inscription, so the send conflicts with (and, at a higher fee,
69
+ * replaces) a stuck relay send of the same output. Output 0 returns the inscription at the ordinals
70
+ * address's dust value; cardinal UTXOs of the payment address pay the fee, and every input signals
71
+ * RBF.
72
+ *
73
+ * `onSignRequest` is called before the wallet prompt with `{ step, total }`; `total` is 1.
74
+ *
75
+ * @throws When `inscriptionId` is not `<revealTxId>i0`, or the reveal output is not at the
76
+ * connected ordinals address.
77
+ */
78
+ export declare function sendBrc20ProgWithdrawToSelf(args: SendBrc20ProgWithdrawToSelfArgs): Promise<{
79
+ txId: string;
80
+ }>;
81
+ /**
82
+ * The miner fees, in sats, of the chain `prepareBrc20ProgWithdraw` signs for the same arguments:
83
+ * commit, reveal and send. Nothing is signed.
84
+ */
85
+ export declare function getBrc20ProgWithdrawFee(args: Brc20ProgWithdrawArgs): Promise<number>;
@@ -8,13 +8,13 @@ export declare const GAS_PER_BYTE = 12000;
8
8
  */
9
9
  export declare function compressSmartContractData(inputHex: string): Promise<string>;
10
10
  /**
11
- * Encodes a function call to a smart contract using the provided ABI and function name, along with the parameters for the function call. This function uses the Web3 library to create a contract instance and encode the function call data according to the ABI specification. It also includes error handling to ensure that the specified function exists in the ABI and that the parameters are correctly formatted.
11
+ * Encodes a function call to a smart contract using the provided ABI and function name, along with the parameters for the function call. The function call data is encoded with ethers according to the ABI specification; an overloaded name is resolved by argument count. It also includes error handling to ensure that the specified function exists in the ABI and that the parameters are correctly formatted.
12
12
  *
13
13
  * @param abi - The ABI of the smart contract, which defines the functions and their parameters.
14
14
  * @param functionName - The name of the function to call on the smart contract.
15
15
  * @param params - An array of parameters to be passed to the function call, which should match the types defined in the ABI for the specified function.
16
16
  * @returns A hexadecimal string representing the encoded function call data, which can be included in a transaction to call the smart contract function. The encoding is done according to the ABI specification, and the resulting string can be used as the calldata for a transaction.
17
- * @throws Will throw an error if the specified function name does not exist in the ABI or if the parameters do not match the expected types defined in the ABI for that function. It will also throw an error if there is an issue with the Web3 library during encoding.
17
+ * @throws Will throw an error if the specified function name does not exist in the ABI or if the parameters do not match the expected types defined in the ABI for that function.
18
18
  */
19
19
  export declare function evmEncodeFunctionCall(abi: any, functionName: string, params: any): string;
20
20
  export declare function getEvmAddressFromBitcoinAddress(bitcoinAddress: string): string;
@@ -94,33 +94,6 @@ export declare function callSmartContract(smartContractContractAddr: string, inp
94
94
  sendToOpReturnTxId: string;
95
95
  signedSendToOpReturnTxHex: string;
96
96
  }>;
97
- /**
98
- * Calls a smart contract function by creating an inscription with the encoded function call data and sending it to the OP_RETURN output. The function takes the smart contract address, ABI, function name, and parameters, encodes the function call using the ABI, and then follows a similar process as `deploySmartContract` to create and send the inscription. It also handles optional payment parameters and allows for a dry run mode where the transaction hexes are returned without broadcasting.
99
- *
100
- * @param smartContractContractAddr - The address of the smart contract to call, represented as a string. This address will be included in the inscription content to indicate which contract function is being called.
101
- * @param abi - The ABI of the smart contract, used to encode the function call data along with the function name and parameters.
102
- * @param funcName - The name of the function to call on the smart contract, represented as a string. This will be used along with the ABI to encode the function call data.
103
- * @param params - An array of parameters to be passed to the contract function, which will be encoded using the ABI along with the function name.
104
- * @param estimatedGas - The estimated gas required for the smart contract function call, used to determine if padding is needed for the inscription content.
105
- * @param feeRate - The fee rate in sats/vbyte to be used for the transactions involved in the function call process.
106
- * @param postage - An optional parameter representing the postage to be included in the minting transaction, specified in sats. If null, no postage will be included.
107
- * @param paymentAddr - An optional parameter representing the Bitcoin address to which payment should be sent for the minting transaction. If null, no payment will be made.
108
- * @param payment - An optional parameter representing the amount of payment to be sent for the minting transaction, specified in sats. If null or less than or equal to 0, no payment will be made.
109
- * @param dryRun - A boolean flag indicating whether to perform a dry run. If true, the function will return the transaction hexes without broadcasting them to the network. If false, the transactions will be broadcasted after creation.
110
- *
111
- * @returns An object containing details of the function call process, including transaction IDs, signed transaction hexes, inscription ID, postage, and secret used in the minting process. If dryRun is true, the transactions will not be broadcasted and the hexes will be returned for inspection.
112
- */
113
- export declare function callSmartContractAbi(smartContractContractAddr: string, abi: any, funcName: string, params: any, estimatedGas: number, feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, dryRun: boolean): Promise<{
114
- commitTxId: string;
115
- signedCommitTxHex: string;
116
- revealTxId: string;
117
- signedRevealTxHex: string;
118
- inscriptionId: string;
119
- postage: number;
120
- secret: string;
121
- sendToOpReturnTxId: string;
122
- signedSendToOpReturnTxHex: string;
123
- }>;
124
97
  /**
125
98
  * Calls a smart contract function by creating an inscription with the provided input data and sending it to the OP_RETURN output. The function first compresses the input data, then creates an inscription with the compressed data and mints it. After minting, it sends the inscription to an OP_RETURN output with a specific format. The function also handles optional payment parameters and allows for a dry run mode where the transaction hexes are returned without broadcasting.
126
99
  *
@@ -147,33 +120,6 @@ export declare function callSmartContractFromPaymentWallet(smartContractContract
147
120
  sendToOpReturnTxId: string;
148
121
  signedSendToOpReturnTxHex: string;
149
122
  }>;
150
- /**
151
- * Calls a smart contract function using the provided ABI and function name by encoding the function call data, creating an inscription with the encoded data, and sending it to the OP_RETURN output. The function takes the smart contract address, ABI, function name, and parameters, encodes the function call using the ABI, and then follows a similar process as `callSmartContract` to create and send the inscription. It also handles optional payment parameters and allows for a dry run mode where the transaction hexes are returned without broadcasting.
152
- *
153
- * @param smartContractContractAddr - The address of the smart contract to call, represented as a string. This address will be included in the inscription content to indicate which contract function is being called.
154
- * @param abi - The ABI of the smart contract, used to encode the function call data along with the function name and parameters.
155
- * @param funcName - The name of the function to call on the smart contract, represented as a string. This will be used along with the ABI to encode the function call data.
156
- * @param params - An array of parameters to be passed to the contract function, which will be encoded using the ABI along with the function name.
157
- * @param estimatedGas - The estimated gas required for the smart contract function call, used to determine if padding is needed for the inscription content.
158
- * @param feeRate - The fee rate in sats/vbyte to be used for the transactions involved in the function call process.
159
- * @param postage - An optional parameter representing the postage to be included in the minting transaction, specified in sats. If null, no postage will be included.
160
- * @param paymentAddr - An optional parameter representing the Bitcoin address to which payment should be sent for the minting transaction. If null, no payment will be made.
161
- * @param payment - An optional parameter representing the amount of payment to be sent for the minting transaction, specified in sats. If null or less than or equal to 0, no payment will be made.
162
- * @param dryRun - A boolean flag indicating whether to perform a dry run. If true, the function will return the transaction hexes without broadcasting them to the network. If false, the transactions will be broadcasted after creation.
163
- *
164
- * @returns An object containing details of the function call process, including transaction IDs, signed transaction hexes, inscription ID, postage, and secret used in the minting process. If dryRun is true, the transactions will not be broadcasted and the hexes will be returned for inspection.
165
- */
166
- export declare function callSmartContractAbiFromPaymentWallet(smartContractContractAddr: string, abi: any, funcName: string, params: any, estimatedGas: number, feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, dryRun: boolean): Promise<{
167
- commitTxId: string;
168
- signedCommitTxHex: string;
169
- revealTxId: string;
170
- signedRevealTxHex: string;
171
- inscriptionId: string;
172
- postage: number;
173
- secret: string;
174
- sendToOpReturnTxId: string;
175
- signedSendToOpReturnTxHex: string;
176
- }>;
177
123
  /**
178
124
  * Deposits a BRC-20 token into the BRC2.0 programmable module by creating an inscription with the transfer operation and sending it to the OP_RETURN output. The function takes the token tick, amount, fee rate, and optional payment parameters, creates an inscription with the transfer operation, mints it, and then sends it to an OP_RETURN output with a specific format. It also allows for a dry run mode where the transaction hexes are returned without broadcasting.
179
125
  *
@@ -93,6 +93,8 @@ export declare function finalizePsbtInputs(psbt: bitcoinjs.Psbt, noSignIdxes?: n
93
93
  * @param inscription An optional array containing inscription details, where the first element is the inscription ID and the second element is the satpoint.
94
94
  */
95
95
  export declare function saveExtraUtxos(txHexes: string[], inscription: string[] | null): void;
96
+ /** Whether unbroadcast extra transactions are saved, so new transactions may spend their outputs. */
97
+ export declare function hasExtraTxes(): boolean;
96
98
  /**
97
99
  * Retrieves the currently saved extra UTXOs that are being used in transactions but not yet confirmed on the blockchain.
98
100
  */