@omnisat/lasereyes 0.0.14 → 0.0.15

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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
2
3
  import { ReactNode } from 'react';
3
4
  import * as bitcoin from 'bitcoinjs-lib';
4
5
 
@@ -109,6 +110,9 @@ type LaserEyesContextType = {
109
110
  txId?: string;
110
111
  } | undefined>;
111
112
  pushPsbt: (tx: string) => Promise<string | undefined>;
113
+ inscribe: (content: any) => Promise<string | undefined>;
114
+ isCreatingCommit: boolean;
115
+ isInscribing: boolean;
112
116
  };
113
117
  type Config = {
114
118
  network: typeof MAINNET | typeof TESTNET | typeof REGTEST;
@@ -131,6 +135,13 @@ declare const LaserEyesProvider: ({ children, config, }: {
131
135
  children: ReactNode;
132
136
  config?: Config | undefined;
133
137
  }) => react_jsx_runtime.JSX.Element;
138
+ interface DeScribeCreateResponse {
139
+ inscriberAddress: string;
140
+ psbtHex: string;
141
+ psbtBase64: string;
142
+ feeRate: number;
143
+ totalFees: number;
144
+ }
134
145
 
135
146
  declare const getBitcoinNetwork: (network: typeof MAINNET | typeof TESTNET | typeof REGTEST) => bitcoin.networks.Network;
136
147
  declare const findOrdinalsAddress: (addresses: any) => any;
@@ -147,5 +158,31 @@ declare function createSendBtcPsbt(address: string, paymentAddress: string, reci
147
158
  psbtHex: string;
148
159
  }>;
149
160
  declare function getRedeemScript(paymentPublicKey: string, network: typeof MAINNET | typeof TESTNET): Buffer | undefined;
161
+ declare function delay(ms: number): Promise<unknown>;
162
+
163
+ declare const useInscriber: ({ inscribeApiUrl, }: {
164
+ inscribeApiUrl: string;
165
+ }) => {
166
+ content: any;
167
+ setContent: react.Dispatch<any>;
168
+ setMimeType: react.Dispatch<react.SetStateAction<"text/plain;charset=utf-8">>;
169
+ previewUrl: string;
170
+ setPreviewUrl: react.Dispatch<react.SetStateAction<string>>;
171
+ getCommitPsbt: () => Promise<void>;
172
+ isFetchingCommitPsbt: boolean;
173
+ commitPsbtHex: string;
174
+ commitPsbtBase64: string;
175
+ handleSignCommit: () => Promise<string | undefined>;
176
+ commitTxId: string;
177
+ setCommitTxId: react.Dispatch<react.SetStateAction<string>>;
178
+ feeRate: number;
179
+ setFeeRate: react.Dispatch<react.SetStateAction<number>>;
180
+ totalFees: number;
181
+ inscriberAddress: string;
182
+ inscribe: () => Promise<string>;
183
+ isInscribing: boolean;
184
+ inscriptionTxId: string;
185
+ reset: () => void;
186
+ };
150
187
 
151
- export { LEATHER, LEATHER_MAINNET, LEATHER_TESTNET, LaserEyesProvider, MAGIC_EDEN, MAINNET, MEMPOOL_SPACE_TESTNET_URL, MEMPOOL_SPACE_URL, OKX, OKX_MAINNET, OKX_TESTNET, OYL, P2PKH, P2PSH, P2SH, P2TR, P2WPKH, P2WSH, PHANTOM, REGTEST, SIGNET, TESTNET, UNISAT, UNISAT_MAINNET, UNISAT_TESTNET, WALLETS, WIZZ, WIZZ_MAINNET, WIZZ_TESTNET, XVERSE, XVERSE_MAINNET, XVERSE_NETWORK, XVERSE_TESTNET, createConfig, createSendBtcPsbt, estimateTxSize, findOrdinalsAddress, findPaymentAddress, getAddressType, getAddressUtxos, getBTCBalance, getBitcoinNetwork, getLeatherNetwork, getMempoolSpaceUrl, getNetworkForLeather, getNetworkForOkx, getNetworkForUnisat, getNetworkForWizz, getNetworkForXverse, getRedeemScript, getUnisatNetwork, getWizzNetwork, getXverseNetwork, isBase64, isHex, satoshisToBTC, useLaserEyes };
188
+ export { DeScribeCreateResponse, LEATHER, LEATHER_MAINNET, LEATHER_TESTNET, LaserEyesProvider, MAGIC_EDEN, MAINNET, MEMPOOL_SPACE_TESTNET_URL, MEMPOOL_SPACE_URL, OKX, OKX_MAINNET, OKX_TESTNET, OYL, P2PKH, P2PSH, P2SH, P2TR, P2WPKH, P2WSH, PHANTOM, REGTEST, SIGNET, TESTNET, UNISAT, UNISAT_MAINNET, UNISAT_TESTNET, WALLETS, WIZZ, WIZZ_MAINNET, WIZZ_TESTNET, XVERSE, XVERSE_MAINNET, XVERSE_NETWORK, XVERSE_TESTNET, createConfig, createSendBtcPsbt, delay, estimateTxSize, findOrdinalsAddress, findPaymentAddress, getAddressType, getAddressUtxos, getBTCBalance, getBitcoinNetwork, getLeatherNetwork, getMempoolSpaceUrl, getNetworkForLeather, getNetworkForOkx, getNetworkForUnisat, getNetworkForWizz, getNetworkForXverse, getRedeemScript, getUnisatNetwork, getWizzNetwork, getXverseNetwork, isBase64, isHex, satoshisToBTC, useInscriber, useLaserEyes };
package/dist/index.js CHANGED
@@ -108,6 +108,7 @@ __export(src_exports, {
108
108
  XVERSE_TESTNET: () => XVERSE_TESTNET,
109
109
  createConfig: () => createConfig,
110
110
  createSendBtcPsbt: () => createSendBtcPsbt,
111
+ delay: () => delay,
111
112
  estimateTxSize: () => estimateTxSize,
112
113
  findOrdinalsAddress: () => findOrdinalsAddress,
113
114
  findPaymentAddress: () => findPaymentAddress,
@@ -129,6 +130,7 @@ __export(src_exports, {
129
130
  isBase64: () => isBase64,
130
131
  isHex: () => isHex,
131
132
  satoshisToBTC: () => satoshisToBTC,
133
+ useInscriber: () => useInscriber,
132
134
  useLaserEyes: () => useLaserEyes
133
135
  });
134
136
  module.exports = __toCommonJS(src_exports);
@@ -329,7 +331,12 @@ var initialWalletContext = {
329
331
  }),
330
332
  pushPsbt: (tx) => __async(void 0, null, function* () {
331
333
  return "";
332
- })
334
+ }),
335
+ inscribe: (content) => __async(void 0, null, function* () {
336
+ return "";
337
+ }),
338
+ isCreatingCommit: false,
339
+ isInscribing: false
333
340
  };
