btc-wallet 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +63 -21
- package/dist/index.js.map +3 -3
- package/esm/index.js +63 -21
- 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
|
}
|
@@ -2433,20 +2460,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2433
2460
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2434
2461
|
const originalAccountId = originalWallet.account;
|
2435
2462
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2463
|
+
console.log({ accountId, originalAccountId, originalPublicKey });
|
2436
2464
|
const iframeSrc = new URL(iframe.src);
|
2437
2465
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2438
2466
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2439
2467
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2440
2468
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2441
2469
|
iframe.src = iframeSrc.toString();
|
2470
|
+
console.log("iframe src", iframe.src);
|
2442
2471
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2443
2472
|
var _a2, _b;
|
2444
2473
|
if (event.origin !== iframeSrc.origin)
|
2445
2474
|
return;
|
2446
2475
|
const { action, requestId, data } = event.data;
|
2447
2476
|
if (action === "signAndSendTransaction") {
|
2477
|
+
console.log("signAndSendTransaction message", event.data);
|
2448
2478
|
try {
|
2449
2479
|
const result = yield wallet.signAndSendTransaction(data);
|
2480
|
+
console.log("signAndSendTransaction result", result);
|
2450
2481
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2451
2482
|
{
|
2452
2483
|
requestId,
|
@@ -2456,6 +2487,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2456
2487
|
{ targetOrigin: event.origin }
|
2457
2488
|
);
|
2458
2489
|
} catch (error) {
|
2490
|
+
console.error("signAndSendTransaction error", error);
|
2459
2491
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2460
2492
|
{
|
2461
2493
|
requestId,
|
@@ -2547,17 +2579,16 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2547
2579
|
signAndSendTransaction,
|
2548
2580
|
signAndSendTransactions
|
2549
2581
|
};
|
2582
|
+
initWalletButton(options.network.networkId, wallet);
|
2550
2583
|
if (!inter) {
|
2551
2584
|
inter = setInterval(() => __async(void 0, null, function* () {
|
2552
2585
|
const btcContext = window.btcContext;
|
2553
2586
|
if (btcContext) {
|
2554
2587
|
clearInterval(inter);
|
2555
2588
|
const context = btcContext.getContext();
|
2556
|
-
const accountId = state.getAccount();
|
2557
|
-
initWalletButton(options.network.networkId, accountId, wallet);
|
2558
2589
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2559
2590
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2560
|
-
|
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
|
}
|
@@ -2611,6 +2643,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2611
2643
|
}
|
2612
2644
|
function signIn(_02) {
|
2613
2645
|
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
2646
|
+
console.log(provider);
|
2614
2647
|
const accountId = state.getAccount();
|
2615
2648
|
const publicKey = state.getPublicKey();
|
2616
2649
|
const btcContext = window.btcContext;
|
@@ -2625,7 +2658,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2625
2658
|
const btcAccount = yield btcContext.login();
|
2626
2659
|
const btcPublicKey = yield btcContext.getPublicKey();
|
2627
2660
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2628
|
-
initWalletButton(options.network.networkId, accountId, wallet);
|
2629
2661
|
return [
|
2630
2662
|
{
|
2631
2663
|
accountId: nearTempAddress,
|
@@ -2717,6 +2749,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2717
2749
|
txBytes,
|
2718
2750
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2719
2751
|
).join("");
|
2752
|
+
console.log("txHex:", txHex);
|
2720
2753
|
const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
|
2721
2754
|
return { txBytes, txHex, hash };
|
2722
2755
|
});
|
@@ -2741,8 +2774,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2741
2774
|
btcPubKey: state.getBtcPublicKey(),
|
2742
2775
|
data: toHex(strIntention)
|
2743
2776
|
});
|
2777
|
+
console.log("result:", result);
|
2744
2778
|
if (result.result_code === 0) {
|
2745
2779
|
const hash = newTransactions.map((t) => t.hash);
|
2780
|
+
console.log("txHash:", hash);
|
2746
2781
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2747
2782
|
return result2;
|
2748
2783
|
} else {
|
@@ -2750,6 +2785,26 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2750
2785
|
}
|
2751
2786
|
});
|
2752
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
|
+
}
|
2753
2808
|
return wallet;
|
2754
2809
|
});
|
2755
2810
|
function getNonceFromApi(network, accountId) {
|
@@ -2808,22 +2863,6 @@ function toHex(originalString) {
|
|
2808
2863
|
hexString = hexString.replace(/(^0+)/g, "");
|
2809
2864
|
return hexString;
|
2810
2865
|
}
|
2811
|
-
function initWalletButton(network, accountId, wallet) {
|
2812
|
-
return __async(this, null, function* () {
|
2813
|
-
yield delay(1e3);
|
2814
|
-
const checkAndSetupWalletButton = () => {
|
2815
|
-
if (accountId && window.btcContext.account) {
|
2816
|
-
setupWalletButton(network, wallet, window.btcContext);
|
2817
|
-
} else {
|
2818
|
-
removeWalletButton();
|
2819
|
-
!window.btcContext.account && setTimeout(() => {
|
2820
|
-
checkAndSetupWalletButton();
|
2821
|
-
}, 5e3);
|
2822
|
-
}
|
2823
|
-
};
|
2824
|
-
checkAndSetupWalletButton();
|
2825
|
-
});
|
2826
|
-
}
|
2827
2866
|
var rcpUrls = {
|
2828
2867
|
mainnet: [
|
2829
2868
|
"https://near.lava.build",
|
@@ -2852,14 +2891,17 @@ function pollTransactionStatuses(network, hashes) {
|
|
2852
2891
|
try {
|
2853
2892
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2854
2893
|
if (result && result.status) {
|
2894
|
+
console.log(`Transaction ${hash} result:`, result);
|
2855
2895
|
return result;
|
2856
2896
|
}
|
2857
2897
|
} catch (error) {
|
2898
|
+
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2858
2899
|
}
|
2859
2900
|
if (attempt === maxAttempts) {
|
2860
2901
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2861
2902
|
}
|
2862
2903
|
yield delay(1e4);
|
2904
|
+
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2863
2905
|
}
|
2864
2906
|
});
|
2865
2907
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2869,7 +2911,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2869
2911
|
|
2870
2912
|
// src/index.ts
|
2871
2913
|
var getVersion = () => {
|
2872
|
-
return "0.1.
|
2914
|
+
return "0.1.3";
|
2873
2915
|
};
|
2874
2916
|
if (typeof window !== "undefined") {
|
2875
2917
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|