tronlink-signer 0.1.0 → 0.1.1
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 +21 -0
- package/README.md +165 -0
- package/package.json +17 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TronLink
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# tronlink-signer
|
|
2
|
+
|
|
3
|
+
Standalone SDK for signing TRON transactions via the TronLink browser wallet. Private keys never leave TronLink — all signing happens in the browser through a local approval page.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install tronlink-signer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { TronSigner } from "tronlink-signer";
|
|
15
|
+
|
|
16
|
+
const signer = new TronSigner();
|
|
17
|
+
await signer.start();
|
|
18
|
+
|
|
19
|
+
const { address } = await signer.connectWallet();
|
|
20
|
+
const { txId } = await signer.sendTrx("TXxx...", 1);
|
|
21
|
+
const { balance } = await signer.getBalance("TXxx...");
|
|
22
|
+
|
|
23
|
+
await signer.stop();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API
|
|
27
|
+
|
|
28
|
+
### `new TronSigner(config?: Partial<AppConfig>)`
|
|
29
|
+
|
|
30
|
+
Creates a new signer instance. If no config is provided, it reads from environment variables via `loadConfig()`.
|
|
31
|
+
|
|
32
|
+
### `signer.start(): Promise<void>`
|
|
33
|
+
|
|
34
|
+
Starts the local HTTP server for browser approval.
|
|
35
|
+
|
|
36
|
+
### `signer.stop(): Promise<void>`
|
|
37
|
+
|
|
38
|
+
Stops the server and clears all pending requests.
|
|
39
|
+
|
|
40
|
+
### `signer.getConfig(): AppConfig`
|
|
41
|
+
|
|
42
|
+
Returns the current configuration.
|
|
43
|
+
|
|
44
|
+
### `signer.connectWallet(network?: TronNetwork): Promise<{ address: string }>`
|
|
45
|
+
|
|
46
|
+
Opens the browser to connect TronLink and retrieve the wallet address.
|
|
47
|
+
|
|
48
|
+
### `signer.sendTrx(to, amount, network?): Promise<{ txId: string }>`
|
|
49
|
+
|
|
50
|
+
Sends TRX to a recipient address. Opens a browser approval page for the user to confirm.
|
|
51
|
+
|
|
52
|
+
| Parameter | Type | Description |
|
|
53
|
+
| --------- | ---- | ----------- |
|
|
54
|
+
| `to` | `string` | Recipient Tron address (base58) |
|
|
55
|
+
| `amount` | `number` | Amount of TRX to send |
|
|
56
|
+
| `network` | `TronNetwork` | Optional network override |
|
|
57
|
+
|
|
58
|
+
### `signer.sendTrc20(contractAddress, to, amount, decimals?, network?): Promise<{ txId: string }>`
|
|
59
|
+
|
|
60
|
+
Sends TRC20 tokens. Opens a browser approval page.
|
|
61
|
+
|
|
62
|
+
| Parameter | Type | Description |
|
|
63
|
+
| --------- | ---- | ----------- |
|
|
64
|
+
| `contractAddress` | `string` | TRC20 token contract address |
|
|
65
|
+
| `to` | `string` | Recipient Tron address (base58) |
|
|
66
|
+
| `amount` | `string` | Amount in smallest unit |
|
|
67
|
+
| `decimals` | `number` | Token decimals (default: 6) |
|
|
68
|
+
| `network` | `TronNetwork` | Optional network override |
|
|
69
|
+
|
|
70
|
+
### `signer.signMessage(message, network?): Promise<{ signature: string }>`
|
|
71
|
+
|
|
72
|
+
Signs a plain text message.
|
|
73
|
+
|
|
74
|
+
### `signer.signTypedData(typedData, network?): Promise<{ signature: string }>`
|
|
75
|
+
|
|
76
|
+
Signs EIP-712 typed data.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const { signature } = await signer.signTypedData({
|
|
80
|
+
domain: { name: "MyDApp", version: "1", chainId: 728126428 },
|
|
81
|
+
types: {
|
|
82
|
+
Greeting: [{ name: "contents", type: "string" }],
|
|
83
|
+
},
|
|
84
|
+
primaryType: "Greeting",
|
|
85
|
+
message: { contents: "Hello Tron!" },
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `signer.signTransaction(transaction, network?): Promise<{ signedTransaction: Record<string, unknown> }>`
|
|
90
|
+
|
|
91
|
+
Signs a raw transaction without broadcasting it.
|
|
92
|
+
|
|
93
|
+
### `signer.getBalance(address, network?): Promise<{ balance: string; balanceSun: number }>`
|
|
94
|
+
|
|
95
|
+
Gets TRX balance for an address. No browser approval needed.
|
|
96
|
+
|
|
97
|
+
## How It Works
|
|
98
|
+
|
|
99
|
+
1. Your code calls a signing method (e.g., `signMessage`)
|
|
100
|
+
2. A local HTTP server starts on port 3386 and the browser opens an approval page
|
|
101
|
+
3. The approval page discovers the wallet via **TIP-6963** protocol (fallback to `window.tron`)
|
|
102
|
+
4. Auto-unlocks wallet and switches network if needed
|
|
103
|
+
5. User reviews and clicks Approve / Reject
|
|
104
|
+
6. TronLink handles signing in the browser
|
|
105
|
+
7. The result is returned to your code
|
|
106
|
+
|
|
107
|
+
The local server binds to `127.0.0.1` only. If port 3386 is in use, it auto-increments. Requests timeout after 5 minutes.
|
|
108
|
+
|
|
109
|
+
## Networks
|
|
110
|
+
|
|
111
|
+
All signing methods accept an optional `network` parameter:
|
|
112
|
+
|
|
113
|
+
| Network | Full Host | Explorer |
|
|
114
|
+
| ------- | --------- | -------- |
|
|
115
|
+
| `mainnet` (default) | `https://api.trongrid.io` | `https://tronscan.org` |
|
|
116
|
+
| `nile` | `https://nile.trongrid.io` | `https://nile.tronscan.org` |
|
|
117
|
+
| `shasta` | `https://api.shasta.trongrid.io` | `https://shasta.tronscan.org` |
|
|
118
|
+
|
|
119
|
+
## Environment Variables
|
|
120
|
+
|
|
121
|
+
| Variable | Description | Default |
|
|
122
|
+
| -------- | ----------- | ------- |
|
|
123
|
+
| `TRON_NETWORK` | Default network | `mainnet` |
|
|
124
|
+
| `TRON_HTTP_PORT` | Local HTTP server port | `3386` |
|
|
125
|
+
| `TRON_API_KEY` | TronGrid API key (optional) | - |
|
|
126
|
+
|
|
127
|
+
## Types
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
type TronNetwork = "mainnet" | "nile" | "shasta";
|
|
131
|
+
|
|
132
|
+
interface AppConfig {
|
|
133
|
+
network: TronNetwork;
|
|
134
|
+
httpPort: number;
|
|
135
|
+
apiKey?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface NetworkConfig {
|
|
139
|
+
name: string;
|
|
140
|
+
fullHost: string;
|
|
141
|
+
explorerUrl: string;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Exports
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
// Class
|
|
149
|
+
export { TronSigner } from "./tron-signer.js";
|
|
150
|
+
|
|
151
|
+
// Config
|
|
152
|
+
export { NETWORKS, DEFAULT_HTTP_PORT, REQUEST_TIMEOUT_MS, loadConfig } from "./config.js";
|
|
153
|
+
|
|
154
|
+
// Types
|
|
155
|
+
export type {
|
|
156
|
+
TronNetwork, NetworkConfig, AppConfig,
|
|
157
|
+
PendingRequestType, PendingRequest,
|
|
158
|
+
ConnectData, SendTrxData, SendTrc20Data,
|
|
159
|
+
SignMessageData, SignTypedDataData, SignTransactionData,
|
|
160
|
+
} from "./types.js";
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT License Copyright (c) 2026 TronLink
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tronlink-signer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "TronLink browser wallet signer SDK for TRON transactions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,21 +11,28 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsup",
|
|
16
|
-
"typecheck": "tsc --noEmit"
|
|
17
|
-
},
|
|
18
14
|
"keywords": [
|
|
19
15
|
"tron",
|
|
20
16
|
"tronlink",
|
|
17
|
+
"tronweb",
|
|
21
18
|
"wallet",
|
|
22
19
|
"signer",
|
|
20
|
+
"blockchain",
|
|
23
21
|
"tip-6963"
|
|
24
22
|
],
|
|
25
23
|
"files": [
|
|
26
24
|
"dist"
|
|
27
25
|
],
|
|
28
26
|
"license": "MIT",
|
|
27
|
+
"homepage": "https://github.com/TronLink/mcp-tronlink-signer/tree/main/packages/tronlink-signer#readme",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/TronLink/mcp-tronlink-signer.git",
|
|
31
|
+
"directory": "packages/tronlink-signer"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/TronLink/mcp-tronlink-signer/issues"
|
|
35
|
+
},
|
|
29
36
|
"engines": {
|
|
30
37
|
"node": ">=18"
|
|
31
38
|
},
|
|
@@ -39,5 +46,9 @@
|
|
|
39
46
|
"@types/node": "^25.5.0",
|
|
40
47
|
"tsup": "^8.5.1",
|
|
41
48
|
"typescript": "^5.7.3"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"typecheck": "tsc --noEmit"
|
|
42
53
|
}
|
|
43
|
-
}
|
|
54
|
+
}
|