btc-wallet 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +7 -45
- package/dist/index.js.map +2 -2
- package/esm/index.js +7 -45
- 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
|
}
|
@@ -2350,10 +2326,12 @@ function setupWalletButton(network, wallet, originalWallet) {
|
|
2350
2326
|
});
|
2351
2327
|
iframe.addEventListener("mouseenter", () => {
|
2352
2328
|
var _a;
|
2353
|
-
(
|
2354
|
-
|
2355
|
-
|
2356
|
-
|
2329
|
+
if (document.activeElement !== iframe) {
|
2330
|
+
(_a = document.activeElement) == null ? void 0 : _a.setAttribute("tabindex", "null");
|
2331
|
+
setTimeout(() => {
|
2332
|
+
iframe.focus();
|
2333
|
+
}, 0);
|
2334
|
+
}
|
2357
2335
|
});
|
2358
2336
|
const button = createFloatingButtonWithIframe({
|
2359
2337
|
openImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn.png",
|
@@ -2426,24 +2404,20 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2426
2404
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2427
2405
|
const originalAccountId = originalWallet.account;
|
2428
2406
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2429
|
-
console.log({ accountId, originalAccountId, originalPublicKey });
|
2430
2407
|
const iframeSrc = new URL(iframe.src);
|
2431
2408
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2432
2409
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2433
2410
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2434
2411
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2435
2412
|
iframe.src = iframeSrc.toString();
|
2436
|
-
console.log("iframe src", iframe.src);
|
2437
2413
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2438
2414
|
var _a2, _b;
|
2439
2415
|
if (event.origin !== iframeSrc.origin)
|
2440
2416
|
return;
|
2441
2417
|
const { action, requestId, data } = event.data;
|
2442
2418
|
if (action === "signAndSendTransaction") {
|
2443
|
-
console.log("signAndSendTransaction message", event.data);
|
2444
2419
|
try {
|
2445
2420
|
const result = yield wallet.signAndSendTransaction(data);
|
2446
|
-
console.log("signAndSendTransaction result", result);
|
2447
2421
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2448
2422
|
{
|
2449
2423
|
requestId,
|
@@ -2453,7 +2427,6 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2453
2427
|
{ targetOrigin: event.origin }
|
2454
2428
|
);
|
2455
2429
|
} catch (error) {
|
2456
|
-
console.error("signAndSendTransaction error", error);
|
2457
2430
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2458
2431
|
{
|
2459
2432
|
requestId,
|
@@ -2554,7 +2527,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2554
2527
|
const context = btcContext.getContext();
|
2555
2528
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2556
2529
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2557
|
-
console.info("accountsChanged:", nearTempAddress, btcContext.account);
|
2558
2530
|
emitter.emit("accountsChanged", {
|
2559
2531
|
accounts: [
|
2560
2532
|
{
|
@@ -2568,7 +2540,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2568
2540
|
accounts: []
|
2569
2541
|
});
|
2570
2542
|
}));
|
2571
|
-
console.log("metadata.autoConnect:", metadata);
|
2572
2543
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2573
2544
|
yield btcContext.autoConnect();
|
2574
2545
|
}
|
@@ -2609,7 +2580,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2609
2580
|
}
|
2610
2581
|
function signIn(_02) {
|
2611
2582
|
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
2612
|
-
console.log(provider);
|
2613
2583
|
const accountId = state.getAccount();
|
2614
2584
|
const publicKey = state.getPublicKey();
|
2615
2585
|
const btcContext = window.btcContext;
|
@@ -2715,7 +2685,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2715
2685
|
txBytes,
|
2716
2686
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2717
2687
|
).join("");
|
2718
|
-
console.log("txHex:", txHex);
|
2719
2688
|
const hash = bs58.encode(new Uint8Array(sha256.array(txBytes)));
|
2720
2689
|
return { txBytes, txHex, hash };
|
2721
2690
|
});
|
@@ -2740,10 +2709,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2740
2709
|
btcPubKey: state.getBtcPublicKey(),
|
2741
2710
|
data: toHex(strIntention)
|
2742
2711
|
});
|
2743
|
-
console.log("result:", result);
|
2744
2712
|
if (result.result_code === 0) {
|
2745
2713
|
const hash = newTransactions.map((t) => t.hash);
|
2746
|
-
console.log("txHash:", hash);
|
2747
2714
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2748
2715
|
return result2;
|
2749
2716
|
} else {
|
@@ -2753,11 +2720,9 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2753
2720
|
}
|
2754
2721
|
function initWalletButton(network, wallet2) {
|
2755
2722
|
return __async(this, null, function* () {
|
2756
|
-
console.log("initWalletButton:", network, wallet2);
|
2757
2723
|
const checkAndSetupWalletButton = () => {
|
2758
2724
|
const accountId = state.getAccount();
|
2759
2725
|
const btcContext = window.btcContext;
|
2760
|
-
console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
|
2761
2726
|
if (accountId && btcContext.account) {
|
2762
2727
|
setupWalletButton(network, wallet2, btcContext);
|
2763
2728
|
} else {
|
@@ -2857,17 +2822,14 @@ function pollTransactionStatuses(network, hashes) {
|
|
2857
2822
|
try {
|
2858
2823
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2859
2824
|
if (result && result.status) {
|
2860
|
-
console.log(`Transaction ${hash} result:`, result);
|
2861
2825
|
return result;
|
2862
2826
|
}
|
2863
2827
|
} catch (error) {
|
2864
|
-
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2865
2828
|
}
|
2866
2829
|
if (attempt === maxAttempts) {
|
2867
2830
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2868
2831
|
}
|
2869
2832
|
yield delay(1e4);
|
2870
|
-
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2871
2833
|
}
|
2872
2834
|
});
|
2873
2835
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2877,7 +2839,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2877
2839
|
|
2878
2840
|
// src/index.ts
|
2879
2841
|
var getVersion = () => {
|
2880
|
-
return "0.1.
|
2842
|
+
return "0.1.5";
|
2881
2843
|
};
|
2882
2844
|
if (typeof window !== "undefined") {
|
2883
2845
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|