334
341
 
335
342
  // src/providers/LaserEyesProvider.tsx
@@ -511,6 +518,9 @@ function getRedeemScript(paymentPublicKey, network) {
511
518
  });
512
519
  return (_a = p2sh == null ? void 0 : p2sh.redeem) == null ? void 0 : _a.output;
513
520
  }
521
+ function delay(ms) {
522
+ return new Promise((resolve) => setTimeout(resolve, ms));
523
+ }
514
524
 
515
525
  // src/providers/LaserEyesProvider.tsx
516
526
  var import_sats_connect = require("sats-connect");
@@ -521,6 +531,7 @@ var LaserEyesContext = (0, import_react.createContext)(initialWalletContext);
521
531
  var useLaserEyes = () => {
522
532
  return (0, import_react.useContext)(LaserEyesContext);
523
533
  };
534
+ var DeSCRIBE_API_URL = "http://localhost:3000/api";
524
535
  var LaserEyesProvider = ({
525
536
  children,
526
537
  config
@@ -1674,6 +1685,53 @@ var LaserEyesProvider = ({
1674
1685
  throw error;
1675
1686
  }
1676
1687
  });
1688
+ const [isCreatingCommit, setIsCreatingCommit] = (0, import_react.useState)(false);
1689
+ const [isInscribing, setIsInscribing] = (0, import_react.useState)(false);
1690
+ const inscribe = (content) => __async(void 0, null, function* () {
1691
+ var _a;
1692
+ try {
1693
+ console.log("inscribing!");
1694
+ if (!library)
1695
+ throw new Error("Library not found");
1696
+ if (!paymentAddress)
1697
+ throw new Error("Payment address not found");
1698
+ if (!paymentPublicKey)
1699
+ throw new Error("Payment public key not found");
1700
+ setIsCreatingCommit(true);
1701
+ const commitResponse = yield import_axios2.default.post(`${DeSCRIBE_API_URL}/create-inscription`, {
1702
+ content,
1703
+ paymentAddress,
1704
+ paymentPublicKey,
1705
+ feeRate: 10,
1706
+ mimeType: "text/plain;charset=utf-8"
1707
+ }).then((res) => res.data).finally(() => setIsCreatingCommit(false));
1708
+ const signedResponse = yield signPsbt(commitResponse.psbtHex, true, true);
1709
+ if (!signedResponse)
1710
+ throw new Error("Error signing PSBT");
1711
+ if (!signedResponse.txId)
1712
+ throw new Error("Error pushing PSBT");
1713
+ const { txId: commitTxId } = signedResponse;
1714
+ setIsInscribing(true);
1715
+ let txId;
1716
+ try {
1717
+ txId = yield import_axios2.default.post(`${DeSCRIBE_API_URL}/inscribe`, {
1718
+ content,
1719
+ mimeType: "text/plain;charset=utf-8",
1720
+ ordinalAddress: address2,
1721
+ commitTxId
1722
+ }).then((res) => res.data).finally(() => setIsInscribing(false));
1723
+ } catch (e) {
1724
+ throw e;
1725
+ }
1726
+ if (!txId)
1727
+ throw new Error("Error inscribing");
1728
+ return txId;
1729
+ } catch (error) {
1730
+ if (error instanceof import_axios2.AxiosError && ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data)) {
1731
+ throw new Error(error.response.data);
1732
+ }
1733
+ }
1734
+ });
1677
1735
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1678
1736
  LaserEyesContext.Provider,
