btc-wallet 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +63 -22
- package/dist/index.js.map +3 -3
- package/esm/index.js +63 -22
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -133,6 +133,7 @@ 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);
|
136
137
|
return accounts;
|
137
138
|
});
|
138
139
|
}
|
@@ -698,6 +699,7 @@ var WalletClientProvider = class {
|
|
698
699
|
}
|
699
700
|
}
|
700
701
|
if (method === "personal_sign" /* personalSign */) {
|
702
|
+
console.log("personal_sign ---- ", arg);
|
701
703
|
return new Promise((resolve, reject) => {
|
702
704
|
eventUtils_default.emit("personalSign" /* personalSign */, arg);
|
703
705
|
eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
|
@@ -1003,6 +1005,7 @@ var ConnectModal = ({ open, onClose }) => {
|
|
1003
1005
|
yield connect(connector.metadata.id);
|
1004
1006
|
closeConnectModal();
|
1005
1007
|
} catch (error) {
|
1008
|
+
console.error("onConnect error", error);
|
1006
1009
|
if (error.code === 4001) {
|
1007
1010
|
setRetryVisible(true);
|
1008
1011
|
}
|
@@ -1545,10 +1548,13 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1545
1548
|
}), [userOpBundle, smartAccount, accountContract]);
|
1546
1549
|
(0, import_react8.useEffect)(() => {
|
1547
1550
|
if (userOpBundle && open) {
|
1551
|
+
console.log("deserializeUserOp start");
|
1548
1552
|
setDeserializeLoading(true);
|
1549
1553
|
deserializeUserOp().then((result) => {
|
1554
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
|
1550
1555
|
setDeserializeResult(result);
|
1551
1556
|
}).catch((error) => {
|
1557
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
|
1552
1558
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1553
1559
|
error
|
1554
1560
|
});
|
@@ -1559,6 +1565,7 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1559
1565
|
(0, import_react8.useEffect)(() => {
|
1560
1566
|
if (open && publicClient && evmAccount && userOpBundle) {
|
1561
1567
|
publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
|
1568
|
+
console.log("\u{1F680} ~ getBalance ~ error:", error);
|
1562
1569
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1563
1570
|
error
|
1564
1571
|
});
|
@@ -1723,6 +1730,7 @@ var AASignerProvider = class {
|
|
1723
1730
|
this.getPublicClient = () => {
|
1724
1731
|
var _a, _b;
|
1725
1732
|
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);
|
1726
1734
|
return (0, import_viem4.createPublicClient)({
|
1727
1735
|
transport: (0, import_viem4.http)(rpcUrl)
|
1728
1736
|
});
|
@@ -1757,8 +1765,10 @@ var AASignerProvider = class {
|
|
1757
1765
|
return `0x${this.chainId.toString(16)}`;
|
1758
1766
|
} else if (arg.method === "personal_sign" /* personalSign */) {
|
1759
1767
|
let message = (_a = arg.params) == null ? void 0 : _a[0];
|
1768
|
+
console.log("personal_sign message:", message);
|
1760
1769
|
if (message.length !== 66) {
|
1761
1770
|
const hash = (0, import_viem4.hashMessage)({ raw: message });
|
1771
|
+
console.log("personal_sign hash:", hash);
|
1762
1772
|
message = hash;
|
1763
1773
|
}
|
1764
1774
|
const result = yield this.personalSign(message || "");
|
@@ -1766,15 +1776,19 @@ var AASignerProvider = class {
|
|
1766
1776
|
if (!convertResult) {
|
1767
1777
|
throw new Error("sign error");
|
1768
1778
|
}
|
1779
|
+
console.log(`personal_sign result(${convertResult.length}): `, convertResult);
|
1769
1780
|
return convertResult;
|
1770
1781
|
} else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
|
1771
1782
|
const typedData = (_b = arg.params) == null ? void 0 : _b[1];
|
1783
|
+
console.log("signTypedData typedData", typedData);
|
1772
1784
|
const hash = (0, import_viem4.hashTypedData)(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
|
1785
|
+
console.log("signTypedData hash", hash);
|
1773
1786
|
const result = yield this.personalSign(hash || "");
|
1774
1787
|
const convertResult = convertSignature(result);
|
1775
1788
|
if (!convertResult) {
|
1776
1789
|
throw new Error("sign error");
|
1777
1790
|
}
|
1791
|
+
console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
|
1778
1792
|
return convertResult;
|
1779
1793
|
} else if (arg.method === "wallet_switchEthereumChain") {
|
1780
1794
|
if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
|
@@ -1946,6 +1960,7 @@ var ConnectProvider = ({
|
|
1946
1960
|
setEVMAccount(res);
|
1947
1961
|
}).catch((e) => {
|
1948
1962
|
setEVMAccount(void 0);
|
1963
|
+
console.error("smartAccount getAddress error", e);
|
1949
1964
|
});
|
1950
1965
|
} else {
|
1951
1966
|
setEVMAccount(void 0);
|
@@ -1967,6 +1982,7 @@ var ConnectProvider = ({
|
|
1967
1982
|
const requestAccount = (0, import_react10.useCallback)(
|
1968
1983
|
(connector2) => __async(void 0, null, function* () {
|
1969
1984
|
let accounts2 = yield connector2.getAccounts();
|
1985
|
+
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1970
1986
|
if (accounts2.length === 0 && autoConnect) {
|
1971
1987
|
accounts2 = yield connector2.requestAccounts();
|
1972
1988
|
}
|
@@ -1976,7 +1992,9 @@ var ConnectProvider = ({
|
|
1976
1992
|
);
|
1977
1993
|
const requestDirectAccount = (0, import_react10.useCallback)(
|
1978
1994
|
(connector2) => __async(void 0, null, function* () {
|
1995
|
+
console.log(111);
|
1979
1996
|
let accounts2 = yield connector2.getAccounts();
|
1997
|
+
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1980
1998
|
if (accounts2.length === 0) {
|
1981
1999
|
accounts2 = yield connector2.requestAccounts();
|
1982
2000
|
}
|
@@ -1988,6 +2006,7 @@ var ConnectProvider = ({
|
|
1988
2006
|
(0, import_react10.useEffect)(() => {
|
1989
2007
|
if (connector) {
|
1990
2008
|
requestAccount(connector).catch((e) => {
|
2009
|
+
console.log("get account error", e);
|
1991
2010
|
setAccounts([]);
|
1992
2011
|
});
|
1993
2012
|
} else {
|
@@ -2043,6 +2062,7 @@ var ConnectProvider = ({
|
|
2043
2062
|
})
|
2044
2063
|
})
|
2045
2064
|
);
|
2065
|
+
console.log("walletEntryPlugin init");
|
2046
2066
|
}
|
2047
2067
|
}, [options, evmSupportChainIds, accountContract]);
|
2048
2068
|
(0, import_react10.useEffect)(() => {
|
@@ -2051,6 +2071,7 @@ var ConnectProvider = ({
|
|
2051
2071
|
import_wallet.walletEntryPlugin.setWalletCore({
|
2052
2072
|
ethereum: smartAccount.provider
|
2053
2073
|
});
|
2074
|
+
console.log("walletEntryPlugin setWalletCore");
|
2054
2075
|
}
|
2055
2076
|
}, [smartAccount, options]);
|
2056
2077
|
(0, import_react10.useEffect)(() => {
|
@@ -2058,8 +2079,10 @@ var ConnectProvider = ({
|
|
2058
2079
|
if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
|
2059
2080
|
if (evmAccount) {
|
2060
2081
|
import_wallet.walletEntryPlugin.walletEntryCreate();
|
2082
|
+
console.log("walletEntryPlugin walletEntryCreate");
|
2061
2083
|
} else {
|
2062
2084
|
import_wallet.walletEntryPlugin.walletEntryDestroy();
|
2085
|
+
console.log("walletEntryPlugin walletEntryDestroy");
|
2063
2086
|
}
|
2064
2087
|
}
|
2065
2088
|
}, [evmAccount, smartAccount, options]);
|
@@ -2358,6 +2381,7 @@ var import_js_sha256 = require("js-sha256");
|
|
2358
2381
|
|
2359
2382
|
// src/utils/initWalletButton.ts
|
2360
2383
|
function setupWalletButton(network, wallet, originalWallet) {
|
2384
|
+
console.log("setupWalletButton");
|
2361
2385
|
if (document.getElementById("satoshi-wallet-button")) {
|
2362
2386
|
return;
|
2363
2387
|
}
|
@@ -2404,6 +2428,9 @@ function createFloatingButtonWithIframe({
|
|
2404
2428
|
iframe.style.display = isCurrentlyVisible ? "none" : "block";
|
2405
2429
|
button.src = isCurrentlyVisible ? openImageUrl : closeImageUrl;
|
2406
2430
|
localStorage.setItem("iframeVisible", String(!isCurrentlyVisible));
|
2431
|
+
setTimeout(() => {
|
2432
|
+
iframe.focus();
|
2433
|
+
}, 0);
|
2407
2434
|
};
|
2408
2435
|
return button;
|
2409
2436
|
}
|
@@ -2415,9 +2442,6 @@ function createIframe({
|
|
2415
2442
|
iframe.id = "satoshi-wallet-iframe";
|
2416
2443
|
iframe.allow = "clipboard-read; clipboard-write";
|
2417
2444
|
iframe.src = iframeUrl;
|
2418
|
-
iframe.onclick = () => {
|
2419
|
-
iframe.focus();
|
2420
|
-
};
|
2421
2445
|
Object.assign(iframe.style, __spreadValues({
|
2422
2446
|
position: "fixed",
|
2423
2447
|
bottom: "90px",
|
@@ -2436,20 +2460,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2436
2460
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2437
2461
|
const originalAccountId = originalWallet.account;
|
2438
2462
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2463
|
+
console.log({ accountId, originalAccountId, originalPublicKey });
|
2439
2464
|
const iframeSrc = new URL(iframe.src);
|
2440
2465
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2441
2466
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2442
2467
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2443
2468
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2444
2469
|
iframe.src = iframeSrc.toString();
|
2470
|
+
console.log("iframe src", iframe.src);
|
2445
2471
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2446
2472
|
var _a2, _b;
|
2447
2473
|
if (event.origin !== iframeSrc.origin)
|
2448
2474
|
return;
|
2449
2475
|
const { action, requestId, data } = event.data;
|
2450
2476
|
if (action === "signAndSendTransaction") {
|
2477
|
+
console.log("signAndSendTransaction message", event.data);
|
2451
2478
|
try {
|
2452
2479
|
const result = yield wallet.signAndSendTransaction(data);
|
2480
|
+
console.log("signAndSendTransaction result", result);
|
2453
2481
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2454
2482
|
{
|
2455
2483
|
requestId,
|
@@ -2459,6 +2487,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2459
2487
|
{ targetOrigin: event.origin }
|
2460
2488
|
);
|
2461
2489
|
} catch (error) {
|
2490
|
+
console.error("signAndSendTransaction error", error);
|
2462
2491
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2463
2492
|
{
|
2464
2493
|
requestId,
|
@@ -2550,6 +2579,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2550
2579
|
signAndSendTransaction,
|
2551
2580
|
signAndSendTransactions
|
2552
2581
|
};
|
2582
|
+
initWalletButton(options.network.networkId, wallet);
|
2553
2583
|
if (!inter) {
|
2554
2584
|
inter = setInterval(() => __async(void 0, null, function* () {
|
2555
2585
|
const btcContext = window.btcContext;
|
@@ -2558,6 +2588,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2558
2588
|
const context = btcContext.getContext();
|
2559
2589
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2560
2590
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2591
|
+
console.info("accountsChanged:", nearTempAddress, btcContext.account);
|
2561
2592
|
emitter.emit("accountsChanged", {
|
2562
2593
|
accounts: [
|
2563
2594
|
{
|
@@ -2571,6 +2602,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2571
2602
|
accounts: []
|
2572
2603
|
});
|
2573
2604
|
}));
|
2605
|
+
console.log("metadata.autoConnect:", metadata);
|
2574
2606
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2575
2607
|
yield btcContext.autoConnect();
|
2576
2608
|
}
|
@@ -2578,7 +2610,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2578
2610
|
}
|
2579
2611
|
}), 500);
|
2580
2612
|
}
|
2581
|
-
initWalletButton(options.network.networkId, state.getAccount(), wallet);
|
2582
2613
|
function viewMethod(_02) {
|
2583
2614
|
return __async(this, arguments, function* ({ method, args = {} }) {
|
2584
2615
|
const res = yield provider.query({
|
@@ -2604,7 +2635,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2604
2635
|
state.saveAccount(nearTempAddress);
|
2605
2636
|
state.savePublicKey(nearTempPublicKey);
|
2606
2637
|
state.saveBtcPublicKey(btcPublicKey);
|
2607
|
-
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2608
2638
|
return {
|
2609
2639
|
nearTempAddress,
|
2610
2640
|
nearTempPublicKey
|
@@ -2613,6 +2643,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2613
2643
|
}
|
2614
2644
|
function signIn(_02) {
|
2615
2645
|
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
2646
|
+
console.log(provider);
|
2616
2647
|
const accountId = state.getAccount();
|
2617
2648
|
const publicKey = state.getPublicKey();
|
2618
2649
|
const btcContext = window.btcContext;
|
@@ -2718,6 +2749,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2718
2749
|
txBytes,
|
2719
2750
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2720
2751
|
).join("");
|
2752
|
+
console.log("txHex:", txHex);
|
2721
2753
|
const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
|
2722
2754
|
return { txBytes, txHex, hash };
|
2723
2755
|
});
|
@@ -2742,8 +2774,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2742
2774
|
btcPubKey: state.getBtcPublicKey(),
|
2743
2775
|
data: toHex(strIntention)
|
2744
2776
|
});
|
2777
|
+
console.log("result:", result);
|
2745
2778
|
if (result.result_code === 0) {
|
2746
2779
|
const hash = newTransactions.map((t) => t.hash);
|
2780
|
+
console.log("txHash:", hash);
|
2747
2781
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2748
2782
|
return result2;
|
2749
2783
|
} else {
|
@@ -2751,6 +2785,26 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2751
2785
|
}
|
2752
2786
|
});
|
2753
2787
|
}
|
2788
|
+
function initWalletButton(network, wallet2) {
|
2789
|
+
return __async(this, null, function* () {
|
2790
|
+
console.log("initWalletButton:", network, wallet2);
|
2791
|
+
const checkAndSetupWalletButton = () => {
|
2792
|
+
const accountId = state.getAccount();
|
2793
|
+
const btcContext = window.btcContext;
|
2794
|
+
console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
|
2795
|
+
if (accountId && btcContext.account) {
|
2796
|
+
setupWalletButton(network, wallet2, btcContext);
|
2797
|
+
} else {
|
2798
|
+
removeWalletButton();
|
2799
|
+
!btcContext.account && setTimeout(() => {
|
2800
|
+
checkAndSetupWalletButton();
|
2801
|
+
}, 5e3);
|
2802
|
+
}
|
2803
|
+
};
|
2804
|
+
yield delay(1e3);
|
2805
|
+
checkAndSetupWalletButton();
|
2806
|
+
});
|
2807
|
+
}
|
2754
2808
|
return wallet;
|
2755
2809
|
});
|
2756
2810
|
function getNonceFromApi(network, accountId) {
|
@@ -2809,22 +2863,6 @@ function toHex(originalString) {
|
|
2809
2863
|
hexString = hexString.replace(/(^0+)/g, "");
|
2810
2864
|
return hexString;
|
2811
2865
|
}
|
2812
|
-
function initWalletButton(network, accountId, wallet) {
|
2813
|
-
return __async(this, null, function* () {
|
2814
|
-
yield delay(1e3);
|
2815
|
-
const checkAndSetupWalletButton = () => {
|
2816
|
-
if (accountId && window.btcContext.account) {
|
2817
|
-
setupWalletButton(network, wallet, window.btcContext);
|
2818
|
-
} else {
|
2819
|
-
removeWalletButton();
|
2820
|
-
!window.btcContext.account && setTimeout(() => {
|
2821
|
-
checkAndSetupWalletButton();
|
2822
|
-
}, 5e3);
|
2823
|
-
}
|
2824
|
-
};
|
2825
|
-
checkAndSetupWalletButton();
|
2826
|
-
});
|
2827
|
-
}
|
2828
2866
|
var rcpUrls = {
|
2829
2867
|
mainnet: [
|
2830
2868
|
"https://near.lava.build",
|
@@ -2853,14 +2891,17 @@ function pollTransactionStatuses(network, hashes) {
|
|
2853
2891
|
try {
|
2854
2892
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2855
2893
|
if (result && result.status) {
|
2894
|
+
console.log(`Transaction ${hash} result:`, result);
|
2856
2895
|
return result;
|
2857
2896
|
}
|
2858
2897
|
} catch (error) {
|
2898
|
+
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2859
2899
|
}
|
2860
2900
|
if (attempt === maxAttempts) {
|
2861
2901
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2862
2902
|
}
|
2863
2903
|
yield delay(1e4);
|
2904
|
+
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2864
2905
|
}
|
2865
2906
|
});
|
2866
2907
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2870,7 +2911,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2870
2911
|
|
2871
2912
|
// src/index.ts
|
2872
2913
|
var getVersion = () => {
|
2873
|
-
return "0.1.
|
2914
|
+
return "0.1.3";
|
2874
2915
|
};
|
2875
2916
|
if (typeof window !== "undefined") {
|
2876
2917
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|