@bestinslot/wallet-kit 0.13.5 → 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.
@@ -41892,6 +41892,62 @@ function subscribeToNetwork(t) {
41892
41892
  listeners.delete(t);
41893
41893
  };
41894
41894
  }
41895
+ const DEFAULT_ENDPOINTS = {
41896
+ mainnet: {
41897
+ indexer: "https://ts-proxy.bestinslot.xyz/v3/mainnet",
41898
+ tx: "https://ts-proxy.bestinslot.xyz/v3/mainnet",
41899
+ sequencerRead: "https://sa-proxy.bestinslot.xyz",
41900
+ sequencer: "https://sa-proxy.bestinslot.xyz",
41901
+ rpc: "https://rpc.brc20.build"
41902
+ },
41903
+ signet: {
41904
+ indexer: "https://ts-proxy.bestinslot.xyz/v3/signet",
41905
+ tx: "https://ts-proxy.bestinslot.xyz/v3/signet",
41906
+ sequencerRead: "https://sas-proxy.bestinslot.xyz",
41907
+ sequencer: "https://sas-proxy.bestinslot.xyz",
41908
+ rpc: "https://rpc-signet.brc20.build"
41909
+ },
41910
+ // Testnet has no swap sequencer or BRC2.0 RPC unless one is configured.
41911
+ testnet: {
41912
+ indexer: "https://ts-proxy.bestinslot.xyz/v3/testnet",
41913
+ tx: "https://ts-proxy.bestinslot.xyz/v3/testnet"
41914
+ }
41915
+ }, ENDPOINT_KEYS = [
41916
+ "indexer",
41917
+ "tx",
41918
+ "sequencerRead",
41919
+ "sequencer",
41920
+ "rpc"
41921
+ ];
41922
+ let endpointOverrides = {};
41923
+ function setEndpoints(t) {
41924
+ const e = {};
41925
+ for (const [r, A] of Object.entries(t ?? {})) {
41926
+ if (!(r in DEFAULT_ENDPOINTS))
41927
+ throw new Error(`setEndpoints: unknown network '${r}'`);
41928
+ const s = {};
41929
+ for (const [n, o] of Object.entries(A ?? {})) {
41930
+ if (!ENDPOINT_KEYS.includes(n))
41931
+ throw new Error(`setEndpoints: unknown endpoint '${n}' for ${r}`);
41932
+ if (o === void 0)
41933
+ continue;
41934
+ let a;
41935
+ try {
41936
+ a = new URL(o);
41937
+ } catch {
41938
+ throw new Error(`setEndpoints: ${r}.${n} is not a valid URL: ${o}`);
41939
+ }
41940
+ if (a.protocol !== "https:" && a.protocol !== "http:")
41941
+ throw new Error(`setEndpoints: ${r}.${n} must be an http(s) URL: ${o}`);
41942
+ s[n] = o;
41943
+ }
41944
+ e[r] = s;
41945
+ }
41946
+ endpointOverrides = e;
41947
+ }
41948
+ function getEndpoints(t = currentNetwork) {
41949
+ return { ...DEFAULT_ENDPOINTS[t], ...endpointOverrides[t] };
41950
+ }
41895
41951
  function handleNetworkChange() {
41896
41952
  getWalletInfo()?.provider === "unisat" && PROVIDERS.unisat?.checkNetwork?.();
41897
41953
  }
@@ -65523,8 +65579,55 @@ async function withdrawFromBrc20Prog(t, e, r, A, s, n, o, a) {
65523
65579
  }
65524
65580
  const txHexByIdCache = {};
65525
65581
  let currentExtraTxHexes = [], currentExtraInscriptions = null;
