@omnisat/lasereyes 0.0.43 → 0.0.45
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 +1 -38
- package/dist/index.js +78 -197
- package/dist/index.mjs +78 -196
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -139,13 +139,6 @@ interface MempoolUtxo {
|
|
|
139
139
|
};
|
|
140
140
|
value: number;
|
|
141
141
|
}
|
|
142
|
-
interface CommitPsbtResponse {
|
|
143
|
-
inscriberAddress: string;
|
|
144
|
-
psbtHex: string;
|
|
145
|
-
psbtBase64: string;
|
|
146
|
-
feeRate: number;
|
|
147
|
-
totalFees: number;
|
|
148
|
-
}
|
|
149
142
|
|
|
150
143
|
declare const createConfig: (config: Config) => Config;
|
|
151
144
|
|
|
@@ -171,36 +164,6 @@ declare function createSendBtcPsbt(address: string, paymentAddress: string, reci
|
|
|
171
164
|
declare function getRedeemScript(paymentPublicKey: string, network: typeof MAINNET | typeof TESTNET | typeof TESTNET4 | typeof SIGNET | typeof FRACTAL_MAINNET | typeof FRACTAL_TESTNET): Buffer | undefined;
|
|
172
165
|
declare function delay(ms: number): Promise<unknown>;
|
|
173
166
|
|
|
174
|
-
declare const useInscriber: ({ inscribeApiUrl, }: {
|
|
175
|
-
inscribeApiUrl: string;
|
|
176
|
-
}) => {
|
|
177
|
-
content: any;
|
|
178
|
-
setContent: React.Dispatch<any>;
|
|
179
|
-
setMimeType: React.Dispatch<React.SetStateAction<"text/plain;charset=utf-8">>;
|
|
180
|
-
previewUrl: string;
|
|
181
|
-
setPreviewUrl: React.Dispatch<React.SetStateAction<string>>;
|
|
182
|
-
getCommitPsbt: () => Promise<CommitPsbtResponse>;
|
|
183
|
-
isFetchingCommitPsbt: boolean;
|
|
184
|
-
commitPsbtHex: string;
|
|
185
|
-
commitPsbtBase64: string;
|
|
186
|
-
handleSignCommit: (tx?: string) => Promise<string | undefined>;
|
|
187
|
-
commitTxId: string;
|
|
188
|
-
setCommitTxId: React.Dispatch<React.SetStateAction<string>>;
|
|
189
|
-
feeRate: number;
|
|
190
|
-
setFeeRate: React.Dispatch<React.SetStateAction<number>>;
|
|
191
|
-
totalFees: number;
|
|
192
|
-
inscriberAddress: string;
|
|
193
|
-
inscribe: ({ content: providedContent, mimeType: providedMimeType, ordinalAddress: providedAddress, commitTxId: providedCommitTxId, }: {
|
|
194
|
-
content?: any;
|
|
195
|
-
mimeType?: string | undefined;
|
|
196
|
-
ordinalAddress?: string | undefined;
|
|
197
|
-
commitTxId?: string | undefined;
|
|
198
|
-
}) => Promise<string>;
|
|
199
|
-
isInscribing: boolean;
|
|
200
|
-
inscriptionTxId: string;
|
|
201
|
-
reset: () => void;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
167
|
interface OylLogoProps extends React.SVGProps<SVGSVGElement> {
|
|
205
168
|
size?: number;
|
|
206
169
|
variant?: "first" | "second";
|
|
@@ -256,4 +219,4 @@ declare const WalletIcon: ({ size, className, variant, walletName, }: {
|
|
|
256
219
|
walletName: typeof XVERSE | typeof WIZZ | typeof LEATHER | typeof MAGIC_EDEN | typeof OKX | typeof PHANTOM | typeof UNISAT | typeof OYL;
|
|
257
220
|
}) => react_jsx_runtime.JSX.Element;
|
|
258
221
|
|
|
259
|
-
export { FRACTAL_MAINNET, FRACTAL_TESTNET, LEATHER, LEATHER_MAINNET, LEATHER_TESTNET, LaserEyesProvider, LeatherLogo, MAGIC_EDEN, MAINNET, MEMPOOL_SPACE_SIGNET_URL, MEMPOOL_SPACE_TESTNET_URL, MEMPOOL_SPACE_URL, MagicEdenLogo, OKX, OKX_MAINNET, OKX_TESTNET, OP_WALLET_MAINNET, OP_WALLET_TESTNET, OYL, OkxLogo, OylLogo, P2PKH, P2PSH, P2SH, P2TR, P2WPKH, P2WSH, PHANTOM, PhantomLogo, REGTEST, SIGNET, TESTNET, TESTNET4, UNISAT, UNISAT_FRACTAL_MAINNET, UNISAT_FRACTAL_TESTNET, UNISAT_MAINNET, UNISAT_SIGNET, UNISAT_TESTNET, UNISAT_TESTNET4, UnisatLogo, WALLETS, WIZZ, WIZZ_MAINNET, WIZZ_SIGNET, WIZZ_TESTNET, WIZZ_TESTNET4, WalletIcon, WizzLogo, XVERSE, XVERSE_MAINNET, XVERSE_NETWORK, XVERSE_SIGNET, XVERSE_TESTNET, XverseLogo, createConfig, createSendBtcPsbt, delay, estimateTxSize, findOrdinalsAddress, findPaymentAddress, getAddressUtxos, getBTCBalance, getBitcoinNetwork, getLeatherNetwork, getMempoolSpaceUrl, getNetworkForLeather, getNetworkForOkx, getNetworkForUnisat, getNetworkForWizz, getNetworkForXverse, getRedeemScript, getUnisatNetwork, getWizzNetwork, getXverseNetwork, isBase64, isHex, satoshisToBTC,
|
|
222
|
+
export { FRACTAL_MAINNET, FRACTAL_TESTNET, LEATHER, LEATHER_MAINNET, LEATHER_TESTNET, LaserEyesProvider, LeatherLogo, MAGIC_EDEN, MAINNET, MEMPOOL_SPACE_SIGNET_URL, MEMPOOL_SPACE_TESTNET_URL, MEMPOOL_SPACE_URL, MagicEdenLogo, OKX, OKX_MAINNET, OKX_TESTNET, OP_WALLET_MAINNET, OP_WALLET_TESTNET, OYL, OkxLogo, OylLogo, P2PKH, P2PSH, P2SH, P2TR, P2WPKH, P2WSH, PHANTOM, PhantomLogo, REGTEST, SIGNET, TESTNET, TESTNET4, UNISAT, UNISAT_FRACTAL_MAINNET, UNISAT_FRACTAL_TESTNET, UNISAT_MAINNET, UNISAT_SIGNET, UNISAT_TESTNET, UNISAT_TESTNET4, UnisatLogo, WALLETS, WIZZ, WIZZ_MAINNET, WIZZ_SIGNET, WIZZ_TESTNET, WIZZ_TESTNET4, WalletIcon, WizzLogo, XVERSE, XVERSE_MAINNET, XVERSE_NETWORK, XVERSE_SIGNET, XVERSE_TESTNET, XverseLogo, createConfig, createSendBtcPsbt, delay, estimateTxSize, findOrdinalsAddress, findPaymentAddress, getAddressUtxos, getBTCBalance, getBitcoinNetwork, getLeatherNetwork, getMempoolSpaceUrl, getNetworkForLeather, getNetworkForOkx, getNetworkForUnisat, getNetworkForWizz, getNetworkForXverse, getRedeemScript, getUnisatNetwork, getWizzNetwork, getXverseNetwork, isBase64, isHex, satoshisToBTC, useLaserEyes };
|
package/dist/index.js
CHANGED
|
@@ -166,7 +166,6 @@ __export(src_exports, {
|
|
|
166
166
|
isBase64: () => isBase64,
|
|
167
167
|
isHex: () => isHex,
|
|
168
168
|
satoshisToBTC: () => satoshisToBTC,
|
|
169
|
-
useInscriber: () => useInscriber,
|
|
170
169
|
useLaserEyes: () => useLaserEyes
|
|
171
170
|
});
|
|
172
171
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -461,7 +460,12 @@ var findPaymentAddress = (addresses) => {
|
|
|
461
460
|
};
|
|
462
461
|
var getBTCBalance = (address2, network) => __async(void 0, null, function* () {
|
|
463
462
|
try {
|
|
464
|
-
const utxos = yield getAddressUtxos(
|
|
463
|
+
const utxos = yield getAddressUtxos(
|
|
464
|
+
address2,
|
|
465
|
+
network
|
|
466
|
+
);
|
|
467
|
+
if (!utxos)
|
|
468
|
+
return 0;
|
|
465
469
|
return utxos.reduce((acc, utxo) => acc + utxo.value, 0);
|
|
466
470
|
} catch (error) {
|
|
467
471
|
console.error("Error fetching BTC balance:", error);
|
|
@@ -493,13 +497,30 @@ function estimateTxSize(taprootInputCount, nonTaprootInputCount, outputCount) {
|
|
|
493
497
|
}
|
|
494
498
|
function getAddressUtxos(address2, network) {
|
|
495
499
|
return __async(this, null, function* () {
|
|
500
|
+
if (address2.startsWith("t")) {
|
|
501
|
+
if (network === MAINNET) {
|
|
502
|
+
return [];
|
|
503
|
+
}
|
|
504
|
+
if (network === FRACTAL_MAINNET) {
|
|
505
|
+
return [];
|
|
506
|
+
}
|
|
507
|
+
if (network === FRACTAL_TESTNET) {
|
|
508
|
+
return [];
|
|
509
|
+
}
|
|
510
|
+
}
|
|
496
511
|
return yield import_axios.default.get(`${getMempoolSpaceUrl2(network)}/api/address/${address2}/utxo`).then((response) => response.data);
|
|
497
512
|
});
|
|
498
513
|
}
|
|
499
514
|
function createSendBtcPsbt(address2, paymentAddress, recipientAddress, amount, paymentPublicKey, network, feeRate = 7) {
|
|
500
515
|
return __async(this, null, function* () {
|
|
501
516
|
const isTaprootOnly = address2 === paymentAddress;
|
|
502
|
-
const utxos = yield getAddressUtxos(
|
|
517
|
+
const utxos = yield getAddressUtxos(
|
|
518
|
+
paymentAddress,
|
|
519
|
+
network
|
|
520
|
+
);
|
|
521
|
+
if (!utxos) {
|
|
522
|
+
throw new Error("No UTXOs found");
|
|
523
|
+
}
|
|
503
524
|
const sortedUtxos = utxos.sort(
|
|
504
525
|
(a, b) => b.value - a.value
|
|
505
526
|
);
|
|
@@ -591,7 +612,6 @@ var LaserEyesProvider = ({
|
|
|
591
612
|
children,
|
|
592
613
|
config
|
|
593
614
|
}) => {
|
|
594
|
-
var _a;
|
|
595
615
|
const selfRef = (0, import_react.useRef)({
|
|
596
616
|
accounts: []
|
|
597
617
|
});
|
|
@@ -615,11 +635,9 @@ var LaserEyesProvider = ({
|
|
|
615
635
|
const [hasLeather, setHasLeather] = (0, import_react.useState)(false);
|
|
616
636
|
const [hasPhantom, setHasPhantom] = (0, import_react.useState)(false);
|
|
617
637
|
const [hasWizz, setHasWizz] = (0, import_react.useState)(false);
|
|
618
|
-
const [network, setNetwork] = (0, import_usehooks_ts.useLocalStorage)("network", (
|
|
619
|
-
initializeWithValue: false
|
|
620
|
-
});
|
|
638
|
+
const [network, setNetwork] = (0, import_usehooks_ts.useLocalStorage)("network", (config == null ? void 0 : config.network) || MAINNET);
|
|
621
639
|
(0, import_react.useEffect)(() => {
|
|
622
|
-
if (config) {
|
|
640
|
+
if (config && config.network) {
|
|
623
641
|
setNetwork(config.network);
|
|
624
642
|
getNetwork().then((foundNetwork) => {
|
|
625
643
|
try {
|
|
@@ -652,8 +670,8 @@ var LaserEyesProvider = ({
|
|
|
652
670
|
}, []);
|
|
653
671
|
(0, import_react.useEffect)(() => {
|
|
654
672
|
const observer = new MutationObserver(() => {
|
|
655
|
-
var
|
|
656
|
-
const xverseLib = (
|
|
673
|
+
var _a;
|
|
674
|
+
const xverseLib = (_a = window == null ? void 0 : window.XverseProviders) == null ? void 0 : _a.BitcoinProvider;
|
|
657
675
|
if (xverseLib) {
|
|
658
676
|
setHasXverse(true);
|
|
659
677
|
observer.disconnect();
|
|
@@ -692,10 +710,10 @@ var LaserEyesProvider = ({
|
|
|
692
710
|
}, []);
|
|
693
711
|
(0, import_react.useEffect)(() => {
|
|
694
712
|
const observer = new MutationObserver(() => {
|
|
695
|
-
var
|
|
713
|
+
var _a, _b;
|
|
696
714
|
let foundOkx;
|
|
697
715
|
if (network === TESTNET || network === TESTNET4 || network === SIGNET || network === FRACTAL_TESTNET) {
|
|
698
|
-
foundOkx = (
|
|
716
|
+
foundOkx = (_a = window == null ? void 0 : window.okxwallet) == null ? void 0 : _a.bitcoinTestnet;
|
|
699
717
|
} else if (network === MAINNET || network === FRACTAL_MAINNET) {
|
|
700
718
|
foundOkx = (_b = window == null ? void 0 : window.okxwallet) == null ? void 0 : _b.bitcoin;
|
|
701
719
|
}
|
|
@@ -724,8 +742,8 @@ var LaserEyesProvider = ({
|
|
|
724
742
|
}, []);
|
|
725
743
|
(0, import_react.useEffect)(() => {
|
|
726
744
|
const observer = new MutationObserver(() => {
|
|
727
|
-
var
|
|
728
|
-
const phantomLib = (
|
|
745
|
+
var _a;
|
|
746
|
+
const phantomLib = (_a = window == null ? void 0 : window.phantom) == null ? void 0 : _a.bitcoin;
|
|
729
747
|
if (phantomLib && phantomLib.isPhantom) {
|
|
730
748
|
setHasPhantom(true);
|
|
731
749
|
observer.disconnect();
|
|
@@ -933,15 +951,23 @@ var LaserEyesProvider = ({
|
|
|
933
951
|
throw error;
|
|
934
952
|
}
|
|
935
953
|
});
|
|
936
|
-
const connectOkx = () => __async(void 0, null, function* () {
|
|
954
|
+
const connectOkx = (0, import_react.useCallback)(() => __async(void 0, null, function* () {
|
|
955
|
+
var _a;
|
|
937
956
|
try {
|
|
938
957
|
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, OKX);
|
|
958
|
+
console.log("connecting", network);
|
|
939
959
|
const lib = network === TESTNET || network === TESTNET4 || network === FRACTAL_TESTNET ? window.okxwallet.bitcoinTestnet : network === SIGNET ? window.okxwallet.bitcoinSignet : window.okxwallet.bitcoin;
|
|
940
960
|
const okxAccounts = yield lib.connect();
|
|
941
961
|
if (!okxAccounts)
|
|
942
962
|
throw new Error("No accounts found");
|
|
943
963
|
setAccounts([okxAccounts]);
|
|
944
964
|
setAddress(okxAccounts.address);
|
|
965
|
+
if (((_a = String(okxAccounts.address)) == null ? void 0 : _a.startsWith("tb")) && network !== TESTNET && network !== TESTNET4 && network !== SIGNET) {
|
|
966
|
+
console.log("err");
|
|
967
|
+
throw new Error(
|
|
968
|
+
`Please switch networks to ${network} in the wallet settings.`
|
|
969
|
+
);
|
|
970
|
+
}
|
|
945
971
|
setPaymentAddress(okxAccounts.address);
|
|
946
972
|
setPublicKey(okxAccounts.publicKey);
|
|
947
973
|
setPaymentPublicKey(okxAccounts.publicKey);
|
|
@@ -954,9 +980,9 @@ var LaserEyesProvider = ({
|
|
|
954
980
|
console.log("error", error);
|
|
955
981
|
throw error;
|
|
956
982
|
}
|
|
957
|
-
});
|
|
983
|
+
}), [hasOkx, network]);
|
|
958
984
|
const connectLeather = (0, import_react.useCallback)(() => __async(void 0, null, function* () {
|
|
959
|
-
var
|
|
985
|
+
var _a;
|
|
960
986
|
try {
|
|
961
987
|
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, LEATHER);
|
|
962
988
|
const lib = window.LeatherProvider;
|
|
@@ -974,9 +1000,9 @@ var LaserEyesProvider = ({
|
|
|
974
1000
|
const segwitAddress = addresses.find(
|
|
975
1001
|
(address3) => address3.type === P2WPKH
|
|
976
1002
|
);
|
|
977
|
-
if (((
|
|
1003
|
+
if (((_a = String(taprootAddress == null ? void 0 : taprootAddress.address)) == null ? void 0 : _a.startsWith("tb")) && network !== TESTNET && network !== TESTNET4 && network !== SIGNET) {
|
|
978
1004
|
throw new Error(
|
|
979
|
-
|
|
1005
|
+
`Please switch networks to ${network} in the wallet settings.`
|
|
980
1006
|
);
|
|
981
1007
|
}
|
|
982
1008
|
setAccounts(leatherAccountsParsed);
|
|
@@ -1234,10 +1260,13 @@ var LaserEyesProvider = ({
|
|
|
1234
1260
|
}
|
|
1235
1261
|
});
|
|
1236
1262
|
const getNetwork = (0, import_react.useCallback)(() => __async(void 0, null, function* () {
|
|
1237
|
-
var
|
|
1263
|
+
var _a, _b;
|
|
1238
1264
|
try {
|
|
1239
1265
|
if (provider === UNISAT) {
|
|
1240
1266
|
const unisatNetwork = yield library == null ? void 0 : library.getChain();
|
|
1267
|
+
if (!unisatNetwork) {
|
|
1268
|
+
return (_a = config == null ? void 0 : config.network) != null ? _a : MAINNET;
|
|
1269
|
+
}
|
|
1241
1270
|
return getNetworkForUnisat(unisatNetwork.enum);
|
|
1242
1271
|
} else if (provider === XVERSE) {
|
|
1243
1272
|
if (address2.slice(0, 1) === "t") {
|
|
@@ -1300,7 +1329,7 @@ var LaserEyesProvider = ({
|
|
|
1300
1329
|
const wizzNetwork = yield library == null ? void 0 : library.getNetwork();
|
|
1301
1330
|
return getNetworkForWizz(wizzNetwork);
|
|
1302
1331
|
}
|
|
1303
|
-
return (
|
|
1332
|
+
return (_b = config == null ? void 0 : config.network) != null ? _b : MAINNET;
|
|
1304
1333
|
} catch (error) {
|
|
1305
1334
|
throw error;
|
|
1306
1335
|
}
|
|
@@ -1354,26 +1383,39 @@ var LaserEyesProvider = ({
|
|
|
1354
1383
|
if (!library)
|
|
1355
1384
|
return;
|
|
1356
1385
|
if (provider === UNISAT) {
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
return yield library.getBalance();
|
|
1386
|
+
const bal = yield library.getBalance();
|
|
1387
|
+
setBalance(bal.total);
|
|
1388
|
+
return bal.total;
|
|
1361
1389
|
} else if (provider === XVERSE) {
|
|
1362
|
-
|
|
1390
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1391
|
+
setBalance(bal);
|
|
1392
|
+
return bal;
|
|
1363
1393
|
} else if (provider === OYL) {
|
|
1364
1394
|
const balanceResponse = yield library.getBalance();
|
|
1365
|
-
|
|
1395
|
+
const bal = balanceResponse.btc.total * 1e8;
|
|
1396
|
+
setBalance(bal);
|
|
1397
|
+
return bal;
|
|
1366
1398
|
} else if (provider === MAGIC_EDEN) {
|
|
1367
|
-
|
|
1399
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1400
|
+
setBalance(bal);
|
|
1401
|
+
return bal;
|
|
1368
1402
|
} else if (provider === OKX) {
|
|
1369
|
-
|
|
1403
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1404
|
+
setBalance(bal);
|
|
1405
|
+
return bal;
|
|
1370
1406
|
} else if (provider === LEATHER) {
|
|
1371
|
-
|
|
1407
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1408
|
+
setBalance(bal);
|
|
1409
|
+
return bal;
|
|
1372
1410
|
} else if (provider === PHANTOM) {
|
|
1373
|
-
|
|
1411
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1412
|
+
setBalance(bal);
|
|
1413
|
+
return bal;
|
|
1374
1414
|
} else if (provider === WIZZ) {
|
|
1375
1415
|
const balanceResponse = yield library.getBalance();
|
|
1376
|
-
|
|
1416
|
+
const bal = balanceResponse.total * 1e8;
|
|
1417
|
+
setBalance(bal);
|
|
1418
|
+
return bal;
|
|
1377
1419
|
}
|
|
1378
1420
|
} catch (error) {
|
|
1379
1421
|
throw error;
|
|
@@ -1399,7 +1441,7 @@ var LaserEyesProvider = ({
|
|
|
1399
1441
|
}
|
|
1400
1442
|
});
|
|
1401
1443
|
const sendBTC = (to, amount) => __async(void 0, null, function* () {
|
|
1402
|
-
var
|
|
1444
|
+
var _a;
|
|
1403
1445
|
try {
|
|
1404
1446
|
if (amount <= 0)
|
|
1405
1447
|
throw new Error("Amount must be greater than 0");
|
|
@@ -1485,7 +1527,7 @@ var LaserEyesProvider = ({
|
|
|
1485
1527
|
}
|
|
1486
1528
|
]
|
|
1487
1529
|
});
|
|
1488
|
-
if ((
|
|
1530
|
+
if ((_a = response == null ? void 0 : response.result) == null ? void 0 : _a.txid) {
|
|
1489
1531
|
return response.result.txid;
|
|
1490
1532
|
} else {
|
|
1491
1533
|
if (response.error.code === import_sats_connect.RpcErrorCode.USER_REJECTION) {
|
|
@@ -1507,7 +1549,7 @@ var LaserEyesProvider = ({
|
|
|
1507
1549
|
}
|
|
1508
1550
|
});
|
|
1509
1551
|
const signMessage = (message, toSignAddress) => __async(void 0, null, function* () {
|
|
1510
|
-
var
|
|
1552
|
+
var _a;
|
|
1511
1553
|
try {
|
|
1512
1554
|
if (!library)
|
|
1513
1555
|
return;
|
|
@@ -1565,7 +1607,7 @@ var LaserEyesProvider = ({
|
|
|
1565
1607
|
message,
|
|
1566
1608
|
paymentType
|
|
1567
1609
|
});
|
|
1568
|
-
return (
|
|
1610
|
+
return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
|
|
1569
1611
|
} else if (provider === PHANTOM) {
|
|
1570
1612
|
const utf8Bytes = new TextEncoder().encode(message);
|
|
1571
1613
|
const uintArray = new Uint8Array(utf8Bytes);
|
|
@@ -1959,166 +2001,6 @@ var LaserEyesProvider = ({
|
|
|
1959
2001
|
);
|
|
1960
2002
|
};
|
|
1961
2003
|
|
|
1962
|
-
// src/hooks/useInscriber.ts
|
|
1963
|
-
var import_react2 = require("react");
|
|
1964
|
-
|
|
1965
|
-
// src/consts/inscribe.ts
|
|
1966
|
-
var MIME_TYPE_TEXT = "text/plain;charset=utf-8";
|
|
1967
|
-
|
|
1968
|
-
// src/hooks/useInscriber.ts
|
|
1969
|
-
var import_axios3 = __toESM(require("axios"));
|
|
1970
|
-
var DESCRIBE_API_URL = "http://localhost:3000/api";
|
|
1971
|
-
var useInscriber = ({
|
|
1972
|
-
inscribeApiUrl = DESCRIBE_API_URL
|
|
1973
|
-
}) => {
|
|
1974
|
-
const { address: address2, paymentAddress, paymentPublicKey, publicKey, signPsbt } = useLaserEyes();
|
|
1975
|
-
const [content, setContent] = (0, import_react2.useState)("");
|
|
1976
|
-
const [mimeType, setMimeType] = (0, import_react2.useState)(MIME_TYPE_TEXT);
|
|
1977
|
-
const [commitPsbtHex, setCommitPsbtHex] = (0, import_react2.useState)("");
|
|
1978
|
-
const [commitPsbtBase64, setCommitPsbtBase64] = (0, import_react2.useState)("");
|
|
1979
|
-
const [commitTxId, setCommitTxId] = (0, import_react2.useState)("");
|
|
1980
|
-
const [feeRate, setFeeRate] = (0, import_react2.useState)(10);
|
|
1981
|
-
const [totalFees, setTotalFees] = (0, import_react2.useState)(0);
|
|
1982
|
-
const [inscriberAddress, setInscriberAddress] = (0, import_react2.useState)("");
|
|
1983
|
-
const [inscriptionTxId, setInscriptionTxId] = (0, import_react2.useState)("");
|
|
1984
|
-
const [previewUrl, setPreviewUrl] = (0, import_react2.useState)("");
|
|
1985
|
-
const [isFetchingCommitPsbt, setIsFetchingCommitPsbt] = (0, import_react2.useState)(false);
|
|
1986
|
-
const [isInscribing, setIsInscribing] = (0, import_react2.useState)(false);
|
|
1987
|
-
(0, import_react2.useEffect)(() => {
|
|
1988
|
-
setCommitPsbtHex("");
|
|
1989
|
-
setCommitPsbtBase64("");
|
|
1990
|
-
setCommitTxId("");
|
|
1991
|
-
}, [content, address2, mimeType, feeRate]);
|
|
1992
|
-
const getCommitPsbt = (0, import_react2.useCallback)(() => __async(void 0, null, function* () {
|
|
1993
|
-
try {
|
|
1994
|
-
if (!content)
|
|
1995
|
-
throw new Error("missing content");
|
|
1996
|
-
if (!paymentAddress)
|
|
1997
|
-
throw new Error("missing paymentAddress");
|
|
1998
|
-
if (!paymentPublicKey)
|
|
1999
|
-
throw new Error("missing paymentPublicKey");
|
|
2000
|
-
if (!feeRate)
|
|
2001
|
-
throw new Error("missing feeRate");
|
|
2002
|
-
if (!mimeType)
|
|
2003
|
-
throw new Error("missing mimeType");
|
|
2004
|
-
setIsFetchingCommitPsbt(true);
|
|
2005
|
-
return yield import_axios3.default.post(`${inscribeApiUrl}/create-inscription`, {
|
|
2006
|
-
content,
|
|
2007
|
-
paymentAddress,
|
|
2008
|
-
paymentPublicKey,
|
|
2009
|
-
feeRate,
|
|
2010
|
-
mimeType
|
|
2011
|
-
}).then((res) => res.data).then((data) => {
|
|
2012
|
-
setCommitPsbtHex(data.psbtHex);
|
|
2013
|
-
setCommitPsbtBase64(data.psbtBase64);
|
|
2014
|
-
setFeeRate(feeRate);
|
|
2015
|
-
setTotalFees(data.totalFees);
|
|
2016
|
-
setInscriberAddress(data.inscriberAddress);
|
|
2017
|
-
return data;
|
|
2018
|
-
});
|
|
2019
|
-
} catch (e) {
|
|
2020
|
-
console.error(e);
|
|
2021
|
-
throw new Error(e.response.data);
|
|
2022
|
-
} finally {
|
|
2023
|
-
setIsFetchingCommitPsbt(false);
|
|
2024
|
-
}
|
|
2025
|
-
}), [paymentAddress, paymentPublicKey, content, feeRate, mimeType, publicKey]);
|
|
2026
|
-
const handleSignCommit = (tx) => __async(void 0, null, function* () {
|
|
2027
|
-
try {
|
|
2028
|
-
const toBeSigned = tx != null ? tx : commitPsbtHex;
|
|
2029
|
-
if (!toBeSigned)
|
|
2030
|
-
throw new Error("missing tx");
|
|
2031
|
-
const signedResponse = yield signPsbt(toBeSigned, true, true);
|
|
2032
|
-
setCommitTxId(signedResponse == null ? void 0 : signedResponse.txId);
|
|
2033
|
-
return signedResponse == null ? void 0 : signedResponse.txId;
|
|
2034
|
-
} catch (e) {
|
|
2035
|
-
console.error(e);
|
|
2036
|
-
throw e;
|
|
2037
|
-
}
|
|
2038
|
-
});
|
|
2039
|
-
const inscribe = (0, import_react2.useCallback)(
|
|
2040
|
-
(_0) => __async(void 0, [_0], function* ({
|
|
2041
|
-
content: providedContent,
|
|
2042
|
-
mimeType: providedMimeType,
|
|
2043
|
-
ordinalAddress: providedAddress,
|
|
2044
|
-
commitTxId: providedCommitTxId
|
|
2045
|
-
}) {
|
|
2046
|
-
try {
|
|
2047
|
-
const inscribeContent = providedContent != null ? providedContent : content;
|
|
2048
|
-
const inscribeMimeType = providedMimeType != null ? providedMimeType : mimeType;
|
|
2049
|
-
const inscribeOutputAddress = providedAddress != null ? providedAddress : address2;
|
|
2050
|
-
let inscribeCommitTxId = providedCommitTxId != null ? providedCommitTxId : commitTxId;
|
|
2051
|
-
if (!inscribeContent)
|
|
2052
|
-
throw new Error("missing content");
|
|
2053
|
-
if (!inscribeMimeType)
|
|
2054
|
-
throw new Error("missing mimeType");
|
|
2055
|
-
if (!inscribeOutputAddress)
|
|
2056
|
-
throw new Error("missing address");
|
|
2057
|
-
setIsInscribing(true);
|
|
2058
|
-
if (!inscribeCommitTxId) {
|
|
2059
|
-
const signed = yield getCommitPsbt();
|
|
2060
|
-
inscribeCommitTxId = yield handleSignCommit(signed.psbtBase64);
|
|
2061
|
-
if (!inscribeCommitTxId)
|
|
2062
|
-
throw new Error("failed to broadcast commit");
|
|
2063
|
-
console.log("tempCommitTxId", inscribeCommitTxId);
|
|
2064
|
-
}
|
|
2065
|
-
yield delay(1e4);
|
|
2066
|
-
if (!inscribeCommitTxId)
|
|
2067
|
-
throw new Error("missing commitTxId");
|
|
2068
|
-
return yield import_axios3.default.post(`${inscribeApiUrl}/inscribe`, {
|
|
2069
|
-
content,
|
|
2070
|
-
mimeType,
|
|
2071
|
-
ordinalAddress: address2,
|
|
2072
|
-
commitTxId: inscribeCommitTxId
|
|
2073
|
-
}).then((res) => res.data).then((data) => {
|
|
2074
|
-
setInscriptionTxId(data);
|
|
2075
|
-
return data;
|
|
2076
|
-
});
|
|
2077
|
-
} catch (e) {
|
|
2078
|
-
console.error(e);
|
|
2079
|
-
throw e;
|
|
2080
|
-
} finally {
|
|
2081
|
-
setIsInscribing(false);
|
|
2082
|
-
}
|
|
2083
|
-
}),
|
|
2084
|
-
[address2, commitTxId, content, mimeType]
|
|
2085
|
-
);
|
|
2086
|
-
const reset = () => {
|
|
2087
|
-
setContent("");
|
|
2088
|
-
setMimeType(MIME_TYPE_TEXT);
|
|
2089
|
-
setCommitPsbtHex("");
|
|
2090
|
-
setCommitPsbtBase64("");
|
|
2091
|
-
setCommitTxId("");
|
|
2092
|
-
setFeeRate(10);
|
|
2093
|
-
setTotalFees(0);
|
|
2094
|
-
setInscriberAddress("");
|
|
2095
|
-
setInscriptionTxId("");
|
|
2096
|
-
setPreviewUrl("");
|
|
2097
|
-
};
|
|
2098
|
-
return {
|
|
2099
|
-
content,
|
|
2100
|
-
setContent,
|
|
2101
|
-
setMimeType,
|
|
2102
|
-
previewUrl,
|
|
2103
|
-
setPreviewUrl,
|
|
2104
|
-
getCommitPsbt,
|
|
2105
|
-
isFetchingCommitPsbt,
|
|
2106
|
-
commitPsbtHex,
|
|
2107
|
-
commitPsbtBase64,
|
|
2108
|
-
handleSignCommit,
|
|
2109
|
-
commitTxId,
|
|
2110
|
-
setCommitTxId,
|
|
2111
|
-
feeRate,
|
|
2112
|
-
setFeeRate,
|
|
2113
|
-
totalFees,
|
|
2114
|
-
inscriberAddress,
|
|
2115
|
-
inscribe,
|
|
2116
|
-
isInscribing,
|
|
2117
|
-
inscriptionTxId,
|
|
2118
|
-
reset
|
|
2119
|
-
};
|
|
2120
|
-
};
|
|
2121
|
-
|
|
2122
2004
|
// src/icons/oyl.tsx
|
|
2123
2005
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
2124
2006
|
var OylLogo = (_a) => {
|
|
@@ -2799,6 +2681,5 @@ var WalletIcon = ({
|
|
|
2799
2681
|
isBase64,
|
|
2800
2682
|
isHex,
|
|
2801
2683
|
satoshisToBTC,
|
|
2802
|
-
useInscriber,
|
|
2803
2684
|
useLaserEyes
|
|
2804
2685
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -356,7 +356,12 @@ var findPaymentAddress = (addresses) => {
|
|
|
356
356
|
};
|
|
357
357
|
var getBTCBalance = (address2, network) => __async(void 0, null, function* () {
|
|
358
358
|
try {
|
|
359
|
-
const utxos = yield getAddressUtxos(
|
|
359
|
+
const utxos = yield getAddressUtxos(
|
|
360
|
+
address2,
|
|
361
|
+
network
|
|
362
|
+
);
|
|
363
|
+
if (!utxos)
|
|
364
|
+
return 0;
|
|
360
365
|
return utxos.reduce((acc, utxo) => acc + utxo.value, 0);
|
|
361
366
|
} catch (error) {
|
|
362
367
|
console.error("Error fetching BTC balance:", error);
|
|
@@ -388,13 +393,30 @@ function estimateTxSize(taprootInputCount, nonTaprootInputCount, outputCount) {
|
|
|
388
393
|
}
|
|
389
394
|
function getAddressUtxos(address2, network) {
|
|
390
395
|
return __async(this, null, function* () {
|
|
396
|
+
if (address2.startsWith("t")) {
|
|
397
|
+
if (network === MAINNET) {
|
|
398
|
+
return [];
|
|
399
|
+
}
|
|
400
|
+
if (network === FRACTAL_MAINNET) {
|
|
401
|
+
return [];
|
|
402
|
+
}
|
|
403
|
+
if (network === FRACTAL_TESTNET) {
|
|
404
|
+
return [];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
391
407
|
return yield axios.get(`${getMempoolSpaceUrl2(network)}/api/address/${address2}/utxo`).then((response) => response.data);
|
|
392
408
|
});
|
|
393
409
|
}
|
|
394
410
|
function createSendBtcPsbt(address2, paymentAddress, recipientAddress, amount, paymentPublicKey, network, feeRate = 7) {
|
|
395
411
|
return __async(this, null, function* () {
|
|
396
412
|
const isTaprootOnly = address2 === paymentAddress;
|
|
397
|
-
const utxos = yield getAddressUtxos(
|
|
413
|
+
const utxos = yield getAddressUtxos(
|
|
414
|
+
paymentAddress,
|
|
415
|
+
network
|
|
416
|
+
);
|
|
417
|
+
if (!utxos) {
|
|
418
|
+
throw new Error("No UTXOs found");
|
|
419
|
+
}
|
|
398
420
|
const sortedUtxos = utxos.sort(
|
|
399
421
|
(a, b) => b.value - a.value
|
|
400
422
|
);
|
|
@@ -495,7 +517,6 @@ var LaserEyesProvider = ({
|
|
|
495
517
|
children,
|
|
496
518
|
config
|
|
497
519
|
}) => {
|
|
498
|
-
var _a;
|
|
499
520
|
const selfRef = useRef({
|
|
500
521
|
accounts: []
|
|
501
522
|
});
|
|
@@ -519,11 +540,9 @@ var LaserEyesProvider = ({
|
|
|
519
540
|
const [hasLeather, setHasLeather] = useState(false);
|
|
520
541
|
const [hasPhantom, setHasPhantom] = useState(false);
|
|
521
542
|
const [hasWizz, setHasWizz] = useState(false);
|
|
522
|
-
const [network, setNetwork] = useLocalStorage("network", (
|
|
523
|
-
initializeWithValue: false
|
|
524
|
-
});
|
|
543
|
+
const [network, setNetwork] = useLocalStorage("network", (config == null ? void 0 : config.network) || MAINNET);
|
|
525
544
|
useEffect(() => {
|
|
526
|
-
if (config) {
|
|
545
|
+
if (config && config.network) {
|
|
527
546
|
setNetwork(config.network);
|
|
528
547
|
getNetwork().then((foundNetwork) => {
|
|
529
548
|
try {
|
|
@@ -556,8 +575,8 @@ var LaserEyesProvider = ({
|
|
|
556
575
|
}, []);
|
|
557
576
|
useEffect(() => {
|
|
558
577
|
const observer = new MutationObserver(() => {
|
|
559
|
-
var
|
|
560
|
-
const xverseLib = (
|
|
578
|
+
var _a;
|
|
579
|
+
const xverseLib = (_a = window == null ? void 0 : window.XverseProviders) == null ? void 0 : _a.BitcoinProvider;
|
|
561
580
|
if (xverseLib) {
|
|
562
581
|
setHasXverse(true);
|
|
563
582
|
observer.disconnect();
|
|
@@ -596,10 +615,10 @@ var LaserEyesProvider = ({
|
|
|
596
615
|
}, []);
|
|
597
616
|
useEffect(() => {
|
|
598
617
|
const observer = new MutationObserver(() => {
|
|
599
|
-
var
|
|
618
|
+
var _a, _b;
|
|
600
619
|
let foundOkx;
|
|
601
620
|
if (network === TESTNET || network === TESTNET4 || network === SIGNET || network === FRACTAL_TESTNET) {
|
|
602
|
-
foundOkx = (
|
|
621
|
+
foundOkx = (_a = window == null ? void 0 : window.okxwallet) == null ? void 0 : _a.bitcoinTestnet;
|
|
603
622
|
} else if (network === MAINNET || network === FRACTAL_MAINNET) {
|
|
604
623
|
foundOkx = (_b = window == null ? void 0 : window.okxwallet) == null ? void 0 : _b.bitcoin;
|
|
605
624
|
}
|
|
@@ -628,8 +647,8 @@ var LaserEyesProvider = ({
|
|
|
628
647
|
}, []);
|
|
629
648
|
useEffect(() => {
|
|
630
649
|
const observer = new MutationObserver(() => {
|
|
631
|
-
var
|
|
632
|
-
const phantomLib = (
|
|
650
|
+
var _a;
|
|
651
|
+
const phantomLib = (_a = window == null ? void 0 : window.phantom) == null ? void 0 : _a.bitcoin;
|
|
633
652
|
if (phantomLib && phantomLib.isPhantom) {
|
|
634
653
|
setHasPhantom(true);
|
|
635
654
|
observer.disconnect();
|
|
@@ -837,15 +856,23 @@ var LaserEyesProvider = ({
|
|
|
837
856
|
throw error;
|
|
838
857
|
}
|
|
839
858
|
});
|
|
840
|
-
const connectOkx = () => __async(void 0, null, function* () {
|
|
859
|
+
const connectOkx = useCallback(() => __async(void 0, null, function* () {
|
|
860
|
+
var _a;
|
|
841
861
|
try {
|
|
842
862
|
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, OKX);
|
|
863
|
+
console.log("connecting", network);
|
|
843
864
|
const lib = network === TESTNET || network === TESTNET4 || network === FRACTAL_TESTNET ? window.okxwallet.bitcoinTestnet : network === SIGNET ? window.okxwallet.bitcoinSignet : window.okxwallet.bitcoin;
|
|
844
865
|
const okxAccounts = yield lib.connect();
|
|
845
866
|
if (!okxAccounts)
|
|
846
867
|
throw new Error("No accounts found");
|
|
847
868
|
setAccounts([okxAccounts]);
|
|
848
869
|
setAddress(okxAccounts.address);
|
|
870
|
+
if (((_a = String(okxAccounts.address)) == null ? void 0 : _a.startsWith("tb")) && network !== TESTNET && network !== TESTNET4 && network !== SIGNET) {
|
|
871
|
+
console.log("err");
|
|
872
|
+
throw new Error(
|
|
873
|
+
`Please switch networks to ${network} in the wallet settings.`
|
|
874
|
+
);
|
|
875
|
+
}
|
|
849
876
|
setPaymentAddress(okxAccounts.address);
|
|
850
877
|
setPublicKey(okxAccounts.publicKey);
|
|
851
878
|
setPaymentPublicKey(okxAccounts.publicKey);
|
|
@@ -858,9 +885,9 @@ var LaserEyesProvider = ({
|
|
|
858
885
|
console.log("error", error);
|
|
859
886
|
throw error;
|
|
860
887
|
}
|
|
861
|
-
});
|
|
888
|
+
}), [hasOkx, network]);
|
|
862
889
|
const connectLeather = useCallback(() => __async(void 0, null, function* () {
|
|
863
|
-
var
|
|
890
|
+
var _a;
|
|
864
891
|
try {
|
|
865
892
|
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, LEATHER);
|
|
866
893
|
const lib = window.LeatherProvider;
|
|
@@ -878,9 +905,9 @@ var LaserEyesProvider = ({
|
|
|
878
905
|
const segwitAddress = addresses.find(
|
|
879
906
|
(address3) => address3.type === P2WPKH
|
|
880
907
|
);
|
|
881
|
-
if (((
|
|
908
|
+
if (((_a = String(taprootAddress == null ? void 0 : taprootAddress.address)) == null ? void 0 : _a.startsWith("tb")) && network !== TESTNET && network !== TESTNET4 && network !== SIGNET) {
|
|
882
909
|
throw new Error(
|
|
883
|
-
|
|
910
|
+
`Please switch networks to ${network} in the wallet settings.`
|
|
884
911
|
);
|
|
885
912
|
}
|
|
886
913
|
setAccounts(leatherAccountsParsed);
|
|
@@ -1138,10 +1165,13 @@ var LaserEyesProvider = ({
|
|
|
1138
1165
|
}
|
|
1139
1166
|
});
|
|
1140
1167
|
const getNetwork = useCallback(() => __async(void 0, null, function* () {
|
|
1141
|
-
var
|
|
1168
|
+
var _a, _b;
|
|
1142
1169
|
try {
|
|
1143
1170
|
if (provider === UNISAT) {
|
|
1144
1171
|
const unisatNetwork = yield library == null ? void 0 : library.getChain();
|
|
1172
|
+
if (!unisatNetwork) {
|
|
1173
|
+
return (_a = config == null ? void 0 : config.network) != null ? _a : MAINNET;
|
|
1174
|
+
}
|
|
1145
1175
|
return getNetworkForUnisat(unisatNetwork.enum);
|
|
1146
1176
|
} else if (provider === XVERSE) {
|
|
1147
1177
|
if (address2.slice(0, 1) === "t") {
|
|
@@ -1204,7 +1234,7 @@ var LaserEyesProvider = ({
|
|
|
1204
1234
|
const wizzNetwork = yield library == null ? void 0 : library.getNetwork();
|
|
1205
1235
|
return getNetworkForWizz(wizzNetwork);
|
|
1206
1236
|
}
|
|
1207
|
-
return (
|
|
1237
|
+
return (_b = config == null ? void 0 : config.network) != null ? _b : MAINNET;
|
|
1208
1238
|
} catch (error) {
|
|
1209
1239
|
throw error;
|
|
1210
1240
|
}
|
|
@@ -1258,26 +1288,39 @@ var LaserEyesProvider = ({
|
|
|
1258
1288
|
if (!library)
|
|
1259
1289
|
return;
|
|
1260
1290
|
if (provider === UNISAT) {
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
return yield library.getBalance();
|
|
1291
|
+
const bal = yield library.getBalance();
|
|
1292
|
+
setBalance(bal.total);
|
|
1293
|
+
return bal.total;
|
|
1265
1294
|
} else if (provider === XVERSE) {
|
|
1266
|
-
|
|
1295
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1296
|
+
setBalance(bal);
|
|
1297
|
+
return bal;
|
|
1267
1298
|
} else if (provider === OYL) {
|
|
1268
1299
|
const balanceResponse = yield library.getBalance();
|
|
1269
|
-
|
|
1300
|
+
const bal = balanceResponse.btc.total * 1e8;
|
|
1301
|
+
setBalance(bal);
|
|
1302
|
+
return bal;
|
|
1270
1303
|
} else if (provider === MAGIC_EDEN) {
|
|
1271
|
-
|
|
1304
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1305
|
+
setBalance(bal);
|
|
1306
|
+
return bal;
|
|
1272
1307
|
} else if (provider === OKX) {
|
|
1273
|
-
|
|
1308
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1309
|
+
setBalance(bal);
|
|
1310
|
+
return bal;
|
|
1274
1311
|
} else if (provider === LEATHER) {
|
|
1275
|
-
|
|
1312
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1313
|
+
setBalance(bal);
|
|
1314
|
+
return bal;
|
|
1276
1315
|
} else if (provider === PHANTOM) {
|
|
1277
|
-
|
|
1316
|
+
const bal = yield getBTCBalance(paymentAddress, network);
|
|
1317
|
+
setBalance(bal);
|
|
1318
|
+
return bal;
|
|
1278
1319
|
} else if (provider === WIZZ) {
|
|
1279
1320
|
const balanceResponse = yield library.getBalance();
|
|
1280
|
-
|
|
1321
|
+
const bal = balanceResponse.total * 1e8;
|
|
1322
|
+
setBalance(bal);
|
|
1323
|
+
return bal;
|
|
1281
1324
|
}
|
|
1282
1325
|
} catch (error) {
|
|
1283
1326
|
throw error;
|
|
@@ -1303,7 +1346,7 @@ var LaserEyesProvider = ({
|
|
|
1303
1346
|
}
|
|
1304
1347
|
});
|
|
1305
1348
|
const sendBTC = (to, amount) => __async(void 0, null, function* () {
|
|
1306
|
-
var
|
|
1349
|
+
var _a;
|
|
1307
1350
|
try {
|
|
1308
1351
|
if (amount <= 0)
|
|
1309
1352
|
throw new Error("Amount must be greater than 0");
|
|
@@ -1389,7 +1432,7 @@ var LaserEyesProvider = ({
|
|
|
1389
1432
|
}
|
|
1390
1433
|
]
|
|
1391
1434
|
});
|
|
1392
|
-
if ((
|
|
1435
|
+
if ((_a = response == null ? void 0 : response.result) == null ? void 0 : _a.txid) {
|
|
1393
1436
|
return response.result.txid;
|
|
1394
1437
|
} else {
|
|
1395
1438
|
if (response.error.code === RpcErrorCode.USER_REJECTION) {
|
|
@@ -1411,7 +1454,7 @@ var LaserEyesProvider = ({
|
|
|
1411
1454
|
}
|
|
1412
1455
|
});
|
|
1413
1456
|
const signMessage = (message, toSignAddress) => __async(void 0, null, function* () {
|
|
1414
|
-
var
|
|
1457
|
+
var _a;
|
|
1415
1458
|
try {
|
|
1416
1459
|
if (!library)
|
|
1417
1460
|
return;
|
|
@@ -1469,7 +1512,7 @@ var LaserEyesProvider = ({
|
|
|
1469
1512
|
message,
|
|
1470
1513
|
paymentType
|
|
1471
1514
|
});
|
|
1472
|
-
return (
|
|
1515
|
+
return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
|
|
1473
1516
|
} else if (provider === PHANTOM) {
|
|
1474
1517
|
const utf8Bytes = new TextEncoder().encode(message);
|
|
1475
1518
|
const uintArray = new Uint8Array(utf8Bytes);
|
|
@@ -1863,166 +1906,6 @@ var LaserEyesProvider = ({
|
|
|
1863
1906
|
);
|
|
1864
1907
|
};
|
|
1865
1908
|
|
|
1866
|
-
// src/hooks/useInscriber.ts
|
|
1867
|
-
import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
|
|
1868
|
-
|
|
1869
|
-
// src/consts/inscribe.ts
|
|
1870
|
-
var MIME_TYPE_TEXT = "text/plain;charset=utf-8";
|
|
1871
|
-
|
|
1872
|
-
// src/hooks/useInscriber.ts
|
|
1873
|
-
import axios3 from "axios";
|
|
1874
|
-
var DESCRIBE_API_URL = "http://localhost:3000/api";
|
|
1875
|
-
var useInscriber = ({
|
|
1876
|
-
inscribeApiUrl = DESCRIBE_API_URL
|
|
1877
|
-
}) => {
|
|
1878
|
-
const { address: address2, paymentAddress, paymentPublicKey, publicKey, signPsbt } = useLaserEyes();
|
|
1879
|
-
const [content, setContent] = useState2("");
|
|
1880
|
-
const [mimeType, setMimeType] = useState2(MIME_TYPE_TEXT);
|
|
1881
|
-
const [commitPsbtHex, setCommitPsbtHex] = useState2("");
|
|
1882
|
-
const [commitPsbtBase64, setCommitPsbtBase64] = useState2("");
|
|
1883
|
-
const [commitTxId, setCommitTxId] = useState2("");
|
|
1884
|
-
const [feeRate, setFeeRate] = useState2(10);
|
|
1885
|
-
const [totalFees, setTotalFees] = useState2(0);
|
|
1886
|
-
const [inscriberAddress, setInscriberAddress] = useState2("");
|
|
1887
|
-
const [inscriptionTxId, setInscriptionTxId] = useState2("");
|
|
1888
|
-
const [previewUrl, setPreviewUrl] = useState2("");
|
|
1889
|
-
const [isFetchingCommitPsbt, setIsFetchingCommitPsbt] = useState2(false);
|
|
1890
|
-
const [isInscribing, setIsInscribing] = useState2(false);
|
|
1891
|
-
useEffect2(() => {
|
|
1892
|
-
setCommitPsbtHex("");
|
|
1893
|
-
setCommitPsbtBase64("");
|
|
1894
|
-
setCommitTxId("");
|
|
1895
|
-
}, [content, address2, mimeType, feeRate]);
|
|
1896
|
-
const getCommitPsbt = useCallback2(() => __async(void 0, null, function* () {
|
|
1897
|
-
try {
|
|
1898
|
-
if (!content)
|
|
1899
|
-
throw new Error("missing content");
|
|
1900
|
-
if (!paymentAddress)
|
|
1901
|
-
throw new Error("missing paymentAddress");
|
|
1902
|
-
if (!paymentPublicKey)
|
|
1903
|
-
throw new Error("missing paymentPublicKey");
|
|
1904
|
-
if (!feeRate)
|
|
1905
|
-
throw new Error("missing feeRate");
|
|
1906
|
-
if (!mimeType)
|
|
1907
|
-
throw new Error("missing mimeType");
|
|
1908
|
-
setIsFetchingCommitPsbt(true);
|
|
1909
|
-
return yield axios3.post(`${inscribeApiUrl}/create-inscription`, {
|
|
1910
|
-
content,
|
|
1911
|
-
paymentAddress,
|
|
1912
|
-
paymentPublicKey,
|
|
1913
|
-
feeRate,
|
|
1914
|
-
mimeType
|
|
1915
|
-
}).then((res) => res.data).then((data) => {
|
|
1916
|
-
setCommitPsbtHex(data.psbtHex);
|
|
1917
|
-
setCommitPsbtBase64(data.psbtBase64);
|
|
1918
|
-
setFeeRate(feeRate);
|
|
1919
|
-
setTotalFees(data.totalFees);
|
|
1920
|
-
setInscriberAddress(data.inscriberAddress);
|
|
1921
|
-
return data;
|
|
1922
|
-
});
|
|
1923
|
-
} catch (e) {
|
|
1924
|
-
console.error(e);
|
|
1925
|
-
throw new Error(e.response.data);
|
|
1926
|
-
} finally {
|
|
1927
|
-
setIsFetchingCommitPsbt(false);
|
|
1928
|
-
}
|
|
1929
|
-
}), [paymentAddress, paymentPublicKey, content, feeRate, mimeType, publicKey]);
|
|
1930
|
-
const handleSignCommit = (tx) => __async(void 0, null, function* () {
|
|
1931
|
-
try {
|
|
1932
|
-
const toBeSigned = tx != null ? tx : commitPsbtHex;
|
|
1933
|
-
if (!toBeSigned)
|
|
1934
|
-
throw new Error("missing tx");
|
|
1935
|
-
const signedResponse = yield signPsbt(toBeSigned, true, true);
|
|
1936
|
-
setCommitTxId(signedResponse == null ? void 0 : signedResponse.txId);
|
|
1937
|
-
return signedResponse == null ? void 0 : signedResponse.txId;
|
|
1938
|
-
} catch (e) {
|
|
1939
|
-
console.error(e);
|
|
1940
|
-
throw e;
|
|
1941
|
-
}
|
|
1942
|
-
});
|
|
1943
|
-
const inscribe = useCallback2(
|
|
1944
|
-
(_0) => __async(void 0, [_0], function* ({
|
|
1945
|
-
content: providedContent,
|
|
1946
|
-
mimeType: providedMimeType,
|
|
1947
|
-
ordinalAddress: providedAddress,
|
|
1948
|
-
commitTxId: providedCommitTxId
|
|
1949
|
-
}) {
|
|
1950
|
-
try {
|
|
1951
|
-
const inscribeContent = providedContent != null ? providedContent : content;
|
|
1952
|
-
const inscribeMimeType = providedMimeType != null ? providedMimeType : mimeType;
|
|
1953
|
-
const inscribeOutputAddress = providedAddress != null ? providedAddress : address2;
|
|
1954
|
-
let inscribeCommitTxId = providedCommitTxId != null ? providedCommitTxId : commitTxId;
|
|
1955
|
-
if (!inscribeContent)
|
|
1956
|
-
throw new Error("missing content");
|
|
1957
|
-
if (!inscribeMimeType)
|
|
1958
|
-
throw new Error("missing mimeType");
|
|
1959
|
-
if (!inscribeOutputAddress)
|
|
1960
|
-
throw new Error("missing address");
|
|
1961
|
-
setIsInscribing(true);
|
|
1962
|
-
if (!inscribeCommitTxId) {
|
|
1963
|
-
const signed = yield getCommitPsbt();
|
|
1964
|
-
inscribeCommitTxId = yield handleSignCommit(signed.psbtBase64);
|
|
1965
|
-
if (!inscribeCommitTxId)
|
|
1966
|
-
throw new Error("failed to broadcast commit");
|
|
1967
|
-
console.log("tempCommitTxId", inscribeCommitTxId);
|
|
1968
|
-
}
|
|
1969
|
-
yield delay(1e4);
|
|
1970
|
-
if (!inscribeCommitTxId)
|
|
1971
|
-
throw new Error("missing commitTxId");
|
|
1972
|
-
return yield axios3.post(`${inscribeApiUrl}/inscribe`, {
|
|
1973
|
-
content,
|
|
1974
|
-
mimeType,
|
|
1975
|
-
ordinalAddress: address2,
|
|
1976
|
-
commitTxId: inscribeCommitTxId
|
|
1977
|
-
}).then((res) => res.data).then((data) => {
|
|
1978
|
-
setInscriptionTxId(data);
|
|
1979
|
-
return data;
|
|
1980
|
-
});
|
|
1981
|
-
} catch (e) {
|
|
1982
|
-
console.error(e);
|
|
1983
|
-
throw e;
|
|
1984
|
-
} finally {
|
|
1985
|
-
setIsInscribing(false);
|
|
1986
|
-
}
|
|
1987
|
-
}),
|
|
1988
|
-
[address2, commitTxId, content, mimeType]
|
|
1989
|
-
);
|
|
1990
|
-
const reset = () => {
|
|
1991
|
-
setContent("");
|
|
1992
|
-
setMimeType(MIME_TYPE_TEXT);
|
|
1993
|
-
setCommitPsbtHex("");
|
|
1994
|
-
setCommitPsbtBase64("");
|
|
1995
|
-
setCommitTxId("");
|
|
1996
|
-
setFeeRate(10);
|
|
1997
|
-
setTotalFees(0);
|
|
1998
|
-
setInscriberAddress("");
|
|
1999
|
-
setInscriptionTxId("");
|
|
2000
|
-
setPreviewUrl("");
|
|
2001
|
-
};
|
|
2002
|
-
return {
|
|
2003
|
-
content,
|
|
2004
|
-
setContent,
|
|
2005
|
-
setMimeType,
|
|
2006
|
-
previewUrl,
|
|
2007
|
-
setPreviewUrl,
|
|
2008
|
-
getCommitPsbt,
|
|
2009
|
-
isFetchingCommitPsbt,
|
|
2010
|
-
commitPsbtHex,
|
|
2011
|
-
commitPsbtBase64,
|
|
2012
|
-
handleSignCommit,
|
|
2013
|
-
commitTxId,
|
|
2014
|
-
setCommitTxId,
|
|
2015
|
-
feeRate,
|
|
2016
|
-
setFeeRate,
|
|
2017
|
-
totalFees,
|
|
2018
|
-
inscriberAddress,
|
|
2019
|
-
inscribe,
|
|
2020
|
-
isInscribing,
|
|
2021
|
-
inscriptionTxId,
|
|
2022
|
-
reset
|
|
2023
|
-
};
|
|
2024
|
-
};
|
|
2025
|
-
|
|
2026
1909
|
// src/icons/oyl.tsx
|
|
2027
1910
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
2028
1911
|
var OylLogo = (_a) => {
|
|
@@ -2702,6 +2585,5 @@ export {
|
|
|
2702
2585
|
isBase64,
|
|
2703
2586
|
isHex,
|
|
2704
2587
|
satoshisToBTC,
|
|
2705
|
-
useInscriber,
|
|
2706
2588
|
useLaserEyes
|
|
2707
2589
|
};
|