@omnisat/lasereyes 0.0.11 → 0.0.13
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 +36 -2
- package/dist/index.js +834 -34
- package/dist/index.mjs +819 -34
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -50,9 +50,14 @@ var UNISAT_MAINNET = "livenet";
|
|
|
50
50
|
var UNISAT_TESTNET = "testnet";
|
|
51
51
|
var XVERSE_MAINNET = "Mainnet";
|
|
52
52
|
var XVERSE_TESTNET = "Testnet";
|
|
53
|
+
var OKX_MAINNET = "livenet";
|
|
54
|
+
var OKX_TESTNET = "testnet";
|
|
55
|
+
var WIZZ_MAINNET = "livenet";
|
|
56
|
+
var WIZZ_TESTNET = "testnet";
|
|
53
57
|
var LEATHER_MAINNET = "mainnet";
|
|
54
58
|
var LEATHER_TESTNET = "testnet";
|
|
55
59
|
var MAINNET = "mainnet";
|
|
60
|
+
var SIGNET = "signet";
|
|
56
61
|
var TESTNET = "testnet";
|
|
57
62
|
var REGTEST = "regtest";
|
|
58
63
|
var getXverseNetwork = (network) => {
|
|
@@ -76,6 +81,13 @@ var getUnisatNetwork = (network) => {
|
|
|
76
81
|
return UNISAT_TESTNET;
|
|
77
82
|
return UNISAT_MAINNET;
|
|
78
83
|
};
|
|
84
|
+
var getWizzNetwork = (network) => {
|
|
85
|
+
if (network === MAINNET)
|
|
86
|
+
return WIZZ_MAINNET;
|
|
87
|
+
if (network === TESTNET)
|
|
88
|
+
return WIZZ_TESTNET;
|
|
89
|
+
return WIZZ_MAINNET;
|
|
90
|
+
};
|
|
79
91
|
var getNetworkForUnisat = (network) => {
|
|
80
92
|
if (network === UNISAT_MAINNET)
|
|
81
93
|
return MAINNET;
|
|
@@ -97,6 +109,20 @@ var getNetworkForLeather = (network) => {
|
|
|
97
109
|
return TESTNET;
|
|
98
110
|
return MAINNET;
|
|
99
111
|
};
|
|
112
|
+
var getNetworkForOkx = (network) => {
|
|
113
|
+
if (network === OKX_MAINNET)
|
|
114
|
+
return MAINNET;
|
|
115
|
+
if (network === OKX_TESTNET)
|
|
116
|
+
return TESTNET;
|
|
117
|
+
return MAINNET;
|
|
118
|
+
};
|
|
119
|
+
var getNetworkForWizz = (network) => {
|
|
120
|
+
if (network === WIZZ_MAINNET)
|
|
121
|
+
return MAINNET;
|
|
122
|
+
if (network === WIZZ_TESTNET)
|
|
123
|
+
return TESTNET;
|
|
124
|
+
return MAINNET;
|
|
125
|
+
};
|
|
100
126
|
var MEMPOOL_SPACE_URL = "https://mempool.space";
|
|
101
127
|
var MEMPOOL_SPACE_TESTNET_URL = "https://mempool.space/testnet";
|
|
102
128
|
var getMempoolSpaceUrl = (network) => network === TESTNET ? MEMPOOL_SPACE_TESTNET_URL : MEMPOOL_SPACE_URL;
|
|
@@ -107,6 +133,9 @@ var UNISAT = "unisat";
|
|
|
107
133
|
var XVERSE = "xverse";
|
|
108
134
|
var PHANTOM = "phantom";
|
|
109
135
|
var LEATHER = "leather";
|
|
136
|
+
var MAGIC_EDEN = "magic-eden";
|
|
137
|
+
var OKX = "okx";
|
|
138
|
+
var WIZZ = "wizz";
|
|
110
139
|
var P2TR = "p2tr";
|
|
111
140
|
var P2PKH = "p2pkh";
|
|
112
141
|
var P2WPKH = "p2wpkh";
|
|
@@ -164,6 +193,12 @@ var LOCAL_STORAGE_DEFAULT_WALLET = "defaultWallet";
|
|
|
164
193
|
var initialWalletContext = {
|
|
165
194
|
hasUnisat: false,
|
|
166
195
|
hasXverse: false,
|
|
196
|
+
hasOyl: false,
|
|
197
|
+
hasMagicEden: false,
|
|
198
|
+
hasOkx: false,
|
|
199
|
+
hasLeather: false,
|
|
200
|
+
hasPhantom: false,
|
|
201
|
+
hasWizz: false,
|
|
167
202
|
connected: false,
|
|
168
203
|
isConnecting: false,
|
|
169
204
|
publicKey: "",
|
|
@@ -220,6 +255,15 @@ import { useLocalStorage } from "usehooks-ts";
|
|
|
220
255
|
// src/lib/helpers.ts
|
|
221
256
|
import * as bitcoin from "bitcoinjs-lib";
|
|
222
257
|
import axios from "axios";
|
|
258
|
+
|
|
259
|
+
// src/lib/urls.ts
|
|
260
|
+
var MEMPOOL_SPACE_URL2 = "https://mempool.space";
|
|
261
|
+
var MEMPOOL_SPACE_TESTNET_URL2 = "https://mempool.space/testnet";
|
|
262
|
+
var getMempoolSpaceUrl2 = (network) => network === TESTNET ? MEMPOOL_SPACE_TESTNET_URL2 : MEMPOOL_SPACE_URL2;
|
|
263
|
+
|
|
264
|
+
// src/lib/helpers.ts
|
|
265
|
+
import * as ecc from "@bitcoinerlab/secp256k1";
|
|
266
|
+
bitcoin.initEccLib(ecc);
|
|
223
267
|
var getBitcoinNetwork = (network) => {
|
|
224
268
|
if (network === TESTNET) {
|
|
225
269
|
return bitcoin.networks.testnet;
|
|
@@ -247,6 +291,13 @@ var getBTCBalance = (address2) => __async(void 0, null, function* () {
|
|
|
247
291
|
throw new Error("Failed to fetch BTC balance");
|
|
248
292
|
}
|
|
249
293
|
});
|
|
294
|
+
var getAddressUtxos = (address2) => __async(void 0, null, function* () {
|
|
295
|
+
try {
|
|
296
|
+
return yield axios.get(`https://blockchain.info/unspent?active=${address2}`).then((response) => response.data.unspent_outputs);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
throw new Error("Failed to fetch UTXOs");
|
|
299
|
+
}
|
|
300
|
+
});
|
|
250
301
|
var satoshisToBTC = (satoshis) => {
|
|
251
302
|
if (Number.isNaN(satoshis) || satoshis === void 0)
|
|
252
303
|
return "--";
|
|
@@ -287,6 +338,96 @@ function getAddressType(address2) {
|
|
|
287
338
|
}
|
|
288
339
|
throw new Error("Invalid address");
|
|
289
340
|
}
|
|
341
|
+
function estimateTxSize(taprootInputCount, nonTaprootInputCount, outputCount) {
|
|
342
|
+
const baseTxSize = 10;
|
|
343
|
+
const taprootInputSize = 57;
|
|
344
|
+
const nonTaprootInputSize = 41;
|
|
345
|
+
const outputSize = 34;
|
|
346
|
+
const totalInputSize = taprootInputCount * taprootInputSize + nonTaprootInputCount * nonTaprootInputSize;
|
|
347
|
+
const totalOutputSize = outputCount * outputSize;
|
|
348
|
+
return baseTxSize + totalInputSize + totalOutputSize;
|
|
349
|
+
}
|
|
350
|
+
function createSendBtcPsbt(address2, paymentAddress, recipientAddress, amount, paymentPublicKey, network, feeRate = 7) {
|
|
351
|
+
return __async(this, null, function* () {
|
|
352
|
+
const isTaprootOnly = address2 === paymentAddress;
|
|
353
|
+
const mempoolUrl = `${getMempoolSpaceUrl2(
|
|
354
|
+
network
|
|
355
|
+
)}/api/address/${paymentAddress}/utxo`;
|
|
356
|
+
const utxos = yield axios.get(mempoolUrl).then((response) => response.data);
|
|
357
|
+
const sortedUtxos = utxos.sort(
|
|
358
|
+
(a, b) => b.value - a.value
|
|
359
|
+
);
|
|
360
|
+
const psbt = new bitcoin.Psbt({ network: getBitcoinNetwork(network) });
|
|
361
|
+
const estTxSize = estimateTxSize(1, 0, 2);
|
|
362
|
+
const satsNeeded = Math.floor(estTxSize * feeRate) + amount;
|
|
363
|
+
let amountGathered = 0;
|
|
364
|
+
let counter = 0;
|
|
365
|
+
try {
|
|
366
|
+
for (var iter = __forAwait(sortedUtxos), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
|
|
367
|
+
let utxo = temp.value;
|
|
368
|
+
const { txid, vout, value } = utxo;
|
|
369
|
+
const script = bitcoin.address.toOutputScript(
|
|
370
|
+
paymentAddress,
|
|
371
|
+
getBitcoinNetwork(network)
|
|
372
|
+
);
|
|
373
|
+
psbt.addInput({
|
|
374
|
+
hash: txid,
|
|
375
|
+
index: vout,
|
|
376
|
+
witnessUtxo: {
|
|
377
|
+
script,
|
|
378
|
+
value
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
if (!isTaprootOnly) {
|
|
382
|
+
const redeemScript = getRedeemScript(paymentPublicKey, network);
|
|
383
|
+
psbt.updateInput(counter, { redeemScript });
|
|
384
|
+
}
|
|
385
|
+
amountGathered += value;
|
|
386
|
+
if (amountGathered >= satsNeeded) {
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
} catch (temp) {
|
|
391
|
+
error = [temp];
|
|
392
|
+
} finally {
|
|
393
|
+
try {
|
|
394
|
+
more && (temp = iter.return) && (yield temp.call(iter));
|
|
395
|
+
} finally {
|
|
396
|
+
if (error)
|
|
397
|
+
throw error[0];
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (amountGathered < satsNeeded) {
|
|
401
|
+
throw new Error("Insufficient funds");
|
|
402
|
+
}
|
|
403
|
+
psbt.addOutput({
|
|
404
|
+
address: recipientAddress,
|
|
405
|
+
value: amount
|
|
406
|
+
});
|
|
407
|
+
if (amountGathered > satsNeeded) {
|
|
408
|
+
psbt.addOutput({
|
|
409
|
+
address: paymentAddress,
|
|
410
|
+
value: amountGathered - satsNeeded - amount
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
psbtBase64: psbt.toBase64(),
|
|
415
|
+
psbtHex: psbt.toHex()
|
|
416
|
+
};
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
function getRedeemScript(paymentPublicKey, network) {
|
|
420
|
+
var _a;
|
|
421
|
+
const p2wpkh = bitcoin.payments.p2wpkh({
|
|
422
|
+
pubkey: Buffer.from(paymentPublicKey, "hex"),
|
|
423
|
+
network: getBitcoinNetwork(network)
|
|
424
|
+
});
|
|
425
|
+
const p2sh = bitcoin.payments.p2sh({
|
|
426
|
+
redeem: p2wpkh,
|
|
427
|
+
network: getBitcoinNetwork(network)
|
|
428
|
+
});
|
|
429
|
+
return (_a = p2sh == null ? void 0 : p2sh.redeem) == null ? void 0 : _a.output;
|
|
430
|
+
}
|
|
290
431
|
|
|
291
432
|
// src/providers/LaserEyesProvider.tsx
|
|
292
433
|
import {
|
|
@@ -296,6 +437,7 @@ import {
|
|
|
296
437
|
signTransaction
|
|
297
438
|
} from "sats-connect";
|
|
298
439
|
import { fromOutputScript } from "bitcoinjs-lib/src/address";
|
|
440
|
+
import axios2 from "axios";
|
|
299
441
|
import { jsx } from "react/jsx-runtime";
|
|
300
442
|
var LaserEyesContext = createContext(initialWalletContext);
|
|
301
443
|
var useLaserEyes = () => {
|
|
@@ -321,6 +463,12 @@ var LaserEyesProvider = ({
|
|
|
321
463
|
const [balance, setBalance] = useState();
|
|
322
464
|
const [hasUnisat, setHasUnisat] = useState(false);
|
|
323
465
|
const [hasXverse, setHasXverse] = useState(false);
|
|
466
|
+
const [hasOyl, setHasOyl] = useState(false);
|
|
467
|
+
const [hasMagicEden, setHasMagicEden] = useState(false);
|
|
468
|
+
const [hasOkx, setHasOkx] = useState(false);
|
|
469
|
+
const [hasLeather, setHasLeather] = useState(false);
|
|
470
|
+
const [hasPhantom, setHasPhantom] = useState(false);
|
|
471
|
+
const [hasWizz, setHasWizz] = useState(false);
|
|
324
472
|
const [network, setNetwork] = useLocalStorage("network", MAINNET, {
|
|
325
473
|
initializeWithValue: false
|
|
326
474
|
});
|
|
@@ -345,11 +493,47 @@ var LaserEyesProvider = ({
|
|
|
345
493
|
const xverseLib = (_a = window == null ? void 0 : window.XverseProviders) == null ? void 0 : _a.BitcoinProvider;
|
|
346
494
|
setHasXverse(!!xverseLib);
|
|
347
495
|
}, []);
|
|
496
|
+
useEffect(() => {
|
|
497
|
+
const oylLib = window == null ? void 0 : window.oyl;
|
|
498
|
+
setHasOyl(!!oylLib);
|
|
499
|
+
}, []);
|
|
500
|
+
useEffect(() => {
|
|
501
|
+
const magicEdenLib = window == null ? void 0 : window.magicEden;
|
|
502
|
+
setHasMagicEden(!!magicEdenLib);
|
|
503
|
+
}, []);
|
|
504
|
+
useEffect(() => {
|
|
505
|
+
}, []);
|
|
506
|
+
useEffect(() => {
|
|
507
|
+
let foundOkx;
|
|
508
|
+
if (network === TESTNET) {
|
|
509
|
+
foundOkx = window.okxwallet.bitcoinTestnet;
|
|
510
|
+
} else if (network === MAINNET) {
|
|
511
|
+
foundOkx = window.okxwallet.bitcoin;
|
|
512
|
+
}
|
|
513
|
+
setHasOkx(!!foundOkx);
|
|
514
|
+
}, []);
|
|
515
|
+
useEffect(() => {
|
|
516
|
+
const leatherLib = window == null ? void 0 : window.LeatherProvider;
|
|
517
|
+
setHasLeather(!!leatherLib);
|
|
518
|
+
}, []);
|
|
519
|
+
useEffect(() => {
|
|
520
|
+
var _a;
|
|
521
|
+
const phantomLib = (_a = window == null ? void 0 : window.phantom) == null ? void 0 : _a.bitcoin;
|
|
522
|
+
if (phantomLib && phantomLib.isPhantom) {
|
|
523
|
+
setHasPhantom(!!phantomLib);
|
|
524
|
+
} else {
|
|
525
|
+
setHasPhantom(false);
|
|
526
|
+
}
|
|
527
|
+
}, []);
|
|
528
|
+
useEffect(() => {
|
|
529
|
+
const wissLib = window == null ? void 0 : window.wizz;
|
|
530
|
+
setHasWizz(!!wissLib);
|
|
531
|
+
}, []);
|
|
348
532
|
useEffect(() => {
|
|
349
533
|
setBalance(void 0);
|
|
350
534
|
}, [network]);
|
|
351
535
|
useEffect(() => {
|
|
352
|
-
if (provider !== UNISAT) {
|
|
536
|
+
if (provider !== UNISAT && provider !== WIZZ) {
|
|
353
537
|
return;
|
|
354
538
|
}
|
|
355
539
|
library.getAccounts().then((accounts2) => {
|
|
@@ -399,7 +583,6 @@ var LaserEyesProvider = ({
|
|
|
399
583
|
try {
|
|
400
584
|
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, XVERSE);
|
|
401
585
|
let xverseNetwork = getXverseNetwork((config == null ? void 0 : config.network) || MAINNET);
|
|
402
|
-
console.log({ xverseNetwork });
|
|
403
586
|
const getAddressOptions = {
|
|
404
587
|
payload: {
|
|
405
588
|
purposes: ["ordinals", "payment"],
|
|
@@ -420,7 +603,6 @@ var LaserEyesProvider = ({
|
|
|
420
603
|
setLibrary(window.BitcoinProvider);
|
|
421
604
|
}
|
|
422
605
|
getBTCBalance(foundPaymentAddress.address).then((totalBalance) => {
|
|
423
|
-
console.log({ totalBalance });
|
|
424
606
|
setBalance(totalBalance);
|
|
425
607
|
});
|
|
426
608
|
},
|
|
@@ -437,38 +619,186 @@ var LaserEyesProvider = ({
|
|
|
437
619
|
throw error;
|
|
438
620
|
}
|
|
439
621
|
});
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
622
|
+
const connectOyl = () => __async(void 0, null, function* () {
|
|
623
|
+
try {
|
|
624
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, OYL);
|
|
625
|
+
const lib = window.oyl;
|
|
626
|
+
const result = yield lib.requestAccounts();
|
|
627
|
+
const oylPubKey = yield lib.getPublicKey();
|
|
628
|
+
setPaymentPublicKey(oylPubKey);
|
|
629
|
+
setAccounts(result);
|
|
630
|
+
setAddress(result[0]);
|
|
631
|
+
setPaymentAddress(result[1]);
|
|
632
|
+
setLibrary(lib);
|
|
633
|
+
setProvider(OYL);
|
|
634
|
+
handleAccountsChanged(result);
|
|
635
|
+
setConnected(true);
|
|
636
|
+
} catch (error) {
|
|
637
|
+
throw new Error(`Can't lasereyes to ${OYL} wallet`);
|
|
444
638
|
}
|
|
445
|
-
|
|
446
|
-
|
|
639
|
+
});
|
|
640
|
+
const connectMagicEden = () => __async(void 0, null, function* () {
|
|
641
|
+
try {
|
|
642
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, MAGIC_EDEN);
|
|
643
|
+
let xverseNetwork = getXverseNetwork((config == null ? void 0 : config.network) || MAINNET);
|
|
644
|
+
const getAddressOptions = {
|
|
645
|
+
getProvider: () => __async(void 0, null, function* () {
|
|
646
|
+
return window.magicEden.bitcoin;
|
|
647
|
+
}),
|
|
648
|
+
payload: {
|
|
649
|
+
purposes: ["ordinals", "payment"],
|
|
650
|
+
message: "Address for receiving Ordinals and payments",
|
|
651
|
+
network: {
|
|
652
|
+
type: xverseNetwork
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
onFinish: (response) => {
|
|
656
|
+
setPublicKey(String(response.addresses[0].publicKey));
|
|
657
|
+
setPaymentPublicKey(String(response.addresses[1].publicKey));
|
|
658
|
+
const foundAddress = findOrdinalsAddress(response.addresses);
|
|
659
|
+
const foundPaymentAddress = findPaymentAddress(response.addresses);
|
|
660
|
+
if (foundAddress && foundPaymentAddress) {
|
|
661
|
+
setAddress(foundAddress.address);
|
|
662
|
+
setPaymentAddress(foundPaymentAddress.address);
|
|
663
|
+
setProvider(MAGIC_EDEN);
|
|
664
|
+
setLibrary(window.magicEden.bitcoin);
|
|
665
|
+
}
|
|
666
|
+
getBTCBalance(foundPaymentAddress.address).then((totalBalance) => {
|
|
667
|
+
setBalance(totalBalance);
|
|
668
|
+
});
|
|
669
|
+
},
|
|
670
|
+
onCancel: () => {
|
|
671
|
+
throw new Error(`User canceled lasereyes to ${MAGIC_EDEN} wallet`);
|
|
672
|
+
},
|
|
673
|
+
onError: (error) => {
|
|
674
|
+
throw new Error(`Can't lasereyes to ${MAGIC_EDEN} wallet`);
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
console.log(JSON.stringify(getAddressOptions));
|
|
678
|
+
yield getAddress(getAddressOptions);
|
|
679
|
+
setConnected(true);
|
|
680
|
+
} catch (error) {
|
|
681
|
+
console.log("error", error);
|
|
682
|
+
throw error;
|
|
447
683
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
684
|
+
});
|
|
685
|
+
const connectOkx = () => __async(void 0, null, function* () {
|
|
686
|
+
try {
|
|
687
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, OKX);
|
|
688
|
+
const lib = network === TESTNET ? window.okxwallet.bitcoinTestnet : window.okxwallet.bitcoin;
|
|
689
|
+
const okxAccounts = yield lib.requestAccounts();
|
|
690
|
+
if (!okxAccounts)
|
|
691
|
+
throw new Error("No accounts found");
|
|
692
|
+
const okxPubKey = yield lib.getPublicKey();
|
|
693
|
+
if (!okxPubKey)
|
|
694
|
+
throw new Error("No public key found");
|
|
695
|
+
setAccounts(okxAccounts);
|
|
696
|
+
setAddress(okxAccounts[0]);
|
|
697
|
+
setPaymentAddress(okxAccounts[0]);
|
|
698
|
+
setPublicKey(okxPubKey);
|
|
699
|
+
setPaymentPublicKey(okxPubKey);
|
|
700
|
+
setLibrary(lib);
|
|
701
|
+
setProvider(OKX);
|
|
702
|
+
setConnected(true);
|
|
703
|
+
const balance2 = yield lib == null ? void 0 : lib.getBalance();
|
|
704
|
+
setBalance(balance2 == null ? void 0 : balance2.total);
|
|
705
|
+
} catch (error) {
|
|
706
|
+
throw error;
|
|
454
707
|
}
|
|
455
|
-
};
|
|
456
|
-
const
|
|
708
|
+
});
|
|
709
|
+
const connectLeather = () => __async(void 0, null, function* () {
|
|
457
710
|
try {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
711
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, LEATHER);
|
|
712
|
+
const lib = window.LeatherProvider;
|
|
713
|
+
const getAddressesResponse = yield lib.request(
|
|
714
|
+
"getAddresses"
|
|
715
|
+
);
|
|
716
|
+
const addressesResponse = getAddressesResponse.result;
|
|
717
|
+
const addresses = addressesResponse.addresses;
|
|
718
|
+
const leatherAccountsParsed = addresses.map(
|
|
719
|
+
(address3) => address3.address
|
|
720
|
+
);
|
|
721
|
+
const taprootAddress = addresses.find(
|
|
722
|
+
(address3) => address3.type === P2TR
|
|
723
|
+
);
|
|
724
|
+
const segwitAddress = addresses.find(
|
|
725
|
+
(address3) => address3.type === P2WPKH
|
|
726
|
+
);
|
|
727
|
+
setAccounts(leatherAccountsParsed);
|
|
728
|
+
setAddress(String(taprootAddress == null ? void 0 : taprootAddress.address));
|
|
729
|
+
setPublicKey(String(taprootAddress == null ? void 0 : taprootAddress.publicKey));
|
|
730
|
+
setPaymentAddress(String(segwitAddress == null ? void 0 : segwitAddress.address));
|
|
731
|
+
setPaymentPublicKey(String(segwitAddress == null ? void 0 : segwitAddress.publicKey));
|
|
732
|
+
setLibrary(lib);
|
|
733
|
+
setProvider(LEATHER);
|
|
734
|
+
const balance2 = yield getBTCBalance(String(segwitAddress == null ? void 0 : segwitAddress.address));
|
|
735
|
+
setBalance(balance2);
|
|
736
|
+
handleAccountsChanged(leatherAccountsParsed);
|
|
737
|
+
setConnected(true);
|
|
738
|
+
yield getNetwork().then((network2) => {
|
|
739
|
+
if (!network2) {
|
|
740
|
+
setNetwork(MAINNET);
|
|
741
|
+
} else {
|
|
742
|
+
setNetwork(network2);
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
setConnected(true);
|
|
746
|
+
} catch (error) {
|
|
747
|
+
new Error(`Can't lasereyes to ${LEATHER} wallet`);
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
const connectPhantom = () => __async(void 0, null, function* () {
|
|
751
|
+
try {
|
|
752
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, PHANTOM);
|
|
753
|
+
const lib = window.phantom.bitcoin;
|
|
754
|
+
const phantomAccounts = yield lib.requestAccounts();
|
|
755
|
+
const phantomAccountsParsed = phantomAccounts.map(
|
|
756
|
+
(account) => account.address
|
|
757
|
+
);
|
|
758
|
+
setAccounts(phantomAccountsParsed);
|
|
759
|
+
const ordinalsAccount = phantomAccounts.find(
|
|
760
|
+
(account) => account.purpose === "ordinals"
|
|
761
|
+
);
|
|
762
|
+
const paymentAccount = phantomAccounts.find(
|
|
763
|
+
(account) => account.purpose === "payment"
|
|
764
|
+
);
|
|
765
|
+
setAddress(ordinalsAccount == null ? void 0 : ordinalsAccount.address);
|
|
766
|
+
setPublicKey(ordinalsAccount == null ? void 0 : ordinalsAccount.publicKey);
|
|
767
|
+
setPaymentAddress(paymentAccount == null ? void 0 : paymentAccount.address);
|
|
768
|
+
setPaymentPublicKey(paymentAccount == null ? void 0 : paymentAccount.publicKey);
|
|
769
|
+
setLibrary(lib);
|
|
770
|
+
setProvider(PHANTOM);
|
|
771
|
+
const balance2 = yield getBTCBalance(String(paymentAccount == null ? void 0 : paymentAccount.address));
|
|
772
|
+
setBalance(balance2);
|
|
773
|
+
setConnected(true);
|
|
774
|
+
} catch (error) {
|
|
775
|
+
throw new Error(`Can't lasereyes to ${PHANTOM} wallet`);
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
const connectWizz = () => __async(void 0, null, function* () {
|
|
779
|
+
try {
|
|
780
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, WIZZ);
|
|
781
|
+
const lib = window.wizz;
|
|
782
|
+
const wizzAccounts = yield lib.requestAccounts();
|
|
783
|
+
if (!wizzAccounts)
|
|
784
|
+
throw new Error("No accounts found");
|
|
785
|
+
const wizzPubKey = yield lib.getPublicKey();
|
|
786
|
+
if (!wizzPubKey)
|
|
787
|
+
throw new Error("No public key found");
|
|
788
|
+
setAccounts(wizzAccounts);
|
|
789
|
+
setAddress(wizzAccounts[0]);
|
|
790
|
+
setPaymentAddress(wizzAccounts[0]);
|
|
791
|
+
setPublicKey(wizzPubKey);
|
|
792
|
+
setPaymentPublicKey(wizzPubKey);
|
|
793
|
+
setLibrary(lib);
|
|
794
|
+
setProvider(WIZZ);
|
|
795
|
+
setConnected(true);
|
|
796
|
+
const balance2 = yield lib == null ? void 0 : lib.getBalance();
|
|
797
|
+
setBalance(balance2 == null ? void 0 : balance2.total);
|
|
468
798
|
} catch (error) {
|
|
469
799
|
throw error;
|
|
470
800
|
}
|
|
471
|
-
};
|
|
801
|
+
});
|
|
472
802
|
const connect = (walletName) => __async(void 0, null, function* () {
|
|
473
803
|
setIsConnecting(true);
|
|
474
804
|
try {
|
|
@@ -478,8 +808,20 @@ var LaserEyesProvider = ({
|
|
|
478
808
|
yield connectUnisat();
|
|
479
809
|
} else if (walletName === XVERSE) {
|
|
480
810
|
yield connectXverse();
|
|
811
|
+
} else if (walletName === OYL) {
|
|
812
|
+
yield connectOyl();
|
|
813
|
+
} else if (walletName === MAGIC_EDEN) {
|
|
814
|
+
yield connectMagicEden();
|
|
815
|
+
} else if (walletName === OKX) {
|
|
816
|
+
yield connectOkx();
|
|
817
|
+
} else if (walletName === LEATHER) {
|
|
818
|
+
yield connectLeather();
|
|
819
|
+
} else if (walletName === PHANTOM) {
|
|
820
|
+
yield connectPhantom();
|
|
821
|
+
} else if (walletName === WIZZ) {
|
|
822
|
+
yield connectWizz();
|
|
481
823
|
} else {
|
|
482
|
-
throw new Error("
|
|
824
|
+
throw new Error("Unsupported wallet..");
|
|
483
825
|
}
|
|
484
826
|
setConnected(true);
|
|
485
827
|
} catch (error) {
|
|
@@ -502,6 +844,43 @@ var LaserEyesProvider = ({
|
|
|
502
844
|
setBalance(void 0);
|
|
503
845
|
localStorage == null ? void 0 : localStorage.removeItem(LOCAL_STORAGE_DEFAULT_WALLET);
|
|
504
846
|
};
|
|
847
|
+
const handleAccountsChanged = (_accounts) => {
|
|
848
|
+
if (provider !== UNISAT)
|
|
849
|
+
return;
|
|
850
|
+
if (!_accounts.length) {
|
|
851
|
+
disconnect();
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
if (self.accounts[0] === _accounts[0]) {
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
self.accounts = _accounts;
|
|
858
|
+
if (_accounts.length > 0) {
|
|
859
|
+
connect(UNISAT);
|
|
860
|
+
} else {
|
|
861
|
+
setConnected(false);
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
const handleNetworkChanged = (network2) => {
|
|
865
|
+
try {
|
|
866
|
+
let foundNetwork = MAINNET;
|
|
867
|
+
if (provider === UNISAT) {
|
|
868
|
+
foundNetwork = getNetworkForUnisat(network2);
|
|
869
|
+
setNetwork(foundNetwork);
|
|
870
|
+
connect(provider);
|
|
871
|
+
} else if (provider === XVERSE) {
|
|
872
|
+
throw new Error("Not implemented");
|
|
873
|
+
} else if (provider === WIZZ) {
|
|
874
|
+
foundNetwork = getNetworkForWizz(network2);
|
|
875
|
+
setNetwork(foundNetwork);
|
|
876
|
+
connect(provider);
|
|
877
|
+
} else {
|
|
878
|
+
throw new Error("The connected wallet doesn't support this method..");
|
|
879
|
+
}
|
|
880
|
+
} catch (error) {
|
|
881
|
+
throw error;
|
|
882
|
+
}
|
|
883
|
+
};
|
|
505
884
|
const requestAccounts = () => __async(void 0, null, function* () {
|
|
506
885
|
try {
|
|
507
886
|
if (!library)
|
|
@@ -531,6 +910,50 @@ var LaserEyesProvider = ({
|
|
|
531
910
|
}
|
|
532
911
|
};
|
|
533
912
|
return [address2];
|
|
913
|
+
} else if (provider === OYL) {
|
|
914
|
+
return yield library.requestAccounts();
|
|
915
|
+
} else if (provider === OKX) {
|
|
916
|
+
return yield library.requestAccounts();
|
|
917
|
+
} else if (provider === LEATHER) {
|
|
918
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, LEATHER);
|
|
919
|
+
const lib = window.LeatherProvider;
|
|
920
|
+
const getAddressesResponse = yield lib.request(
|
|
921
|
+
"getAddresses"
|
|
922
|
+
);
|
|
923
|
+
const addressesResponse = getAddressesResponse.result;
|
|
924
|
+
const addresses = addressesResponse.addresses;
|
|
925
|
+
const leatherAccountsParsed = addresses.map(
|
|
926
|
+
(address3) => address3.address
|
|
927
|
+
);
|
|
928
|
+
const taprootAddress = addresses.find(
|
|
929
|
+
(address3) => address3.type === P2TR
|
|
930
|
+
);
|
|
931
|
+
const segwitAddress = addresses.find(
|
|
932
|
+
(address3) => address3.type === P2WPKH
|
|
933
|
+
);
|
|
934
|
+
setAccounts(leatherAccountsParsed);
|
|
935
|
+
setAddress(String(taprootAddress == null ? void 0 : taprootAddress.address));
|
|
936
|
+
setPaymentAddress(String(segwitAddress == null ? void 0 : segwitAddress.address));
|
|
937
|
+
setLibrary(lib);
|
|
938
|
+
setProvider(LEATHER);
|
|
939
|
+
handleAccountsChanged(leatherAccountsParsed);
|
|
940
|
+
setConnected(true);
|
|
941
|
+
yield getNetwork().then((network2) => {
|
|
942
|
+
if (!network2) {
|
|
943
|
+
setNetwork(MAINNET);
|
|
944
|
+
} else {
|
|
945
|
+
setNetwork(network2);
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
setConnected(true);
|
|
949
|
+
} else if (provider === PHANTOM) {
|
|
950
|
+
const phantomAccounts = yield library.requestAccounts();
|
|
951
|
+
const phantomAccountsParsed = phantomAccounts.map(
|
|
952
|
+
(account) => account.address
|
|
953
|
+
);
|
|
954
|
+
return phantomAccountsParsed;
|
|
955
|
+
} else if (provider === WIZZ) {
|
|
956
|
+
return yield library.requestAccounts();
|
|
534
957
|
} else {
|
|
535
958
|
throw new Error("The connected wallet doesn't support this method..");
|
|
536
959
|
}
|
|
@@ -553,6 +976,34 @@ var LaserEyesProvider = ({
|
|
|
553
976
|
return TESTNET;
|
|
554
977
|
}
|
|
555
978
|
return MAINNET;
|
|
979
|
+
} else if (provider === OYL) {
|
|
980
|
+
if (address2.slice(0, 1) === "t") {
|
|
981
|
+
return TESTNET;
|
|
982
|
+
}
|
|
983
|
+
return MAINNET;
|
|
984
|
+
} else if (provider === MAGIC_EDEN) {
|
|
985
|
+
if (address2.slice(0, 1) === "t") {
|
|
986
|
+
return TESTNET;
|
|
987
|
+
}
|
|
988
|
+
return MAINNET;
|
|
989
|
+
} else if (provider === OKX) {
|
|
990
|
+
const okxNetwork = yield library == null ? void 0 : library.getNetwork();
|
|
991
|
+
const foundNetwork = getNetworkForOkx(okxNetwork);
|
|
992
|
+
setNetwork(foundNetwork);
|
|
993
|
+
} else if (provider === LEATHER) {
|
|
994
|
+
if (address2.slice(0, 1) === "t") {
|
|
995
|
+
return TESTNET;
|
|
996
|
+
}
|
|
997
|
+
return MAINNET;
|
|
998
|
+
} else if (provider === PHANTOM) {
|
|
999
|
+
if (address2.slice(0, 1) === "t") {
|
|
1000
|
+
return TESTNET;
|
|
1001
|
+
}
|
|
1002
|
+
return MAINNET;
|
|
1003
|
+
} else if (provider === WIZZ) {
|
|
1004
|
+
const wizzNetwork = yield library == null ? void 0 : library.getNetwork();
|
|
1005
|
+
const foundNetwork = getNetworkForWizz(wizzNetwork);
|
|
1006
|
+
setNetwork(foundNetwork);
|
|
556
1007
|
}
|
|
557
1008
|
return (_a = config == null ? void 0 : config.network) != null ? _a : MAINNET;
|
|
558
1009
|
} catch (error) {
|
|
@@ -564,7 +1015,11 @@ var LaserEyesProvider = ({
|
|
|
564
1015
|
if (!library)
|
|
565
1016
|
return;
|
|
566
1017
|
if (provider === UNISAT) {
|
|
567
|
-
const wantedNetwork =
|
|
1018
|
+
const wantedNetwork = getWizzNetwork(network2);
|
|
1019
|
+
yield library == null ? void 0 : library.switchNetwork(wantedNetwork);
|
|
1020
|
+
setNetwork(network2);
|
|
1021
|
+
} else if (provider === WIZZ) {
|
|
1022
|
+
const wantedNetwork = getNetworkForWizz(network2);
|
|
568
1023
|
yield library == null ? void 0 : library.switchNetwork(wantedNetwork);
|
|
569
1024
|
setNetwork(network2);
|
|
570
1025
|
} else {
|
|
@@ -579,7 +1034,12 @@ var LaserEyesProvider = ({
|
|
|
579
1034
|
if (!library)
|
|
580
1035
|
return;
|
|
581
1036
|
if (provider === UNISAT) {
|
|
582
|
-
|
|
1037
|
+
return yield library == null ? void 0 : library.getPublicKey();
|
|
1038
|
+
} else if (provider === OYL) {
|
|
1039
|
+
return yield library == null ? void 0 : library.getPublicKey();
|
|
1040
|
+
} else if (provider === OKX) {
|
|
1041
|
+
return yield library == null ? void 0 : library.getPublicKey();
|
|
1042
|
+
} else if (provider === WIZZ) {
|
|
583
1043
|
return yield library == null ? void 0 : library.getPublicKey();
|
|
584
1044
|
} else {
|
|
585
1045
|
throw new Error("The connected wallet doesn't support this method..");
|
|
@@ -596,6 +1056,20 @@ var LaserEyesProvider = ({
|
|
|
596
1056
|
return yield library.getBalance();
|
|
597
1057
|
} else if (provider === XVERSE) {
|
|
598
1058
|
return yield getBTCBalance(paymentAddress);
|
|
1059
|
+
} else if (provider === OYL) {
|
|
1060
|
+
const balanceResponse = yield library.getBalance();
|
|
1061
|
+
return balanceResponse.btc.total * 1e8;
|
|
1062
|
+
} else if (provider === MAGIC_EDEN) {
|
|
1063
|
+
return yield getBTCBalance(paymentAddress);
|
|
1064
|
+
} else if (provider === OKX) {
|
|
1065
|
+
return yield getBTCBalance(paymentAddress);
|
|
1066
|
+
} else if (provider === LEATHER) {
|
|
1067
|
+
return yield getBTCBalance(paymentAddress);
|
|
1068
|
+
} else if (provider === PHANTOM) {
|
|
1069
|
+
return yield getBTCBalance(paymentAddress);
|
|
1070
|
+
} else if (provider === WIZZ) {
|
|
1071
|
+
const balanceResponse = yield library.getBalance();
|
|
1072
|
+
return balanceResponse.total * 1e8;
|
|
599
1073
|
}
|
|
600
1074
|
} catch (error) {
|
|
601
1075
|
throw error;
|
|
@@ -607,6 +1081,12 @@ var LaserEyesProvider = ({
|
|
|
607
1081
|
return;
|
|
608
1082
|
if (provider === UNISAT) {
|
|
609
1083
|
return yield library.getInscriptions(0, 10);
|
|
1084
|
+
} else if (provider === OYL) {
|
|
1085
|
+
return yield library.getInscriptions(0, 10);
|
|
1086
|
+
} else if (provider === OKX) {
|
|
1087
|
+
return yield library.getInscriptions(0, 10);
|
|
1088
|
+
} else if (provider === WIZZ) {
|
|
1089
|
+
return yield library.getInscriptions(0, 10);
|
|
610
1090
|
} else {
|
|
611
1091
|
throw new Error("The connected wallet doesn't support this method..");
|
|
612
1092
|
}
|
|
@@ -615,6 +1095,7 @@ var LaserEyesProvider = ({
|
|
|
615
1095
|
}
|
|
616
1096
|
});
|
|
617
1097
|
const sendBTC = (to, amount) => __async(void 0, null, function* () {
|
|
1098
|
+
var _a;
|
|
618
1099
|
try {
|
|
619
1100
|
if (amount <= 0)
|
|
620
1101
|
throw new Error("Amount must be greater than 0");
|
|
@@ -632,7 +1113,7 @@ var LaserEyesProvider = ({
|
|
|
632
1113
|
recipients: [
|
|
633
1114
|
{
|
|
634
1115
|
address: to,
|
|
635
|
-
amount
|
|
1116
|
+
amount
|
|
636
1117
|
}
|
|
637
1118
|
]
|
|
638
1119
|
});
|
|
@@ -645,12 +1126,73 @@ var LaserEyesProvider = ({
|
|
|
645
1126
|
throw new Error("Error sending BTC: " + response.error.message);
|
|
646
1127
|
}
|
|
647
1128
|
}
|
|
1129
|
+
} else if (provider === OYL) {
|
|
1130
|
+
const { psbtHex, psbtBase64 } = yield createSendBtcPsbt(
|
|
1131
|
+
address2,
|
|
1132
|
+
paymentAddress,
|
|
1133
|
+
to,
|
|
1134
|
+
amount,
|
|
1135
|
+
paymentPublicKey,
|
|
1136
|
+
//@ts-ignore
|
|
1137
|
+
network,
|
|
1138
|
+
7
|
|
1139
|
+
);
|
|
1140
|
+
const psbt = yield signPsbt(psbtBase64, true, true);
|
|
1141
|
+
if (!psbt)
|
|
1142
|
+
throw new Error("Error sending BTC");
|
|
1143
|
+
return psbt.txId;
|
|
1144
|
+
} else if (provider === MAGIC_EDEN) {
|
|
1145
|
+
const { psbtHex, psbtBase64 } = yield createSendBtcPsbt(
|
|
1146
|
+
address2,
|
|
1147
|
+
paymentAddress,
|
|
1148
|
+
to,
|
|
1149
|
+
amount,
|
|
1150
|
+
paymentPublicKey,
|
|
1151
|
+
//@ts-ignore
|
|
1152
|
+
network,
|
|
1153
|
+
7
|
|
1154
|
+
);
|
|
1155
|
+
const psbt = yield signPsbt(psbtBase64, true, true);
|
|
1156
|
+
if (!psbt)
|
|
1157
|
+
throw new Error("Error sending BTC");
|
|
1158
|
+
return psbt.txId;
|
|
1159
|
+
} else if (provider === OKX) {
|
|
1160
|
+
const txId = yield library == null ? void 0 : library.sendBitcoin(to, amount);
|
|
1161
|
+
if (!txId)
|
|
1162
|
+
throw new Error("Transaction failed");
|
|
1163
|
+
return txId;
|
|
1164
|
+
} else if (provider === LEATHER) {
|
|
1165
|
+
const response = yield library == null ? void 0 : library.request("sendTransfer", {
|
|
1166
|
+
recipients: [
|
|
1167
|
+
{
|
|
1168
|
+
address: to,
|
|
1169
|
+
amount
|
|
1170
|
+
}
|
|
1171
|
+
]
|
|
1172
|
+
});
|
|
1173
|
+
if ((_a = response == null ? void 0 : response.result) == null ? void 0 : _a.txid) {
|
|
1174
|
+
return response.result.txid;
|
|
1175
|
+
} else {
|
|
1176
|
+
if (response.error.code === RpcErrorCode.USER_REJECTION) {
|
|
1177
|
+
throw new Error("User rejected the request");
|
|
1178
|
+
} else {
|
|
1179
|
+
throw new Error("Error sending BTC: " + response.error.message);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
} else if (provider === WIZZ) {
|
|
1183
|
+
const txId = yield library == null ? void 0 : library.sendBitcoin(to, amount);
|
|
1184
|
+
if (txId) {
|
|
1185
|
+
return txId;
|
|
1186
|
+
} else {
|
|
1187
|
+
throw new Error("Error sending BTC");
|
|
1188
|
+
}
|
|
648
1189
|
}
|
|
649
1190
|
} catch (error) {
|
|
650
1191
|
throw error;
|
|
651
1192
|
}
|
|
652
1193
|
});
|
|
653
1194
|
const signMessage = (message) => __async(void 0, null, function* () {
|
|
1195
|
+
var _a;
|
|
654
1196
|
try {
|
|
655
1197
|
if (!library)
|
|
656
1198
|
return;
|
|
@@ -670,6 +1212,26 @@ var LaserEyesProvider = ({
|
|
|
670
1212
|
throw new Error("Error signing message: " + response.error.message);
|
|
671
1213
|
}
|
|
672
1214
|
}
|
|
1215
|
+
} else if (provider === OKX) {
|
|
1216
|
+
return yield library == null ? void 0 : library.signMessage(message);
|
|
1217
|
+
} else if (provider === LEATHER) {
|
|
1218
|
+
const signed = yield library == null ? void 0 : library.request("signMessage", {
|
|
1219
|
+
message,
|
|
1220
|
+
paymentType: P2TR
|
|
1221
|
+
});
|
|
1222
|
+
console.log(signed);
|
|
1223
|
+
return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
|
|
1224
|
+
} else if (provider === PHANTOM) {
|
|
1225
|
+
const utf8Bytes = new TextEncoder().encode(message);
|
|
1226
|
+
const uintArray = new Uint8Array(utf8Bytes);
|
|
1227
|
+
const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
|
|
1228
|
+
console.log(response);
|
|
1229
|
+
const binaryString = String.fromCharCode(...response.signature);
|
|
1230
|
+
return btoa(binaryString);
|
|
1231
|
+
} else if (provider === WIZZ) {
|
|
1232
|
+
return yield library == null ? void 0 : library.signMessage(message);
|
|
1233
|
+
} else {
|
|
1234
|
+
throw new Error("The connected wallet doesn't support this method..");
|
|
673
1235
|
}
|
|
674
1236
|
} catch (error) {
|
|
675
1237
|
throw error;
|
|
@@ -787,11 +1349,203 @@ var LaserEyesProvider = ({
|
|
|
787
1349
|
signedPsbtBase64,
|
|
788
1350
|
txId
|
|
789
1351
|
};
|
|
1352
|
+
} else if (provider === OYL) {
|
|
1353
|
+
const signedPsbt = yield library == null ? void 0 : library.signPsbt(psbtHex, true, true);
|
|
1354
|
+
console.log({ signedPsbt });
|
|
1355
|
+
const psbtSignedPsbt = bitcoin2.Psbt.fromHex(signedPsbt);
|
|
1356
|
+
console.log("psbtSignedPsbt", psbtSignedPsbt.toBase64());
|
|
1357
|
+
if (broadcast) {
|
|
1358
|
+
console.log("broadcastin");
|
|
1359
|
+
const txId = yield pushPsbt(psbtSignedPsbt.toHex());
|
|
1360
|
+
return {
|
|
1361
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1362
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1363
|
+
txId
|
|
1364
|
+
};
|
|
1365
|
+
} else {
|
|
1366
|
+
return {
|
|
1367
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1368
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1369
|
+
txId: void 0
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
} else if (provider === MAGIC_EDEN) {
|
|
1373
|
+
const toSignPsbt = bitcoin2.Psbt.fromBase64(String(psbtBase64), {
|
|
1374
|
+
network: getBitcoinNetwork(network)
|
|
1375
|
+
});
|
|
1376
|
+
const inputs = toSignPsbt.data.inputs;
|
|
1377
|
+
const inputsToSign = [];
|
|
1378
|
+
const ordinalAddressData = {
|
|
1379
|
+
address: address2,
|
|
1380
|
+
signingIndexes: []
|
|
1381
|
+
};
|
|
1382
|
+
const paymentsAddressData = {
|
|
1383
|
+
address: paymentAddress,
|
|
1384
|
+
signingIndexes: []
|
|
1385
|
+
};
|
|
1386
|
+
let counter = 0;
|
|
1387
|
+
try {
|
|
1388
|
+
for (var iter2 = __forAwait(inputs), more2, temp2, error2; more2 = !(temp2 = yield iter2.next()).done; more2 = false) {
|
|
1389
|
+
let input = temp2.value;
|
|
1390
|
+
const { script } = input.witnessUtxo;
|
|
1391
|
+
const addressFromScript = fromOutputScript(
|
|
1392
|
+
script,
|
|
1393
|
+
getBitcoinNetwork(network)
|
|
1394
|
+
);
|
|
1395
|
+
if (addressFromScript === paymentAddress) {
|
|
1396
|
+
paymentsAddressData.signingIndexes.push(Number(counter));
|
|
1397
|
+
} else if (addressFromScript === address2) {
|
|
1398
|
+
ordinalAddressData.signingIndexes.push(Number(counter));
|
|
1399
|
+
}
|
|
1400
|
+
counter++;
|
|
1401
|
+
}
|
|
1402
|
+
} catch (temp2) {
|
|
1403
|
+
error2 = [temp2];
|
|
1404
|
+
} finally {
|
|
1405
|
+
try {
|
|
1406
|
+
more2 && (temp2 = iter2.return) && (yield temp2.call(iter2));
|
|
1407
|
+
} finally {
|
|
1408
|
+
if (error2)
|
|
1409
|
+
throw error2[0];
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
if (ordinalAddressData.signingIndexes.length > 0) {
|
|
1413
|
+
inputsToSign.push(ordinalAddressData);
|
|
1414
|
+
}
|
|
1415
|
+
if (paymentsAddressData.signingIndexes.length > 0) {
|
|
1416
|
+
inputsToSign.push(paymentsAddressData);
|
|
1417
|
+
}
|
|
1418
|
+
let txId, signedPsbtHex, signedPsbtBase64;
|
|
1419
|
+
const xverseNetwork = getXverseNetwork(network);
|
|
1420
|
+
const signPsbtOptions = {
|
|
1421
|
+
getProvider: () => __async(void 0, null, function* () {
|
|
1422
|
+
return window.magicEden.bitcoin;
|
|
1423
|
+
}),
|
|
1424
|
+
payload: {
|
|
1425
|
+
network: {
|
|
1426
|
+
type: xverseNetwork
|
|
1427
|
+
},
|
|
1428
|
+
message: "Sign Transaction",
|
|
1429
|
+
psbtBase64: toSignPsbt.toBase64(),
|
|
1430
|
+
broadcast,
|
|
1431
|
+
inputsToSign
|
|
1432
|
+
},
|
|
1433
|
+
onFinish: (response) => {
|
|
1434
|
+
if (response.psbtBase64) {
|
|
1435
|
+
const signedPsbt = bitcoin2.Psbt.fromBase64(
|
|
1436
|
+
String(response.psbtBase64),
|
|
1437
|
+
{
|
|
1438
|
+
network: getBitcoinNetwork(network)
|
|
1439
|
+
}
|
|
1440
|
+
);
|
|
1441
|
+
signedPsbtHex = signedPsbt.toHex();
|
|
1442
|
+
signedPsbtBase64 = signedPsbt.toBase64();
|
|
1443
|
+
}
|
|
1444
|
+
},
|
|
1445
|
+
onCancel: () => {
|
|
1446
|
+
console.log("Canceled");
|
|
1447
|
+
throw new Error("User canceled the request");
|
|
1448
|
+
},
|
|
1449
|
+
onError: (error3) => {
|
|
1450
|
+
console.log("error", error3);
|
|
1451
|
+
throw error3;
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
yield signTransaction(signPsbtOptions);
|
|
1455
|
+
if (broadcast) {
|
|
1456
|
+
const signed = bitcoin2.Psbt.fromBase64(String(signedPsbtBase64));
|
|
1457
|
+
const finalized = signed.finalizeAllInputs();
|
|
1458
|
+
const extracted = finalized.extractTransaction();
|
|
1459
|
+
const txId2 = yield pushPsbt(extracted.toHex());
|
|
1460
|
+
return {
|
|
1461
|
+
signedPsbtHex: extracted.toHex(),
|
|
1462
|
+
signedPsbtBase64: "test",
|
|
1463
|
+
txId: txId2
|
|
1464
|
+
};
|
|
1465
|
+
} else {
|
|
1466
|
+
return {
|
|
1467
|
+
signedPsbtHex,
|
|
1468
|
+
signedPsbtBase64,
|
|
1469
|
+
txId
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
} else if (provider === OKX) {
|
|
1473
|
+
const signedPsbt = yield library == null ? void 0 : library.signPsbt(psbtHex, {
|
|
1474
|
+
autoFinalized: finalize
|
|
1475
|
+
});
|
|
1476
|
+
const psbtSignedPsbt = bitcoin2.Psbt.fromHex(signedPsbt);
|
|
1477
|
+
if (finalize && broadcast) {
|
|
1478
|
+
const txId = yield pushPsbt(signedPsbt);
|
|
1479
|
+
return {
|
|
1480
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1481
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1482
|
+
txId
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
return {
|
|
1486
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1487
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1488
|
+
txId: void 0
|
|
1489
|
+
};
|
|
1490
|
+
} else if (provider === LEATHER) {
|
|
1491
|
+
const requestParams = {
|
|
1492
|
+
hex: psbtHex,
|
|
1493
|
+
broadcast
|
|
1494
|
+
};
|
|
1495
|
+
const response = yield library == null ? void 0 : library.request(
|
|
1496
|
+
"signPsbt",
|
|
1497
|
+
requestParams
|
|
1498
|
+
);
|
|
1499
|
+
const leatherHexResult = response.result;
|
|
1500
|
+
const signedTx = leatherHexResult.hex;
|
|
1501
|
+
const signed = bitcoin2.Psbt.fromBase64(String(signedTx));
|
|
1502
|
+
if (finalize && broadcast) {
|
|
1503
|
+
const finalized = signed.finalizeAllInputs();
|
|
1504
|
+
const extracted = finalized.extractTransaction();
|
|
1505
|
+
const txId = yield pushPsbt(extracted.toHex());
|
|
1506
|
+
return {
|
|
1507
|
+
signedPsbtHex: signed.toHex(),
|
|
1508
|
+
signedPsbtBase64: signed.toBase64(),
|
|
1509
|
+
txId
|
|
1510
|
+
};
|
|
1511
|
+
} else if (finalize) {
|
|
1512
|
+
const finalized = signed.finalizeAllInputs();
|
|
1513
|
+
return {
|
|
1514
|
+
signedPsbtHex: finalized.toHex(),
|
|
1515
|
+
signedPsbtBase64: finalized.toBase64(),
|
|
1516
|
+
txId: void 0
|
|
1517
|
+
};
|
|
1518
|
+
} else {
|
|
1519
|
+
return {
|
|
1520
|
+
signedPsbtHex: signed.toHex(),
|
|
1521
|
+
signedPsbtBase64: signed.toBase64(),
|
|
1522
|
+
txId: void 0
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
} else if (provider === WIZZ) {
|
|
1526
|
+
const signedPsbt = yield library == null ? void 0 : library.signPsbt(psbtHex, {
|
|
1527
|
+
autoFinalized: finalize,
|
|
1528
|
+
broadcast: false
|
|
1529
|
+
});
|
|
1530
|
+
const psbtSignedPsbt = bitcoin2.Psbt.fromHex(signedPsbt);
|
|
1531
|
+
if (finalize && broadcast) {
|
|
1532
|
+
const txId = yield pushPsbt(signedPsbt);
|
|
1533
|
+
return {
|
|
1534
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1535
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1536
|
+
txId
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
return {
|
|
1540
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1541
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1542
|
+
txId: void 0
|
|
1543
|
+
};
|
|
790
1544
|
} else {
|
|
791
1545
|
throw new Error("The connected wallet doesn't support this method..");
|
|
792
1546
|
}
|
|
793
|
-
} catch (
|
|
794
|
-
throw
|
|
1547
|
+
} catch (error3) {
|
|
1548
|
+
throw error3;
|
|
795
1549
|
}
|
|
796
1550
|
});
|
|
797
1551
|
const pushPsbt = (psbt) => __async(void 0, null, function* () {
|
|
@@ -800,6 +1554,16 @@ var LaserEyesProvider = ({
|
|
|
800
1554
|
return;
|
|
801
1555
|
if (provider === UNISAT) {
|
|
802
1556
|
return yield library == null ? void 0 : library.pushPsbt(psbt);
|
|
1557
|
+
} else if (provider === OYL) {
|
|
1558
|
+
return yield library == null ? void 0 : library.pushPsbt(psbt);
|
|
1559
|
+
} else if (provider === OKX) {
|
|
1560
|
+
return yield library == null ? void 0 : library.pushPsbt(psbt);
|
|
1561
|
+
} else if (provider === MAGIC_EDEN) {
|
|
1562
|
+
return yield axios2.post("https://mempool.space/api/tx", psbt).then((res) => res.data);
|
|
1563
|
+
} else if (provider === LEATHER) {
|
|
1564
|
+
return yield axios2.post("https://mempool.space/api/tx", psbt).then((res) => res.data);
|
|
1565
|
+
} else if (provider === WIZZ) {
|
|
1566
|
+
return yield library == null ? void 0 : library.pushPsbt(psbt);
|
|
803
1567
|
} else {
|
|
804
1568
|
throw new Error("The connected wallet doesn't support this method..");
|
|
805
1569
|
}
|
|
@@ -824,6 +1588,12 @@ var LaserEyesProvider = ({
|
|
|
824
1588
|
isConnecting,
|
|
825
1589
|
hasUnisat,
|
|
826
1590
|
hasXverse,
|
|
1591
|
+
hasOyl,
|
|
1592
|
+
hasMagicEden,
|
|
1593
|
+
hasOkx,
|
|
1594
|
+
hasLeather,
|
|
1595
|
+
hasPhantom,
|
|
1596
|
+
hasWizz,
|
|
827
1597
|
// functions
|
|
828
1598
|
connect,
|
|
829
1599
|
disconnect,
|
|
@@ -847,9 +1617,13 @@ export {
|
|
|
847
1617
|
LEATHER_MAINNET,
|
|
848
1618
|
LEATHER_TESTNET,
|
|
849
1619
|
LaserEyesProvider,
|
|
1620
|
+
MAGIC_EDEN,
|
|
850
1621
|
MAINNET,
|
|
851
1622
|
MEMPOOL_SPACE_TESTNET_URL,
|
|
852
1623
|
MEMPOOL_SPACE_URL,
|
|
1624
|
+
OKX,
|
|
1625
|
+
OKX_MAINNET,
|
|
1626
|
+
OKX_TESTNET,
|
|
853
1627
|
OYL,
|
|
854
1628
|
P2PKH,
|
|
855
1629
|
P2PSH,
|
|
@@ -859,27 +1633,38 @@ export {
|
|
|
859
1633
|
P2WSH,
|
|
860
1634
|
PHANTOM,
|
|
861
1635
|
REGTEST,
|
|
1636
|
+
SIGNET,
|
|
862
1637
|
TESTNET,
|
|
863
1638
|
UNISAT,
|
|
864
1639
|
UNISAT_MAINNET,
|
|
865
1640
|
UNISAT_TESTNET,
|
|
866
1641
|
WALLETS,
|
|
1642
|
+
WIZZ,
|
|
1643
|
+
WIZZ_MAINNET,
|
|
1644
|
+
WIZZ_TESTNET,
|
|
867
1645
|
XVERSE,
|
|
868
1646
|
XVERSE_MAINNET,
|
|
869
1647
|
XVERSE_NETWORK,
|
|
870
1648
|
XVERSE_TESTNET,
|
|
871
1649
|
createConfig,
|
|
1650
|
+
createSendBtcPsbt,
|
|
1651
|
+
estimateTxSize,
|
|
872
1652
|
findOrdinalsAddress,
|
|
873
1653
|
findPaymentAddress,
|
|
874
1654
|
getAddressType,
|
|
1655
|
+
getAddressUtxos,
|
|
875
1656
|
getBTCBalance,
|
|
876
1657
|
getBitcoinNetwork,
|
|
877
1658
|
getLeatherNetwork,
|
|
878
1659
|
getMempoolSpaceUrl,
|
|
879
1660
|
getNetworkForLeather,
|
|
1661
|
+
getNetworkForOkx,
|
|
880
1662
|
getNetworkForUnisat,
|
|
1663
|
+
getNetworkForWizz,
|
|
881
1664
|
getNetworkForXverse,
|
|
1665
|
+
getRedeemScript,
|
|
882
1666
|
getUnisatNetwork,
|
|
1667
|
+
getWizzNetwork,
|
|
883
1668
|
getXverseNetwork,
|
|
884
1669
|
isBase64,
|
|
885
1670
|
isHex,
|