@bestinslot/wallet-kit 0.14.3 → 0.15.0-rc.1

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.
Files changed (34) hide show
  1. package/README.md +3 -1
  2. package/dist/balances-CcnzsQly.js +10930 -0
  3. package/dist/browser.js +110 -95
  4. package/dist/core.js +40 -34
  5. package/dist/{mint-CSk_3TfL.js → helpers-BvhfqxFB.js} +28787 -28389
  6. package/dist/node.js +726 -1166
  7. package/dist/react.js +4 -4
  8. package/dist/register-browser-providers-DxplsCV5.js +810 -0
  9. package/dist/types/api/helpers.d.ts +3 -0
  10. package/dist/types/api/swap.d.ts +3 -3
  11. package/dist/types/api/wallet.d.ts +2 -2
  12. package/dist/types/core/bis-providers.d.ts +49 -0
  13. package/dist/types/core/bis.d.ts +2 -0
  14. package/dist/types/core/bis_swap.d.ts +32 -7
  15. package/dist/types/core/brc20-send.d.ts +2 -1
  16. package/dist/types/core/chain-providers.d.ts +133 -0
  17. package/dist/types/core/helpers.d.ts +48 -31
  18. package/dist/types/core/mint.d.ts +82 -8
  19. package/dist/types/core/providers.d.ts +11 -3
  20. package/dist/types/core/sign-progress.d.ts +3 -1
  21. package/dist/types/core/store-network.d.ts +8 -0
  22. package/dist/types/core.d.ts +2 -0
  23. package/dist/types/provider/api.d.ts +20 -0
  24. package/dist/types/provider/bitcoin-wallet.d.ts +45 -0
  25. package/dist/types/provider/metamask.d.ts +6 -0
  26. package/dist/types/provider/phantom.d.ts +2 -0
  27. package/dist/types/provider/wallet-standard.d.ts +14 -0
  28. package/dist/types/types/common.d.ts +1 -1
  29. package/dist/types/types/global.d.ts +3 -5
  30. package/dist/vue.js +3 -3
  31. package/package.json +29 -25
  32. package/dist/balances-DYYM7kpl.js +0 -10363
  33. package/dist/register-browser-providers-BdTwEVwB.js +0 -500
  34. package/dist/types/provider/leather.d.ts +0 -2
@@ -1,4 +1,7 @@
1
1
  export { BackendError } from '../core/backend-error';
2
+ export { BisBrc20RpcProvider, BisChainProvider } from '../core/bis-providers';
3
+ export type { BisBrc20RpcProviderOptions, BisChainProviderOptions } from '../core/bis-providers';
2
4
  export { getEvmAddressFromBitcoinAddress, getEvmAddressFromPkScript } from '../core/brc20';
5
+ export type { Brc20RpcProvider, ChainBalance, ChainProvider, MempoolAcceptResult, OrdinalUtxo, Utxo, } from '../core/chain-providers';
3
6
  export { delegateInscription, jsonInscription, textInscription } from '../types/inscription';
4
7
  export { addressWalletInfo, opReturnWalletInfo } from '../types/wallet';
@@ -1,4 +1,4 @@
1
- import { GetRecentActivityRequest, WalletActivityKind } from '../core/bis_swap';
1
+ import { DepositOrderOptions, GetRecentActivityRequest, WalletActivityKind } from '../core/bis_swap';
2
2
  import { SignProgressOptions } from '../core/sign-progress';
3
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
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';
@@ -130,13 +130,13 @@ export declare function unwrapBtc(pkscript: string, amount: bigint): Promise<boo
130
130
  * @param feeRate - The fee rate for the deposit operation.
131
131
  * @param createAllowanceIfNeeded - Whether to create an allowance if needed.
132
132
  * @param reclaimInscriptions - Optional transfer inscriptions to reclaim toward the deposit, each with `inscriptionId` and `amount` (bigint, 18 decimals).
133
- * @param options - `onSignRequest` is called before each wallet prompt with `{ step, total }`. `total` is 3, 5 or 7.
133
+ * @param options - `onSignRequest` is called before each wallet prompt with `{ step, total }`. `total` is 3, 5 or 7, and 3 whenever `batchInscriptions` is set. `batchInscriptions` inscribes the base-layer conversion, the allowance and the deposit from one commit and sends them to OP_RETURN in one tx. `batchSendLayout` (`single`, `interleaved` or `auto`, default `single`) picks how that tx lays out its OP_RETURN outputs.
134
134
  * @returns A promise that resolves to an array of transaction IDs related to the deposit operation.
135
135
  */
