@neuraiproject/neurai-depin-terminal 1.0.0
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 +195 -0
- package/config.example.json +10 -0
- package/dist/index.cjs +218 -0
- package/package.json +61 -0
- package/src/config/ConfigManager.js +363 -0
- package/src/constants.js +208 -0
- package/src/errors.js +149 -0
- package/src/index.js +528 -0
- package/src/lib/depinMsgLoader.js +73 -0
- package/src/lib/empty.js +2 -0
- package/src/messaging/MessagePoller.js +300 -0
- package/src/messaging/MessageSender.js +194 -0
- package/src/messaging/MessageStore.js +99 -0
- package/src/services/RpcService.js +200 -0
- package/src/ui/TerminalUI.js +272 -0
- package/src/ui/components/ErrorOverlay.js +99 -0
- package/src/ui/components/InputBox.js +63 -0
- package/src/ui/components/MessageBox.js +51 -0
- package/src/ui/components/StatusBar.js +32 -0
- package/src/ui/components/TopBar.js +63 -0
- package/src/utils.js +309 -0
- package/src/wallet/WalletManager.js +94 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 NeuraiProject
|
|
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,195 @@
|
|
|
1
|
+
# Neurai DePIN Terminal
|
|
2
|
+
|
|
3
|
+
Terminal client for Neurai DePIN messaging with full-screen interface.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ Full-screen terminal interface with blessed
|
|
8
|
+
- ✅ Simple configuration via `config.json`
|
|
9
|
+
- ✅ **Encrypted private key storage** with AES-256-GCM encryption
|
|
10
|
+
- ✅ Automatic broadcast to all token holders
|
|
11
|
+
- ✅ Full support for server privacy layer (`depinpoolpkey`)
|
|
12
|
+
- ✅ Automatic polling every 10 seconds (configurable)
|
|
13
|
+
- ✅ Proper message deduplication
|
|
14
|
+
- ✅ Robust error handling and reconnection
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- Node.js v22 or higher
|
|
19
|
+
- A DePIN token on the Neurai network
|
|
20
|
+
- WIF private key of an address that owns the token
|
|
21
|
+
- Access to a Neurai DePIN RPC server
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
### Install from npm
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install -g @neuraiproject/neurai-depin-terminal
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then run:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
neurai-depin-terminal
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
cd docs/neurai-depin-client
|
|
39
|
+
npm install
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Configuration
|
|
43
|
+
|
|
44
|
+
When you run the application for the first time, an interactive wizard will start and create the `config.json` file:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm start
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The wizard will ask you for:
|
|
51
|
+
|
|
52
|
+
1. **RPC Server**: DePIN RPC server URL (required)
|
|
53
|
+
2. **RPC Username**: RPC username (optional, leave empty if not required)
|
|
54
|
+
3. **RPC Password**: RPC password (optional, leave empty if not required)
|
|
55
|
+
4. **DePIN Token**: Asset name (any valid Neurai asset)
|
|
56
|
+
5. **Private Key**: Your private key in WIF format
|
|
57
|
+
6. **Encryption Password**: Password to encrypt your private key (4-30 characters, required)
|
|
58
|
+
7. **Polling Interval**: Interval in milliseconds to check for new messages (default: 10000)
|
|
59
|
+
|
|
60
|
+
**Important:** Your private key will be encrypted with AES-256-GCM using the password you provide. You will need to enter this password every time you start the application. The decrypted key is kept in memory only and never saved unencrypted.
|
|
61
|
+
|
|
62
|
+
### Example config.json
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"rpc_url": "https://rpc-depin.neurai.org",
|
|
67
|
+
"rpc_username": "",
|
|
68
|
+
"rpc_password": "",
|
|
69
|
+
"token": "MYTOKEN",
|
|
70
|
+
"privateKey": "a1b2c3...encrypted_data...xyz789",
|
|
71
|
+
"network": "xna",
|
|
72
|
+
"pollInterval": 10000
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Note:** The `privateKey` field contains the encrypted private key in the format `salt:iv:authTag:encrypted` (all in hex, colon-separated). This is automatically created by the wizard when you provide your encryption password.
|
|
77
|
+
|
|
78
|
+
**Note:** The `/rpc` path is automatically appended by the application, so just provide the base URL (e.g., `https://rpc-depin.neurai.org` or `https://rpc-depin.neurai.org:19001`).
|
|
79
|
+
|
|
80
|
+
## Usage
|
|
81
|
+
|
|
82
|
+
Once configured, simply run:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm start
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Building Binaries
|
|
89
|
+
|
|
90
|
+
You can create standalone executables for Linux, macOS, and Windows:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm run build
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The binaries will be generated in the `bin/` directory. This allows you to run the application without having Node.js installed on the target machine.
|
|
97
|
+
|
|
98
|
+
**Note:** The build process uses `esbuild` to bundle the source code and `pkg` to create the executables.
|
|
99
|
+
|
|
100
|
+
### Password Prompt: On startup, you will be prompted to enter your encryption password to decrypt the private key. You have 3 attempts. If all attempts fail, the application will exit.
|
|
101
|
+
|
|
102
|
+
### Interface
|
|
103
|
+
|
|
104
|
+
The application will display a full-screen interface with:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
┌────────────────────────────────────────────────────────────┐
|
|
108
|
+
│ Neurai DePIN | RPC: localhost:19001 | ● Connected │
|
|
109
|
+
│ Token: MYTOKEN | NXXXabc...xyz | Last poll: 10:23:45 │
|
|
110
|
+
├────────────────────────────────────────────────────────────┤
|
|
111
|
+
│ │
|
|
112
|
+
│ [10:20:15] NXXXdef...123: Hello world │
|
|
113
|
+
│ [10:21:32] NXXXghi...456: Testing DePIN messaging │
|
|
114
|
+
│ [10:22:18] YOU: This is my message │
|
|
115
|
+
│ │
|
|
116
|
+
│ │
|
|
117
|
+
├────────────────────────────────────────────────────────────┤
|
|
118
|
+
│ > Type message... (Enter: Send | Ctrl+C: Quit) │
|
|
119
|
+
└────────────────────────────────────────────────────────────┘
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Components:**
|
|
123
|
+
|
|
124
|
+
- **Top bar**: Shows RPC connection status, configured token, address and last poll time
|
|
125
|
+
- **Message area**: Shows received and sent messages (scrollable with arrow keys)
|
|
126
|
+
- **Input area**: Type your message here
|
|
127
|
+
|
|
128
|
+
### Keyboard Shortcuts
|
|
129
|
+
|
|
130
|
+
- **Enter** or **Ctrl+S**: Send message
|
|
131
|
+
- **Ctrl+C** or **Escape**: Exit application
|
|
132
|
+
- **Up/Down arrows**: Scroll in message area
|
|
133
|
+
|
|
134
|
+
## How It Works
|
|
135
|
+
|
|
136
|
+
1. **Startup**: Application loads configuration and connects to RPC server
|
|
137
|
+
2. **Polling**: Every 10 seconds (configurable) checks for new messages in the DePIN pool
|
|
138
|
+
3. **Reception**: Messages are automatically decrypted and displayed on screen
|
|
139
|
+
4. **Sending**: When pressing Ctrl+S, the message is sent to **all token holders** (broadcast)
|
|
140
|
+
5. **Privacy**: If the server has a privacy layer configured (`depinpoolpkey`), messages are additionally encrypted
|
|
141
|
+
|
|
142
|
+
## Architecture
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
src/
|
|
146
|
+
├── index.js # Main entry point
|
|
147
|
+
├── config/
|
|
148
|
+
│ └── ConfigManager.js # Configuration management + wizard
|
|
149
|
+
├── wallet/
|
|
150
|
+
│ └── WalletManager.js # WIF derivation + RPC client
|
|
151
|
+
├── messaging/
|
|
152
|
+
│ ├── MessageStore.js # Message deduplication
|
|
153
|
+
│ ├── MessagePoller.js # Automatic polling
|
|
154
|
+
│ └── MessageSender.js # Broadcast sending
|
|
155
|
+
├── ui/
|
|
156
|
+
│ └── TerminalUI.js # Blessed interface
|
|
157
|
+
└── lib/
|
|
158
|
+
└── depinMsgLoader.js # IIFE bundle loader
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Troubleshooting
|
|
162
|
+
|
|
163
|
+
### Error: "neurai-depin-msg bundle not found"
|
|
164
|
+
|
|
165
|
+
Run `npm install` to install dependencies.
|
|
166
|
+
|
|
167
|
+
### Error: "Error connecting to RPC"
|
|
168
|
+
|
|
169
|
+
Verify that:
|
|
170
|
+
- The RPC server is accessible
|
|
171
|
+
- The URL in `config.json` is correct
|
|
172
|
+
- Credentials (username/password) are correct if the server requires them
|
|
173
|
+
|
|
174
|
+
### I'm not receiving messages
|
|
175
|
+
|
|
176
|
+
Verify that:
|
|
177
|
+
- Your address owns the configured DePIN token
|
|
178
|
+
- Other token holders exist with revealed public keys
|
|
179
|
+
- The RPC server supports DePIN methods (`depinreceivemsg`, `depinsubmitmsg`)
|
|
180
|
+
|
|
181
|
+
### Error: "No recipients found with revealed public key"
|
|
182
|
+
|
|
183
|
+
For others to receive your messages, they must have revealed their public key. This is done through a special transaction to the burn address or via the corresponding RPC command.
|
|
184
|
+
|
|
185
|
+
## Security
|
|
186
|
+
|
|
187
|
+
- **Private key storage**: Your WIF private key is encrypted with AES-256-GCM using a password-derived key (scrypt with 32-byte salt). The encrypted private key is stored in `config.json` in the format `salt:iv:authTag:encrypted`. The decrypted key is only kept in memory during runtime and is never saved unencrypted to disk.
|
|
188
|
+
- **Password requirements**: Encryption password must be between 4 and 30 characters. You have 3 attempts to enter the correct password on startup.
|
|
189
|
+
- **Private key usage**: Your private key is never sent to the server. It's only used locally to sign and decrypt messages.
|
|
190
|
+
- **Message encryption**: Messages are encrypted with ECIES (Elliptic Curve Integrated Encryption Scheme) before being sent.
|
|
191
|
+
- **Privacy layer**: If enabled, adds an additional encryption layer using the server pool's public key.
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT
|