65526
- function getBackendUrl(t) {
65527
- return `https://ts-proxy.bestinslot.xyz/v3/${getNetwork()}/${t}`;
65582
+ const SEQUENCER_READ_ROUTES = /* @__PURE__ */ new Set([
65583
+ "get_tokens",
65584
+ "get_table_data",
65585
+ "volume",
65586
+ "klines",
65587
+ "tvl",
65588
+ "pair-activity",
65589
+ "recent-activity",
65590
+ "wallet-activity",
65591
+ "get_token_decimals"
65592
+ ]);
65593
+ function getEndpointBase(t) {
65594
+ const e = getNetwork(), r = getEndpoints(e)[t];
65595
+ if (!r)
65596
+ throw new Error(`No '${t}' endpoint configured for ${e}; set one with setEndpoints()`);
65597
+ return r.replace(/\/+$/, "");
65598
+ }
65599
+ function sequencerEndpointFor(t) {
65600
+ const e = t.split(/[/?]/, 1)[0] ?? "";
65601
+ return SEQUENCER_READ_ROUTES.has(e) ? "sequencerRead" : "sequencer";
65602
+ }
65603
+ const serviceInfoByOrigin = /* @__PURE__ */ new Map();
65604
+ async function assertServiceNetwork(t) {
65605
+ const e = new URL(t);
65606
+ if (!e.pathname.startsWith("/v1"))
65607
+ return;
65608
+ let r = serviceInfoByOrigin.get(e.origin);
65609
+ r || (r = fetchWithErrors(new URL("/v1/info", e).toString(), {
65610
+ method: "GET"
65611
+ }), serviceInfoByOrigin.set(e.origin, r), r.catch(() => serviceInfoByOrigin.delete(e.origin)));
65612
+ let A;
65613
+ try {
65614
+ A = (await r).network;
65615
+ } catch (n) {
65616
+ const o = n instanceof Error ? n.message : String(n);
65617
+ throw new Error(`Could not read ${e.origin}/v1/info: ${o}`);
65618
+ }
65619
+ const s = getNetwork();
65620
+ if (A !== s)
65621
+ throw new Error(
65622
+ `Endpoint ${e.origin} serves '${A}', but the selected network is '${s}'`
65623
+ );
65624
+ }
65625
+ async function getEndpointUrl(t, e) {
65626
+ const r = getEndpointBase(t);
65627
+ return await assertServiceNetwork(r), `${r}/${e}`;
65628
+ }
65629
+ function getSwapBackendUrl(t) {
65630
+ return getEndpointUrl(sequencerEndpointFor(t), t);
65528
65631
  }
65529
65632
  function createSigningInput(t, e) {
65530
65633
  const r = [];
@@ -65738,34 +65841,34 @@ async function getCardinalUtxos(t, e) {
65738
65841
  return fixCardinalUtxos(r, t);
65739
65842
  }
65740
65843
  async function fetchCardinalUtxos(t) {
65741
- const e = getBackendUrl(`cardinal_utxos/${t}`);
65844
+ const e = await getEndpointUrl("indexer", `cardinal_utxos/${t}`);
65742
65845
  return (await fetchWithErrors(e, { method: "GET" })).data;
65743
65846
  }
65744
65847
  async function getCardinalBalance(t) {
65745
- const e = getBackendUrl(`cardinal_utxos/${t}`), r = await fetchWithErrors(e, { method: "GET" }), A = fixCardinalUtxos(r.data, t);
65848
+ const e = await getEndpointUrl("indexer", `cardinal_utxos/${t}`), r = await fetchWithErrors(e, { method: "GET" }), A = fixCardinalUtxos(r.data, t);
65746
65849
  let s = 0;
65747
65850
  for (const n of A)
65748
65851
  s += n.value;
65749
65852
  return s;
65750
65853
  }
65751
65854
  async function getAllBalanceDetails(t) {
65752
- const e = getBackendUrl(`all_balance_details/${t}`);
65855
+ const e = await getEndpointUrl("indexer", `all_balance_details/${t}`);
65753
65856
  return fetchWithErrors(e, { method: "GET" });
65754
65857
  }
65755
65858
  async function getOrdinalUtxos(t) {
65756
- const e = getBackendUrl(`ordinal_utxos/${t}`), r = await fetchWithErrors(e, { method: "GET" });
65859
+ const e = await getEndpointUrl("indexer", `ordinal_utxos/${t}`), r = await fetchWithErrors(e, { method: "GET" });
65757
65860
  return fixOrdinalUtxos(r.data, t);
65758
65861
  }
65759
65862
  async function getTxhex(t) {
65760
65863
  if (!txHexByIdCache[t]) {
65761
- const e = getBackendUrl(`gettxhex/${t}`);
65864
+ const e = await getEndpointUrl("indexer", `gettxhex/${t}`);
65762
65865
  txHexByIdCache[t] = await fetchWithErrors(e, { method: "GET" });
65763
65866
  }
65764
65867
  return txHexByIdCache[t];
65765
65868
  }
65766
65869
  async function validateTxes(t) {
65870
+ const e = await getEndpointUrl("tx", "testmempoolaccept");
65767
65871
  try {
65768
- const e = getBackendUrl("testmempoolaccept");
65769
65872
  return await (await fetch(e, {
65770
65873
  method: "POST",
65771
65874
  headers: {
@@ -65780,8 +65883,8 @@ async function validateTxes(t) {
65780
65883
  async function broadcastTxes(t) {
65781
65884
  if (currentExtraTxHexes.length > 0)
65782
65885
  throw new Error("Cannot broadcast txes when extra txes are set");
65886
+ const e = await getEndpointUrl("tx", "sendrawtransactions");
65783
65887
  try {
65784
- const e = getBackendUrl("sendrawtransactions");
65785
65888
  return await (await fetch(e, {
65786
65889
  method: "POST",
65787
65890
  headers: {
@@ -65794,8 +65897,9 @@ async function broadcastTxes(t) {
65794
65897
  }
65795
65898
  }
65796
65899
  async function verifySignature(t, e, r) {
65900
+ const A = await getEndpointUrl("indexer", "brc20_verify_bip322");
65797
65901
  try {
65798
- const A = getBackendUrl("brc20_verify_bip322"), s = getBitcoinNetwork();
65902
+ const s = getBitcoinNetwork();
65799
65903
  return (await (await fetch(A, {
65800
65904
  method: "POST",
65801
65905
  headers: {
@@ -65843,16 +65947,12 @@ async function fetchWithErrors(t, e) {
65843
65947
  throw new Error(`API Request Failed: ${A}`);
65844
65948
  }
65845
65949
  }
65846
- function getPublicRpcUrl() {
65847
- const t = getNetwork();
65848
- if (t === "signet")
65849
- return "https://rpc-signet.brc20.build";
65850
- if (t === "mainnet")
65851
- return "https://rpc.brc20.build";
65852
- throw new Error("Unsupported network for public RPC URL");
65950
+ async function getPublicRpcUrl() {
65951
+ const t = getEndpointBase("rpc");
65952
+ return await assertServiceNetwork(t), t;
65853
65953
  }
65854
65954
  async function ethCallOnPublicRpc(t, e, r, A) {
65855
- const s = getPublicRpcUrl(), n = evmEncodeFunctionCall(e, r, A);
65955
+ const s = await getPublicRpcUrl(), n = evmEncodeFunctionCall(e, r, A);
65856
65956
  return fetchWithErrors(s, {
65857
65957
  method: "POST",
65858
65958
  headers: {
@@ -65872,14 +65972,6 @@ async function ethCallOnPublicRpc(t, e, r, A) {
65872
65972
  })
65873
65973
  }).then((o) => o.result);
65874
65974
  }
65875
- function getSwapBackendUrl(t) {
65876
- const e = getNetwork();
65877
- if (e === "signet")
65878
- return `https://sas-proxy.bestinslot.xyz/${t}`;
65879
- if (e === "mainnet")
65880
- return `https://sa-proxy.bestinslot.xyz/${t}`;
65881
- throw new Error("Unsupported network for orderbook backend URL");
65882
- }
65883
65975
  const ENABLE_RBF_NO_LOCKTIME = 4294967293, DUST_VALUE_P2PKH = 546, DUST_VALUE_P2WPKH = 294, DUST_VALUE_P2SH = 540, DUST_VALUE_P2TR = 330, DUST_VALUE_MAX = Math.max(
65884
65976
  DUST_VALUE_P2PKH,
65885
65977
  DUST_VALUE_P2WPKH,
@@ -67710,85 +67802,87 @@ async function mintWithExtraInputInCommitFeeRate(t, e, r, A, s, n, o) {
67710
67802
  };
67711
67803
  }
67712
67804
  export {
67713
- compressSmartContractData as $,
67714
- concat as A,
67805
+ saveSwapWalletInfo as $,
67806
+ sha256$6 as A,
67715
67807
  Buffer as B,
67716
- hexToBase64 as C,
67717
- srcExports as D,
67718
- finalizePsbtInputs as E,
67719
- broadcastTxes as F,
67720
- Buffer$1 as G,
67721
- WalletInfo as H,
67722
- getCardinalUtxos as I,
67723
- buildTransaction as J,
67724
- buildPsbtFromTx as K,
67725
- validateTxes as L,
67726
- distExports$2 as M,
67727
- memoryStorage as N,
67728
- getBitcoinNetwork as O,
67729
- saveWalletInfo as P,
67730
- registerProvider as Q,
67731
- subscribeToNetwork as R,
67732
- base64ToHex as S,
67733
- createUnsecuredToken as T,
67734
- getSignFn as U,
67735
- sendInscriptionToOpReturnAll as V,
67808
+ writeUInt32 as C,
67809
+ concat as D,
67810
+ hexToBase64 as E,
67811
+ srcExports as F,
67812
+ finalizePsbtInputs as G,
67813
+ broadcastTxes as H,
67814
+ Buffer$1 as I,
67815
+ WalletInfo as J,
67816
+ getCardinalUtxos as K,
67817
+ buildTransaction as L,
67818
+ buildPsbtFromTx as M,
67819
+ validateTxes as N,
67820
+ distExports$2 as O,
67821
+ memoryStorage as P,
67822
+ getBitcoinNetwork as Q,
67823
+ saveWalletInfo as R,
67824
+ registerProvider as S,
67825
+ subscribeToNetwork as T,
67826
+ base64ToHex as U,
67827
+ createUnsecuredToken as V,
67736
67828
  WalletAccountChangedError as W,
67737
- sendInscriptionInPaymentWalletToOpReturnAll as X,
67738
- sendInscriptionAll as Y,
67739
- saveSwapWalletInfo as Z,
67740
- readSwapWalletInfo as _,
67829
+ getSignFn as X,
67830
+ sendInscriptionToOpReturnAll as Y,
67831
+ sendInscriptionInPaymentWalletToOpReturnAll as Z,
67832
+ sendInscriptionAll as _,
67741
67833
  getAllBalanceDetails as a,
67742
- Buff$3 as a0,
67743
- InscriptionDetails as a1,
67744
- fetchCardinalUtxos as a2,
67745
- resolveReclaimInputs as a3,
67746
- mintWithReclaimsCheckFees as a4,
67747
- mintAllCheckFees as a5,
67748
- saveExtraUtxos as a6,
67749
- Script as a7,
67750
- sendInscriptionToOpReturnWithExtraInputsAndExtraOutputFeeRate as a8,
67751
- clearExtraUtxos as a9,
67752
- utxoOutputTypeFromOutputScript as aa,
67753
- mintWithExtraInputInCommitFeeRate as ab,
67754
- mintWithReclaimsAll as ac,
67755
- mintAll as ad,
67756
- sendInscriptionToOpReturnWithExtraInputsAndExtraOutputAll as ae,
67757
- mintWithExtraInputInCommitAll as af,
67758
- callSmartContract as ag,
67759
- callSmartContractFromPaymentWallet as ah,
67760
- evmEncodeFunctionCall as ai,
67761
- depositToBrc20Prog as aj,
67762
- withdrawFromBrc20Prog as ak,
67763
- inscribeMultiple as al,
67764
- inscribeWithParent as am,
67765
- getInscribeMultipleFee as an,
67766
- getSwapBackendUrl as ao,
67767
- fetchWithErrors as ap,
67768
- ethCallOnPublicRpc as aq,
67834
+ readSwapWalletInfo as a0,
67835
+ getSwapBackendUrl as a1,
67836
+ compressSmartContractData as a2,
67837
+ Buff$3 as a3,
67838
+ InscriptionDetails as a4,
67839
+ fetchCardinalUtxos as a5,
67840
+ resolveReclaimInputs as a6,
67841
+ mintWithReclaimsCheckFees as a7,
67842
+ mintAllCheckFees as a8,
67843
+ saveExtraUtxos as a9,
67844
+ Script as aa,
67845
+ sendInscriptionToOpReturnWithExtraInputsAndExtraOutputFeeRate as ab,
67846
+ clearExtraUtxos as ac,
67847
+ utxoOutputTypeFromOutputScript as ad,
67848
+ mintWithExtraInputInCommitFeeRate as ae,
67849
+ mintWithReclaimsAll as af,
67850
+ mintAll as ag,
67851
+ sendInscriptionToOpReturnWithExtraInputsAndExtraOutputAll as ah,
67852
+ mintWithExtraInputInCommitAll as ai,
67853
+ callSmartContract as aj,
67854
+ callSmartContractFromPaymentWallet as ak,
67855
+ evmEncodeFunctionCall as al,
67856
+ depositToBrc20Prog as am,
67857
+ withdrawFromBrc20Prog as an,
67858
+ inscribeMultiple as ao,
67859
+ inscribeWithParent as ap,
67860
+ getInscribeMultipleFee as aq,
67861
+ fetchWithErrors as ar,
67862
+ ethCallOnPublicRpc as as,
67769
67863
  getCardinalBalance as b,
67770
67864
  clearWalletInfo as c,
67771
- getNetwork as d,
67772
- getOrdinalsWallet as e,
67773
- getPaymentWallet as f,
67865
+ getEndpoints as d,
67866
+ getNetwork as e,
67867
+ getOrdinalsWallet as f,
67774
67868
  getWallets as g,
67775
- getWalletInfo as h,
67776
- setNetwork as i,
67777
- signMessage as j,
67778
- signMessageLocalVerify as k,
67779
- signMessageLocalVerifyDeterministic as l,
67780
- subscribeToAccountChanges as m,
67781
- index$2 as n,
67782
- module$1 as o,
67783
- getEvmAddressFromBitcoinAddress as p,
67784
- getEvmAddressFromPkScript as q,
67785
- delegateInscription as r,
67869
+ getPaymentWallet as h,
67870
+ getWalletInfo as i,
67871
+ setEndpoints as j,
67872
+ setNetwork as k,
67873
+ signMessage as l,
67874
+ signMessageLocalVerify as m,
67875
+ signMessageLocalVerifyDeterministic as n,
67876
+ subscribeToAccountChanges as o,
67877
+ index$2 as p,
67878
+ module$1 as q,
67879
+ getEvmAddressFromBitcoinAddress as r,
67786
67880
  sendBTC as s,
67787
- jsonInscription as t,
67788
- textInscription as u,
67789
- addressWalletInfo as v,
67790
- opReturnWalletInfo as w,
67791
- requireBitcoinjsMessage as x,
67792
- sha256$6 as y,
67793
- writeUInt32 as z
67881
+ getEvmAddressFromPkScript as t,
67882
+ delegateInscription as u,
67883
+ jsonInscription as v,
67884
+ textInscription as w,
67885
+ addressWalletInfo as x,
67886
+ opReturnWalletInfo as y,
67887
+ requireBitcoinjsMessage as z
67794
67888
  };