btc-wallet 0.3.24 → 0.3.26

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/README.md CHANGED
@@ -1,29 +1,44 @@
1
1
  # BTC Wallet
2
2
 
3
- BTC Wallet is a toolkit that enables the use of Bitcoin on the NEAR blockchain through the Satoshi protocol. It provides seamless integration for managing Bitcoin transactions and interactions within the NEAR ecosystem.
4
-
5
- ## Features
6
-
7
- - **NEAR Integration**: Leverage the Satoshi protocol to use Bitcoin on the NEAR blockchain.
3
+ BTC Wallet is a toolkit that enables Bitcoin usage on the NEAR blockchain through the Satoshi protocol.
8
4
 
9
5
  ## Installation
10
6
 
11
- Install `btc-wallet` using npm or yarn:
12
-
13
7
  ```bash
14
8
  pnpm install btc-wallet
15
- or
9
+ # or
16
10
  yarn add btc-wallet
17
11
  ```
18
12
 
19
- ## Usage
13
+ ## API Reference
20
14
 
21
- ### Initialize BTC Wallet
15
+ ### `BtcWalletSelectorContextProvider` and `setupBTCWallet`
22
16
 
23
- To use BTC Wallet in your project, wrap your application with the `BtcWalletSelectorContextProvider`:
17
+ Initialize and integrate BTC wallet with NEAR wallet selector.
18
+
19
+ ```typescript
20
+ // 1. Setup wallet selector with BTC wallet module
21
+ import { setupWalletSelector } from '@near-wallet-selector/core';
22
+ import { setupBTCWallet } from 'btc-wallet';
23
+
24
+ const selector = await setupWalletSelector({
25
+ network: 'mainnet', // or 'testnet'
26
+ debug: true,
27
+ modules: [
28
+ setupBTCWallet({
29
+ iconUrl?: string, // optional: custom wallet icon URL
30
+ deprecated?: boolean, // optional: mark as deprecated
31
+ autoConnect?: boolean, // optional: enable auto-connect, defaults to true
32
+ syncLogOut?: boolean, // optional: sync logout across tabs, defaults to true
33
+ env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev' // optional: defaults to NEAR network environment
34
+ }),
35
+ // setup other wallets...
36
+ ],
37
+ });
38
+
39
+ // 2. Wrap your app with BtcWalletSelectorContextProvider
40
+ import { BtcWalletSelectorContextProvider } from 'btc-wallet';
24
41
 
25
- ```javascript
26
- import BtcWalletSelectorContextProvider from 'btc-wallet';
27
42
  function App() {
28
43
  return (
29
44
  <BtcWalletSelectorContextProvider>
@@ -33,31 +48,61 @@ function App() {
33
48
  }
34
49
  ```
35
50
 
36
- ### Setup Wallet Selector
51
+ ### `executeBTCDepositAndAction`
52
+
53
+ Execute a native BTC deposit to receive corresponding BTC tokens on NEAR through the Satoshi bridge. You must provide either `action` or `amount`, but not both.
54
+
55
+ ```typescript
56
+ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
57
+ // Option 1: For dApp one-click BTC deposit and action
58
+ action?: {
59
+ receiver_id: string; // receiver account on NEAR
60
+ amount: string; // amount to deposit
61
+ msg: string; // message for the transaction
62
+ };
63
+
64
+ // Option 2: For direct Satoshi bridge deposit
65
+ amount?: string; // amount to deposit to Satoshi bridge
66
+
67
+ // Common optional parameters
68
+ feeRate?: number; // optional: custom fee rate for the BTC transaction
69
+ fixedAmount?: boolean; // optional: whether to use fixed amount
70
+ env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev'; // optional: defaults to NEAR network environment
71
+ pollResult?: T; // optional: whether to poll for transaction result
72
+ }
37
73
 
38
- Integrate BTC Wallet with NEAR's wallet selector:
74
+ // Example 1: dApp one-click BTC deposit
75
+ await executeBTCDepositAndAction({
76
+ action: {
77
+ receiver_id: 'account.near',
78
+ amount: '1000000', // in smallest units
79
+ msg: 'Deposit'
80
+ },
81
+ feeRate: 5
82
+ });
39
83
 
40
- ```javascript
41
- import { setupWalletSelector } from '@near-wallet-selector/core';
42
- import { setupBTCWallet } from 'btc-wallet';
43
- setupWalletSelector({
44
- network: 'mainnet', // or 'testnet'
45
- modules: [setupBTCWallet()],
84
+ // Example 2: Direct Satoshi bridge deposit
85
+ await executeBTCDepositAndAction({
86
+ amount: '1000000', // amount to deposit to Satoshi bridge
87
+ feeRate: 5
46
88
  });
47
89
  ```
48
90
 
49
- ### Execute Burrow Supply
91
+ ### `getBtcBalance`
50
92
 
51
- To execute a Burrow supply operation, use the `executeBurrowSupply` function:
93
+ Get the native BTC balance for a given Bitcoin address.
52
94
 
53
- ```javascript
54
- import { executeBurrowSupply } from 'btc-wallet';
55
- executeBurrowSupply({
56
- amount: '0.01', // BTC amount
57
- environment: 'mainnet', // or 'testnet'
58
- }).then(() => {
59
- console.log('Burrow supply executed successfully');
60
- }).catch((error) => {
61
- console.error('Error executing Burrow supply:', error);
62
- });
95
+ ```typescript
96
+ import { getBtcBalance } from 'btc-wallet';
97
+
98
+ const balance = await getBtcBalance(address: string);
99
+ // Returns balance in satoshis
63
100
  ```
101
+
102
+ ## Requirements
103
+
104
+ - React 17.0.0 or higher
105
+
106
+ ## License
107
+
108
+ This project is licensed under the MIT License - see the LICENSE file for details.
package/dist/index.js CHANGED
@@ -2616,19 +2616,63 @@ var import_utils7 = require("@near-js/utils");
2616
2616
  var import_bs58 = __toESM(require("bs58"), 1);
2617
2617
  var import_js_sha256 = require("js-sha256");
2618
2618
 
2619
- // src/utils/initWalletButton.ts
2620
- var walletUrlConfig = {
2621
- dev: "https://wallet-dev.satoshibridge.top",
2622
- testnet: "https://wallet-test.satoshibridge.top",
2623
- mainnet: "https://wallet.satoshibridge.top"
2619
+ // src/config.ts
2620
+ var walletConfig = {
2621
+ dev: {
2622
+ base_url: "https://api.dev.satoshibridge.top",
2623
+ token: "nbtc-dev.testnet",
2624
+ accountContractId: "acc-dev.testnet",
2625
+ bridgeContractId: "brg-dev.testnet",
2626
+ walletUrl: "https://wallet-dev.satoshibridge.top",
2627
+ bridgeUrl: "https://dev.satoshibridge.top/"
2628
+ },
2629
+ testnet: {
2630
+ base_url: "https://api.testnet.satoshibridge.top",
2631
+ token: "nbtc2-nsp.testnet",
2632
+ accountContractId: "acc2-nsp.testnet",
2633
+ bridgeContractId: "brg2-nsp.testnet",
2634
+ walletUrl: "https://wallet-test.satoshibridge.top",
2635
+ bridgeUrl: "https://testnet.satoshibridge.top/"
2636
+ },
2637
+ private_mainnet: {
2638
+ base_url: "https://api.stg.satoshibridge.top",
2639
+ token: "nbtc.toalice.near",
2640
+ accountContractId: "acc.toalice.near",
2641
+ bridgeContractId: "brg.toalice.near",
2642
+ walletUrl: "https://wallet-stg.satoshibridge.top",
2643
+ bridgeUrl: "https://stg.satoshibridge.top/"
2644
+ },
2645
+ mainnet: {
2646
+ base_url: "https://api.mainnet.satoshibridge.top",
2647
+ token: "nbtc.toalice.near",
2648
+ accountContractId: "acc.toalice.near",
2649
+ bridgeContractId: "brg.toalice.near",
2650
+ walletUrl: "https://wallet.satoshibridge.top",
2651
+ bridgeUrl: "https://www.satoshibridge.top/"
2652
+ }
2624
2653
  };
2625
- function setupWalletButton(network, wallet, originalWallet) {
2654
+ var nearRpcUrls = {
2655
+ mainnet: [
2656
+ "https://near.lava.build",
2657
+ "https://rpc.mainnet.near.org",
2658
+ "https://free.rpc.fastnear.com",
2659
+ "https://near.drpc.org"
2660
+ ],
2661
+ testnet: ["https://rpc.testnet.near.org"]
2662
+ };
2663
+ var btcRpcUrls = {
2664
+ mainnet: "https://mempool.space/api",
2665
+ testnet: "https://mempool.space/testnet/api"
2666
+ };
2667
+
2668
+ // src/utils/initWalletButton.ts
2669
+ function setupWalletButton(env, wallet, originalWallet) {
2626
2670
  console.log("setupWalletButton");
2627
2671
  if (document.getElementById("satoshi-wallet-button")) {
2628
2672
  return;
2629
2673
  }
2630
2674
  const iframe = createIframe({
2631
- iframeUrl: walletUrlConfig[network],
2675
+ iframeUrl: walletConfig[env].walletUrl,
2632
2676
  iframeStyle: { width: "400px", height: "650px" }
2633
2677
  });
2634
2678
  iframe.addEventListener("mouseenter", () => {
@@ -2759,55 +2803,6 @@ function removeWalletButton() {
2759
2803
  iframe == null ? void 0 : iframe.remove();
2760
2804
  }
2761
2805
 
2762
- // src/config.ts
2763
- var walletConfig = {
2764
- dev: {
2765
- base_url: "https://api.dev.satoshibridge.top",
2766
- token: "nbtc-dev.testnet",
2767
- accountContractId: "acc-dev.testnet",
2768
- bridgeContractId: "brg-dev.testnet",
2769
- walletUrl: "https://wallet-dev.satoshibridge.top",
2770
- bridgeUrl: "https://dev.satoshibridge.top/"
2771
- },
2772
- testnet: {
2773
- base_url: "https://api.testnet.satoshibridge.top",
2774
- token: "nbtc2-nsp.testnet",
2775
- accountContractId: "acc2-nsp.testnet",
2776
- bridgeContractId: "brg2-nsp.testnet",
2777
- walletUrl: "https://wallet-test.satoshibridge.top",
2778
- bridgeUrl: "https://testnet.satoshibridge.top/"
2779
- },
2780
- private_mainnet: {
2781
- base_url: "https://api.stg.satoshibridge.top",
2782
- token: "nbtc.toalice.near",
2783
- accountContractId: "acc.toalice.near",
2784
- bridgeContractId: "brg.toalice.near",
2785
- walletUrl: "https://wallet-stg.satoshibridge.top",
2786
- bridgeUrl: "https://stg.satoshibridge.top/"
2787
- },
2788
- mainnet: {
2789
- base_url: "https://api.mainnet.satoshibridge.top",
2790
- token: "nbtc.toalice.near",
2791
- accountContractId: "acc.toalice.near",
2792
- bridgeContractId: "brg.toalice.near",
2793
- walletUrl: "https://wallet.satoshibridge.top",
2794
- bridgeUrl: "https://www.satoshibridge.top/"
2795
- }
2796
- };
2797
- var nearRpcUrls = {
2798
- mainnet: [
2799
- "https://near.lava.build",
2800
- "https://rpc.mainnet.near.org",
2801
- "https://free.rpc.fastnear.com",
2802
- "https://near.drpc.org"
2803
- ],
2804
- testnet: ["https://rpc.testnet.near.org"]
2805
- };
2806
- var btcRpcUrls = {
2807
- mainnet: "https://mempool.space/api",
2808
- testnet: "https://mempool.space/testnet/api"
2809
- };
2810
-
2811
2806
  // src/utils/nearUtils.ts
2812
2807
  var import_near_api_js = require("near-api-js");
2813
2808
  function nearCallFunction(contractId, methodName, args, options) {
@@ -3579,7 +3574,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3579
3574
  signAndSendTransaction,
3580
3575
  signAndSendTransactions
3581
3576
  };
3582
- const env = options.network.networkId || metadata.env || "mainnet";
3577
+ const env = metadata.env || options.network.networkId || "mainnet";
3583
3578
  const currentConfig = walletConfig[env];
3584
3579
  const walletNetwork = ["mainnet", "private_mainnet"].includes(env) ? "mainnet" : "testnet";
3585
3580
  yield initBtcContext();
@@ -3590,7 +3585,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3590
3585
  const accountId = state.getAccount();
3591
3586
  const btcContext = window.btcContext;
3592
3587
  if (accountId && btcContext.account) {
3593
- setupWalletButton(walletNetwork, wallet, btcContext);
3588
+ setupWalletButton(env, wallet, btcContext);
3594
3589
  } else {
3595
3590
  removeWalletButton();
3596
3591
  setTimeout(() => {
@@ -3949,7 +3944,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3949
3944
  if (!btcContext.account)
3950
3945
  return;
3951
3946
  const btcNetwork = yield btcContext.getNetwork();
3952
- console.log("btcNetwork:", btcNetwork, network);
3953
3947
  const networkMap = {
3954
3948
  livenet: ["mainnet", "private_mainnet"],
3955
3949
  testnet: ["testnet", "dev"]
@@ -3976,7 +3970,7 @@ function setupBTCWallet({
3976
3970
  syncLogOut = true,
3977
3971
  env = "mainnet"
3978
3972
  } = {}) {
3979
- console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion());
3973
+ console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
3980
3974
  const btcWallet = () => __async(this, null, function* () {
3981
3975
  return {
3982
3976
  id: "btc-wallet",
@@ -4000,7 +3994,7 @@ function setupBTCWallet({
4000
3994
 
4001
3995
  // src/index.ts
4002
3996
  var getVersion = () => {
4003
- return "0.3.24";
3997
+ return "0.3.26";
4004
3998
  };
4005
3999
  if (typeof window !== "undefined") {
4006
4000
  window.__BTC_WALLET_VERSION = getVersion();