@otoplo/wallet-common 0.2.1 → 0.2.2

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/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { AddressType as O, Networks as E, Address as I, CommonUtils as $, BufferUtils as m, HDPrivateKey as J, TransactionBuilder as j, Transaction as x, UnitUtils as z, Script as b, Opcode as A, Hash as _, ScriptOpcode as L, BNExtended as F, Output as we, TxSigner as q, SighashType as X, ScriptFactory as Ae, OutputSighashType as Y, BufferWriter as ve } from "libnexa-ts";
1
+ import { AddressType as O, Networks as E, Address as I, CommonUtils as W, BufferUtils as m, HDPrivateKey as j, TransactionBuilder as z, Transaction as x, UnitUtils as q, Script as b, Opcode as A, Hash as _, ScriptOpcode as L, BNExtended as F, Output as we, TxSigner as X, SighashType as Y, ScriptFactory as Ae, OutputSighashType as Z, BufferWriter as ve } from "libnexa-ts";
2
2
  import B from "js-big-decimal";
3
3
  import { ElectrumClient as be, TransportScheme as H, ConnectionStatus as Se } from "@otoplo/electrum-client";
4
4
  import { mnemonicToSeedSync as ke, generateMnemonic as Te, validateMnemonic as Ie } from "@scure/bip39";
5
5
  import { DAppProvider as xe } from "wallet-comms-sdk";
6
6
  import { wordlist as se } from "@scure/bip39/wordlists/english.js";
7
- import { createSlice as S, createAsyncThunk as Ne, createSelector as W } from "@reduxjs/toolkit";
7
+ import { createSlice as S, createAsyncThunk as Ne, createSelector as G } from "@reduxjs/toolkit";
8
8
  import { useSelector as Me } from "react-redux";
9
- const w = -1, Z = 9223372036854775807n, Ee = 274710, yt = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
9
+ const w = -1, Q = 9223372036854775807n, Ee = 274710, yt = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
10
10
  function C() {
11
11
  return E.defaultNetwork == E.testnet;
12
12
  }
