btc-wallet 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connector/magicEden.d.ts +21 -4
- package/dist/index.js +198 -10
- package/dist/index.js.map +3 -3
- package/esm/index.js +198 -10
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
@@ -1,6 +1,23 @@
|
|
1
|
-
import
|
2
|
-
import {
|
3
|
-
export declare class MagicEdenConnector extends
|
4
|
-
|
1
|
+
import EventEmitter from 'events';
|
2
|
+
import { BaseConnector, type WalletMetadata } from './base';
|
3
|
+
export declare class MagicEdenConnector extends BaseConnector {
|
4
|
+
#private;
|
5
5
|
constructor();
|
6
|
+
readonly metadata: WalletMetadata;
|
7
|
+
isReady(): boolean;
|
8
|
+
private loadAccounts;
|
9
|
+
sendInscription(): Promise<{
|
10
|
+
txid: string;
|
11
|
+
}>;
|
12
|
+
requestAccounts(): Promise<string[]>;
|
13
|
+
getAccounts(): Promise<string[]>;
|
14
|
+
getPublicKey(): Promise<string>;
|
15
|
+
signMessage(signStr: string): Promise<string>;
|
16
|
+
on(event: string, handler: (data?: unknown) => void): EventEmitter<[never]>;
|
17
|
+
removeListener(event: string, handler: (data?: unknown) => void): EventEmitter<[never]>;
|
18
|
+
getProvider(): any;
|
19
|
+
getNetwork(): Promise<'livenet' | 'testnet'>;
|
20
|
+
switchNetwork(): Promise<void>;
|
21
|
+
sendBitcoin(toAddress: string, satoshis: number): Promise<string>;
|
22
|
+
disconnect(): void;
|
6
23
|
}
|
package/dist/index.js
CHANGED
@@ -509,21 +509,209 @@ var XverseConnector = class extends BaseConnector {
|
|
509
509
|
_network = new WeakMap();
|
510
510
|
_event = new WeakMap();
|
511
511
|
|
512
|
+
// src/connector/magicEden.ts
|
513
|
+
var import_events2 = __toESM(require("events"), 1);
|
514
|
+
|
512
515
|
// src/icons/magicEden.png
|
513
516
|
var magicEden_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADYAAAAgCAYAAABZyotbAAADGklEQVR42sVYTW7aQBT+Z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icEden.ts
|
516
|
-
var
|
519
|
+
var _network2, _event2;
|
520
|
+
var MagicEdenConnector = class extends BaseConnector {
|
517
521
|
constructor() {
|
518
|
-
super(
|
522
|
+
super();
|
523
|
+
__privateAdd(this, _network2, "Mainnet");
|
524
|
+
__privateAdd(this, _event2, new import_events2.default());
|
519
525
|
this.metadata = {
|
520
|
-
id: "
|
521
|
-
name: "
|
526
|
+
id: "magicEden",
|
527
|
+
name: "Magic Eden Wallet",
|
522
528
|
icon: magicEden_default,
|
523
|
-
downloadUrl: "https://
|
529
|
+
downloadUrl: "https://www.magiceden.io"
|
524
530
|
};
|
531
|
+
this.loadAccounts = (network) => __async(this, null, function* () {
|
532
|
+
const { getAddress, AddressPurpose } = yield import("sats-connect");
|
533
|
+
const addresses = yield new Promise((resolve, reject) => {
|
534
|
+
const getAddressOptions = {
|
535
|
+
payload: {
|
536
|
+
purposes: [AddressPurpose.Payment, AddressPurpose.Ordinals],
|
537
|
+
message: "Address for receiving Ordinals and payments",
|
538
|
+
network: {
|
539
|
+
type: network
|
540
|
+
}
|
541
|
+
},
|
542
|
+
onFinish: (response) => {
|
543
|
+
resolve(response.addresses);
|
544
|
+
},
|
545
|
+
onCancel: () => reject({
|
546
|
+
code: 4001,
|
547
|
+
message: "User rejected the request."
|
548
|
+
})
|
549
|
+
};
|
550
|
+
getAddress(getAddressOptions).catch((error) => reject(error));
|
551
|
+
});
|
552
|
+
localStorage.setItem("btc-connect-magicEden-addresses-" + network, JSON.stringify(addresses));
|
553
|
+
return addresses;
|
554
|
+
});
|
555
|
+
__privateGet(this, _event2).setMaxListeners(100);
|
556
|
+
}
|
557
|
+
isReady() {
|
558
|
+
return typeof window !== "undefined" && "magicEden" in window && !!window.magicEden;
|
559
|
+
}
|
560
|
+
sendInscription() {
|
561
|
+
return __async(this, null, function* () {
|
562
|
+
throw new Error("Unsupported");
|
563
|
+
});
|
564
|
+
}
|
565
|
+
requestAccounts() {
|
566
|
+
return __async(this, null, function* () {
|
567
|
+
if (!this.isReady()) {
|
568
|
+
throw new Error(`${this.metadata.name} is not install!`);
|
569
|
+
}
|
570
|
+
const addresses = yield this.loadAccounts(__privateGet(this, _network2));
|
571
|
+
return addresses.map((item) => item.address);
|
572
|
+
});
|
573
|
+
}
|
574
|
+
getAccounts() {
|
575
|
+
return __async(this, null, function* () {
|
576
|
+
if (!this.isReady()) {
|
577
|
+
throw new Error(`${this.metadata.name} is not install!`);
|
578
|
+
}
|
579
|
+
const data = localStorage.getItem("btc-connect-magicEden-addresses-" + __privateGet(this, _network2));
|
580
|
+
if (data) {
|
581
|
+
const addresses = JSON.parse(data);
|
582
|
+
return addresses.map((item) => item.address);
|
583
|
+
} else {
|
584
|
+
return [];
|
585
|
+
}
|
586
|
+
});
|
587
|
+
}
|
588
|
+
getPublicKey() {
|
589
|
+
return __async(this, null, function* () {
|
590
|
+
if (!this.isReady()) {
|
591
|
+
throw new Error(`${this.metadata.name} is not install!`);
|
592
|
+
}
|
593
|
+
const data = localStorage.getItem("btc-connect-magicEden-addresses-" + __privateGet(this, _network2));
|
594
|
+
if (data) {
|
595
|
+
const addresses = JSON.parse(data);
|
596
|
+
return addresses[0].publicKey;
|
597
|
+
} else {
|
598
|
+
return "";
|
599
|
+
}
|
600
|
+
});
|
601
|
+
}
|
602
|
+
signMessage(signStr) {
|
603
|
+
return __async(this, null, function* () {
|
604
|
+
if (!this.isReady()) {
|
605
|
+
throw new Error(`${this.metadata.name} is not install!`);
|
606
|
+
}
|
607
|
+
const addresses = yield this.getAccounts();
|
608
|
+
if (addresses.length === 0) {
|
609
|
+
throw new Error(`${this.metadata.name} not connected!`);
|
610
|
+
}
|
611
|
+
const { signMessage } = yield import("sats-connect");
|
612
|
+
const sig = yield new Promise((resolve, reject) => {
|
613
|
+
const signMessageOptions = {
|
614
|
+
payload: {
|
615
|
+
network: {
|
616
|
+
type: __privateGet(this, _network2)
|
617
|
+
},
|
618
|
+
address: addresses[0],
|
619
|
+
message: signStr
|
620
|
+
},
|
621
|
+
onFinish: (response) => {
|
622
|
+
resolve(response);
|
623
|
+
},
|
624
|
+
onCancel: () => {
|
625
|
+
reject({
|
626
|
+
code: 4001,
|
627
|
+
message: "User rejected the request."
|
628
|
+
});
|
629
|
+
}
|
630
|
+
};
|
631
|
+
signMessage(signMessageOptions).catch((e) => {
|
632
|
+
reject(e);
|
633
|
+
});
|
634
|
+
});
|
635
|
+
const modifiedSig = Buffer.from(sig, "base64");
|
636
|
+
modifiedSig[0] = 31 + (modifiedSig[0] - 31) % 4;
|
637
|
+
return modifiedSig.toString("base64");
|
638
|
+
});
|
639
|
+
}
|
640
|
+
on(event, handler) {
|
641
|
+
return __privateGet(this, _event2).on(event, handler);
|
642
|
+
}
|
643
|
+
removeListener(event, handler) {
|
644
|
+
return __privateGet(this, _event2).removeListener(event, handler);
|
645
|
+
}
|
646
|
+
getProvider() {
|
647
|
+
if (this.isReady()) {
|
648
|
+
if ("magicEden" in window) {
|
649
|
+
const anyWindow = window;
|
650
|
+
if (anyWindow.magicEden.bitcoin && anyWindow.magicEden.bitcoin.isMagicEden)
|
651
|
+
return anyWindow.magicEden.bitcoin;
|
652
|
+
}
|
653
|
+
}
|
654
|
+
}
|
655
|
+
getNetwork() {
|
656
|
+
return __async(this, null, function* () {
|
657
|
+
if (!this.isReady()) {
|
658
|
+
throw new Error(`${this.metadata.name} is not install!`);
|
659
|
+
}
|
660
|
+
return __privateGet(this, _network2) === "Mainnet" ? "livenet" : "testnet";
|
661
|
+
});
|
662
|
+
}
|
663
|
+
switchNetwork() {
|
664
|
+
return __async(this, null, function* () {
|
665
|
+
throw new Error("Unsupported");
|
666
|
+
});
|
667
|
+
}
|
668
|
+
sendBitcoin(toAddress, satoshis) {
|
669
|
+
return __async(this, null, function* () {
|
670
|
+
const provider = this.getProvider();
|
671
|
+
if (!provider) {
|
672
|
+
throw new Error(`${this.metadata.name} is not install!`);
|
673
|
+
}
|
674
|
+
const { sendBtcTransaction } = yield import("sats-connect");
|
675
|
+
const addresses = yield this.getAccounts();
|
676
|
+
if (addresses.length === 0) {
|
677
|
+
throw new Error(`${this.metadata.name} not connected!`);
|
678
|
+
}
|
679
|
+
const result = yield new Promise((resolve, reject) => {
|
680
|
+
const sendBtcOptions = {
|
681
|
+
payload: {
|
682
|
+
network: {
|
683
|
+
type: __privateGet(this, _network2)
|
684
|
+
},
|
685
|
+
recipients: [
|
686
|
+
{
|
687
|
+
address: toAddress,
|
688
|
+
amountSats: BigInt(satoshis)
|
689
|
+
}
|
690
|
+
],
|
691
|
+
senderAddress: addresses[0]
|
692
|
+
},
|
693
|
+
onFinish: (response) => {
|
694
|
+
resolve(response);
|
695
|
+
},
|
696
|
+
onCancel: () => {
|
697
|
+
reject({
|
698
|
+
code: 4001,
|
699
|
+
message: "User rejected the request."
|
700
|
+
});
|
701
|
+
}
|
702
|
+
};
|
703
|
+
sendBtcTransaction(sendBtcOptions).catch((e) => reject(e));
|
704
|
+
});
|
705
|
+
return result;
|
706
|
+
});
|
707
|
+
}
|
708
|
+
disconnect() {
|
709
|
+
localStorage.removeItem("btc-connect-magicEden-addresses-Mainnet");
|
710
|
+
localStorage.removeItem("btc-connect-magicEden-addresses-Testnet");
|
525
711
|
}
|
526
712
|
};
|
713
|
+
_network2 = new WeakMap();
|
714
|
+
_event2 = new WeakMap();
|
527
715
|
|
528
716
|
// src/context/index.tsx
|
529
717
|
var import_aa = require("@particle-network/aa");
|
@@ -645,8 +833,8 @@ var EthereumProvider = class {
|
|
645
833
|
};
|
646
834
|
|
647
835
|
// src/utils/eventUtils.ts
|
648
|
-
var
|
649
|
-
var events = new
|
836
|
+
var import_events3 = require("events");
|
837
|
+
var events = new import_events3.EventEmitter();
|
650
838
|
events.setMaxListeners(100);
|
651
839
|
var getPendingSignEventAccount = () => {
|
652
840
|
return events.listenerCount("sendUserOpResult" /* sendUserOpResult */) + events.listenerCount("personalSignResult" /* personalSignResult */) + events.listenerCount("signTypedDataResult" /* signTypedDataResult */);
|
@@ -1703,7 +1891,7 @@ var signModal_default = SignModal;
|
|
1703
1891
|
// src/evmSigner/index.ts
|
1704
1892
|
var import_util3 = require("@ethereumjs/util");
|
1705
1893
|
var import_chains3 = require("@particle-network/chains");
|
1706
|
-
var
|
1894
|
+
var import_events4 = require("events");
|
1707
1895
|
var import_viem4 = require("viem");
|
1708
1896
|
var AASignerProvider = class {
|
1709
1897
|
constructor(supportChainIds, projectId, clientKey, rpcUrls) {
|
@@ -1726,7 +1914,7 @@ var AASignerProvider = class {
|
|
1726
1914
|
transport: (0, import_viem4.http)(rpcUrl)
|
1727
1915
|
});
|
1728
1916
|
};
|
1729
|
-
this.events = new
|
1917
|
+
this.events = new import_events4.EventEmitter();
|
1730
1918
|
this.events.setMaxListeners(100);
|
1731
1919
|
if (typeof window !== "undefined") {
|
1732
1920
|
const localChainId = localStorage.getItem("connect-evm-chain-id");
|
@@ -3120,7 +3308,7 @@ function executeBurrowSupply(_0) {
|
|
3120
3308
|
|
3121
3309
|
// src/index.ts
|
3122
3310
|
var getVersion = () => {
|
3123
|
-
return "0.3.
|
3311
|
+
return "0.3.2";
|
3124
3312
|
};
|
3125
3313
|
if (typeof window !== "undefined") {
|
3126
3314
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|