@bestinslot/wallet-kit 0.14.3 → 0.14.4

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/react.js CHANGED
@@ -1,11 +1,11 @@
1
- import { useSyncExternalStore as u, useCallback as r, useState as w } from "react";
2
- import { U as c, e, k as l, i as n } from "./mint-CSk_3TfL.js";
1
+ import { useSyncExternalStore as l, useCallback as r, useState as i } from "react";
2
+ import { Z as u, e, l as c, j as n } from "./mint-eUvlNox0.js";
3
3
  function m() {
4
- const t = u(c, e, e), s = r((o) => l(o), []);
4
+ const t = l(u, e, e), s = r((o) => c(o), []);
5
5
  return [t, s];
6
6
  }
7
7
  function S() {
8
- const t = u(c, e, e), [s, o] = w(() => n() ?? null), a = r(() => o(n() ?? null), []), k = r((i) => l(i), []);
8
+ const t = l(u, e, e), [s, o] = i(() => n() ?? null), a = r(() => o(n() ?? null), []), k = r((w) => c(w), []);
9
9
  return { session: s, network: t, setNetwork: k, refresh: a };
10
10
  }
11
11
  export {
@@ -1,4 +1,4 @@
1
- import { G as l, F as x, H as b, e as d, V as B, J as p, h as S, X as T, T as P } from "./mint-CSk_3TfL.js";
1
+ import { K as l, J as x, L as b, e as d, _ as B, N as p, h as S, $ as P, Y as T } from "./mint-eUvlNox0.js";
2
2
  async function C() {
3
3
  if (!window.LeatherProvider) throw new Error("Leather extension not found.");
4
4
  const e = await window.LeatherProvider.request("getAddresses");
@@ -122,11 +122,11 @@ function H() {
122
122
  if (e === "testnet") return window.okxwallet?.bitcoinTestnet;
123
123
  if (e === "signet") return window.okxwallet?.bitcoinSignet;
124
124
  }
125
- async function U() {
125
+ async function N() {
126
126
  const e = H();
127
127
  return typeof e?.getAccounts != "function" ? [] : await e.getAccounts() ?? [];
128
128
  }
129
- function N(e) {
129
+ function U(e) {
130
130
  const n = H();
131
131
  if (typeof n?.on != "function") return () => {
132
132
  };
@@ -240,8 +240,8 @@ async function W(e, n, t, s, o, i) {
240
240
  }
241
241
  const _ = {
242
242
  getWallets: K,
243
- getAccounts: U,
244
- onAccountsChanged: N,
243
+ getAccounts: N,
244
+ onAccountsChanged: U,
245
245
  signMessage: q,
246
246
  signMessageDeterministic: D,
247
247
  sendBTC: O,
@@ -273,7 +273,7 @@ function R(e) {
273
273
  const t = (s) => e(s ?? []);
274
274
  return n.on("accountsChanged", t), () => n.removeListener?.("accountsChanged", t);
275
275
  }
276
- async function V(e) {
276
+ async function j(e) {
277
277
  await k();
278
278
  try {
279
279
  const n = await window.unisat.signMessage(e, "bip322-simple");
@@ -282,7 +282,7 @@ async function V(e) {
282
282
  throw console.error("Failed to sign message", n), new Error("Failed to sign message.");
283
283
  }
284
284
  }
285
- async function j(e) {
285
+ async function J(e) {
286
286
  await k();
287
287
  const n = S();
288
288
  if (!n) throw new Error("No payment wallet found.");
@@ -297,7 +297,7 @@ async function j(e) {
297
297
  throw console.error("Failed to sign message", s), new Error("Failed to sign message.");
298
298
  }
299
299
  }
300
- async function J(e, n) {
300
+ async function V(e, n) {
301
301
  await k();
302
302
  try {
303
303
  return await window.unisat.sendBitcoin(n, e);
@@ -328,7 +328,7 @@ async function E(e, n, t) {
328
328
  }
329
329
  return n && (o = await window.unisat.pushPsbt(o)), o;
330
330
  }
331
- async function Q(e, n, t, s, o, i) {
331
+ async function Y(e, n, t, s, o, i) {
332
332
  let r = null;
333
333
  if (!n)
334
334
  r = await E(x(e), !1, []);
@@ -363,16 +363,16 @@ async function Q(e, n, t, s, o, i) {
363
363
  signedTxHex: u
364
364
  };
365
365
  }
366
- const Y = {
366
+ const Q = {
367
367
  checkNetwork: k,
368
368
  getWallets: G,
369
369
  getAccounts: z,
370
370
  onAccountsChanged: R,
371
- signMessage: V,
372
- signMessageDeterministic: j,
373
- sendBTC: J,
371
+ signMessage: j,
372
+ signMessageDeterministic: J,
373
+ sendBTC: V,
374
374
  signPSBT: E,
375
- sign: Q
375
+ sign: Y
376
376
  };
377
377
  function y() {
378
378
  const e = d();
@@ -383,7 +383,7 @@ function y() {
383
383
  }
384
384
  async function Z() {
385
385
  if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
386
- const e = T({
386
+ const e = P({
387
387
  purposes: ["ordinals", "payment"],
388
388
  message: "[Best in Slot] wants to know your addresses!",
389
389
  network: {
@@ -399,7 +399,7 @@ async function Z() {
399
399
  }
400
400
  async function ee(e, n, t) {
401
401
  if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
402
- const s = T({
402
+ const s = P({
403
403
  address: t,
404
404
  message: e,
405
405
  protocol: "BIP322",
@@ -417,7 +417,7 @@ async function ne(e) {
417
417
  if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
418
418
  const n = S();
419
419
  if (!n) throw new Error("No payment wallet found.");
420
- const t = n.address, s = T({
420
+ const t = n.address, s = P({
421
421
  address: t,
422
422
  message: e,
423
423
  protocol: "ECDSA",
@@ -447,7 +447,7 @@ async function te(e, n) {
447
447
  }
448
448
  async function X(e, n, t, s) {
449
449
  if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
450
- const o = T({
450
+ const o = P({
451
451
  network: {
452
452
  type: y()
453
453
  },
@@ -494,7 +494,7 @@ const ie = {
494
494
  signPSBT: X,
495
495
  sign: se
496
496
  };
497
- P("leather", A);
498
- P("okx", _);
499
- P("unisat", Y);
500
- P("xverse", ie);
497
+ T("leather", A);
498
+ T("okx", _);
499
+ T("unisat", Q);
500
+ T("xverse", ie);
@@ -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,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,54 @@
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
+ /**
31
+ * Reads the inscription's output from the `inscription_utxo` route. An indexer without that
32
+ * route (HTTP 404) is searched through `ordinal_utxos` instead.
33
+ */
34
+ inscriptionUtxo(address: string, inscriptionId: string): Promise<OrdinalUtxo | null>;
35
+ balance(address: string): Promise<ChainBalance>;
36
+ txHex(txid: string): Promise<string>;
37
+ testMempoolAccept(txHexes: string[]): Promise<MempoolAcceptResult[]>;
38
+ broadcast(txHexes: string[]): Promise<string[]>;
39
+ }
40
+ /**
41
+ * The default {@link Brc20RpcProvider}: sends JSON-RPC requests over HTTP.
42
+ *
43
+ * Without constructor options it uses the `rpc` endpoint of the selected network, as set with
44
+ * `setEndpoints`.
45
+ */
46
+ export declare class BisBrc20RpcProvider implements Brc20RpcProvider {
47
+ private readonly rpc?;
48
+ /**
49
+ * @param options The JSON-RPC URL that takes the place of the `setEndpoints` value.
50
+ * @throws {Error} If the URL is not an absolute http(s) URL.
51
+ */
52
+ constructor(options?: BisBrc20RpcProviderOptions);
53
+ request(method: string, params: unknown[]): Promise<unknown>;
54
+ }
@@ -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';
@@ -321,7 +321,7 @@ export interface GetTvlHistoryResponse {
321
321
  /**
322
322
  * Fetches a daily Total Value Locked (TVL) series for a token pair from the swap backend, for charting TVL over time.
323
323
  *
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).
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 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
325
  *
326
326
  * @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
327
  * @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.
@@ -0,0 +1,140 @@
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
+ /**
64
+ * Optional. Returns the address's unspent output that carries the inscription, or `null` when
65
+ * the address holds no such output. `inscription_ids` and `satpoints` may list just that
66
+ * inscription. wallet-kit uses it to find an inscription it is about to spend; a provider
67
+ * without it is searched through {@link ChainProvider.ordinalUtxos} instead.
68
+ */
69
+ inscriptionUtxo?: (address: string, inscriptionId: string) => Promise<OrdinalUtxo | null>;
70
+ /** Returns the address's balance. A provider without mempool data reports `mempool: 0`. */
71
+ balance: (address: string) => Promise<ChainBalance>;
72
+ /** Returns the raw transaction with the given id, hex encoded. */
73
+ txHex: (txid: string) => Promise<string>;
74
+ /**
75
+ * Tests whether the transactions, in order, would enter the mempool. Later transactions may
76
+ * spend outputs of earlier ones. Returns one result per transaction, in the same order.
77
+ */
78
+ testMempoolAccept: (txHexes: string[]) => Promise<MempoolAcceptResult[]>;
79
+ /** Broadcasts the transactions, in order, and returns their txids. */
80
+ broadcast: (txHexes: string[]) => Promise<string[]>;
81
+ }
82
+ /**
83
+ * A BRC2.0 JSON-RPC endpoint. wallet-kit uses it for `eth_call` reads.
84
+ */
85
+ export interface Brc20RpcProvider {
86
+ /**
87
+ * Sends one JSON-RPC request and returns its `result`. Throws when the request fails or the
88
+ * response carries an `error`.
89
+ */
90
+ request: (method: string, params: unknown[]) => Promise<unknown>;
91
+ }
92
+ /** The providers for one network. A key left out uses the default provider. */
93
+ export interface NetworkProviders {
94
+ chain?: ChainProvider;
95
+ brc20Rpc?: Brc20RpcProvider;
96
+ }
97
+ /** Per-network provider overrides accepted by {@link setProviders}. */
98
+ export type ProvidersConfig = {
99
+ [N in BISNetwork]?: NetworkProviders;
100
+ };
101
+ /**
102
+ * Sets the chain data and BRC2.0 RPC providers per network. A network or key left out uses the
103
+ * defaults, {@link BisChainProvider} and {@link BisBrc20RpcProvider}, which read the endpoints
104
+ * set with `setEndpoints`. Every call replaces the previous overrides; `setProviders({})`
105
+ * restores the defaults.
106
+ *
107
+ * @param config Per-network providers, e.g. `{ signet: { chain: myChainProvider } }`.
108
+ * @throws {Error} If a network or key is unknown, or a provider lacks one of its methods.
109
+ */
110
+ export declare function setProviders(config: ProvidersConfig): void;
111
+ /**
112
+ * Returns the providers in effect for a network: the overrides set with {@link setProviders},
113
+ * and the default providers for the keys left out.
114
+ *
115
+ * @param network The network to read. Defaults to the selected network.
116
+ * @returns The chain data and BRC2.0 RPC providers for that network.
117
+ */
118
+ export declare function getProviders(network?: BISNetwork): Required<NetworkProviders>;
119
+ /**
120
+ * Returns the chain data 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 BisChainProvider}.
124
+ */
125
+ export declare function getChainProvider(network?: BISNetwork): ChainProvider;
126
+ /**
127
+ * Returns the BRC2.0 RPC provider for a network.
128
+ *
129
+ * @param network The network to read. Defaults to the selected network.
130
+ * @returns The provider set with {@link setProviders}, or the default {@link BisBrc20RpcProvider}.
131
+ */
132
+ export declare function getBrc20RpcProvider(network?: BISNetwork): Brc20RpcProvider;
133
+ /**
134
+ * Whether a network has a BRC2.0 RPC: a provider set with {@link setProviders}, or an `rpc`
135
+ * endpoint for the default provider.
136
+ *
137
+ * @param network The network to read. Defaults to the selected network.
138
+ * @returns Whether BRC2.0 RPC requests on that network have somewhere to go.
139
+ */
140
+ 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,56 @@ 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
+ * Finds the address's unspent output that carries an inscription, with the saved extra transactions applied: the output they create for the inscription comes first, and an output they spend is not returned. A chain provider with `inscriptionUtxo` (see `setProviders`) answers in one lookup, whatever else the address holds; any other is searched through its `ordinalUtxos`.
193
+ *
194
+ * @param addr The address holding the inscription.
195
+ * @param inscriptionId The inscription's id (`<txid>i<index>`).
196
+ * @returns The output, or `null` when the address does not hold the inscription.
197
+ */
198
+ export declare function getInscriptionUtxo(addr: string, inscriptionId: string): Promise<OrdinalUtxoInfo | null>;
199
+ /**
200
+ * 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
201
  *
183
202
  * @param txid The transaction ID for which to fetch the raw transaction hex.
184
203
  * @returns A promise that resolves to the raw transaction hex string.
185
204
  */
186
205
  export declare function getTxhex(txid: string): Promise<string>;
187
206
  /**
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.
207
+ * 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
208
  *
190
209
  * @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.
210
+ * @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
211
  */
193
- export declare function validateTxes(txHexes: string[]): Promise<any>;
212
+ export declare function validateTxes(txHexes: string[]): Promise<MempoolAcceptResult[] | null>;
194
213
  /**
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.
214
+ * 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
215
  *
197
216
  * @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.
217
+ * @returns A promise that resolves to the broadcast transactions' txids, or null when the provider's request fails with a {@link BackendError}.
199
218
  * @throws An error if there are extra transaction hexes currently set, as broadcasting is not allowed in that state.
200
219
  */
201
- export declare function broadcastTxes(txHexes: string[]): Promise<any>;
220
+ export declare function broadcastTxes(txHexes: string[]): Promise<string[] | null>;
221
+ /** The BRC2.0 precompile that verifies a BIP-322 signature; it returns 1 for a valid one. */
222
+ export declare const BIP322_VERIFY_PRECOMPILE = "0x00000000000000000000000000000000000000fe";
202
223
  /**
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.
224
+ * Verifies a BIP-322 signature with the BRC2.0 chain's own verifier: an `eth_call` to its BIP-322
225
+ * precompile through the network's BRC2.0 RPC provider (see `setProviders`). A signature it accepts
226
+ * is one the chain accepts. A call the node rejects, such as one with a malformed signature, or a
227
+ * request that fails, counts as invalid.
204
228
  *
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.
229
+ * @param message The signed message.
230
+ * @param signatureHex The signature, hex encoded.
231
+ * @param address The address that signed.
232
+ * @returns Whether the chain's verifier accepts the signature.
233
+ * @throws {Error} If the address is not valid on the selected network.
210
234
  */
211
235
  export declare function verifySignature(message: string, signatureHex: string, address: string): Promise<boolean>;
212
236
  /**
@@ -232,12 +256,13 @@ export declare function fetchWithErrors<T>(url: string, options: RequestInit): P
232
256
  /**
233
257
  * Retrieves the BRC2.0 JSON-RPC URL configured as the `rpc` endpoint for the selected network.
234
258
  *
259
+ * @param base An RPC URL to use in place of the configured `rpc` endpoint.
235
260
  * @returns The RPC URL.
236
261
  * @throws {Error} If the selected network has no RPC endpoint configured.
237
262
  */
238
- export declare function getPublicRpcUrl(): Promise<string>;
263
+ export declare function getPublicRpcUrl(base?: string): Promise<string>;
239
264
  /**
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.
265
+ * 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
266
  *
242
267
  * @param to The address of the contract to call.
243
268
  * @param abi The ABI of the contract to call.
@@ -1,7 +1,8 @@
1
- import { APIOrdinalUtxoInfo, APIUtxoInfo } from '../core/helpers';
2
1
  import { SignFunction, 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';
@@ -131,7 +132,7 @@ export declare function mintWithReclaimsAll(inscriptionDetails: InscriptionDetai
131
132
  * broadcasting. Mirrors mintWithExtraInputInCommitFeeRate. `fetchedCardinalUtxos`, the
132
133
  * payer's `fetchCardinalUtxos` response, funds the commit in place of a new fetch.
133
134
  */
134
- export declare function mintWithReclaimsCheckFees(inscriptionDetails: InscriptionDetails, reclaimInputs: ReclaimInput[], feeRate: number, postage: number | null, fetchedCardinalUtxos?: APIUtxoInfo[]): Promise<{
135
+ export declare function mintWithReclaimsCheckFees(inscriptionDetails: InscriptionDetails, reclaimInputs: ReclaimInput[], feeRate: number, postage: number | null, fetchedCardinalUtxos?: Utxo[]): Promise<{
135
136
  unsigned_commit_tx_hex: string;
136
137
  signed_reveal_tx_hex: string;
137
138
  inscription_id: string;
@@ -195,11 +196,11 @@ export interface InscriptionUTXODetails {
195
196
  utxo: string;
196
197
  }
197
198
  /**
198
- * Locates an inscription's UTXO on `inscriptionAddr`. Searches `ordinalUtxos` when given.
199
- * Otherwise an inscription created by the saved extra transactions resolves from them
200
- * directly, and any other inscription is looked up in the backend's `ordinal_utxos` list.
199
+ * Locates an inscription's UTXO on `inscriptionAddr`. Searches `ordinalUtxos` when given;
200
+ * otherwise reads it with `getInscriptionUtxo` (saved extra transactions first, then the
201
+ * chain provider).
201
202
  */
202
- export declare function getInscriptionDetails(inscriptionId: string, inscriptionAddr: string, ordinalUtxos?: APIOrdinalUtxoInfo[]): Promise<InscriptionUTXODetails | null>;
203
+ export declare function getInscriptionDetails(inscriptionId: string, inscriptionAddr: string, ordinalUtxos?: OrdinalUtxoInfo[]): Promise<InscriptionUTXODetails | null>;
203
204
  /**
204
205
  * 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
206
  *
@@ -271,7 +272,7 @@ interface InscribeCheckFeesResult {
271
272
  *
272
273
  * @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
274
  */
274
- export declare function mintAllCheckFees(inscriptionDetails: InscriptionDetails, feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, fetchedCardinalUtxos?: APIUtxoInfo[]): Promise<InscribeCheckFeesResult>;
275
+ export declare function mintAllCheckFees(inscriptionDetails: InscriptionDetails, feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, fetchedCardinalUtxos?: Utxo[]): Promise<InscribeCheckFeesResult>;
275
276
  /**
276
277
  * 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
278
  *
@@ -350,7 +351,7 @@ interface SendInscriptionFeeRateResult {
350
351
  *
351
352
  * @returns an object containing the transaction ID, unsigned transaction hex, and calculated transaction fee
352
353
  */
353
- export declare function sendInscriptionToOpReturnWithExtraInputsAndExtraOutputFeeRate(inscriptionId: string, extraInputUtxos: UtxoInfoWithWallet[], targetWallet: WalletInfo, targetPostage: number, extraOutputUtxos: OutputUtxoInfo[], feeRate: number, fetchedCardinalUtxos?: APIUtxoInfo[]): Promise<SendInscriptionFeeRateResult>;
354
+ export declare function sendInscriptionToOpReturnWithExtraInputsAndExtraOutputFeeRate(inscriptionId: string, extraInputUtxos: UtxoInfoWithWallet[], targetWallet: WalletInfo, targetPostage: number, extraOutputUtxos: OutputUtxoInfo[], feeRate: number, fetchedCardinalUtxos?: Utxo[]): Promise<SendInscriptionFeeRateResult>;
354
355
  /**
355
356
  * 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
357
  *
@@ -379,5 +380,5 @@ export declare function mintWithExtraInputInCommitAll(inscriptionDetails: Inscri
379
380
  *
380
381
  * @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
382
  */
382
- export declare function mintWithExtraInputInCommitFeeRate(inscriptionDetails: InscriptionDetails, extraInputUtxos: UtxoInfoWithWallet[], feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, fetchedCardinalUtxos?: APIUtxoInfo[]): Promise<InscribeCheckFeesResult>;
383
+ export declare function mintWithExtraInputInCommitFeeRate(inscriptionDetails: InscriptionDetails, extraInputUtxos: UtxoInfoWithWallet[], feeRate: number, postage: number | null, paymentAddr: string | null, payment: number | null, fetchedCardinalUtxos?: Utxo[]): Promise<InscribeCheckFeesResult>;
383
384
  export {};