btc-wallet 0.5.99-beta → 0.6.0-beta

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.
@@ -28,6 +28,12 @@ export declare function getBtcBalance(account?: string): Promise<{
28
28
  }>;
29
29
  export declare function sendBitcoin(address: string, amount: number, feeRate: number): Promise<string>;
30
30
  export declare function getPublicKeyBase58(): Promise<any>;
31
+ export declare function getAddressByPublicKeyBase58(btcPublicKeyBase58: string): {
32
+ p2pkh: string | undefined;
33
+ p2sh: string | undefined;
34
+ p2wpkh: string | undefined;
35
+ p2wsh: string | undefined;
36
+ };
31
37
  export declare function signMessage(message: string): Promise<{
32
38
  signature: string;
33
39
  publicKey: string;
package/dist/index.js CHANGED
@@ -115,6 +115,7 @@ __export(src_exports, {
115
115
  checkSatoshiWhitelist: () => checkSatoshiWhitelist,
116
116
  estimateDepositAmount: () => estimateDepositAmount,
117
117
  executeBTCDepositAndAction: () => executeBTCDepositAndAction,
118
+ getAddressByPublicKeyBase58: () => getAddressByPublicKeyBase58,
118
119
  getBtcBalance: () => getBtcBalance,
119
120
  getBtcGasPrice: () => getBtcGasPrice,
120
121
  getBtcUtxos: () => getBtcUtxos,
@@ -2527,12 +2528,22 @@ var ConnectProvider = ({
2527
2528
  }, [options.aaOptions.accountContracts, accountContract]);
2528
2529
  const connector = (0, import_react10.useMemo)(() => getConnector(), [connectorId, connectors]);
2529
2530
  const getPublicKey = (0, import_react10.useCallback)(() => __async(void 0, null, function* () {
2531
+ var _a2;
2530
2532
  const connector2 = getConnector();
2531
2533
  if (!connector2) {
2532
2534
  throw new Error("Wallet not connected!");
2533
2535
  }
2534
- const pubKey = yield connector2.getPublicKey();
2535
- return pubKey;
2536
+ try {
2537
+ const pubKey = yield connector2.getPublicKey();
2538
+ return pubKey;
2539
+ } catch (error) {
2540
+ console.error("[BTC Wallet] getPublicKey error:", error);
2541
+ if ((_a2 = error.message) == null ? void 0 : _a2.includes("is not install")) {
2542
+ setConnectorId(void 0);
2543
+ setAccounts([]);
2544
+ }
2545
+ throw error;
2546
+ }
2536
2547
  }), [getConnector]);
2537
2548
  const signMessage2 = (0, import_react10.useCallback)(
2538
2549
  (message) => __async(void 0, null, function* () {
@@ -2555,11 +2566,21 @@ var ConnectProvider = ({
2555
2566
  [connector]
2556
2567
  );
2557
2568
  const getNetwork2 = (0, import_react10.useCallback)(() => __async(void 0, null, function* () {
2569
+ var _a2;
2558
2570
  if (!connector) {
2559
2571
  throw new Error("Wallet not connected!");
2560
2572
  }
2561
- const network = yield connector.getNetwork();
2562
- return network;
2573
+ try {
2574
+ const network = yield connector.getNetwork();
2575
+ return network;
2576
+ } catch (error) {
2577
+ console.error("[BTC Wallet] getNetwork error:", error);
2578
+ if ((_a2 = error.message) == null ? void 0 : _a2.includes("is not install")) {
2579
+ setConnectorId(void 0);
2580
+ setAccounts([]);
2581
+ }
2582
+ throw error;
2583
+ }
2563
2584
  }), [connector]);
2564
2585
  const switchNetwork = (0, import_react10.useCallback)(
2565
2586
  (network) => __async(void 0, null, function* () {
@@ -2593,26 +2614,50 @@ var ConnectProvider = ({
2593
2614
  }, [options, evmSupportChainIds, getPublicKey, signMessage2, accountContract]);
2594
2615
  const requestAccount = (0, import_react10.useCallback)(
2595
2616
  (connector2) => __async(void 0, null, function* () {
2596
- let accounts2 = yield connector2.getAccounts();
2597
- if (accounts2.length === 0 && autoConnect) {
2598
- accounts2 = yield connector2.requestAccounts();
2617
+ var _a2;
2618
+ try {
2619
+ let accounts2 = yield connector2.getAccounts();
2620
+ if (accounts2.length === 0 && autoConnect) {
2621
+ accounts2 = yield connector2.requestAccounts();
2622
+ }
2623
+ setAccounts(accounts2);
2624
+ } catch (error) {
2625
+ console.error("[BTC Wallet] requestAccount error:", error);
2626
+ if ((_a2 = error.message) == null ? void 0 : _a2.includes("is not install")) {
2627
+ setConnectorId(void 0);
2628
+ }
2629
+ setAccounts([]);
2630
+ throw error;
2599
2631
  }
2600
- setAccounts(accounts2);
2601
2632
  }),
2602
2633
  [autoConnect]
2603
2634
  );
2604
2635
  const requestDirectAccount = (0, import_react10.useCallback)((connector2) => __async(void 0, null, function* () {
2605
- let accounts2 = yield connector2.getAccounts();
2606
- if (accounts2.length === 0) {
2607
- accounts2 = yield connector2.requestAccounts();
2636
+ var _a2;
2637
+ try {
2638
+ let accounts2 = yield connector2.getAccounts();
2639
+ if (accounts2.length === 0) {
2640
+ accounts2 = yield connector2.requestAccounts();
2641
+ }
2642
+ setAccounts(accounts2);
2643
+ return accounts2;
2644
+ } catch (error) {
2645
+ console.error("[BTC Wallet] requestDirectAccount error:", error);
2646
+ if ((_a2 = error.message) == null ? void 0 : _a2.includes("is not install")) {
2647
+ setConnectorId(void 0);
2648
+ setAccounts([]);
2649
+ }
2650
+ throw error;
2608
2651
  }
2609
- setAccounts(accounts2);
2610
- return accounts2;
2611
2652
  }), []);
2612
2653
  (0, import_react10.useEffect)(() => {
2613
2654
  if (connector) {
2614
2655
  requestAccount(connector).catch((e) => {
2615
- console.error("get account error", e);
2656
+ var _a2;
2657
+ console.error("[BTC Wallet] requestAccount error:", e);
2658
+ if ((_a2 = e.message) == null ? void 0 : _a2.includes("is not install")) {
2659
+ setConnectorId(void 0);
2660
+ }
2616
2661
  setAccounts([]);
2617
2662
  });
2618
2663
  } else {
@@ -2923,6 +2968,13 @@ function useBtcWalletSelector() {
2923
2968
  eventCache.lastProcessedTime = now;
2924
2969
  getPublicKey().then((res) => {
2925
2970
  context.emit("updatePublicKey", res);
2971
+ }).catch((error) => {
2972
+ var _a;
2973
+ console.error("[BTC Wallet] getPublicKey failed in accountsChanged:", error);
2974
+ if ((_a = error.message) == null ? void 0 : _a.includes("is not install")) {
2975
+ disconnect == null ? void 0 : disconnect();
2976
+ context.emit("btcLogOut");
2977
+ }
2926
2978
  });
2927
2979
  };
2928
2980
  connector == null ? void 0 : connector.on("accountsChanged", handleAccountsChanged);
@@ -2951,7 +3003,6 @@ function useBtcWalletSelector() {
2951
3003
  );
2952
3004
  return account || null;
2953
3005
  } catch (error) {
2954
- console.error("btcLoginError", error);
2955
3006
  context.emit("btcLoginError");
2956
3007
  return null;
2957
3008
  }
@@ -3998,6 +4049,21 @@ function getPublicKeyBase58() {
3998
4049
  return publicKeyBase58;
3999
4050
  });
4000
4051
  }
4052
+ function getAddressByPublicKeyBase58(btcPublicKeyBase58) {
4053
+ const publicKey = import_bs582.default.decode(btcPublicKeyBase58);
4054
+ const uncompressedPublicKey = Buffer.concat([Buffer.from([4]), publicKey]);
4055
+ const compressedPublicKeyUint8 = ecc.pointCompress(uncompressedPublicKey, true);
4056
+ const compressedPublicKey = Buffer.from(compressedPublicKeyUint8);
4057
+ const p2pkh = bitcoin.payments.p2pkh({ pubkey: uncompressedPublicKey }).address;
4058
+ const p2sh = bitcoin.payments.p2sh({
4059
+ redeem: bitcoin.payments.p2pkh({ pubkey: uncompressedPublicKey })
4060
+ }).address;
4061
+ const p2wpkh = bitcoin.payments.p2wpkh({ pubkey: compressedPublicKey }).address;
4062
+ const p2wsh = bitcoin.payments.p2wsh({
4063
+ redeem: bitcoin.payments.p2pkh({ pubkey: compressedPublicKey })
4064
+ }).address;
4065
+ return { p2pkh, p2sh, p2wpkh, p2wsh };
4066
+ }
4001
4067
  function signMessage(message) {
4002
4068
  return __async(this, null, function* () {
4003
4069
  const { signMessage: signMessage2, getPublicKey } = getBtcProvider();
@@ -5450,7 +5516,7 @@ function getGroup(state) {
5450
5516
 
5451
5517
  // src/index.ts
5452
5518
  var getVersion = () => {
5453
- return "0.5.99-beta";
5519
+ return "0.6.0-beta";
5454
5520
  };
5455
5521
  if (typeof window !== "undefined") {
5456
5522
  window.__BTC_WALLET_VERSION = getVersion();