136
136
  export declare function deposit(tokenAddress: string, amount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: {
137
137
  inscriptionId: string;
138
138
  amount: bigint;
139
- }[], options?: SignProgressOptions): Promise<string[]>;
139
+ }[], options?: DepositOrderOptions): Promise<string[]>;
140
140
  /**
141
141
  * Wraps BTC into the smart wallet as WBTC (the swap layer's BTC representation),
142
142
  * the BTC equivalent of `deposit`.
@@ -1,6 +1,6 @@
1
1
  import { WalletInfo } from '../types/wallet';
2
- export { getAllBalanceDetails, getCardinalBalance, getEndpoints, getOrdinalsWallet, getPaymentWallet, getSession, sendBTC, sendInscription, setEndpoints, setNetwork, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from '../core/bis';
3
- export type { AccountChangeEvent, Endpoints, EndpointsConfig } from '../core/bis';
2
+ export { getAllBalanceDetails, getCardinalBalance, getEndpoints, getOrdinalsWallet, getPaymentWallet, getProviders, getSession, sendBTC, sendInscription, setEndpoints, setNetwork, setProviders, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from '../core/bis';
3
+ export type { AccountChangeEvent, Endpoints, EndpointsConfig, NetworkProviders, ProvidersConfig, } from '../core/bis';
4
4
  export type { WalletInfo };
5
5
  export { getNetwork } from '../core/store-network';
6
6
  export type { BISNetwork, BISSession, BISWallet, BISWalletProvider, BISWalletPurpose, } from '../types/common';
@@ -0,0 +1,49 @@
1
+ import { Brc20RpcProvider, ChainBalance, ChainProvider, MempoolAcceptResult, OrdinalUtxo, Utxo } from './chain-providers';
2
+ /** Endpoint base URLs for a {@link BisChainProvider}. A key left out reads `setEndpoints`. */
3
+ export interface BisChainProviderOptions {
4
+ /** Base URL for UTXO, balance and raw transaction reads. */
5
+ indexer?: string;
6
+ /** Base URL for mempool acceptance tests and broadcasts. */
7
+ tx?: string;
8
+ }
9
+ /** Endpoint base URL for a {@link BisBrc20RpcProvider}. Left out, it reads `setEndpoints`. */
10
+ export interface BisBrc20RpcProviderOptions {
11
+ /** The BRC2.0 JSON-RPC URL. */
12
+ rpc?: string;
13
+ }
14
+ /**
15
+ * The default {@link ChainProvider}: reads chain data from the Best in Slot API.
16
+ *
17
+ * Without constructor options it uses the `indexer` and `tx` endpoints of the selected network,
18
+ * as set with `setEndpoints`. Returned outputs keep every field the API sends.
19
+ */
20
+ export declare class BisChainProvider implements ChainProvider {
21
+ private readonly indexer?;
22
+ private readonly tx?;
23
+ /**
24
+ * @param options Endpoint base URLs that take the place of the `setEndpoints` values.
25
+ * @throws {Error} If a URL is not an absolute http(s) URL.
26
+ */
27
+ constructor(options?: BisChainProviderOptions);
28
+ cardinalUtxos(address: string): Promise<Utxo[]>;
29
+ ordinalUtxos(address: string): Promise<OrdinalUtxo[]>;
30
+ balance(address: string): Promise<ChainBalance>;
31
+ txHex(txid: string): Promise<string>;
32
+ testMempoolAccept(txHexes: string[]): Promise<MempoolAcceptResult[]>;
33
+ broadcast(txHexes: string[]): Promise<string[]>;
34
+ }
35
+ /**
36
+ * The default {@link Brc20RpcProvider}: sends JSON-RPC requests over HTTP.
37
+ *
38
+ * Without constructor options it uses the `rpc` endpoint of the selected network, as set with
39
+ * `setEndpoints`.
40
+ */
41
+ export declare class BisBrc20RpcProvider implements Brc20RpcProvider {
42
+ private readonly rpc?;
43
+ /**
44
+ * @param options The JSON-RPC URL that takes the place of the `setEndpoints` value.
45
+ * @throws {Error} If the URL is not an absolute http(s) URL.
46
+ */
47
+ constructor(options?: BisBrc20RpcProviderOptions);
48
+ request(method: string, params: unknown[]): Promise<unknown>;
49
+ }
@@ -1,6 +1,8 @@
1
1
  import { BISWalletPurpose } from '../types/common';
2
2
  import { SendInscriptionResult } from '../types/inscription';
3
3
  import { WalletInfo } from '../types/wallet';
4
+ export { getProviders, setProviders } from './chain-providers';
5
+ export type { NetworkProviders, ProvidersConfig } from './chain-providers';
4
6
  export { getAllBalanceDetails, getCardinalBalance } from './helpers';
5
7
  export { getOrdinalsWallet, getPaymentWallet, sendBTC, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from './providers';
6
8
  export type { AccountChangeEvent } from './providers';
@@ -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.