btc-wallet 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +10 -41
- package/dist/index.js.map +2 -2
- package/esm/index.js +10 -41
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/esm/index.js
CHANGED
@@ -84,7 +84,6 @@ var InjectedConnector = class extends BaseConnector {
|
|
84
84
|
requestAccounts() {
|
85
85
|
return __async(this, null, function* () {
|
86
86
|
const accounts = yield this.getProviderOrThrow().requestAccounts();
|
87
|
-
console.log("\u{1F680} ~ InjectedConnector ~ requestAccounts ~ accounts:", accounts);
|
88
87
|
return accounts;
|
89
88
|
});
|
90
89
|
}
|
@@ -650,7 +649,6 @@ var WalletClientProvider = class {
|
|
650
649
|
}
|
651
650
|
}
|
652
651
|
if (method === "personal_sign" /* personalSign */) {
|
653
|
-
console.log("personal_sign ---- ", arg);
|
654
652
|
return new Promise((resolve, reject) => {
|
655
653
|
eventUtils_default.emit("personalSign" /* personalSign */, arg);
|
656
654
|
eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
|
@@ -956,7 +954,6 @@ var ConnectModal = ({ open, onClose }) => {
|
|
956
954
|
yield connect(connector.metadata.id);
|
957
955
|
closeConnectModal();
|
958
956
|
} catch (error) {
|
959
|
-
console.error("onConnect error", error);
|
960
957
|
if (error.code === 4001) {
|
961
958
|
setRetryVisible(true);
|
962
959
|
}
|
@@ -1499,13 +1496,10 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1499
1496
|
}), [userOpBundle, smartAccount, accountContract]);
|
1500
1497
|
useEffect4(() => {
|
1501
1498
|
if (userOpBundle && open) {
|
1502
|
-
console.log("deserializeUserOp start");
|
1503
1499
|
setDeserializeLoading(true);
|
1504
1500
|
deserializeUserOp().then((result) => {
|
1505
|
-
console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
|
1506
1501
|
setDeserializeResult(result);
|
1507
1502
|
}).catch((error) => {
|
1508
|
-
console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
|
1509
1503
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1510
1504
|
error
|
1511
1505
|
});
|
@@ -1516,7 +1510,6 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1516
1510
|
useEffect4(() => {
|
1517
1511
|
if (open && publicClient && evmAccount && userOpBundle) {
|
1518
1512
|
publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
|
1519
|
-
console.log("\u{1F680} ~ getBalance ~ error:", error);
|
1520
1513
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1521
1514
|
error
|
1522
1515
|
});
|
@@ -1689,7 +1682,6 @@ var AASignerProvider = class {
|
|
1689
1682
|
this.getPublicClient = () => {
|
1690
1683
|
var _a, _b;
|
1691
1684
|
const rpcUrl = ((_a = this == null ? void 0 : this.rpcUrls) == null ? void 0 : _a[this.chainId]) || ((_b = chains3.getEVMChainInfoById(this.chainId || 1)) == null ? void 0 : _b.rpcUrl);
|
1692
|
-
console.log("rpcUrl", rpcUrl);
|
1693
1685
|
return createPublicClient({
|
1694
1686
|
transport: http(rpcUrl)
|
1695
1687
|
});
|
@@ -1724,10 +1716,8 @@ var AASignerProvider = class {
|
|
1724
1716
|
return `0x${this.chainId.toString(16)}`;
|
1725
1717
|
} else if (arg.method === "personal_sign" /* personalSign */) {
|
1726
1718
|
let message = (_a = arg.params) == null ? void 0 : _a[0];
|
1727
|
-
console.log("personal_sign message:", message);
|
1728
1719
|
if (message.length !== 66) {
|
1729
1720
|
const hash = hashMessage({ raw: message });
|
1730
|
-
console.log("personal_sign hash:", hash);
|
1731
1721
|
message = hash;
|
1732
1722
|
}
|
1733
1723
|
const result = yield this.personalSign(message || "");
|
@@ -1735,19 +1725,15 @@ var AASignerProvider = class {
|
|
1735
1725
|
if (!convertResult) {
|
1736
1726
|
throw new Error("sign error");
|
1737
1727
|
}
|
1738
|
-
console.log(`personal_sign result(${convertResult.length}): `, convertResult);
|
1739
1728
|
return convertResult;
|
1740
1729
|
} else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
|
1741
1730
|
const typedData = (_b = arg.params) == null ? void 0 : _b[1];
|
1742
|
-
console.log("signTypedData typedData", typedData);
|
1743
1731
|
const hash = hashTypedData(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
|
1744
|
-
console.log("signTypedData hash", hash);
|
1745
1732
|
const result = yield this.personalSign(hash || "");
|
1746
1733
|
const convertResult = convertSignature(result);
|
1747
1734
|
if (!convertResult) {
|
1748
1735
|
throw new Error("sign error");
|
1749
1736
|
}
|
1750
|
-
console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
|
1751
1737
|
return convertResult;
|
1752
1738
|
} else if (arg.method === "wallet_switchEthereumChain") {
|
1753
1739
|
if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
|
@@ -1919,7 +1905,6 @@ var ConnectProvider = ({
|
|
1919
1905
|
setEVMAccount(res);
|
1920
1906
|
}).catch((e) => {
|
1921
1907
|
setEVMAccount(void 0);
|
1922
|
-
console.error("smartAccount getAddress error", e);
|
1923
1908
|
});
|
1924
1909
|
} else {
|
1925
1910
|
setEVMAccount(void 0);
|
@@ -1941,7 +1926,6 @@ var ConnectProvider = ({
|
|
1941
1926
|
const requestAccount = useCallback7(
|
1942
1927
|
(connector2) => __async(void 0, null, function* () {
|
1943
1928
|
let accounts2 = yield connector2.getAccounts();
|
1944
|
-
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1945
1929
|
if (accounts2.length === 0 && autoConnect) {
|
1946
1930
|
accounts2 = yield connector2.requestAccounts();
|
1947
1931
|
}
|
@@ -1951,9 +1935,7 @@ var ConnectProvider = ({
|
|
1951
1935
|
);
|
1952
1936
|
const requestDirectAccount = useCallback7(
|
1953
1937
|
(connector2) => __async(void 0, null, function* () {
|
1954
|
-
console.log(111);
|
1955
1938
|
let accounts2 = yield connector2.getAccounts();
|
1956
|
-
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1957
1939
|
if (accounts2.length === 0) {
|
1958
1940
|
accounts2 = yield connector2.requestAccounts();
|
1959
1941
|
}
|
@@ -1965,7 +1947,6 @@ var ConnectProvider = ({
|
|
1965
1947
|
useEffect5(() => {
|
1966
1948
|
if (connector) {
|
1967
1949
|
requestAccount(connector).catch((e) => {
|
1968
|
-
console.log("get account error", e);
|
1969
1950
|
setAccounts([]);
|
1970
1951
|
});
|
1971
1952
|
} else {
|
@@ -2021,7 +2002,6 @@ var ConnectProvider = ({
|
|
2021
2002
|
})
|
2022
2003
|
})
|
2023
2004
|
);
|
2024
|
-
console.log("walletEntryPlugin init");
|
2025
2005
|
}
|
2026
2006
|
}, [options, evmSupportChainIds, accountContract]);
|
2027
2007
|
useEffect5(() => {
|
@@ -2030,7 +2010,6 @@ var ConnectProvider = ({
|
|
2030
2010
|
walletEntryPlugin.setWalletCore({
|
2031
2011
|
ethereum: smartAccount.provider
|
2032
2012
|
});
|
2033
|
-
console.log("walletEntryPlugin setWalletCore");
|
2034
2013
|
}
|
2035
2014
|
}, [smartAccount, options]);
|
2036
2015
|
useEffect5(() => {
|
@@ -2038,10 +2017,8 @@ var ConnectProvider = ({
|
|
2038
2017
|
if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
|
2039
2018
|
if (evmAccount) {
|
2040
2019
|
walletEntryPlugin.walletEntryCreate();
|
2041
|
-
console.log("walletEntryPlugin walletEntryCreate");
|
2042
2020
|
} else {
|
2043
2021
|
walletEntryPlugin.walletEntryDestroy();
|
2044
|
-
console.log("walletEntryPlugin walletEntryDestroy");
|
2045
2022
|
}
|
2046
2023
|
}
|
2047
2024
|
}, [evmAccount, smartAccount, options]);
|
@@ -2340,7 +2317,6 @@ import { sha256 } from "js-sha256";
|
|
2340
2317
|
|
2341
2318
|
// src/utils/initWalletButton.ts
|
2342
2319
|
function setupWalletButton(network, wallet, originalWallet) {
|
2343
|
-
console.log("setupWalletButton");
|
2344
2320
|
if (document.getElementById("satoshi-wallet-button")) {
|
2345
2321
|
return;
|
2346
2322
|
}
|
@@ -2348,6 +2324,15 @@ function setupWalletButton(network, wallet, originalWallet) {
|
|
2348
2324
|
iframeUrl: network === "testnet" ? "https://wallet-dev.satoshibridge.top" : "https://wallet.satoshibridge.top",
|
2349
2325
|
iframeStyle: { width: "400px", height: "650px" }
|
2350
2326
|
});
|
2327
|
+
iframe.addEventListener("mouseenter", () => {
|
2328
|
+
var _a;
|
2329
|
+
if (document.activeElement !== iframe) {
|
2330
|
+
(_a = document.activeElement) == null ? void 0 : _a.setAttribute("tabindex", "null");
|
2331
|
+
setTimeout(() => {
|
2332
|
+
iframe.focus();
|
2333
|
+
}, 0);
|
2334
|
+
}
|
2335
|
+
});
|
2351
2336
|
const button = createFloatingButtonWithIframe({
|
2352
2337
|
openImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn.png",
|
2353
2338
|
closeImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn-active.png",
|
@@ -2419,24 +2404,20 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2419
2404
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2420
2405
|
const originalAccountId = originalWallet.account;
|
2421
2406
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2422
|
-
console.log({ accountId, originalAccountId, originalPublicKey });
|
2423
2407
|
const iframeSrc = new URL(iframe.src);
|
2424
2408
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2425
2409
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2426
2410
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2427
2411
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2428
2412
|
iframe.src = iframeSrc.toString();
|
2429
|
-
console.log("iframe src", iframe.src);
|
2430
2413
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2431
2414
|
var _a2, _b;
|
2432
2415
|
if (event.origin !== iframeSrc.origin)
|
2433
2416
|
return;
|
2434
2417
|
const { action, requestId, data } = event.data;
|
2435
2418
|
if (action === "signAndSendTransaction") {
|
2436
|
-
console.log("signAndSendTransaction message", event.data);
|
2437
2419
|
try {
|
2438
2420
|
const result = yield wallet.signAndSendTransaction(data);
|
2439
|
-
console.log("signAndSendTransaction result", result);
|
2440
2421
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2441
2422
|
{
|
2442
2423
|
requestId,
|
@@ -2446,7 +2427,6 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2446
2427
|
{ targetOrigin: event.origin }
|
2447
2428
|
);
|
2448
2429
|
} catch (error) {
|
2449
|
-
console.error("signAndSendTransaction error", error);
|
2450
2430
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2451
2431
|
{
|
2452
2432
|
requestId,
|
@@ -2547,7 +2527,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2547
2527
|
const context = btcContext.getContext();
|
2548
2528
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2549
2529
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2550
|
-
console.info("accountsChanged:", nearTempAddress, btcContext.account);
|
2551
2530
|
emitter.emit("accountsChanged", {
|
2552
2531
|
accounts: [
|
2553
2532
|
{
|
@@ -2561,7 +2540,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2561
2540
|
accounts: []
|
2562
2541
|
});
|
2563
2542
|
}));
|
2564
|
-
console.log("metadata.autoConnect:", metadata);
|
2565
2543
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2566
2544
|
yield btcContext.autoConnect();
|
2567
2545
|
}
|
@@ -2602,7 +2580,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2602
2580
|
}
|
2603
2581
|
function signIn(_02) {
|
2604
2582
|
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
2605
|
-
console.log(provider);
|
2606
2583
|
const accountId = state.getAccount();
|
2607
2584
|
const publicKey = state.getPublicKey();
|
2608
2585
|
const btcContext = window.btcContext;
|
@@ -2708,7 +2685,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2708
2685
|
txBytes,
|
2709
2686
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2710
2687
|
).join("");
|
2711
|
-
console.log("txHex:", txHex);
|
2712
2688
|
const hash = bs58.encode(new Uint8Array(sha256.array(txBytes)));
|
2713
2689
|
return { txBytes, txHex, hash };
|
2714
2690
|
});
|
@@ -2733,10 +2709,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2733
2709
|
btcPubKey: state.getBtcPublicKey(),
|
2734
2710
|
data: toHex(strIntention)
|
2735
2711
|
});
|
2736
|
-
console.log("result:", result);
|
2737
2712
|
if (result.result_code === 0) {
|
2738
2713
|
const hash = newTransactions.map((t) => t.hash);
|
2739
|
-
console.log("txHash:", hash);
|
2740
2714
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2741
2715
|
return result2;
|
2742
2716
|
} else {
|
@@ -2746,11 +2720,9 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2746
2720
|
}
|
2747
2721
|
function initWalletButton(network, wallet2) {
|
2748
2722
|
return __async(this, null, function* () {
|
2749
|
-
console.log("initWalletButton:", network, wallet2);
|
2750
2723
|
const checkAndSetupWalletButton = () => {
|
2751
2724
|
const accountId = state.getAccount();
|
2752
2725
|
const btcContext = window.btcContext;
|
2753
|
-
console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
|
2754
2726
|
if (accountId && btcContext.account) {
|
2755
2727
|
setupWalletButton(network, wallet2, btcContext);
|
2756
2728
|
} else {
|
@@ -2850,17 +2822,14 @@ function pollTransactionStatuses(network, hashes) {
|
|
2850
2822
|
try {
|
2851
2823
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2852
2824
|
if (result && result.status) {
|
2853
|
-
console.log(`Transaction ${hash} result:`, result);
|
2854
2825
|
return result;
|
2855
2826
|
}
|
2856
2827
|
} catch (error) {
|
2857
|
-
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2858
2828
|
}
|
2859
2829
|
if (attempt === maxAttempts) {
|
2860
2830
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2861
2831
|
}
|
2862
2832
|
yield delay(1e4);
|
2863
|
-
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2864
2833
|
}
|
2865
2834
|
});
|
2866
2835
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2870,7 +2839,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2870
2839
|
|
2871
2840
|
// src/index.ts
|
2872
2841
|
var getVersion = () => {
|
2873
|
-
return "0.1.
|
2842
|
+
return "0.1.5";
|
2874
2843
|
};
|
2875
2844
|
if (typeof window !== "undefined") {
|
2876
2845
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|