btc-wallet 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
package/esm/index.js CHANGED
@@ -459,6 +459,210 @@ var XverseConnector = class extends BaseConnector {
459
459
  _network = new WeakMap();
460
460
  _event = new WeakMap();
461
461
 
462
+ // src/connector/magicEden.ts
463
+ import EventEmitter2 from "events";
464
+
465
+ // src/icons/magicEden.png
466
+ var magicEden_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADYAAAAgCAYAAABZyotbAAADGklEQVR42sVYTW7aQBT+ZsZk0yy8jWoqIxWK1E16A3KDcoLACRqkGKFugE0VAVLgBElOQHqC0BPUm0q0EMVVoWxZNCsYv25MlR/AY2O73xKZefO9ed+b7w0DgFm+ZrquPCdCAYAOwAbQM0btS0SIaa5aJ6AEIhPR49Ge2SxfM6Urb0B4Fowx1nj5o9WMhpTVJ8J7xA3OKsb3VpdNs9YFAaVN30VBbpqr1omogWQwXyxeZDhhexaJqDHNVetho8zyNTNBUgCga9qfQ+5pCnGQuzMbunTlDf4DuOqHYcjtpe7P12k3XjAnPe4MeJC/BCH3+431YZt249KXEPwIANgka1HgnPg0lFm+Zkopv6qU+aasAzQImPSfy+V+N+M05gCghQnrnRw2kfN0pYdPPOlCiObB8MyJXWOqZTnNVesR6EqXUt7cmQ09cWLryE2yVsm/tTOHXLensLyZSt33Q7eQMBpbpznO+dUmB/ME74xR255kTy8BdqywetcYtSqJntjDk5NS3vmRIqKmMWrbALBYLE88f+e3+kmYO1SF2ADRYJAed/6VacbpzoUQRTDmqCTu1+vTQqTEiKhJRDsaYeYIIcpPfz0YnjmC8yMAc4Vyr0deiulxp7ELOSK3vKl1HwzPHCIqKixTCNIllTUWlhwRNdPjztZy1jTNQcQI1DxCkHukq40uRckoM2flKmLpit5Gy2F19RSulEoXuuuiEtuJreCN3+Wwunr2VKBQzq9uW9eJ3GPbyKnoSnUAJRc9v3KO/II2Ru1LIUQGoCsANmO4BlD220iAAdRO37ZPwuxN27X7eOUWaO7aS92fk6+umCMEL4bdVySWKgjUBlDmCMGPdhlbtCRJeQOogl5Il1LWJ1kryPJfhBCDVTISJSal7CsOoDqCPyuUpJTOJGsVjVHbTqwUJ1mrBOAw5jAmgH7SGjtOKI45efvx0JfYcrlvRxKOJfsMx33mrUEQf7bdPeBzMpSYY3z7ZHMAlfXzkJrXU26/QnRVhspdsfKU7EEbvgBQ8Ehe7/r8taXdFzy96WBMj+ycQLbrUm9l5f4C3RupufZdcK8AAAAASUVORK5CYII=";
467
+
468
+ // src/connector/magicEden.ts
469
+ var _network2, _event2;
470
+ var MagicEdenConnector = class extends BaseConnector {
471
+ constructor() {
472
+ super();
473
+ __privateAdd(this, _network2, "Mainnet");
474
+ __privateAdd(this, _event2, new EventEmitter2());
475
+ this.metadata = {
476
+ id: "magicEden",
477
+ name: "Magic Eden Wallet",
478
+ icon: magicEden_default,
479
+ downloadUrl: "https://www.magiceden.io"
480
+ };
481
+ this.loadAccounts = (network) => __async(this, null, function* () {
482
+ const { getAddress, AddressPurpose } = yield import("sats-connect");
483
+ const addresses = yield new Promise((resolve, reject) => {
484
+ const getAddressOptions = {
485
+ payload: {
486
+ purposes: [AddressPurpose.Payment, AddressPurpose.Ordinals],
487
+ message: "Address for receiving Ordinals and payments",
488
+ network: {
489
+ type: network
490
+ }
491
+ },
492
+ onFinish: (response) => {
493
+ resolve(response.addresses);
494
+ },
495
+ onCancel: () => reject({
496
+ code: 4001,
497
+ message: "User rejected the request."
498
+ })
499
+ };
500
+ getAddress(getAddressOptions).catch((error) => reject(error));
501
+ });
502
+ localStorage.setItem("btc-connect-magicEden-addresses-" + network, JSON.stringify(addresses));
503
+ return addresses;
504
+ });
505
+ __privateGet(this, _event2).setMaxListeners(100);
506
+ }
507
+ isReady() {
508
+ return typeof window !== "undefined" && "magicEden" in window && !!window.magicEden;
509
+ }
510
+ sendInscription() {
511
+ return __async(this, null, function* () {
512
+ throw new Error("Unsupported");
513
+ });
514
+ }
515
+ requestAccounts() {
516
+ return __async(this, null, function* () {
517
+ if (!this.isReady()) {
518
+ throw new Error(`${this.metadata.name} is not install!`);
519
+ }
520
+ const addresses = yield this.loadAccounts(__privateGet(this, _network2));
521
+ return addresses.map((item) => item.address);
522
+ });
523
+ }
524
+ getAccounts() {
525
+ return __async(this, null, function* () {
526
+ if (!this.isReady()) {
527
+ throw new Error(`${this.metadata.name} is not install!`);
528
+ }
529
+ const data = localStorage.getItem("btc-connect-magicEden-addresses-" + __privateGet(this, _network2));
530
+ if (data) {
531
+ const addresses = JSON.parse(data);
532
+ return addresses.map((item) => item.address);
533
+ } else {
534
+ return [];
535
+ }
536
+ });
537
+ }
538
+ getPublicKey() {
539
+ return __async(this, null, function* () {
540
+ if (!this.isReady()) {
541
+ throw new Error(`${this.metadata.name} is not install!`);
542
+ }
543
+ const data = localStorage.getItem("btc-connect-magicEden-addresses-" + __privateGet(this, _network2));
544
+ if (data) {
545
+ const addresses = JSON.parse(data);
546
+ return addresses[0].publicKey;
547
+ } else {
548
+ return "";
549
+ }
550
+ });
551
+ }
552
+ signMessage(signStr) {
553
+ return __async(this, null, function* () {
554
+ if (!this.isReady()) {
555
+ throw new Error(`${this.metadata.name} is not install!`);
556
+ }
557
+ const addresses = yield this.getAccounts();
558
+ if (addresses.length === 0) {
559
+ throw new Error(`${this.metadata.name} not connected!`);
560
+ }
561
+ const { signMessage } = yield import("sats-connect");
562
+ const sig = yield new Promise((resolve, reject) => {
563
+ const signMessageOptions = {
564
+ payload: {
565
+ network: {
566
+ type: __privateGet(this, _network2)
567
+ },
568
+ address: addresses[0],
569
+ message: signStr
570
+ },
571
+ onFinish: (response) => {
572
+ resolve(response);
573
+ },
574
+ onCancel: () => {
575
+ reject({
576
+ code: 4001,
577
+ message: "User rejected the request."
578
+ });
579
+ }
580
+ };
581
+ signMessage(signMessageOptions).catch((e) => {
582
+ reject(e);
583
+ });
584
+ });
585
+ const modifiedSig = Buffer.from(sig, "base64");
586
+ modifiedSig[0] = 31 + (modifiedSig[0] - 31) % 4;
587
+ return modifiedSig.toString("base64");
588
+ });
589
+ }
590
+ on(event, handler) {
591
+ return __privateGet(this, _event2).on(event, handler);
592
+ }
593
+ removeListener(event, handler) {
594
+ return __privateGet(this, _event2).removeListener(event, handler);
595
+ }
596
+ getProvider() {
597
+ if (this.isReady()) {
598
+ if ("magicEden" in window) {
599
+ const anyWindow = window;
600
+ if (anyWindow.magicEden.bitcoin && anyWindow.magicEden.bitcoin.isMagicEden)
601
+ return anyWindow.magicEden.bitcoin;
602
+ }
603
+ }
604
+ }
605
+ getNetwork() {
606
+ return __async(this, null, function* () {
607
+ if (!this.isReady()) {
608
+ throw new Error(`${this.metadata.name} is not install!`);
609
+ }
610
+ return __privateGet(this, _network2) === "Mainnet" ? "livenet" : "testnet";
611
+ });
612
+ }
613
+ switchNetwork() {
614
+ return __async(this, null, function* () {
615
+ throw new Error("Unsupported");
616
+ });
617
+ }
618
+ sendBitcoin(toAddress, satoshis) {
619
+ return __async(this, null, function* () {
620
+ const provider = this.getProvider();
621
+ if (!provider) {
622
+ throw new Error(`${this.metadata.name} is not install!`);
623
+ }
624
+ const { sendBtcTransaction } = yield import("sats-connect");
625
+ const addresses = yield this.getAccounts();
626
+ if (addresses.length === 0) {
627
+ throw new Error(`${this.metadata.name} not connected!`);
628
+ }
629
+ const result = yield new Promise((resolve, reject) => {
630
+ const sendBtcOptions = {
631
+ payload: {
632
+ network: {
633
+ type: __privateGet(this, _network2)
634
+ },
635
+ recipients: [
636
+ {
637
+ address: toAddress,
638
+ amountSats: BigInt(satoshis)
639
+ }
640
+ ],
641
+ senderAddress: addresses[0]
642
+ },
643
+ onFinish: (response) => {
644
+ resolve(response);
645
+ },
646
+ onCancel: () => {
647
+ reject({
648
+ code: 4001,
649
+ message: "User rejected the request."
650
+ });
651
+ }
652
+ };
653
+ sendBtcTransaction(sendBtcOptions).catch((e) => reject(e));
654
+ });
655
+ return result;
656
+ });
657
+ }
658
+ disconnect() {
659
+ localStorage.removeItem("btc-connect-magicEden-addresses-Mainnet");
660
+ localStorage.removeItem("btc-connect-magicEden-addresses-Testnet");
661
+ }
662
+ };
663
+ _network2 = new WeakMap();
664
+ _event2 = new WeakMap();
665
+
462
666
  // src/context/index.tsx
463
667
  import { SmartAccount } from "@particle-network/aa";
464
668
  import { chains as chains4 } from "@particle-network/chains";
@@ -579,8 +783,8 @@ var EthereumProvider = class {
579
783
  };
580
784
 
581
785
  // src/utils/eventUtils.ts
582
- import { EventEmitter as EventEmitter2 } from "events";
583
- var events = new EventEmitter2();
786
+ import { EventEmitter as EventEmitter3 } from "events";
787
+ var events = new EventEmitter3();
584
788
  events.setMaxListeners(100);
585
789
  var getPendingSignEventAccount = () => {
586
790
  return events.listenerCount("sendUserOpResult" /* sendUserOpResult */) + events.listenerCount("personalSignResult" /* personalSignResult */) + events.listenerCount("signTypedDataResult" /* signTypedDataResult */);
@@ -1643,7 +1847,7 @@ var signModal_default = SignModal;
1643
1847
  // src/evmSigner/index.ts
1644
1848
  import { intToHex as intToHex2 } from "@ethereumjs/util";
1645
1849
  import { chains as chains3 } from "@particle-network/chains";
1646
- import { EventEmitter as EventEmitter3 } from "events";
1850
+ import { EventEmitter as EventEmitter4 } from "events";
1647
1851
  import {
1648
1852
  InvalidParamsRpcError,
1649
1853
  SwitchChainError,
@@ -1674,7 +1878,7 @@ var AASignerProvider = class {
1674
1878
  transport: http(rpcUrl)
1675
1879
  });
1676
1880
  };
1677
- this.events = new EventEmitter3();
1881
+ this.events = new EventEmitter4();
1678
1882
  this.events.setMaxListeners(100);
1679
1883
  if (typeof window !== "undefined") {
1680
1884
  const localChainId = localStorage.getItem("connect-evm-chain-id");
@@ -2127,11 +2331,16 @@ function ComfirmBox({ onClose, status = 1, fromChain = {
2127
2331
  import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
2128
2332
  var WalletSelectorContext = React.createContext(null);
2129
2333
  function BtcWalletSelectorContextProvider({
2130
- children,
2131
- autoConnect = false
2334
+ children
2132
2335
  }) {
2133
2336
  const [isProcessing, setIsProcessing] = useState8(false);
2134
- const connectors = [new UnisatConnector(), new XverseConnector()];
2337
+ const connectors = [
2338
+ new UnisatConnector(),
2339
+ new XverseConnector(),
2340
+ new OKXConnector(),
2341
+ new BitgetConnector(),
2342
+ new MagicEdenConnector()
2343
+ ];
2135
2344
  const walletSelectorContextValue = useMemo6(() => {
2136
2345
  const simpleFn = {};
2137
2346
  return {
@@ -3063,7 +3272,7 @@ function executeBurrowSupply(_0) {
3063
3272
 
3064
3273
  // src/index.ts
3065
3274
  var getVersion = () => {
3066
- return "0.3.0";
3275
+ return "0.3.2";
3067
3276
  };
3068
3277
  if (typeof window !== "undefined") {
3069
3278
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
@@ -3075,6 +3284,7 @@ export {
3075
3284
  BybitConnector,
3076
3285
  ConnectProvider,
3077
3286
  InjectedConnector,
3287
+ MagicEdenConnector,
3078
3288
  OKXConnector,
3079
3289
  TokenPocketConnector,
3080
3290
  UnisatConnector,