btc-wallet 0.0.8 → 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 +44 -30
- package/dist/index.js.map +3 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/initWalletButton.d.ts +4 -2
- package/esm/index.js +44 -30
- 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
1
|
import type { Wallet } from '@near-wallet-selector/core';
|
2
|
-
|
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 }
|
@@ -2517,9 +2532,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2517
2532
|
initWalletButton(options.network.networkId, accountId, wallet);
|
2518
2533
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2519
2534
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2520
|
-
|
2521
|
-
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2522
|
-
}, 1e3);
|
2535
|
+
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2523
2536
|
emitter.emit("accountsChanged", {
|
2524
2537
|
accounts: [
|
2525
2538
|
{
|
@@ -2587,6 +2600,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2587
2600
|
const btcAccount = yield btcContext.login();
|
2588
2601
|
const btcPublicKey = yield btcContext.getPublicKey();
|
2589
2602
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2603
|
+
initWalletButton(options.network.networkId, accountId, wallet);
|
2590
2604
|
return [
|
2591
2605
|
{
|
2592
2606
|
accountId: nearTempAddress,
|
@@ -2770,17 +2784,20 @@ function toHex(originalString) {
|
|
2770
2784
|
return hexString;
|
2771
2785
|
}
|
2772
2786
|
function initWalletButton(network, accountId, wallet) {
|
2773
|
-
|
2774
|
-
|
2775
|
-
|
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
|
+
}
|
2776
2795
|
!window.btcContext.account && setTimeout(() => {
|
2777
2796
|
checkAndSetupWalletButton();
|
2778
|
-
},
|
2779
|
-
}
|
2780
|
-
|
2781
|
-
|
2782
|
-
};
|
2783
|
-
checkAndSetupWalletButton();
|
2797
|
+
}, 1e4);
|
2798
|
+
};
|
2799
|
+
checkAndSetupWalletButton();
|
2800
|
+
});
|
2784
2801
|
}
|
2785
2802
|
var rcpUrls = {
|
2786
2803
|
mainnet: [
|
@@ -2795,9 +2812,6 @@ var rcpUrls = {
|
|
2795
2812
|
"https://near-testnet.drpc.org"
|
2796
2813
|
]
|
2797
2814
|
};
|
2798
|
-
function delay(ms) {
|
2799
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
2800
|
-
}
|
2801
2815
|
function pollTransactionStatuses(network, hashes) {
|
2802
2816
|
return __async(this, null, function* () {
|
2803
2817
|
const provider = new providers.FailoverRpcProvider(
|
@@ -2830,7 +2844,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2830
2844
|
|
2831
2845
|
// src/index.ts
|
2832
2846
|
var getVersion = () => {
|
2833
|
-
return "0.0.
|
2847
|
+
return "0.0.9";
|
2834
2848
|
};
|
2835
2849
|
if (typeof window !== "undefined") {
|
2836
2850
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|