@omnisat/lasereyes 0.0.12 → 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 +18 -2
- package/dist/index.js +615 -8
- package/dist/index.mjs +604 -8
- package/package.json +1 -1
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";
|
|
@@ -165,6 +194,11 @@ var initialWalletContext = {
|
|
|
165
194
|
hasUnisat: false,
|
|
166
195
|
hasXverse: false,
|
|
167
196
|
hasOyl: false,
|
|
197
|
+
hasMagicEden: false,
|
|
198
|
+
hasOkx: false,
|
|
199
|
+
hasLeather: false,
|
|
200
|
+
hasPhantom: false,
|
|
201
|
+
hasWizz: false,
|
|
168
202
|
connected: false,
|
|
169
203
|
isConnecting: false,
|
|
170
204
|
publicKey: "",
|
|
@@ -344,7 +378,7 @@ function createSendBtcPsbt(address2, paymentAddress, recipientAddress, amount, p
|
|
|
344
378
|
value
|
|
345
379
|
}
|
|
346
380
|
});
|
|
347
|
-
if (isTaprootOnly) {
|
|
381
|
+
if (!isTaprootOnly) {
|
|
348
382
|
const redeemScript = getRedeemScript(paymentPublicKey, network);
|
|
349
383
|
psbt.updateInput(counter, { redeemScript });
|
|
350
384
|
}
|
|
@@ -403,6 +437,7 @@ import {
|
|
|
403
437
|
signTransaction
|
|
404
438
|
} from "sats-connect";
|
|
405
439
|
import { fromOutputScript } from "bitcoinjs-lib/src/address";
|
|
440
|
+
import axios2 from "axios";
|
|
406
441
|
import { jsx } from "react/jsx-runtime";
|
|
407
442
|
var LaserEyesContext = createContext(initialWalletContext);
|
|
408
443
|
var useLaserEyes = () => {
|
|
@@ -429,6 +464,11 @@ var LaserEyesProvider = ({
|
|
|
429
464
|
const [hasUnisat, setHasUnisat] = useState(false);
|
|
430
465
|
const [hasXverse, setHasXverse] = useState(false);
|
|
431
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);
|
|
432
472
|
const [network, setNetwork] = useLocalStorage("network", MAINNET, {
|
|
433
473
|
initializeWithValue: false
|
|
434
474
|
});
|
|
@@ -457,11 +497,43 @@ var LaserEyesProvider = ({
|
|
|
457
497
|
const oylLib = window == null ? void 0 : window.oyl;
|
|
458
498
|
setHasOyl(!!oylLib);
|
|
459
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
|
+
}, []);
|
|
460
532
|
useEffect(() => {
|
|
461
533
|
setBalance(void 0);
|
|
462
534
|
}, [network]);
|
|
463
535
|
useEffect(() => {
|
|
464
|
-
if (provider !== UNISAT) {
|
|
536
|
+
if (provider !== UNISAT && provider !== WIZZ) {
|
|
465
537
|
return;
|
|
466
538
|
}
|
|
467
539
|
library.getAccounts().then((accounts2) => {
|
|
@@ -565,19 +637,189 @@ var LaserEyesProvider = ({
|
|
|
565
637
|
throw new Error(`Can't lasereyes to ${OYL} wallet`);
|
|
566
638
|
}
|
|
567
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;
|
|
683
|
+
}
|
|
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;
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
const connectLeather = () => __async(void 0, null, function* () {
|
|
710
|
+
try {
|
|
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);
|
|
798
|
+
} catch (error) {
|
|
799
|
+
throw error;
|
|
800
|
+
}
|
|
801
|
+
});
|
|
568
802
|
const connect = (walletName) => __async(void 0, null, function* () {
|
|
569
803
|
setIsConnecting(true);
|
|
570
804
|
try {
|
|
571
805
|
if (!walletName)
|
|
572
806
|
throw new Error("No wallet provided");
|
|
573
807
|
if (walletName === UNISAT) {
|
|
574
|
-
console.log("connectin unisat");
|
|
575
808
|
yield connectUnisat();
|
|
576
809
|
} else if (walletName === XVERSE) {
|
|
577
810
|
yield connectXverse();
|
|
578
811
|
} else if (walletName === OYL) {
|
|
579
|
-
console.log("connectin oyl");
|
|
580
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();
|
|
581
823
|
} else {
|
|
582
824
|
throw new Error("Unsupported wallet..");
|
|
583
825
|
}
|
|
@@ -612,7 +854,6 @@ var LaserEyesProvider = ({
|
|
|
612
854
|
if (self.accounts[0] === _accounts[0]) {
|
|
613
855
|
return;
|
|
614
856
|
}
|
|
615
|
-
console.log("acct changed", _accounts[0]);
|
|
616
857
|
self.accounts = _accounts;
|
|
617
858
|
if (_accounts.length > 0) {
|
|
618
859
|
connect(UNISAT);
|
|
@@ -629,6 +870,10 @@ var LaserEyesProvider = ({
|
|
|
629
870
|
connect(provider);
|
|
630
871
|
} else if (provider === XVERSE) {
|
|
631
872
|
throw new Error("Not implemented");
|
|
873
|
+
} else if (provider === WIZZ) {
|
|
874
|
+
foundNetwork = getNetworkForWizz(network2);
|
|
875
|
+
setNetwork(foundNetwork);
|
|
876
|
+
connect(provider);
|
|
632
877
|
} else {
|
|
633
878
|
throw new Error("The connected wallet doesn't support this method..");
|
|
634
879
|
}
|
|
@@ -667,6 +912,48 @@ var LaserEyesProvider = ({
|
|
|
667
912
|
return [address2];
|
|
668
913
|
} else if (provider === OYL) {
|
|
669
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();
|
|
670
957
|
} else {
|
|
671
958
|
throw new Error("The connected wallet doesn't support this method..");
|
|
672
959
|
}
|
|
@@ -694,6 +981,29 @@ var LaserEyesProvider = ({
|
|
|
694
981
|
return TESTNET;
|
|
695
982
|
}
|
|
696
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);
|
|
697
1007
|
}
|
|
698
1008
|
return (_a = config == null ? void 0 : config.network) != null ? _a : MAINNET;
|
|
699
1009
|
} catch (error) {
|
|
@@ -705,7 +1015,11 @@ var LaserEyesProvider = ({
|
|
|
705
1015
|
if (!library)
|
|
706
1016
|
return;
|
|
707
1017
|
if (provider === UNISAT) {
|
|
708
|
-
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);
|
|
709
1023
|
yield library == null ? void 0 : library.switchNetwork(wantedNetwork);
|
|
710
1024
|
setNetwork(network2);
|
|
711
1025
|
} else {
|
|
@@ -723,6 +1037,10 @@ var LaserEyesProvider = ({
|
|
|
723
1037
|
return yield library == null ? void 0 : library.getPublicKey();
|
|
724
1038
|
} else if (provider === OYL) {
|
|
725
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) {
|
|
1043
|
+
return yield library == null ? void 0 : library.getPublicKey();
|
|
726
1044
|
} else {
|
|
727
1045
|
throw new Error("The connected wallet doesn't support this method..");
|
|
728
1046
|
}
|
|
@@ -741,6 +1059,17 @@ var LaserEyesProvider = ({
|
|
|
741
1059
|
} else if (provider === OYL) {
|
|
742
1060
|
const balanceResponse = yield library.getBalance();
|
|
743
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;
|
|
744
1073
|
}
|
|
745
1074
|
} catch (error) {
|
|
746
1075
|
throw error;
|
|
@@ -754,6 +1083,10 @@ var LaserEyesProvider = ({
|
|
|
754
1083
|
return yield library.getInscriptions(0, 10);
|
|
755
1084
|
} else if (provider === OYL) {
|
|
756
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);
|
|
757
1090
|
} else {
|
|
758
1091
|
throw new Error("The connected wallet doesn't support this method..");
|
|
759
1092
|
}
|
|
@@ -762,6 +1095,7 @@ var LaserEyesProvider = ({
|
|
|
762
1095
|
}
|
|
763
1096
|
});
|
|
764
1097
|
const sendBTC = (to, amount) => __async(void 0, null, function* () {
|
|
1098
|
+
var _a;
|
|
765
1099
|
try {
|
|
766
1100
|
if (amount <= 0)
|
|
767
1101
|
throw new Error("Amount must be greater than 0");
|
|
@@ -807,12 +1141,58 @@ var LaserEyesProvider = ({
|
|
|
807
1141
|
if (!psbt)
|
|
808
1142
|
throw new Error("Error sending BTC");
|
|
809
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
|
+
}
|
|
810
1189
|
}
|
|
811
1190
|
} catch (error) {
|
|
812
1191
|
throw error;
|
|
813
1192
|
}
|
|
814
1193
|
});
|
|
815
1194
|
const signMessage = (message) => __async(void 0, null, function* () {
|
|
1195
|
+
var _a;
|
|
816
1196
|
try {
|
|
817
1197
|
if (!library)
|
|
818
1198
|
return;
|
|
@@ -832,6 +1212,26 @@ var LaserEyesProvider = ({
|
|
|
832
1212
|
throw new Error("Error signing message: " + response.error.message);
|
|
833
1213
|
}
|
|
834
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..");
|
|
835
1235
|
}
|
|
836
1236
|
} catch (error) {
|
|
837
1237
|
throw error;
|
|
@@ -969,11 +1369,183 @@ var LaserEyesProvider = ({
|
|
|
969
1369
|
txId: void 0
|
|
970
1370
|
};
|
|
971
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
|
+
};
|
|
972
1544
|
} else {
|
|
973
1545
|
throw new Error("The connected wallet doesn't support this method..");
|
|
974
1546
|
}
|
|
975
|
-
} catch (
|
|
976
|
-
throw
|
|
1547
|
+
} catch (error3) {
|
|
1548
|
+
throw error3;
|
|
977
1549
|
}
|
|
978
1550
|
});
|
|
979
1551
|
const pushPsbt = (psbt) => __async(void 0, null, function* () {
|
|
@@ -984,6 +1556,14 @@ var LaserEyesProvider = ({
|
|
|
984
1556
|
return yield library == null ? void 0 : library.pushPsbt(psbt);
|
|
985
1557
|
} else if (provider === OYL) {
|
|
986
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);
|
|
987
1567
|
} else {
|
|
988
1568
|
throw new Error("The connected wallet doesn't support this method..");
|
|
989
1569
|
}
|
|
@@ -1009,6 +1589,11 @@ var LaserEyesProvider = ({
|
|
|
1009
1589
|
hasUnisat,
|
|
1010
1590
|
hasXverse,
|
|
1011
1591
|
hasOyl,
|
|
1592
|
+
hasMagicEden,
|
|
1593
|
+
hasOkx,
|
|
1594
|
+
hasLeather,
|
|
1595
|
+
hasPhantom,
|
|
1596
|
+
hasWizz,
|
|
1012
1597
|
// functions
|
|
1013
1598
|
connect,
|
|
1014
1599
|
disconnect,
|
|
@@ -1032,9 +1617,13 @@ export {
|
|
|
1032
1617
|
LEATHER_MAINNET,
|
|
1033
1618
|
LEATHER_TESTNET,
|
|
1034
1619
|
LaserEyesProvider,
|
|
1620
|
+
MAGIC_EDEN,
|
|
1035
1621
|
MAINNET,
|
|
1036
1622
|
MEMPOOL_SPACE_TESTNET_URL,
|
|
1037
1623
|
MEMPOOL_SPACE_URL,
|
|
1624
|
+
OKX,
|
|
1625
|
+
OKX_MAINNET,
|
|
1626
|
+
OKX_TESTNET,
|
|
1038
1627
|
OYL,
|
|
1039
1628
|
P2PKH,
|
|
1040
1629
|
P2PSH,
|
|
@@ -1044,11 +1633,15 @@ export {
|
|
|
1044
1633
|
P2WSH,
|
|
1045
1634
|
PHANTOM,
|
|
1046
1635
|
REGTEST,
|
|
1636
|
+
SIGNET,
|
|
1047
1637
|
TESTNET,
|
|
1048
1638
|
UNISAT,
|
|
1049
1639
|
UNISAT_MAINNET,
|
|
1050
1640
|
UNISAT_TESTNET,
|
|
1051
1641
|
WALLETS,
|
|
1642
|
+
WIZZ,
|
|
1643
|
+
WIZZ_MAINNET,
|
|
1644
|
+
WIZZ_TESTNET,
|
|
1052
1645
|
XVERSE,
|
|
1053
1646
|
XVERSE_MAINNET,
|
|
1054
1647
|
XVERSE_NETWORK,
|
|
@@ -1065,10 +1658,13 @@ export {
|
|
|
1065
1658
|
getLeatherNetwork,
|
|
1066
1659
|
getMempoolSpaceUrl,
|
|
1067
1660
|
getNetworkForLeather,
|
|
1661
|
+
getNetworkForOkx,
|
|
1068
1662
|
getNetworkForUnisat,
|
|
1663
|
+
getNetworkForWizz,
|
|
1069
1664
|
getNetworkForXverse,
|
|
1070
1665
|
getRedeemScript,
|
|
1071
1666
|
getUnisatNetwork,
|
|
1667
|
+
getWizzNetwork,
|
|
1072
1668
|
getXverseNetwork,
|
|
1073
1669
|
isBase64,
|
|
1074
1670
|
isHex,
|