@omnisat/lasereyes 0.0.13 → 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
@@ -582,11 +593,12 @@ var LaserEyesProvider = ({
582
593
  (0, import_react.useEffect)(() => {
583
594
  }, []);
584
595
  (0, import_react.useEffect)(() => {
596
+ var _a, _b;
585
597
  let foundOkx;
586
598
  if (network === TESTNET) {
587
- foundOkx = window.okxwallet.bitcoinTestnet;
599
+ foundOkx = (_a = window.okxwallet) == null ? void 0 : _a.bitcoinTestnet;
588
600
  } else if (network === MAINNET) {
589
- foundOkx = window.okxwallet.bitcoin;
601
+ foundOkx = (_b = window.okxwallet) == null ? void 0 : _b.bitcoin;
590
602
  }
591
603
  setHasOkx(!!foundOkx);
592
604
  }, []);
@@ -711,6 +723,9 @@ var LaserEyesProvider = ({
711
723
  setProvider(OYL);
712
724
  handleAccountsChanged(result);
713
725
  setConnected(true);
726
+ getBTCBalance(result[1]).then((totalBalance) => {
727
+ setBalance(totalBalance);
728
+ });
714
729
  } catch (error) {
715
730
  throw new Error(`Can't lasereyes to ${OYL} wallet`);
716
731
  }
@@ -1215,7 +1230,7 @@ var LaserEyesProvider = ({
1215
1230
  network,
1216
1231
  7
1217
1232
  );
1218
- const psbt = yield signPsbt(psbtBase64, true, true);
1233
+ const psbt = yield signPsbt(psbtHex, true, true);
1219
1234
  if (!psbt)
1220
1235
  throw new Error("Error sending BTC");
1221
1236
  return psbt.txId;
@@ -1290,6 +1305,27 @@ var LaserEyesProvider = ({
1290
1305
  throw new Error("Error signing message: " + response.error.message);
1291
1306
  }
1292
1307
  }
1308
+ } else if (provider === MAGIC_EDEN) {
1309
+ let signedMessage;
1310
+ yield (0, import_sats_connect.signMessage)({
1311
+ getProvider: () => __async(void 0, null, function* () {
1312
+ return window.magicEden.bitcoin;
1313
+ }),
1314
+ payload: {
1315
+ network: {
1316
+ type: import_sats_connect.BitcoinNetworkType.Mainnet
1317
+ },
1318
+ address: address2,
1319
+ message
1320
+ },
1321
+ onFinish: (response) => {
1322
+ signedMessage = response;
1323
+ },
1324
+ onCancel: () => {
1325
+ alert("Request canceled");
1326
+ }
1327
+ });
1328
+ return signedMessage;
1293
1329
  } else if (provider === OKX) {
1294
1330
  return yield library == null ? void 0 : library.signMessage(message);
1295
1331
  } else if (provider === LEATHER) {
@@ -1649,6 +1685,53 @@ var LaserEyesProvider = ({
1649
1685
  throw error;
1650
1686
  }
1651
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
+ });
1652
1735
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1653
1736
  LaserEyesContext.Provider,
1654
1737
  {
@@ -1684,12 +1767,154 @@ var LaserEyesProvider = ({
1684
1767
  sendBTC,
1685
1768
  signPsbt,
1686
1769
  pushPsbt,
1687
- signMessage
1770
+ signMessage,
1771
+ inscribe,
1772
+ isCreatingCommit,
1773
+ isInscribing
1688
1774
  },
1689
1775
  children
1690
1776
  }
1691
1777
  );
1692
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
+ };
1693
1918
  // Annotate the CommonJS export names for ESM import in node:
1694
1919
  0 && (module.exports = {
1695
1920
  LEATHER,
@@ -1727,6 +1952,7 @@ var LaserEyesProvider = ({
1727
1952
  XVERSE_TESTNET,
1728
1953
  createConfig,
1729
1954
  createSendBtcPsbt,
1955
+ delay,
1730
1956
  estimateTxSize,
1731
1957
  findOrdinalsAddress,
1732
1958
  findPaymentAddress,
@@ -1748,5 +1974,6 @@ var LaserEyesProvider = ({
1748
1974
  isBase64,
1749
1975
  isHex,
1750
1976
  satoshisToBTC,
1977
+ useInscriber,
1751
1978
  useLaserEyes
1752
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,21 +433,27 @@ 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 {
442
+ BitcoinNetworkType,
434
443
  getAddress,
435
444
  request,
436
445
  RpcErrorCode,
446
+ signMessage as signMessageSatsConnect,
437
447
  signTransaction
438
448
  } from "sats-connect";
439
449
  import { fromOutputScript } from "bitcoinjs-lib/src/address";
440
- import axios2 from "axios";
450
+ import axios2, { AxiosError } from "axios";
441
451
  import { jsx } from "react/jsx-runtime";
442
452
  var LaserEyesContext = createContext(initialWalletContext);
443
453
  var useLaserEyes = () => {
444
454
  return useContext(LaserEyesContext);
445
455
  };
456
+ var DeSCRIBE_API_URL = "http://localhost:3000/api";
446
457
  var LaserEyesProvider = ({
447
458
  children,
448
459
  config
@@ -504,11 +515,12 @@ var LaserEyesProvider = ({
504
515
  useEffect(() => {
505
516
  }, []);
506
517
  useEffect(() => {
518
+ var _a, _b;
507
519
  let foundOkx;
508
520
  if (network === TESTNET) {
509
- foundOkx = window.okxwallet.bitcoinTestnet;
521
+ foundOkx = (_a = window.okxwallet) == null ? void 0 : _a.bitcoinTestnet;
510
522
  } else if (network === MAINNET) {
511
- foundOkx = window.okxwallet.bitcoin;
523
+ foundOkx = (_b = window.okxwallet) == null ? void 0 : _b.bitcoin;
512
524
  }
513
525
  setHasOkx(!!foundOkx);
514
526
  }, []);
@@ -633,6 +645,9 @@ var LaserEyesProvider = ({
633
645
  setProvider(OYL);
634
646
  handleAccountsChanged(result);
635
647
  setConnected(true);
648
+ getBTCBalance(result[1]).then((totalBalance) => {
649
+ setBalance(totalBalance);
650
+ });
636
651
  } catch (error) {
637
652
  throw new Error(`Can't lasereyes to ${OYL} wallet`);
638
653
  }
@@ -1137,7 +1152,7 @@ var LaserEyesProvider = ({
1137
1152
  network,
1138
1153
  7
1139
1154
  );
1140
- const psbt = yield signPsbt(psbtBase64, true, true);
1155
+ const psbt = yield signPsbt(psbtHex, true, true);
1141
1156
  if (!psbt)
1142
1157
  throw new Error("Error sending BTC");
1143
1158
  return psbt.txId;
@@ -1212,6 +1227,27 @@ var LaserEyesProvider = ({
1212
1227
  throw new Error("Error signing message: " + response.error.message);
1213
1228
  }
1214
1229
  }
1230
+ } else if (provider === MAGIC_EDEN) {
1231
+ let signedMessage;
1232
+ yield signMessageSatsConnect({
1233
+ getProvider: () => __async(void 0, null, function* () {
1234
+ return window.magicEden.bitcoin;
1235
+ }),
1236
+ payload: {
1237
+ network: {
1238
+ type: BitcoinNetworkType.Mainnet
1239
+ },
1240
+ address: address2,
1241
+ message
1242
+ },
1243
+ onFinish: (response) => {
1244
+ signedMessage = response;
1245
+ },
1246
+ onCancel: () => {
1247
+ alert("Request canceled");
1248
+ }
1249
+ });
1250
+ return signedMessage;
1215
1251
  } else if (provider === OKX) {
1216
1252
  return yield library == null ? void 0 : library.signMessage(message);
1217
1253
  } else if (provider === LEATHER) {
@@ -1571,6 +1607,53 @@ var LaserEyesProvider = ({
1571
1607
  throw error;
1572
1608
  }
1573
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
+ });
1574
1657
  return /* @__PURE__ */ jsx(
1575
1658
  LaserEyesContext.Provider,
1576
1659
  {
@@ -1606,12 +1689,154 @@ var LaserEyesProvider = ({
1606
1689
  sendBTC,
1607
1690
  signPsbt,
1608
1691
  pushPsbt,
1609
- signMessage
1692
+ signMessage,
1693
+ inscribe,
1694
+ isCreatingCommit,
1695
+ isInscribing
1610
1696
  },
1611
1697
  children
1612
1698
  }
1613
1699
  );
1614
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
+ };
1615
1840
  export {
1616
1841
  LEATHER,
1617
1842
  LEATHER_MAINNET,
@@ -1648,6 +1873,7 @@ export {
1648
1873
  XVERSE_TESTNET,
1649
1874
  createConfig,
1650
1875
  createSendBtcPsbt,
1876
+ delay,
1651
1877
  estimateTxSize,
1652
1878
  findOrdinalsAddress,
1653
1879
  findPaymentAddress,
@@ -1669,5 +1895,6 @@ export {
1669
1895
  isBase64,
1670
1896
  isHex,
1671
1897
  satoshisToBTC,
1898
+ useInscriber,
1672
1899
  useLaserEyes
1673
1900
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnisat/lasereyes",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "sideEffects": false,
5
5
  "private": false,
6
6
  "license": "MIT",