@bestinslot/wallet-kit 0.14.3 → 0.15.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.
@@ -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 { BatchedSendLayout } from './mint';
4
5
  import { SignProgressOptions } from './sign-progress';
5
6
  import { BISSwapWalletInfo } from './store';
6
7
  /**
@@ -321,7 +322,7 @@ export interface GetTvlHistoryResponse {
321
322
  /**
322
323
  * Fetches a daily Total Value Locked (TVL) series for a token pair from the swap backend, for charting TVL over time.
323
324
  *
324
- * TVL is valued in WBTC sats: 2 x the WBTC-side reserve for a WBTC pair. A token/token pair (`wbtc_side: ''`) is valued through each token's direct BTC pool as of that day, and its point is `tvl: null` on days its BTC exposure is below the backend's threshold. Points are one per day, oldest first, each carrying the pair's reserves as of that day (carried forward across days with no on-chain change).
325
+ * TVL is valued in WBTC sats: 2 x the WBTC-side reserve for a WBTC pair. A token/token pair (`wbtc_side: ''`) is valued along each token's BTC price route at that day's reserves, and its point is `tvl: null` on days its BTC exposure is below the backend's threshold. Points are one per day, oldest first, each carrying the pair's reserves as of that day (carried forward across days with no on-chain change).
325
326
  *
326
327
  * @param params An object with the pair address and the number of days to look back (max 365; the backend clamps out-of-range values).
327
328
  * @returns {Promise<GetTvlHistoryResponse>} A promise that resolves to the pair address, token addresses and symbols, which side is WBTC, the period in days, and the ascending array of `{ timestamp, block_height, tvl }` points. Each `tvl` is a string of sats (or `null`, see above) and can be converted to bigint if needed.
@@ -500,6 +501,26 @@ export interface ReclaimInscription {
500
501
  amount: bigint;
501
502
  }
502
503
  export declare function sumReclaimAmounts(reclaims?: ReclaimInscription[] | null): bigint;
504
+ export interface DepositOrderOptions extends SignProgressOptions {
505
+ /**
506
+ * Inscribes the base-layer conversion, the allowance and the deposit from one commit tx and
507
+ * sends all of them to the BRC20PROG OP_RETURN in one tx, so the deposit takes three wallet
508
+ * prompts (BIP-322, commit, send) whatever it needs. Applies when the conversion or the
509
+ * allowance is needed; a deposit alone takes its usual three prompts.
510
+ */
511
+ batchInscriptions?: boolean;
512
+ /**
513
+ * How the batched send moves the inscriptions into OP_RETURN outputs (see `BatchedSendLayout`).
514
+ * Defaults to `single`.
515
+ */
516
+ batchSendLayout?: BatchedSendLayout;
517
+ /**
518
+ * Signs a batched deposit's commit and send in one wallet prompt when the wallet can sign several
519
+ * PSBTs at once (UniSat, OKX, Xverse) and the payer is not a legacy P2PKH address, so the
520
+ * deposit takes two prompts (BIP-322, then both txs). Defaults to true; false keeps three.
521
+ */
522
+ batchSigning?: boolean;
523
+ }
503
524
  /**
504
525
  * Creates and broadcasts a deposit order for swapping BRC-20 tokens by performing necessary checks, generating signatures, and making API calls to the swap backend. The function handles both BRC-2.0 and base BRC-20 token balances, checks allowances, and prepares the required data for the deposit order.
505
526
  *
@@ -508,11 +529,11 @@ export declare function sumReclaimAmounts(reclaims?: ReclaimInscription[] | null
508
529
  * @param feeRate The fee rate to use for the transactions, represented in sats/vbyte.
509
530
  * @param createAllowanceIfNeeded A boolean flag indicating whether to create an allowance for the BRC-2.0 token transfer if the current allowance is insufficient. Defaults to true.
510
531
  * @param reclaimInscriptions Optional transfer inscriptions to reclaim toward the base-layer sufficiency check, each with `inscriptionId` and `amount` (bigint, 18 decimals).
511
- * @param options `onSignRequest` is called before each wallet prompt, with `total` set: 3, plus 2 when base-layer balance is converted, plus 2 when an allowance is created.
532
+ * @param options `onSignRequest` is called before each wallet prompt, with `total` set: 3, plus 2 when base-layer balance is converted, plus 2 when an allowance is created. With `batchInscriptions`, `total` is 3.
512
533
  *
513
534
  * @returns {Promise<string[]>} A promise that resolves to an array of transaction IDs (txids) for the transactions involved in the deposit order, including the commit transaction, reveal transaction, and send-to-opreturn transaction.
514
535
  */
