btc-wallet 0.3.18 → 0.3.20
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 +59 -42
 - package/dist/index.js.map +3 -3
 - package/esm/index.js +59 -42
 - package/esm/index.js.map +3 -3
 - package/package.json +1 -1
 
    
        package/esm/index.js
    CHANGED
    
    | 
         @@ -271,7 +271,7 @@ var _network, _event; 
     | 
|
| 
       271 
271 
     | 
    
         
             
            var XverseConnector = class extends BaseConnector {
         
     | 
| 
       272 
272 
     | 
    
         
             
              constructor() {
         
     | 
| 
       273 
273 
     | 
    
         
             
                super();
         
     | 
| 
       274 
     | 
    
         
            -
                __privateAdd(this, _network, " 
     | 
| 
      
 274 
     | 
    
         
            +
                __privateAdd(this, _network, "Mainnet");
         
     | 
| 
       275 
275 
     | 
    
         
             
                __privateAdd(this, _event, new EventEmitter());
         
     | 
| 
       276 
276 
     | 
    
         
             
                this.metadata = {
         
     | 
| 
       277 
277 
     | 
    
         
             
                  id: "xverse",
         
     | 
| 
         @@ -2545,21 +2545,18 @@ function useBtcWalletSelector() { 
     | 
|
| 
       2545 
2545 
     | 
    
         
             
                    return context;
         
     | 
| 
       2546 
2546 
     | 
    
         
             
                  },
         
     | 
| 
       2547 
2547 
     | 
    
         
             
                  getNetwork: getNetwork2,
         
     | 
| 
       2548 
     | 
    
         
            -
                  switchNetwork 
     | 
| 
       2549 
     | 
    
         
            -
                    console.log("switchNetwork:", network);
         
     | 
| 
       2550 
     | 
    
         
            -
                    yield switchNetwork(network);
         
     | 
| 
       2551 
     | 
    
         
            -
                  }),
         
     | 
| 
      
 2548 
     | 
    
         
            +
                  switchNetwork,
         
     | 
| 
       2552 
2549 
     | 
    
         
             
                  sendBitcoin: sendBitcoin2
         
     | 
| 
       2553 
2550 
     | 
    
         
             
                };
         
     | 
| 
       2554 
2551 
     | 
    
         
             
              }, [
         
     | 
| 
       2555 
2552 
     | 
    
         
             
                accounts,
         
     | 
| 
       2556 
     | 
    
         
            -
                context,
         
     | 
| 
       2557 
     | 
    
         
            -
                disconnect,
         
     | 
| 
       2558 
2553 
     | 
    
         
             
                getNetwork2,
         
     | 
| 
       2559 
2554 
     | 
    
         
             
                switchNetwork,
         
     | 
| 
      
 2555 
     | 
    
         
            +
                sendBitcoin2,
         
     | 
| 
       2560 
2556 
     | 
    
         
             
                openConnectModal,
         
     | 
| 
       2561 
2557 
     | 
    
         
             
                requestDirectAccount,
         
     | 
| 
       2562 
     | 
    
         
            -
                 
     | 
| 
      
 2558 
     | 
    
         
            +
                context,
         
     | 
| 
      
 2559 
     | 
    
         
            +
                disconnect
         
     | 
| 
       2563 
2560 
     | 
    
         
             
              ]);
         
     | 
| 
       2564 
2561 
     | 
    
         
             
              return hook;
         
     | 
| 
       2565 
2562 
     | 
    
         
             
            }
         
     | 