1679
1737
  {
@@ -1709,12 +1767,154 @@ var LaserEyesProvider = ({
1709
1767
  sendBTC,
1710
1768
  signPsbt,
1711
1769
  pushPsbt,
1712
- signMessage
1770
+ signMessage,
1771
+ inscribe,
1772
+ isCreatingCommit,
1773
+ isInscribing
1713
1774
  },
1714
1775
  children
1715
1776
  }
1716
1777
  );
1717
1778
  };
1779
+
1780
+ // src/hooks/useInscriber.ts
1781
+ var import_react2 = require("react");
1782
+
1783
+ // src/consts/inscribe.ts
1784
+ var MIME_TYPE_TEXT = "text/plain;charset=utf-8";
1785
+
1786
+ // src/hooks/useInscriber.ts
1787
+ var import_axios3 = __toESM(require("axios"));
1788
+ var DESCRIBE_API_URL = "http://localhost:3000/api";
1789
+ var useInscriber = ({
1790
+ inscribeApiUrl = DESCRIBE_API_URL
1791
+ }) => {
1792
+ const { address: address2, paymentAddress, paymentPublicKey, publicKey, signPsbt } = useLaserEyes();
1793
+ const [content, setContent] = (0, import_react2.useState)("");
1794
+ const [mimeType, setMimeType] = (0, import_react2.useState)(MIME_TYPE_TEXT);
1795
+ const [commitPsbtHex, setCommitPsbtHex] = (0, import_react2.useState)("");
1796
+ const [commitPsbtBase64, setCommitPsbtBase64] = (0, import_react2.useState)("");
1797
+ const [commitTxId, setCommitTxId] = (0, import_react2.useState)("");
1798
+ const [feeRate, setFeeRate] = (0, import_react2.useState)(10);
1799
+ const [totalFees, setTotalFees] = (0, import_react2.useState)(0);
1800
+ const [inscriberAddress, setInscriberAddress] = (0, import_react2.useState)("");
1801
+ const [inscriptionTxId, setInscriptionTxId] = (0, import_react2.useState)("");
1802
+ const [previewUrl, setPreviewUrl] = (0, import_react2.useState)("");
1803
+ const [isFetchingCommitPsbt, setIsFetchingCommitPsbt] = (0, import_react2.useState)(false);
1804
+ const [isInscribing, setIsInscribing] = (0, import_react2.useState)(false);
1805
+ const getCommitPsbt = (0, import_react2.useCallback)(() => __async(void 0, null, function* () {
1806
+ try {
1807
+ if (!content)
1808
+ throw new Error("missing content");
1809
+ if (!paymentAddress)
1810
+ throw new Error("missing paymentAddress");
1811
+ if (!paymentPublicKey)
1812
+ throw new Error("missing paymentPublicKey");
1813
+ if (!feeRate)
1814
+ throw new Error("missing feeRate");
1815
+ if (!mimeType)
1816
+ throw new Error("missing mimeType");
1817
+ setIsFetchingCommitPsbt(true);
1818
+ return yield import_axios3.default.post(`${inscribeApiUrl}/create-inscription`, {
1819
+ content,
1820
+ paymentAddress,
1821
+ paymentPublicKey,
1822
+ feeRate,
1823
+ mimeType
1824
+ }).then((res) => res.data).then((data) => {
1825
+ setCommitPsbtHex(data.psbtHex);
1826
+ setCommitPsbtBase64(data.psbtBase64);
1827
+ setFeeRate(feeRate);
1828
+ setTotalFees(data.totalFees);
1829
+ setInscriberAddress(data.inscriberAddress);
1830
+ });
1831
+ } catch (e) {
1832
+ console.error(e);
1833
+ throw e;
1834
+ } finally {
1835
+ setIsFetchingCommitPsbt(false);
1836
+ }
1837
+ }), [paymentAddress, paymentPublicKey, content, feeRate, mimeType, publicKey]);
1838
+ const handleSignCommit = () => __async(void 0, null, function* () {
1839
+ try {
1840
+ const signedResponse = yield signPsbt(commitPsbtHex, true, true);
1841
+ setCommitTxId(signedResponse == null ? void 0 : signedResponse.txId);
1842
+ return signedResponse == null ? void 0 : signedResponse.txId;
1843
+ } catch (e) {
1844
+ console.error(e);
1845
+ throw e;
1846
+ }
1847
+ });
1848
+ const inscribe = (0, import_react2.useCallback)(() => __async(void 0, null, function* () {
1849
+ try {
1850
+ if (!content)
1851
+ throw new Error("missing content");
1852
+ if (!address2)
1853
+ throw new Error("missing address");
1854
+ if (!mimeType)
1855
+ throw new Error("missing mimeType");
1856
+ if (!commitTxId) {
1857
+ yield getCommitPsbt();
1858
+ yield handleSignCommit();
1859
+ }
1860
+ setIsInscribing(true);
1861
+ yield delay(1e4);
1862
+ return yield import_axios3.default.post(`${inscribeApiUrl}/inscribe`, {
1863
+ content,
1864
+ mimeType,
1865
+ ordinalAddress: address2,
1866
+ commitTxId
1867
+ }).then((res) => res.data).then((data) => {
1868
+ setInscriptionTxId(data);
1869
+ return data;
1870
+ });
1871
+ } catch (e) {
1872
+ console.error(e);
1873
+ throw e;
1874
+ } finally {
1875
+ setIsInscribing(false);
1876
+ }
1877
+ }), [address2, commitTxId, content, mimeType]);
1878
+ const reset = () => {
1879
+ setContent("");
1880
+ setMimeType(MIME_TYPE_TEXT);
1881
+ setCommitPsbtHex("");
1882
+ setCommitPsbtBase64("");
1883
+ setCommitTxId("");
1884
+ setFeeRate(10);
1885
+ setTotalFees(0);
1886
+ setInscriberAddress("");
1887
+ setInscriptionTxId("");
1888
+ setPreviewUrl("");
1889
+ };
1890
+ (0, import_react2.useEffect)(() => {
1891
+ if (commitTxId && !inscriptionTxId) {
1892
+ inscribe();
1893
+ }
1894
+ }, [commitTxId, inscribe, inscriptionTxId]);
1895
+ return {
1896
+ content,
1897
+ setContent,
1898
+ setMimeType,
1899
+ previewUrl,
1900
+ setPreviewUrl,
1901
+ getCommitPsbt,
1902
+ isFetchingCommitPsbt,
1903
+ commitPsbtHex,
1904
+ commitPsbtBase64,
1905
+ handleSignCommit,
1906
+ commitTxId,
1907
+ setCommitTxId,
1908
+ feeRate,
1909
+ setFeeRate,
1910
+ totalFees,
1911
+ inscriberAddress,
1912
+ inscribe,
1913
+ isInscribing,
1914
+ inscriptionTxId,
1915
+ reset
1916
+ };
1917
+ };
1718
1918
  // Annotate the CommonJS export names for ESM import in node:
