btc-wallet 0.1.6 → 0.1.7
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 +43 -2
- package/dist/index.js.map +2 -2
- package/esm/index.js +43 -2
- package/esm/index.js.map +2 -2
- 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
|
}
|
@@ -2445,20 +2469,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2445
2469
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2446
2470
|
const originalAccountId = originalWallet.account;
|
2447
2471
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2472
|
+
console.log({ accountId, originalAccountId, originalPublicKey });
|
2448
2473
|
const iframeSrc = new URL(iframe.src);
|
2449
2474
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2450
2475
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2451
2476
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2452
2477
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2453
2478
|
iframe.src = iframeSrc.toString();
|
2479
|
+
console.log("iframe src", iframe.src);
|
2454
2480
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2455
2481
|
var _a2, _b;
|
2456
2482
|
if (event.origin !== iframeSrc.origin)
|
2457
2483
|
return;
|
2458
2484
|
const { action, requestId, data } = event.data;
|
2459
2485
|
if (action === "signAndSendTransaction") {
|
2486
|
+
console.log("signAndSendTransaction message", event.data);
|
2460
2487
|
try {
|
2461
2488
|
const result = yield wallet.signAndSendTransaction(data);
|
2489
|
+
console.log("signAndSendTransaction result", result);
|
2462
2490
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2463
2491
|
{
|
2464
2492
|
requestId,
|
@@ -2468,6 +2496,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2468
2496
|
{ targetOrigin: event.origin }
|
2469
2497
|
);
|
2470
2498
|
} catch (error) {
|
2499
|
+
console.error("signAndSendTransaction error", error);
|
2471
2500
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2472
2501
|
{
|
2473
2502
|
requestId,
|
@@ -2563,11 +2592,13 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2563
2592
|
if (!inter) {
|
2564
2593
|
inter = setInterval(() => __async(void 0, null, function* () {
|
2565
2594
|
const btcContext = window.btcContext;
|
2595
|
+
console.log("inter btcContext:", btcContext);
|
2566
2596
|
if (btcContext) {
|
2567
2597
|
clearInterval(inter);
|
2568
2598
|
const context = btcContext.getContext();
|
2569
2599
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2570
2600
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2601
|
+
console.info("accountsChanged:", nearTempAddress, btcContext.account);
|
2571
2602
|
emitter.emit("accountsChanged", {
|
2572
2603
|
accounts: [
|
2573
2604
|
{
|
@@ -2581,6 +2612,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2581
2612
|
accounts: []
|
2582
2613
|
});
|
2583
2614
|
}));
|
2615
|
+
console.log("metadata.autoConnect:", metadata);
|
2584
2616
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2585
2617
|
yield btcContext.autoConnect();
|
2586
2618
|
}
|
@@ -2621,6 +2653,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2621
2653
|
}
|
2622
2654
|
function signIn(_02) {
|
2623
2655
|
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
2656
|
+
console.log(provider);
|
2624
2657
|
const accountId = state.getAccount();
|
2625
2658
|
const publicKey = state.getPublicKey();
|
2626
2659
|
const btcContext = window.btcContext;
|
@@ -2649,7 +2682,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2649
2682
|
btcContext.logout();
|
2650
2683
|
state.clear();
|
2651
2684
|
window.localStorage.removeItem("near-wallet-selector:selectedWalletId");
|
2652
|
-
|
2685
|
+
removeWalletButton();
|
2653
2686
|
});
|
2654
2687
|
}
|
2655
2688
|
function getAccounts() {
|
@@ -2726,6 +2759,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2726
2759
|
txBytes,
|
2727
2760
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2728
2761
|
).join("");
|
2762
|
+
console.log("txHex:", txHex);
|
2729
2763
|
const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
|
2730
2764
|
return { txBytes, txHex, hash };
|
2731
2765
|
});
|
@@ -2750,8 +2784,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2750
2784
|
btcPubKey: state.getBtcPublicKey(),
|
2751
2785
|
data: toHex(strIntention)
|
2752
2786
|
});
|
2787
|
+
console.log("result:", result);
|
2753
2788
|
if (result.result_code === 0) {
|
2754
2789
|
const hash = newTransactions.map((t) => t.hash);
|
2790
|
+
console.log("txHash:", hash);
|
2755
2791
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2756
2792
|
return result2;
|
2757
2793
|
} else {
|
@@ -2761,9 +2797,11 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2761
2797
|
}
|
2762
2798
|
function initWalletButton(network, wallet2) {
|
2763
2799
|
return __async(this, null, function* () {
|
2800
|
+
console.log("initWalletButton:", network, wallet2);
|
2764
2801
|
const checkAndSetupWalletButton = () => {
|
2765
2802
|
const accountId = state.getAccount();
|
2766
2803
|
const btcContext = window.btcContext;
|
2804
|
+
console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
|
2767
2805
|
if (accountId && btcContext.account) {
|
2768
2806
|
setupWalletButton(network, wallet2, btcContext);
|
2769
2807
|
} else {
|
@@ -2863,14 +2901,17 @@ function pollTransactionStatuses(network, hashes) {
|
|
2863
2901
|
try {
|
2864
2902
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2865
2903
|
if (result && result.status) {
|
2904
|
+
console.log(`Transaction ${hash} result:`, result);
|
2866
2905
|
return result;
|
2867
2906
|
}
|
2868
2907
|
} catch (error) {
|
2908
|
+
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2869
2909
|
}
|
2870
2910
|
if (attempt === maxAttempts) {
|
2871
2911
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2872
2912
|
}
|
2873
2913
|
yield delay(1e4);
|
2914
|
+
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2874
2915
|
}
|
2875
2916
|
});
|
2876
2917
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2880,7 +2921,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2880
2921
|
|
2881
2922
|
// src/index.ts
|
2882
2923
|
var getVersion = () => {
|
2883
|
-
return "0.1.
|
2924
|
+
return "0.1.7";
|
2884
2925
|
};
|
2885
2926
|
if (typeof window !== "undefined") {
|
2886
2927
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|