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/dist/connector/index.d.ts +1 -0
- package/dist/connector/magicEden.d.ts +23 -0
- package/dist/core/btcWalletSelectorContext.d.ts +1 -1
- package/dist/index.js +218 -8
- package/dist/index.js.map +4 -4
- package/esm/index.js +218 -8
- package/esm/index.js.map +4 -4
- package/package.json +1 -1
@@ -0,0 +1,23 @@
|
|
1
|
+
import EventEmitter from 'events';
|
2
|
+
import { BaseConnector, type WalletMetadata } from './base';
|
3
|
+
export declare class MagicEdenConnector extends BaseConnector {
|
4
|
+
#private;
|
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;
|
23
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
export declare function BtcWalletSelectorContextProvider({ children,
|
2
|
+
export declare function BtcWalletSelectorContextProvider({ children, }: {
|
3
3
|
children: React.ReactNode;
|
4
4
|
autoConnect?: boolean;
|
5
5
|
}): import("react/jsx-runtime").JSX.Element;
|
package/dist/index.js
CHANGED
@@ -84,6 +84,7 @@ __export(src_exports, {
|
|
84
84
|
BybitConnector: () => BybitConnector,
|
85
85
|
ConnectProvider: () => ConnectProvider,
|
86
86
|
InjectedConnector: () => InjectedConnector,
|
87
|
+
MagicEdenConnector: () => MagicEdenConnector,
|
87
88
|
OKXConnector: () => OKXConnector,
|
88
89
|
TokenPocketConnector: () => TokenPocketConnector,
|
89
90
|
UnisatConnector: () => UnisatConnector,
|
@@ -508,6 +509,210 @@ var XverseConnector = class extends BaseConnector {
|
|
508
509
|
_network = new WeakMap();
|
509
510
|
_event = new WeakMap();
|
510
511
|
|
512
|
+
// src/connector/magicEden.ts
|
513
|
+
var import_events2 = __toESM(require("events"), 1);
|
514
|
+
|
515
|
+
// src/icons/magicEden.png
|
516
|
+
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=";
|
517
|
+
|
518
|
+
// src/connector/magicEden.ts
|
519
|
+
var _network2, _event2;
|
520
|
+
var MagicEdenConnector = class extends BaseConnector {
|
521
|
+
constructor() {
|
522
|
+
super();
|
523
|
+
__privateAdd(this, _network2, "Mainnet");
|
524
|
+
__privateAdd(this, _event2, new import_events2.default());
|
525
|
+
this.metadata = {
|
526
|
+
id: "magicEden",
|
527
|
+
name: "Magic Eden Wallet",
|
528
|
+
icon: magicEden_default,
|
529
|
+
downloadUrl: "https://www.magiceden.io"
|
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");
|
711
|
+
}
|
712
|
+
};
|
713
|
+
_network2 = new WeakMap();
|
714
|
+
_event2 = new WeakMap();
|
715
|
+
|
511
716
|
// src/context/index.tsx
|
512
717
|
var import_aa = require("@particle-network/aa");
|
513
718
|
var import_chains4 = require("@particle-network/chains");
|
@@ -628,8 +833,8 @@ var EthereumProvider = class {
|
|
628
833
|
};
|
629
834
|
|
630
835
|
// src/utils/eventUtils.ts
|
631
|
-
var
|
632
|
-
var events = new
|
836
|
+
var import_events3 = require("events");
|
837
|
+
var events = new import_events3.EventEmitter();
|
633
838
|
events.setMaxListeners(100);
|
634
839
|
var getPendingSignEventAccount = () => {
|
635
840
|
return events.listenerCount("sendUserOpResult" /* sendUserOpResult */) + events.listenerCount("personalSignResult" /* personalSignResult */) + events.listenerCount("signTypedDataResult" /* signTypedDataResult */);
|
@@ -1686,7 +1891,7 @@ var signModal_default = SignModal;
|
|
1686
1891
|
// src/evmSigner/index.ts
|
1687
1892
|
var import_util3 = require("@ethereumjs/util");
|
1688
1893
|
var import_chains3 = require("@particle-network/chains");
|
1689
|
-
var
|
1894
|
+
var import_events4 = require("events");
|
1690
1895
|
var import_viem4 = require("viem");
|
1691
1896
|
var AASignerProvider = class {
|
1692
1897
|
constructor(supportChainIds, projectId, clientKey, rpcUrls) {
|
@@ -1709,7 +1914,7 @@ var AASignerProvider = class {
|
|
1709
1914
|
transport: (0, import_viem4.http)(rpcUrl)
|
1710
1915
|
});
|
1711
1916
|
};
|
1712
|
-
this.events = new
|
1917
|
+
this.events = new import_events4.EventEmitter();
|
1713
1918
|
this.events.setMaxListeners(100);
|
1714
1919
|
if (typeof window !== "undefined") {
|
1715
1920
|
const localChainId = localStorage.getItem("connect-evm-chain-id");
|
@@ -2162,11 +2367,16 @@ function ComfirmBox({ onClose, status = 1, fromChain = {
|
|
2162
2367
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
2163
2368
|
var WalletSelectorContext = import_react11.default.createContext(null);
|
2164
2369
|
function BtcWalletSelectorContextProvider({
|
2165
|
-
children
|
2166
|
-
autoConnect = false
|
2370
|
+
children
|
2167
2371
|
}) {
|
2168
2372
|
const [isProcessing, setIsProcessing] = (0, import_react11.useState)(false);
|
2169
|
-
const connectors = [
|
2373
|
+
const connectors = [
|
2374
|
+
new UnisatConnector(),
|
2375
|
+
new XverseConnector(),
|
2376
|
+
new OKXConnector(),
|
2377
|
+
new BitgetConnector(),
|
2378
|
+
new MagicEdenConnector()
|
2379
|
+
];
|
2170
2380
|
const walletSelectorContextValue = (0, import_react11.useMemo)(() => {
|
2171
2381
|
const simpleFn = {};
|
2172
2382
|
return {
|
@@ -3098,7 +3308,7 @@ function executeBurrowSupply(_0) {
|
|
3098
3308
|
|
3099
3309
|
// src/index.ts
|
3100
3310
|
var getVersion = () => {
|
3101
|
-
return "0.3.
|
3311
|
+
return "0.3.2";
|
3102
3312
|
};
|
3103
3313
|
if (typeof window !== "undefined") {
|
3104
3314
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|