@bestinslot/wallet-kit 0.13.6 → 0.13.7

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,12 +1,12 @@
1
1
  import { useSyncExternalStore as u, useCallback as r, useState as w } from "react";
2
- import { R as c, d as t, i as l, h as n } from "./mint-C_wN10-d.js";
2
+ import { T as c, e, k as l, i as n } from "./mint-D4wMHU5r.js";
3
3
  function m() {
4
- const e = u(c, t, t), s = r((o) => l(o), []);
5
- return [e, s];
4
+ const t = u(c, e, e), s = r((o) => l(o), []);
5
+ return [t, s];
6
6
  }
7
7
  function S() {
8
- const e = u(c, t, t), [s, o] = w(() => n() ?? null), a = r(() => o(n() ?? null), []), k = r((i) => l(i), []);
9
- return { session: s, network: e, setNetwork: k, refresh: a };
8
+ const t = u(c, e, e), [s, o] = w(() => n() ?? null), a = r(() => o(n() ?? null), []), k = r((i) => l(i), []);
9
+ return { session: s, network: t, setNetwork: k, refresh: a };
10
10
  }
11
11
  export {
12
12
  m as useNetwork,
@@ -1,5 +1,5 @@
1
- import { D as l, C as x, E as b, d, S as B, G as p, f as S, T, Q as P } from "./mint-C_wN10-d.js";
2
- async function X() {
1
+ import { F as l, E as x, G as b, e as d, U as B, I as p, h as S, V as P, S as T } from "./mint-D4wMHU5r.js";
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");
5
5
  if (!e) throw new Error("Failed to get wallets.");
@@ -92,14 +92,14 @@ async function I(e, n, t, s, o, i) {
92
92
  };
93
93
  }
94
94
  const A = {
95
- getWallets: X,
95
+ getWallets: C,
96
96
  signMessage: $,
97
97
  signMessageDeterministic: L,
98
98
  sendBTC: F,
99
99
  signPSBT: M,
100
100
  sign: I
101
101
  };
102
- async function K() {
102
+ async function U() {
103
103
  if (!window.okxwallet) throw new Error("OKX extension not found.");
104
104
  const e = d();
105
105
  let n;
@@ -116,24 +116,24 @@ async function K() {
116
116
  }
117
117
  ];
118
118
  }
119
- function C() {
119
+ function H() {
120
120
  const e = d();
121
121
  if (e === "mainnet") return window.okxwallet?.bitcoin;
122
122
  if (e === "testnet") return window.okxwallet?.bitcoinTestnet;
123
123
  if (e === "signet") return window.okxwallet?.bitcoinSignet;
124
124
  }
125
- async function U() {
126
- const e = C();
125
+ async function K() {
126
+ const e = H();
127
127
  return typeof e?.getAccounts != "function" ? [] : await e.getAccounts() ?? [];
128
128
  }
129
- function D(e) {
130
- const n = C();
129
+ function N(e) {
130
+ const n = H();
131
131
  if (typeof n?.on != "function") return () => {
132
132
  };
133
133
  const t = (s) => e(s?.address ? [s.address] : []);
134
134
  return n.on("accountChanged", t), () => n.removeListener?.("accountChanged", t);
135
135
  }
136
- async function N(e) {
136
+ async function q(e) {
137
137
  if (!window.okxwallet) throw new Error("OKX extension not found.");
138
138
  const n = d();
139
139
  let t;
@@ -146,7 +146,7 @@ async function N(e) {
146
146
  else throw new Error("Unsupported network for OKX.");
147
147
  return p.from(t, "base64").toString("hex");
148
148
  }
149
- async function q(e) {
149
+ async function D(e) {
150
150
  if (!window.okxwallet) throw new Error("OKX extension not found.");
151
151
  const n = S();
152
152
  if (!n) throw new Error("No payment wallet found.");
@@ -239,11 +239,11 @@ async function W(e, n, t, s, o, i) {
239
239
  };
240
240
  }
241
241
  const _ = {
242
- getWallets: K,
243
- getAccounts: U,
244
- onAccountsChanged: D,
245
- signMessage: N,
246
- signMessageDeterministic: q,
242
+ getWallets: U,
243
+ getAccounts: K,
244
+ onAccountsChanged: N,
245
+ signMessage: q,
246
+ signMessageDeterministic: D,
247
247
  sendBTC: O,
248
248
  signPSBT: v,
249
249
  sign: W
@@ -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 j(e) {
276
+ async function V(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 j(e) {
282
282
  throw console.error("Failed to sign message", n), new Error("Failed to sign message.");
283
283
  }
284
284
  }
285
- async function Q(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 Q(e) {
297
297
  throw console.error("Failed to sign message", s), new Error("Failed to sign message.");
298
298
  }
299
299
  }
300
- async function V(e, n) {
300
+ async function J(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 J(e, n, t, s, o, i) {
331
+ async function Q(e, n, t, s, o, i) {
332
332
  let r = null;
333
333
  if (!n)
334
334
  r = await E(x(e), !1, []);
@@ -368,11 +368,11 @@ const Y = {
368
368
  getWallets: G,
369
369
  getAccounts: z,
370
370
  onAccountsChanged: R,
371
- signMessage: j,
372
- signMessageDeterministic: Q,
373
- sendBTC: V,
371
+ signMessage: V,
372
+ signMessageDeterministic: j,
373
+ sendBTC: J,
374
374
  signPSBT: E,
375
- sign: J
375
+ sign: Q
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",
@@ -445,9 +445,9 @@ async function te(e, n) {
445
445
  ]
446
446
  })).result.txid;
447
447
  }
448
- async function H(e, n, t, s) {
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
  },
@@ -462,7 +462,7 @@ async function se(e, n, t, s, o, i) {
462
462
  const r = l.Psbt.fromHex(e), a = [];
463
463
  for (let w = 0; w < r.inputCount; w++)
464
464
  i && i.includes(w) || s.includes(w) || a.push(w);
465
- const c = await H(
465
+ const c = await X(
466
466
  x(e),
467
467
  !1,
468
468
  [
@@ -491,10 +491,10 @@ const ie = {
491
491
  signMessage: ee,
492
492
  signMessageDeterministic: ne,
493
493
  sendBTC: te,
494
- signPSBT: H,
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", Y);
500
+ T("xverse", ie);
@@ -1,6 +1,6 @@
1
1
  import { WalletInfo } from '../types/wallet';
2
- export { getAllBalanceDetails, getCardinalBalance, getOrdinalsWallet, getPaymentWallet, getSession, sendBTC, sendInscription, setNetwork, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from '../core/bis';
3
- export type { AccountChangeEvent } from '../core/bis';
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';
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';
@@ -5,7 +5,8 @@ export { getAllBalanceDetails, getCardinalBalance } from './helpers';
5
5
  export { getOrdinalsWallet, getPaymentWallet, sendBTC, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from './providers';
6
6
  export type { AccountChangeEvent } from './providers';
7
7
  export { getWalletInfo as getSession } from './store';
8
- export { getNetwork, setNetwork } from './store-network';
8
+ export { getEndpoints, getNetwork, setEndpoints, setNetwork } from './store-network';
9
+ export type { Endpoints, EndpointsConfig } from './store-network';
9
10
  /**
10
11
  * Sends an inscription to a target wallet with the specified postage, fee rate, and dry run option. The function determines the appropriate method for sending the inscription based on the target wallet's properties and the specified wallet type. It uses the provided signing function to sign the necessary transactions for sending the inscription.
11
12
  *
@@ -1,7 +1,41 @@
1
+ import { Endpoints } from './store-network';
1
2
  import * as bitcoinjs from 'bitcoinjs-lib';
2
3
  export declare const txHexByIdCache: {
3
4
  [txid: string]: any;
4
5
  };
6
+ /**
7
+ * Returns the base URL configured for an endpoint on the selected network.
8
+ *
9
+ * @param key The endpoint to resolve.
10
+ * @returns The base URL, without a trailing slash.
11
+ * @throws {Error} If the selected network has no such endpoint configured.
12
+ */
13
+ export declare function getEndpointBase(key: keyof Endpoints): string;
14
+ /**
15
+ * Picks the sequencer endpoint for a route: `sequencerRead` for display reads,
16
+ * `sequencer` for writes and pre-sign reads.
17
+ *
18
+ * @param path The route path, optionally with a sub-path and query string.
19
+ * @returns The endpoint key that serves the route.
20
+ */
21
+ export declare function sequencerEndpointFor(path: string): 'sequencerRead' | 'sequencer';
22
+ /**
23
+ * Builds the full URL for a route on a configured endpoint, after checking that
24
+ * a `/v1` service serves the selected network.
25
+ *
26
+ * @param key The endpoint that serves the route.
27
+ * @param path The route path, with any query string, relative to the endpoint base.
28
+ * @returns The full URL.
29
+ */
30
+ export declare function getEndpointUrl(key: keyof Endpoints, path: string): Promise<string>;
31
+ /**
32
+ * Builds the full URL for a swap sequencer route, routed to `sequencerRead` or
33
+ * `sequencer` by {@link sequencerEndpointFor}.
34
+ *
35
+ * @param path The route path, with any query string.
36
+ * @returns The full URL.
37
+ */
38
+ export declare function getSwapBackendUrl(path: string): Promise<string>;
5
39
  /**
6
40
  * Creates an unsecured JWT token with the given payload.
7
41
  *
@@ -185,13 +219,6 @@ export declare function verifySignature(message: string, signatureHex: string, a
185
219
  * @throws An error if the verification process fails, such as due to invalid input parameters.
186
220
  */
187
221
  export declare function verifySignatureLocal(message: string, signatureHex: string, address: string): boolean;
188
- /**
189
- * Fetches the current chain tip (the latest block height) from the backend API. The function sends a request to the backend to retrieve the current chain tip and returns it as a number. If the request fails, it throws an error indicating that the chain tip could not be retrieved.
190
- *
191
- * @returns A promise that resolves to the current chain tip (latest block height) as a number, or throws an error if the request fails.
192
- * @throws An error if the request to fetch the chain tip fails, indicating that the chain tip could not be retrieved.
193
- */
194
- export declare function getChainTip(): Promise<number>;
195
222
  /**
196
223
  * A generic helper function to handle fetch requests with consistent error handling.
197
224
  * It automatically checks for non-ok HTTP responses and for an 'error' field
@@ -205,13 +232,14 @@ export declare function getChainTip(): Promise<number>;
205
232
  */
206
233
  export declare function fetchWithErrors<T>(url: string, options: RequestInit): Promise<T>;
207
234
  /**
208
- * Retrieves the appropriate BRC2.0 public RPC URL based on the current network (signet or mainnet). The function checks the current network using the getNetwork function and returns the corresponding public RPC URL for that network. If the network is not supported, it throws an error indicating that the network is unsupported for the public RPC URL.
235
+ * Retrieves the BRC2.0 JSON-RPC URL configured as the `rpc` endpoint for the selected network.
209
236
  *
210
- * @returns The public RPC URL corresponding to the current network (signet or mainnet).
237
+ * @returns The RPC URL.
238
+ * @throws {Error} If the selected network has no RPC endpoint configured.
211
239
  */
212
- export declare function getPublicRpcUrl(): string;
240
+ export declare function getPublicRpcUrl(): Promise<string>;
213
241
  /**
214
- * Executes an eth_call on the appropriate public RPC URL based on the current network (signet or mainnet). The function constructs the JSON-RPC request payload with the provided data and sends it to the public 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.
242
+ * 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.
215
243
  *
216
244
  * @param to The address of the contract to call.
217
245
  * @param abi The ABI of the contract to call.
@@ -220,10 +248,3 @@ export declare function getPublicRpcUrl(): string;
220
248
  * @returns A promise that resolves to the result of the eth_call as a string, or throws an error if the request fails.
221
249
  */
222
250
  export declare function ethCallOnPublicRpc(to: string, abi: any, functionName: string, params: any): Promise<string>;
223
- /**
224
- * Constructs the appropriate backend URL for a given API path based on the current network (signet or mainnet). The function checks the current network using the getNetwork function and returns the corresponding URL for the swap backend API. If the network is not supported, it throws an error indicating that the network is unsupported for the orderbook backend URL.
225
- *
226
- * @param path The specific API path to append to the base URL for the swap backend.
227
- * @returns The full URL for the swap backend API corresponding to the current network and the provided path.
228
- */
229
- export declare function getSwapBackendUrl(path: string): string;
@@ -18,3 +18,45 @@ export declare function setNetwork(newNetwork: BISNetwork): void;
18
18
  * @returns An unsubscribe function that removes the listener.
19
19
  */
20
20
  export declare function subscribeToNetwork(listener: (network: BISNetwork) => void): () => void;
21
+ /**
22
+ * Base URLs of the backend services the kit talks to on one network. Each is
23
+ * joined with a route path (`<base>/<route>`), so a trailing slash is optional.
24
+ */
25
+ export interface Endpoints {
26
+ /** Indexer reads: UTXOs, balances, raw transactions, BIP-322 verification. */
27
+ indexer: string;
28
+ /** Bitcoin transaction submission: `testmempoolaccept` and `sendrawtransactions`. */
29
+ tx: string;
30
+ /** Swap sequencer display reads: tokens, pairs table, volume, klines, TVL, activity feeds, token decimals. */
31
+ sequencerRead: string;
32
+ /** Swap sequencer writes and the fresh reads taken right before signing (status, fees, nonce, balances, reserves, deposit, swap, withdraw, ...). */
33
+ sequencer: string;
34
+ /** BRC2.0 JSON-RPC endpoint used for `eth_call`. */
35
+ rpc: string;
36
+ }
37
+ /** Per-network endpoint overrides accepted by {@link setEndpoints}. */
38
+ export type EndpointsConfig = {
39
+ [N in BISNetwork]?: Partial<Endpoints>;
40
+ };
41
+ /**
42
+ * Overrides the backend base URLs per network. Each network's entry is merged
43
+ * over the built-in defaults, so only the keys you pass change. Every call
44
+ * replaces the previous overrides; `setEndpoints({})` restores the defaults.
45
+ *
46
+ * A base URL whose path starts with `/v1` is checked against its server's
47
+ * `/v1/info` before the first request to that origin, and requests fail if the
48
+ * server reports a different network than the one selected.
49
+ *
50
+ * @param config Per-network partial endpoint maps, e.g. `{ signet: { rpc: 'https://my-rpc.example' } }`.
51
+ * @throws {Error} If a key is unknown or a value is not an absolute http(s) URL.
52
+ */
53
+ export declare function setEndpoints(config: EndpointsConfig): void;
54
+ /**
55
+ * Returns the effective base URLs for a network: the defaults with any
56
+ * {@link setEndpoints} overrides applied. Testnet has no `sequencerRead`,
57
+ * `sequencer` or `rpc` unless configured.
58
+ *
59
+ * @param network The network to read. Defaults to the selected network.
60
+ * @returns The endpoint map for that network.
61
+ */
62
+ export declare function getEndpoints(network?: BISNetwork): Partial<Endpoints>;
@@ -4,7 +4,8 @@ export * as brc20 from './api/brc20';
4
4
  export * as mint from './api/mint';
5
5
  export * as balances from './api/balances';
6
6
  export * from './api/helpers';
7
- export { getNetwork, setNetwork, subscribeToNetwork } from './core/store-network';
7
+ export { getEndpoints, getNetwork, setEndpoints, setNetwork, subscribeToNetwork, } from './core/store-network';
8
+ export type { Endpoints, EndpointsConfig } from './core/store-network';
8
9
  export type { PaymentOpts } from './types/common';
9
10
  export * as bitcoinjs from 'bitcoinjs-lib';
10
11
  export * as Buff from '@cmdcode/buff-utils';
package/dist/vue.js CHANGED
@@ -1,13 +1,13 @@
1
- import { ref as s, onScopeDispose as i, watch as u } from "vue";
2
- import { d as r, R as c, i as a } from "./mint-C_wN10-d.js";
3
- function w() {
4
- const e = s(r()), t = c((o) => {
5
- e.value !== o && (e.value = o);
1
+ import { ref as s, onScopeDispose as u, watch as i } from "vue";
2
+ import { e as r, T as c, k as a } from "./mint-D4wMHU5r.js";
3
+ function n() {
4
+ const o = s(r()), t = c((e) => {
5
+ o.value !== e && (o.value = e);
6
6
  });
7
- return i(t, !0), u(e, (o) => {
8
- o !== r() && a(o);
9
- }), e;
7
+ return u(t, !0), i(o, (e) => {
8
+ e !== r() && a(e);
9
+ }), o;
10
10
  }
11
11
  export {
12
- w as useNetwork
12
+ n as useNetwork
13
13
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bestinslot/wallet-kit",
3
3
  "type": "module",
4
- "version": "0.13.6",
4
+ "version": "0.13.7",
5
5
  "private": false,
6
6
  "description": "A lightweight JavaScript library for connecting Bitcoin wallets with a unified API.",
7
7
  "license": "MIT",