@@ -19,7 +19,7 @@ function R(a, e = O.PayToScriptTemplate) {
19
19
  function At() {
20
20
  return `https://${C() ? "testnet-" : ""}explorer.nexa.org`;
21
21
  }
22
- function G() {
22
+ function J() {
23
23
  return Math.floor(Date.now() / 1e3);
24
24
  }
25
25
  function vt(a, e) {
@@ -39,18 +39,18 @@ function St(a) {
39
39
  return a.length === 0 ? "" : a.charAt(0).toUpperCase() + a.substring(1);
40
40
  }
41
41
  function ae(a) {
42
- return $.isHexa(a) ? m.hexToBuffer(a) : I.fromString(a).data;
42
+ return W.isHexa(a) ? m.hexToBuffer(a) : I.fromString(a).data;
43
43
  }
44
44
  function v(a) {
45
- return $.isHexa(a) ? a : m.bufferToHex(ae(a));
45
+ return W.isHexa(a) ? a : m.bufferToHex(ae(a));
46
46
  }
47
47
  function kt(a) {
48
- return $.isHexa(a) ? new I(ae(a), E.defaultNetwork, O.GroupIdAddress).toString() : a;
48
+ return W.isHexa(a) ? new I(ae(a), E.defaultNetwork, O.GroupIdAddress).toString() : a;
49
49
  }
50
50
  function U(a) {
51
51
  return a == null || a === "" ? "" : BigInt(a) <= 0n ? "0" : a.toString();
52
52
  }
53
- function Q(a) {
53
+ function ee(a) {
54
54
  let e = BigInt(0), t = BigInt(0);
55
55
  return a.forEach((s) => {
56
56
  e += BigInt(s.confirmed), t += BigInt(s.unconfirmed);
@@ -236,7 +236,7 @@ class Et {
236
236
  accountId: e,
237
237
  tokenIdHex: t.tokenIdHex,
238
238
  type: "token",
239
- addedTime: G()
239
+ addedTime: J()
240
240
  };
241
241
  await this.store.upsertToken(t), await this.saveAsset(s), this.notify({ type: "token_refresh" });
242
242
  }
@@ -556,12 +556,12 @@ class Pt {
556
556
  accountKeys = /* @__PURE__ */ new Map();
557
557
  walletKeys = /* @__PURE__ */ new Map();
558
558
  init(e) {
559
- this.seed = typeof e == "string" ? ke(e) : e, this.masterKey = J.fromSeed(this.seed).deriveChild(44, !0).deriveChild(29223, !0);
559
+ this.seed = typeof e == "string" ? ke(e) : e, this.masterKey = j.fromSeed(this.seed).deriveChild(44, !0).deriveChild(29223, !0);
560
560
  }
561
561
  reset() {
562
562
  if (!this.seed)
563
563
  throw new Error("KeysManager not initialized");
564
- this.masterKey = J.fromSeed(this.seed).deriveChild(44, !0).deriveChild(29223, !0), this.accountKeys.clear(), this.walletKeys.clear();
564
+ this.masterKey = j.fromSeed(this.seed).deriveChild(44, !0).deriveChild(29223, !0), this.accountKeys.clear(), this.walletKeys.clear();
565
565
  }
566
566
  getAccountKey(e) {
567
567
  let t = this.accountKeys.get(e);
@@ -687,7 +687,7 @@ class Ut {
687
687
  await this.deleteNft(e, o.tokenIdHex);
688
688
  for (const [o, r] of Object.entries(t)) {
689
689
  const c = v(o), d = r && BigInt(r.confirmed) + BigInt(r.unconfirmed) > 0n, u = n?.some((l) => l.tokenIdHex == c);
690
- !d && !u || d && u || (!d && u ? await this.deleteNft(e, c) : await this.handleNftReceive(e, c, G()));
690
+ !d && !u || d && u || (!d && u ? await this.deleteNft(e, c) : await this.handleNftReceive(e, c, J()));
691
691
  }
692
692
  }
693
693
  async deleteToken(e, t) {
@@ -771,7 +771,7 @@ class Dt {
771
771
  // Will be set in classifyAndSaveTransaction
772
772
  txId: s.txid,
773
773
  txIdem: s.txidem,
774
- time: d ? s.time : G(),
774
+ time: d ? s.time : J(),
775
775
  height: d ? s.height : 0,
776
776
  type: c,
777
777
  fee: s.fee_satoshi.toString(),
@@ -794,7 +794,7 @@ class Dt {
794
794
  const n = {
795
795
  isConsolidate: !0,
796
796
  templateData: s
797
- }, i = new j(), o = await this.populateNexaInputsAndChange(i, e, t, n);
797
+ }, i = new z(), o = await this.populateNexaInputsAndChange(i, e, t, n);
798
798
  return this.finalizeTransaction(i, Array.from(o.values()));
799
799
  }
800
800
  prepareTransaction(e, t, s, n) {
@@ -802,9 +802,9 @@ class Dt {
802
802
  throw new Error("Invalid Address.");
803
803
  if (s && BigInt(t) < 1n || !s && parseInt(t) < x.DUST_AMOUNT)
804
804
  throw new Error("The amount is too low.");
805
- if (s && BigInt(t) > Z || !s && parseInt(t) > x.MAX_MONEY)
805
+ if (s && BigInt(t) > Q || !s && parseInt(t) > x.MAX_MONEY)
806
806
  throw new Error("The amount is too high.");
807
- const i = new j();
807
+ const i = new z();
808
808
  if (n && i.addData(n), s) {
809
809
  if (!R(s, O.GroupIdAddress))
810
810
  throw new Error("Invalid Token ID");
@@ -865,8 +865,8 @@ class Dt {
865
865
  }
866
866
  const c = {
867
867
  errorMsg: "Not enough Nexa balance.",
868
- amount: z.formatNEXA(e.transaction.outputs[0].value),
869
- fee: z.formatNEXA(e.transaction.estimateRequiredFee())
868
+ amount: q.formatNEXA(e.transaction.outputs[0].value),
869
+ fee: q.formatNEXA(e.transaction.estimateRequiredFee())
870
870
  };
871
871
  throw new Error(JSON.stringify(c));
872
872
  }
@@ -890,7 +890,7 @@ class Dt {
890
890
  const f = this.keyManager.getKey(u.keyPath);
891
891
  c.set(u.address, f.privateKey);
892
892
  }
893
- if (d > Z)
893
+ if (d > Q)
894
894
  throw new Error("Token inputs exceeded max amount. Consider sending in small chunks");
895
895
  if (e.transaction.inputs.length > this.MAX_INPUTS_OUTPUTS)
896
896
  throw new Error("Too many inputs. Consider consolidating transactions or reduce the send amount.");
@@ -992,16 +992,16 @@ const ce = [
992
992
  { code: "jpy", symbol: "¥", name: "Japanese Yen" }
993
993
  ], De = Object.fromEntries(
994
994
  ce.map((a) => [a.code, a.symbol])
995
- ), Kt = ce.map((a) => a.code), ee = {
995
+ ), Kt = ce.map((a) => a.code), te = {
996
996
  nexacoin: "nexa"
997
997
  };
998
998
  async function Ve(a) {
999
- const e = Object.keys(ee).join(","), t = await fetch(`https://api.coingecko.com/api/v3/coins/markets?ids=${e}&vs_currency=${a}`);
999
+ const e = Object.keys(te).join(","), t = await fetch(`https://api.coingecko.com/api/v3/coins/markets?ids=${e}&vs_currency=${a}`);
1000
1000
  if (!t.ok)
1001
1001
  throw new Error("Failed to fetch market data");
1002
1002
  const s = await t.json(), n = {};
1003
1003
  return s.forEach((i) => {
1004
- n[ee[i.id]] = {
1004
+ n[te[i.id]] = {
1005
1005
  id: i.id,
1006
1006
  name: i.name ?? "",
1007
1007
  symbol: i.symbol ?? "",
@@ -1257,12 +1257,12 @@ class Wt {
1257
1257
  const s = e.txDetails.tx.inputs[t], n = this.validateAndGetSubscript(s);
1258
1258
  if (s.scriptSig.isEmpty()) {
1259
1259
  e.allMyOutputsCovered = !0;
1260
- const i = q.sign(e.txDetails.tx, t, X.ALL, n, e.privateKey).toTxFormat(), o = b.empty().add(e.privateKey.publicKey.toBuffer());
1260
+ const i = X.sign(e.txDetails.tx, t, Y.ALL, n, e.privateKey).toTxFormat(), o = b.empty().add(e.privateKey.publicKey.toBuffer());
1261
1261
  s.scriptSig = Ae.buildScriptTemplateIn(void 0, o, b.empty().add(i));
1262
1262
  } else {
1263
- const i = s.scriptSig.findPlaceholder(), r = s.scriptSig.chunks[i].buf.subarray(64), c = X.fromBuffer(r);
1263
+ const i = s.scriptSig.findPlaceholder(), r = s.scriptSig.chunks[i].buf.subarray(64), c = Y.fromBuffer(r);
1264
1264
  this.processSignatureCoverage(e, c);
1265
- const d = q.sign(e.txDetails.tx, t, c, n, e.privateKey).toTxFormat(r);
1265
+ const d = X.sign(e.txDetails.tx, t, c, n, e.privateKey).toTxFormat(r);
1266
1266
  s.scriptSig.replaceChunk(i, b.empty().add(d));
1267
1267
  }
1268
1268
  }
@@ -1287,9 +1287,9 @@ class Wt {
1287
1287
  }
1288
1288
  processSignatureCoverage(e, t) {
1289
1289
  if (!e.allMyOutputsCovered)
1290
- if (t.outType == Y.TWO)
1290
+ if (t.outType == Z.TWO)
1291
1291
  e.coveredOutputs.add(t.outData[0]), e.coveredOutputs.add(t.outData[1]), this.checkSignatureCoverage(e);
1292
- else if (t.outType == Y.FIRSTN) {
1292
+ else if (t.outType == Z.FIRSTN) {
1293
1293
  const s = t.outData[0];
1294
1294
  for (let n = 0; n < s; n++)
1295
1295
  e.coveredOutputs.add(n);
@@ -1471,7 +1471,7 @@ class T {
1471
1471
  id: w,
1472
1472
  name: "Main Wallet",
1473
1473
  address: this.getReceiveAddress(),
1474
- balance: Q(e.map((t) => t.balance)),
1474
+ balance: ee(e.map((t) => t.balance)),
1475
1475
  tokensBalance: K(e.map((t) => t.tokensBalance)),
1476
1476
  sessions: {}
1477
1477
  }
@@ -1612,7 +1612,7 @@ class T {
1612
1612
  for (const r of o)
1613
1613
  t.set(r.tx_hash, r);
1614
1614
  await this.checkGapLimit(y.RECEIVE), await this.checkGapLimit(y.CHANGE);
1615
- const s = this.getMainAddresses(), n = Q(s.map((o) => o.balance)), i = K(s.map((o) => o.tokensBalance));
1615
+ const s = this.getMainAddresses(), n = ee(s.map((o) => o.balance)), i = K(s.map((o) => o.tokensBalance));
1616
1616
  this.notify({ type: "account_balance_updated", accountId: w, balance: n, tokensBalance: i }), this.notify({ type: "main_address_updated", address: this.getReceiveAddress() }), await this.postProcessActivity(w, Array.from(t.values()), s.map((o) => o.address), i);
1617
1617
  }
1618
1618
  async postProcessAccountsUpdate(e) {
@@ -1786,7 +1786,7 @@ const ze = {
1786
1786
  }), jt = le.actions, Qe = le.reducer, et = {
1787
1787
  currency: "usd",
1788
1788
  data: {}
1789
- }, te = Ne("market/updateMarketData", async (a, e) => {
1789
+ }, $ = Ne("market/updateMarketData", async (a, e) => {
1790
1790
  const t = e.getState();
1791
1791
  return await Ve(t.market.currency);
1792
1792
  }), he = S({
@@ -1801,15 +1801,13 @@ const ze = {
1801
1801
  }
1802
1802
  },
1803
1803
  extraReducers: (a) => {
1804
- a.addCase(te.fulfilled, (e, t) => {
1804
+ a.addCase($.fulfilled, (e, t) => {
1805
1805
  e.data = t.payload;
1806
- }).addCase(te.rejected, (e, t) => {
1806
+ }).addCase($.rejected, (e, t) => {
1807
1807
  console.error(t.error.message);
1808
1808
  });
1809
1809
  }
1810
- });
1811
- he.actions;
1812
- const tt = he.reducer, st = {
1810
+ }), zt = { updateMarketData: $ }, qt = he.actions, tt = he.reducer, st = {
1813
1811
  wallet: {},
1814
1812
  web3: {}
1815
1813
  }, pe = S({
@@ -1826,7 +1824,7 @@ const tt = he.reducer, st = {
1826
1824
  e.payload === "wallet" ? a.wallet = {} : e.payload === "web3" ? a.web3 = {} : e.payload === "all" && (a.wallet = {}, a.web3 = {});
1827
1825
  }
1828
1826
  }
1829
- }), zt = pe.actions, at = pe.reducer, nt = {
1827
+ }), Xt = pe.actions, at = pe.reducer, nt = {
1830
1828
  status: "Offline",
1831
1829
  height: 0,
1832
1830
  hasNetwork: !0,
@@ -1848,7 +1846,7 @@ const tt = he.reducer, st = {
1848
1846
  a.isSuspended = e.payload;
1849
1847
  }
1850
1848
  }
1851
- }), qt = fe.actions, it = fe.reducer, rt = {
1849
+ }), Yt = fe.actions, it = fe.reducer, rt = {
1852
1850
  isAuthorized: !1,
1853
1851
  selectedAccount: w,
1854
1852
  accounts: {
@@ -1919,7 +1917,7 @@ const tt = he.reducer, st = {
1919
1917
  a.accounts[e.payload.accountId].sessions = {};
1920
1918
  }
1921
1919
  }
1922
- }), Xt = me.actions, ot = me.reducer, Yt = {
1920
+ }), Zt = me.actions, ot = me.reducer, Qt = {
1923
1921
  loader: Qe,
1924
1922
  dapp: Ye,
1925
1923
  status: it,
@@ -1927,16 +1925,16 @@ const tt = he.reducer, st = {
1927
1925
  auth: qe,
1928
1926
  notifications: at,
1929
1927
  market: tt
1930
- }, g = Me.withTypes(), Zt = () => g((a) => a.auth), Qt = (a) => g((e) => e.market.data[a]), es = () => g((a) => a.status.height), ts = (a) => g((e) => e.wallet.accounts[a]), ss = () => g((a) => a.wallet.selectedAccount), as = () => g((a) => Math.max(...Object.keys(a.wallet.accounts).map(Number))), ns = (a) => g((e) => e.wallet.accounts[a].address), is = (a) => g((e) => e.wallet.accounts[a].balance), rs = (a, e) => g((t) => t.wallet.accounts[a].tokensBalance[e]), os = (a, e) => g((t) => t.wallet.accounts[a].sessions[e]), cs = () => g((a) => a.wallet.vaults), ge = W(
1928
+ }, g = Me.withTypes(), es = () => g((a) => a.auth), ts = (a) => g((e) => e.market.data[a]), ss = () => g((a) => a.status.height), as = (a) => g((e) => e.wallet.accounts[a]), ns = () => g((a) => a.wallet.selectedAccount), is = () => g((a) => Math.max(...Object.keys(a.wallet.accounts).map(Number))), rs = (a) => g((e) => e.wallet.accounts[a].address), os = (a) => g((e) => e.wallet.accounts[a].balance), cs = (a, e) => g((t) => t.wallet.accounts[a].tokensBalance[e]), ds = (a, e) => g((t) => t.wallet.accounts[a].sessions[e]), us = () => g((a) => a.wallet.vaults), ge = G(
1931
1929
  [(a) => a.notifications.wallet],
1932
1930
  (a) => Object.values(a).sort((e, t) => t.createdAt - e.createdAt)
1933
- ), ye = W(
1931
+ ), ye = G(
1934
1932
  [(a) => a.notifications.web3],
1935
1933
  (a) => Object.values(a).sort((e, t) => t.createdAt - e.createdAt)
1936
- ), ct = W(
1934
+ ), ct = G(
1937
1935
  [ge, ye],
1938
1936
  (a, e) => [...a, ...e].sort((t, s) => s.createdAt - t.createdAt)
1939
- ), ds = () => g(ge), us = () => g(ye), ls = () => g(ct);
1937
+ ), ls = () => g(ge), hs = () => g(ye), ps = () => g(ct);
1940
1938
  export {
1941
1939
  h as AccountType,
1942
1940
  Ut as AssetService,
@@ -1945,9 +1943,9 @@ export {
1945
1943
  Pt as KeyManager,
1946
1944
  y as KeySpace,
1947
1945
  w as MAIN_WALLET_ID,
1948
- Z as MAX_INT64,
1946
+ Q as MAX_INT64,
1949
1947
  ie as RostrumService,
1950
- ee as SUPPORTED_TOKENS,
1948
+ te as SUPPORTED_TOKENS,
1951
1949
  $t as SessionManager,
1952
1950
  N as SessionRequestType,
1953
1951
  Dt as TransactionService,
@@ -1963,7 +1961,7 @@ export {
1963
1961
  St as capitalizeFirstLetter,
1964
1962
  Kt as currencyCodes,
1965
1963
  De as currencySymbols,
1966
- G as currentTimestamp,
1964
+ J as currentTimestamp,
1967
1965
  Jt as dappModalActions,
1968
1966
  Ye as dappModalReducer,
1969
1967
  Ht as encryptMnemonic,
@@ -1992,38 +1990,41 @@ export {
1992
1990
  k as keyPathToString,
1993
1991
  jt as loaderActions,
1994
1992
  Qe as loaderReducer,
1995
- zt as notificationsActions,
1993
+ qt as marketActions,
1994
+ tt as marketReducer,
1995
+ zt as marketThunks,
1996
+ Xt as notificationsActions,
1996
1997
  at as notificationsReducer,
1997
1998
  Ot as parseTokenDataUrl,
1998
1999
  Nt as prettifyAmount,
1999
- Yt as sharedReducers,
2000
+ Qt as sharedReducers,
2000
2001
  xt as sleep,
2001
- qt as statusActions,
2002
+ Yt as statusActions,
2002
2003
  it as statusReducer,
2003
2004
  Ce as stringToKeyPath,
2004
- Q as sumBalance,
2005
+ ee as sumBalance,
2005
2006
  K as sumTokensBalance,
2006
2007
  U as tokenAmountToAssetAmount,
2007
2008
  kt as tokenHexToAddr,
2008
2009
  v as tokenIdToHex,
2009
2010
  Bt as transformTokenIconUrl,
2010
2011
  bt as truncateStringMiddle,
2011
- ts as useAccount,
2012
- ls as useAllNotifications,
2013
- Zt as useAuth,
2014
- es as useBlockHeight,
2015
- os as useDAppSession,
2016
- as as useLastAccountId,
2017
- ns as useMainReceiveAddress,
2018
- Qt as useMarketData,
2019
- ss as useSelectedAccount,
2020
- rs as useTokenBalance,
2021
- cs as useVaults,
2022
- is as useWalletBalance,
2023
- ds as useWalletNotifications,
2024
- us as useWeb3Notifications,
2012
+ as as useAccount,
2013
+ ps as useAllNotifications,
2014
+ es as useAuth,
2015
+ ss as useBlockHeight,
2016
+ ds as useDAppSession,
2017
+ is as useLastAccountId,
2018
+ rs as useMainReceiveAddress,
2019
+ ts as useMarketData,
2020
+ ns as useSelectedAccount,
2021
+ cs as useTokenBalance,
2022
+ us as useVaults,
2023
+ os as useWalletBalance,
2024
+ ls as useWalletNotifications,
2025
+ hs as useWeb3Notifications,
2025
2026
  Rt as validateAndDecryptMnemonic,
2026
- Xt as walletActions,
2027
+ Zt as walletActions,
2027
2028
  ot as walletReducer
2028
2029
  };
2029
2030
  //# sourceMappingURL=index.js.map