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/dist/index.js
CHANGED
@@ -133,7 +133,6 @@ var InjectedConnector = class extends BaseConnector {
|
|
133
133
|
requestAccounts() {
|
134
134
|
return __async(this, null, function* () {
|
135
135
|
const accounts = yield this.getProviderOrThrow().requestAccounts();
|
136
|
-
console.log("\u{1F680} ~ InjectedConnector ~ requestAccounts ~ accounts:", accounts);
|
137
136
|
return accounts;
|
138
137
|
});
|
139
138
|
}
|
@@ -699,7 +698,6 @@ var WalletClientProvider = class {
|
|
699
698
|
}
|
700
699
|
}
|
701
700
|
if (method === "personal_sign" /* personalSign */) {
|
702
|
-
console.log("personal_sign ---- ", arg);
|
703
701
|
return new Promise((resolve, reject) => {
|
704
702
|
eventUtils_default.emit("personalSign" /* personalSign */, arg);
|
705
703
|
eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
|
@@ -1005,7 +1003,6 @@ var ConnectModal = ({ open, onClose }) => {
|
|
1005
1003
|
yield connect(connector.metadata.id);
|
1006
1004
|
closeConnectModal();
|
1007
1005
|
} catch (error) {
|
1008
|
-
console.error("onConnect error", error);
|
1009
1006
|
if (error.code === 4001) {
|
1010
1007
|
setRetryVisible(true);
|
1011
1008
|
}
|
@@ -1548,13 +1545,10 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1548
1545
|
}), [userOpBundle, smartAccount, accountContract]);
|
1549
1546
|
(0, import_react8.useEffect)(() => {
|
1550
1547
|
if (userOpBundle && open) {
|
1551
|
-
console.log("deserializeUserOp start");
|
1552
1548
|
setDeserializeLoading(true);
|
1553
1549
|
deserializeUserOp().then((result) => {
|
1554
|
-
console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
|
1555
1550
|
setDeserializeResult(result);
|
1556
1551
|
}).catch((error) => {
|
1557
|
-
console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
|
1558
1552
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1559
1553
|
error
|
1560
1554
|
});
|
@@ -1565,7 +1559,6 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1565
1559
|
(0, import_react8.useEffect)(() => {
|
1566
1560
|
if (open && publicClient && evmAccount && userOpBundle) {
|
1567
1561
|
publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
|
1568
|
-
console.log("\u{1F680} ~ getBalance ~ error:", error);
|
1569
1562
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1570
1563
|
error
|
1571
1564
|
});
|
@@ -1730,7 +1723,6 @@ var AASignerProvider = class {
|
|
1730
1723
|
this.getPublicClient = () => {
|
1731
1724
|
var _a, _b;
|
1732
1725
|
const rpcUrl = ((_a = this == null ? void 0 : this.rpcUrls) == null ? void 0 : _a[this.chainId]) || ((_b = import_chains3.chains.getEVMChainInfoById(this.chainId || 1)) == null ? void 0 : _b.rpcUrl);
|
1733
|
-
console.log("rpcUrl", rpcUrl);
|
1734
1726
|
return (0, import_viem4.createPublicClient)({
|
1735
1727
|
transport: (0, import_viem4.http)(rpcUrl)
|
1736
1728
|
});
|
@@ -1765,10 +1757,8 @@ var AASignerProvider = class {
|
|
1765
1757
|
return `0x${this.chainId.toString(16)}`;
|
1766
1758
|
} else if (arg.method === "personal_sign" /* personalSign */) {
|
1767
1759
|
let message = (_a = arg.params) == null ? void 0 : _a[0];
|
1768
|
-
console.log("personal_sign message:", message);
|
1769
1760
|
if (message.length !== 66) {
|
1770
1761
|
const hash = (0, import_viem4.hashMessage)({ raw: message });
|
1771
|
-
console.log("personal_sign hash:", hash);
|
1772
1762
|
message = hash;
|
1773
1763
|
}
|
1774
1764
|
const result = yield this.personalSign(message || "");
|
@@ -1776,19 +1766,15 @@ var AASignerProvider = class {
|
|
1776
1766
|
if (!convertResult) {
|
1777
1767
|
throw new Error("sign error");
|
1778
1768
|
}
|
1779
|
-
console.log(`personal_sign result(${convertResult.length}): `, convertResult);
|
1780
1769
|
return convertResult;
|
1781
1770
|
} else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
|
1782
1771
|
const typedData = (_b = arg.params) == null ? void 0 : _b[1];
|
1783
|
-
console.log("signTypedData typedData", typedData);
|
1784
1772
|
const hash = (0, import_viem4.hashTypedData)(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
|
1785
|
-
console.log("signTypedData hash", hash);
|
1786
1773
|
const result = yield this.personalSign(hash || "");
|
1787
1774
|
const convertResult = convertSignature(result);
|
1788
1775
|
if (!convertResult) {
|
1789
1776
|
throw new Error("sign error");
|
1790
1777
|
}
|
1791
|
-
console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
|
1792
1778
|
return convertResult;
|
1793
1779
|
} else if (arg.method === "wallet_switchEthereumChain") {
|
1794
1780
|
if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
|
@@ -1960,7 +1946,6 @@ var ConnectProvider = ({
|
|
1960
1946
|
setEVMAccount(res);
|
1961
1947
|
}).catch((e) => {
|
1962
1948
|
setEVMAccount(void 0);
|
1963
|
-
console.error("smartAccount getAddress error", e);
|
1964
1949
|
});
|
1965
1950
|
} else {
|
1966
1951
|
setEVMAccount(void 0);
|
@@ -1982,7 +1967,6 @@ var ConnectProvider = ({
|
|
1982
1967
|
const requestAccount = (0, import_react10.useCallback)(
|
1983
1968
|
(connector2) => __async(void 0, null, function* () {
|
1984
1969
|
let accounts2 = yield connector2.getAccounts();
|
1985
|
-
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1986
1970
|
if (accounts2.length === 0 && autoConnect) {
|
1987
1971
|
accounts2 = yield connector2.requestAccounts();
|
1988
1972
|
}
|
@@ -1992,9 +1976,7 @@ var ConnectProvider = ({
|
|
1992
1976
|
);
|
1993
1977
|
const requestDirectAccount = (0, import_react10.useCallback)(
|
1994
1978
|
(connector2) => __async(void 0, null, function* () {
|
1995
|
-
console.log(111);
|
1996
1979
|
let accounts2 = yield connector2.getAccounts();
|
1997
|
-
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1998
1980
|
if (accounts2.length === 0) {
|
1999
1981
|
accounts2 = yield connector2.requestAccounts();
|
2000
1982
|
}
|
@@ -2006,7 +1988,6 @@ var ConnectProvider = ({
|
|
2006
1988
|
(0, import_react10.useEffect)(() => {
|
2007
1989
|
if (connector) {
|
2008
1990
|
requestAccount(connector).catch((e) => {
|
2009
|
-
console.log("get account error", e);
|
2010
1991
|
setAccounts([]);
|
2011
1992
|
});
|
2012
1993
|
} else {
|
@@ -2062,7 +2043,6 @@ var ConnectProvider = ({
|
|
2062
2043
|
})
|
2063
2044
|
})
|
2064
2045
|
);
|
2065
|
-
console.log("walletEntryPlugin init");
|
2066
2046
|
}
|
2067
2047
|
}, [options, evmSupportChainIds, accountContract]);
|
2068
2048
|
(0, import_react10.useEffect)(() => {
|
@@ -2071,7 +2051,6 @@ var ConnectProvider = ({
|
|
2071
2051
|
import_wallet.walletEntryPlugin.setWalletCore({
|
2072
2052
|
ethereum: smartAccount.provider
|
2073
2053
|
});
|
2074
|
-
console.log("walletEntryPlugin setWalletCore");
|
2075
2054
|
}
|
2076
2055
|
}, [smartAccount, options]);
|
2077
2056
|
(0, import_react10.useEffect)(() => {
|
@@ -2079,10 +2058,8 @@ var ConnectProvider = ({
|
|
2079
2058
|
if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
|
2080
2059
|
if (evmAccount) {
|
2081
2060
|
import_wallet.walletEntryPlugin.walletEntryCreate();
|
2082
|
-
console.log("walletEntryPlugin walletEntryCreate");
|
2083
2061
|
} else {
|
2084
2062
|
import_wallet.walletEntryPlugin.walletEntryDestroy();
|
2085
|
-
console.log("walletEntryPlugin walletEntryDestroy");
|
2086
2063
|
}
|
2087
2064
|
}
|
2088
2065
|
}, [evmAccount, smartAccount, options]);
|
@@ -2381,7 +2358,6 @@ var import_js_sha256 = require("js-sha256");
|
|
2381
2358
|
|
2382
2359
|
// src/utils/initWalletButton.ts
|
2383
2360
|
function setupWalletButton(network, wallet, originalWallet) {
|
2384
|
-
console.log("setupWalletButton");
|
2385
2361
|
if (document.getElementById("satoshi-wallet-button")) {
|
2386
2362
|
return;
|
2387
2363
|
}
|
@@ -2391,10 +2367,12 @@ function setupWalletButton(network, wallet, originalWallet) {
|
|
2391
2367
|
});
|
2392
2368
|
iframe.addEventListener("mouseenter", () => {
|
2393
2369
|
var _a;
|
2394
|
-
(
|
2395
|
-
|
2396
|
-
|
2397
|
-
|
2370
|
+
if (document.activeElement !== iframe) {
|
2371
|
+
(_a = document.activeElement) == null ? void 0 : _a.setAttribute("tabindex", "null");
|
2372
|
+
setTimeout(() => {
|
2373
|
+
iframe.focus();
|
2374
|
+
}, 0);
|
2375
|
+
}
|
2398
2376
|
});
|
2399
2377
|
const button = createFloatingButtonWithIframe({
|
2400
2378
|
openImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn.png",
|
@@ -2467,24 +2445,20 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2467
2445
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2468
2446
|
const originalAccountId = originalWallet.account;
|
2469
2447
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2470
|
-
console.log({ accountId, originalAccountId, originalPublicKey });
|
2471
2448
|
const iframeSrc = new URL(iframe.src);
|
2472
2449
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2473
2450
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2474
2451
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2475
2452
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2476
2453
|
iframe.src = iframeSrc.toString();
|
2477
|
-
console.log("iframe src", iframe.src);
|
2478
2454
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2479
2455
|
var _a2, _b;
|
2480
2456
|
if (event.origin !== iframeSrc.origin)
|
2481
2457
|
return;
|
2482
2458
|
const { action, requestId, data } = event.data;
|
2483
2459
|
if (action === "signAndSendTransaction") {
|
2484
|
-
console.log("signAndSendTransaction message", event.data);
|
2485
2460
|
try {
|
2486
2461
|
const result = yield wallet.signAndSendTransaction(data);
|
2487
|
-
console.log("signAndSendTransaction result", result);
|
2488
2462
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2489
2463
|
{
|
2490
2464
|
requestId,
|
@@ -2494,7 +2468,6 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2494
2468
|
{ targetOrigin: event.origin }
|
2495
2469
|
);
|
2496
2470
|
} catch (error) {
|
2497
|
-
console.error("signAndSendTransaction error", error);
|
2498
2471
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2499
2472
|
{
|
2500
2473
|
requestId,
|
@@ -2595,7 +2568,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2595
2568
|
const context = btcContext.getContext();
|
2596
2569
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2597
2570
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2598
|
-
console.info("accountsChanged:", nearTempAddress, btcContext.account);
|
2599
2571
|
emitter.emit("accountsChanged", {
|
2600
2572
|
accounts: [
|
2601
2573
|
{
|
@@ -2609,7 +2581,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2609
2581
|
accounts: []
|
2610
2582
|
});
|
2611
2583
|
}));
|
2612
|
-
console.log("metadata.autoConnect:", metadata);
|
2613
2584
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2614
2585
|
yield btcContext.autoConnect();
|
2615
2586
|
}
|
@@ -2650,7 +2621,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2650
2621
|
}
|
2651
2622
|
function signIn(_02) {
|
2652
2623
|
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
2653
|
-
console.log(provider);
|
2654
2624
|
const accountId = state.getAccount();
|
2655
2625
|
const publicKey = state.getPublicKey();
|
2656
2626
|
const btcContext = window.btcContext;
|
@@ -2756,7 +2726,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2756
2726
|
txBytes,
|
2757
2727
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2758
2728
|
).join("");
|
2759
|
-
console.log("txHex:", txHex);
|
2760
2729
|
const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
|
2761
2730
|
return { txBytes, txHex, hash };
|
2762
2731
|
});
|
@@ -2781,10 +2750,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2781
2750
|
btcPubKey: state.getBtcPublicKey(),
|
2782
2751
|
data: toHex(strIntention)
|
2783
2752
|
});
|
2784
|
-
console.log("result:", result);
|
2785
2753
|
if (result.result_code === 0) {
|
2786
2754
|
const hash = newTransactions.map((t) => t.hash);
|
2787
|
-
console.log("txHash:", hash);
|
2788
2755
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2789
2756
|
return result2;
|
2790
2757
|
} else {
|
@@ -2794,11 +2761,9 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2794
2761
|
}
|
2795
2762
|
function initWalletButton(network, wallet2) {
|
2796
2763
|
return __async(this, null, function* () {
|
2797
|
-
console.log("initWalletButton:", network, wallet2);
|
2798
2764
|
const checkAndSetupWalletButton = () => {
|
2799
2765
|
const accountId = state.getAccount();
|
2800
2766
|
const btcContext = window.btcContext;
|
2801
|
-
console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
|
2802
2767
|
if (accountId && btcContext.account) {
|
2803
2768
|
setupWalletButton(network, wallet2, btcContext);
|
2804
2769
|
} else {
|
@@ -2898,17 +2863,14 @@ function pollTransactionStatuses(network, hashes) {
|
|
2898
2863
|
try {
|
2899
2864
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2900
2865
|
if (result && result.status) {
|
2901
|
-
console.log(`Transaction ${hash} result:`, result);
|
2902
2866
|
return result;
|
2903
2867
|
}
|
2904
2868
|
} catch (error) {
|
2905
|
-
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2906
2869
|
}
|
2907
2870
|
if (attempt === maxAttempts) {
|
2908
2871
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2909
2872
|
}
|
2910
2873
|
yield delay(1e4);
|
2911
|
-
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2912
2874
|
}
|
2913
2875
|
});
|
2914
2876
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2918,7 +2880,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2918
2880
|
|
2919
2881
|
// src/index.ts
|
2920
2882
|
var getVersion = () => {
|
2921
|
-
return "0.1.
|
2883
|
+
return "0.1.5";
|
2922
2884
|
};
|
2923
2885
|
if (typeof window !== "undefined") {
|
2924
2886
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|