btc-wallet 0.0.8 → 0.1.0
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 -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 +47 -30
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1127,6 +1127,7 @@ var checkBTCVersion = (accountContracts, accountContractKey, version) => {
|
|
|
1127
1127
|
}
|
|
1128
1128
|
return accountContracts[accountContractKey].some((item) => item.version === version);
|
|
1129
1129
|
};
|
|
1130
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1130
1131
|
|
|
1131
1132
|
// src/utils/ethereumUtils.ts
|
|
1132
1133
|
var import_util2 = require("@ethereumjs/util");
|
|
@@ -2357,8 +2358,10 @@ var import_js_sha256 = require("js-sha256");
|
|
|
2357
2358
|
|
|
2358
2359
|
// src/utils/initWalletButton.ts
|
|
2359
2360
|
function setupWalletButton(network, wallet, originalWallet) {
|
|
2360
|
-
if (document.getElementById("satoshi-wallet-button"))
|
|
2361
|
+
if (document.getElementById("satoshi-wallet-button")) {
|
|
2362
|
+
sendInitializeData(wallet, originalWallet);
|
|
2361
2363
|
return;
|
|
2364
|
+
}
|
|
2362
2365
|
const iframe = createIframe({
|
|
2363
2366
|
iframeUrl: network === "testnet" ? "https://wallet-dev.satoshibridge.top" : "https://wallet.satoshibridge.top",
|
|
2364
2367
|
iframeStyle: { width: "400px", height: "650px" }
|
|
@@ -2425,33 +2428,48 @@ function createIframe({
|
|
|
2425
2428
|
document.body.appendChild(iframe);
|
|
2426
2429
|
return iframe;
|
|
2427
2430
|
}
|
|
2428
|
-
function
|
|
2431
|
+
function sendInitializeData(wallet, originalWallet) {
|
|
2429
2432
|
return __async(this, null, function* () {
|
|
2430
|
-
var _a;
|
|
2433
|
+
var _a, _b;
|
|
2434
|
+
yield delay(1e3);
|
|
2431
2435
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
|
2432
2436
|
const originalAccountId = originalWallet.account;
|
|
2433
2437
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
|
2438
|
+
const iframe = document.getElementById("satoshi-wallet-iframe");
|
|
2439
|
+
if ((iframe == null ? void 0 : iframe.contentWindow) && ((_b = iframe.contentDocument) == null ? void 0 : _b.readyState) === "complete") {
|
|
2440
|
+
iframe.contentWindow.postMessage(
|
|
2441
|
+
{
|
|
2442
|
+
action: "initializeData",
|
|
2443
|
+
success: true,
|
|
2444
|
+
data: {
|
|
2445
|
+
accountId,
|
|
2446
|
+
originalAccountId,
|
|
2447
|
+
originalPublicKey
|
|
2448
|
+
}
|
|
2449
|
+
},
|
|
2450
|
+
{ targetOrigin: window.location.origin }
|
|
2451
|
+
);
|
|
2452
|
+
}
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2456
|
+
return __async(this, null, function* () {
|
|
2457
|
+
iframe.onload = () => sendInitializeData(wallet, originalWallet);
|
|
2434
2458
|
const iframeSrc = new URL(iframe.src);
|
|
2435
2459
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
|
2436
|
-
if (accountId)
|
|
2437
|
-
iframeSrc.searchParams.set("accountId", accountId);
|
|
2438
|
-
if (originalAccountId)
|
|
2439
|
-
iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
|
2440
|
-
if (originalPublicKey)
|
|
2441
|
-
iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
|
2442
2460
|
iframe.src = iframeSrc.toString();
|
|
2443
2461
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
|
2444
|
-
var
|
|
2462
|
+
var _a, _b;
|
|
2445
2463
|
if (event.origin !== iframeSrc.origin)
|
|
2446
2464
|
return;
|
|
2447
|
-
const { action, requestId,
|
|
2465
|
+
const { action, requestId, data } = event.data;
|
|
2448
2466
|
if (action === "signAndSendTransaction") {
|
|
2449
2467
|
try {
|
|
2450
|
-
const result = yield wallet.signAndSendTransaction(
|
|
2451
|
-
(
|
|
2468
|
+
const result = yield wallet.signAndSendTransaction(data);
|
|
2469
|
+
(_a = event.source) == null ? void 0 : _a.postMessage(
|
|
2452
2470
|
{
|
|
2453
2471
|
requestId,
|
|
2454
|
-
|
|
2472
|
+
data,
|
|
2455
2473
|
success: true
|
|
2456
2474
|
},
|
|
2457
2475
|
{ targetOrigin: event.origin }
|
|
@@ -2558,9 +2576,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
|
2558
2576
|
initWalletButton(options.network.networkId, accountId, wallet);
|
|
2559
2577
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
|
2560
2578
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
|
2561
|
-
|
|
2562
|
-
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
|
2563
|
-
}, 1e3);
|
|
2579
|
+
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
|
2564
2580
|
emitter.emit("accountsChanged", {
|
|
2565
2581
|
accounts: [
|
|
2566
2582
|
{
|
|
@@ -2628,6 +2644,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
|
2628
2644
|
const btcAccount = yield btcContext.login();
|
|
2629
2645
|
const btcPublicKey = yield btcContext.getPublicKey();
|
|
2630
2646
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
|
2647
|
+
initWalletButton(options.network.networkId, accountId, wallet);
|
|
2631
2648
|
return [
|
|
2632
2649
|
{
|
|
2633
2650
|
accountId: nearTempAddress,
|
|
@@ -2811,17 +2828,20 @@ function toHex(originalString) {
|
|
|
2811
2828
|
return hexString;
|
|
2812
2829
|
}
|
|
2813
2830
|
function initWalletButton(network, accountId, wallet) {
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2831
|
+
return __async(this, null, function* () {
|
|
2832
|
+
yield delay(2e3);
|
|
2833
|
+
const checkAndSetupWalletButton = () => {
|
|
2834
|
+
if (accountId && window.btcContext.account) {
|
|
2835
|
+
setupWalletButton(network, wallet, window.btcContext);
|
|
2836
|
+
} else {
|
|
2837
|
+
removeWalletButton();
|
|
2838
|
+
}
|
|
2817
2839
|
!window.btcContext.account && setTimeout(() => {
|
|
2818
2840
|
checkAndSetupWalletButton();
|
|
2819
|
-
},
|
|
2820
|
-
}
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
};
|
|
2824
|
-
checkAndSetupWalletButton();
|
|
2841
|
+
}, 1e4);
|
|
2842
|
+
};
|
|
2843
|
+
checkAndSetupWalletButton();
|
|
2844
|
+
});
|
|
2825
2845
|
}
|
|
2826
2846
|
var rcpUrls = {
|
|
2827
2847
|
mainnet: [
|
|
@@ -2836,9 +2856,6 @@ var rcpUrls = {
|
|
|
2836
2856
|
"https://near-testnet.drpc.org"
|
|
2837
2857
|
]
|
|
2838
2858
|
};
|
|
2839
|
-
function delay(ms) {
|
|
2840
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2841
|
-
}
|
|
2842
2859
|
function pollTransactionStatuses(network, hashes) {
|
|
2843
2860
|
return __async(this, null, function* () {
|
|
2844
2861
|
const provider = new import_near_api_js.providers.FailoverRpcProvider(
|
|
@@ -2871,7 +2888,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
|
2871
2888
|
|
|
2872
2889
|
// src/index.ts
|
|
2873
2890
|
var getVersion = () => {
|
|
2874
|
-
return "0.0
|
|
2891
|
+
return "0.1.0";
|
|
2875
2892
|
};
|
|
2876
2893
|
if (typeof window !== "undefined") {
|
|
2877
2894
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|