btc-wallet 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +70 -22
- package/dist/index.js.map +3 -3
- package/esm/index.js +70 -22
- 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
|
}
|
@@ -2324,6 +2348,13 @@ function setupWalletButton(network, wallet, originalWallet) {
|
|
2324
2348
|
iframeUrl: network === "testnet" ? "https://wallet-dev.satoshibridge.top" : "https://wallet.satoshibridge.top",
|
2325
2349
|
iframeStyle: { width: "400px", height: "650px" }
|
2326
2350
|
});
|
2351
|
+
iframe.addEventListener("mouseenter", () => {
|
2352
|
+
var _a;
|
2353
|
+
(_a = document.activeElement) == null ? void 0 : _a.setAttribute("tabindex", "null");
|
2354
|
+
setTimeout(() => {
|
2355
|
+
iframe.focus();
|
2356
|
+
}, 0);
|
2357
|
+
});
|
2327
2358
|
const button = createFloatingButtonWithIframe({
|
2328
2359
|
openImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn.png",
|
2329
2360
|
closeImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn-active.png",
|
@@ -2363,6 +2394,9 @@ function createFloatingButtonWithIframe({
|
|
2363
2394
|
iframe.style.display = isCurrentlyVisible ? "none" : "block";
|
2364
2395
|
button.src = isCurrentlyVisible ? openImageUrl : closeImageUrl;
|
2365
2396
|
localStorage.setItem("iframeVisible", String(!isCurrentlyVisible));
|
2397
|
+
setTimeout(() => {
|
2398
|
+
iframe.focus();
|
2399
|
+
}, 0);
|
2366
2400
|
};
|
2367
2401
|
return button;
|
2368
2402
|
}
|
@@ -2374,9 +2408,6 @@ function createIframe({
|
|
2374
2408
|
iframe.id = "satoshi-wallet-iframe";
|
2375
2409
|
iframe.allow = "clipboard-read; clipboard-write";
|
2376
2410
|
iframe.src = iframeUrl;
|
2377
|
-
iframe.onclick = () => {
|
2378
|
-
iframe.focus();
|
2379
|
-
};
|
2380
2411
|
Object.assign(iframe.style, __spreadValues({
|
2381
2412
|
position: "fixed",
|
2382
2413
|
bottom: "90px",
|
@@ -2395,20 +2426,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2395
2426
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2396
2427
|
const originalAccountId = originalWallet.account;
|
2397
2428
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2429
|
+
console.log({ accountId, originalAccountId, originalPublicKey });
|
2398
2430
|
const iframeSrc = new URL(iframe.src);
|
2399
2431
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2400
2432
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2401
2433
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2402
2434
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2403
2435
|
iframe.src = iframeSrc.toString();
|
2436
|
+
console.log("iframe src", iframe.src);
|
2404
2437
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2405
2438
|
var _a2, _b;
|
2406
2439
|
if (event.origin !== iframeSrc.origin)
|
2407
2440
|
return;
|
2408
2441
|
const { action, requestId, data } = event.data;
|
2409
2442
|
if (action === "signAndSendTransaction") {
|
2443
|
+
console.log("signAndSendTransaction message", event.data);
|
2410
2444
|
try {
|
2411
2445
|
const result = yield wallet.signAndSendTransaction(data);
|
2446
|
+
console.log("signAndSendTransaction result", result);
|
2412
2447
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2413
2448
|
{
|
2414
2449
|
requestId,
|
@@ -2418,6 +2453,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2418
2453
|
{ targetOrigin: event.origin }
|
2419
2454
|
);
|
2420
2455
|
} catch (error) {
|
2456
|
+
console.error("signAndSendTransaction error", error);
|
2421
2457
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2422
2458
|
{
|
2423
2459
|
requestId,
|
@@ -2509,6 +2545,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2509
2545
|
signAndSendTransaction,
|
2510
2546
|
signAndSendTransactions
|
2511
2547
|
};
|
2548
|
+
initWalletButton(options.network.networkId, wallet);
|
2512
2549
|
if (!inter) {
|
2513
2550
|
inter = setInterval(() => __async(void 0, null, function* () {
|
2514
2551
|
const btcContext = window.btcContext;
|
@@ -2517,6 +2554,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2517
2554
|
const context = btcContext.getContext();
|
2518
2555
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2519
2556
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2557
|
+
console.info("accountsChanged:", nearTempAddress, btcContext.account);
|
2520
2558
|
emitter.emit("accountsChanged", {
|
2521
2559
|
accounts: [
|
2522
2560
|
{
|
@@ -2530,6 +2568,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2530
2568
|
accounts: []
|
2531
2569
|
});
|
2532
2570
|
}));
|
2571
|
+
console.log("metadata.autoConnect:", metadata);
|
2533
2572
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2534
2573
|
yield btcContext.autoConnect();
|
2535
2574
|
}
|
@@ -2537,7 +2576,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2537
2576
|
}
|
2538
2577
|
}), 500);
|
2539
2578
|
}
|
2540
|
-
initWalletButton(options.network.networkId, state.getAccount(), wallet);
|
2541
2579
|
function viewMethod(_02) {
|
2542
2580
|
return __async(this, arguments, function* ({ method, args = {} }) {
|
2543
2581
|
const res = yield provider.query({
|
@@ -2563,7 +2601,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2563
2601
|
state.saveAccount(nearTempAddress);
|
2564
2602
|
state.savePublicKey(nearTempPublicKey);
|
2565
2603
|
state.saveBtcPublicKey(btcPublicKey);
|
2566
|
-
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2567
2604
|
return {
|
2568
2605
|
nearTempAddress,
|
2569
2606
|
nearTempPublicKey
|
@@ -2572,6 +2609,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2572
2609
|
}
|
2573
2610
|
function signIn(_02) {
|
2574
2611
|
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
2612
|
+
console.log(provider);
|
2575
2613
|
const accountId = state.getAccount();
|
2576
2614
|
const publicKey = state.getPublicKey();
|
2577
2615
|
const btcContext = window.btcContext;
|
@@ -2677,6 +2715,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2677
2715
|
txBytes,
|
2678
2716
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2679
2717
|
).join("");
|
2718
|
+
console.log("txHex:", txHex);
|
2680
2719
|
const hash = bs58.encode(new Uint8Array(sha256.array(txBytes)));
|
2681
2720
|
return { txBytes, txHex, hash };
|
2682
2721
|
});
|
@@ -2701,8 +2740,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2701
2740
|
btcPubKey: state.getBtcPublicKey(),
|
2702
2741
|
data: toHex(strIntention)
|
2703
2742
|
});
|
2743
|
+
console.log("result:", result);
|
2704
2744
|
if (result.result_code === 0) {
|
2705
2745
|
const hash = newTransactions.map((t) => t.hash);
|
2746
|
+
console.log("txHash:", hash);
|
2706
2747
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2707
2748
|
return result2;
|
2708
2749
|
} else {
|
@@ -2710,6 +2751,26 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2710
2751
|
}
|
2711
2752
|
});
|
2712
2753
|
}
|
2754
|
+
function initWalletButton(network, wallet2) {
|
2755
|
+
return __async(this, null, function* () {
|
2756
|
+
console.log("initWalletButton:", network, wallet2);
|
2757
|
+
const checkAndSetupWalletButton = () => {
|
2758
|
+
const accountId = state.getAccount();
|
2759
|
+
const btcContext = window.btcContext;
|
2760
|
+
console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
|
2761
|
+
if (accountId && btcContext.account) {
|
2762
|
+
setupWalletButton(network, wallet2, btcContext);
|
2763
|
+
} else {
|
2764
|
+
removeWalletButton();
|
2765
|
+
!btcContext.account && setTimeout(() => {
|
2766
|
+
checkAndSetupWalletButton();
|
2767
|
+
}, 5e3);
|
2768
|
+
}
|
2769
|
+
};
|
2770
|
+
yield delay(1e3);
|
2771
|
+
checkAndSetupWalletButton();
|
2772
|
+
});
|
2773
|
+
}
|
2713
2774
|
return wallet;
|
2714
2775
|
});
|
2715
2776
|
function getNonceFromApi(network, accountId) {
|
@@ -2768,22 +2829,6 @@ function toHex(originalString) {
|
|
2768
2829
|
hexString = hexString.replace(/(^0+)/g, "");
|
2769
2830
|
return hexString;
|
2770
2831
|
}
|
2771
|
-
function initWalletButton(network, accountId, wallet) {
|
2772
|
-
return __async(this, null, function* () {
|
2773
|
-
yield delay(1e3);
|
2774
|
-
const checkAndSetupWalletButton = () => {
|
2775
|
-
if (accountId && window.btcContext.account) {
|
2776
|
-
setupWalletButton(network, wallet, window.btcContext);
|
2777
|
-
} else {
|
2778
|
-
removeWalletButton();
|
2779
|
-
!window.btcContext.account && setTimeout(() => {
|
2780
|
-
checkAndSetupWalletButton();
|
2781
|
-
}, 5e3);
|
2782
|
-
}
|
2783
|
-
};
|
2784
|
-
checkAndSetupWalletButton();
|
2785
|
-
});
|
2786
|
-
}
|
2787
2832
|
var rcpUrls = {
|
2788
2833
|
mainnet: [
|
2789
2834
|
"https://near.lava.build",
|
@@ -2812,14 +2857,17 @@ function pollTransactionStatuses(network, hashes) {
|
|
2812
2857
|
try {
|
2813
2858
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2814
2859
|
if (result && result.status) {
|
2860
|
+
console.log(`Transaction ${hash} result:`, result);
|
2815
2861
|
return result;
|
2816
2862
|
}
|
2817
2863
|
} catch (error) {
|
2864
|
+
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2818
2865
|
}
|
2819
2866
|
if (attempt === maxAttempts) {
|
2820
2867
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2821
2868
|
}
|
2822
2869
|
yield delay(1e4);
|
2870
|
+
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2823
2871
|
}
|
2824
2872
|
});
|
2825
2873
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2829,7 +2877,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2829
2877
|
|
2830
2878
|
// src/index.ts
|
2831
2879
|
var getVersion = () => {
|
2832
|
-
return "0.1.
|
2880
|
+
return "0.1.4";
|
2833
2881
|
};
|
2834
2882
|
if (typeof window !== "undefined") {
|
2835
2883
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|