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/esm/index.js
CHANGED
@@ -84,6 +84,7 @@ 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);
|
87
88
|
return accounts;
|
88
89
|
});
|
89
90
|
}
|
@@ -649,6 +650,7 @@ var WalletClientProvider = class {
|
|
649
650
|
}
|
650
651
|
}
|
651
652
|
if (method === "personal_sign" /* personalSign */) {
|
653
|
+
console.log("personal_sign ---- ", arg);
|
652
654
|
return new Promise((resolve, reject) => {
|
653
655
|
eventUtils_default.emit("personalSign" /* personalSign */, arg);
|
654
656
|
eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
|
@@ -954,6 +956,7 @@ var ConnectModal = ({ open, onClose }) => {
|
|
954
956
|
yield connect(connector.metadata.id);
|
955
957
|
closeConnectModal();
|
956
958
|
} catch (error) {
|
959
|
+
console.error("onConnect error", error);
|
957
960
|
if (error.code === 4001) {
|
958
961
|
setRetryVisible(true);
|
959
962
|
}
|
@@ -1496,10 +1499,13 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1496
1499
|
}), [userOpBundle, smartAccount, accountContract]);
|
1497
1500
|
useEffect4(() => {
|
1498
1501
|
if (userOpBundle && open) {
|
1502
|
+
console.log("deserializeUserOp start");
|
1499
1503
|
setDeserializeLoading(true);
|
1500
1504
|
deserializeUserOp().then((result) => {
|
1505
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
|
1501
1506
|
setDeserializeResult(result);
|
1502
1507
|
}).catch((error) => {
|
1508
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
|
1503
1509
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1504
1510
|
error
|
1505
1511
|
});
|
@@ -1510,6 +1516,7 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1510
1516
|
useEffect4(() => {
|
1511
1517
|
if (open && publicClient && evmAccount && userOpBundle) {
|
1512
1518
|
publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
|
1519
|
+
console.log("\u{1F680} ~ getBalance ~ error:", error);
|
1513
1520
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1514
1521
|
error
|
1515
1522
|
});
|
@@ -1682,6 +1689,7 @@ var AASignerProvider = class {
|
|
1682
1689
|
this.getPublicClient = () => {
|
1683
1690
|
var _a, _b;
|
1684
1691
|
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);
|
1685
1693
|
return createPublicClient({
|
1686
1694
|
transport: http(rpcUrl)
|
1687
1695
|
});
|
@@ -1716,8 +1724,10 @@ var AASignerProvider = class {
|
|
1716
1724
|
return `0x${this.chainId.toString(16)}`;
|
1717
1725
|
} else if (arg.method === "personal_sign" /* personalSign */) {
|
1718
1726
|
let message = (_a = arg.params) == null ? void 0 : _a[0];
|
1727
|
+
console.log("personal_sign message:", message);
|
1719
1728
|
if (message.length !== 66) {
|
1720
1729
|
const hash = hashMessage({ raw: message });
|
1730
|
+
console.log("personal_sign hash:", hash);
|
1721
1731
|
message = hash;
|
1722
1732
|
}
|
1723
1733
|
const result = yield this.personalSign(message || "");
|
@@ -1725,15 +1735,19 @@ var AASignerProvider = class {
|
|
1725
1735
|
if (!convertResult) {
|
1726
1736
|
throw new Error("sign error");
|
1727
1737
|
}
|
1738
|
+
console.log(`personal_sign result(${convertResult.length}): `, convertResult);
|
1728
1739
|
return convertResult;
|
1729
1740
|
} else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
|
1730
1741
|
const typedData = (_b = arg.params) == null ? void 0 : _b[1];
|
1742
|
+
console.log("signTypedData typedData", typedData);
|
1731
1743
|
const hash = hashTypedData(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
|
1744
|
+
console.log("signTypedData hash", hash);
|
1732
1745
|
const result = yield this.personalSign(hash || "");
|
1733
1746
|
const convertResult = convertSignature(result);
|
1734
1747
|
if (!convertResult) {
|
1735
1748
|
throw new Error("sign error");
|
1736
1749
|
}
|
1750
|
+
console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
|
1737
1751
|
return convertResult;
|
1738
1752
|
} else if (arg.method === "wallet_switchEthereumChain") {
|
1739
1753
|
if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
|
@@ -1905,6 +1919,7 @@ var ConnectProvider = ({
|
|
1905
1919
|
setEVMAccount(res);
|
1906
1920
|
}).catch((e) => {
|
1907
1921
|
setEVMAccount(void 0);
|
1922
|
+
console.error("smartAccount getAddress error", e);
|
1908
1923
|
});
|
1909
1924
|
} else {
|
1910
1925
|
setEVMAccount(void 0);
|
@@ -1926,6 +1941,7 @@ var ConnectProvider = ({
|
|
1926
1941
|
const requestAccount = useCallback7(
|
1927
1942
|
(connector2) => __async(void 0, null, function* () {
|
1928
1943
|
let accounts2 = yield connector2.getAccounts();
|
1944
|
+
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1929
1945
|
if (accounts2.length === 0 && autoConnect) {
|
1930
1946
|
accounts2 = yield connector2.requestAccounts();
|
1931
1947
|
}
|
@@ -1935,7 +1951,9 @@ var ConnectProvider = ({
|
|
1935
1951
|
);
|
1936
1952
|
const requestDirectAccount = useCallback7(
|
1937
1953
|
(connector2) => __async(void 0, null, function* () {
|
1954
|
+
console.log(111);
|
1938
1955
|
let accounts2 = yield connector2.getAccounts();
|
1956
|
+
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1939
1957
|
if (accounts2.length === 0) {
|
1940
1958
|
accounts2 = yield connector2.requestAccounts();
|
1941
1959
|
}
|
@@ -1947,6 +1965,7 @@ var ConnectProvider = ({
|
|
1947
1965
|
useEffect5(() => {
|
1948
1966
|
if (connector) {
|
1949
1967
|
requestAccount(connector).catch((e) => {
|
1968
|
+
console.log("get account error", e);
|
1950
1969
|
setAccounts([]);
|
1951
1970
|
});
|
1952
1971
|
} else {
|
@@ -2002,6 +2021,7 @@ var ConnectProvider = ({
|
|
2002
2021
|
})
|
2003
2022
|
})
|
2004
2023
|
);
|
2024
|
+
console.log("walletEntryPlugin init");
|
2005
2025
|
}
|
2006
2026
|
}, [options, evmSupportChainIds, accountContract]);
|
2007
2027
|
useEffect5(() => {
|
@@ -2010,6 +2030,7 @@ var ConnectProvider = ({
|
|
2010
2030
|
walletEntryPlugin.setWalletCore({
|
2011
2031
|
ethereum: smartAccount.provider
|
2012
2032
|
});
|
2033
|
+
console.log("walletEntryPlugin setWalletCore");
|
2013
2034
|
}
|
2014
2035
|
}, [smartAccount, options]);
|
2015
2036
|
useEffect5(() => {
|
@@ -2017,8 +2038,10 @@ var ConnectProvider = ({
|
|
2017
2038
|
if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
|
2018
2039
|
if (evmAccount) {
|
2019
2040
|
walletEntryPlugin.walletEntryCreate();
|
2041
|
+
console.log("walletEntryPlugin walletEntryCreate");
|
2020
2042
|
} else {
|
2021
2043
|
walletEntryPlugin.walletEntryDestroy();
|
2044
|
+
console.log("walletEntryPlugin walletEntryDestroy");
|
2022
2045
|
}
|
2023
2046
|
}
|
2024
2047
|
}, [evmAccount, smartAccount, options]);
|
@@ -2317,6 +2340,7 @@ import { sha256 } from "js-sha256";
|
|
2317
2340
|
|
2318
2341
|
// src/utils/initWalletButton.ts
|
2319
2342
|
function setupWalletButton(network, wallet, originalWallet) {
|
2343
|
+
console.log("setupWalletButton");
|
2320
2344
|
if (document.getElementById("satoshi-wallet-button")) {
|
2321
2345
|
return;
|
2322
2346
|
}
|
@@ -2363,6 +2387,9 @@ function createFloatingButtonWithIframe({
|
|
2363
2387
|
iframe.style.display = isCurrentlyVisible ? "none" : "block";
|
2364
2388
|
button.src = isCurrentlyVisible ? openImageUrl : closeImageUrl;
|
2365
2389
|
localStorage.setItem("iframeVisible", String(!isCurrentlyVisible));
|
2390
|
+
setTimeout(() => {
|
2391
|
+
iframe.focus();
|
2392
|
+
}, 0);
|
2366
2393
|
};
|
2367
2394
|
return button;
|
2368
2395
|
}
|
@@ -2392,20 +2419,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2392
2419
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2393
2420
|
const originalAccountId = originalWallet.account;
|
2394
2421
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2422
|
+
console.log({ accountId, originalAccountId, originalPublicKey });
|
2395
2423
|
const iframeSrc = new URL(iframe.src);
|
2396
2424
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2397
2425
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2398
2426
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2399
2427
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2400
2428
|
iframe.src = iframeSrc.toString();
|
2429
|
+
console.log("iframe src", iframe.src);
|
2401
2430
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2402
2431
|
var _a2, _b;
|
2403
2432
|
if (event.origin !== iframeSrc.origin)
|
2404
2433
|
return;
|
2405
2434
|
const { action, requestId, data } = event.data;
|
2406
2435
|
if (action === "signAndSendTransaction") {
|
2436
|
+
console.log("signAndSendTransaction message", event.data);
|
2407
2437
|
try {
|
2408
2438
|
const result = yield wallet.signAndSendTransaction(data);
|
2439
|
+
console.log("signAndSendTransaction result", result);
|
2409
2440
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2410
2441
|
{
|
2411
2442
|
requestId,
|
@@ -2415,6 +2446,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2415
2446
|
{ targetOrigin: event.origin }
|
2416
2447
|
);
|
2417
2448
|
} catch (error) {
|
2449
|
+
console.error("signAndSendTransaction error", error);
|
2418
2450
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2419
2451
|
{
|
2420
2452
|
requestId,
|
@@ -2506,17 +2538,16 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2506
2538
|
signAndSendTransaction,
|
2507
2539
|
signAndSendTransactions
|
2508
2540
|
};
|
2541
|
+
initWalletButton(options.network.networkId, wallet);
|
2509
2542
|
if (!inter) {
|
2510
2543
|
inter = setInterval(() => __async(void 0, null, function* () {
|
2511
2544
|
const btcContext = window.btcContext;
|
2512
2545
|
if (btcContext) {
|
2513
2546
|
clearInterval(inter);
|
2514
2547
|
const context = btcContext.getContext();
|
2515
|
-
const accountId = state.getAccount();
|
2516
|
-
initWalletButton(options.network.networkId, accountId, wallet);
|
2517
2548
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2518
2549
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2519
|
-
|
2550
|
+
console.info("accountsChanged:", nearTempAddress, btcContext.account);
|
2520
2551
|
emitter.emit("accountsChanged", {
|
2521
2552
|
accounts: [
|
2522
2553
|
{
|
@@ -2530,6 +2561,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2530
2561
|
accounts: []
|
2531
2562
|
});
|
2532
2563
|
}));
|
2564
|
+
console.log("metadata.autoConnect:", metadata);
|
2533
2565
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2534
2566
|
yield btcContext.autoConnect();
|
2535
2567
|
}
|
@@ -2570,6 +2602,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2570
2602
|
}
|
2571
2603
|
function signIn(_02) {
|
2572
2604
|
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
2605
|
+
console.log(provider);
|
2573
2606
|
const accountId = state.getAccount();
|
2574
2607
|
const publicKey = state.getPublicKey();
|
2575
2608
|
const btcContext = window.btcContext;
|
@@ -2584,7 +2617,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2584
2617
|
const btcAccount = yield btcContext.login();
|
2585
2618
|
const btcPublicKey = yield btcContext.getPublicKey();
|
2586
2619
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2587
|
-
initWalletButton(options.network.networkId, accountId, wallet);
|
2588
2620
|
return [
|
2589
2621
|
{
|
2590
2622
|
accountId: nearTempAddress,
|
@@ -2676,6 +2708,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2676
2708
|
txBytes,
|
2677
2709
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2678
2710
|
).join("");
|
2711
|
+
console.log("txHex:", txHex);
|
2679
2712
|
const hash = bs58.encode(new Uint8Array(sha256.array(txBytes)));
|
2680
2713
|
return { txBytes, txHex, hash };
|
2681
2714
|
});
|
@@ -2700,8 +2733,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2700
2733
|
btcPubKey: state.getBtcPublicKey(),
|
2701
2734
|
data: toHex(strIntention)
|
2702
2735
|
});
|
2736
|
+
console.log("result:", result);
|
2703
2737
|
if (result.result_code === 0) {
|
2704
2738
|
const hash = newTransactions.map((t) => t.hash);
|
2739
|
+
console.log("txHash:", hash);
|
2705
2740
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2706
2741
|
return result2;
|
2707
2742
|
} else {
|
@@ -2709,6 +2744,26 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2709
2744
|
}
|
2710
2745
|
});
|
2711
2746
|
}
|
2747
|
+
function initWalletButton(network, wallet2) {
|
2748
|
+
return __async(this, null, function* () {
|
2749
|
+
console.log("initWalletButton:", network, wallet2);
|
2750
|
+
const checkAndSetupWalletButton = () => {
|
2751
|
+
const accountId = state.getAccount();
|
2752
|
+
const btcContext = window.btcContext;
|
2753
|
+
console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
|
2754
|
+
if (accountId && btcContext.account) {
|
2755
|
+
setupWalletButton(network, wallet2, btcContext);
|
2756
|
+
} else {
|
2757
|
+
removeWalletButton();
|
2758
|
+
!btcContext.account && setTimeout(() => {
|
2759
|
+
checkAndSetupWalletButton();
|
2760
|
+
}, 5e3);
|
2761
|
+
}
|
2762
|
+
};
|
2763
|
+
yield delay(1e3);
|
2764
|
+
checkAndSetupWalletButton();
|
2765
|
+
});
|
2766
|
+
}
|
2712
2767
|
return wallet;
|
2713
2768
|
});
|
2714
2769
|
function getNonceFromApi(network, accountId) {
|
@@ -2767,22 +2822,6 @@ function toHex(originalString) {
|
|
2767
2822
|
hexString = hexString.replace(/(^0+)/g, "");
|
2768
2823
|
return hexString;
|
2769
2824
|
}
|
2770
|
-
function initWalletButton(network, accountId, wallet) {
|
2771
|
-
return __async(this, null, function* () {
|
2772
|
-
yield delay(1e3);
|
2773
|
-
const checkAndSetupWalletButton = () => {
|
2774
|
-
if (accountId && window.btcContext.account) {
|
2775
|
-
setupWalletButton(network, wallet, window.btcContext);
|
2776
|
-
} else {
|
2777
|
-
removeWalletButton();
|
2778
|
-
!window.btcContext.account && setTimeout(() => {
|
2779
|
-
checkAndSetupWalletButton();
|
2780
|
-
}, 5e3);
|
2781
|
-
}
|
2782
|
-
};
|
2783
|
-
checkAndSetupWalletButton();
|
2784
|
-
});
|
2785
|
-
}
|
2786
2825
|
var rcpUrls = {
|
2787
2826
|
mainnet: [
|
2788
2827
|
"https://near.lava.build",
|
@@ -2811,14 +2850,17 @@ function pollTransactionStatuses(network, hashes) {
|
|
2811
2850
|
try {
|
2812
2851
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2813
2852
|
if (result && result.status) {
|
2853
|
+
console.log(`Transaction ${hash} result:`, result);
|
2814
2854
|
return result;
|
2815
2855
|
}
|
2816
2856
|
} catch (error) {
|
2857
|
+
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2817
2858
|
}
|
2818
2859
|
if (attempt === maxAttempts) {
|
2819
2860
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2820
2861
|
}
|
2821
2862
|
yield delay(1e4);
|
2863
|
+
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2822
2864
|
}
|
2823
2865
|
});
|
2824
2866
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2828,7 +2870,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2828
2870
|
|
2829
2871
|
// src/index.ts
|
2830
2872
|
var getVersion = () => {
|
2831
|
-
return "0.1.
|
2873
|
+
return "0.1.3";
|
2832
2874
|
};
|
2833
2875
|
if (typeof window !== "undefined") {
|
2834
2876
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|