1719
1919
  0 && (module.exports = {
1720
1920
  LEATHER,
@@ -1752,6 +1952,7 @@ var LaserEyesProvider = ({
1752
1952
  XVERSE_TESTNET,
1753
1953
  createConfig,
1754
1954
  createSendBtcPsbt,
1955
+ delay,
1755
1956
  estimateTxSize,
1756
1957
  findOrdinalsAddress,
1757
1958
  findPaymentAddress,
@@ -1773,5 +1974,6 @@ var LaserEyesProvider = ({
1773
1974
  isBase64,
1774
1975
  isHex,
1775
1976
  satoshisToBTC,
1977
+ useInscriber,
1776
1978
  useLaserEyes
1777
1979
  });
package/dist/index.mjs CHANGED
@@ -246,7 +246,12 @@ var initialWalletContext = {
246
246
  }),
247
247
  pushPsbt: (tx) => __async(void 0, null, function* () {
248
248
  return "";
249
- })
249
+ }),
250
+ inscribe: (content) => __async(void 0, null, function* () {
251
+ return "";
252
+ }),
253
+ isCreatingCommit: false,
254
+ isInscribing: false
250
255
  };
251
256
 
252
257
  // src/providers/LaserEyesProvider.tsx
@@ -428,6 +433,9 @@ function getRedeemScript(paymentPublicKey, network) {
428
433
  });
