btc-wallet 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
package/esm/index.js CHANGED
@@ -459,21 +459,209 @@ 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
+
462
465
  // src/icons/magicEden.png
463
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=";
464
467
 
465
468
  // src/connector/magicEden.ts
466
- var MagicEdenConnector = class extends InjectedConnector {
469
+ var _network2, _event2;
470
+ var MagicEdenConnector = class extends BaseConnector {
467
471
  constructor() {
468
- super("magicEden.bitcoin");
472
+ super();
473
+ __privateAdd(this, _network2, "Mainnet");
474
+ __privateAdd(this, _event2, new EventEmitter2());
469
475
  this.metadata = {
470
- id: "magic-eden",
471
- name: "MagicEden Wallet",
476
+ id: "magicEden",
477
+ name: "Magic Eden Wallet",
472
478
  icon: magicEden_default,
473
- downloadUrl: "https://wallet.magiceden.io/"
479
+ downloadUrl: "https://www.magiceden.io"
474
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");
475
661
  }
476
662
  };
663
+ _network2 = new WeakMap();
664
+ _event2 = new WeakMap();
477
665
 
478
666
  // src/context/index.tsx
479
667
  import { SmartAccount } from "@particle-network/aa";
@@ -595,8 +783,8 @@ var EthereumProvider = class {
595
783
  };
596
784
 
597
785
  // src/utils/eventUtils.ts
598
- import { EventEmitter as EventEmitter2 } from "events";
599
- var events = new EventEmitter2();
786
+ import { EventEmitter as EventEmitter3 } from "events";
787
+ var events = new EventEmitter3();
600
788
  events.setMaxListeners(100);
601
789
  var getPendingSignEventAccount = () => {
602
790
  return events.listenerCount("sendUserOpResult" /* sendUserOpResult */) + events.listenerCount("personalSignResult" /* personalSignResult */) + events.listenerCount("signTypedDataResult" /* signTypedDataResult */);
@@ -1659,7 +1847,7 @@ var signModal_default = SignModal;
1659
1847
  // src/evmSigner/index.ts
1660
1848
  import { intToHex as intToHex2 } from "@ethereumjs/util";
1661
1849
  import { chains as chains3 } from "@particle-network/chains";
1662
- import { EventEmitter as EventEmitter3 } from "events";
1850
+ import { EventEmitter as EventEmitter4 } from "events";
1663
1851
  import {
1664
1852
  InvalidParamsRpcError,
1665
1853
  SwitchChainError,
@@ -1690,7 +1878,7 @@ var AASignerProvider = class {
1690
1878
  transport: http(rpcUrl)
1691
1879
  });
1692
1880
  };
1693
- this.events = new EventEmitter3();
1881
+ this.events = new EventEmitter4();
1694
1882
  this.events.setMaxListeners(100);
1695
1883
  if (typeof window !== "undefined") {
1696
1884
  const localChainId = localStorage.getItem("connect-evm-chain-id");
@@ -2839,18 +3027,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2839
3027
  near_transactions: newTransactions.map((t) => t.txHex),
2840
3028
  gas_token: currentConfig.token,
2841
3029
  gas_limit: "3000",
2842
- use_near_pay_gas: false,
2843
3030
  nonce
2844
3031
  };
2845
- const nearAccount = yield provider.query({
2846
- request_type: "view_account",
2847
- account_id: accountId,
2848
- finality: "final"
2849
- });
2850
- const availableBalance = parseFloat(nearAccount.amount) / __pow(10, 24);
2851
- if (availableBalance > 0.2) {
2852
- intention.use_near_pay_gas = true;
2853
- }
2854
3032
  const strIntention = JSON.stringify(intention);
2855
3033
  const signature = yield btcContext.signMessage(strIntention);
2856
3034
  const result = yield uploadBTCTx(currentConfig.base_url, {
@@ -2873,10 +3051,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2873
3051
  const checkAndSetupWalletButton = () => {
2874
3052
  const accountId = state.getAccount();
2875
3053
  const btcContext = window.btcContext;
2876
- console.log("checkAndSetupWalletButton:", {
2877
- nearAccountId: accountId,
2878
- btcAccountId: btcContext.account
2879
- });
2880
3054
  if (accountId && btcContext.account) {
2881
3055
  setupWalletButton(network, wallet2, btcContext);
2882
3056
  } else {
@@ -3084,7 +3258,7 @@ function executeBurrowSupply(_0) {
3084
3258
 
3085
3259
  // src/index.ts
3086
3260
  var getVersion = () => {
3087
- return "0.3.1";
3261
+ return "0.3.3";
3088
3262
  };
3089
3263
  if (typeof window !== "undefined") {
3090
3264
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();