515
- export declare function createAndBroadcastDepositOrder(tokenAddress: string, tokenAmount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: ReclaimInscription[], options?: SignProgressOptions): Promise<string[]>;
536
+ export declare function createAndBroadcastDepositOrder(tokenAddress: string, tokenAmount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: ReclaimInscription[], options?: DepositOrderOptions): Promise<string[]>;
516
537
  /**
517
538
  * Checks the miner fees required for creating a deposit order for swapping BRC-20 tokens, including the fees for minting inscriptions for allowance and deposit, as well as the fees for sending those inscriptions to OP_RETURN. The function also checks if the user has sufficient balance and allowance for the specified token amount.
518
539
  *
@@ -520,19 +541,23 @@ export declare function createAndBroadcastDepositOrder(tokenAddress: string, tok
520
541
  * @param tokenAmount The amount of the BRC-20 token to deposit, represented as a bigint in 18 decimals format.
521
542
  * @param feeRate The fee rate to use for the transactions, represented in sats/vbyte.
522
543
  * @param createAllowanceIfNeeded A boolean flag indicating whether to include the fees for creating an allowance inscription if the current allowance is insufficient. Defaults to true.
544
+ * @param reclaimInscriptions Optional transfer inscriptions the deposit reclaims, as for `createAndBroadcastDepositOrder`.
545
+ * @param options `batchInscriptions` and `batchSendLayout` as the deposit will be made with, so the fees are those of the package it builds.
523
546
  *
524
547
  * @returns A promise that resolves to an object containing the following properties:
525
548
  * - needs_approval: A boolean indicating whether an allowance inscription needs to be created.
526
- * - allowance_fees_total: The total miner fees for creating and sending the allowance inscription to OP_RETURN (0 if no allowance inscription is needed).
527
- * - base_deposit_fees_total: The total miner fees for creating and sending the base deposit inscription to OP_RETURN (0 if no base deposit inscription is needed).
528
- * - deposit_fees_total: The total miner fees for creating and sending the deposit inscription to OP_RETURN.
549
+ * - allowance_fees_total: The total miner fees for creating and sending the allowance inscription to OP_RETURN (0 if no allowance inscription is needed, and 0 when batched).
550
+ * - base_deposit_fees_total: The total miner fees for creating and sending the base deposit inscription to OP_RETURN (0 if no base deposit inscription is needed, and 0 when batched).
551
+ * - deposit_fees_total: The total miner fees for creating and sending the deposit inscription to OP_RETURN; when batched, the fees of the whole package, burned OP_RETURN sats included.
552
+ * - batched: Whether the deposit is one batched package.
529
553
  * - fee_rate: The fee rate used for the calculations, in sats/vbyte.
530
554
  */
