tronweb-mobile 6.2.1-m-2.0.3

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2022 tronweb3
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # tronweb-mobile
2
+
3
+ tronweb-mobile is a JavaScript library provided for use within the **TronLink App**, designed to integrate Tron-related capabilities into DApp environments.
4
+
5
+ The library is based on [TronWeb](https://tronweb.network), integrating its methods and functions while overriding signature-related capabilities. This allows DApps to invoke **TronLink App’s internal signing workflow** directly through global objects.
6
+
7
+ ## Features
8
+
9
+ - Integrates core methods and functions from [TronWeb](https://tronweb.network)
10
+ - Automatically injected into the page environment when a DApp is opened in the TronLink App
11
+ - Exposes unified global objects to maintain compatibility with existing Tron DApps
12
+ - Overrides signature methods so that all signing operations are handled internally by the TronLink App
13
+ - Supports TIP-6963 multi injected provider discovery for seamless wallet detection
14
+
15
+ ## Injection Mechanism
16
+
17
+ When a user opens a DApp using the **TronLink App**:
18
+
19
+ - `tronweb-mobile.js` is automatically injected into the WebView
20
+ - DApps do not need to manually import or initialize the library
21
+ - The TronLink App's capabilities can be accessed directly through global objects
22
+
23
+ ## Global Objects
24
+
25
+ tronweb-mobile injects the following global objects into the page environment:
26
+
27
+ - `window.tronWeb`
28
+ - `window.tron`
29
+ - `window.tronLink`
30
+
31
+ DApps can use these objects to interact with the Tron network and perform signing operations.
32
+
33
+ ## Overridden Signature Methods
34
+
35
+ tronweb-mobile overrides and intercepts the following signature-related methods:
36
+
37
+ - `sign`
38
+ - `multiSign`
39
+ - `signTransaction`
40
+ - `signMessageV2`
41
+ - `_signTypedData`
42
+
43
+ When a DApp invokes any of these methods, the process is as follows:
44
+
45
+ 1. The call is intercepted by tronweb-mobile
46
+ 2. The request is forwarded to the TronLink App via global objects (`tron`, `tronLink`, or `tronWeb`)
47
+ 3. The TronLink App prompts the user for confirmation and completes the signing process internally
48
+ 4. The signature result is returned to the DApp
49
+
50
+ All signing operations are completed inside the TronLink App. DApps never have direct access to the user’s private keys.
51
+
52
+ ## TIP-6963: Multi Injected Provider Discovery
53
+
54
+ tronweb-mobile implements [TIP-6963](https://github.com/tronprotocol/tips), a provider discovery protocol mirroring [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963) for the TRON ecosystem. It allows DApps to discover injected wallet providers via window events rather than relying on the race condition of `window.tronWeb`.
55
+
56
+ ### How It Works
57
+
58
+ 1. **Wallet announces** — On initialization, tronweb-mobile dispatches a `TIP6963:announceProvider` event containing provider info (`uuid`, `name`, `icon`, `rdns`) and the provider object
59
+ 2. **DApp requests** — A DApp dispatches `TIP6963:requestProvider` to request announcement from all available wallets
60
+ 3. **Wallet re-announces** — tronweb-mobile listens for `TIP6963:requestProvider` and re-announces itself
61
+
62
+ ### DApp Integration
63
+
64
+ ```javascript
65
+ // Discover all injected TRON wallets
66
+ window.addEventListener('TIP6963:announceProvider', (event) => {
67
+ const { info, provider } = event.detail;
68
+ console.log(`Discovered wallet: ${info.name} (${info.rdns})`);
69
+ // Use `provider` to interact with the wallet
70
+ });
71
+
72
+ // Trigger discovery
73
+ window.dispatchEvent(new Event('TIP6963:requestProvider'));
74
+ ```
75
+
76
+ ### Provider Info
77
+
78
+ | Field | Value |
79
+ |--------|-------------------|
80
+ | `name` | TronLink |
81
+ | `rdns` | io.tronlink |
82
+ | `uuid` | (per-session UUID) |
83
+ | `icon` | TronLink logo |
84
+
85
+ ## Usage Examples
86
+
87
+ To get started, retrieve the global objects in your JavaScript file:
88
+
89
+ ```javascript
90
+ const { tronWeb, tron, tronLink } = window;
91
+ ```
92
+
93
+ Transaction signing example:
94
+
95
+ ```javascript
96
+ const signedTx = await tronWeb.trx.sign(transaction)
97
+ ```
98
+
99
+ Message signing example:
100
+
101
+ ```javascript
102
+ const signature = await tronWeb.trx.signMessageV2(message)
103
+ ```
104
+
105
+ When running inside the TronLink App environment, the above calls will automatically trigger the in-app signing confirmation flow.
106
+
107
+ ## Applicable Scenarios
108
+
109
+ - DApps running inside the **TronLink App WebView**
110
+ - Decentralized applications that need to interact with the Tron network
111
+ - Projects built on [TronWeb](https://tronweb.network) that require API compatibility
112
+
113
+ ## Notes
114
+
115
+ - tronweb-mobile is only injected in the **TronLink App environment**
116
+ - The library will not be available in standard browser environments
117
+ - DApps should check for the existence of `window.tronWeb` or `window.tronLink` at runtime
118
+
119
+ ## Contribution
120
+
121
+ If you would like to contribute to tronweb-mobile, you can follow these steps:
122
+
123
+ ### Prerequisites
124
+
125
+ - **Node.js**: `v18.19.0` (recommended to use [nvm](https://github.com/nvm-sh/nvm) for version management)
126
+ - **pnpm**: `v7.32.0` (install via `npm install -g pnpm@7.32.0`)
127
+
128
+ ### Steps
129
+
130
+ - Fork this repository and clone it locally
131
+ - Install the dependencies: `pnpm install`
132
+ - Make your changes to the code
133
+ - Build the tronweb-mobile distribution files: `pnpm build`
134
+ - (Optional) Open a DApp inside the TronLink App to verify that the injection works correctly
135
+ - Run the tests: `pnpm test`
136
+ - Push your changes and submit a Pull Request
137
+
138
+ ## License
139
+
140
+ [MIT](https://opensource.org/licenses/MIT)