429
434
  return (_a = p2sh == null ? void 0 : p2sh.redeem) == null ? void 0 : _a.output;
430
435
  }
436
+ function delay(ms) {
437
+ return new Promise((resolve) => setTimeout(resolve, ms));
438
+ }
431
439
 
432
440
  // src/providers/LaserEyesProvider.tsx
433
441
  import {
@@ -435,16 +443,17 @@ import {
435
443
  getAddress,
436
444
  request,
437
445
  RpcErrorCode,
438
- signTransaction,
439
- signMessage as signMessageSatsConnect
446
+ signMessage as signMessageSatsConnect,
447
+ signTransaction
440
448
  } from "sats-connect";
441
449
  import { fromOutputScript } from "bitcoinjs-lib/src/address";
442
- import axios2 from "axios";
450
+ import axios2, { AxiosError } from "axios";
443
451
  import { jsx } from "react/jsx-runtime";
444
452
  var LaserEyesContext = createContext(initialWalletContext);
445
453
  var useLaserEyes = () => {
446
454
  return useContext(LaserEyesContext);
447
455
  };
456
+ var DeSCRIBE_API_URL = "http://localhost:3000/api";
448
457
  var LaserEyesProvider = ({
449
458
  children,
450
459
  config
@@ -1598,6 +1607,53 @@ var LaserEyesProvider = ({
1598
1607
  throw error;
1599
1608
  }
1600
1609
  });
1610
+ const [isCreatingCommit, setIsCreatingCommit] = useState(false);
1611
+ const [isInscribing, setIsInscribing] = useState(false);
1612
+ const inscribe = (content) => __async(void 0, null, function* () {
1613
+ var _a;
1614
+ try {
1615
+ console.log("inscribing!");
1616
+ if (!library)
1617
+ throw new Error("Library not found");
1618
+ if (!paymentAddress)
1619
+ throw new Error("Payment address not found");
1620
+ if (!paymentPublicKey)
1621
+ throw new Error("Payment public key not found");
1622
+ setIsCreatingCommit(true);
1623
+ const commitResponse = yield axios2.post(`${DeSCRIBE_API_URL}/create-inscription`, {
1624
+ content,
1625
+ paymentAddress,
1626
+ paymentPublicKey,
1627
+ feeRate: 10,
1628
+ mimeType: "text/plain;charset=utf-8"
1629
+ }).then((res) => res.data).finally(() => setIsCreatingCommit(false));
1630
+ const signedResponse = yield signPsbt(commitResponse.psbtHex, true, true);
1631
+ if (!signedResponse)
1632
+ throw new Error("Error signing PSBT");
1633
+ if (!signedResponse.txId)
1634
+ throw new Error("Error pushing PSBT");
1635
+ const { txId: commitTxId } = signedResponse;
1636
+ setIsInscribing(true);
1637
+ let txId;
1638
+ try {
1639
+ txId = yield axios2.post(`${DeSCRIBE_API_URL}/inscribe`, {
1640
+ content,
1641
+ mimeType: "text/plain;charset=utf-8",
1642
+ ordinalAddress: address2,
1643
+ commitTxId
1644
+ }).then((res) => res.data).finally(() => setIsInscribing(false));
1645
+ } catch (e) {
1646
+ throw e;
1647
+ }
1648
+ if (!txId)
1649
+ throw new Error("Error inscribing");
1650
+ return txId;
1651
+ } catch (error) {
1652
+ if (error instanceof AxiosError && ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data)) {
1653
+ throw new Error(error.response.data);
1654
+ }
1655
+ }
1656
+ });
1601
1657
  return /* @__PURE__ */ jsx(
1602
1658
  LaserEyesContext.Provider,
1603
1659
  {
@@ -1633,12 +1689,154 @@ var LaserEyesProvider = ({
1633
1689
  sendBTC,
1634
1690
  signPsbt,
1635
1691
  pushPsbt,
1636
- signMessage
1692
+ signMessage,
1693
+ inscribe,
1694
+ isCreatingCommit,
1695
+ isInscribing
1637
1696
  },
1638
1697
  children
1639
1698
  }
1640
1699
  );
1641
1700
  };
1701
+
1702
+ // src/hooks/useInscriber.ts
1703
+ import { useCallback, useEffect as useEffect2, useState as useState2 } from "react";
1704
+
1705
+ // src/consts/inscribe.ts
1706
+ var MIME_TYPE_TEXT = "text/plain;charset=utf-8";
1707
+
1708
+ // src/hooks/useInscriber.ts
1709
+ import axios3 from "axios";
1710
+ var DESCRIBE_API_URL = "http://localhost:3000/api";
1711
+ var useInscriber = ({
1712
+ inscribeApiUrl = DESCRIBE_API_URL
1713
+ }) => {
1714
+ const { address: address2, paymentAddress, paymentPublicKey, publicKey, signPsbt } = useLaserEyes();
1715
+ const [content, setContent] = useState2("");
1716
+ const [mimeType, setMimeType] = useState2(MIME_TYPE_TEXT);
1717
+ const [commitPsbtHex, setCommitPsbtHex] = useState2("");
1718
+ const [commitPsbtBase64, setCommitPsbtBase64] = useState2("");
1719
+ const [commitTxId, setCommitTxId] = useState2("");
1720
+ const [feeRate, setFeeRate] = useState2(10);
1721
+ const [totalFees, setTotalFees] = useState2(0);
1722
+ const [inscriberAddress, setInscriberAddress] = useState2("");
1723
+ const [inscriptionTxId, setInscriptionTxId] = useState2("");
1724
+ const [previewUrl, setPreviewUrl] = useState2("");
1725
+ const [isFetchingCommitPsbt, setIsFetchingCommitPsbt] = useState2(false);
1726
+ const [isInscribing, setIsInscribing] = useState2(false);
1727
+ const getCommitPsbt = useCallback(() => __async(void 0, null, function* () {
1728
+ try {
1729
+ if (!content)
1730
+ throw new Error("missing content");
1731
+ if (!paymentAddress)
1732
+ throw new Error("missing paymentAddress");
1733
+ if (!paymentPublicKey)
1734
+ throw new Error("missing paymentPublicKey");
1735
+ if (!feeRate)
1736
+ throw new Error("missing feeRate");
1737
+ if (!mimeType)
1738
+ throw new Error("missing mimeType");
1739
+ setIsFetchingCommitPsbt(true);
1740
+ return yield axios3.post(`${inscribeApiUrl}/create-inscription`, {
1741
+ content,
1742
+ paymentAddress,
1743
+ paymentPublicKey,
1744
+ feeRate,
1745
+ mimeType
1746
+ }).then((res) => res.data).then((data) => {
1747
+ setCommitPsbtHex(data.psbtHex);
1748
+ setCommitPsbtBase64(data.psbtBase64);
1749
+ setFeeRate(feeRate);
1750
+ setTotalFees(data.totalFees);
1751
+ setInscriberAddress(data.inscriberAddress);
1752
+ });
1753
+ } catch (e) {
1754
+ console.error(e);
1755
+ throw e;
1756
+ } finally {
1757
+ setIsFetchingCommitPsbt(false);
1758
+ }
1759
+ }), [paymentAddress, paymentPublicKey, content, feeRate, mimeType, publicKey]);
1760
+ const handleSignCommit = () => __async(void 0, null, function* () {
1761
+ try {
1762
+ const signedResponse = yield signPsbt(commitPsbtHex, true, true);
1763
+ setCommitTxId(signedResponse == null ? void 0 : signedResponse.txId);
1764
+ return signedResponse == null ? void 0 : signedResponse.txId;
1765
+ } catch (e) {
1766
+ console.error(e);
1767
+ throw e;
1768
+ }
1769
+ });
1770
+ const inscribe = useCallback(() => __async(void 0, null, function* () {
1771
+ try {
1772
+ if (!content)
1773
+ throw new Error("missing content");
1774
+ if (!address2)
1775
+ throw new Error("missing address");
1776
+ if (!mimeType)
1777
+ throw new Error("missing mimeType");
1778
+ if (!commitTxId) {
1779
+ yield getCommitPsbt();
1780
+ yield handleSignCommit();
1781
+ }
1782
+ setIsInscribing(true);
1783
+ yield delay(1e4);
1784
+ return yield axios3.post(`${inscribeApiUrl}/inscribe`, {
1785
+ content,
1786
+ mimeType,
1787
+ ordinalAddress: address2,
1788
+ commitTxId
1789
+ }).then((res) => res.data).then((data) => {
1790
+ setInscriptionTxId(data);
1791
+ return data;
1792
+ });
1793
+ } catch (e) {
1794
+ console.error(e);
1795
+ throw e;
1796
+ } finally {
1797
+ setIsInscribing(false);
1798
+ }
1799
+ }), [address2, commitTxId, content, mimeType]);
1800
+ const reset = () => {
1801
+ setContent("");
1802
+ setMimeType(MIME_TYPE_TEXT);
1803
+ setCommitPsbtHex("");
1804
+ setCommitPsbtBase64("");
1805
+ setCommitTxId("");
1806
+ setFeeRate(10);
1807
+ setTotalFees(0);
1808
+ setInscriberAddress("");
1809
+ setInscriptionTxId("");
1810
+ setPreviewUrl("");
1811
+ };
1812
+ useEffect2(() => {
1813
+ if (commitTxId && !inscriptionTxId) {
1814
+ inscribe();
1815
+ }
1816
+ }, [commitTxId, inscribe, inscriptionTxId]);
1817
+ return {
1818
+ content,
1819
+ setContent,
1820
+ setMimeType,
1821
+ previewUrl,
1822
+ setPreviewUrl,
1823
+ getCommitPsbt,
1824
+ isFetchingCommitPsbt,
1825
+ commitPsbtHex,
1826
+ commitPsbtBase64,
1827
+ handleSignCommit,
1828
+ commitTxId,
1829
+ setCommitTxId,
1830
+ feeRate,
1831
+ setFeeRate,
1832
+ totalFees,
1833
+ inscriberAddress,
1834
+ inscribe,
1835
+ isInscribing,
1836
+ inscriptionTxId,
1837
+ reset
1838
+ };
1839
+ };
1642
1840
  export {
1643
1841
  LEATHER,
1644
1842
  LEATHER_MAINNET,
@@ -1675,6 +1873,7 @@ export {
1675
1873
  XVERSE_TESTNET,
1676
1874
  createConfig,
1677
1875
  createSendBtcPsbt,
1876
+ delay,
1678
1877
  estimateTxSize,
1679
1878
  findOrdinalsAddress,
1680
1879
  findPaymentAddress,
@@ -1696,5 +1895,6 @@ export {
1696
1895
  isBase64,
1697
1896
  isHex,
1698
1897
  satoshisToBTC,
1898
+ useInscriber,
1699
1899
  useLaserEyes
1700
1900
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnisat/lasereyes",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "sideEffects": false,
5
5
  "private": false,
6
6
  "license": "MIT",