| 
         @@ -3497,6 +3494,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({ 
     | 
|
| 
       3497 
3494 
     | 
    
         
             
                getAccounts,
         
     | 
| 
       3498 
3495 
     | 
    
         
             
                verifyOwner,
         
     | 
| 
       3499 
3496 
     | 
    
         
             
                signMessage,
         
     | 
| 
      
 3497 
     | 
    
         
            +
                isSignedIn,
         
     | 
| 
       3500 
3498 
     | 
    
         
             
                signAndSendTransaction,
         
     | 
| 
       3501 
3499 
     | 
    
         
             
                signAndSendTransactions
         
     | 
| 
       3502 
3500 
     | 
    
         
             
              };
         
     | 
| 
         @@ -3504,25 +3502,43 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({ 
     | 
|
| 
       3504 
3502 
     | 
    
         
             
              const currentConfig = isDev ? walletConfig.dev : walletConfig[options.network.networkId];
         
     | 
| 
       3505 
3503 
     | 
    
         
             
              const walletNetwork = isDev ? "dev" : options.network.networkId;
         
     | 
| 
       3506 
3504 
     | 
    
         
             
              yield initBtcContext();
         
     | 
| 
       3507 
     | 
    
         
            -
              function setupBtcContextListeners( 
     | 
| 
      
 3505 
     | 
    
         
            +
              function setupBtcContextListeners() {
         
     | 
| 
       3508 
3506 
     | 
    
         
             
                return __async(this, null, function* () {
         
     | 
| 
       3509 
     | 
    
         
            -
                  const  
     | 
| 
      
 3507 
     | 
    
         
            +
                  const handleConnectionUpdate = () => __async(this, null, function* () {
         
     | 
| 
      
 3508 
     | 
    
         
            +
                    yield checkBtcNetwork(walletNetwork);
         
     | 
| 
      
 3509 
     | 
    
         
            +
                    const accountId = state.getAccount();
         
     | 
| 
      
 3510 
     | 
    
         
            +
                    const btcContext = window.btcContext;
         
     | 
| 
      
 3511 
     | 
    
         
            +
                    if (accountId && btcContext.account) {
         
     | 
| 
      
 3512 
     | 
    
         
            +
                      setupWalletButton(walletNetwork, wallet, btcContext);
         
     | 
| 
      
 3513 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 3514 
     | 
    
         
            +
                      removeWalletButton();
         
     | 
| 
      
 3515 
     | 
    
         
            +
                      setTimeout(() => {
         
     | 
| 
      
 3516 
     | 
    
         
            +
                        handleConnectionUpdate();
         
     | 
| 
      
 3517 
     | 
    
         
            +
                      }, 5e3);
         
     | 
| 
      
 3518 
     | 
    
         
            +
                    }
         
     | 
| 
      
 3519 
     | 
    
         
            +
                  });
         
     | 
| 
      
 3520 
     | 
    
         
            +
                  const context = window.btcContext.getContext();
         
     | 
| 
       3510 
3521 
     | 
    
         
             
                  context.on("updatePublicKey", (btcPublicKey) => __async(this, null, function* () {
         
     | 
| 
       3511 
     | 
    
         
            -
                     
     | 
| 
       3512 
     | 
    
         
            -
                     
     | 
| 
       3513 
     | 
    
         
            -
                    initConnected(walletNetwork, wallet);
         
     | 
| 
      
 3522 
     | 
    
         
            +
                    console.log("updatePublicKey");
         
     | 
| 
      
 3523 
     | 
    
         
            +
                    const { nearAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
         
     | 
| 
       3514 
3524 
     | 
    
         
             
                    emitter.emit("accountsChanged", {
         
     | 
| 
       3515 
     | 
    
         
            -
                      accounts: [{ accountId:  
     | 
| 
      
 3525 
     | 
    
         
            +
                      accounts: [{ accountId: nearAddress }]
         
     | 
| 
       3516 
3526 
     | 
    
         
             
                    });
         
     | 
| 
      
 3527 
     | 
    
         
            +
                    yield handleConnectionUpdate();
         
     | 
| 
       3517 
3528 
     | 
    
         
             
                  }));
         
     | 
| 
       3518 
3529 
     | 
    
         
             
                  context.on("btcLoginError", () => __async(this, null, function* () {
         
     | 
| 
      
 3530 
     | 
    
         
            +
                    console.log("btcLoginError");
         
     | 
| 
       3519 
3531 
     | 
    
         
             
                    emitter.emit("accountsChanged", { accounts: [] });
         
     | 
| 
      
 3532 
     | 
    
         
            +
                    yield handleConnectionUpdate();
         
     | 
| 
       3520 
3533 
     | 
    
         
             
                  }));
         
     | 
| 
       3521 
3534 
     | 
    
         
             
                  context.on("btcLogOut", () => __async(this, null, function* () {
         
     | 
| 
      
 3535 
     | 
    
         
            +
                    console.log("btcLogOut");
         
     | 
| 
       3522 
3536 
     | 
    
         
             
                    emitter.emit("accountsChanged", { accounts: [] });
         
     | 
| 
      
 3537 
     | 
    
         
            +
                    yield handleConnectionUpdate();
         
     | 
| 
       3523 
3538 
     | 
    
         
             
                  }));
         
     | 
| 
      
 3539 
     | 
    
         
            +
                  yield handleConnectionUpdate();
         
     | 
| 
       3524 
3540 
     | 
    
         
             
                  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
         
     | 
| 
       3525 
     | 
    
         
            -
                    yield btcContext.autoConnect();
         
     | 
| 
      
 3541 
     | 
    
         
            +
                    yield window.btcContext.autoConnect();
         
     | 
| 
       3526 
3542 
     | 
    
         
             
                  }
         
     | 
| 
       3527 
3543 
     | 
    
         
             
                });
         
     | 
| 
       3528 
3544 
     | 
    
         
             
              }
         
     | 
| 
         @@ -3543,7 +3559,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({ 
     | 
|
| 
       3543 
3559 
     | 
    
         
             
                      delayMs: 500
         
     | 
| 
       3544 
3560 
     | 
    
         
             
                    }
         
     | 
| 
       3545 
3561 
     | 
    
         
             
                  );
         
     | 
| 
       3546 
     | 
    
         
            -
                  yield setupBtcContextListeners( 
     | 
| 
      
 3562 
     | 
    
         
            +
                  yield setupBtcContextListeners();
         
     | 
| 
       3547 
3563 
     | 
    
         
             
                  return btcContext;
         
     | 
| 
       3548 
3564 
     | 
    
         
             
                });
         
     | 
| 
       3549 
3565 
     | 
    
         
             
              }
         
     | 
| 
         @@ -3554,22 +3570,22 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({ 
     | 
|
| 
       3554 
3570 
     | 
    
         
             
              }
         
     | 
| 
       3555 
3571 
     | 
    
         
             
              function getNearAccountByBtcPublicKey(btcPublicKey) {
         
     | 
| 
       3556 
3572 
     | 
    
         
             
                return __async(this, null, function* () {
         
     | 
| 
       3557 
     | 
    
         
            -
                  const  
     | 
| 
      
 3573 
     | 
    
         
            +
                  const nearAddress = yield nearCall2(
         
     | 
| 
       3558 
3574 
     | 
    
         
             
                    currentConfig.accountContractId,
         
     | 
| 
       3559 
3575 
     | 
    
         
             
                    "get_chain_signature_near_account_id",
         
     | 
| 
       3560 
3576 
     | 
    
         
             
                    { btc_public_key: btcPublicKey }
         
     | 
| 
       3561 
3577 
     | 
    
         
             
                  );
         
     | 
| 
       3562 
     | 
    
         
            -
                  const  
     | 
| 
      
 3578 
     | 
    
         
            +
                  const nearPublicKey = yield nearCall2(
         
     | 
| 
       3563 
3579 
     | 
    
         
             
                    currentConfig.accountContractId,
         
     | 
| 
       3564 
3580 
     | 
    
         
             
                    "get_chain_signature_near_account_public_key",
         
     | 
| 
       3565 
3581 
     | 
    
         
             
                    { btc_public_key: btcPublicKey }
         
     | 
| 
       3566 
3582 
     | 
    
         
             
                  );
         
     | 
| 
       3567 
     | 
    
         
            -
                  state.saveAccount( 
     | 
| 
       3568 
     | 
    
         
            -
                  state.savePublicKey( 
     | 
| 
      
 3583 
     | 
    
         
            +
                  state.saveAccount(nearAddress);
         
     | 
| 
      
 3584 
     | 
    
         
            +
                  state.savePublicKey(nearPublicKey);
         
     | 
| 
       3569 
3585 
     | 
    
         
             
                  state.saveBtcPublicKey(btcPublicKey);
         
     | 
| 
       3570 
3586 
     | 
    
         
             
                  return {
         
     | 
| 
       3571 
     | 
    
         
            -
                     
     | 
| 
       3572 
     | 
    
         
            -
                     
     | 
| 
      
 3587 
     | 
    
         
            +
                    nearAddress,
         
     | 
| 
      
 3588 
     | 
    
         
            +
                    nearPublicKey
         
     | 
| 
       3573 
3589 
     | 
    
         
             
                  };
         
     | 
| 
       3574 
3590 
     | 
    
         
             
                });
         
     | 
| 
       3575 
3591 
     | 
    
         
             
              }
         
     | 
| 
         @@ -3587,12 +3603,11 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({ 
     | 
|
| 
       3587 
3603 
     | 
    
         
             
                  if (!btcPublicKey) {
         
     | 
| 
       3588 
3604 
     | 
    
         
             
                    throw new Error("No connected BTC wallet, please connect your BTC wallet first.");
         
     | 
| 
       3589 
3605 
     | 
    
         
             
                  }
         
     | 
| 
       3590 
     | 
    
         
            -
                  const {  
     | 
| 
       3591 
     | 
    
         
            -
                  initConnected(walletNetwork, wallet);
         
     | 
| 
      
 3606 
     | 
    
         
            +
                  const { nearAddress, nearPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
         
     | 
| 
       3592 
3607 
     | 
    
         
             
                  return [
         
     | 
| 
       3593 
3608 
     | 
    
         
             
                    {
         
     | 
| 
       3594 
     | 
    
         
            -
                      accountId:  
     | 
| 
       3595 
     | 
    
         
            -
                      publicKey:  
     | 
| 
      
 3609 
     | 
    
         
            +
                      accountId: nearAddress,
         
     | 
| 
      
 3610 
     | 
    
         
            +
                      publicKey: nearPublicKey
         
     | 
| 
       3596 
3611 
     | 
    
         
             
                    }
         
     | 
| 
       3597 
3612 
     | 
    
         
             
                  ];
         
     | 
| 
       3598 
3613 
     | 
    
         
             
                });
         
     | 
| 
         @@ -3607,13 +3622,17 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({ 
     | 
|
| 
       3607 
3622 
     | 
    
         
             
                  const btcContext = window.btcContext;
         
     | 
| 
       3608 
3623 
     | 
    
         
             
                  if (metadata.syncLogOut) {
         
     | 
| 
       3609 
3624 
     | 
    
         
             
                    btcContext.logout();
         
     | 
| 
       3610 
     | 
    
         
            -
                    yield delay(300);
         
     | 
| 
       3611 
3625 
     | 
    
         
             
                  }
         
     | 
| 
       3612 
3626 
     | 
    
         
             
                  state.clear();
         
     | 
| 
       3613 
3627 
     | 
    
         
             
                  window.localStorage.removeItem("near-wallet-selector:selectedWalletId");
         
     | 
| 
       3614 
3628 
     | 
    
         
             
                  removeWalletButton();
         
     | 
| 
       3615 
3629 
     | 
    
         
             
                });
         
     | 
| 
       3616 
3630 
     | 
    
         
             
              }
         
     | 
| 
      
 3631 
     | 
    
         
            +
              function isSignedIn() {
         
     | 
| 
      
 3632 
     | 
    
         
            +
                const accountId = state.getAccount();
         
     | 
| 
      
 3633 
     | 
    
         
            +
                const publicKey = state.getPublicKey();
         
     | 
| 
      
 3634 
     | 
    
         
            +
                return accountId && publicKey;
         
     | 
| 
      
 3635 
     | 
    
         
            +
              }
         
     | 
| 
       3617 
3636 
     | 
    
         
             
              function getAccounts() {
         
     | 
| 
       3618 
3637 
     | 
    
         
             
                return __async(this, null, function* () {
         
     | 
| 
       3619 
3638 
     | 
    
         
             
                  return [{ accountId: state.getAccount() }];
         
     | 
| 
         @@ -3847,22 +3866,20 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({ 
     | 
|
| 
       3847 
3866 
     | 
    
         
             
                  return { txBytes, txHex, hash };
         
     | 
| 
       3848 
3867 
     | 
    
         
             
                });
         
     | 
| 
       3849 
3868 
     | 
    
         
             
              }
         
     | 
| 
       3850 
     | 
    
         
            -
              function  
     | 
| 
      
 3869 
     | 
    
         
            +
              function checkBtcNetwork(network) {
         
     | 
| 
       3851 
3870 
     | 
    
         
             
                return __async(this, null, function* () {
         
     | 
| 
       3852 
     | 
    
         
            -
                  const  
     | 
| 
       3853 
     | 
    
         
            -
             
     | 
| 
       3854 
     | 
    
         
            -
                     
     | 
| 
       3855 
     | 
    
         
            -
             
     | 
| 
       3856 
     | 
    
         
            -
             
     | 
| 
       3857 
     | 
    
         
            -
             
     | 
| 
       3858 
     | 
    
         
            -
             
     | 
| 
       3859 
     | 
    
         
            -
             
     | 
| 
       3860 
     | 
    
         
            -
                        checkAndSetupWalletButton();
         
     | 
| 
       3861 
     | 
    
         
            -
                      }, 5e3);
         
     | 
| 
       3862 
     | 
    
         
            -
                    }
         
     | 
| 
      
 3871 
     | 
    
         
            +
                  const btcContext = window.btcContext;
         
     | 
| 
      
 3872 
     | 
    
         
            +
                  if (!btcContext.account)
         
     | 
| 
      
 3873 
     | 
    
         
            +
                    return;
         
     | 
| 
      
 3874 
     | 
    
         
            +
                  const btcNetwork = yield btcContext.getNetwork();
         
     | 
| 
      
 3875 
     | 
    
         
            +
                  console.log("btcNetwork:", btcNetwork, network);
         
     | 
| 
      
 3876 
     | 
    
         
            +
                  const networkMap = {
         
     | 
| 
      
 3877 
     | 
    
         
            +
                    livenet: ["mainnet"],
         
     | 
| 
      
 3878 
     | 
    
         
            +
                    testnet: ["testnet", "dev"]
         
     | 
| 
       3863 
3879 
     | 
    
         
             
                  };
         
     | 
| 
       3864 
     | 
    
         
            -
                   
     | 
| 
       3865 
     | 
    
         
            -
             
     | 
| 
      
 3880 
     | 
    
         
            +
                  if (!networkMap[btcNetwork].includes(network)) {
         
     | 
| 
      
 3881 
     | 
    
         
            +
                    yield btcContext.switchNetwork(btcNetwork === "livenet" ? "testnet" : "livenet");
         
     | 
| 
      
 3882 
     | 
    
         
            +
                  }
         
     | 
| 
       3866 
3883 
     | 
    
         
             
                });
         
     | 
| 
       3867 
3884 
     | 
    
         
             
              }
         
     | 
| 
       3868 
3885 
     | 
    
         
             
              return wallet;
         
     | 
| 
         @@ -3906,7 +3923,7 @@ function setupBTCWallet({ 
     | 
|
| 
       3906 
3923 
     | 
    
         | 
| 
       3907 
3924 
     | 
    
         
             
            // src/index.ts
         
     | 
| 
       3908 
3925 
     | 
    
         
             
            var getVersion = () => {
         
     | 
| 
       3909 
     | 
    
         
            -
              return "0.3. 
     | 
| 
      
 3926 
     | 
    
         
            +
              return "0.3.20";
         
     | 
| 
       3910 
3927 
     | 
    
         
             
            };
         
     | 
| 
       3911 
3928 
     | 
    
         
             
            if (typeof window !== "undefined") {
         
     | 
| 
       3912 
3929 
     | 
    
         
             
              window.__BTC_WALLET_VERSION = getVersion();
         
     |