531
- export declare function getMinerFeesOfDepositOrder(tokenAddress: string, tokenAmount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: ReclaimInscription[]): Promise<{
555
+ export declare function getMinerFeesOfDepositOrder(tokenAddress: string, tokenAmount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: ReclaimInscription[], options?: Pick<DepositOrderOptions, 'batchInscriptions' | 'batchSendLayout'>): Promise<{
532
556
  needs_approval: boolean;
533
557
  allowance_fees_total: number;
534
558
  base_deposit_fees_total: number;
535
559
  deposit_fees_total: number;
560
+ batched: boolean;
536
561
  fee_rate: number;
537
562
  }>;
538
563
  /**
@@ -1,6 +1,7 @@
1
1
  import { SignProgressOptions } from './sign-progress';
2
2
  import { InscriptionDetails } from '../types/inscription';
3
3
  import { WalletInfo } from '../types/wallet';
4
+ import { assertFeeRate } from './mint';
4
5
  /** The transactions of one inscribe-and-send step. */
5
6
  export interface Brc20SendPart {
6
7
  commitTxId: string;
@@ -67,7 +68,7 @@ export declare function parseBrc20Amount(value: string, label: string): bigint;
67
68
  /** Formats an 18-decimal bigint as the shortest BRC-20 decimal string, such as `"7.5"`. */
68
69
  export declare function formatBrc20Amount(value: bigint): string;
69
70
  export declare function assertRecipient(recipient: string): void;
70
- export declare function assertFeeRate(feeRate: number): void;
71
+ export { assertFeeRate };
71
72
  export declare function runChain(steps: ChainStep[], feeRate: number, dryRun: boolean, options: SignProgressOptions): Promise<Brc20SendQuote | ChainResult>;
72
73
  export interface SendAsBrc20Args extends SignProgressOptions {
73
74
  tick: string;
@@ -0,0 +1,133 @@
1
+ import { BISNetwork } from '../types/common';
2
+ /**
3
+ * An unspent output that carries no inscriptions and no runes.
4
+ */
5
+ export interface Utxo {
6
+ /** The id of the transaction that created the output. */
7
+ txid: string;
8
+ /** The output's index in that transaction. */
9
+ vout: number;
10
+ /** The output's value in sats. */
11
+ value: number;
12
+ }
13
+ /**
14
+ * An unspent output that carries one or more inscriptions.
15
+ */
16
+ export interface OrdinalUtxo extends Utxo {
17
+ /** The ids of the inscriptions on the output. */
18
+ inscription_ids: string[];
19
+ /** The satpoint (`txid:vout:offset`) of each entry of `inscription_ids`, in the same order. */
20
+ satpoints: string[];
21
+ /** The height of the block that confirmed the output, or `null` while it is unconfirmed. */
22
+ block_height?: number | null;
23
+ }
24
+ /**
25
+ * The mempool acceptance verdict for one transaction, in the shape of Bitcoin Core's
26
+ * `testmempoolaccept` entries.
27
+ */
28
+ export interface MempoolAcceptResult {
29
+ /** Whether the transaction would enter the mempool. */
30
+ allowed: boolean;
31
+ /** Why the transaction would be rejected, when `allowed` is false. */
32
+ 'reject-reason'?: string;
33
+ }
34
+ /**
35
+ * The balance of an address in sats, over every output of the address, inscribed and runic ones
36
+ * included. The spendable total is `confirmed + mempool`.
37
+ */
38
+ export interface ChainBalance {
39
+ /** The sum of the address's confirmed outputs that no mempool transaction spends. */
40
+ confirmed: number;
41
+ /** The sum of the address's unspent outputs that unconfirmed transactions create. */
42
+ mempool: number;
43
+ }
44
+ /**
45
+ * The Bitcoin chain data wallet-kit reads and the transaction submission it performs.
46
+ *
47
+ * wallet-kit applies its own pending transactions on top of what a provider returns: outputs a
48
+ * pending transaction spends are dropped, and outputs it creates for the address are added. A
49
+ * provider therefore only reports what the chain (and optionally the mempool) holds.
50
+ *
51
+ * Every method throws when it cannot answer.
52
+ */
53
+ export interface ChainProvider {
54
+ /**
55
+ * Lists the address's unspent outputs that carry no inscriptions and no runes. A provider
56
+ * that cannot tell whether an output carries an inscription or a rune throws instead of
57
+ * returning it. A provider without mempool data returns the confirmed outputs, minus those
58
+ * that mempool transactions spend.
59
+ */
60
+ cardinalUtxos: (address: string) => Promise<Utxo[]>;
61
+ /** Lists the address's unspent outputs that carry inscriptions. */
62
+ ordinalUtxos: (address: string) => Promise<OrdinalUtxo[]>;
63
+ /** Returns the address's balance. A provider without mempool data reports `mempool: 0`. */
64
+ balance: (address: string) => Promise<ChainBalance>;
65
+ /** Returns the raw transaction with the given id, hex encoded. */
66
+ txHex: (txid: string) => Promise<string>;
67
+ /**
68
+ * Tests whether the transactions, in order, would enter the mempool. Later transactions may
69
+ * spend outputs of earlier ones. Returns one result per transaction, in the same order.
70
+ */
71
+ testMempoolAccept: (txHexes: string[]) => Promise<MempoolAcceptResult[]>;
72
+ /** Broadcasts the transactions, in order, and returns their txids. */
73
+ broadcast: (txHexes: string[]) => Promise<string[]>;
74
+ }
75
+ /**
76
+ * A BRC2.0 JSON-RPC endpoint. wallet-kit uses it for `eth_call` reads.
77
+ */
78
+ export interface Brc20RpcProvider {
79
+ /**
80
+ * Sends one JSON-RPC request and returns its `result`. Throws when the request fails or the
81
+ * response carries an `error`.
82
+ */
83
+ request: (method: string, params: unknown[]) => Promise<unknown>;
84
+ }
85
+ /** The providers for one network. A key left out uses the default provider. */
86
+ export interface NetworkProviders {
87
+ chain?: ChainProvider;
88
+ brc20Rpc?: Brc20RpcProvider;
89
+ }
90
+ /** Per-network provider overrides accepted by {@link setProviders}. */
91
+ export type ProvidersConfig = {
92
+ [N in BISNetwork]?: NetworkProviders;
93
+ };
94
+ /**
95
+ * Sets the chain data and BRC2.0 RPC providers per network. A network or key left out uses the
96
+ * defaults, {@link BisChainProvider} and {@link BisBrc20RpcProvider}, which read the endpoints
97
+ * set with `setEndpoints`. Every call replaces the previous overrides; `setProviders({})`
98
+ * restores the defaults.
99
+ *
100
+ * @param config Per-network providers, e.g. `{ signet: { chain: myChainProvider } }`.
101
+ * @throws {Error} If a network or key is unknown, or a provider lacks one of its methods.
102
+ */
103
+ export declare function setProviders(config: ProvidersConfig): void;
104
+ /**
105
+ * Returns the providers in effect for a network: the overrides set with {@link setProviders},
106
+ * and the default providers for the keys left out.
107
+ *
108
+ * @param network The network to read. Defaults to the selected network.
109
+ * @returns The chain data and BRC2.0 RPC providers for that network.
110
+ */
111
+ export declare function getProviders(network?: BISNetwork): Required<NetworkProviders>;
112
+ /**
113
+ * Returns the chain data provider for a network.
114
+ *
115
+ * @param network The network to read. Defaults to the selected network.
116
+ * @returns The provider set with {@link setProviders}, or the default {@link BisChainProvider}.
117
+ */
118
+ export declare function getChainProvider(network?: BISNetwork): ChainProvider;
119
+ /**
120
+ * Returns the BRC2.0 RPC provider for a network.
121
+ *
122
+ * @param network The network to read. Defaults to the selected network.
123
+ * @returns The provider set with {@link setProviders}, or the default {@link BisBrc20RpcProvider}.
124
+ */
125
+ export declare function getBrc20RpcProvider(network?: BISNetwork): Brc20RpcProvider;
126
+ /**
127
+ * Whether a network has a BRC2.0 RPC: a provider set with {@link setProviders}, or an `rpc`
128
+ * endpoint for the default provider.
129
+ *
130
+ * @param network The network to read. Defaults to the selected network.
131
+ * @returns Whether BRC2.0 RPC requests on that network have somewhere to go.
132
+ */
133
+ export declare function hasBrc20Rpc(network?: BISNetwork): boolean;
@@ -1,3 +1,4 @@
1
+ import { MempoolAcceptResult, OrdinalUtxo, Utxo } from './chain-providers';
1
2
  import { Endpoints } from './store-network';
2
3
  import * as bitcoinjs from 'bitcoinjs-lib';
3
4
  export declare const txHexByIdCache: {
@@ -25,9 +26,10 @@ export declare function sequencerEndpointFor(path: string): 'sequencerRead' | 's
25
26
  *
26
27
  * @param key The endpoint that serves the route.
27
28
  * @param path The route path, with any query string, relative to the endpoint base.
29
+ * @param base A base URL to use in place of the configured `key` endpoint.
28
30
  * @returns The full URL.
29
31
  */
30
- export declare function getEndpointUrl(key: keyof Endpoints, path: string): Promise<string>;
32
+ export declare function getEndpointUrl(key: keyof Endpoints, path: string, base?: string): Promise<string>;
31
33
  /**
32
34
  * Builds the full URL for a swap sequencer route, routed to `sequencerRead` or
33
35
  * `sequencer` by {@link sequencerEndpointFor}.
@@ -84,6 +86,18 @@ export declare function clearExtraUtxos(): void;
84
86
  * @returns A string representing the type of the UTXO output, such as 'pubkeyhash', 'scripthash', 'witness_v0_keyhash', 'witness_v0_scripthash', 'witness_v1_taproot', 'pubkey', 'anchor', 'witness_unknown', 'nulldata', 'multisig', or 'nonstandard'.
85
87
  */
86
88
  export declare function utxoOutputTypeFromOutputScript(output: any, network: any): 'pubkeyhash' | 'scripthash' | 'witness_v0_keyhash' | 'witness_v0_scripthash' | 'witness_v1_taproot' | 'pubkey' | 'anchor' | 'witness_unknown' | 'nulldata' | 'multisig' | 'nonstandard';
89
+ /** The output types wallet-kit can spend, named as in Bitcoin Core's `scriptPubKey.type`. */
90
+ export type UtxoScriptType = APIUtxoInfo['script_type'];
91
+ /** A cardinal UTXO with the outpoint string and script type wallet-kit's transaction builders read. */
92
+ export type CardinalUtxoInfo = Utxo & {
93
+ utxo: string;
94
+ script_type: UtxoScriptType;
95
+ };
96
+ /** An ordinal UTXO with the outpoint string and script type wallet-kit's transaction builders read. */
97
+ export type OrdinalUtxoInfo = OrdinalUtxo & {
98
+ utxo: string;
99
+ script_type: UtxoScriptType;
100
+ };
87
101
  /**
88
102
  * Returns the ordinal UTXOs that the saved extra transactions create for `addr`: the
89
103
  * output carrying the saved extra inscription, unless another extra transaction spends it.
@@ -92,13 +106,14 @@ export declare function utxoOutputTypeFromOutputScript(output: any, network: any
92
106
  * @param addr The address the inscription output must pay to.
93
107
  * @returns The extra ordinal UTXOs for `addr`, empty when no extras are saved.
94
108
  */
95
- export declare function getExtraOrdinalUtxos(addr: string): APIOrdinalUtxoInfo[];
109
+ export declare function getExtraOrdinalUtxos(addr: string): OrdinalUtxoInfo[];
96
110
  /**
97
111
  * Converts a witness stack to a script witness format that can be used in Bitcoin transactions.
98
112
  * @param witness An array representing the witness stack, where each element is a buffer or a string that can be converted to a buffer.
99
113
  * @returns A buffer containing the script witness data that can be included in a Bitcoin transaction input.
100
114
  */
101
115
  export declare function witnessStackToScriptWitness(witness: any[]): any;
116
+ /** A cardinal UTXO as the Best in Slot API's `cardinal_utxos` route serves it. */
102
117
  export interface APIUtxoInfo {
103
118
  address: string;
104
119
  amounts: number[] | null;
@@ -116,24 +131,22 @@ export interface APIUtxoInfo {
116
131
  vsize: number | null;
117
132
  }
118
133
  /**
119
- * Fetches the UTXOs associated with a given address from the backend API and applies fixes to include any extra UTXOs that are currently in the process of being used in transactions but not yet confirmed on the blockchain.
134
+ * Lists the cardinal UTXOs of an address from the chain provider (see `setProviders`), with the saved extra transactions applied: outputs they spend are dropped and outputs they create for the address are added.
120
135
  *
121
136
  * @param addr The address for which to fetch the UTXOs.
122
137
  * @param fetchedUtxos A response from `fetchCardinalUtxos(addr)` to use in place of a new fetch. Each call works on its own copy, since coin selection sorts and splices the list it is given.
123
138
  * @returns A promise that resolves to an array of UTXO information objects.
124
139
  */
125
- export declare function getCardinalUtxos(addr: string, fetchedUtxos?: APIUtxoInfo[]): Promise<APIUtxoInfo[]>;
140
+ export declare function getCardinalUtxos(addr: string, fetchedUtxos?: Utxo[]): Promise<CardinalUtxoInfo[]>;
126
141
  /**
127
- * Fetches the backend's cardinal UTXO list for an address as served, without the saved extra UTXOs applied. A dry run that prices several transactions fetches this once and passes it to each `getCardinalUtxos` call.
142
+ * Fetches the chain provider's cardinal UTXO list for an address as served, without the saved extra UTXOs applied. A dry run that prices several transactions fetches this once and passes it to each `getCardinalUtxos` call.
128
143
  *
129
144
  * @param addr The address for which to fetch the UTXOs.
130
- * @returns A promise that resolves to the backend's array of UTXO information objects.
145
+ * @returns A promise that resolves to the provider's array of UTXOs.
131
146
  */
132
- export declare function fetchCardinalUtxos(addr: string): Promise<APIUtxoInfo[]>;
147
+ export declare function fetchCardinalUtxos(addr: string): Promise<Utxo[]>;
133
148
  /**
134
- * This function gets the balance of a given address by fetching its UTXOs from the backend and summing
135
- * their values. It also applies fixes to include any extra UTXOs that are currently in the process of
136
- * being used in transactions but not yet confirmed on the blockchain.
149
+ * Sums the values of an address's cardinal UTXOs, with the saved extra transactions applied as in `getCardinalUtxos`.
137
150
  *
138
151
  * @param address The address for which to fetch the balance.
139
152
  * @returns The total balance of the address in satoshis.
@@ -144,15 +157,13 @@ export interface AllBalanceDetails {
144
157
  mempool_balance: number;
145
158
  }
146
159
  /**
147
- * Fetches the balance details of a given address from the backend API, including both confirmed and mempool balances. It also applies fixes to include any extra UTXOs that are currently in the process of being used in transactions but not yet confirmed on the blockchain.
160
+ * Reads the confirmed and mempool balances of an address from the chain provider (see `setProviders`).
148
161
  *
149
162
  * @param addr The address for which to fetch the balance details.
150
163
  * @returns A promise that resolves to an object containing the confirmed balance and mempool balance of the address in satoshis.
151
164
  */
152
165
  export declare function getAllBalanceDetails(addr: string): Promise<AllBalanceDetails>;
153
- /**
154
- * Represents the structure of UTXO information returned by the backend API for ordinal UTXOs. It includes details such as the address, amounts, block height, inscription IDs, rune IDs, satpoints, script, script type, transaction fee, transaction ID, UTXO identifier, value, vout index, and virtual size of the UTXO.
155
- */
166
+ /** An ordinal UTXO as the Best in Slot API's `ordinal_utxos` route serves it. */
156
167
  export interface APIOrdinalUtxoInfo {
157
168
  address: string;
158
169
  amounts: number[] | null;
@@ -170,43 +181,48 @@ export interface APIOrdinalUtxoInfo {
170
181
  vsize: number | null;
171
182
  }
172
183
  /**
173
- * Fetches the ordinal UTXOs associated with a given address from the backend API and applies fixes to include any extra UTXOs that are currently in the process of being used in transactions but not yet confirmed on the blockchain.
184
+ * Lists the ordinal UTXOs of an address from the chain provider (see `setProviders`), with the saved extra transactions applied: outputs they spend are dropped and the output carrying the saved extra inscription is added.
174
185
  *
175
186
  * @param addr The address for which to fetch the ordinal UTXOs.
176
187
  *
177
188
  * @returns A promise that resolves to an array of ordinal UTXO information objects.
178
189
  */
179
- export declare function getOrdinalUtxos(addr: string): Promise<APIOrdinalUtxoInfo[]>;
190
+ export declare function getOrdinalUtxos(addr: string): Promise<OrdinalUtxoInfo[]>;
180
191
  /**
181
- * Fetches the raw transaction hex for a given transaction ID from the backend API. It caches the result to avoid redundant network requests.
192
+ * Returns the raw transaction hex for a transaction ID. Transactions the kit built or fetched before come from a cache; any other is read from the chain provider (see `setProviders`).
182
193
  *
183
194
  * @param txid The transaction ID for which to fetch the raw transaction hex.
184
195
  * @returns A promise that resolves to the raw transaction hex string.
185
196
  */
186
197
  export declare function getTxhex(txid: string): Promise<string>;
187
198
  /**
188
- * Validates a list of transaction hexes by sending them to the backend API for testing their acceptance into the mempool. The function combines the provided transaction hexes with any currently saved extra transaction hexes and sends them to the backend for validation.
199
+ * Tests the mempool acceptance of a list of transactions through the chain provider (see `setProviders`). The saved extra transactions are tested first, so the given transactions may spend their outputs.
189
200
  *
190
201
  * @param txHexes An array of transaction hex strings representing the transactions to be validated.
191
- * @returns A promise that resolves to the validation result returned by the backend API, or null if the validation request fails.
202
+ * @returns A promise that resolves to one result per tested transaction, saved extras included, or null when the provider's request fails with a {@link BackendError}.
192
203
  */
193
- export declare function validateTxes(txHexes: string[]): Promise<any>;
204
+ export declare function validateTxes(txHexes: string[]): Promise<MempoolAcceptResult[] | null>;
194
205
  /**
195
- * Broadcasts a list of transaction hexes to the network by sending them to the backend API. The function throws an error if there are any extra transaction hexes currently set, as broadcasting is not allowed in that state.
206
+ * Broadcasts a list of transactions through the chain provider (see `setProviders`). The function throws an error if there are any extra transaction hexes currently set, as broadcasting is not allowed in that state.
196
207
  *
197
208
  * @param txHexes An array of transaction hex strings representing the transactions to be broadcasted.
198
- * @returns A promise that resolves to the result of the broadcast request returned by the backend API, or null if the broadcast request fails.
209
+ * @returns A promise that resolves to the broadcast transactions' txids, or null when the provider's request fails with a {@link BackendError}.
199
210
  * @throws An error if there are extra transaction hexes currently set, as broadcasting is not allowed in that state.
200
211
  */
201
- export declare function broadcastTxes(txHexes: string[]): Promise<any>;
212
+ export declare function broadcastTxes(txHexes: string[]): Promise<string[] | null>;
213
+ /** The BRC2.0 precompile that verifies a BIP-322 signature; it returns 1 for a valid one. */
214
+ export declare const BIP322_VERIFY_PRECOMPILE = "0x00000000000000000000000000000000000000fe";
202
215
  /**
203
- * Verifies a signature for a given message, signature, and address by sending the verification request to the backend API. The function constructs the necessary parameters for the verification request, including converting the message to hexadecimal format and generating the pkscript from the provided address, and then sends the request to the backend for verification.
216
+ * Verifies a BIP-322 signature with the BRC2.0 chain's own verifier: an `eth_call` to its BIP-322
217
+ * precompile through the network's BRC2.0 RPC provider (see `setProviders`). A signature it accepts
218
+ * is one the chain accepts. A call the node rejects, such as one with a malformed signature, or a
219
+ * request that fails, counts as invalid.
204
220
  *
205
- * @param message The message for which the signature needs to be verified.
206
- * @param signatureHex The signature in hexadecimal format that needs to be verified against the message and address.
207
- * @param address The Bitcoin address that is claimed to have produced the signature for the given message.
208
- * @returns A promise that resolves to a boolean indicating whether the signature is valid for the given message and address, or throws an error if the verification process fails.
209
- * @throws An error if the verification process fails, such as due to network issues or invalid input parameters.
221
+ * @param message The signed message.
222
+ * @param signatureHex The signature, hex encoded.
223
+ * @param address The address that signed.
224
+ * @returns Whether the chain's verifier accepts the signature.
225
+ * @throws {Error} If the address is not valid on the selected network.
210
226
  */
211
227
  export declare function verifySignature(message: string, signatureHex: string, address: string): Promise<boolean>;
212
228
  /**
@@ -232,12 +248,13 @@ export declare function fetchWithErrors<T>(url: string, options: RequestInit): P
232
248
  /**
233
249
  * Retrieves the BRC2.0 JSON-RPC URL configured as the `rpc` endpoint for the selected network.
234
250
  *
251
+ * @param base An RPC URL to use in place of the configured `rpc` endpoint.
235
252
  * @returns The RPC URL.
236
253
  * @throws {Error} If the selected network has no RPC endpoint configured.
237
254
  */
238
- export declare function getPublicRpcUrl(): Promise<string>;
255
+ export declare function getPublicRpcUrl(base?: string): Promise<string>;
239
256
  /**
240
- * Executes an eth_call on the BRC2.0 RPC configured for the selected network. The function constructs the JSON-RPC request payload with the provided data and sends it to the RPC URL for execution. It returns a promise that resolves to the result of the eth_call, or throws an error if the request fails.
257
+ * Executes an eth_call through the BRC2.0 RPC provider of the selected network (see `setProviders`). It returns a promise that resolves to the result of the eth_call, or throws an error if the request fails.
241
258
  *
242
259
  * @param to The address of the contract to call.
243
260
  * @param abi The ABI of the contract to call.
@@ -1,10 +1,13 @@
1
- import { APIOrdinalUtxoInfo, APIUtxoInfo } from '../core/helpers';
2
- import { SignFunction, SignResponse } from '../provider/api';
1
+ import { SignFunction, SignManyFunction, SignResponse } from '../provider/api';
3
2
  import { PaymentOpts } from '../types/common';
4
3
  import { InscribeFees, InscribeMultipleResult, InscribeResult, SendInscriptionResult, InscriptionDetails } from '../types/inscription';
4
+ import { Utxo } from './chain-providers';
5
+ import { OrdinalUtxoInfo } from './helpers';
5
6
  import { Buffer } from 'node:buffer';
6
7
  import { WalletInfo } from '../types/wallet';
7
8
  import * as bitcoinjs from 'bitcoinjs-lib';
9
+ /** Fee rates are sat/vB and may be fractional; every fee built from one is rounded up to whole sats. */
10
+ export declare function assertFeeRate(feeRate: number): void;
8
11
  export declare function getDustValue(wallet: WalletInfo): number;
9
12
  interface TapLeafScriptInfo {
10
13
  script: Buffer;
@@ -125,13 +128,82 @@ export declare function mintWithReclaimsAll(inscriptionDetails: InscriptionDetai
125
128
  postage: number;
126
129
  secret: string;
127
130
  }>;
131
+ /** One inscription of an `inscribeAllToOpReturn` package. */
132
+ export interface BatchedReveal {
133
+ revealTxId: string;
134
+ signedRevealTxHex: string;
135
+ inscriptionId: string;
136
+ secret: string;
137
+ }
138
+ /**
139
+ * How the send tx of `inscribeAllToOpReturn` moves its inscriptions into OP_RETURN outputs.
140
+ *
141
+ * - `single`: one OP_RETURN output worth `postage * (n - 1) + 1` sats, which covers the first sat
142
+ * of every inscription input. The postage of all but the last inscription is burned.
143
+ * - `interleaved`: a 1-sat OP_RETURN output per inscription, each followed by a payer output that
144
+ * takes back the rest of that inscription's postage (the last one merges into change). Only `n`
145
+ * sats are burned. Multiple OP_RETURN outputs relay from Bitcoin Core 30.
146
+ * - `auto`: whichever of the two costs the payer less at the fee rate.
147
+ *
148
+ * Either layout leaves one postage minus a sat after its last OP_RETURN. The send pays the fee
149
+ * from it, or adds a payer input and returns it as change when that costs less (low fee rates).
150
+ */
151
+ export type BatchedSendLayout = 'single' | 'interleaved' | 'auto';
152
+ export interface InscribeAllToOpReturnResult {
153
+ commitTxId: string;
154
+ signedCommitTxHex: string;
155
+ /** One reveal per inscription, in the order the inscriptions were given. */
156
+ reveals: BatchedReveal[];
157
+ sendTxId: string;
158
+ signedSendTxHex: string;
159
+ /** The send layout used; `auto` resolves to one of the other two. */
160
+ sendLayout: Exclude<BatchedSendLayout, 'auto'>;
161
+ /** Miner fees of the commit, the reveals and the send, plus the sats burned in OP_RETURN outputs. */
162
+ totalFee: number;
163
+ }
164
+ /**
165
+ * The fees an `inscribeAllToOpReturn` package with the same arguments would pay, built offline
166
+ * without signing: the commit, the reveals, and the send's miner fee plus the sats it burns in
167
+ * OP_RETURN outputs. The send is priced against `cardinals` (or a fresh fetch) as they stand
168
+ * before the commit, the way `inscribeAllToOpReturn` picks its send plan.
169
+ */
170
+ export declare function getInscribeAllToOpReturnFee(inscriptions: InscriptionDetails[], reclaimInputs: ReclaimInput[], opReturnWallet: WalletInfo, feeRate: number, sendLayout?: BatchedSendLayout, cardinals?: UtxoInfo[]): Promise<{
171
+ totalFee: number;
172
+ sendLayout: Exclude<BatchedSendLayout, 'auto'>;
173
+ }>;
174
+ /**
175
+ * `psbt`'s unsigned transaction with each input's scriptSig as signing will leave it, so its txid
176
+ * is the signed tx's; or null when a signature lands in a scriptSig. SegWit and taproot inputs
177
+ * sign in the witness and keep an empty scriptSig, and a P2SH-P2WPKH input's scriptSig is the push
178
+ * of its redeem script. Any other input, such as legacy P2PKH, makes it null.
179
+ */
180
+ export declare function unsignedTxOnceSigned(psbt: bitcoinjs.Psbt): bitcoinjs.Transaction | null;
181
+ /**
182
+ * Inscribes several inscriptions from one commit tx and sends them all to OP_RETURN outputs in
183
+ * one tx, so the wallet signs two transactions however many inscriptions there are. The signed
184
+ * package is validated with testmempoolaccept and returned for the caller to broadcast.
185
+ *
186
+ * Commit outputs: one self-send per reclaim input (same index and value as the input), then one
187
+ * taproot commit output per inscription, then payer change. Each inscription keeps its own reveal
188
+ * tx, because BRC-20 indexers only accept an inscription made in the first input of its reveal.
189
+ *
190
+ * The send tx spends the reveal outputs as inputs `0..n-1` in the given order, and its outputs
191
+ * follow `sendLayout`. Either way the first sat of every inscription input lands in an OP_RETURN
192
+ * output, in input order, so ord moves each inscription there and indexers process them in that
193
+ * order.
194
+ *
195
+ * With `signManyFunc`, the commit and the send are signed in one wallet prompt whenever the commit's
196
+ * txid is known before signing (see `unsignedTxOnceSigned`); the package is refused if the signed
197
+ * commit's txid differs. Otherwise `signFunc` signs the commit, then the send.
198
+ */
199
+ export declare function inscribeAllToOpReturn(inscriptions: InscriptionDetails[], reclaimInputs: ReclaimInput[], opReturnWallet: WalletInfo, feeRate: number, signFunc: SignFunction, sendLayout?: BatchedSendLayout, signManyFunc?: SignManyFunction | null): Promise<InscribeAllToOpReturnResult>;
128
200
  /**
129
201
  * Estimates the fees for a reclaim mint by building the unsigned reclaim
130
202
  * commit tx (Task 1) and a fee-sizing reveal tx offline, without signing or
131
203
  * broadcasting. Mirrors mintWithExtraInputInCommitFeeRate. `fetchedCardinalUtxos`, the
132
204
  * payer's `fetchCardinalUtxos` response, funds the commit in place of a new fetch.
133
205
  */
134
- export declare function mintWithReclaimsCheckFees(inscriptionDetails: InscriptionDetails, reclaimInputs: ReclaimInput[], feeRate: number, postage: number | null, fetchedCardinalUtxos?: APIUtxoInfo[]): Promise<{
206
+ export declare function mintWithReclaimsCheckFees(inscriptionDetails: InscriptionDetails, reclaimInputs: ReclaimInput[], feeRate: number, postage: number | null, fetchedCardinalUtxos?: Utxo[]): Promise<{
135
207
  unsigned_commit_tx_hex: string;
136
208
  signed_reveal_tx_hex: string;
137
209
  inscription_id: string;
@@ -161,10 +233,12 @@ export declare function resolveReclaimInputs(reclaimInscriptions: {
161
233
  * @param amounts - array of amounts to send to each output wallet (must be the same length as outputWallets)
162
234
  * @param changeWallet - the wallet to send the change to
163
235
  * @param feeRate - the fee rate in sat/vbyte
236
+ * @param fundingInput - add a payer UTXO even when `forceInUtxos` cover the outputs and the fee, so
237
+ * their surplus returns as change instead of going to the miner
164
238
  *
165
239
  * @returns an object containing the built transaction and the fee paid for the transaction
166
240
  */
167
- export declare function buildTransactionMultiOutput(utxoArray: UtxoInfo[], forceInUtxos: UtxoInfoWithWallet[], payerWallet: WalletInfo, outputWallets: WalletInfo[], amounts: number[], changeWallet: WalletInfo, feeRate: number): BuildTransactionResult;
241
+ export declare function buildTransactionMultiOutput(utxoArray: UtxoInfo[], forceInUtxos: UtxoInfoWithWallet[], payerWallet: WalletInfo, outputWallets: WalletInfo[], amounts: number[], changeWallet: WalletInfo, feeRate: number, fundingInput?: boolean): BuildTransactionResult;
168
242
  interface SendMultiInscriptionWithBufferResult {
169
243
  txid: string;
170
244
  signed_tx_hex: string;
@@ -199,7 +273,7 @@ export interface InscriptionUTXODetails {
199
273
  * Otherwise an inscription created by the saved extra transactions resolves from them
200
274
  * directly, and any other inscription is looked up in the backend's `ordinal_utxos` list.
201
275
  */
202
- export declare function getInscriptionDetails(inscriptionId: string, inscriptionAddr: string, ordinalUtxos?: APIOrdinalUtxoInfo[]): Promise<InscriptionUTXODetails | null>;
276
+ export declare function getInscriptionDetails(inscriptionId: string, inscriptionAddr: string, ordinalUtxos?: OrdinalUtxoInfo[]): Promise<InscriptionUTXODetails | null>;
203
277
  /**
204
278
  * Sends multiple inscriptions in one transaction with a buffer output and returns the fee paid for the transaction. This is used for batch minting or batch sending when the user wants to know the fee before actually sending the transaction.
205
279
  *
@@ -271,7 +345,7 @@ interface InscribeCheckFeesResult {
271
345
  *
272
346
  * @returns an object containing the estimated commit fee, reveal fee, total fee, unsigned commit transaction hex, signed reveal transaction hex, inscription ID, and postage used
273
347
  */
274
- export declare function mintAllCheckFees(inscriptionDetails: InscriptionDetails, feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, fetchedCardinalUtxos?: APIUtxoInfo[]): Promise<InscribeCheckFeesResult>;
348
+ export declare function mintAllCheckFees(inscriptionDetails: InscriptionDetails, feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, fetchedCardinalUtxos?: Utxo[]): Promise<InscribeCheckFeesResult>;
275
349
  /**
276
350
  * Sends an inscription to a target address using an OP_RETURN output. This function builds a transaction that spends the inscription UTXO and creates an OP_RETURN output with the inscription data, along with a target output with the specified postage. It then signs and broadcasts the transaction. If dryRun is true, it returns the signed transaction hex without broadcasting.
277
351
  *
@@ -350,7 +424,7 @@ interface SendInscriptionFeeRateResult {
350
424
  *
351
425
  * @returns an object containing the transaction ID, unsigned transaction hex, and calculated transaction fee
352
426
  */
353
- export declare function sendInscriptionToOpReturnWithExtraInputsAndExtraOutputFeeRate(inscriptionId: string, extraInputUtxos: UtxoInfoWithWallet[], targetWallet: WalletInfo, targetPostage: number, extraOutputUtxos: OutputUtxoInfo[], feeRate: number, fetchedCardinalUtxos?: APIUtxoInfo[]): Promise<SendInscriptionFeeRateResult>;
427
+ export declare function sendInscriptionToOpReturnWithExtraInputsAndExtraOutputFeeRate(inscriptionId: string, extraInputUtxos: UtxoInfoWithWallet[], targetWallet: WalletInfo, targetPostage: number, extraOutputUtxos: OutputUtxoInfo[], feeRate: number, fetchedCardinalUtxos?: Utxo[]): Promise<SendInscriptionFeeRateResult>;
354
428
  /**
355
429
  * Mints an inscription with extra input UTXOs included in the commit transaction. This function builds and signs the commit and reveal transactions for minting an inscription, while allowing the user to include additional input UTXOs in the commit transaction. This can be useful in cases where the user wants to fund the commit transaction with specific UTXOs or needs to include additional inputs for other reasons. The function retrieves the connected wallets, builds and signs the transactions, validates them, and broadcasts them to the network. If dryRun is true, it returns the signed transaction hex without broadcasting.
356
430
  *
@@ -379,5 +453,5 @@ export declare function mintWithExtraInputInCommitAll(inscriptionDetails: Inscri
379
453
  *
380
454
  * @returns an object containing the estimated commit fee, reveal fee, total fee, unsigned commit transaction hex, signed reveal transaction hex, inscription ID, and postage used
381
455
  */
382
- export declare function mintWithExtraInputInCommitFeeRate(inscriptionDetails: InscriptionDetails, extraInputUtxos: UtxoInfoWithWallet[], feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, fetchedCardinalUtxos?: APIUtxoInfo[]): Promise<InscribeCheckFeesResult>;
456
+ export declare function mintWithExtraInputInCommitFeeRate(inscriptionDetails: InscriptionDetails, extraInputUtxos: UtxoInfoWithWallet[], feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, fetchedCardinalUtxos?: Utxo[]): Promise<InscribeCheckFeesResult>;
383
457
  export {};
@@ -1,4 +1,4 @@
1
- import { BISProvider, SignFunction } from '../provider/api';
1
+ import { BISProvider, SignFunction, SignManyFunction } from '../provider/api';
2
2
  import { BISSession, BISWallet, BISWalletProvider, BISWalletPurpose } from '../types/common';
3
3
  /**
4
4
  * Thrown before signing when the account active in the wallet extension differs from the
@@ -78,8 +78,16 @@ export declare function getPaymentWallet(): BISWallet | undefined;
78
78
  */
79
79
  export declare function getSignFn(provider: BISWalletProvider): SignFunction;
80
80
  /**
81
- * Signs a message using the currently connected wallet provider, then verifies it
82
- * against the backend. Returns the signature, or throws if signing or verification fails.
81
+ * Returns the specified provider's function for signing several PSBTs in one wallet prompt, or
82
+ * null when the provider or its installed wallet has none.
83
+ *
84
+ * @param provider The wallet provider.
85
+ * @returns The provider's batch sign function, or null.
86
+ */
87
+ export declare function getSignManyFn(provider: BISWalletProvider): SignManyFunction | null;
88
+ /**
89
+ * Signs a message using the currently connected wallet provider, then verifies its BIP-322
90
+ * signature. Returns the signature, or throws if signing or verification fails.
83
91
  *
84
92
  * @param message The message to sign.
85
93
  * @param walletType The wallet purpose to sign with ('payment' | 'ordinals' | 'all').
@@ -1,4 +1,4 @@
1
- import { SignFunction } from '../provider/api';
1
+ import { SignFunction, SignManyFunction } from '../provider/api';
2
2
  /** A wallet prompt a multi-signature flow is about to raise. */
3
3
  export interface SignRequest {
4
4
  /** 1-based index of this prompt within the flow. */
@@ -27,4 +27,6 @@ export declare class SignProgress {
27
27
  constructor(options?: SignProgressOptions, total?: number);
28
28
  next(): void;
29
29
  wrap(signFn: SignFunction): SignFunction;
30
+ /** As `wrap`, for a function that signs several PSBTs in one prompt: each call counts once. */
31
+ wrapMany(signMany: SignManyFunction): SignManyFunction;
30
32
  }
@@ -51,6 +51,14 @@ export type EndpointsConfig = {
51
51
  * @throws {Error} If a key is unknown or a value is not an absolute http(s) URL.
52
52
  */
53
53
  export declare function setEndpoints(config: EndpointsConfig): void;
54
+ /**
55
+ * Checks that a value is an absolute http(s) URL.
56
+ *
57
+ * @param label The setting the value belongs to, used as the error prefix.
58
+ * @param value The URL to check.
59
+ * @throws {Error} If the value is not a valid URL or uses another protocol.
60
+ */
61
+ export declare function assertHttpUrl(label: string, value: string): void;
54
62
  /**
55
63
  * Returns the effective base URLs for a network: the defaults with any
56
64
  * {@link setEndpoints} overrides applied. Testnet has no `sequencerRead`,