btc-wallet 0.0.7 → 0.0.9
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 +47 -34
- package/dist/index.js.map +3 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/initWalletButton.d.ts +5 -3
- package/esm/index.js +47 -34
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/dist/utils/index.d.ts
CHANGED
@@ -9,3 +9,4 @@ export declare function copyToClipboard(text: string): Promise<unknown>;
|
|
9
9
|
export declare const defaultTokenIcon = "https://static.particle.network/token-list/defaultToken/default.png";
|
10
10
|
export declare const ipfsToSrc: (ipfs: string) => string;
|
11
11
|
export declare const checkBTCVersion: (accountContracts: AAOptions["accountContracts"], accountContractKey: string, version: string) => boolean;
|
12
|
+
export declare const delay: (ms: number) => Promise<unknown>;
|
@@ -1,6 +1,8 @@
|
|
1
|
-
import { Wallet } from '@near-wallet-selector/core';
|
2
|
-
|
1
|
+
import type { Wallet } from '@near-wallet-selector/core';
|
2
|
+
interface OriginalWallet {
|
3
3
|
account: string | null;
|
4
4
|
getPublicKey: () => Promise<string>;
|
5
|
-
}
|
5
|
+
}
|
6
|
+
export declare function setupWalletButton(network: string, wallet: Wallet, originalWallet: OriginalWallet): void;
|
6
7
|
export declare function removeWalletButton(): void;
|
8
|
+
export {};
|
package/esm/index.js
CHANGED
@@ -1078,6 +1078,7 @@ var checkBTCVersion = (accountContracts, accountContractKey, version) => {
|
|
1078
1078
|
}
|
1079
1079
|
return accountContracts[accountContractKey].some((item) => item.version === version);
|
1080
1080
|
};
|
1081
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
1081
1082
|
|
1082
1083
|
// src/utils/ethereumUtils.ts
|
1083
1084
|
import { bytesToHex, publicToAddress, toBytes, toChecksumAddress, toRpcSig } from "@ethereumjs/util";
|
@@ -2316,8 +2317,10 @@ import { sha256 } from "js-sha256";
|
|
2316
2317
|
|
2317
2318
|
// src/utils/initWalletButton.ts
|
2318
2319
|
function setupWalletButton(network, wallet, originalWallet) {
|
2319
|
-
if (document.getElementById("satoshi-wallet-button"))
|
2320
|
+
if (document.getElementById("satoshi-wallet-button")) {
|
2321
|
+
sendInitializeData(wallet, originalWallet);
|
2320
2322
|
return;
|
2323
|
+
}
|
2321
2324
|
const iframe = createIframe({
|
2322
2325
|
iframeUrl: network === "testnet" ? "https://wallet-dev.satoshibridge.top" : "https://wallet.satoshibridge.top",
|
2323
2326
|
iframeStyle: { width: "400px", height: "650px" }
|
@@ -2384,33 +2387,45 @@ function createIframe({
|
|
2384
2387
|
document.body.appendChild(iframe);
|
2385
2388
|
return iframe;
|
2386
2389
|
}
|
2387
|
-
function
|
2390
|
+
function sendInitializeData(wallet, originalWallet) {
|
2388
2391
|
return __async(this, null, function* () {
|
2389
|
-
var _a;
|
2392
|
+
var _a, _b;
|
2393
|
+
yield delay(1e3);
|
2390
2394
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2391
2395
|
const originalAccountId = originalWallet.account;
|
2392
2396
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2397
|
+
const iframe = document.getElementById("satoshi-wallet-iframe");
|
2398
|
+
if ((iframe == null ? void 0 : iframe.contentWindow) && ((_b = iframe.contentDocument) == null ? void 0 : _b.readyState) === "complete") {
|
2399
|
+
iframe.contentWindow.postMessage({
|
2400
|
+
action: "initializeData",
|
2401
|
+
success: true,
|
2402
|
+
data: {
|
2403
|
+
accountId,
|
2404
|
+
originalAccountId,
|
2405
|
+
originalPublicKey
|
2406
|
+
}
|
2407
|
+
});
|
2408
|
+
}
|
2409
|
+
});
|
2410
|
+
}
|
2411
|
+
function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
2412
|
+
return __async(this, null, function* () {
|
2413
|
+
iframe.onload = () => sendInitializeData(wallet, originalWallet);
|
2393
2414
|
const iframeSrc = new URL(iframe.src);
|
2394
2415
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2395
|
-
if (accountId)
|
2396
|
-
iframeSrc.searchParams.set("accountId", accountId);
|
2397
|
-
if (originalAccountId)
|
2398
|
-
iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2399
|
-
if (originalPublicKey)
|
2400
|
-
iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2401
2416
|
iframe.src = iframeSrc.toString();
|
2402
2417
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2403
|
-
var
|
2418
|
+
var _a, _b;
|
2404
2419
|
if (event.origin !== iframeSrc.origin)
|
2405
2420
|
return;
|
2406
|
-
const { action, requestId,
|
2421
|
+
const { action, requestId, data } = event.data;
|
2407
2422
|
if (action === "signAndSendTransaction") {
|
2408
2423
|
try {
|
2409
|
-
const result = yield wallet.signAndSendTransaction(
|
2410
|
-
(
|
2424
|
+
const result = yield wallet.signAndSendTransaction(data);
|
2425
|
+
(_a = event.source) == null ? void 0 : _a.postMessage(
|
2411
2426
|
{
|
2412
2427
|
requestId,
|
2413
|
-
|
2428
|
+
data,
|
2414
2429
|
success: true
|
2415
2430
|
},
|
2416
2431
|
{ targetOrigin: event.origin }
|
@@ -2516,11 +2531,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2516
2531
|
const accountId = state.getAccount();
|
2517
2532
|
initWalletButton(options.network.networkId, accountId, wallet);
|
2518
2533
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2519
|
-
const { nearTempAddress
|
2520
|
-
|
2521
|
-
setTimeout(() => {
|
2522
|
-
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2523
|
-
}, 1e3);
|
2534
|
+
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2535
|
+
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2524
2536
|
emitter.emit("accountsChanged", {
|
2525
2537
|
accounts: [
|
2526
2538
|
{
|
@@ -2535,7 +2547,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2535
2547
|
});
|
2536
2548
|
}));
|
2537
2549
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2538
|
-
btcContext.autoConnect();
|
2550
|
+
yield btcContext.autoConnect();
|
2539
2551
|
}
|
2540
2552
|
clearInterval(inter);
|
2541
2553
|
}
|
@@ -2588,6 +2600,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2588
2600
|
const btcAccount = yield btcContext.login();
|
2589
2601
|
const btcPublicKey = yield btcContext.getPublicKey();
|
2590
2602
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2603
|
+
initWalletButton(options.network.networkId, accountId, wallet);
|
2591
2604
|
return [
|
2592
2605
|
{
|
2593
2606
|
accountId: nearTempAddress,
|
@@ -2771,17 +2784,20 @@ function toHex(originalString) {
|
|
2771
2784
|
return hexString;
|
2772
2785
|
}
|
2773
2786
|
function initWalletButton(network, accountId, wallet) {
|
2774
|
-
|
2775
|
-
|
2776
|
-
|
2777
|
-
|
2778
|
-
|
2779
|
-
|
2787
|
+
return __async(this, null, function* () {
|
2788
|
+
yield delay(2e3);
|
2789
|
+
const checkAndSetupWalletButton = () => {
|
2790
|
+
if (accountId && window.btcContext.account) {
|
2791
|
+
setupWalletButton(network, wallet, window.btcContext);
|
2792
|
+
} else {
|
2793
|
+
removeWalletButton();
|
2794
|
+
}
|
2795
|
+
!window.btcContext.account && setTimeout(() => {
|
2780
2796
|
checkAndSetupWalletButton();
|
2781
|
-
},
|
2782
|
-
}
|
2783
|
-
|
2784
|
-
|
2797
|
+
}, 1e4);
|
2798
|
+
};
|
2799
|
+
checkAndSetupWalletButton();
|
2800
|
+
});
|
2785
2801
|
}
|
2786
2802
|
var rcpUrls = {
|
2787
2803
|
mainnet: [
|
@@ -2796,9 +2812,6 @@ var rcpUrls = {
|
|
2796
2812
|
"https://near-testnet.drpc.org"
|
2797
2813
|
]
|
2798
2814
|
};
|
2799
|
-
function delay(ms) {
|
2800
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
2801
|
-
}
|
2802
2815
|
function pollTransactionStatuses(network, hashes) {
|
2803
2816
|
return __async(this, null, function* () {
|
2804
2817
|
const provider = new providers.FailoverRpcProvider(
|
@@ -2831,7 +2844,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2831
2844
|
|
2832
2845
|
// src/index.ts
|
2833
2846
|
var getVersion = () => {
|
2834
|
-
return "0.0.
|
2847
|
+
return "0.0.9";
|
2835
2848
|
};
|
2836
2849
|
if (typeof window !== "undefined") {
|
2837
2850
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|